Making the code more efficient and light

This commit is contained in:
Levent007 2021-03-08 12:54:45 +01:00
parent 2fd278e4cd
commit 19087e93dd

View File

@ -61,7 +61,7 @@ export default class SeedingMode extends BasePlugin {
constructor(server, options, connectors) { constructor(server, options, connectors) {
super(server, options, connectors); super(server, options, connectors);
this.waitOnMapChange = false; this.stop = false;
this.broadcast = this.broadcast.bind(this); this.broadcast = this.broadcast.bind(this);
this.onNewGame = this.onNewGame.bind(this); this.onNewGame = this.onNewGame.bind(this);
} }
@ -79,39 +79,25 @@ export default class SeedingMode extends BasePlugin {
this.server.removeEventListener('NEW_GAME', this.onNewGame); this.server.removeEventListener('NEW_GAME', this.onNewGame);
} }
onNewGame(info) { onNewGame() {
this.waitOnMapChange = true; this.stop = true;
setTimeout(() => {
this.stop = false;
}, 30 * 1000);
} }
async broadcast() { async broadcast() {
if (this.options.waitOnNewGames && this.waitOnMapChange) { if (this.stop) return;
setTimeout(async () => { if (
if ( this.server.a2sPlayerCount !== 0 &&
this.server.a2sPlayerCount !== 0 && this.server.a2sPlayerCount < this.options.seedingThreshold
this.server.a2sPlayerCount < this.options.seedingThreshold )
) await this.server.rcon.broadcast(this.options.seedingMessage);
await this.server.rcon.broadcast(this.options.seedingMessage); else if (
else if ( this.server.a2sPlayerCount !== 0 &&
this.server.a2sPlayerCount !== 0 && this.options.liveEnabled &&
this.options.liveEnabled && this.server.a2sPlayerCount < this.options.liveThreshold
this.server.a2sPlayerCount < this.options.liveThreshold )
) await this.server.rcon.broadcast(this.options.liveMessage);
await this.server.rcon.broadcast(this.options.liveMessage);
this.waitOnMapChange = false;
}, this.options.waitTimeOnNewGame * 1000);
} else {
if (
this.server.a2sPlayerCount !== 0 &&
this.server.a2sPlayerCount < this.options.seedingThreshold
)
await this.server.rcon.broadcast(this.options.seedingMessage);
else if (
this.server.a2sPlayerCount !== 0 &&
this.options.liveEnabled &&
this.server.a2sPlayerCount < this.options.liveThreshold
)
await this.server.rcon.broadcast(this.options.liveMessage);
}
} }
} }