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:
@@ -17,6 +17,7 @@ if TYPE_CHECKING:
|
||||
|
||||
_dcs_saved_game_folder: Optional[str] = None
|
||||
_prefer_liberation_payloads: bool = False
|
||||
_server_port: int = 16880
|
||||
|
||||
|
||||
# fmt: off
|
||||
@@ -75,11 +76,13 @@ class MigrationUnpickler(pickle.Unpickler):
|
||||
# fmt: on
|
||||
|
||||
|
||||
def setup(user_folder: str, prefer_liberation_payloads: bool) -> None:
|
||||
def setup(user_folder: str, prefer_liberation_payloads: bool, port: int) -> None:
|
||||
global _dcs_saved_game_folder
|
||||
_dcs_saved_game_folder = user_folder
|
||||
global _prefer_liberation_payloads
|
||||
global _server_port
|
||||
_dcs_saved_game_folder = user_folder
|
||||
_prefer_liberation_payloads = prefer_liberation_payloads
|
||||
_server_port = port
|
||||
if not save_dir().exists():
|
||||
save_dir().mkdir(parents=True)
|
||||
|
||||
@@ -126,6 +129,11 @@ def save_dir() -> Path:
|
||||
return base_path() / "Retribution" / "Saves"
|
||||
|
||||
|
||||
def server_port() -> int:
|
||||
global _server_port
|
||||
return _server_port
|
||||
|
||||
|
||||
def _temporary_save_file() -> str:
|
||||
return str(save_dir() / "tmpsave.retribution")
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import time
|
||||
from collections.abc import Iterator
|
||||
from contextlib import contextmanager
|
||||
from threading import Thread
|
||||
from typing import Optional
|
||||
|
||||
import uvicorn
|
||||
from uvicorn import Config
|
||||
@@ -13,12 +14,13 @@ from game.sim import GameUpdateEvents
|
||||
|
||||
|
||||
class Server(uvicorn.Server):
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, port: Optional[int]) -> None:
|
||||
settings = ServerSettings.get(port)
|
||||
super().__init__(
|
||||
Config(
|
||||
app=app,
|
||||
host=ServerSettings.get().server_bind_address,
|
||||
port=ServerSettings.get().server_port,
|
||||
host=settings.server_bind_address,
|
||||
port=settings.server_port,
|
||||
# Configured explicitly with default_logging.yaml or logging.yaml.
|
||||
log_config=None,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from functools import lru_cache
|
||||
from typing import Optional
|
||||
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
@@ -30,5 +31,5 @@ class ServerSettings(BaseSettings):
|
||||
|
||||
@classmethod
|
||||
@lru_cache
|
||||
def get(cls) -> ServerSettings:
|
||||
return cls()
|
||||
def get(cls, port: Optional[int] = server_port) -> ServerSettings:
|
||||
return cls(server_port=port)
|
||||
|
||||
Reference in New Issue
Block a user