Skip to content

Commit

Permalink
Merge pull request #10 from Thomas-Smyth/beta
Browse files Browse the repository at this point in the history
SquadJS v1.0.6 Release
  • Loading branch information
Thomas-Smyth authored May 18, 2020
2 parents 31c2fba + cf7cfab commit 3c9de1d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SquadJS",
"version": "1.0.5",
"version": "1.0.6",
"repository": "https://github.com/Thomas-Smyth/SquadJS.git",
"author": "Thomas Smyth <https://github.com/Thomas-Smyth>",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions plugins/discord-server-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { COPYRIGHT_MESSAGE } from 'core/config';
import { SERVER_A2S_UPDATED } from 'squad-server/events/server';

function makeEmbed(server, options) {
let players = `${server.a2sPlayerCount}`;
let players = `${server.playerCount}`;
if (server.publicQueue + server.reserveQueue > 0)
players += ` (+${server.publicQueue + server.reserveQueue})`;
players += ` / ${server.publicSlots}`;
Expand Down Expand Up @@ -82,6 +82,6 @@ export default async function plugin(server, discordClient, options = {}) {
});

server.on(SERVER_A2S_UPDATED, () => {
if(!options.disableStatus) discordClient.user.setActivity(`(${server.a2sPlayerCount}/${server.publicSlots}) ${server.currentLayer}`, { type: 'WATCHING' });
if(!options.disableStatus) discordClient.user.setActivity(`(${server.playerCount}/${server.publicSlots}) ${server.currentLayer}`, { type: 'WATCHING' });
});
}
14 changes: 8 additions & 6 deletions plugins/influxdb-log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default function influxdbLog(server, influxDB, options = {}) {

if (!influxDB)
throw new Error('InfluxDBLog must be provided with a InfluxDB connection.');

const serverID = options.overrideServerID || server.id;

let points = [];
setInterval(() => {
Expand All @@ -26,7 +28,7 @@ export default function influxdbLog(server, influxDB, options = {}) {
server.on(LOG_PARSER_SERVER_TICK_RATE, info => {
points.push({
measurement: 'ServerTickRate',
tags: { server: server.id },
tags: { server: serverID },
fields: { tick_rate: info.tickRate },
timestamp: info.time
});
Expand All @@ -35,7 +37,7 @@ export default function influxdbLog(server, influxDB, options = {}) {
server.on(SERVER_PLAYERS_UPDATED, players => {
points.push({
measurement: 'PlayerCount',
tags: { server: server.id },
tags: { server: serverID },
fields: { player_count: players.length },
timestamp: new Date()
});
Expand All @@ -44,7 +46,7 @@ export default function influxdbLog(server, influxDB, options = {}) {
server.on(LOG_PARSER_NEW_GAME, info => {
points.push({
measurement: 'Match',
tags: { server: server.id },
tags: { server: serverID },
fields: {
dlc: info.dlc,
mapClassname: info.mapClassname,
Expand All @@ -59,7 +61,7 @@ export default function influxdbLog(server, influxDB, options = {}) {
server.on(LOG_PARSER_PLAYER_WOUNDED, info => {
points.push({
measurement: 'PlayerWounded',
tags: { server: server.id },
tags: { server: serverID },
fields: {
victim: info.victim ? info.victim.steamID : null,
victimName: info.victim ? info.victim.name : null,
Expand All @@ -80,7 +82,7 @@ export default function influxdbLog(server, influxDB, options = {}) {
server.on(LOG_PARSER_PLAYER_DIED, info => {
points.push({
measurement: 'PlayerDied',
tags: { server: server.id },
tags: { server: serverID },
fields: {
victim: info.victim ? info.victim.steamID : null,
victimName: info.victim ? info.victim.name : null,
Expand All @@ -101,7 +103,7 @@ export default function influxdbLog(server, influxDB, options = {}) {
server.on(LOG_PARSER_PLAYER_REVIVED, info => {
points.push({
measurement: 'PlayerRevived',
tags: { server: server.id },
tags: { server: serverID },
fields: {
victim: info.victim ? info.victim.steamID : null,
victimName: info.victim ? info.victim.name : null,
Expand Down
16 changes: 9 additions & 7 deletions plugins/mysql-log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'squad-server/events/log-parser';
import { SERVER_PLAYERS_UPDATED } from 'squad-server/events/server';

export default function mysqlLog(server, mysqlPool) {
export default function mysqlLog(server, mysqlPool, options = {}) {
if (!server)
throw new Error(
'MySQLLog must be provided with a reference to the server.'
Expand All @@ -16,23 +16,25 @@ export default function mysqlLog(server, mysqlPool) {
if (!mysqlPool)
throw new Error('MySQLLog must be provided with a mysql Pool.');

const serverID = options.overrideServerID || server.id;

server.on(LOG_PARSER_SERVER_TICK_RATE, info => {
mysqlPool.query(
'INSERT INTO ServerTickRate(time, server, tick_rate) VALUES (?,?,?)',
[info.time, server.id, info.tickRate]
[info.time, serverID, info.tickRate]
);
});

server.on(SERVER_PLAYERS_UPDATED, players => {
mysqlPool.query(
'INSERT INTO PlayerCount(time, server, player_count) VALUES (NOW(),?,?)',
[server.id, players.length]
[serverID, players.length]
);
});

server.on(LOG_PARSER_NEW_GAME, info => {
mysqlPool.query('call NewMatch(?,?,?,?,?,?,?)', [
server.id,
serverID,
info.time,
info.dlc,
info.mapClassname,
Expand All @@ -44,7 +46,7 @@ export default function mysqlLog(server, mysqlPool) {

server.on(LOG_PARSER_PLAYER_WOUNDED, info => {
mysqlPool.query('call InsertPlayerWounded(?,?,?,?,?,?,?,?,?,?,?,?,?)', [
server.id,
serverID,
info.time,
info.victim ? info.victim.steamID : null,
info.victim ? info.victim.name : null,
Expand All @@ -62,7 +64,7 @@ export default function mysqlLog(server, mysqlPool) {

server.on(LOG_PARSER_PLAYER_DIED, info => {
mysqlPool.query('call InsertPlayerDied(?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [
server.id,
serverID,
info.time,
info.woundTime,
info.victim ? info.victim.steamID : null,
Expand All @@ -83,7 +85,7 @@ export default function mysqlLog(server, mysqlPool) {
mysqlPool.query(
'call InsertPlayerRevived(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
[
server.id,
serverID,
info.time,
info.woundTime,
info.victim ? info.victim.steamID : null,
Expand Down
1 change: 1 addition & 0 deletions squad-server/events/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const SERVER_LAYERS_UPDATED = 'SERVER_LAYERS_UPDATED';
* - maxPlayers - Maximum number of players on the server.
* - publicSlots - Maximum number of public slots.
* - reserveSlots - Maximum number of reserved slots.
* - playerCount - Player count as per A2S query.
* - publicQueue - Length of the public queue.
* - reserveQueue - Length of the reserved queue.
* - matchTimeout - Time until match ends?
Expand Down
3 changes: 2 additions & 1 deletion squad-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class Server extends EventEmitter {
this.publicSlots = parseInt(data.raw.rules.NUMPUBCONN);
this.reserveSlots = parseInt(data.raw.rules.NUMPRIVCONN);

this.a2sPlayerCount = Math.min(data.players.length, this.maxPlayers);
this.playerCount = parseInt(data.raw.rules.PlayerCount_i);
this.publicQueue = parseInt(data.raw.rules.PublicQueue_i);
this.reserveQueue = parseInt(data.raw.rules.ReservedQueue_i);

Expand All @@ -88,6 +88,7 @@ export default class Server extends EventEmitter {
maxPlayers: this.maxPlayers,
publicSlots: this.publicSlots,
reserveSlots: this.reserveSlots,
playerCount: this.playerCount,
publicQueue: this.publicQueue,
reserveQueue: this.reserveQueue,
matchTimeout: this.matchTimeout,
Expand Down
2 changes: 1 addition & 1 deletion squad-server/log-parser/rules/player-wounded.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from '../../events/log-parser.js';

export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquadTrace: \[DedicatedServer]ASQSoldier::Wound\(\): Player:(.+) KillingDamage=(?:-)*([0-9.]+) from ([A-z_0-9]+) caused by ([A-z_0-9]+)_C/,
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquadTrace: \[DedicatedServer](?:ASQSoldier::)?Wound\(\): Player:(.+) KillingDamage=(?:-)*([0-9.]+) from ([A-z_0-9]+) caused by ([A-z_0-9]+)_C/,
onMatch: async (args, logParser) => {
const data = {
...logParser.eventStore[args[3]],
Expand Down
7 changes: 5 additions & 2 deletions squad-server/rcon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export default class Rcon {
this.requestQueue = [];
this.currentMultiPacket = [];
this.ignoreNextEndPacket = false;

this.onData = this.onData.bind(this);
}

/* RCON functionality */
Expand Down Expand Up @@ -96,7 +98,7 @@ export default class Rcon {
// setup socket
this.client = new net.Socket();

this.client.on('data', this.onData.bind(this));
this.client.on('data', this.onData);

this.client.on('error', err => {
this.verbose(`Socket Error: ${err.message}`);
Expand All @@ -106,6 +108,7 @@ export default class Rcon {
this.client.on('close', async hadError => {
this.verbose(`Socket Closed. AutoReconnect: ${this.autoReconnect}`);
this.connected = false;
this.client.removeListener('data', this.onData);
if (!this.autoReconnect) return;
if (this.reconnectInterval !== null) return;
this.reconnectInterval = setInterval(async () => {
Expand Down Expand Up @@ -228,7 +231,7 @@ export default class Rcon {
this.requestQueue.push(handleAuthMultiPacket);
else this.requestQueue.push(handleMultiPacket);

this.client.on('error', reject);
this.client.once('error', reject);

// send packets
this.client.write(encodedPacket);
Expand Down

0 comments on commit 3c9de1d

Please sign in to comment.