Skip to content
Open
231 changes: 178 additions & 53 deletions README.md

Large diffs are not rendered by default.

46 changes: 31 additions & 15 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@
"plugin": "CBLInfo",
"enabled": true,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"embedInfo": {
"clan": "",
"iconURL": "https://communitybanlist.com/static/media/cbl-logo.caf6584e.png",
"url": "https://communitybanlist.com/"
},
"threshold": 6
},
{
Expand All @@ -87,21 +92,30 @@
"plugin": "DiscordAdminBroadcast",
"enabled": false,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"color": 16761867
},
{
"plugin": "DiscordAdminCamLogs",
"enabled": false,
"discordClient": "discord",
"channelID": "",
"color": 16761867
"channelIDs": [],
"colors": {
"entry": 2202966,
"exit": 15416641
},
"embedInfo": {
"clan": "SquadJS ",
"name": "Admin Camera",
"iconURL": null,
"url": null
}
},
{
"plugin": "DiscordAdminRequest",
"enabled": true,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"ignoreChats": [],
"ignorePhrases": [],
"command": "admin",
Expand All @@ -115,7 +129,7 @@
"plugin": "DiscordChat",
"enabled": true,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"chatColors": {},
"color": 16761867,
"ignoreChats": [
Expand All @@ -126,21 +140,21 @@
"plugin": "DiscordDebug",
"enabled": false,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"events": []
},
{
"plugin": "DiscordFOBHABExplosionDamage",
"enabled": true,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"color": 16761867
},
{
"plugin": "DiscordKillFeed",
"enabled": false,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"color": 16761867,
"disableCBL": false
},
Expand All @@ -149,28 +163,28 @@
"enabled": true,
"discordClient": "discord",
"command": "!placeholder",
"channelID": ""
"channelIDs": []
},
{
"plugin": "DiscordRcon",
"enabled": false,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"permissions": {},
"prependAdminNameInBroadcast": false
},
{
"plugin": "DiscordRoundWinner",
"enabled": true,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"color": 16761867
},
{
"plugin": "DiscordRoundEnded",
"enabled": true,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"color": 16761867
},
{
Expand All @@ -187,7 +201,7 @@
"plugin": "DiscordSquadCreated",
"enabled": false,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"color": 16761867,
"useEmbed": true
},
Expand All @@ -201,7 +215,7 @@
"plugin": "DiscordTeamkill",
"enabled": true,
"discordClient": "discord",
"channelID": "",
"channelIDs": [],
"color": 16761867,
"disableCBL": false
},
Expand Down Expand Up @@ -248,6 +262,8 @@
"RCON": 1
},
"colors": {
"DiscordJS": "cyanBright",
"Err": "redBright",
"SquadServer": "yellowBright",
"SquadServerFactory": "yellowBright",
"LogParser": "blueBright",
Expand Down
31 changes: 19 additions & 12 deletions core/log-parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Logger from '../logger.js';
import TailLogReader from './log-readers/tail.js';
import FTPLogReader from './log-readers/ftp.js';

const addedLines = [];

export default class LogParser extends EventEmitter {
constructor(filename = 'filename.log', options = {}) {
super();
Expand Down Expand Up @@ -45,25 +47,28 @@ export default class LogParser extends EventEmitter {

async processLine(line) {
Logger.verbose('LogParser', 4, `Matching on line: ${line}`);

for (const rule of this.getRules()) {
let i = this.getRules().length;
while (i--) {
const rule = this.getRules()[i];
const match = line.match(rule.regex);
if (!match) continue;
addedLines.push({ rule, match });
}
this.linesPerMinute += 1;
this.onLine(addedLines);
addedLines.length = 0;
}

onLine(addedLine) {
for (const ad of addedLine) {
const { rule, match } = ad;
Logger.verbose('LogParser', 3, `Matched on line: ${match[0]}`);

match[1] = moment.utc(match[1], 'YYYY.MM.DD-hh.mm.ss:SSS').toDate();
match[2] = parseInt(match[2]);

rule.onMatch(match, this);

this.matchingLinesPerMinute++;
this.matchingLatency += Date.now() - match[1];

break;
this.matchingLinesPerMinute += 1;
this.matchingLatency += Number(Date.now()) - match[1];
}

this.linesPerMinute++;
}

// manage cleanup disconnected players, session data.
Expand Down Expand Up @@ -100,7 +105,9 @@ export default class LogParser extends EventEmitter {
} lines per minute | Matching lines per minute: ${
this.matchingLinesPerMinute
} matching lines per minute | Average matching latency: ${
this.matchingLatency / this.matchingLinesPerMinute
Number.isNaN(this.matchingLatency / this.matchingLinesPerMinute)
? 0
: this.matchingLatency / this.matchingLinesPerMinute
}ms`
);
this.linesPerMinute = 0;
Expand Down
8 changes: 4 additions & 4 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"./rcon": "./rcon.js"
},
"dependencies": {
"async": "^3.2.0",
"chalk": "^4.1.0",
"async": "^3.2.4",
"chalk": "^5.2.0",
"ftp-tail": "^1.1.1",
"moment": "^2.29.1",
"tail": "^2.0.4"
"moment": "^2.29.4",
"tail": "^2.2.6"
}
}
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
"squad-server": "1.0.0"
},
"devDependencies": {
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-config-standard": "^16.0.2",
"eslint": "^7.32.0",
"eslint-config-prettier": "^7.2.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-promise": "^4.3.1",
"eslint-plugin-standard": "^5.0.0",
"husky": "^5.1.3",
"husky": "^5.2.0",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1"
}
"prettier": "^2.8.8"
},
"packageManager": "yarn@3.6.1"
}
16 changes: 14 additions & 2 deletions squad-server/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

import Discord from 'discord.js';
import { Client, Events, GatewayIntentBits } from 'discord.js';
import sequelize from 'sequelize';
import AwnAPI from './utils/awn-api.js';

Expand Down Expand Up @@ -103,7 +103,19 @@ export default class SquadServerFactory {
Logger.verbose('SquadServerFactory', 1, `Starting ${type} connector ${connectorName}...`);

if (type === 'discord') {
const connector = new Discord.Client();
if (!(typeof connectorConfig === 'string' || typeof connectorConfig === 'object')) {
throw new Error('Unknown Discord connector config type.');
}
const connector = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
connector.once(Events.ClientReady, (c) => {
Logger.verbose('DiscordJS', 1, `Logged in as ${c.user.tag}`);
});
await connector.login(connectorConfig);
return connector;
}
Expand Down
18 changes: 9 additions & 9 deletions squad-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"version": "1.0.0",
"type": "module",
"dependencies": {
"axios": "^0.21.1",
"axios": "^0.21.4",
"core": "1.0.0",
"didyoumean": "^1.2.1",
"discord.js": "^12.3.1",
"gamedig": "^2.0.20",
"graphql": "^15.4.0",
"graphql-request": "^3.4.0",
"mariadb": "^2.5.1",
"mysql2": "^2.2.5",
"discord.js": "^14.11.0",
"gamedig": "^2.0.28",
"graphql": "^15.8.0",
"graphql-request": "^3.7.0",
"mariadb": "^2.5.6",
"mysql2": "^2.3.3",
"pg": "^8.5.1",
"pg-hstore": "^2.3.3",
"sequelize": "^6.3.5",
"socket.io": "^4.5.4",
"sqlite3": "^5.0.0",
"tedious": "^15.1.2",
"sqlite3": "^5.1.6",
"tedious": "^15.1.3",
"tinygradient": "^1.1.2"
},
"exports": {
Expand Down
Loading