From cb5d33b936f3bcf46bc794ae9ae795007c8cbfb9 Mon Sep 17 00:00:00 2001 From: Eric Froemling Date: Mon, 20 Apr 2020 21:44:11 -0700 Subject: [PATCH] more work on prefab servers --- assets/src/server/server.py | 37 ++++++++++++++++++++----------------- tools/batools/build.py | 17 +++++------------ tools/snippets | 7 ++++++- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/assets/src/server/server.py b/assets/src/server/server.py index 336b8b73..1c98af84 100755 --- a/assets/src/server/server.py +++ b/assets/src/server/server.py @@ -225,7 +225,7 @@ def _run_server_cycle(binary_path: str, config: Dict[str, Any], # If we hit ANY Exceptions (including KeyboardInterrupt) we want to kill # the server binary, so we need to catch BaseException. except BaseException: - print("Killing server binary...") + print("Stopping server...") # First, ask it nicely to die and give it a moment. # If that doesn't work, bring down the hammer. @@ -234,7 +234,7 @@ def _run_server_cycle(binary_path: str, config: Dict[str, Any], process.wait(timeout=10) except subprocess.TimeoutExpired: process.kill() - print("Server binary's dead, Jim.") + print("Server stopped.") raise @@ -245,23 +245,23 @@ def main() -> None: the game binary to keep things fresh. """ - # We expect to be running from the dir where this script lives. - script_dir = os.path.dirname(sys.argv[0]) - if script_dir != '': - os.chdir(script_dir) + # We want to actually run from the 'dist' subdir. + if not os.path.isdir('dist'): + raise RuntimeError('"dist" directory not found.') + os.chdir('dist') - config_path = './config.py' + config_path = '../config.yaml' binary_path = None if os.name == 'nt': - test_paths = 'bs_headless.exe', 'BallisticaCore.exe' + test_paths = ['ballisticacore_headless.exe'] else: - test_paths = './bs_headless', './ballisticacore' + test_paths = ['./ballisticacore_headless'] for path in test_paths: if os.path.exists(path): binary_path = path break if binary_path is None: - raise Exception('Unable to locate bs_headless binary.') + raise RuntimeError('Unable to locate ballisticacore_headless binary.') config = _get_default_config() @@ -278,10 +278,10 @@ def main() -> None: # Print a little spiel in interactive mode (make sure we do this before our # thread reads stdin). if sys.stdin.isatty(): - print("ballisticacore server wrapper starting up...\n" - "tip: enter python commands via stdin to " - "reconfigure the server on the fly:\n" - "example: config['party_name'] = 'New Party Name'") + print("BallisticaCore server wrapper starting up...") + # "tip: enter python commands via stdin to " + # "reconfigure the server on the fly:\n" + # "example: config['party_name'] = 'New Party Name'") class InputThread(threading.Thread): """A thread that just sits around waiting for input from stdin.""" @@ -289,7 +289,6 @@ def main() -> None: def run(self) -> None: while True: line = sys.stdin.readline() - print('GOT LINE', line) input_commands.append(line.strip()) thread = InputThread() @@ -309,7 +308,8 @@ def main() -> None: del __builtins__.exit del __builtins__.quit - # Sleep for a moment to allow initial stdin data to get through. + # Sleep for a moment to allow initial stdin data to get through + # (since it is being read in another thread). time.sleep(0.25) # Restart indefinitely until we're told not to. @@ -318,4 +318,7 @@ def main() -> None: if __name__ == '__main__': - main() + try: + main() + except KeyboardInterrupt: + sys.exit(-1) diff --git a/tools/batools/build.py b/tools/batools/build.py index fd158d48..b53580e9 100644 --- a/tools/batools/build.py +++ b/tools/batools/build.py @@ -85,8 +85,12 @@ class PrefabTarget(Enum): """Types of prefab builds able to be run.""" DEBUG = 'debug' DEBUG_BUILD = 'debug-build' + SERVER_DEBUG = 'server-debug' + SERVER_DEBUG_BUILD = 'server-debug-build' RELEASE = 'release' RELEASE_BUILD = 'release-build' + SERVER_RELEASE = 'server-release' + SERVER_RELEASE_BUILD = 'server-release-build' def _checkpaths(inpaths: List[str], category: SourceCategory, @@ -455,18 +459,7 @@ def make_prefab(target: PrefabTarget) -> None: raise RuntimeError(f'make_prefab: unrecognized platform:' f' {platform.system()}.') - if target is PrefabTarget.DEBUG: - mtarget = f'prefab-{base}-debug' - elif target is PrefabTarget.DEBUG_BUILD: - mtarget = f'prefab-{base}-debug-build' - elif target is PrefabTarget.RELEASE: - mtarget = f'prefab-{base}-release' - elif target is PrefabTarget.RELEASE_BUILD: - mtarget = f'prefab-{base}-release-build' - else: - raise RuntimeError(f'Invalid target: {target}') - - run(f'make {mtarget}') + run(f'make prefab-{base}-{target.value}') def _vstr(nums: Sequence[int]) -> str: diff --git a/tools/snippets b/tools/snippets index 322959e3..cb60caff 100755 --- a/tools/snippets +++ b/tools/snippets @@ -534,7 +534,12 @@ def make_prefab() -> None: if len(sys.argv) != 3: raise RuntimeError('Expected one argument') target = batools.build.PrefabTarget(sys.argv[2]) - batools.build.make_prefab(target) + try: + batools.build.make_prefab(target) + except (Exception, KeyboardInterrupt) as exc: + if str(exc): + print(f'make_prefab failed with error: {exc}') + sys.exit(-1) def update_makebob() -> None: