Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for 'PLAYER_DISCONNECTED' race condition #321

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions squad-server/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export default class SquadServerFactory {

for (const pluginConfig of config.plugins) {
if (!pluginConfig.enabled) continue;
//ignore non JS files
if (!pluginConfig.plugin.endsWith('.js')){

// ignore non JS files
if (!pluginConfig.plugin.endsWith('.js')) {
continue;
}

Expand Down
8 changes: 6 additions & 2 deletions squad-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class SquadServer extends EventEmitter {
this.layerHistoryMaxLength = options.layerHistoryMaxLength || 20;

this.players = [];
this.oldplayers = [];

this.squads = [];

Expand Down Expand Up @@ -226,8 +227,10 @@ export default class SquadServer extends EventEmitter {

this.logParser.on('PLAYER_DISCONNECTED', async (data) => {
data.player = await this.getPlayerByEOSID(data.eosID);

delete data.steamID;
if (!data.player) {
const foundoldplayers = this.oldplayers.filter((player) => player.eosID === data.eosID);
data.player = foundoldplayers[0] ? foundoldplayers[0] : null;
}

this.emit('PLAYER_DISCONNECTED', data);
});
Expand Down Expand Up @@ -392,6 +395,7 @@ export default class SquadServer extends EventEmitter {
});

this.players = players;
this.oldplayers = oldPlayerInfo;

for (const player of this.players) {
if (typeof oldPlayerInfo[player.steamID] === 'undefined') continue;
Expand Down