Skip to content

Commit 561eb83

Browse files
Format
1 parent d0fe119 commit 561eb83

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

rlbot/managers/match.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from rlbot.interface import RLBOT_SERVER_IP, RLBOT_SERVER_PORT, SocketRelay
1010
from rlbot.utils import fill_desired_game_state, gateway
1111
from rlbot.utils.logging import DEFAULT_LOGGER
12-
from rlbot.utils.os_detector import RLBOT_SERVER_NAME, OS, CURRENT_OS
12+
from rlbot.utils.os_detector import CURRENT_OS, OS, RLBOT_SERVER_NAME
1313

1414

1515
class MatchManager:
@@ -23,10 +23,7 @@ class MatchManager:
2323
rlbot_server_port = RLBOT_SERVER_PORT
2424
initialized = False
2525

26-
def __init__(
27-
self,
28-
rlbot_server_path: Path | None = None
29-
):
26+
def __init__(self, rlbot_server_path: Path | None = None):
3027
"""
3128
Initialize a MatchManager.
3229
Args:
@@ -54,8 +51,14 @@ def ensure_server_started(self):
5451
otherwise the global installed RLBotServer will be used, if any.
5552
"""
5653

57-
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
58-
self.rlbot_server_process, self.rlbot_server_port = gateway.find_server_process(exe_name)
54+
exe_name = (
55+
self.rlbot_server_path.stem
56+
if self.rlbot_server_path is not None and self.rlbot_server_path.is_file()
57+
else RLBOT_SERVER_NAME
58+
)
59+
self.rlbot_server_process, self.rlbot_server_port = gateway.find_server_process(
60+
exe_name
61+
)
5962
if self.rlbot_server_process is not None:
6063
self.logger.info("%s is already running!", exe_name)
6164
return
@@ -64,8 +67,15 @@ def ensure_server_started(self):
6467
# Look in cwd or localappdata
6568
path = Path.cwd() / RLBOT_SERVER_NAME
6669
if not path.exists() and CURRENT_OS == OS.WINDOWS:
67-
self.logger.debug(f"Could not find RLBotServer in cwd ('{path.parent}'), trying %localappdata% instead.")
68-
path = Path(os.environ.get("LOCALAPPDATA")) / "RLBot5" / "bin" / RLBOT_SERVER_NAME
70+
self.logger.debug(
71+
f"Could not find RLBotServer in cwd ('{path.parent}'), trying %localappdata% instead."
72+
)
73+
path = (
74+
Path(os.environ.get("LOCALAPPDATA"))
75+
/ "RLBot5"
76+
/ "bin"
77+
/ RLBOT_SERVER_NAME
78+
)
6979
if not path.exists():
7080
raise FileNotFoundError(
7181
"Unable to find RLBotServer in the current working directory "
@@ -79,7 +89,9 @@ def ensure_server_started(self):
7989
if path.exists() and path.is_dir():
8090
path = path / RLBOT_SERVER_NAME
8191
if not path.exists():
82-
raise FileNotFoundError(f"Unable to find RLBotServer at the specified path '{path}'.")
92+
raise FileNotFoundError(
93+
f"Unable to find RLBotServer at the specified path '{path}'."
94+
)
8395

8496
if path is None or not os.access(path, os.F_OK):
8597
raise FileNotFoundError(

rlbot/utils/gateway.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import os
21
import socket
3-
import stat
42
import subprocess
53
from pathlib import Path
64

@@ -14,9 +12,7 @@
1412
import shlex
1513

1614

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

5551

5652
def launch(exe_path: Path) -> tuple[subprocess.Popen[bytes], int]:
57-
5853
port = find_open_server_port()
5954

6055
if CURRENT_OS == "Windows":

tests/many_match.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
DIR = Path(__file__).parent
1111

1212
BOT_PATH = DIR / "atba/atba.bot.toml"
13-
RLBOT_SERVER_FOLDER = find_file(DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME)
13+
RLBOT_SERVER_PATH = find_file(
14+
DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME
15+
)
1416

1517
num_comms = set()
1618

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

2325

2426
if __name__ == "__main__":
25-
match_manager = MatchManager(RLBOT_SERVER_FOLDER)
27+
match_manager = MatchManager(RLBOT_SERVER_PATH)
2628
match_manager.rlbot_interface.match_comm_handlers.append(handle_match_comm)
2729
match_manager.ensure_server_started()
2830
match_manager.connect_and_run(

tests/run_forever.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
DIR = Path(__file__).parent
1212

1313
BOT_PATH = DIR / "atba/atba.bot.toml"
14-
RLBOT_SERVER_PATH = find_file(DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME)
14+
RLBOT_SERVER_PATH = find_file(
15+
DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME
16+
)
1517

1618
if __name__ == "__main__":
1719
match_manager = MatchManager(RLBOT_SERVER_PATH)

tests/run_match.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
DIR = Path(__file__).parent
1010

1111
MATCH_CONFIG_PATH = DIR / "human_vs_atba.toml"
12-
RLBOT_SERVER_PATH = find_file(DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME)
12+
RLBOT_SERVER_PATH = find_file(
13+
DIR / "../../core/RLBotCS/bin/Release/", RLBOT_SERVER_NAME
14+
)
1315

1416
if __name__ == "__main__":
1517
with MatchManager(RLBOT_SERVER_PATH) as man:

0 commit comments

Comments
 (0)