re-kick working as expected now

This commit is contained in:
RaidMax 2020-02-07 11:15:21 -06:00
parent 1dd88cdacb
commit 33494197e3
3 changed files with 36 additions and 9 deletions

View File

@ -439,7 +439,7 @@ namespace IW4MAdmin
if (isPotentialFalseQuit) 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; return false;
} }
@ -453,7 +453,7 @@ namespace IW4MAdmin
return false; return false;
} }
else if (client.State == ClientState.Connected) else if (client.State != ClientState.Unknown)
{ {
#if DEBUG == true #if DEBUG == true
Logger.WriteDebug($"Begin PreDisconnect for {client}"); Logger.WriteDebug($"Begin PreDisconnect for {client}");
@ -623,7 +623,7 @@ namespace IW4MAdmin
else if (client.IPAddress != null && client.State == ClientState.Disconnecting) 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); await client.CanConnect(client.IPAddress);
} }
} }

View File

@ -367,17 +367,31 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
{ {
pl.CurrentServer.Logger.WriteInfo($"Removing {pl} from stats"); 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); long serverId = GetIdForServer(pl.CurrentServer);
var serverStats = _servers[serverId].ServerStatistics; var serverStats = _servers[serverId].ServerStatistics;
// get individual client's stats // get individual client's stats
var clientStats = pl.GetAdditionalProperty<EFClientStatistics>(CLIENT_STATS_KEY); var clientStats = pl.GetAdditionalProperty<EFClientStatistics>(CLIENT_STATS_KEY);
// sync their stats before they leave // sync their stats before they leave
clientStats = UpdateStats(clientStats); if (clientStats != null)
await SaveClientStats(clientStats); {
clientStats = UpdateStats(clientStats);
await SaveClientStats(clientStats);
// increment the total play time // increment the total play time
serverStats.TotalPlayTime += pl.ConnectionLength; 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) private static async Task SaveClientStats(EFClientStatistics clientStats)

View File

@ -15,20 +15,27 @@ namespace SharedLibraryCore.Database.Models
{ {
public enum ClientState public enum ClientState
{ {
/// <summary>
/// default client state
/// </summary>
Unknown,
/// <summary> /// <summary>
/// represents when the client has been detected as joining /// represents when the client has been detected as joining
/// by the log file, but has not be authenticated by RCon /// by the log file, but has not be authenticated by RCon
/// </summary> /// </summary>
Connecting, Connecting,
/// <summary> /// <summary>
/// represents when the client has been authenticated by RCon /// represents when the client has been authenticated by RCon
/// and validated by the database /// and validated by the database
/// </summary> /// </summary>
Connected, Connected,
/// <summary> /// <summary>
/// represents when the client is leaving (either through RCon or log file) /// represents when the client is leaving (either through RCon or log file)
/// </summary> /// </summary>
Disconnecting, Disconnecting
} }
public enum Permission public enum Permission
@ -358,6 +365,7 @@ namespace SharedLibraryCore.Database.Models
e.FailReason = GameEvent.EventFailReason.Permission; e.FailReason = GameEvent.EventFailReason.Permission;
} }
State = ClientState.Disconnecting;
sender.CurrentServer.Manager.GetEventHandler().AddEvent(e); sender.CurrentServer.Manager.GetEventHandler().AddEvent(e);
return e; return e;
} }
@ -391,6 +399,7 @@ namespace SharedLibraryCore.Database.Models
e.FailReason = GameEvent.EventFailReason.Invalid; e.FailReason = GameEvent.EventFailReason.Invalid;
} }
State = ClientState.Disconnecting;
sender.CurrentServer.Manager.GetEventHandler().AddEvent(e); sender.CurrentServer.Manager.GetEventHandler().AddEvent(e);
return e; return e;
} }
@ -506,7 +515,6 @@ namespace SharedLibraryCore.Database.Models
public async Task OnDisconnect() public async Task OnDisconnect()
{ {
State = ClientState.Disconnecting;
TotalConnectionTime += ConnectionLength; TotalConnectionTime += ConnectionLength;
LastConnection = DateTime.UtcNow; LastConnection = DateTime.UtcNow;
@ -520,6 +528,11 @@ namespace SharedLibraryCore.Database.Models
CurrentServer.Logger.WriteWarning($"Could not update disconnected player {this}"); CurrentServer.Logger.WriteWarning($"Could not update disconnected player {this}");
CurrentServer.Logger.WriteDebug(e.GetExceptionInfo()); CurrentServer.Logger.WriteDebug(e.GetExceptionInfo());
} }
finally
{
State = ClientState.Unknown;
}
} }
public async Task OnJoin(int? ipAddress) public async Task OnJoin(int? ipAddress)