From 6e9a37ef000690beeaadd582494e7f39409811a7 Mon Sep 17 00:00:00 2001 From: "Tran G. (Revernomad) Khoa" Date: Mon, 20 Apr 2026 11:13:18 +0700 Subject: [PATCH] fix: use absolute paths in Arma 3 launch args to survive cwd change Arma 3 changes its own working directory to the exe folder on startup, so relative paths like -config=server.cfg resolved against A3Master/ instead of the server data dir. Configs were never found, and profile/ battleye dirs pointed at the wrong location (confirmed via RPT location in A3Master/server/ instead of the data dir). build_launch_args() now accepts an optional server_dir: Path argument. When provided, all four path args (-config, -cfg, -profiles, -bepath) use absolute paths. Service passes server_dir at the call site. --- backend/adapters/arma3/config_generator.py | 24 ++++++++++++++++++---- backend/core/servers/service.py | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/backend/adapters/arma3/config_generator.py b/backend/adapters/arma3/config_generator.py index 25afe0e..6acaea5 100644 --- a/backend/adapters/arma3/config_generator.py +++ b/backend/adapters/arma3/config_generator.py @@ -401,20 +401,36 @@ class Arma3ConfigGenerator: self, config_sections: dict[str, dict], mod_args: list[str] | None = None, + server_dir: Path | None = None, ) -> list[str]: from adapters.exceptions import LaunchArgsError launch = LaunchConfig(**config_sections.get("launch", {})) server = ServerConfig(**config_sections.get("server", {})) + # Arma 3 changes its own cwd to the exe directory at startup, so relative + # paths in launch args resolve against the exe dir, not server_dir. + # Use absolute paths when server_dir is provided so configs are always found. + if server_dir is not None: + d = Path(server_dir) + config_arg = f"-config={d / 'server.cfg'}" + cfg_arg = f"-cfg={d / 'basic.cfg'}" + profiles_arg = f"-profiles={d / 'server'}" + bepath_arg = f"-bepath={d / 'battleye'}" + else: + config_arg = "-config=server.cfg" + cfg_arg = "-cfg=basic.cfg" + profiles_arg = "-profiles=./server" + bepath_arg = "-bepath=./battleye" + args = [ f"-port={config_sections.get('_port', 2302)}", - "-config=server.cfg", - "-cfg=basic.cfg", - "-profiles=./server", + config_arg, + cfg_arg, + profiles_arg, "-name=server", f"-world={launch.world}", f"-limitFPS={launch.limit_fps}", - "-bepath=./battleye", + bepath_arg, ] if launch.auto_init: args.append("-autoInit") diff --git a/backend/core/servers/service.py b/backend/core/servers/service.py index 898987d..1c4f808 100644 --- a/backend/core/servers/service.py +++ b/backend/core/servers/service.py @@ -274,7 +274,7 @@ class ServerService: # Build launch args try: - launch_args = config_gen.build_launch_args(raw_sections, mod_args) + launch_args = config_gen.build_launch_args(raw_sections, mod_args, server_dir=server_dir) except LaunchArgsError as e: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST,