Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into RCON-PacketParser
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/rcon.js
  • Loading branch information
steelskillet committed Dec 28, 2023
2 parents 6433958 + ae2441d commit a1ea6d1
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ Interested in creating your own plugin? [See more here](./squad-server/plugins/r
<h6>Description</h6>
<p>Message SquadJS will send to players warning them they will be kicked</p>
<h6>Default</h6>
<pre><code>Join a squad, you are are unassigned and will be kicked</code></pre></li>
<pre><code>Join a squad, you are unassigned and will be kicked</code></pre></li>
<li><h4>kickMessage</h4>
<h6>Description</h6>
<p>Message to send to players when they are kicked</p>
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{
"plugin": "AutoKickUnassigned",
"enabled": true,
"warningMessage": "Join a squad, you are are unassigned and will be kicked",
"warningMessage": "Join a squad, you are unassigned and will be kicked",
"kickMessage": "Unassigned - automatically removed",
"frequencyOfWarnings": 30,
"unassignedTimer": 360,
Expand Down
12 changes: 11 additions & 1 deletion core/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ class Logger {
constructor() {
this.verboseness = {};
this.colors = {};
this.includeTimestamps = false;
}

verbose(module, verboseness, message, ...extras) {
let colorFunc = chalk[this.colors[module] || 'white'];
if (typeof colorFunc !== 'function') colorFunc = chalk.white;

if ((this.verboseness[module] || 1) >= verboseness)
console.log(`[${colorFunc(module)}][${verboseness}] ${message}`, ...extras);
console.log(
`${this.includeTimestamps ? '[' + new Date().toISOString() + ']' : ''}[${colorFunc(
module
)}][${verboseness}] ${message}`,
...extras
);
}

setVerboseness(module, verboseness) {
Expand All @@ -21,6 +27,10 @@ class Logger {
setColor(module, color) {
this.colors[module] = color;
}

setTimeStamps(option) {
this.includeTimestamps = option;
}
}

export default new Logger();
3 changes: 3 additions & 0 deletions core/rcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ export default class Rcon extends EventEmitter {

if (type === SERVERDATA_AUTH) {
this.callbackIds.push({ id: this.count, cmd: body });
Logger.verbose('RCON', 2, `Writing Auth Packet`);
Logger.verbose('RCON', 4, `Writing packet with type "${type}" and body "${body}".`);
this.responseCallbackQueue.push(() => {});
this.responseCallbackQueue.push((decodedPacket) => {
this.client.removeListener('error', onError);
Expand All @@ -350,6 +352,7 @@ export default class Rcon extends EventEmitter {
}
});
} else {
Logger.verbose('RCON', 2, `Writing packet with type "${type}" and body "${body}".`);
this.callbackIds.push({ id: this.count, cmd: body });
this.responseCallbackQueue.push((response) => {
this.client.removeListener('error', onError);
Expand Down
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": "3.6.1",
"version": "3.8.2",
"repository": "https://github.com/Team-Silver-Sphere/SquadJS.git",
"author": "Thomas Smyth <https://github.com/Thomas-Smyth>",
"license": "BSL-1.0",
Expand Down
2 changes: 2 additions & 0 deletions squad-server/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default class SquadServerFactory {
static async buildFromConfig(config) {
Logger.setTimeStamps(config.logger.timestamps ? config.logger.timestamps : false);

const plugins = await Plugins.getPlugins();

for (const plugin of Object.keys(plugins)) {
Expand Down
15 changes: 15 additions & 0 deletions squad-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ export default class SquadServer extends EventEmitter {
this.logParser.on('PLAYER_WOUNDED', async (data) => {
data.victim = await this.getPlayerByName(data.victimName);
data.attacker = await this.getPlayerByName(data.attackerName);
if (!data.attacker)
data.attacker = await this.getPlayerByController(data.attackerPlayerController);

if (data.victim && data.attacker)
data.teamkill =
Expand All @@ -257,6 +259,9 @@ export default class SquadServer extends EventEmitter {

this.logParser.on('PLAYER_DIED', async (data) => {
data.victim = await this.getPlayerByName(data.victimName);
data.attacker = await this.getPlayerByName(data.attackerName);
if (!data.attacker)
data.attacker = await this.getPlayerByController(data.attackerPlayerController);

if (data.victim && data.attacker)
data.teamkill =
Expand Down Expand Up @@ -351,6 +356,9 @@ export default class SquadServer extends EventEmitter {
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)
});

Expand Down Expand Up @@ -542,6 +550,13 @@ export default class SquadServer extends EventEmitter {
return this.getPlayerByCondition((player) => player.suffix === suffix, forceUpdate, false);
}

async getPlayerByController(controller, forceUpdate) {
return this.getPlayerByCondition(
(player) => player.playercontroller === controller,
forceUpdate
);
}

async pingSquadJSAPI() {
if (this.pingSquadJSAPITimeout) clearTimeout(this.pingSquadJSAPITimeout);

Expand Down
2 changes: 1 addition & 1 deletion squad-server/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class Layer {
respawnDelay: vehicle.respawnTime
})),
numberOfTanks: (data[t].vehicles || []).filter((v) => {
return v.icon.match(/tank/);
return v.icon.match(/_tank/);
}).length,
numberOfHelicopters: (data[t].vehicles || []).filter((v) => {
return v.icon.match(/helo/);
Expand Down
2 changes: 1 addition & 1 deletion squad-server/layers/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Layers {

Logger.verbose('Layers', 1, 'Pulling layers...');
const response = await axios.get(
'https://raw.githubusercontent.com/Squad-Wiki-Editorial/squad-wiki-pipeline-map-data/master/completed_output/_Current%20Version/finished.json'
'https://raw.githubusercontent.com/Squad-Wiki/squad-wiki-pipeline-map-data/master/completed_output/_Current%20Version/finished.json'
);

for (const layer of response.data.Maps) {
Expand Down
2 changes: 1 addition & 1 deletion squad-server/log-parser/player-disconnected.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
regex:
/^\[([0-9.:-]+)]\[([ 0-9]*)]LogNet: UNetConnection::Close: \[UNetConnection\] RemoteAddr: ([0-9]{17}):[0-9]+, Name: SteamNetConnection_[0-9]+, Driver: GameNetDriver SteamNetDriver_[0-9]+, IsServer: YES, PC: (BP_PlayerController_C_[0-9]+), Owner: BP_PlayerController_C_[0-9]+, UniqueId: Steam:UNKNOWN \[.*\], Channels: [0-9]+, Time: [0-9.:-]+/,
/^\[([0-9.:-]+)]\[([ 0-9]*)]LogNet: UChannel::Close: Sending CloseBunch\. ChIndex == [0-9]+\. Name: \[UChannel\] ChIndex: [0-9]+, Closing: [0-9]+ \[UNetConnection\] RemoteAddr: ([0-9]{17}):[0-9]+, Name: SteamNetConnection_[0-9]+, Driver: GameNetDriver SteamNetDriver_[0-9]+, IsServer: YES, PC: ([^ ]+PlayerController_C_[0-9]+), Owner: [^ ]+PlayerController_C_[0-9]+/,
onMatch: (args, logParser) => {
const data = {
raw: args[0],
Expand Down
3 changes: 2 additions & 1 deletion squad-server/log-parser/player-possess.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default {
time: args[1],
chainID: args[2],
playerSuffix: args[3],
possessClassname: args[4]
possessClassname: args[4],
pawn: args[5]
};

logParser.eventStore.session[args[3]] = args[2];
Expand Down
4 changes: 2 additions & 2 deletions squad-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"pg": "^8.5.1",
"pg-hstore": "^2.3.3",
"sequelize": "^6.3.5",
"socket.io": "^3.1.2",
"socket.io": "^4.5.4",
"sqlite3": "^5.0.0",
"tedious": "^9.2.1",
"tedious": "^15.1.2",
"tinygradient": "^1.1.2"
},
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion squad-server/plugins/auto-kick-unassigned.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class AutoKickUnassigned extends BasePlugin {
warningMessage: {
required: false,
description: 'Message SquadJS will send to players warning them they will be kicked',
default: 'Join a squad, you are are unassigned and will be kicked'
default: 'Join a squad, you are unassigned and will be kicked'
},
kickMessage: {
required: false,
Expand Down
16 changes: 15 additions & 1 deletion squad-server/plugins/discord-base-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,24 @@ export default class DiscordBasePlugin extends BasePlugin {
}

async prepareToMount() {
this.channel = await this.options.discordClient.channels.fetch(this.options.channelID);
try {
this.channel = await this.options.discordClient.channels.fetch(this.options.channelID);
} catch (error) {
this.channel = null;
this.verbose(
1,
`Could not fetch Discord channel with channelID "${this.options.channelID}". Error: ${error.message}`
);
this.verbose(2, `${error.stack}`);
}
}

async sendDiscordMessage(message) {
if (!this.channel) {
this.verbose(1, `Could not send Discord Message. Channel not initialized.`);
return;
}

if (typeof message === 'object' && 'embed' in message)
message.embed.footer = message.embed.footer || { text: COPYRIGHT_MESSAGE };

Expand Down
16 changes: 12 additions & 4 deletions squad-server/rcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ export default class SquadRcon extends Rcon {

const players = [];

if (!response || response.length < 1) return players;

for (const line of response.split('\n')) {
const match = line.match(
/ID: ([0-9]+) \| SteamID: ([0-9]{17}) \| Name: (.+) \| Team ID: ([0-9]+) \| Squad ID: ([0-9]+|N\/A)/
/ID: ([0-9]+) \| SteamID: ([0-9]{17}) \| Name: (.+) \| Team ID: ([0-9]+) \| Squad ID: ([0-9]+|N\/A) \| Is Leader: (True|False) \| Role: ([A-Za-z0-9_]*)\b/
);
if (!match) continue;

Expand All @@ -150,7 +152,9 @@ export default class SquadRcon extends Rcon {
steamID: match[2],
name: match[3],
teamID: match[4],
squadID: match[5] !== 'N/A' ? match[5] : null
squadID: match[5] !== 'N/A' ? match[5] : null,
isLeader: match[6] === 'True',
role: match[7]
});
}

Expand All @@ -164,21 +168,25 @@ export default class SquadRcon extends Rcon {
let teamName;
let teamID;

if (!responseSquad || responseSquad.length < 1) return squads;

for (const line of responseSquad.split('\n')) {
const match = line.match(
/ID: ([0-9]+) \| Name: (.+) \| Size: ([0-9]+) \| Locked: (True|False)/
/ID: ([0-9]+) \| Name: (.+) \| Size: ([0-9]+) \| Locked: (True|False) \| Creator Name: (.+) \| Creator Steam ID: ([0-9]{17})/
);
const matchSide = line.match(/Team ID: (1|2) \((.+)\)/);
if (matchSide) {
teamID = matchSide[1];
teamName = matchSide[2];
}
if (!match) continue;
await squads.push({
squads.push({
squadID: match[1],
squadName: match[2],
size: match[3],
locked: match[4],
creatorName: match[5],
creatorSteamID: match[6],
teamID: teamID,
teamName: teamName
});
Expand Down

0 comments on commit a1ea6d1

Please sign in to comment.