mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Configurable back-end port
This commit is contained in:
@@ -12,6 +12,7 @@ global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
global __last_save_file
|
||||
global __prefer_liberation_payloads
|
||||
global __server_port
|
||||
|
||||
|
||||
USER_PATH = Path(os.environ["LOCALAPPDATA"]) / "DCSRetribution"
|
||||
@@ -25,6 +26,7 @@ def init():
|
||||
global __last_save_file
|
||||
global __ignore_empty_install_directory
|
||||
global __prefer_liberation_payloads
|
||||
global __server_port
|
||||
|
||||
if PREFERENCES_PATH.exists():
|
||||
try:
|
||||
@@ -40,6 +42,7 @@ def init():
|
||||
__prefer_liberation_payloads = pref_data.get(
|
||||
"prefer_liberation_payloads", False
|
||||
)
|
||||
__server_port = pref_data.get("server_port", 16880)
|
||||
is_first_start = False
|
||||
except (KeyError, json.JSONDecodeError):
|
||||
__dcs_saved_game_directory = ""
|
||||
@@ -47,11 +50,13 @@ def init():
|
||||
__last_save_file = ""
|
||||
__ignore_empty_install_directory = False
|
||||
__prefer_liberation_payloads = False
|
||||
__server_port = 16880
|
||||
is_first_start = True
|
||||
else:
|
||||
__last_save_file = ""
|
||||
__ignore_empty_install_directory = False
|
||||
__prefer_liberation_payloads = False
|
||||
__server_port = 16880
|
||||
try:
|
||||
__dcs_saved_game_directory = (
|
||||
dcs.installation.get_dcs_saved_games_directory()
|
||||
@@ -68,18 +73,22 @@ def init():
|
||||
__dcs_installation_directory = ""
|
||||
|
||||
is_first_start = True
|
||||
persistency.setup(__dcs_saved_game_directory, __prefer_liberation_payloads)
|
||||
persistency.setup(
|
||||
__dcs_saved_game_directory, __prefer_liberation_payloads, __server_port
|
||||
)
|
||||
return is_first_start
|
||||
|
||||
|
||||
def setup(saved_game_dir, install_dir, prefer_liberation_payloads):
|
||||
def setup(saved_game_dir, install_dir, prefer_liberation_payloads, port):
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
global __prefer_liberation_payloads
|
||||
global __server_port
|
||||
__dcs_saved_game_directory = saved_game_dir
|
||||
__dcs_installation_directory = install_dir
|
||||
__prefer_liberation_payloads = prefer_liberation_payloads
|
||||
persistency.setup(__dcs_saved_game_directory, __prefer_liberation_payloads)
|
||||
__server_port = port
|
||||
persistency.setup(saved_game_dir, prefer_liberation_payloads, port)
|
||||
|
||||
|
||||
def setup_last_save_file(last_save_file):
|
||||
@@ -92,12 +101,14 @@ def save_config():
|
||||
global __dcs_installation_directory
|
||||
global __last_save_file
|
||||
global __ignore_empty_install_directory
|
||||
global __server_port
|
||||
pref_data = {
|
||||
"saved_game_dir": __dcs_saved_game_directory,
|
||||
"dcs_install_dir": __dcs_installation_directory,
|
||||
"last_save_file": __last_save_file,
|
||||
"ignore_empty_install_directory": __ignore_empty_install_directory,
|
||||
"prefer_liberation_payloads": __prefer_liberation_payloads,
|
||||
"server_port": __server_port,
|
||||
}
|
||||
PREFERENCES_PATH.parent.mkdir(exist_ok=True, parents=True)
|
||||
with PREFERENCES_PATH.open("w") as prefs:
|
||||
@@ -119,6 +130,11 @@ def prefer_liberation_payloads():
|
||||
return __prefer_liberation_payloads
|
||||
|
||||
|
||||
def server_port():
|
||||
global __server_port
|
||||
return __server_port
|
||||
|
||||
|
||||
def ignore_empty_install_directory():
|
||||
global __ignore_empty_install_directory
|
||||
return __ignore_empty_install_directory
|
||||
|
||||
@@ -442,7 +442,8 @@ def main():
|
||||
dump_task_priorities()
|
||||
return
|
||||
|
||||
with Server().run_in_thread():
|
||||
liberation_install.init()
|
||||
with Server(liberation_install.server_port()).run_in_thread():
|
||||
run_ui(game, UiFlags(args.dev, args.show_sim_speed_controls))
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from PySide6.QtWebEngineCore import QWebEnginePage, QWebEngineSettings
|
||||
from PySide6.QtWebEngineWidgets import QWebEngineView
|
||||
|
||||
from game.server.settings import ServerSettings
|
||||
from qt_ui.liberation_install import server_port
|
||||
from qt_ui.models import GameModel
|
||||
|
||||
|
||||
@@ -44,7 +45,7 @@ class QLiberationMap(QWebEngineView):
|
||||
url = QUrl("http://localhost:3000")
|
||||
else:
|
||||
url = QUrl.fromLocalFile(str(Path("client/build/index.html").resolve()))
|
||||
server_settings = ServerSettings.get()
|
||||
server_settings = ServerSettings.get(server_port())
|
||||
host = server_settings.server_bind_address
|
||||
if host.startswith("::"):
|
||||
host = f"[{host}]"
|
||||
|
||||
@@ -12,6 +12,7 @@ from PySide6.QtWidgets import (
|
||||
QPushButton,
|
||||
QVBoxLayout,
|
||||
QCheckBox,
|
||||
QSpinBox,
|
||||
)
|
||||
|
||||
from qt_ui import liberation_install, liberation_theme
|
||||
@@ -46,6 +47,9 @@ class QLiberationPreferences(QFrame):
|
||||
self.payloads_cb = QCheckBox()
|
||||
self.payloads_cb.setChecked(self.prefer_liberation_payloads)
|
||||
|
||||
self.port = liberation_install.server_port()
|
||||
self.port_input = QSpinBox()
|
||||
|
||||
self.initUi()
|
||||
|
||||
def initUi(self):
|
||||
@@ -87,6 +91,17 @@ class QLiberationPreferences(QFrame):
|
||||
)
|
||||
layout.addWidget(self.payloads_cb, 5, 1, alignment=Qt.AlignmentFlag.AlignRight)
|
||||
|
||||
layout.addWidget(
|
||||
QLabel("<strong>Server port (restart required):</strong>"),
|
||||
6,
|
||||
0,
|
||||
alignment=Qt.AlignmentFlag.AlignLeft,
|
||||
)
|
||||
layout.addWidget(self.port_input, 6, 1, alignment=Qt.AlignmentFlag.AlignRight)
|
||||
self.port_input.setRange(1, 2**16 - 1)
|
||||
self.port_input.setValue(self.port)
|
||||
self.port_input.setStyleSheet("QSpinBox{ width: 50 }")
|
||||
|
||||
main_layout.addLayout(layout)
|
||||
main_layout.addStretch()
|
||||
|
||||
@@ -113,6 +128,7 @@ class QLiberationPreferences(QFrame):
|
||||
self.saved_game_dir = self.edit_saved_game_dir.text()
|
||||
self.dcs_install_dir = self.edit_dcs_install_dir.text()
|
||||
self.prefer_liberation_payloads = self.payloads_cb.isChecked()
|
||||
self.port = self.port_input.value()
|
||||
set_theme_index(self.themeSelect.currentIndex())
|
||||
|
||||
if not os.path.isdir(self.saved_game_dir):
|
||||
@@ -169,7 +185,10 @@ class QLiberationPreferences(QFrame):
|
||||
return False
|
||||
|
||||
liberation_install.setup(
|
||||
self.saved_game_dir, self.dcs_install_dir, self.prefer_liberation_payloads
|
||||
self.saved_game_dir,
|
||||
self.dcs_install_dir,
|
||||
self.prefer_liberation_payloads,
|
||||
self.port,
|
||||
)
|
||||
liberation_install.save_config()
|
||||
liberation_theme.save_theme_config()
|
||||
|
||||
Reference in New Issue
Block a user