From 3656b0f5e1613d94fdbf83cdfeac4c7cfc2c6c55 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Sun, 9 Aug 2020 20:55:26 +0700 Subject: [PATCH] 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. --- .../Services/Connection/ConnectionService.uc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sources/Services/Connection/ConnectionService.uc b/sources/Services/Connection/ConnectionService.uc index 3f1d4bb..2514350 100644 --- a/sources/Services/Connection/ConnectionService.uc +++ b/sources/Services/Connection/ConnectionService.uc @@ -38,6 +38,22 @@ var private array activeConnections; // class'ConnectionEvents' every time. var const class 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' // and either 'controllerToCheck.playerReplicationInfo != none' // or 'auxiliaryRepInfo != none'. @@ -123,6 +139,9 @@ public final function bool RegisterConnection(PlayerController player) newConnection.networkAddress = player.GetPlayerNetworkAddress(); newConnection.steamID = player.GetPlayerIDHash(); activeConnections[activeConnections.length] = newConnection; + // Remember recorded connections in case someone decides to + // nuke this service + default.activeConnections = activeConnections; events.static.CallPlayerConnected(newConnection); return true; }