From aef75781bc5a3317f49972065fc83fc7f53c2f6b Mon Sep 17 00:00:00 2001 From: ect0s <73128770+ect0s@users.noreply.github.com> Date: Tue, 29 Jun 2021 19:48:23 -0400 Subject: [PATCH 1/3] Added Event Handling in main server --- squad-server/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/squad-server/index.js b/squad-server/index.js index d65fa70..52b0646 100644 --- a/squad-server/index.js +++ b/squad-server/index.js @@ -288,6 +288,10 @@ export default class SquadServer extends EventEmitter { this.logParser.on('TICK_RATE', (data) => { this.emit('TICK_RATE', data); }); + + this.logParser.on('SQUAD_CREATED', (data) => { + this.emit('SQUAD_CREATED', data); + }); } async restartLogParser() { From 9e0c5cd1b146993a94dd688b9f2898c15a9e90a3 Mon Sep 17 00:00:00 2001 From: ect0s <73128770+ect0s@users.noreply.github.com> Date: Thu, 1 Jul 2021 20:22:34 -0400 Subject: [PATCH 2/3] Add Full player object to SQUAD_CREATED Added full player to SQUAD_CREATED event Refactored DiscordSquadCreated Plugin --- squad-server/index.js | 7 +++++++ squad-server/plugins/discord-squad-created.js | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/squad-server/index.js b/squad-server/index.js index 52b0646..6a8805d 100644 --- a/squad-server/index.js +++ b/squad-server/index.js @@ -290,6 +290,13 @@ export default class SquadServer extends EventEmitter { }); this.logParser.on('SQUAD_CREATED', (data) => { + + data.player = await this.getPlayerBySteamID(data.playerSteamID) + data.player.squadID = data.squadID + delete data.playerName + delete data.playerSteamID + delete data.squadID + this.emit('SQUAD_CREATED', data); }); } diff --git a/squad-server/plugins/discord-squad-created.js b/squad-server/plugins/discord-squad-created.js index f8ff6ff..76f16c8 100644 --- a/squad-server/plugins/discord-squad-created.js +++ b/squad-server/plugins/discord-squad-created.js @@ -56,7 +56,7 @@ export default class DiscordSquadCreated extends DiscordBasePlugin { fields: [ { name: 'Player', - value: info.playerName, + value: info.player.name, inline: true }, { @@ -66,7 +66,7 @@ export default class DiscordSquadCreated extends DiscordBasePlugin { }, { name: 'Squad Number & Squad Name', - value: `${info.squadID} : ${info.squadName}` + value: `${info.player.squadID} : ${info.squadName}` } ], timestamp: info.time.toISOString() @@ -75,7 +75,7 @@ export default class DiscordSquadCreated extends DiscordBasePlugin { } else { - await this.sendDiscordMessage(` \`\`\`Player: ${info.playerName}\n created Squad ${info.squadID} : ${info.squadName}\n on ${info.teamName}\`\`\` `) + await this.sendDiscordMessage(` \`\`\`Player: ${info.player.name}\n created Squad ${info.player.squadID} : ${info.squadName}\n on ${info.teamName}\`\`\` `) } } } From f472676e3edc489bc0210421caddca567c9ee93a Mon Sep 17 00:00:00 2001 From: ect0s <73128770+ect0s@users.noreply.github.com> Date: Fri, 2 Jul 2021 11:34:58 -0400 Subject: [PATCH 3/3] Added Force to getPlayerBySteamID inside SQUAD_CREATED emitter --- squad-server/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/squad-server/index.js b/squad-server/index.js index 6a8805d..360b138 100644 --- a/squad-server/index.js +++ b/squad-server/index.js @@ -291,8 +291,7 @@ export default class SquadServer extends EventEmitter { this.logParser.on('SQUAD_CREATED', (data) => { - data.player = await this.getPlayerBySteamID(data.playerSteamID) - data.player.squadID = data.squadID + data.player = await this.getPlayerBySteamID(data.playerSteamID, true) delete data.playerName delete data.playerSteamID delete data.squadID