diff --git a/Application/Application.csproj b/Application/Application.csproj index 7ce46227..d16640a7 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -25,7 +25,7 @@ - + diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index 428d10be..5668e1ab 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -341,9 +341,7 @@ namespace IW4MAdmin.Application GetApplicationSettings().Configuration()?.DatabaseProvider)) { await new ContextSeed(db).Seed(); - } - - PrivilegedClients = (await ClientSvc.GetPrivilegedClients()).ToDictionary(_client => _client.ClientId); + } #endregion #region COMMANDS @@ -520,14 +518,12 @@ namespace IW4MAdmin.Application #endregion #region INIT - int failedServers = 0; int successServers = 0; Exception lastException = null; async Task Init(ServerConfiguration Conf) { // setup the event handler after the class is initialized - Handler = new GameEventHandler(this); try @@ -560,22 +556,21 @@ namespace IW4MAdmin.Application if (e.GetType() == typeof(DvarException)) { - Logger.WriteDebug($"{Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR"].FormatExt((e as DvarException).Data["dvar_name"])} ({Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR_HELP"]})"); + Logger.WriteDebug($"{e.Message} {(e.GetType() == typeof(DvarException) ? $"({Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR_HELP"]})" : "")}"); } - else if (e.GetType() == typeof(NetworkException)) - { - Logger.WriteDebug(e.Message); - } - - failedServers++; lastException = e; } } await Task.WhenAll(config.Servers.Select(c => Init(c)).ToArray()); - if (successServers - failedServers <= 0) + if (successServers == 0) + { + throw lastException; + } + + if (successServers != config.Servers.Count) { if (!Utilities.PromptBool(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_START_WITH_ERRORS"])) { @@ -731,8 +726,6 @@ namespace IW4MAdmin.Application return ConfigHandler; } - public IDictionary PrivilegedClients { get; private set; } - public bool ShutdownRequested() { return !Running; diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index 5f9e2996..6f72265a 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -200,26 +200,6 @@ namespace IW4MAdmin if (E.Type == GameEvent.EventType.ChangePermission) { var newPermission = (Permission)E.Extra; - - if (newPermission < Permission.Moderator && - !Manager.PrivilegedClients.Remove(E.Target.ClientId, out _)) - { - Logger.WriteWarning($"Could not remove {E.Target}-{newPermission} from privileged users"); - } - - else - { - if (Manager.PrivilegedClients.ContainsKey(E.Target.ClientId)) - { - Manager.PrivilegedClients[E.Target.ClientId] = E.Target; - } - - else if (!Manager.PrivilegedClients.TryAdd(E.Target.ClientId, E.Target)) - { - Logger.WriteWarning($"Could not add {E.Target}-{newPermission} to privileged clients"); - } - } - Logger.WriteInfo($"{E.Origin} is setting {E.Target} to permission level {newPermission}"); await Manager.GetClientService().UpdateLevel(newPermission, E.Target, E.Origin); } diff --git a/Application/RconParsers/BaseRConParser.cs b/Application/RconParsers/BaseRConParser.cs index 4de44627..241033b3 100644 --- a/Application/RconParsers/BaseRConParser.cs +++ b/Application/RconParsers/BaseRConParser.cs @@ -66,22 +66,13 @@ namespace IW4MAdmin.Application.RconParsers { string[] lineSplit = await connection.SendQueryAsync(StaticHelpers.QueryType.GET_DVAR, dvarName); string response = string.Join('\n', lineSplit.Skip(1)); - - if (!lineSplit[0].Contains(Configuration.CommandPrefixes.RConResponse)) - { - throw new DvarException($"Could not retrieve DVAR \"{dvarName}\""); - } - - if (response.Contains("Unknown command")) - { - throw new DvarException($"DVAR \"{dvarName}\" does not exist"); - } - var match = Regex.Match(response, Configuration.Dvar.Pattern); - if (!match.Success) + if (!lineSplit[0].Contains(Configuration.CommandPrefixes.RConResponse) || + response.Contains("Unknown command") || + !match.Success) { - throw new DvarException($"Could not retrieve DVAR \"{dvarName}\""); + throw new DvarException(Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_DVAR"].FormatExt(dvarName)); } string value = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarValue]].Value.StripColors(); @@ -91,9 +82,9 @@ namespace IW4MAdmin.Application.RconParsers return new Dvar() { Name = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarName]].Value.StripColors(), - Value = string.IsNullOrEmpty(value) ? default(T) : (T)Convert.ChangeType(value, typeof(T)), - DefaultValue = string.IsNullOrEmpty(defaultValue) ? default(T) : (T)Convert.ChangeType(defaultValue, typeof(T)), - LatchedValue = string.IsNullOrEmpty(latchedValue) ? default(T) : (T)Convert.ChangeType(latchedValue, typeof(T)), + Value = string.IsNullOrEmpty(value) ? default : (T)Convert.ChangeType(value, typeof(T)), + DefaultValue = string.IsNullOrEmpty(defaultValue) ? default : (T)Convert.ChangeType(defaultValue, typeof(T)), + LatchedValue = string.IsNullOrEmpty(latchedValue) ? default : (T)Convert.ChangeType(latchedValue, typeof(T)), Domain = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarDomain]].Value.StripColors() }; } diff --git a/Plugins/Login/Commands/CLogin.cs b/Plugins/Login/Commands/CLogin.cs index 658eea79..a805228d 100644 --- a/Plugins/Login/Commands/CLogin.cs +++ b/Plugins/Login/Commands/CLogin.cs @@ -18,13 +18,12 @@ namespace IW4MAdmin.Plugins.Login.Commands public override async Task ExecuteAsync(GameEvent E) { - var client = E.Owner.Manager.PrivilegedClients[E.Origin.ClientId]; bool success = E.Owner.Manager.TokenAuthenticator.AuthorizeToken(E.Origin.NetworkId, E.Data); if (!success) { - string[] hashedPassword = await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(E.Data, client.PasswordSalt)); - success = hashedPassword[0] == client.Password; + string[] hashedPassword = await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(E.Data, E.Origin.PasswordSalt)); + success = hashedPassword[0] == E.Origin.Password; } if (success) diff --git a/Plugins/Login/Plugin.cs b/Plugins/Login/Plugin.cs index 8101ac20..f5e268a0 100644 --- a/Plugins/Login/Plugin.cs +++ b/Plugins/Login/Plugin.cs @@ -42,10 +42,8 @@ namespace IW4MAdmin.Plugins.Login E.Origin.Level == EFClient.Permission.Console) return Task.CompletedTask; - E.Owner.Manager.PrivilegedClients.TryGetValue(E.Origin.ClientId, out EFClient client); - if (((Command)E.Extra).Name == new SharedLibraryCore.Commands.CSetPassword().Name && - client?.Password == null) + E.Origin?.Password == null) return Task.CompletedTask; if (((Command)E.Extra).Name == new Commands.CLogin().Name) diff --git a/Plugins/Stats/Cheat/Detection.cs b/Plugins/Stats/Cheat/Detection.cs index 939e1ee9..aa1225ae 100644 --- a/Plugins/Stats/Cheat/Detection.cs +++ b/Plugins/Stats/Cheat/Detection.cs @@ -257,18 +257,18 @@ namespace IW4MAdmin.Plugins.Stats.Cheat // ban on bone ratio if (currentMaxBoneRatio > maxBoneRatioLerpValueForBan) { - Log.WriteDebug("**Maximum Bone Ratio Reached For Ban**"); - Log.WriteDebug($"ClientId: {hit.AttackerId}"); - Log.WriteDebug($"**HitCount: {HitCount}"); - Log.WriteDebug($"**Ratio {currentMaxBoneRatio}"); - Log.WriteDebug($"**MaxRatio {maxBoneRatioLerpValueForBan}"); - var sb = new StringBuilder(); - foreach (var kvp in HitLocationCount) - { - sb.Append($"HitLocation: {kvp.Key} -> {kvp.Value}\r\n"); - } + //Log.WriteDebug("**Maximum Bone Ratio Reached For Ban**"); + //Log.WriteDebug($"ClientId: {hit.AttackerId}"); + //Log.WriteDebug($"**HitCount: {HitCount}"); + //Log.WriteDebug($"**Ratio {currentMaxBoneRatio}"); + //Log.WriteDebug($"**MaxRatio {maxBoneRatioLerpValueForBan}"); + //var sb = new StringBuilder(); + //foreach (var kvp in HitLocationCount) + //{ + // sb.Append($"HitLocation: {kvp.Key} -> {kvp.Value}\r\n"); + //} - Log.WriteDebug(sb.ToString()); + //Log.WriteDebug(sb.ToString()); result = new DetectionPenaltyResult() { @@ -281,18 +281,18 @@ namespace IW4MAdmin.Plugins.Stats.Cheat } else { - Log.WriteDebug("**Maximum Bone Ratio Reached For Flag**"); - Log.WriteDebug($"ClientId: {hit.AttackerId}"); - Log.WriteDebug($"**HitCount: {HitCount}"); - Log.WriteDebug($"**Ratio {currentMaxBoneRatio}"); - Log.WriteDebug($"**MaxRatio {maxBoneRatioLerpValueForFlag}"); - var sb = new StringBuilder(); - foreach (var kvp in HitLocationCount) - { - sb.Append($"HitLocation: {kvp.Key} -> {kvp.Value}\r\n"); - } + //Log.WriteDebug("**Maximum Bone Ratio Reached For Flag**"); + //Log.WriteDebug($"ClientId: {hit.AttackerId}"); + //Log.WriteDebug($"**HitCount: {HitCount}"); + //Log.WriteDebug($"**Ratio {currentMaxBoneRatio}"); + //Log.WriteDebug($"**MaxRatio {maxBoneRatioLerpValueForFlag}"); + //var sb = new StringBuilder(); + //foreach (var kvp in HitLocationCount) + //{ + // sb.Append($"HitLocation: {kvp.Key} -> {kvp.Value}\r\n"); + //} - Log.WriteDebug(sb.ToString()); + //Log.WriteDebug(sb.ToString()); result = new DetectionPenaltyResult() { diff --git a/Plugins/Tests/Tests.csproj b/Plugins/Tests/Tests.csproj index 03e7bb2d..33719eda 100644 --- a/Plugins/Tests/Tests.csproj +++ b/Plugins/Tests/Tests.csproj @@ -13,7 +13,6 @@ - all diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index b531cc8f..dcc3e1b5 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -1119,8 +1119,8 @@ namespace SharedLibraryCore.Commands E.Origin.PasswordSalt = hashedPassword[1]; // update the password for the client in privileged - E.Owner.Manager.PrivilegedClients[E.Origin.ClientId].Password = hashedPassword[0]; - E.Owner.Manager.PrivilegedClients[E.Origin.ClientId].PasswordSalt = hashedPassword[1]; + //E.Owner.Manager.PrivilegedClients[E.Origin.ClientId].Password = hashedPassword[0]; + //E.Owner.Manager.PrivilegedClients[E.Origin.ClientId].PasswordSalt = hashedPassword[1]; await E.Owner.Manager.GetClientService().Update(E.Origin); E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_PASSWORD_SUCCESS"]); diff --git a/SharedLibraryCore/Interfaces/IManager.cs b/SharedLibraryCore/Interfaces/IManager.cs index 3f79c0b7..0f28d960 100644 --- a/SharedLibraryCore/Interfaces/IManager.cs +++ b/SharedLibraryCore/Interfaces/IManager.cs @@ -24,7 +24,6 @@ namespace SharedLibraryCore.Interfaces ClientService GetClientService(); AliasService GetAliasService(); PenaltyService GetPenaltyService(); - IDictionary PrivilegedClients { get; } /// /// Get the event handlers /// diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index 78655e12..e0f56ca6 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -413,7 +413,7 @@ namespace SharedLibraryCore.Services } } - public async Task> GetPrivilegedClients() + public async Task> GetPrivilegedClients(bool includeName = true) { using (var context = new DatabaseContext(disableTracking: true)) { @@ -451,7 +451,13 @@ namespace SharedLibraryCore.Services using (var context = new DatabaseContext(disableTracking: true)) { - long networkId = identifier.ConvertGuidToLong(); + long? networkId = null; + try + { + networkId = identifier.ConvertGuidToLong(); + } + catch { } + int? ipAddress = identifier.ConvertToIP(); IQueryable iqLinkIds = context.Aliases.Where(_alias => _alias.Active); @@ -477,10 +483,11 @@ namespace SharedLibraryCore.Services var iqClients = context.Clients .Where(_client => _client.Active); - if (networkId != long.MinValue) + if (networkId.HasValue) { - iqClients = iqClients.Where(_client => networkId == _client.NetworkId); + iqClients = iqClients.Where(_client => networkId.Value == _client.NetworkId); } + else { iqClients = iqClients.Where(_client => linkIds.Contains(_client.AliasLinkId)); diff --git a/SharedLibraryCore/SharedLibraryCore.csproj b/SharedLibraryCore/SharedLibraryCore.csproj index 14e377fb..a2a0aefc 100644 --- a/SharedLibraryCore/SharedLibraryCore.csproj +++ b/SharedLibraryCore/SharedLibraryCore.csproj @@ -24,9 +24,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers @@ -35,8 +35,8 @@ - - + + diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index 10506a11..dab544af 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -299,7 +299,7 @@ namespace SharedLibraryCore public static int? ConvertToIP(this string str) { - bool success = System.Net.IPAddress.TryParse(str, out System.Net.IPAddress ip); + bool success = IPAddress.TryParse(str, out IPAddress ip); return success && ip.GetAddressBytes().Count(_byte => _byte == 0) != 4 ? (int?)BitConverter.ToInt32(ip.GetAddressBytes(), 0) : null; @@ -307,7 +307,7 @@ namespace SharedLibraryCore public static string ConvertIPtoString(this int? ip) { - return !ip.HasValue ? "" : new System.Net.IPAddress(BitConverter.GetBytes(ip.Value)).ToString(); + return !ip.HasValue ? "" : new IPAddress(BitConverter.GetBytes(ip.Value)).ToString(); } public static string GetTimePassed(DateTime start) diff --git a/WebfrontCore/Controllers/AccountController.cs b/WebfrontCore/Controllers/AccountController.cs index d7f98fe1..322f7260 100644 --- a/WebfrontCore/Controllers/AccountController.cs +++ b/WebfrontCore/Controllers/AccountController.cs @@ -25,7 +25,7 @@ namespace WebfrontCore.Controllers try { - var privilegedClient = Manager.PrivilegedClients[clientId]; + var privilegedClient = await Manager.GetClientService().Get(clientId); bool loginSuccess = Manager.TokenAuthenticator.AuthorizeToken(privilegedClient.NetworkId, password) || (await Task.FromResult(SharedLibraryCore.Helpers.Hashing.Hash(password, privilegedClient.PasswordSalt)))[0] == privilegedClient.Password; diff --git a/WebfrontCore/WebfrontCore.csproj b/WebfrontCore/WebfrontCore.csproj index 37637421..02150747 100644 --- a/WebfrontCore/WebfrontCore.csproj +++ b/WebfrontCore/WebfrontCore.csproj @@ -65,7 +65,7 @@ - + @@ -75,14 +75,12 @@ - - - + + + all runtime; build; native; contentfiles; analyzers - -