Skip to content

Commit

Permalink
Initial constructPartial
Browse files Browse the repository at this point in the history
Initial constructPartial

Modded maps fail the lookup in Layers.getLayerBy(...)

This attempts to build a partial layer from A2S and RCON.

NEW_GAME may require a short delay as the server transitions maps.

Update index.js
  • Loading branch information
ect0s committed Nov 28, 2021
1 parent f34426d commit fd6ca29
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
41 changes: 34 additions & 7 deletions squad-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ export default class SquadServer extends EventEmitter {
});

this.logParser.on('NEW_GAME', async (data) => {
data.layer = await Layers.getLayerByClassname(data.layerClassname);
data.layer =
(await Layers.getLayerByClassname(data.layerClassname)) ||
(await this.constructPartialLayer());

this.layerHistory.unshift({ layer: data.layer, time: data.time });
this.layerHistory = this.layerHistory.slice(0, this.layerHistoryMaxLength);
Expand Down Expand Up @@ -290,11 +292,10 @@ export default class SquadServer extends EventEmitter {
});

this.logParser.on('SQUAD_CREATED', async (data) => {

data.player = await this.getPlayerBySteamID(data.playerSteamID, true)
delete data.playerName
delete data.playerSteamID
delete data.squadID
data.player = await this.getPlayerBySteamID(data.playerSteamID, true);
delete data.playerName;
delete data.playerSteamID;
delete data.squadID;

this.emit('SQUAD_CREATED', data);
});
Expand Down Expand Up @@ -397,7 +398,8 @@ export default class SquadServer extends EventEmitter {
const nextMap = await this.rcon.getNextMap();
const nextMapToBeVoted = nextMap.layer === 'To be voted';

const currentLayer = await Layers.getLayerByName(currentMap.layer);
const currentLayer =
(await Layers.getLayerByName(currentMap.layer)) || (await this.constructPartialLayer());
const nextLayer = nextMapToBeVoted ? null : await Layers.getLayerByName(nextMap.layer);

if (this.layerHistory.length === 0) {
Expand Down Expand Up @@ -580,4 +582,29 @@ export default class SquadServer extends EventEmitter {

this.pingSquadJSAPITimeout = setTimeout(this.pingSquadJSAPI, this.pingSquadJSAPIInterval);
}

async constructPartialLayer() {
Logger.verbose('SquadServer', 1, `Constructing Partial Layer...`);
try {
const rconData = await this.server.getCurrentMap();
const gamedigData = await Gamedig.query({
type: 'squad',
host: this.options.host,
port: this.options.queryPort
});

const layer = {
name: rconData.layer, // "Al Basrah AAS V1"
classname: rconData.level, // "Al Basrah"
layerid: gamedigData.map, // "Al_Basrah_AAS_V1"
map: {
name: rconData.layer // "Al Basrah AAS V1"
},
gamemode: gamedigData.raw.GameMode_s // "AAS"
};
return layer;
} catch (err) {
Logger.verbose('SquadServer', 1, `Failed to Construct Partial Layer`, err);
}
}
}
2 changes: 1 addition & 1 deletion squad-server/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default class Layer {
constructor(data) {
this.name = data.Name;
this.classname = data.levelName;
this.layerid = data.rawName
this.layerid = data.rawName;
this.map = {
name: data.mapName
};
Expand Down

0 comments on commit fd6ca29

Please sign in to comment.