Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions src/helpers/serverUPSHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interface UPSServer extends FactorioServer {
}

/**
* @classdesc UPS handler, generates data that can be fetched. Doesn't historically store it
*/
* @classdesc UPS handler, generates data that can be fetched. Doesn't historically store it
*/
class UPSManager {
private servers: UPSServer[];
private _processing: boolean;
Expand All @@ -42,7 +42,13 @@ class UPSManager {
)
.then((output) => {
try {
this.servers[serverKey].playercount = parseInt(output.resp);
const playercount = parseInt(output.resp)
this.servers[serverKey].playercount = playercount;
if (playercount > 0) {
rcon.rconCommand(`/interface game.tick_paused = false`, this.servers[serverKey].discordid)
} else {
rcon.rconCommand(`/interface game.tick_paused = true`, this.servers[serverKey].discordid)
}
} catch { }
})
.catch(() => { });
Expand All @@ -61,24 +67,16 @@ class UPSManager {

playerStuff(data: playerJoinData | playerLeaveData) {
const line = data.line;
const server = data.server;
const server = this.servers.find(s => s.discordid === data.server.discordid)
if (line.type === "join") {
Object.keys(this.servers).forEach((serverKey) => {
if (this.servers[serverKey]?.discordid === server.discordid)
this.servers[serverKey].playercount++;
if (this.servers[serverKey].playercount == 1) {
rcon.rconCommand("/sc game.tick_paused = false", server.discordid)
}
});
server.playercount++
if (server.playercount > 0)
rcon.rconCommand("/sc game.tick_paused = false", server.discordid)
}
if (line.type === "leave") {
Object.keys(this.servers).forEach((serverKey) => {
if (this.servers[serverKey]?.discordid === server.discordid)
this.servers[serverKey].playercount--;
if (this.servers[serverKey].playercount == 0) {
rcon.rconCommand("/sc game.tick_paused = true", server.discordid)
}
});
server.playercount--
if (server.playercount === 0)
rcon.rconCommand("/sc game.tick_paused = true", server.discordid)
}
}
private async getData() {
Expand Down Expand Up @@ -127,13 +125,14 @@ class UPSManager {
this._processing = false;
}
/**
* Get current data for handling
* @returns {UPS[]} - Collected data
*/
* Get current data for handling
* @returns {UPS[]} - Collected data
*/
exportData(): UPSServer[] {
return this.servers;
}
}

const UPSHandler = new UPSManager(serversJS);
export default UPSHandler;