2024-05-23 00:11:14 -07:00
|
|
|
import 'dart:io';
|
|
|
|
|
2024-05-24 14:52:01 -07:00
|
|
|
import 'package:libac_dart/packets/packets.dart';
|
|
|
|
import 'package:libac_dart/utils/IOTools.dart';
|
2024-05-23 04:12:45 -07:00
|
|
|
import 'package:servermanager/game.dart';
|
2024-05-22 20:47:52 -07:00
|
|
|
import 'package:servermanager/packets/ClientPackets.dart';
|
2024-06-16 20:13:35 -07:00
|
|
|
import 'package:servermanager/structs/SessionData.dart';
|
2024-07-02 16:01:06 -07:00
|
|
|
import 'package:servermanager/structs/credentials.dart';
|
2024-05-23 00:11:14 -07:00
|
|
|
import 'package:servermanager/structs/settings.dart';
|
2024-05-22 16:13:19 -07:00
|
|
|
|
2024-05-25 05:19:59 -07:00
|
|
|
void main() async {
|
2024-05-25 05:03:58 -07:00
|
|
|
print("Current working directory: ${Directory.current.path}");
|
|
|
|
print("/!\\ This server is now starting... /!\\\n\n");
|
|
|
|
|
2024-05-22 20:47:52 -07:00
|
|
|
ClientPackets.register();
|
2024-05-23 00:11:14 -07:00
|
|
|
// Set up paths
|
|
|
|
Settings settings = Settings();
|
2024-05-23 04:12:45 -07:00
|
|
|
await settings.Read();
|
|
|
|
|
2024-06-03 15:13:54 -07:00
|
|
|
print(
|
2024-08-28 11:30:57 -07:00
|
|
|
"Server Admin Credentials\nUsername: ${settings.superuser.name}\nPassword (Default): changeMe123\n\n");
|
2024-05-23 00:11:14 -07:00
|
|
|
|
|
|
|
PathHelper helper = PathHelper(pth: Directory.current.path);
|
|
|
|
helper = helper.resolve("data").mkdir();
|
|
|
|
|
|
|
|
PathHelper steamCmd =
|
|
|
|
PathHelper.builder(helper.build()).resolve("steamcmd").mkdir();
|
|
|
|
PathHelper game = PathHelper.builder(helper.build()).resolve("game").mkdir();
|
|
|
|
|
2024-05-23 04:12:45 -07:00
|
|
|
settings.base_path = helper.build();
|
2024-05-23 00:11:14 -07:00
|
|
|
settings.game_path = game.build();
|
|
|
|
settings.steamcmd_path = steamCmd.build();
|
2024-05-23 04:12:45 -07:00
|
|
|
|
|
|
|
print("Setup of local system variables completed");
|
2024-05-23 00:11:14 -07:00
|
|
|
|
|
|
|
settings.Write();
|
2024-05-23 04:12:45 -07:00
|
|
|
print("Wrote settings.dat");
|
|
|
|
|
|
|
|
print("Initializing SteamCMD");
|
|
|
|
await settings.initializeSteamCmd();
|
2024-06-03 18:33:13 -07:00
|
|
|
print("Initialized Steamcmd");
|
|
|
|
|
|
|
|
print("Running winetricks");
|
2024-08-28 11:30:57 -07:00
|
|
|
if (!settings.wineInitialized) {
|
|
|
|
await settings.initializeWine();
|
|
|
|
settings.wineInitialized = true;
|
|
|
|
settings.Write();
|
|
|
|
}
|
|
|
|
|
2024-06-03 18:33:13 -07:00
|
|
|
print("Finished installing needed DLLs");
|
2024-05-23 04:12:45 -07:00
|
|
|
|
|
|
|
print("Checking for game server updates...");
|
2024-05-25 06:28:52 -07:00
|
|
|
await settings.RunUpdate(valid: false);
|
2024-05-23 22:18:59 -07:00
|
|
|
await settings.createModFolderIfNotExists();
|
|
|
|
await settings.createServerModFolderIfNotExists();
|
|
|
|
await settings.createModJailFolderIfNotExists();
|
2024-07-01 23:24:06 -07:00
|
|
|
await settings.createBackupsFolderIfNotExists();
|
2024-05-23 22:18:59 -07:00
|
|
|
await settings.writeOutModListFile();
|
2024-05-23 04:12:45 -07:00
|
|
|
print("Finished checking for game server updates...");
|
|
|
|
|
|
|
|
if (settings.FTS) {
|
|
|
|
print(
|
|
|
|
"Aborting server startup procedure, initial server setup is not yet complete\n\n[ You must log in with the ServerManager to continue ]");
|
|
|
|
} else {
|
2024-05-24 13:48:21 -07:00
|
|
|
try {
|
|
|
|
print("Downloading mods...");
|
|
|
|
await doDownloadMods(false);
|
2024-05-23 04:12:45 -07:00
|
|
|
|
2024-05-24 13:48:21 -07:00
|
|
|
print("Scanning mods...");
|
2024-05-25 04:50:28 -07:00
|
|
|
settings.inst!.mods = await doScanMods(false);
|
2024-05-24 13:48:21 -07:00
|
|
|
settings.Write();
|
2024-05-23 22:18:59 -07:00
|
|
|
|
2024-05-24 13:48:21 -07:00
|
|
|
print("Starting scheduler...");
|
|
|
|
await settings.subsys.startScheduler();
|
|
|
|
} catch (E) {
|
|
|
|
settings.FTS = true;
|
|
|
|
settings.Write();
|
|
|
|
}
|
2024-05-23 04:12:45 -07:00
|
|
|
}
|
2024-05-22 20:47:52 -07:00
|
|
|
|
2024-05-23 04:12:45 -07:00
|
|
|
print("Starting up server manager server wrapper");
|
2024-06-03 18:33:13 -07:00
|
|
|
|
2024-06-16 20:13:35 -07:00
|
|
|
while (!SessionData.shutdownPending) {
|
|
|
|
try {
|
|
|
|
await PacketServer.start(
|
|
|
|
settings.inst?.serverSettings.WrapperPort ?? 25306);
|
|
|
|
} catch (E) {}
|
|
|
|
}
|
2024-05-22 16:13:19 -07:00
|
|
|
|
|
|
|
print("Server stopping");
|
|
|
|
}
|