Browse Source

Fix events in case of `ConnectionService` restart

When `ConnectionService` was before killed and respawned it would cause
a new connection events for every online player, regardless of whether
they were generated before.

Now list of registered players is also saved in default variables for
`ConnectionService` and quick restart will not cause any issues.
pull/8/head
Anton Tarasenko 4 years ago
parent
commit
3656b0f5e1
  1. 19
      sources/Services/Connection/ConnectionService.uc

19
sources/Services/Connection/ConnectionService.uc

@ -38,6 +38,22 @@ var private array<Connection> activeConnections;
// class'ConnectionEvents' every time. // class'ConnectionEvents' every time.
var const class<ConnectionEvents> events; var const class<ConnectionEvents> events;
// Find all players manually on launch
protected function OnLaunch()
{
local Controller nextController;
local PlayerController nextPlayerController;
nextController = level.controllerList;
while (nextController != none)
{
nextPlayerController = PlayerController(nextController);
if (nextPlayerController != none) {
RegisterConnection(nextPlayerController);
}
nextController = nextController.nextController;
}
}
// Returning 'true' guarantees that 'controllerToCheck != none' // Returning 'true' guarantees that 'controllerToCheck != none'
// and either 'controllerToCheck.playerReplicationInfo != none' // and either 'controllerToCheck.playerReplicationInfo != none'
// or 'auxiliaryRepInfo != none'. // or 'auxiliaryRepInfo != none'.
@ -123,6 +139,9 @@ public final function bool RegisterConnection(PlayerController player)
newConnection.networkAddress = player.GetPlayerNetworkAddress(); newConnection.networkAddress = player.GetPlayerNetworkAddress();
newConnection.steamID = player.GetPlayerIDHash(); newConnection.steamID = player.GetPlayerIDHash();
activeConnections[activeConnections.length] = newConnection; activeConnections[activeConnections.length] = newConnection;
// Remember recorded connections in case someone decides to
// nuke this service
default.activeConnections = activeConnections;
events.static.CallPlayerConnected(newConnection); events.static.CallPlayerConnected(newConnection);
return true; return true;
} }

Loading…
Cancel
Save