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);
print("Scanning mods...");
settings.inst!.mods = await doScanMods();
settings.inst!.mods = await doScanMods(false);
settings.Write();
print("Starting scheduler...");

View file

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

View file

@ -6,6 +6,7 @@ import 'package:libac_dart/utils/IOTools.dart';
import 'package:servermanager/game.dart';
import 'package:servermanager/proton.dart';
import 'package:servermanager/structs/SessionData.dart';
import 'package:servermanager/structs/mod.dart';
import 'package:servermanager/structs/settings.dart';
enum States {
@ -58,10 +59,10 @@ enum WarnIntervals {
type: WarnType.NonIntrusive,
warning: "The server will restart in 2 hours"),
NONE(
seconds: -1,
seconds: 2147483647,
type: WarnType.NonIntrusive,
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 WarnType type;
@ -122,7 +123,7 @@ class StateMachine {
await settings.RunUpdate(valid: false);
await doDownloadMods(false);
settings.inst!.mods = await doScanMods();
settings.inst!.mods = await doScanMods(false);
settings.Write();
await settings.writeOutModListFile();
@ -196,6 +197,7 @@ class StateMachine {
resetKillswitch();
SessionData.timer = settings.inst!.timer.time.copy();
changeState(States.PreStart);
SessionData.enableRestartTimer = settings.inst!.timer.enabled;
}
break;
}
@ -204,6 +206,7 @@ class StateMachine {
// Restart timers and such
SessionData.timer.tickDown();
SessionData.operating_time.tickUp();
SessionData.bumpModUpdateChecker();
// Check if we should send an alert
int sec = SessionData.timer.getTotalSeconds();
@ -233,6 +236,34 @@ class StateMachine {
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
if (SessionData.timer.getTotalSeconds() == 0 &&
settings.inst!.timer.enabled) {

View file

@ -15,4 +15,19 @@ class SessionData {
static String shutdownMessage = "";
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);
return sendCommand(command);
} catch (E) {
// Sending rcon failed
return false;
} finally {
close();
}