Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Layer finding #314

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 16 additions & 2 deletions squad-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -482,6 +491,11 @@ export default class SquadServer extends EventEmitter {
this.matchTimeout = info.matchTimeout;
this.gameVersion = info.gameVersion;

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) {
Logger.verbose('SquadServer', 1, 'Failed to update A2S information.', err);
Expand Down