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

Improve player connection and disconnection logic #258

Merged
merged 6 commits into from
Jan 7, 2023
Merged
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
20 changes: 19 additions & 1 deletion core/log-parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export default class LogParser extends EventEmitter {

options.filename = filename;

this.eventStore = {};
this.eventStore = {
disconnected: {}, // holding area, cleared on map change.
players: {}, // persistent data, steamid, controller, suffix.
session: {}, // old eventstore, nonpersistent data
ect0s marked this conversation as resolved.
Show resolved Hide resolved
clients: {} // used in the connection chain before we resolve a player.
};

this.linesPerMinute = 0;
this.matchingLinesPerMinute = 0;
Expand Down Expand Up @@ -61,6 +66,19 @@ export default class LogParser extends EventEmitter {
this.linesPerMinute++;
}

// manage cleanup disconnected players, session data.
clearEventStore() {
Logger.verbose('LogParser', 2, 'Cleaning Eventstore');
for (const player of Object.values(this.eventStore.players)) {
if (this.eventStore.disconnected[player.steamID] === true) {
Logger.verbose('LogParser', 2, `Removing ${player.steamID} from eventStore`);
delete this.eventStore.players[player.steamID];
delete this.eventStore.disconnected[player.steamID];
}
}
this.eventStore.session = {};
Thomas-Smyth marked this conversation as resolved.
Show resolved Hide resolved
}

getRules() {
return [];
}
Expand Down
19 changes: 19 additions & 0 deletions squad-server/log-parser/client-connected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
regex:
/^\[([0-9.:-]+)]\[([ 0-9]*)]LogNet: AddClientConnection: Added client connection: \[UNetConnection\] RemoteAddr: ([0-9]{17}):[0-9]+, Name: (SteamNetConnection_[0-9]+), Driver: GameNetDriver (SteamNetDriver_[0-9]+), IsServer: YES, PC: NULL, Owner: NULL, UniqueId: INVALID/,
onMatch: (args, logParser) => {
const data = {
raw: args[0],
time: args[1],
chainID: args[2],
steamID: args[3],
connection: args[4],
driver: args[5]
};
/* This is Called when unreal engine adds a client connection
First Step in Adding a Player to server
*/
logParser.eventStore.clients[args[4]] = args[3];
logParser.emit('CLIENT_CONNECTED', data);
}
};
20 changes: 20 additions & 0 deletions squad-server/log-parser/client-login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
regex:
/^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquad: Login: NewPlayer: SteamNetConnection \/Engine\/Transient\.(SteamNetConnection_[0-9]+)/,
onMatch: (args, logParser) => {
const data = {
raw: args[0],
time: args[1],
chainID: args[2],
connection: args[3]
};
/* This is Called when a player begins the Login process
We use this to get a SteamID into playerConnected.
2nd Step in player connected path
*/

logParser.eventStore['client-login'] = logParser.eventStore.clients[args[3]];
delete logParser.eventStore.clients[args[3]];
logParser.emit('CLIENT_LOGIN', data);
}
};
2 changes: 1 addition & 1 deletion squad-server/log-parser/deployable-damaged.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
healthRemaining: args[8]
};

logParser.eventStore[args[3]] = data;
logParser.eventStore.session[args[3]] = data;

logParser.emit('DEPLOYABLE_DAMAGED', data);
}
Expand Down
10 changes: 8 additions & 2 deletions squad-server/log-parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AdminBroadcast from './admin-broadcast.js';
import DeployableDamaged from './deployable-damaged.js';
import NewGame from './new-game.js';
import PlayerConnected from './player-connected.js';
import PlayerControllerConnected from './playercontroller-connected.js';
import PlayerDisconnected from './player-disconnected.js';
import PlayerDamaged from './player-damaged.js';
import PlayerDied from './player-died.js';
Expand All @@ -15,7 +16,9 @@ import RoundEnded from './round-ended.js';
import RoundTickets from './round-tickets.js';
import RoundWinner from './round-winner.js';
import ServerTickRate from './server-tick-rate.js';
import SteamIDConnected from './steamid-connected.js';
import ClientConnected from './client-connected.js';
import ClientLogin from './client-login.js';
import PendingConnectionDestroyed from './pending-connection-destroyed.js';

export default class SquadLogParser extends LogParser {
constructor(options) {
Expand All @@ -28,6 +31,7 @@ export default class SquadLogParser extends LogParser {
DeployableDamaged,
NewGame,
PlayerConnected,
PlayerControllerConnected,
PlayerDisconnected,
PlayerDamaged,
PlayerDied,
Expand All @@ -39,7 +43,9 @@ export default class SquadLogParser extends LogParser {
RoundTickets,
RoundWinner,
ServerTickRate,
SteamIDConnected
ClientConnected,
ClientLogin,
PendingConnectionDestroyed
];
}
}
1 change: 1 addition & 0 deletions squad-server/log-parser/new-game.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export default {
delete logParser.eventStore.WON;

logParser.emit('NEW_GAME', data);
logParser.clearEventStore();
}
};
20 changes: 20 additions & 0 deletions squad-server/log-parser/pending-connection-destroyed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
regex:
/^\[([0-9.:-]+)]\[([ 0-9]*)]LogNet: UNetConnection::PendingConnectionLost\. \[UNetConnection\] RemoteAddr: ([0-9]{17}):[0-9]+, Name: (SteamNetConnection_[0-9]+), Driver: GameNetDriver (SteamNetDriver_[0-9]+), IsServer: YES, PC: NULL, Owner: NULL, UniqueId: (?:Steam:UNKNOWN \[.+\]|INVALID) bPendingDestroy=0/,
onMatch: (args, logParser) => {
const data = {
raw: args[0],
time: args[1],
chainID: args[2],
steamID: args[3],
connection: args[4],
driver: args[5]
};
/* This is Called when a pending client fails
Only used to cleanup clients in eventstore
*/

delete logParser.eventStore.clients[args[4]];
logParser.emit('PENDING_CONNECTION_DESTROYED', data);
}
};
15 changes: 14 additions & 1 deletion squad-server/log-parser/player-connected.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ export default {
time: args[1],
chainID: args[2],
playerSuffix: args[3],
steamID: logParser.eventStore['steamid-connected']
steamID: logParser.eventStore['client-login'], // player connected
controller: logParser.eventStore['player-controller'] // playercontroller connected
};

delete logParser.eventStore['client-login'];
delete logParser.eventStore['player-controller'];

// Handle Reconnecting players
if (logParser.eventStore.disconnected[data.steamID]) {
delete logParser.eventStore.disconnected[data.steamID];
}
logParser.emit('PLAYER_CONNECTED', data);
logParser.eventStore.players[data.steamID] = {
steamID: data.steamID,
suffix: data.playerSuffix,
controller: data.controller
};
}
};
2 changes: 1 addition & 1 deletion squad-server/log-parser/player-damaged.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
weapon: args[6]
};

logParser.eventStore[args[3]] = data;
logParser.eventStore.session[args[3]] = data;

logParser.emit('PLAYER_DAMAGED', data);
}
Expand Down
4 changes: 2 additions & 2 deletions squad-server/log-parser/player-died.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
/^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquadTrace: \[DedicatedServer](?:ASQSoldier::)?Die\(\): Player:(.+) KillingDamage=(?:-)*([0-9.]+) from ([A-z_0-9]+) caused by ([A-z_0-9-]+)_C/,
onMatch: (args, logParser) => {
const data = {
...logParser.eventStore[args[3]],
...logParser.eventStore.session[args[3]],
raw: args[0],
time: args[1],
woundTime: args[1],
Expand All @@ -14,7 +14,7 @@ export default {
weapon: args[6]
};

logParser.eventStore[args[3]] = data;
logParser.eventStore.session[args[3]] = data;

logParser.emit('PLAYER_DIED', data);
}
Expand Down
6 changes: 4 additions & 2 deletions squad-server/log-parser/player-disconnected.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
export default {
regex:
/^\[([0-9.:-]+)]\[([ 0-9]*)]LogEasyAntiCheatServer: \[[0-9:]+] \[[A-z]+] \[EAC Server] \[Info] \[UnregisterClient] Client: ([A-z0-9]+) PlayerGUID: ([0-9]{17})/,
/^\[([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.:-]+/,
onMatch: (args, logParser) => {
const data = {
raw: args[0],
time: args[1],
chainID: args[2],
steamID: args[4]
steamID: args[3],
playerController: args[4]
};

logParser.eventStore.disconnected[data.steamID] = true;
logParser.emit('PLAYER_DISCONNECTED', data);
}
};
2 changes: 1 addition & 1 deletion squad-server/log-parser/player-possess.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
possessClassname: args[4]
};

logParser.eventStore[args[3]] = args[2];
logParser.eventStore.session[args[3]] = args[2];

logParser.emit('PLAYER_POSSESS', data);
}
Expand Down
2 changes: 1 addition & 1 deletion squad-server/log-parser/player-revived.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquad: (.+) has revived (.+)\./,
onMatch: (args, logParser) => {
const data = {
...logParser.eventStore[args[3]],
...logParser.eventStore.session[args[3]],
raw: args[0],
time: args[1],
chainID: args[2],
Expand Down
5 changes: 3 additions & 2 deletions squad-server/log-parser/player-un-possess.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ export default {
time: args[1],
chainID: args[2],
playerSuffix: args[3],
switchPossess: args[3] in logParser.eventStore && logParser.eventStore[args[3]] === args[2]
switchPossess:
args[3] in logParser.eventStore.session && logParser.eventStore.session[args[3]] === args[2]
};

delete logParser.eventStore[args[3]];
delete logParser.eventStore.session[args[3]];

logParser.emit('PLAYER_UNPOSSESS', data);
}
Expand Down
4 changes: 2 additions & 2 deletions squad-server/log-parser/player-wounded.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default {
/^\[([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: (args, logParser) => {
const data = {
...logParser.eventStore[args[3]],
...logParser.eventStore.session[args[3]],
raw: args[0],
time: args[1],
chainID: args[2],
Expand All @@ -13,7 +13,7 @@ export default {
weapon: args[6]
};

logParser.eventStore[args[3]] = data;
logParser.eventStore.session[args[3]] = data;

logParser.emit('PLAYER_WOUNDED', data);
}
Expand Down
16 changes: 16 additions & 0 deletions squad-server/log-parser/playercontroller-connected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default {
regex:
/^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquad: PostLogin: NewPlayer: BP_PlayerController_C .+(BP_PlayerController_C_[0-9]+)/,
onMatch: (args, logParser) => {
const data = {
raw: args[0],
time: args[1],
chainID: args[2],
controller: args[3]
};

logParser.eventStore['player-controller'] = args[3];

logParser.emit('PLAYER_CONTROLLER_CONNECTED', data);
}
};
7 changes: 0 additions & 7 deletions squad-server/log-parser/steamid-connected.js

This file was deleted.