SquadJS/squad-server/index.js

660 lines
20 KiB
JavaScript
Raw Normal View History

2020-05-15 12:42:39 -05:00
import EventEmitter from 'events';
2020-10-23 05:38:06 -05:00
import axios from 'axios';
2020-05-15 12:42:39 -05:00
2020-10-25 09:24:48 -05:00
import Logger from 'core/logger';
import { SQUADJS_API_DOMAIN } from 'core/constants';
2021-02-03 11:33:01 -06:00
import { Layers } from './layers/index.js';
2020-12-10 14:46:29 -06:00
import LogParser from './log-parser/index.js';
2020-12-10 12:51:32 -06:00
import Rcon from './rcon.js';
2020-05-15 12:42:39 -05:00
2020-10-25 09:24:48 -05:00
import { SQUADJS_VERSION } from './utils/constants.js';
2020-10-23 05:38:06 -05:00
2020-11-07 18:10:55 -06:00
import fetchAdminLists from './utils/admin-lists.js';
2020-05-15 12:42:39 -05:00
2020-10-05 12:52:01 -05:00
export default class SquadServer extends EventEmitter {
2020-05-15 12:42:39 -05:00
constructor(options = {}) {
super();
for (const option of ['host'])
2020-10-05 12:52:01 -05:00
if (!(option in options)) throw new Error(`${option} must be specified.`);
2020-05-15 12:42:39 -05:00
2020-12-06 15:21:41 -06:00
this.id = options.id;
this.options = options;
2020-05-15 12:42:39 -05:00
2020-10-05 12:52:01 -05:00
this.layerHistory = [];
2020-05-15 12:42:39 -05:00
this.layerHistoryMaxLength = options.layerHistoryMaxLength || 20;
this.players = [];
this.squads = [];
this.admins = {};
this.adminsInAdminCam = {};
2020-10-05 12:52:01 -05:00
this.plugins = [];
2020-05-15 12:42:39 -05:00
this.setupRCON();
this.setupLogParser();
this.updatePlayerList = this.updatePlayerList.bind(this);
this.updatePlayerListInterval = 30 * 1000;
this.updatePlayerListTimeout = null;
this.updateSquadList = this.updateSquadList.bind(this);
this.updateSquadListInterval = 30 * 1000;
this.updateSquadListTimeout = null;
this.updateLayerInformation = this.updateLayerInformation.bind(this);
this.updateLayerInformationInterval = 30 * 1000;
this.updateLayerInformationTimeout = null;
this.updateA2SInformation = this.updateA2SInformation.bind(this);
this.updateA2SInformationInterval = 30 * 1000;
this.updateA2SInformationTimeout = null;
2020-10-23 05:38:06 -05:00
this.pingSquadJSAPI = this.pingSquadJSAPI.bind(this);
this.pingSquadJSAPIInterval = 5 * 60 * 1000;
this.pingSquadJSAPITimeout = null;
}
2020-11-04 17:17:21 -06:00
async watch() {
2020-11-07 18:10:55 -06:00
Logger.verbose(
'SquadServer',
1,
`Beginning to watch ${this.options.host}:${this.options.queryPort}...`
);
2021-02-03 11:33:01 -06:00
await Layers.pull();
2021-01-07 14:52:55 -06:00
this.admins = await fetchAdminLists(this.options.adminLists);
2020-11-04 17:17:21 -06:00
await this.rcon.connect();
await this.logParser.watch();
await this.updateSquadList();
await this.updatePlayerList(this);
2020-11-04 17:17:21 -06:00
await this.updateLayerInformation();
await this.updateA2SInformation();
Logger.verbose('SquadServer', 1, `Watching ${this.serverName}...`);
await this.pingSquadJSAPI();
}
async unwatch() {
await this.rcon.disconnect();
await this.logParser.unwatch();
}
setupRCON() {
this.rcon = new Rcon({
2020-12-12 14:47:06 -06:00
host: this.options.rconHost || this.options.host,
port: this.options.rconPort,
password: this.options.rconPassword,
autoReconnectInterval: this.options.rconAutoReconnectInterval,
dumpRconResponsesToFile: this.options.dumpRconResponsesToFile,
passThroughPort: this.options.rconPassThroughPort,
passThrough: this.options.rconPassThrough
});
this.rcon.on('CHAT_MESSAGE', async (data) => {
data.player = await this.getPlayerBySteamID(data.steamID);
this.emit('CHAT_MESSAGE', data);
const command = data.message.match(/!([^ ]+) ?(.*)/);
if (command)
this.emit(`CHAT_COMMAND:${command[1].toLowerCase()}`, {
...data,
message: command[2].trim()
});
});
this.rcon.on('POSSESSED_ADMIN_CAMERA', async (data) => {
data.player = await this.getPlayerBySteamID(data.steamID);
this.adminsInAdminCam[data.steamID] = data.time;
this.emit('POSSESSED_ADMIN_CAMERA', data);
});
this.rcon.on('UNPOSSESSED_ADMIN_CAMERA', async (data) => {
data.player = await this.getPlayerBySteamID(data.steamID);
if (this.adminsInAdminCam[data.steamID]) {
data.duration = data.time.getTime() - this.adminsInAdminCam[data.steamID].getTime();
} else {
data.duration = 0;
}
delete this.adminsInAdminCam[data.steamID];
this.emit('UNPOSSESSED_ADMIN_CAMERA', data);
});
this.rcon.on('RCON_ERROR', (data) => {
this.emit('RCON_ERROR', data);
});
this.rcon.on('PLAYER_WARNED', async (data) => {
data.player = await this.getPlayerByName(data.name);
this.emit('PLAYER_WARNED', data);
});
this.rcon.on('PLAYER_KICKED', async (data) => {
data.player = await this.getPlayerBySteamID(data.steamID);
this.emit('PLAYER_KICKED', data);
});
this.rcon.on('PLAYER_BANNED', async (data) => {
data.player = await this.getPlayerBySteamID(data.steamID);
this.emit('PLAYER_BANNED', data);
});
this.rcon.on('SQUAD_CREATED', async (data) => {
data.player = await this.getPlayerBySteamID(data.playerSteamID, true);
delete data.playerName;
delete data.playerSteamID;
this.emit('SQUAD_CREATED', data);
});
}
async restartRCON() {
try {
await this.rcon.disconnect();
} catch (err) {
2020-10-25 08:59:57 -05:00
Logger.verbose('SquadServer', 1, 'Failed to stop RCON instance when restarting.', err);
}
2020-10-25 08:59:57 -05:00
Logger.verbose('SquadServer', 1, 'Setting up new RCON instance...');
this.setupRCON();
await this.rcon.connect();
}
setupLogParser() {
this.logParser = new LogParser(
Object.assign(this.options.ftp, {
mode: this.options.logReaderMode,
logDir: this.options.logDir,
host: this.options.ftp.host || this.options.host
})
);
2020-05-15 12:42:39 -05:00
2020-10-05 12:52:01 -05:00
this.logParser.on('ADMIN_BROADCAST', (data) => {
this.emit('ADMIN_BROADCAST', data);
});
2020-05-15 12:42:39 -05:00
2021-02-03 17:30:54 -06:00
this.logParser.on('DEPLOYABLE_DAMAGED', async (data) => {
2021-02-03 16:31:38 -06:00
data.player = await this.getPlayerByNameSuffix(data.playerSuffix);
delete data.playerSuffix;
2021-02-03 17:30:54 -06:00
this.emit('DEPLOYABLE_DAMAGED', data);
2021-02-03 16:31:38 -06:00
});
2021-02-03 11:33:01 -06:00
this.logParser.on('NEW_GAME', async (data) => {
data.layer = await Layers.getLayerByClassname(data.layerClassname);
2020-10-05 12:52:01 -05:00
2021-02-03 11:33:01 -06:00
this.layerHistory.unshift({ layer: data.layer, time: data.time });
2020-10-05 12:52:01 -05:00
this.layerHistory = this.layerHistory.slice(0, this.layerHistoryMaxLength);
2021-02-03 11:33:01 -06:00
this.currentLayer = data.layer;
await this.updateAdmins();
2020-10-05 12:52:01 -05:00
this.emit('NEW_GAME', data);
});
this.logParser.on('PLAYER_CONNECTED', async (data) => {
Logger.verbose(
'SquadServer',
1,
`Player connected ${data.playerSuffix} - SteamID: ${data.steamID} - EOSID: ${data.eosID}`
);
this.rcon.addIds(data.steamID, data.eosID);
data.player = await this.getPlayerByEOSID(data.eosID);
2020-10-05 12:52:01 -05:00
if (data.player) data.player.suffix = data.playerSuffix;
delete data.steamID;
delete data.playerSuffix;
this.emit('PLAYER_CONNECTED', data);
});
this.logParser.on('PLAYER_DISCONNECTED', async (data) => {
data.player = await this.getPlayerByEOSID(data.playerEOSID);
delete data.steamID;
this.emit('PLAYER_DISCONNECTED', data);
});
2020-10-05 12:52:01 -05:00
this.logParser.on('PLAYER_DAMAGED', async (data) => {
data.victim = await this.getPlayerByName(data.victimName);
data.attacker = await this.getPlayerByEOSID(data.attackerEOSID);
if (!data.attacker.playercontroller) data.attacker.playercontroller = data.attackerController;
if (data.victim && data.attacker) {
if (!data.victim.playercontroller) data.victim.playercontroller = data.attackerController;
2020-10-05 12:52:01 -05:00
2020-10-21 16:49:07 -05:00
data.teamkill =
data.victim.teamID === data.attacker.teamID &&
data.victim.steamID !== data.attacker.steamID;
}
2020-10-05 12:52:01 -05:00
delete data.victimName;
delete data.attackerName;
this.emit('PLAYER_DAMAGED', data);
});
this.logParser.on('PLAYER_WOUNDED', async (data) => {
data.victim = await this.getPlayerByName(data.victimName);
data.attacker = await this.getPlayerByEOSID(data.attackerEOSID);
if (!data.attacker)
data.attacker = await this.getPlayerByController(data.attackerPlayerController);
2020-10-05 12:52:01 -05:00
2020-10-21 16:49:07 -05:00
if (data.victim && data.attacker)
data.teamkill =
data.victim.teamID === data.attacker.teamID &&
data.victim.steamID !== data.attacker.steamID;
2020-10-05 12:52:01 -05:00
delete data.victimName;
delete data.attackerName;
this.emit('PLAYER_WOUNDED', data);
if (data.teamkill) this.emit('TEAMKILL', data);
});
this.logParser.on('PLAYER_DIED', async (data) => {
data.victim = await this.getPlayerByName(data.victimName);
data.attacker = await this.getPlayerByEOSID(data.attackerEOSID);
if (!data.attacker)
data.attacker = await this.getPlayerByController(data.attackerPlayerController);
2020-10-05 12:52:01 -05:00
2020-10-21 16:49:07 -05:00
if (data.victim && data.attacker)
data.teamkill =
data.victim.teamID === data.attacker.teamID &&
data.victim.steamID !== data.attacker.steamID;
2020-10-05 12:52:01 -05:00
delete data.victimName;
delete data.attackerName;
this.emit('PLAYER_DIED', data);
});
this.logParser.on('PLAYER_REVIVED', async (data) => {
data.victim = await this.getPlayerByEOSID(data.victimEOSID);
data.attacker = await this.getPlayerByEOSID(data.attackerEOSID);
data.reviver = await this.getPlayerByEOSID(data.reviverEOSID);
2020-10-05 12:52:01 -05:00
delete data.victimName;
delete data.attackerName;
delete data.reviverName;
this.emit('PLAYER_REVIVED', data);
});
this.logParser.on('PLAYER_POSSESS', async (data) => {
data.player = await this.getPlayerByEOSID(data.playerEOSID);
2020-10-05 12:52:01 -05:00
if (data.player) data.player.possessClassname = data.possessClassname;
delete data.playerSuffix;
this.emit('PLAYER_POSSESS', data);
});
this.logParser.on('PLAYER_UNPOSSESS', async (data) => {
data.player = await this.getPlayerByEOSID(data.playerEOSID);
2020-10-05 12:52:01 -05:00
delete data.playerSuffix;
this.emit('PLAYER_UNPOSSESS', data);
});
this.logParser.on('ROUND_ENDED', async (data) => {
this.emit('ROUND_ENDED', data);
});
2020-10-05 12:52:01 -05:00
this.logParser.on('TICK_RATE', (data) => {
this.emit('TICK_RATE', data);
});
this.logParser.on('CLIENT_EXTERNAL_ACCOUNT_INFO', (data) => {
this.rcon.addIds(data.steamID, data.eosID);
});
// this.logParser.on('CLIENT_CONNECTED', (data) => {
// Logger.verbose("SquadServer", 1, `Client connected. Connection: ${data.connection} - SteamID: ${data.steamID}`)
// })
// this.logParser.on('CLIENT_LOGIN_REQUEST', (data) => {
// Logger.verbose("SquadServer", 1, `Login request. ChainID: ${data.chainID} - Suffix: ${data.suffix} - EOSID: ${data.eosID}`)
// })
// this.logParser.on('RESOLVED_EOS_ID', (data) => {
// Logger.verbose("SquadServer", 1, `Resolved EOSID. ChainID: ${data.chainID} - Suffix: ${data.suffix} - EOSID: ${data.eosID}`)
// })
// this.logParser.on('ADDING_CLIENT_CONNECTION', (data) => {
// Logger.verbose("SquadServer", 1, `Adding client connection`, data)
// })
}
2020-10-05 12:52:01 -05:00
async restartLogParser() {
try {
await this.logParser.unwatch();
} catch (err) {
2020-10-25 08:59:57 -05:00
Logger.verbose('SquadServer', 1, 'Failed to stop LogParser instance when restarting.', err);
}
2020-05-15 12:42:39 -05:00
2020-10-25 08:59:57 -05:00
Logger.verbose('SquadServer', 1, 'Setting up new LogParser instance...');
this.setupLogParser();
await this.logParser.watch();
2020-05-15 12:42:39 -05:00
}
getAdminPermsBySteamID(steamID) {
return this.admins[steamID];
2020-11-07 17:43:08 -06:00
}
2020-11-07 18:10:55 -06:00
getAdminsWithPermission(perm) {
2020-11-07 18:10:55 -06:00
const ret = [];
for (const [steamID, perms] of Object.entries(this.admins)) {
if (perm in perms) ret.push(steamID);
2020-10-27 16:31:05 -05:00
}
2020-11-07 18:10:55 -06:00
return ret;
2020-10-27 16:31:05 -05:00
}
async updateAdmins() {
this.admins = await fetchAdminLists(this.options.adminLists);
}
2020-10-05 12:52:01 -05:00
async updatePlayerList() {
if (this.updatePlayerListTimeout) clearTimeout(this.updatePlayerListTimeout);
2020-05-15 12:42:39 -05:00
2020-11-09 15:10:32 -06:00
Logger.verbose('SquadServer', 1, `Updating player list...`);
try {
const oldPlayerInfo = {};
for (const player of this.players) {
oldPlayerInfo[player.steamID] = player;
}
const players = [];
for (const player of await this.rcon.getListPlayers(this))
players.push({
...oldPlayerInfo[player.steamID],
...player,
playercontroller: this.logParser.eventStore.players[player.steamID]
? this.logParser.eventStore.players[player.steamID].controller
: null,
squad: await this.getSquadByID(player.teamID, player.squadID)
});
this.players = players;
for (const player of this.players) {
if (typeof oldPlayerInfo[player.steamID] === 'undefined') continue;
if (player.teamID !== oldPlayerInfo[player.steamID].teamID)
2020-11-07 18:10:55 -06:00
this.emit('PLAYER_TEAM_CHANGE', {
player: player,
oldTeamID: oldPlayerInfo[player.steamID].teamID,
2020-12-08 10:40:56 -06:00
newTeamID: player.teamID
2020-11-07 18:10:55 -06:00
});
if (player.squadID !== oldPlayerInfo[player.steamID].squadID)
2020-12-08 10:40:56 -06:00
this.emit('PLAYER_SQUAD_CHANGE', {
player: player,
oldSquadID: oldPlayerInfo[player.steamID].squadID,
2020-12-08 10:40:56 -06:00
newSquadID: player.squadID
});
}
2020-12-08 06:17:02 -06:00
2020-12-06 15:45:06 -06:00
this.emit('UPDATED_PLAYER_INFORMATION');
} catch (err) {
2020-10-25 08:59:57 -05:00
Logger.verbose('SquadServer', 1, 'Failed to update player list.', err);
2020-05-15 12:42:39 -05:00
}
2020-11-09 15:10:32 -06:00
Logger.verbose('SquadServer', 1, `Updated player list.`);
2020-10-05 12:52:01 -05:00
this.updatePlayerListTimeout = setTimeout(this.updatePlayerList, this.updatePlayerListInterval);
}
async updateSquadList() {
if (this.updateSquadListTimeout) clearTimeout(this.updateSquadListTimeout);
Logger.verbose('SquadServer', 1, `Updating squad list...`);
try {
this.squads = await this.rcon.getSquads();
} catch (err) {
Logger.verbose('SquadServer', 1, 'Failed to update squad list.', err);
}
Logger.verbose('SquadServer', 1, `Updated squad list.`);
this.updateSquadListTimeout = setTimeout(this.updateSquadList, this.updateSquadListInterval);
}
2020-10-05 12:52:01 -05:00
async updateLayerInformation() {
if (this.updateLayerInformationTimeout) clearTimeout(this.updateLayerInformationTimeout);
2020-11-09 15:10:32 -06:00
Logger.verbose('SquadServer', 1, `Updating layer information...`);
try {
2021-02-03 11:33:01 -06:00
const currentMap = await this.rcon.getCurrentMap();
const nextMap = await this.rcon.getNextMap();
2021-03-08 09:07:18 -06:00
const nextMapToBeVoted = nextMap.layer === 'To be voted';
2020-10-05 12:52:01 -05:00
2021-02-03 11:33:01 -06:00
const currentLayer = await Layers.getLayerByName(currentMap.layer);
const nextLayer = nextMapToBeVoted ? null : await Layers.getLayerByName(nextMap.layer);
2020-10-05 12:52:01 -05:00
2021-02-03 11:33:01 -06:00
if (this.layerHistory.length === 0) {
this.layerHistory.unshift({ layer: currentLayer, time: Date.now() });
this.layerHistory = this.layerHistory.slice(0, this.layerHistoryMaxLength);
}
2020-05-15 12:42:39 -05:00
2021-02-03 11:33:01 -06:00
this.currentLayer = currentLayer;
this.nextLayer = nextLayer;
this.nextLayerToBeVoted = nextMapToBeVoted;
2020-12-06 15:45:06 -06:00
this.emit('UPDATED_LAYER_INFORMATION');
} catch (err) {
2020-10-25 08:59:57 -05:00
Logger.verbose('SquadServer', 1, 'Failed to update layer information.', err);
}
2020-10-05 12:52:01 -05:00
2020-11-09 15:10:32 -06:00
Logger.verbose('SquadServer', 1, `Updated layer information.`);
2020-10-05 12:52:01 -05:00
this.updateLayerInformationTimeout = setTimeout(
this.updateLayerInformation,
this.updateLayerInformationInterval
);
}
async updateA2SInformation() {
if (this.updateA2SInformationTimeout) clearTimeout(this.updateA2SInformationTimeout);
2020-11-09 15:10:32 -06:00
Logger.verbose('SquadServer', 1, `Updating A2S information...`);
try {
// const data = await Gamedig.query({
// type: 'squad',
// host: this.options.host,
// port: this.options.queryPort
// });
const rawData = await this.rcon.execute(`ShowServerInfo`);
Logger.verbose('SquadServer', 3, `A2S raw data`, rawData);
const data = JSON.parse(rawData);
Logger.verbose('SquadServer', 2, `A2S data`, JSON.data);
// Logger.verbose("SquadServer", 1, `A2S data`, JSON.stringify(data, null, 2))
2020-10-05 12:52:01 -05:00
const info = {
raw: data,
serverName: data.ServerName_s,
2020-10-05 12:52:01 -05:00
maxPlayers: parseInt(data.MaxPlayers),
publicQueueLimit: parseInt(data.PublicQueueLimit_I),
reserveSlots: parseInt(data.PlayerReserveCount_I),
2020-10-05 12:52:01 -05:00
playerCount: parseInt(data.PlayerCount_I),
2023-12-12 17:18:35 -06:00
a2sPlayerCount: parseInt(data.PlayerCount_I),
publicQueue: parseInt(data.PublicQueue_I),
reserveQueue: parseInt(data.ReservedQueue_I),
2020-10-05 12:52:01 -05:00
currentLayer: data.MapName_s,
nextLayer: data.NextLayer_s,
teamOne: data.TeamOne_s?.replace(new RegExp(data.MapName_s, 'i'), '') || '',
teamTwo: data.TeamTwo_s?.replace(new RegExp(data.MapName_s, 'i'), '') || '',
matchTimeout: parseFloat(data.MatchTimeout_d),
gameVersion: data.GameVersion_s
};
2020-12-06 15:45:06 -06:00
this.serverName = info.serverName;
this.maxPlayers = info.maxPlayers;
this.publicSlots = info.maxPlayers - info.reserveSlots;
this.reserveSlots = info.reserveSlots;
this.a2sPlayerCount = info.playerCount;
this.publicQueue = info.publicQueue;
this.reserveQueue = info.reserveQueue;
this.matchTimeout = info.matchTimeout;
this.gameVersion = info.gameVersion;
this.emit('UPDATED_A2S_INFORMATION', info);
this.emit('UPDATED_SERVER_INFORMATION', info);
} catch (err) {
2020-10-25 08:59:57 -05:00
Logger.verbose('SquadServer', 1, 'Failed to update A2S information.', err);
}
2020-10-05 12:52:01 -05:00
2020-11-09 15:10:32 -06:00
Logger.verbose('SquadServer', 1, `Updated A2S information.`);
2020-10-05 12:52:01 -05:00
this.updateA2SInformationTimeout = setTimeout(
this.updateA2SInformation,
this.updateA2SInformationInterval
);
}
2020-12-08 10:40:56 -06:00
async getPlayerByCondition(condition, forceUpdate = false, retry = true) {
2020-10-05 12:52:01 -05:00
let matches;
2020-12-08 10:40:56 -06:00
if (!forceUpdate) {
matches = this.players.filter(condition);
if (matches.length === 1) return matches[0];
2020-10-05 12:52:01 -05:00
2020-12-08 10:40:56 -06:00
if (!retry) return null;
}
2020-10-05 12:52:01 -05:00
await this.updatePlayerList();
matches = this.players.filter(condition);
if (matches.length === 1) return matches[0];
2020-10-05 12:52:01 -05:00
return null;
2020-05-15 12:42:39 -05:00
}
async getSquadByCondition(condition, forceUpdate = false, retry = true) {
let matches;
if (!forceUpdate) {
matches = this.squads.filter(condition);
if (matches.length === 1) return matches[0];
if (!retry) return null;
}
await this.updateSquadList();
matches = this.squads.filter(condition);
if (matches.length === 1) return matches[0];
return null;
}
2021-03-07 13:43:45 -06:00
async getSquadByID(teamID, squadID) {
if (squadID === null) return null;
return this.getSquadByCondition(
(squad) => squad.teamID === teamID && squad.squadID === squadID
);
}
2020-12-08 10:40:56 -06:00
async getPlayerBySteamID(steamID, forceUpdate) {
return this.getPlayerByCondition((player) => player.steamID === steamID, forceUpdate);
2020-10-05 12:52:01 -05:00
}
async getPlayerByEOSID(eosID, forceUpdate) {
return this.getPlayerByCondition((player) => player.EOSID === eosID, forceUpdate);
}
2020-05-15 12:42:39 -05:00
2020-12-08 10:40:56 -06:00
async getPlayerByName(name, forceUpdate) {
return this.getPlayerByCondition((player) => player.name === name, forceUpdate);
2020-10-05 12:52:01 -05:00
}
2020-12-08 10:40:56 -06:00
async getPlayerByNameSuffix(suffix, forceUpdate) {
return this.getPlayerByCondition((player) => player.suffix === suffix, forceUpdate, false);
2020-10-05 12:52:01 -05:00
}
async getPlayerByController(controller, forceUpdate) {
return this.getPlayerByCondition(
(player) => player.playercontroller === controller,
forceUpdate
);
}
2020-11-04 17:17:21 -06:00
async pingSquadJSAPI() {
if (this.pingSquadJSAPITimeout) clearTimeout(this.pingSquadJSAPITimeout);
2020-10-05 12:52:01 -05:00
2020-11-04 17:17:21 -06:00
Logger.verbose('SquadServer', 1, 'Pinging SquadJS API...');
2020-05-15 12:42:39 -05:00
2021-01-09 08:51:59 -06:00
const payload = {
// Send information about the server.
2020-11-04 17:17:21 -06:00
server: {
host: this.options.host,
queryPort: this.options.queryPort,
2021-01-09 08:51:59 -06:00
name: this.serverName,
playerCount: this.a2sPlayerCount + this.publicQueue + this.reserveQueue
2020-11-04 17:17:21 -06:00
},
2020-10-14 11:01:19 -05:00
2021-01-09 08:51:59 -06:00
// Send information about SquadJS.
squadjs: {
version: SQUADJS_VERSION,
logReaderMode: this.options.logReaderMode,
2020-10-23 05:38:06 -05:00
2021-01-09 08:51:59 -06:00
// Send the plugin config so we can see what plugins they're using (none of the config is sensitive).
2021-01-09 09:16:00 -06:00
plugins: this.plugins.map((plugin) => ({
...plugin.rawOptions,
plugin: plugin.constructor.name
}))
2021-01-09 08:51:59 -06:00
}
2020-11-04 17:17:21 -06:00
};
2020-10-05 12:52:01 -05:00
2020-11-04 17:17:21 -06:00
try {
2021-01-09 08:51:59 -06:00
const { data } = await axios.post(SQUADJS_API_DOMAIN + '/api/v1/ping', payload);
2020-11-04 17:17:21 -06:00
if (data.error)
Logger.verbose(
'SquadServer',
1,
`Successfully pinged the SquadJS API. Got back error: ${data.error}`
);
else
Logger.verbose(
'SquadServer',
1,
`Successfully pinged the SquadJS API. Got back message: ${data.message}`
);
} catch (err) {
2021-02-26 04:56:26 -06:00
Logger.verbose('SquadServer', 1, 'Failed to ping the SquadJS API: ', err.message);
2020-11-04 17:17:21 -06:00
}
this.pingSquadJSAPITimeout = setTimeout(this.pingSquadJSAPI, this.pingSquadJSAPIInterval);
2020-10-05 12:52:01 -05:00
}
2020-05-15 12:42:39 -05:00
}