diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index bb79469be..ef18ef1d7 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -66,8 +66,6 @@ namespace IW4MAdmin client.CurrentServer = this; Clients[client.ClientNumber] = client; - - client.State = ClientState.Connected; #if DEBUG == true Logger.WriteDebug($"End PreConnect for {client}"); #endif @@ -80,6 +78,7 @@ namespace IW4MAdmin Manager.GetEventHandler().AddEvent(e); await client.OnJoin(client.IPAddress); + client.State = ClientState.Connected; } catch (Exception ex) @@ -460,7 +459,7 @@ namespace IW4MAdmin private async Task OnClientUpdate(EFClient origin) { - var client = Clients.FirstOrDefault(_client => _client.Equals(origin)); + var client = GetClientsAsList().FirstOrDefault(_client => _client.Equals(origin)); if (client != null) { @@ -468,7 +467,9 @@ namespace IW4MAdmin client.Score = origin.Score; // update their IP if it hasn't been set yet - if (client.IPAddress == null && !client.IsBot) + if (client.IPAddress == null && + !client.IsBot && + client.State == ClientState.Connected) { await client.OnJoin(origin.IPAddress); } diff --git a/SharedLibraryCore/Dtos/ServerInfo.cs b/SharedLibraryCore/Dtos/ServerInfo.cs index 103432984..29b430c5e 100644 --- a/SharedLibraryCore/Dtos/ServerInfo.cs +++ b/SharedLibraryCore/Dtos/ServerInfo.cs @@ -19,5 +19,6 @@ namespace SharedLibraryCore.Dtos public Helpers.PlayerHistory[] PlayerHistory { get; set; } public long ID { get; set; } public bool Online { get; set; } + public string ConnectProtocolUrl { get; set; } } } diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index d8a3381f9..e91ef6dbc 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -135,7 +135,7 @@ namespace SharedLibraryCore.Services // this happens when the link we found is different than the one we create before adding an IP if (isAliasLinkUpdated) { - entity.CurrentServer.Logger.WriteDebug($"found a link for {entity} so we are updating link from {entity.AliasLink.AliasLinkId} to {newAliasLink.AliasLinkId}"); + entity.CurrentServer.Logger.WriteDebug($"[updatealias] found a link for {entity} so we are updating link from {entity.AliasLink.AliasLinkId} to {newAliasLink.AliasLinkId}"); var oldAliasLink = entity.AliasLink; @@ -161,7 +161,7 @@ namespace SharedLibraryCore.Services // the existing alias matches ip and name, so we can just ignore the temporary one if (hasExactAliasMatch) { - entity.CurrentServer.Logger.WriteDebug($"{entity} has exact alias match"); + entity.CurrentServer.Logger.WriteDebug($"[updatealias] {entity} has exact alias match"); var oldAlias = entity.CurrentAlias; entity.CurrentAliasId = existingExactAlias.AliasId; @@ -169,8 +169,9 @@ namespace SharedLibraryCore.Services await context.SaveChangesAsync(); // the alias is the same so we can just remove it - if (oldAlias.AliasId != existingExactAlias.AliasId) + if (oldAlias.AliasId != existingExactAlias.AliasId && oldAlias.AliasId > 0) { + entity.CurrentServer.Logger.WriteDebug($"[updatealias] {entity} has exact alias match, so we're going to try to remove aliasId {oldAlias.AliasId} with linkId {oldAlias.AliasId}"); context.Aliases.Remove(oldAlias); await context.SaveChangesAsync(); } @@ -179,7 +180,7 @@ namespace SharedLibraryCore.Services // theres no exact match, but they've played before with the GUID or IP else { - entity.CurrentServer.Logger.WriteDebug($"Connecting player is using a new alias {entity}"); + entity.CurrentServer.Logger.WriteDebug($"[updatealias] {entity} is using a new alias"); var newAlias = new EFAlias() { diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index fecbb60cc..34fde6905 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; +using System.IO; using System.Linq; using System.Reflection; using System.Text; diff --git a/WebfrontCore/Controllers/BaseController.cs b/WebfrontCore/Controllers/BaseController.cs index d4f2978b2..c46c71e1b 100644 --- a/WebfrontCore/Controllers/BaseController.cs +++ b/WebfrontCore/Controllers/BaseController.cs @@ -66,11 +66,16 @@ namespace WebfrontCore.Controllers { try { - Client.ClientId = Convert.ToInt32(base.User.Claims.First(c => c.Type == ClaimTypes.Sid).Value); - Client.NetworkId = User.Claims.First(_claim => _claim.Type == ClaimTypes.PrimarySid).Value.ConvertLong(); - Client.Level = (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), User.Claims.First(c => c.Type == ClaimTypes.Role).Value); - Client.CurrentAlias = new EFAlias() { Name = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value }; - Authorized = Client.ClientId >= 0; + int clientId = Convert.ToInt32(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid)?.Value ?? "-1"); + + if (clientId > 0) + { + Client.ClientId = clientId; + Client.NetworkId = User.Claims.First(_claim => _claim.Type == ClaimTypes.PrimarySid).Value.ConvertLong(); + Client.Level = (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), User.Claims.First(c => c.Type == ClaimTypes.Role).Value); + Client.CurrentAlias = new EFAlias() { Name = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value }; + Authorized = Client.ClientId >= 0; + } } catch (InvalidOperationException) diff --git a/WebfrontCore/Controllers/ServerController.cs b/WebfrontCore/Controllers/ServerController.cs index de4c1d2d0..4b5601ce4 100644 --- a/WebfrontCore/Controllers/ServerController.cs +++ b/WebfrontCore/Controllers/ServerController.cs @@ -36,7 +36,7 @@ namespace WebfrontCore.Controllers LevelInt = (int)p.Level }).ToList(), ChatHistory = s.ChatHistory.ToList(), - PlayerHistory = s.ClientHistory.ToArray(), + PlayerHistory = s.ClientHistory.ToArray() }; return PartialView("_ClientActivity", serverInfo); } diff --git a/WebfrontCore/ViewComponents/ServerListViewComponent.cs b/WebfrontCore/ViewComponents/ServerListViewComponent.cs index e87703385..29df5c5ae 100644 --- a/WebfrontCore/ViewComponents/ServerListViewComponent.cs +++ b/WebfrontCore/ViewComponents/ServerListViewComponent.cs @@ -29,7 +29,8 @@ namespace WebfrontCore.ViewComponents LevelInt = (int)p.Level }).ToList(), ChatHistory = s.ChatHistory.ToList(), - Online = !s.Throttled + Online = !s.Throttled, + ConnectProtocolUrl = s.EventParser.URLProtocolFormat.FormatExt(s.IP, s.GetPort()) }).ToList(); return View("_List", serverInfo); } diff --git a/WebfrontCore/Views/Server/_Server.cshtml b/WebfrontCore/Views/Server/_Server.cshtml index 2345fbbb6..31b15577d 100644 --- a/WebfrontCore/Views/Server/_Server.cshtml +++ b/WebfrontCore/Views/Server/_Server.cshtml @@ -3,21 +3,21 @@ Layout = null; } -