summaryrefslogtreecommitdiff
path: root/server/bin
diff options
context:
space:
mode:
Diffstat (limited to 'server/bin')
-rw-r--r--server/bin/main.dart34
1 files changed, 23 insertions, 11 deletions
diff --git a/server/bin/main.dart b/server/bin/main.dart
index 60910a9..36c64c7 100644
--- a/server/bin/main.dart
+++ b/server/bin/main.dart
@@ -3,6 +3,7 @@
/// Usage (from the server/ directory):
/// dart run bin/main.dart
/// dart run bin/main.dart --port 8080 --static-dir ../web/dist
+/// dart run bin/main.dart --saves-dir /data/saves # e.g. in Docker
library;
import 'dart:io';
@@ -27,15 +28,20 @@ Future<void> main(List<String> args) async {
int.tryParse(Platform.environment['PORT'] ?? '') ??
4567;
final staticDir = _parseString(args, 'static-dir') ?? '../web/dist';
+ // The save directory (game state, settings, saves, seats) defaults to
+ // `saves/` next to the server; override for Docker / multi-game hosts.
+ final savesDir = _parseString(args, 'saves-dir') ?? 'saves';
+ // The game data the engine loads and the client's menus read.
+ final dataDir = _parseString(args, 'data-dir') ?? 'assets/data/';
- // Boot the game engine (single save in saves/, game data from
- // assets/data/), then attach the network layer: the WebSocket game
- // server, with seat ownership persisted next to the game state.
- await _bootGameCore();
+ // Boot the game engine (single save in [savesDir], game data from
+ // [dataDir]), then attach the network layer: the WebSocket game server,
+ // with seat ownership persisted next to the game state.
+ await _bootGameCore(savesDir: savesDir, dataDir: dataDir);
final gameServer = GameServer(
gameState: getIt<GameState>(),
sessions: SessionManager(),
- seatStore: FileSeatStore('saves'),
+ seatStore: FileSeatStore(savesDir),
);
final server = await startServer(
@@ -43,7 +49,7 @@ Future<void> main(List<String> args) async {
staticDir: staticDir,
gameServer: gameServer,
// The client's menus and artwork read the same assets the engine loads.
- dataDir: 'assets/data/',
+ dataDir: dataDir,
imageDir: 'assets/images/',
// In-game ability-text translations for the client's card renderer.
i18nDir: 'assets/i18n/',
@@ -61,19 +67,25 @@ Future<void> main(List<String> args) async {
/// Registers the core singletons (file-backed save), loads the game data,
/// initializes the game state, and restores the most recent save.
-Future<void> _bootGameCore({String dataDir = 'assets/data/'}) async {
+Future<void> _bootGameCore({
+ required String savesDir,
+ required String dataDir,
+}) async {
setupCore(
- saveStore: FileSaveStore('saves'),
- settingsStore: FileSettingsStore('saves'),
+ saveStore: FileSaveStore(savesDir),
+ settingsStore: FileSettingsStore(savesDir),
);
await getIt<GameData>().loadData(dataDir);
final gameState = getIt<GameState>();
gameState.init();
- // Restore the persisted settings (saves/settings.json; no-op on first
+ // Restore the persisted settings (<savesDir>/settings.json; no-op on first
// run) before the server answers the first `welcome` with them.
getIt<Settings>().loadFromDisk();
gameState.load();
- _log.info('game core booted (command index ${gameState.commandIndex})');
+ _log.info(
+ 'game core booted (saves: $savesDir, '
+ 'command index ${gameState.commandIndex})',
+ );
}
int? _parseInt(List<String> args, String name) =>