Fix server ups active on first start

This commit is contained in:
Cooldude2606
2025-09-04 11:58:14 +01:00
parent 5bd6183bb3
commit d654005dae

View File

@@ -6,29 +6,42 @@ export class InstancePlugin extends BaseInstancePlugin {
private gameTimes: number[] = []; private gameTimes: number[] = [];
async onStart() { async onStart() {
this.updateInterval = setInterval(this.updateUps.bind(this), this.instance.config.get("exp_server_ups.update_interval")); if (!this.instance.config.get("factorio.settings")["auto_pause"]) {
this.setInterval();
}
} }
onExit() { onExit() {
if (this.updateInterval) { this.clearInterval();
clearInterval(this.updateInterval);
}
} }
async onInstanceConfigFieldChanged(field: string, curr: unknown): Promise<void> { async onInstanceConfigFieldChanged(field: string, curr: unknown): Promise<void> {
if (field === "exp_server_ups.update_interval") { if (field === "exp_server_ups.update_interval") {
this.onExit(); this.clearInterval();
await this.onStart(); this.setInterval();
} else if (field === "exp_server_ups.average_interval") { } else if (field === "exp_server_ups.average_interval") {
this.gameTimes.splice(curr as number); this.gameTimes.splice(curr as number);
} }
} }
async onPlayerEvent(event: lib.PlayerEvent): Promise<void> { async onPlayerEvent(event: lib.PlayerEvent): Promise<void> {
if (event.type === "join" && !this.updateInterval) { if (event.type === "join") {
await this.onStart(); this.setInterval();
} else if (event.type === "leave" && this.instance.playersOnline.size == 0 && this.instance.config.get("factorio.settings")["auto_pause"] as boolean) { } else if (event.type === "leave" && this.instance.playersOnline.size == 0 && this.instance.config.get("factorio.settings")["auto_pause"]) {
this.onExit(); this.clearInterval();
}
}
setInterval() {
if (!this.updateInterval) {
this.updateInterval = setInterval(this.updateUps.bind(this), this.instance.config.get("exp_server_ups.update_interval"));
}
}
clearInterval() {
if (this.updateInterval) {
clearInterval(this.updateInterval);
this.updateInterval = undefined;
} }
} }