Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Format
  • Loading branch information
NicEastvillage committed Jan 10, 2026
commit 561eb83229c78caa1ba34975976f398a4c5c2484
32 changes: 22 additions & 10 deletions rlbot/managers/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rlbot.interface import RLBOT_SERVER_IP, RLBOT_SERVER_PORT, SocketRelay
from rlbot.utils import fill_desired_game_state, gateway
from rlbot.utils.logging import DEFAULT_LOGGER
from rlbot.utils.os_detector import RLBOT_SERVER_NAME, OS, CURRENT_OS
from rlbot.utils.os_detector import CURRENT_OS, OS, RLBOT_SERVER_NAME


class MatchManager:
Expand All @@ -23,10 +23,7 @@ class MatchManager:
rlbot_server_port = RLBOT_SERVER_PORT
initialized = False

def __init__(
self,
rlbot_server_path: Path | None = None
):
def __init__(self, rlbot_server_path: Path | None = None):
"""
Initialize a MatchManager.
Args:
Expand Down Expand Up @@ -54,8 +51,14 @@ def ensure_server_started(self):
otherwise the global installed RLBotServer will be used, if any.
"""

exe_name = self.rlbot_server_path.stem if self.rlbot_server_path is not None and self.rlbot_server_path.is_file() else RLBOT_SERVER_NAME
self.rlbot_server_process, self.rlbot_server_port = gateway.find_server_process(exe_name)
exe_name = (
self.rlbot_server_path.stem
if self.rlbot_server_path is not None and self.rlbot_server_path.is_file()
else RLBOT_SERVER_NAME
)
self.rlbot_server_process, self.rlbot_server_port = gateway.find_server_process(
exe_name
)
if self.rlbot_server_process is not None:
self.logger.info("%s is already running!", exe_name)
return
Expand All @@ -64,8 +67,15 @@ def ensure_server_started(self):
# Look in cwd or localappdata
path = Path.cwd() / RLBOT_SERVER_NAME
if not path.exists() and CURRENT_OS == OS.WINDOWS:
self.logger.debug(f"Could not find RLBotServer in cwd ('{path.parent}'), trying %localappdata% instead.")
path = Path(os.environ.get("LOCALAPPDATA")) / "RLBot5" / "bin" / RLBOT_SERVER_NAME
self.logger.debug(
f"Could not find RLBotServer in cwd ('{path.parent}'), trying %localappdata% instead."
)
path = (
Path(os.environ.get("LOCALAPPDATA"))
/ "RLBot5"
/ "bin"
/ RLBOT_SERVER_NAME
)
if not path.exists():
raise FileNotFoundError(
"Unable to find RLBotServer in the current working directory "
Expand All @@ -79,7 +89,9 @@ def ensure_server_started(self):
if path.exists() and path.is_dir():
path = path / RLBOT_SERVER_NAME
if not path.exists():
raise FileNotFoundError(f"Unable to find RLBotServer at the specified path '{path}'.")
raise FileNotFoundError(
f"Unable to find RLBotServer at the specified path '{path}'."
)

if path is None or not os.access(path, os.F_OK):
raise FileNotFoundError(
Expand Down
7 changes: 1 addition & 6 deletions rlbot/utils/gateway.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
import socket
import stat
import subprocess
from pathlib import Path

Expand All @@ -14,9 +12,7 @@
import shlex


def find_file(
base_dir: Path, file_name: str
) -> Path | None:
def find_file(base_dir: Path, file_name: str) -> Path | None:
"""
Looks for a file called `file_name` in the given `base_dir` directory and its subdirectories.
Returns the path to the file, or None if it was not found.
Expand Down Expand Up @@ -54,7 +50,6 @@ def find_open_server_port() -> int:


def launch(exe_path: Path) -> tuple[subprocess.Popen[bytes], int]:

port = find_open_server_port()

if CURRENT_OS == "Windows":
Expand Down
6 changes: 4 additions & 2 deletions tests/many_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
DIR = Path(__file__).parent

BOT_PATH = DIR / "atba/atba.bot.toml"
RLBOT_SERVER_FOLDER = find_file(DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME)
RLBOT_SERVER_PATH = find_file(
DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME
)

num_comms = set()

Expand All @@ -22,7 +24,7 @@ def handle_match_comm(comm: flat.MatchComm):


if __name__ == "__main__":
match_manager = MatchManager(RLBOT_SERVER_FOLDER)
match_manager = MatchManager(RLBOT_SERVER_PATH)
match_manager.rlbot_interface.match_comm_handlers.append(handle_match_comm)
match_manager.ensure_server_started()
match_manager.connect_and_run(
Expand Down
4 changes: 3 additions & 1 deletion tests/run_forever.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
DIR = Path(__file__).parent

BOT_PATH = DIR / "atba/atba.bot.toml"
RLBOT_SERVER_PATH = find_file(DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME)
RLBOT_SERVER_PATH = find_file(
DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME
)

if __name__ == "__main__":
match_manager = MatchManager(RLBOT_SERVER_PATH)
Expand Down
4 changes: 3 additions & 1 deletion tests/run_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
DIR = Path(__file__).parent

MATCH_CONFIG_PATH = DIR / "human_vs_atba.toml"
RLBOT_SERVER_PATH = find_file(DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME)
RLBOT_SERVER_PATH = find_file(
DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME
)

if __name__ == "__main__":
with MatchManager(RLBOT_SERVER_PATH) as man:
Expand Down