From 33494197e3a826afbf3dca06802ba54e9e80df52 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Fri, 7 Feb 2020 11:15:21 -0600 Subject: [PATCH] re-kick working as expected now --- Application/IW4MServer.cs | 6 ++--- Plugins/Stats/Helpers/StatManager.cs | 22 +++++++++++++++---- SharedLibraryCore/PartialEntities/EFClient.cs | 17 ++++++++++++-- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index 46c86acec..8322c1e87 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -439,7 +439,7 @@ namespace IW4MAdmin if (isPotentialFalseQuit) { - Logger.WriteInfo($"Receive predisconnect event for {E}, but it occured at game time {E.GameTime.Value}, which is the same last map change, so we're ignoring"); + Logger.WriteInfo($"Receive predisconnect event for {E.Origin}, but it occured at game time {E.GameTime.Value}, which is the same last map change, so we're ignoring"); return false; } @@ -453,7 +453,7 @@ namespace IW4MAdmin return false; } - else if (client.State == ClientState.Connected) + else if (client.State != ClientState.Unknown) { #if DEBUG == true Logger.WriteDebug($"Begin PreDisconnect for {client}"); @@ -623,7 +623,7 @@ namespace IW4MAdmin else if (client.IPAddress != null && client.State == ClientState.Disconnecting) { - Logger.WriteWarning($"{client} state is Disconnecting (probably kicked), but they are still connected. trying to kick again..."); + Logger.WriteWarning($"{client} state is Unknown (probably kicked), but they are still connected. trying to kick again..."); await client.CanConnect(client.IPAddress); } } diff --git a/Plugins/Stats/Helpers/StatManager.cs b/Plugins/Stats/Helpers/StatManager.cs index 0155a046d..857ddcbb9 100644 --- a/Plugins/Stats/Helpers/StatManager.cs +++ b/Plugins/Stats/Helpers/StatManager.cs @@ -367,17 +367,31 @@ namespace IW4MAdmin.Plugins.Stats.Helpers { pl.CurrentServer.Logger.WriteInfo($"Removing {pl} from stats"); + if (pl.CurrentServer == null) + { + pl.CurrentServer.Logger.WriteWarning($"Disconnecting client {pl} is not on a server, state is {pl.State}"); + return; + } + long serverId = GetIdForServer(pl.CurrentServer); var serverStats = _servers[serverId].ServerStatistics; // get individual client's stats var clientStats = pl.GetAdditionalProperty(CLIENT_STATS_KEY); // sync their stats before they leave - clientStats = UpdateStats(clientStats); - await SaveClientStats(clientStats); + if (clientStats != null) + { + clientStats = UpdateStats(clientStats); + await SaveClientStats(clientStats); - // increment the total play time - serverStats.TotalPlayTime += pl.ConnectionLength; + // increment the total play time + serverStats.TotalPlayTime += pl.ConnectionLength; + } + + else + { + pl.CurrentServer.Logger.WriteWarning($"Disconnecting client {pl} has not been added to stats, state is {pl.State}"); + } } private static async Task SaveClientStats(EFClientStatistics clientStats) diff --git a/SharedLibraryCore/PartialEntities/EFClient.cs b/SharedLibraryCore/PartialEntities/EFClient.cs index 1ce137eca..b25a94eaa 100644 --- a/SharedLibraryCore/PartialEntities/EFClient.cs +++ b/SharedLibraryCore/PartialEntities/EFClient.cs @@ -15,20 +15,27 @@ namespace SharedLibraryCore.Database.Models { public enum ClientState { + /// + /// default client state + /// + Unknown, + /// /// represents when the client has been detected as joining /// by the log file, but has not be authenticated by RCon /// Connecting, + /// /// represents when the client has been authenticated by RCon /// and validated by the database /// Connected, + /// /// represents when the client is leaving (either through RCon or log file) /// - Disconnecting, + Disconnecting } public enum Permission @@ -358,6 +365,7 @@ namespace SharedLibraryCore.Database.Models e.FailReason = GameEvent.EventFailReason.Permission; } + State = ClientState.Disconnecting; sender.CurrentServer.Manager.GetEventHandler().AddEvent(e); return e; } @@ -391,6 +399,7 @@ namespace SharedLibraryCore.Database.Models e.FailReason = GameEvent.EventFailReason.Invalid; } + State = ClientState.Disconnecting; sender.CurrentServer.Manager.GetEventHandler().AddEvent(e); return e; } @@ -506,7 +515,6 @@ namespace SharedLibraryCore.Database.Models public async Task OnDisconnect() { - State = ClientState.Disconnecting; TotalConnectionTime += ConnectionLength; LastConnection = DateTime.UtcNow; @@ -520,6 +528,11 @@ namespace SharedLibraryCore.Database.Models CurrentServer.Logger.WriteWarning($"Could not update disconnected player {this}"); CurrentServer.Logger.WriteDebug(e.GetExceptionInfo()); } + + finally + { + State = ClientState.Unknown; + } } public async Task OnJoin(int? ipAddress)