runServer function
Implementation
Future<void> runServer(List<String> arguments, [ServerLoader? onLoad]) async {
final ArgParser argParser = buildParser();
try {
final ArgResults results = argParser.parse(arguments);
bool verbose = false, autosave = false;
int maxPlayers = 10;
// Process the parsed arguments.
if (results.wasParsed('help')) {
printUsage(argParser);
return;
}
if (results.wasParsed('version')) {
print('server version: $version');
return;
}
if (results.wasParsed('verbose')) {
verbose = true;
}
if (results.wasParsed('autosave')) {
autosave = true;
}
if (results.wasParsed('max-players')) {
maxPlayers = int.tryParse(results['max-players'] ?? '') ?? maxPlayers;
}
String description = '';
if (results.wasParsed('description')) {
description = results['description'];
}
final server = await SetonixServer.load();
await server.init(
port: int.tryParse(results['port'] ?? '') ?? kDefaultPort,
verbose: verbose,
autosave: autosave,
description: description,
maxPlayers: maxPlayers,
);
await onLoad?.call(server);
await server.run();
} on FormatException catch (e) {
// Print usage information if an invalid argument was provided.
print(e.message);
print('');
printUsage(argParser);
}
}