From 812121c899e838e55bd61072d1900e2556aff606 Mon Sep 17 00:00:00 2001 From: Skillet Date: Thu, 2 Nov 2023 16:18:31 -0400 Subject: [PATCH 1/2] Change fallback order for layer information --- squad-server/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/squad-server/index.js b/squad-server/index.js index 490f0a7d..d0606fea 100644 --- a/squad-server/index.js +++ b/squad-server/index.js @@ -412,11 +412,18 @@ export default class SquadServer extends EventEmitter { Logger.verbose('SquadServer', 1, `Updating layer information...`); try { + let currentLayer = this.currentLayer; const currentMap = await this.rcon.getCurrentMap(); const nextMap = await this.rcon.getNextMap(); const nextMapToBeVoted = nextMap.layer === 'To be voted'; - const currentLayer = await Layers.getLayerByName(currentMap.layer); + if (currentLayer?.name !== currentMap.layer){ + const rconlayer = await Layers.getLayerByName(currentMap.layer); + if (rconlayer){ + currentLayer = rconlayer; + } + } + const nextLayer = nextMapToBeVoted ? null : await Layers.getLayerByName(nextMap.layer); if (this.layerHistory.length === 0) { @@ -447,6 +454,7 @@ export default class SquadServer extends EventEmitter { Logger.verbose('SquadServer', 1, `Updating A2S information...`); try { + const serverlayer = this.currentLayer; const data = await Gamedig.query({ type: 'squad', host: this.options.host, @@ -466,7 +474,8 @@ export default class SquadServer extends EventEmitter { reserveQueue: parseInt(data.raw.rules.ReservedQueue_i), matchTimeout: parseFloat(data.raw.rules.MatchTimeout_f), - gameVersion: data.raw.version + gameVersion: data.raw.version, + currentLayer: data.map }; this.serverName = info.serverName; @@ -482,6 +491,8 @@ export default class SquadServer extends EventEmitter { this.matchTimeout = info.matchTimeout; this.gameVersion = info.gameVersion; + this.currentLayer = info.currentLayer === serverlayer?.layerid ? this.currentLayer : await Layers.getLayerById(info.currentLayer); + this.emit('UPDATED_A2S_INFORMATION', info); } catch (err) { Logger.verbose('SquadServer', 1, 'Failed to update A2S information.', err); From ab1e6e2844aac697bd336f6ee8533a1badfff9b9 Mon Sep 17 00:00:00 2001 From: Skillet Date: Thu, 2 Nov 2023 20:12:19 -0400 Subject: [PATCH 2/2] make a2s logic easier to read and inline with rcon logic --- squad-server/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/squad-server/index.js b/squad-server/index.js index d0606fea..c7a1f189 100644 --- a/squad-server/index.js +++ b/squad-server/index.js @@ -491,7 +491,10 @@ export default class SquadServer extends EventEmitter { this.matchTimeout = info.matchTimeout; this.gameVersion = info.gameVersion; - this.currentLayer = info.currentLayer === serverlayer?.layerid ? this.currentLayer : await Layers.getLayerById(info.currentLayer); + if (info.currentLayer !== serverlayer?.layerid) { + const a2slayer = await Layers.getLayerById(info.currentLayer); + this.currentLayer = a2slayer ? a2slayer : this.currentLayer; + } this.emit('UPDATED_A2S_INFORMATION', info); } catch (err) {