Make some last minute changes

This commit is contained in:
zontreck 2024-05-25 04:50:28 -07:00
parent ff94b3a0b1
commit 685d7379cb
5 changed files with 56 additions and 6 deletions

View file

@ -54,7 +54,7 @@ void main() async {
await doDownloadMods(false); await doDownloadMods(false);
print("Scanning mods..."); print("Scanning mods...");
settings.inst!.mods = await doScanMods(); settings.inst!.mods = await doScanMods(false);
settings.Write(); settings.Write();
print("Starting scheduler..."); print("Starting scheduler...");

View file

@ -36,7 +36,7 @@ Future<void> doDownloadMods(bool jail) async {
print(result.stdout); print(result.stdout);
} }
Future<List<Mod>> doScanMods() async { Future<List<Mod>> doScanMods(bool jail) async {
Settings settings = Settings(); Settings settings = Settings();
List<Mod> ret = []; List<Mod> ret = [];
@ -44,7 +44,8 @@ Future<List<Mod>> doScanMods() async {
for (Mod M in settings.inst!.mods.toList()) { for (Mod M in settings.inst!.mods.toList()) {
var index = settings.inst!.mods.indexOf(M); var index = settings.inst!.mods.indexOf(M);
// Assemble final path. // Assemble final path.
String modsPath = PathHelper.builder(settings.getModPath()) String modsPath = PathHelper.builder(
jail ? settings.getModJailPath() : settings.getModPath())
.resolve("steamapps") .resolve("steamapps")
.resolve("workshop") .resolve("workshop")
.resolve("content") .resolve("content")

View file

@ -6,6 +6,7 @@ import 'package:libac_dart/utils/IOTools.dart';
import 'package:servermanager/game.dart'; import 'package:servermanager/game.dart';
import 'package:servermanager/proton.dart'; import 'package:servermanager/proton.dart';
import 'package:servermanager/structs/SessionData.dart'; import 'package:servermanager/structs/SessionData.dart';
import 'package:servermanager/structs/mod.dart';
import 'package:servermanager/structs/settings.dart'; import 'package:servermanager/structs/settings.dart';
enum States { enum States {
@ -58,10 +59,10 @@ enum WarnIntervals {
type: WarnType.NonIntrusive, type: WarnType.NonIntrusive,
warning: "The server will restart in 2 hours"), warning: "The server will restart in 2 hours"),
NONE( NONE(
seconds: -1, seconds: 2147483647,
type: WarnType.NonIntrusive, type: WarnType.NonIntrusive,
warning: warning:
""); // -1 is a impossible value, this makes this one a good default value ""); // int32 max value should never be possible, is more seconds than in a single day.
final int seconds; final int seconds;
final WarnType type; final WarnType type;
@ -122,7 +123,7 @@ class StateMachine {
await settings.RunUpdate(valid: false); await settings.RunUpdate(valid: false);
await doDownloadMods(false); await doDownloadMods(false);
settings.inst!.mods = await doScanMods(); settings.inst!.mods = await doScanMods(false);
settings.Write(); settings.Write();
await settings.writeOutModListFile(); await settings.writeOutModListFile();
@ -196,6 +197,7 @@ class StateMachine {
resetKillswitch(); resetKillswitch();
SessionData.timer = settings.inst!.timer.time.copy(); SessionData.timer = settings.inst!.timer.time.copy();
changeState(States.PreStart); changeState(States.PreStart);
SessionData.enableRestartTimer = settings.inst!.timer.enabled;
} }
break; break;
} }
@ -204,6 +206,7 @@ class StateMachine {
// Restart timers and such // Restart timers and such
SessionData.timer.tickDown(); SessionData.timer.tickDown();
SessionData.operating_time.tickUp(); SessionData.operating_time.tickUp();
SessionData.bumpModUpdateChecker();
// Check if we should send an alert // Check if we should send an alert
int sec = SessionData.timer.getTotalSeconds(); int sec = SessionData.timer.getTotalSeconds();
@ -233,6 +236,34 @@ class StateMachine {
SessionData.shutdownPending = false; SessionData.shutdownPending = false;
} }
// Check mod updates
if (SessionData.shouldCheckModUpdates()) {
Timer.periodic(Duration(seconds: 10), (timer) async {
timer.cancel();
SessionData.resetModUpdateChecker();
await doDownloadMods(true);
List<Mod> currentMods = await doScanMods(true);
List<String> updatedMods = [];
for (int i = 0; i < currentMods.length; i++) {
Mod currentMod = settings.inst!.mods[i];
Mod scannedMod = currentMods[i];
if (currentMod.mod_hash == scannedMod.mod_hash) {
// Mod is ok
} else {
// Mod is not ok
updatedMods.add("${scannedMod.mod_name}");
}
}
settings.sendRconCommand(
"broadcast The server will be going down for a restart in 5 minutes. The following mods have been updated: ${updatedMods.join(', ')}");
SessionData.timer.apply((5 * 60));
SessionData.enableRestartTimer = true;
});
}
// Check Total Seconds // Check Total Seconds
if (SessionData.timer.getTotalSeconds() == 0 && if (SessionData.timer.getTotalSeconds() == 0 &&
settings.inst!.timer.enabled) { settings.inst!.timer.enabled) {

View file

@ -15,4 +15,19 @@ class SessionData {
static String shutdownMessage = ""; static String shutdownMessage = "";
static WarnIntervals CURRENT_INTERVAL = WarnIntervals.NONE; static WarnIntervals CURRENT_INTERVAL = WarnIntervals.NONE;
static Time mod_update_check_tracker = Time(hours: 0, minutes: 0, seconds: 0);
static bool enableRestartTimer = false;
static void resetModUpdateChecker() {
mod_update_check_tracker = Time(hours: 0, minutes: 0, seconds: 0);
}
static void bumpModUpdateChecker() {
mod_update_check_tracker.tickUp();
}
static bool shouldCheckModUpdates() {
return mod_update_check_tracker.minutes >= 30;
}
} }

View file

@ -281,6 +281,9 @@ class Settings {
login(inst!.serverSettings.RconPassword); login(inst!.serverSettings.RconPassword);
return sendCommand(command); return sendCommand(command);
} catch (E) {
// Sending rcon failed
return false;
} finally { } finally {
close(); close();
} }