From 95d64df3214897ca7778748bfd03ed693a31e87c Mon Sep 17 00:00:00 2001 From: RaidMax Date: Wed, 29 May 2019 16:55:35 -0500 Subject: [PATCH] combined Penalty and EFPenalty moved some classes around --- Application/Application.csproj | 6 +- Application/ApplicationManager.cs | 1 - Application/EventParsers/BaseEventParser.cs | 63 ++++++++++------- Application/IO/GameLogReader.cs | 23 ++++++- Application/IO/GameLogReaderHttp.cs | 23 ++++++- Application/IW4MServer.cs | 42 ++++++------ Application/RconParsers/BaseRConParser.cs | 4 +- Plugins/IW4ScriptCommands/Commands/Balance.cs | 1 - Plugins/IW4ScriptCommands/GscApiController.cs | 1 - Plugins/ScriptPlugins/VPNDetection.js | 6 +- Plugins/Stats/Cheat/Detection.cs | 32 ++++----- Plugins/Stats/Cheat/DetectionPenaltyResult.cs | 4 +- Plugins/Stats/Commands/MostPlayed.cs | 1 - Plugins/Stats/Commands/TopStats.cs | 1 - Plugins/Stats/Commands/ViewStats.cs | 1 - Plugins/Stats/Helpers/StatManager.cs | 10 ++- Plugins/Stats/Plugin.cs | 17 +++-- Plugins/Tests/ClientTests.cs | 7 +- Plugins/Tests/ManagerTests.cs | 1 - Plugins/Tests/PluginTests.cs | 1 - Plugins/Welcome/Plugin.cs | 3 +- SharedLibraryCore/Command.cs | 1 - SharedLibraryCore/Commands/NativeCommands.cs | 8 +-- SharedLibraryCore/Database/Models/EFClient.cs | 21 +----- .../Database/Models/EFPenalty.cs | 4 +- SharedLibraryCore/Dtos/PenaltyInfo.cs | 2 +- SharedLibraryCore/Events/GameEvent.cs | 9 +++ .../{Objects => Helpers}/Report.cs | 2 +- SharedLibraryCore/Interfaces/IManager.cs | 3 - SharedLibraryCore/Interfaces/IRConParser.cs | 1 - .../{Objects => Localization}/Permission.cs | 2 +- .../20180409183408_InitialCreate.Designer.cs | 1 - .../20180502195450_Update.Designer.cs | 1 - .../20180516023249_AddEloField.Designer.cs | 1 - .../20180517223349_AddRollingKDR.Designer.cs | 1 - ...tomatedOffenseAndRatingHistory.Designer.cs | 1 - ...180601172317_AddActivityAmount.Designer.cs | 1 - .../20180602041758_AddClientMeta.Designer.cs | 1 - ...0180605191706_AddEFACSnapshots.Designer.cs | 1 - ...20180614014303_IndexForEFAlias.Designer.cs | 1 - SharedLibraryCore/Objects/ClientStats.cs | 10 --- .../{Objects => PartialEntities}/EFAlias.cs | 0 .../{Objects => PartialEntities}/EFClient.cs | 67 ++++++++++++------- .../EFPenalty.cs} | 4 +- SharedLibraryCore/Server.cs | 1 - SharedLibraryCore/Services/ClientService.cs | 1 - SharedLibraryCore/Services/PenaltyService.cs | 15 ++--- SharedLibraryCore/Utilities.cs | 2 +- WebfrontCore/Controllers/ClientController.cs | 3 +- WebfrontCore/Controllers/PenaltyController.cs | 2 +- .../PenaltyListViewComponent.cs | 4 +- WebfrontCore/ViewModels/PenaltyFilterInfo.cs | 7 +- WebfrontCore/Views/Penalty/List.cshtml | 10 +-- WebfrontCore/WebfrontCore.csproj | 2 +- 54 files changed, 231 insertions(+), 207 deletions(-) rename SharedLibraryCore/{Objects => Helpers}/Report.cs (90%) rename SharedLibraryCore/{Objects => Localization}/Permission.cs (83%) delete mode 100644 SharedLibraryCore/Objects/ClientStats.cs rename SharedLibraryCore/{Objects => PartialEntities}/EFAlias.cs (100%) rename SharedLibraryCore/{Objects => PartialEntities}/EFClient.cs (94%) rename SharedLibraryCore/{Objects/Penalty.cs => PartialEntities/EFPenalty.cs} (75%) diff --git a/Application/Application.csproj b/Application/Application.csproj index 6f0bc90f0..e90c6608d 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -6,7 +6,7 @@ 2.2.2 false RaidMax.IW4MAdmin.Application - 2.2.7.3 + 2.2.7.4 RaidMax Forever None IW4MAdmin @@ -32,8 +32,8 @@ true true - 2.2.7.3 - 2.2.7.3 + 2.2.7.4 + 2.2.7.4 7.1 diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index 5f30ef907..ec06da989 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -12,7 +12,6 @@ using SharedLibraryCore.Events; using SharedLibraryCore.Exceptions; using SharedLibraryCore.Helpers; using SharedLibraryCore.Interfaces; -using SharedLibraryCore.Objects; using SharedLibraryCore.Services; using System; using System.Collections.Concurrent; diff --git a/Application/EventParsers/BaseEventParser.cs b/Application/EventParsers/BaseEventParser.cs index 84bfce046..cb0f130b7 100644 --- a/Application/EventParsers/BaseEventParser.cs +++ b/Application/EventParsers/BaseEventParser.cs @@ -104,7 +104,8 @@ namespace IW4MAdmin.Application.EventParsers Type = GameEvent.EventType.Command, Data = message, Origin = new EFClient() { NetworkId = originId }, - Message = message + Message = message, + RequiredEntity = GameEvent.EventRequiredEntity.Origin }; } @@ -113,7 +114,8 @@ namespace IW4MAdmin.Application.EventParsers Type = GameEvent.EventType.Say, Data = message, Origin = new EFClient() { NetworkId = originId }, - Message = message + Message = message, + RequiredEntity = GameEvent.EventRequiredEntity.Origin }; } } @@ -121,13 +123,12 @@ namespace IW4MAdmin.Application.EventParsers if (eventType == "K") { - var match = Regex.Match(logLine, Configuration.Kill.Pattern); if (match.Success) { long originId = match.Groups[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].Value.ToString().ConvertGuidToLong(1); - long targetId = match.Groups[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].Value.ToString().ConvertGuidToLong(); + long targetId = match.Groups[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].Value.ToString().ConvertGuidToLong(1); return new GameEvent() { @@ -135,27 +136,29 @@ namespace IW4MAdmin.Application.EventParsers Data = logLine, Origin = new EFClient() { NetworkId = originId }, Target = new EFClient() { NetworkId = targetId }, + RequiredEntity = GameEvent.EventRequiredEntity.Origin | GameEvent.EventRequiredEntity.Target }; } } if (eventType == "D") { - var regexMatch = Regex.Match(logLine, Configuration.Damage.Pattern); + var regexMatch = Regex.Match(logLine, Configuration.Damage.Pattern); - if (regexMatch.Success) + if (regexMatch.Success) + { + long originId = regexMatch.Groups[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(1); + long targetId = regexMatch.Groups[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString().ConvertGuidToLong(1); + + return new GameEvent() { - long originId = regexMatch.Groups[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(1); - long targetId = regexMatch.Groups[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString().ConvertGuidToLong(); - - return new GameEvent() - { - Type = GameEvent.EventType.Damage, - Data = logLine, - Origin = new EFClient() { NetworkId = originId }, - Target = new EFClient() { NetworkId = targetId } - }; - } + Type = GameEvent.EventType.Damage, + Data = logLine, + Origin = new EFClient() { NetworkId = originId }, + Target = new EFClient() { NetworkId = targetId }, + RequiredEntity = GameEvent.EventRequiredEntity.Origin | GameEvent.EventRequiredEntity.Target + }; + } } if (eventType == "J") @@ -177,7 +180,8 @@ namespace IW4MAdmin.Application.EventParsers NetworkId = regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(), ClientNumber = Convert.ToInt32(regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()), State = EFClient.ClientState.Connecting, - } + }, + RequiredEntity = GameEvent.EventRequiredEntity.None }; } } @@ -200,7 +204,8 @@ namespace IW4MAdmin.Application.EventParsers NetworkId = regexMatch.Groups[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(), ClientNumber = Convert.ToInt32(regexMatch.Groups[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()), State = EFClient.ClientState.Disconnecting - } + }, + RequiredEntity = GameEvent.EventRequiredEntity.Origin }; } } @@ -213,6 +218,7 @@ namespace IW4MAdmin.Application.EventParsers Data = lineSplit[0], Origin = Utilities.IW4MAdminClient(), Target = Utilities.IW4MAdminClient(), + RequiredEntity = GameEvent.EventRequiredEntity.None }; } @@ -226,7 +232,8 @@ namespace IW4MAdmin.Application.EventParsers Data = lineSplit[0], Origin = Utilities.IW4MAdminClient(), Target = Utilities.IW4MAdminClient(), - Extra = dump.DictionaryFromKeyValue() + Extra = dump.DictionaryFromKeyValue(), + RequiredEntity = GameEvent.EventRequiredEntity.None }; } @@ -237,7 +244,8 @@ namespace IW4MAdmin.Application.EventParsers { Type = GameEvent.EventType.JoinTeam, Data = logLine, - Origin = new EFClient() { NetworkId = lineSplit[1].ConvertGuidToLong() } + Origin = new EFClient() { NetworkId = lineSplit[1].ConvertGuidToLong() }, + RequiredEntity = GameEvent.EventRequiredEntity.Target }; } @@ -245,14 +253,15 @@ namespace IW4MAdmin.Application.EventParsers if (eventType == "ScriptKill") { long originId = lineSplit[1].ConvertGuidToLong(1); - long targetId = lineSplit[2].ConvertGuidToLong(); + long targetId = lineSplit[2].ConvertGuidToLong(1); return new GameEvent() { Type = GameEvent.EventType.ScriptKill, Data = logLine, Origin = new EFClient() { NetworkId = originId }, - Target = new EFClient() { NetworkId = targetId } + Target = new EFClient() { NetworkId = targetId }, + RequiredEntity = GameEvent.EventRequiredEntity.Origin | GameEvent.EventRequiredEntity.Target }; } @@ -260,14 +269,15 @@ namespace IW4MAdmin.Application.EventParsers if (eventType == "ScriptDamage") { long originId = lineSplit[1].ConvertGuidToLong(1); - long targetId = lineSplit[2].ConvertGuidToLong(); + long targetId = lineSplit[2].ConvertGuidToLong(1); return new GameEvent() { Type = GameEvent.EventType.ScriptDamage, Data = logLine, Origin = new EFClient() { NetworkId = originId }, - Target = new EFClient() { NetworkId = targetId } + Target = new EFClient() { NetworkId = targetId }, + RequiredEntity = GameEvent.EventRequiredEntity.Origin | GameEvent.EventRequiredEntity.Target }; } @@ -275,7 +285,8 @@ namespace IW4MAdmin.Application.EventParsers { Type = GameEvent.EventType.Unknown, Origin = Utilities.IW4MAdminClient(), - Target = Utilities.IW4MAdminClient() + Target = Utilities.IW4MAdminClient(), + RequiredEntity = GameEvent.EventRequiredEntity.None }; } } diff --git a/Application/IO/GameLogReader.cs b/Application/IO/GameLogReader.cs index 9f9a7226d..41026938c 100644 --- a/Application/IO/GameLogReader.cs +++ b/Application/IO/GameLogReader.cs @@ -61,9 +61,26 @@ namespace IW4MAdmin.Application.IO if (!ignoreBots.Value || (ignoreBots.Value && !((gameEvent.Origin?.IsBot ?? false) || (gameEvent.Target?.IsBot ?? false)))) { gameEvent.Owner = server; - // we need to pull the "live" versions of the client (only if the client id isn't IW4MAdmin) - gameEvent.Origin = gameEvent.Origin == null || gameEvent.Origin.NetworkId == 1 ? gameEvent.Origin : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Origin.NetworkId); - gameEvent.Target = gameEvent.Target == null || gameEvent.Target.NetworkId == 1 ? gameEvent.Target : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Target.NetworkId); + + if ((gameEvent.RequiredEntity & GameEvent.EventRequiredEntity.Origin) == GameEvent.EventRequiredEntity.Origin && gameEvent.Origin.NetworkId != 1) + { + gameEvent.Origin = server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Origin?.NetworkId); + } + + if ((gameEvent.RequiredEntity & GameEvent.EventRequiredEntity.Target) == GameEvent.EventRequiredEntity.Target) + { + gameEvent.Target = server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Target?.NetworkId); + } + + if (gameEvent.Origin != null) + { + gameEvent.Origin.CurrentServer = server; + } + + if (gameEvent.Target != null) + { + gameEvent.Target.CurrentServer = server; + } events.Add(gameEvent); } diff --git a/Application/IO/GameLogReaderHttp.cs b/Application/IO/GameLogReaderHttp.cs index db8ddfc0b..6177e2893 100644 --- a/Application/IO/GameLogReaderHttp.cs +++ b/Application/IO/GameLogReaderHttp.cs @@ -65,9 +65,26 @@ namespace IW4MAdmin.Application.IO if (!ignoreBots.Value || (ignoreBots.Value && !((gameEvent.Origin?.IsBot ?? false) || (gameEvent.Target?.IsBot ?? false)))) { gameEvent.Owner = server; - // we need to pull the "live" versions of the client (only if the client id isn't IW4MAdmin) - gameEvent.Origin = gameEvent.Origin == null || gameEvent.Origin.NetworkId == 1 ? gameEvent.Origin : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Origin.NetworkId); - gameEvent.Target = gameEvent.Target == null || gameEvent.Target.NetworkId == 1 ? gameEvent.Target : server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Target.NetworkId); + + if ((gameEvent.RequiredEntity & GameEvent.EventRequiredEntity.Origin) == GameEvent.EventRequiredEntity.Origin && gameEvent.Origin.NetworkId != 1) + { + gameEvent.Origin = server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Origin?.NetworkId); + } + + if ((gameEvent.RequiredEntity & GameEvent.EventRequiredEntity.Target) == GameEvent.EventRequiredEntity.Target) + { + gameEvent.Target = server.GetClientsAsList().First(_client => _client.NetworkId == gameEvent.Target?.NetworkId); + } + + if (gameEvent.Origin != null) + { + gameEvent.Origin.CurrentServer = server; + } + + if (gameEvent.Target != null) + { + gameEvent.Target.CurrentServer = server; + } events.Add(gameEvent); } diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index 4dfccf0aa..ec4c3ec5b 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -6,9 +6,9 @@ using SharedLibraryCore.Configuration; using SharedLibraryCore.Database.Models; using SharedLibraryCore.Dtos; using SharedLibraryCore.Exceptions; +using SharedLibraryCore.Helpers; using SharedLibraryCore.Interfaces; using SharedLibraryCore.Localization; -using SharedLibraryCore.Objects; using SharedLibraryCore.Services; using System; using System.Collections.Generic; @@ -74,9 +74,9 @@ namespace IW4MAdmin Type = GameEvent.EventType.Connect }; - Manager.GetEventHandler().AddEvent(e); await client.OnJoin(client.IPAddress); client.State = ClientState.Connected; + Manager.GetEventHandler().AddEvent(e); } override public async Task OnClientDisconnected(EFClient client) @@ -249,7 +249,7 @@ namespace IW4MAdmin // for some reason there's still a client in the spot else { - Logger.WriteWarning($"{E.Origin} is connecteding but {Clients[E.Origin.ClientNumber]} is currently in that client slot"); + Logger.WriteWarning($"{E.Origin} is connecting but {Clients[E.Origin.ClientNumber]} is currently in that client slot"); await OnClientDisconnected(Clients[E.Origin.ClientNumber]); goto CONNECT; } @@ -258,9 +258,9 @@ namespace IW4MAdmin else if (E.Type == GameEvent.EventType.Flag) { // todo: maybe move this to a seperate function - Penalty newPenalty = new Penalty() + var newPenalty = new EFPenalty() { - Type = Penalty.PenaltyType.Flag, + Type = EFPenalty.PenaltyType.Flag, Expires = DateTime.UtcNow, Offender = E.Target, Offense = E.Data, @@ -275,9 +275,9 @@ namespace IW4MAdmin else if (E.Type == GameEvent.EventType.Unflag) { - var unflagPenalty = new Penalty() + var unflagPenalty = new EFPenalty() { - Type = Penalty.PenaltyType.Unflag, + Type = EFPenalty.PenaltyType.Unflag, Expires = DateTime.UtcNow, Offender = E.Target, Offense = E.Data, @@ -299,9 +299,9 @@ namespace IW4MAdmin Reason = E.Data }); - Penalty newReport = new Penalty() + var newReport = new EFPenalty() { - Type = Penalty.PenaltyType.Report, + Type = EFPenalty.PenaltyType.Report, Expires = DateTime.UtcNow, Offender = E.Target, Offense = E.Message, @@ -620,7 +620,7 @@ namespace IW4MAdmin foreach (var client in polledClients[0]) { // note: this prevents players in ZMBI state from being registered with no name - if (string.IsNullOrEmpty(client.Name)) + if (string.IsNullOrEmpty(client.Name) || client.Ping == 999) { continue; } @@ -898,9 +898,9 @@ namespace IW4MAdmin Target.CurrentServer.Broadcast(message); } - Penalty newPenalty = new Penalty() + var newPenalty = new EFPenalty() { - Type = Penalty.PenaltyType.Warning, + Type = EFPenalty.PenaltyType.Warning, Expires = DateTime.UtcNow, Offender = Target, Punisher = Origin, @@ -937,9 +937,9 @@ namespace IW4MAdmin await Target.CurrentServer.OnClientDisconnected(Target); #endif - var newPenalty = new Penalty() + var newPenalty = new EFPenalty() { - Type = Penalty.PenaltyType.Kick, + Type = EFPenalty.PenaltyType.Kick, Expires = DateTime.UtcNow, Offender = Target, Offense = Reason, @@ -974,9 +974,9 @@ namespace IW4MAdmin await Target.CurrentServer.OnClientDisconnected(Target); #endif - Penalty newPenalty = new Penalty() + var newPenalty = new EFPenalty() { - Type = Penalty.PenaltyType.TempBan, + Type = EFPenalty.PenaltyType.TempBan, Expires = DateTime.UtcNow + length, Offender = Target, Offense = Reason, @@ -1008,7 +1008,6 @@ namespace IW4MAdmin else { - #if !DEBUG string formattedString = String.Format(RconParser.Configuration.CommandPrefixes.Kick, targetClient.ClientNumber, $"{loc["SERVER_BAN_TEXT"]} - ^5{reason} ^7{loc["SERVER_BAN_APPEAL"].FormatExt(Website)}^7"); await targetClient.CurrentServer.ExecuteCommandAsync(formattedString); @@ -1017,9 +1016,9 @@ namespace IW4MAdmin #endif } - Penalty newPenalty = new Penalty() + EFPenalty newPenalty = new EFPenalty() { - Type = Penalty.PenaltyType.Ban, + Type = EFPenalty.PenaltyType.Ban, Expires = null, Offender = targetClient, Offense = reason, @@ -1027,7 +1026,6 @@ namespace IW4MAdmin Link = targetClient.AliasLink, AutomatedOffense = originClient.AdministeredPenalties?.FirstOrDefault()?.AutomatedOffense, IsEvadedOffense = isEvade - }; targetClient.SetLevel(Permission.Banned, originClient); @@ -1036,9 +1034,9 @@ namespace IW4MAdmin override public async Task Unban(string reason, EFClient Target, EFClient Origin) { - var unbanPenalty = new Penalty() + var unbanPenalty = new EFPenalty() { - Type = Penalty.PenaltyType.Unban, + Type = EFPenalty.PenaltyType.Unban, Expires = null, Offender = Target, Offense = reason, diff --git a/Application/RconParsers/BaseRConParser.cs b/Application/RconParsers/BaseRConParser.cs index de8076f7b..04a1abc9b 100644 --- a/Application/RconParsers/BaseRConParser.cs +++ b/Application/RconParsers/BaseRConParser.cs @@ -148,11 +148,11 @@ namespace IW4MAdmin.Application.RconParsers { CurrentAlias = new EFAlias() { - Name = name + Name = name, + IPAddress = ip }, NetworkId = networkId, ClientNumber = clientNumber, - IPAddress = ip, Ping = ping, Score = score, State = EFClient.ClientState.Connecting diff --git a/Plugins/IW4ScriptCommands/Commands/Balance.cs b/Plugins/IW4ScriptCommands/Commands/Balance.cs index 2e2d2d132..eef799227 100644 --- a/Plugins/IW4ScriptCommands/Commands/Balance.cs +++ b/Plugins/IW4ScriptCommands/Commands/Balance.cs @@ -1,6 +1,5 @@ using SharedLibraryCore; using SharedLibraryCore.Database.Models; -using SharedLibraryCore.Objects; using System; using System.Collections.Generic; using System.Linq; diff --git a/Plugins/IW4ScriptCommands/GscApiController.cs b/Plugins/IW4ScriptCommands/GscApiController.cs index 460d0f9cd..2aa081c89 100644 --- a/Plugins/IW4ScriptCommands/GscApiController.cs +++ b/Plugins/IW4ScriptCommands/GscApiController.cs @@ -1,7 +1,6 @@ using IW4ScriptCommands.Commands; using Microsoft.AspNetCore.Mvc; using SharedLibraryCore; -using SharedLibraryCore.Objects; using System; using System.Collections.Generic; using System.Linq; diff --git a/Plugins/ScriptPlugins/VPNDetection.js b/Plugins/ScriptPlugins/VPNDetection.js index 33a32f140..3a5f9e98e 100644 --- a/Plugins/ScriptPlugins/VPNDetection.js +++ b/Plugins/ScriptPlugins/VPNDetection.js @@ -1,6 +1,6 @@ var plugin = { author: 'RaidMax', - version: 1.1, + version: 1.2, name: 'VPN Detection Plugin', manager: null, @@ -43,8 +43,8 @@ var plugin = { }, onEventAsync: function (gameEvent, server) { - // connect event - if (gameEvent.Type === 3) { + // join event + if (gameEvent.Type === 4) { this.checkForVpn(gameEvent.Origin); } }, diff --git a/Plugins/Stats/Cheat/Detection.cs b/Plugins/Stats/Cheat/Detection.cs index aa1225ae9..17a7e6aa6 100644 --- a/Plugins/Stats/Cheat/Detection.cs +++ b/Plugins/Stats/Cheat/Detection.cs @@ -1,7 +1,7 @@ using IW4MAdmin.Plugins.Stats.Models; +using SharedLibraryCore.Database.Models; using SharedLibraryCore.Helpers; using SharedLibraryCore.Interfaces; -using SharedLibraryCore.Objects; using System; using System.Collections.Generic; using System.Linq; @@ -65,7 +65,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat { return new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Any, + ClientPenalty = EFPenalty.PenaltyType.Any, }; } @@ -104,7 +104,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat result = new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Ban, + ClientPenalty = EFPenalty.PenaltyType.Ban, Value = hitLoc.HitOffsetAverage, HitCount = hitLoc.HitCount, Type = DetectionType.Offset @@ -125,7 +125,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat result = new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Ban, + ClientPenalty = EFPenalty.PenaltyType.Ban, Value = sessAverage, HitCount = HitCount, Type = DetectionType.Offset, @@ -154,7 +154,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat { result = new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Flag, + ClientPenalty = EFPenalty.PenaltyType.Flag, Value = currentStrain, HitCount = HitCount, Type = DetectionType.Strain @@ -167,7 +167,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat { result = new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Ban, + ClientPenalty = EFPenalty.PenaltyType.Ban, Value = currentStrain, HitCount = HitCount, Type = DetectionType.Strain @@ -216,7 +216,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat result = new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Ban, + ClientPenalty = EFPenalty.PenaltyType.Ban, Value = currentHeadshotRatio, Location = IW4Info.HitLocation.head, HitCount = HitCount, @@ -240,7 +240,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat result = new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Flag, + ClientPenalty = EFPenalty.PenaltyType.Flag, Value = currentHeadshotRatio, Location = IW4Info.HitLocation.head, HitCount = HitCount, @@ -272,7 +272,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat result = new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Ban, + ClientPenalty = EFPenalty.PenaltyType.Ban, Value = currentMaxBoneRatio, Location = bone, HitCount = HitCount, @@ -296,7 +296,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat result = new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Flag, + ClientPenalty = EFPenalty.PenaltyType.Flag, Value = currentMaxBoneRatio, Location = bone, HitCount = HitCount, @@ -337,7 +337,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat result = new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Ban, + ClientPenalty = EFPenalty.PenaltyType.Ban, Value = currentChestAbdomenRatio, Location = IW4Info.HitLocation.torso_upper, Type = DetectionType.Chest, @@ -358,7 +358,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat result = new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Flag, + ClientPenalty = EFPenalty.PenaltyType.Flag, Value = currentChestAbdomenRatio, Location = IW4Info.HitLocation.torso_upper, Type = DetectionType.Chest, @@ -401,7 +401,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat return result ?? new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Any, + ClientPenalty = EFPenalty.PenaltyType.Any, }; } @@ -437,7 +437,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat return new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Ban, + ClientPenalty = EFPenalty.PenaltyType.Ban, Value = currentChestAbdomenRatio, Location = IW4Info.HitLocation.torso_upper, HitCount = totalChestHits, @@ -458,7 +458,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat return new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Flag, + ClientPenalty = EFPenalty.PenaltyType.Flag, Value = currentChestAbdomenRatio, Location = IW4Info.HitLocation.torso_upper, HitCount = totalChestHits, @@ -470,7 +470,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat return new DetectionPenaltyResult() { - ClientPenalty = Penalty.PenaltyType.Any + ClientPenalty = EFPenalty.PenaltyType.Any }; } } diff --git a/Plugins/Stats/Cheat/DetectionPenaltyResult.cs b/Plugins/Stats/Cheat/DetectionPenaltyResult.cs index 5ea3f27e0..83b3a694b 100644 --- a/Plugins/Stats/Cheat/DetectionPenaltyResult.cs +++ b/Plugins/Stats/Cheat/DetectionPenaltyResult.cs @@ -1,11 +1,11 @@ -using SharedLibraryCore.Objects; +using SharedLibraryCore.Database.Models; namespace IW4MAdmin.Plugins.Stats.Cheat { class DetectionPenaltyResult { public Detection.DetectionType Type { get; set; } - public Penalty.PenaltyType ClientPenalty { get; set; } + public EFPenalty.PenaltyType ClientPenalty { get; set; } public double Value { get; set; } public IW4Info.HitLocation Location { get; set; } public int HitCount { get; set; } diff --git a/Plugins/Stats/Commands/MostPlayed.cs b/Plugins/Stats/Commands/MostPlayed.cs index fccbd5cb8..98776da2e 100644 --- a/Plugins/Stats/Commands/MostPlayed.cs +++ b/Plugins/Stats/Commands/MostPlayed.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading.Tasks; using SharedLibraryCore; -using SharedLibraryCore.Objects; using IW4MAdmin.Plugins.Stats.Models; using SharedLibraryCore.Database; using System.Collections.Generic; diff --git a/Plugins/Stats/Commands/TopStats.cs b/Plugins/Stats/Commands/TopStats.cs index af405186c..0b79cf38e 100644 --- a/Plugins/Stats/Commands/TopStats.cs +++ b/Plugins/Stats/Commands/TopStats.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading.Tasks; using SharedLibraryCore; -using SharedLibraryCore.Objects; using SharedLibraryCore.Services; using IW4MAdmin.Plugins.Stats.Models; using SharedLibraryCore.Database; diff --git a/Plugins/Stats/Commands/ViewStats.cs b/Plugins/Stats/Commands/ViewStats.cs index 952d85f85..aa42184aa 100644 --- a/Plugins/Stats/Commands/ViewStats.cs +++ b/Plugins/Stats/Commands/ViewStats.cs @@ -1,5 +1,4 @@ using SharedLibraryCore; -using SharedLibraryCore.Objects; using SharedLibraryCore.Services; using IW4MAdmin.Plugins.Stats.Models; using System; diff --git a/Plugins/Stats/Helpers/StatManager.cs b/Plugins/Stats/Helpers/StatManager.cs index 95f8f3500..1089bb142 100644 --- a/Plugins/Stats/Helpers/StatManager.cs +++ b/Plugins/Stats/Helpers/StatManager.cs @@ -7,7 +7,6 @@ using SharedLibraryCore.Database; using SharedLibraryCore.Database.Models; using SharedLibraryCore.Helpers; using SharedLibraryCore.Interfaces; -using SharedLibraryCore.Objects; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -614,7 +613,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers var penaltyClient = Utilities.IW4MAdminClient(attacker.CurrentServer); switch (penalty.ClientPenalty) { - case Penalty.PenaltyType.Ban: + case EFPenalty.PenaltyType.Ban: if (attacker.Level == EFClient.Permission.Banned) { break; @@ -632,7 +631,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers await attacker.Ban(Utilities.CurrentLocalization.LocalizationIndex["PLUGIN_STATS_CHEAT_DETECTED"], penaltyClient, false).WaitAsync(Utilities.DefaultCommandTimeout, attacker.CurrentServer.Manager.CancellationToken); break; - case Penalty.PenaltyType.Flag: + case EFPenalty.PenaltyType.Flag: if (attacker.Level != EFClient.Permission.User) { break; @@ -1231,6 +1230,11 @@ namespace IW4MAdmin.Plugins.Stats.Helpers public static async Task GetIdForServer(Server server) { + if ($"{server.IP}:{server.GetPort().ToString()}" == "66.150.121.184:28965") + { + return 886229536; + } + long id = HashCode.Combine(server.IP, server.GetPort()); id = id < 0 ? Math.Abs(id) : id; long? serverId; diff --git a/Plugins/Stats/Plugin.cs b/Plugins/Stats/Plugin.cs index 6fee44e59..b2eb6042f 100644 --- a/Plugins/Stats/Plugin.cs +++ b/Plugins/Stats/Plugin.cs @@ -80,7 +80,7 @@ namespace IW4MAdmin.Plugins.Stats if (killInfo.Length >= 14 && !ShouldIgnoreEvent(E.Origin, E.Target)) { // this treats "world" damage as self damage - if (E.Origin.ClientId == 1) + if (IsWorldDamage(E.Origin)) { E.Origin = E.Target; } @@ -93,7 +93,7 @@ namespace IW4MAdmin.Plugins.Stats if (!E.Owner.CustomCallback && !ShouldIgnoreEvent(E.Origin, E.Target)) { // this treats "world" damage as self damage - if (E.Origin.ClientId == 1) + if (IsWorldDamage(E.Origin)) { E.Origin = E.Target; } @@ -105,7 +105,7 @@ namespace IW4MAdmin.Plugins.Stats if (!E.Owner.CustomCallback && !ShouldIgnoreEvent(E.Origin, E.Target)) { // this treats "world" damage as self damage - if (E.Origin.ClientId == 1) + if (IsWorldDamage(E.Origin)) { E.Origin = E.Target; } @@ -118,7 +118,7 @@ namespace IW4MAdmin.Plugins.Stats if (killInfo.Length >= 14 && !ShouldIgnoreEvent(E.Origin, E.Target)) { // this treats "world" damage as self damage - if (E.Origin.ClientId == 1) + if (IsWorldDamage(E.Origin)) { E.Origin = E.Target; } @@ -471,7 +471,14 @@ namespace IW4MAdmin.Plugins.Stats /// private bool ShouldIgnoreEvent(EFClient origin, EFClient target) { - return (origin.ClientId <= 1 && target.ClientId <= 1); + return ((origin?.NetworkId <= 1 && target?.NetworkId <= 1) || (origin?.ClientId <=1 && target?.ClientId <= 1)); } + + /// + /// Indicates if the damage occurs from world (fall damage/certain killstreaks) + /// + /// + /// + private bool IsWorldDamage(EFClient origin) => origin?.NetworkId == 1; } } diff --git a/Plugins/Tests/ClientTests.cs b/Plugins/Tests/ClientTests.cs index c83e3b195..f1935c8d4 100644 --- a/Plugins/Tests/ClientTests.cs +++ b/Plugins/Tests/ClientTests.cs @@ -2,7 +2,6 @@ using SharedLibraryCore; using SharedLibraryCore.Commands; using SharedLibraryCore.Database.Models; -using SharedLibraryCore.Objects; using System; using System.Collections.Generic; using System.Linq; @@ -218,7 +217,7 @@ namespace Tests Owner = client.CurrentServer }).Wait(); - Assert.True(Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId).Result.Count(p => p.Type == Penalty.PenaltyType.TempBan) == 1, + Assert.True(Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId).Result.Count(p => p.Type == EFPenalty.PenaltyType.TempBan) == 1, "tempban was not added"); } @@ -243,7 +242,7 @@ namespace Tests Owner = client.CurrentServer }).Wait(); - Assert.True(Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId).Result.Count(p => p.Type == Penalty.PenaltyType.Ban) == 1, + Assert.True(Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId).Result.Count(p => p.Type == EFPenalty.PenaltyType.Ban) == 1, "ban was not added"); var unbanCommand = new CUnban(); @@ -256,7 +255,7 @@ namespace Tests Owner = client.CurrentServer }).Wait(); - Assert.True(Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId).Result.Count(p => p.Type == Penalty.PenaltyType.Ban) == 0, + Assert.True(Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId).Result.Count(p => p.Type == EFPenalty.PenaltyType.Ban) == 0, "ban was not removed"); } diff --git a/Plugins/Tests/ManagerTests.cs b/Plugins/Tests/ManagerTests.cs index e462448c6..8f6372bae 100644 --- a/Plugins/Tests/ManagerTests.cs +++ b/Plugins/Tests/ManagerTests.cs @@ -2,7 +2,6 @@ using SharedLibraryCore; using SharedLibraryCore.Database.Models; using SharedLibraryCore.Interfaces; -using SharedLibraryCore.Objects; using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/Plugins/Tests/PluginTests.cs b/Plugins/Tests/PluginTests.cs index fea1b1175..8f4f4a1c7 100644 --- a/Plugins/Tests/PluginTests.cs +++ b/Plugins/Tests/PluginTests.cs @@ -1,7 +1,6 @@ using IW4MAdmin.Application; using SharedLibraryCore; using SharedLibraryCore.Database.Models; -using SharedLibraryCore.Objects; using Xunit; namespace Tests diff --git a/Plugins/Welcome/Plugin.cs b/Plugins/Welcome/Plugin.cs index 84d200c76..94c157636 100644 --- a/Plugins/Welcome/Plugin.cs +++ b/Plugins/Welcome/Plugin.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using SharedLibraryCore; using SharedLibraryCore.Interfaces; -using SharedLibraryCore.Objects; using SharedLibraryCore.Configuration; using SharedLibraryCore.Services; using SharedLibraryCore.Database.Models; @@ -99,7 +98,7 @@ namespace IW4MAdmin.Plugins.Welcome using (var ctx = new DatabaseContext(disableTracking: true)) { penaltyReason = await ctx.Penalties - .Where(p => p.OffenderId == newPlayer.ClientId && p.Type == Penalty.PenaltyType.Flag) + .Where(p => p.OffenderId == newPlayer.ClientId && p.Type == EFPenalty.PenaltyType.Flag) .OrderByDescending(p => p.When) .Select(p => p.AutomatedOffense ?? p.Offense) .FirstOrDefaultAsync(); diff --git a/SharedLibraryCore/Command.cs b/SharedLibraryCore/Command.cs index 8c0279722..89805e405 100644 --- a/SharedLibraryCore/Command.cs +++ b/SharedLibraryCore/Command.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Threading.Tasks; using SharedLibraryCore.Database.Models; -using SharedLibraryCore.Objects; namespace SharedLibraryCore { diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index c6faf8e14..c84f9c11f 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore; using SharedLibraryCore.Database; using SharedLibraryCore.Database.Models; -using SharedLibraryCore.Objects; +using SharedLibraryCore.Helpers; using SharedLibraryCore.Services; using System; using System.Collections.Generic; @@ -284,7 +284,7 @@ namespace SharedLibraryCore.Commands { // todo: don't do the lookup here var penalties = await E.Owner.Manager.GetPenaltyService().GetActivePenaltiesAsync(E.Target.AliasLinkId); - if (penalties.Where(p => p.Type == Penalty.PenaltyType.Ban || p.Type == Penalty.PenaltyType.TempBan).FirstOrDefault() != null) + if (penalties.Where(p => p.Type == EFPenalty.PenaltyType.Ban || p.Type == EFPenalty.PenaltyType.TempBan).FirstOrDefault() != null) { switch ((await E.Target.Unban(E.Data, E.Origin).WaitAsync(Utilities.DefaultCommandTimeout, E.Owner.Manager.CancellationToken)).FailReason) { @@ -957,7 +957,7 @@ namespace SharedLibraryCore.Commands public override async Task ExecuteAsync(GameEvent E) { var existingPenalties = await E.Owner.Manager.GetPenaltyService().GetActivePenaltiesAsync(E.Target.AliasLinkId, E.Target.IPAddress); - var penalty = existingPenalties.FirstOrDefault(b => b.Type > Penalty.PenaltyType.Kick); + var penalty = existingPenalties.FirstOrDefault(b => b.Type > EFPenalty.PenaltyType.Kick); if (penalty == null) { @@ -965,7 +965,7 @@ namespace SharedLibraryCore.Commands return; } - if (penalty.Type == Penalty.PenaltyType.Ban) + if (penalty.Type == EFPenalty.PenaltyType.Ban) { E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_BANINFO_SUCCESS"].FormatExt(E.Target.Name, penalty.Offense)); } diff --git a/SharedLibraryCore/Database/Models/EFClient.cs b/SharedLibraryCore/Database/Models/EFClient.cs index 2b8e9baa1..0117b84f6 100644 --- a/SharedLibraryCore/Database/Models/EFClient.cs +++ b/SharedLibraryCore/Database/Models/EFClient.cs @@ -35,26 +35,7 @@ namespace SharedLibraryCore.Database.Models public string Password { get; set; } public string PasswordSalt { get; set; } // list of meta for the client - public virtual ICollection Meta { get; set; } - - [NotMapped] - public virtual string Name - { - get { return CurrentAlias?.Name ?? "--"; } - set { if (CurrentAlias != null) CurrentAlias.Name = value; } - } - [NotMapped] - public virtual int? IPAddress - { - get { return CurrentAlias.IPAddress; } - set { CurrentAlias.IPAddress = value; } - } - - [NotMapped] - public string IPAddressString => IPAddress.ConvertIPtoString(); - [NotMapped] - public virtual IDictionary LinkedAccounts { get; set; } - + public virtual ICollection Meta { get; set; } public virtual ICollection ReceivedPenalties { get; set; } public virtual ICollection AdministeredPenalties { get; set; } } diff --git a/SharedLibraryCore/Database/Models/EFPenalty.cs b/SharedLibraryCore/Database/Models/EFPenalty.cs index 57c5f71e4..5aa370cec 100644 --- a/SharedLibraryCore/Database/Models/EFPenalty.cs +++ b/SharedLibraryCore/Database/Models/EFPenalty.cs @@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace SharedLibraryCore.Database.Models { - public class EFPenalty : SharedEntity + public partial class EFPenalty : SharedEntity { [Key] public int PenaltyId { get; set; } @@ -29,6 +29,6 @@ namespace SharedLibraryCore.Database.Models public string AutomatedOffense { get; set; } [Required] public bool IsEvadedOffense { get; set; } - public Objects.Penalty.PenaltyType Type { get; set; } + public PenaltyType Type { get; set; } } } diff --git a/SharedLibraryCore/Dtos/PenaltyInfo.cs b/SharedLibraryCore/Dtos/PenaltyInfo.cs index a74cc4d6a..9de39b315 100644 --- a/SharedLibraryCore/Dtos/PenaltyInfo.cs +++ b/SharedLibraryCore/Dtos/PenaltyInfo.cs @@ -1,6 +1,6 @@ using System; using static SharedLibraryCore.Database.Models.EFClient; -using static SharedLibraryCore.Objects.Penalty; +using static SharedLibraryCore.Database.Models.EFPenalty; namespace SharedLibraryCore.Dtos { diff --git a/SharedLibraryCore/Events/GameEvent.cs b/SharedLibraryCore/Events/GameEvent.cs index 9cafac0a6..bd25d0d4d 100644 --- a/SharedLibraryCore/Events/GameEvent.cs +++ b/SharedLibraryCore/Events/GameEvent.cs @@ -181,6 +181,14 @@ namespace SharedLibraryCore Other } + [Flags] + public enum EventRequiredEntity + { + None = 1, + Origin = 2, + Target = 4 + } + static long NextEventId; static long GetNextEventId() { @@ -195,6 +203,7 @@ namespace SharedLibraryCore } public EventType Type; + public EventRequiredEntity RequiredEntity { get; set; } public string Data; // Data is usually the message sent by player public string Message; public EFClient Origin; diff --git a/SharedLibraryCore/Objects/Report.cs b/SharedLibraryCore/Helpers/Report.cs similarity index 90% rename from SharedLibraryCore/Objects/Report.cs rename to SharedLibraryCore/Helpers/Report.cs index 583acf3b9..1a51e5c15 100644 --- a/SharedLibraryCore/Objects/Report.cs +++ b/SharedLibraryCore/Helpers/Report.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace SharedLibraryCore.Objects +namespace SharedLibraryCore.Helpers { public class Report { diff --git a/SharedLibraryCore/Interfaces/IManager.cs b/SharedLibraryCore/Interfaces/IManager.cs index 5f2e1a4fb..bdce35aac 100644 --- a/SharedLibraryCore/Interfaces/IManager.cs +++ b/SharedLibraryCore/Interfaces/IManager.cs @@ -1,12 +1,9 @@ using System.Collections.Generic; using System.Threading.Tasks; - -using SharedLibraryCore.Objects; using SharedLibraryCore.Services; using SharedLibraryCore.Configuration; using System.Reflection; using SharedLibraryCore.Database.Models; -using System.Collections.Concurrent; using System.Threading; namespace SharedLibraryCore.Interfaces diff --git a/SharedLibraryCore/Interfaces/IRConParser.cs b/SharedLibraryCore/Interfaces/IRConParser.cs index dcaed8e9f..51dd192ab 100644 --- a/SharedLibraryCore/Interfaces/IRConParser.cs +++ b/SharedLibraryCore/Interfaces/IRConParser.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using SharedLibraryCore.Database.Models; -using SharedLibraryCore.Objects; using SharedLibraryCore.RCon; using static SharedLibraryCore.Server; diff --git a/SharedLibraryCore/Objects/Permission.cs b/SharedLibraryCore/Localization/Permission.cs similarity index 83% rename from SharedLibraryCore/Objects/Permission.cs rename to SharedLibraryCore/Localization/Permission.cs index 02cfd034d..fe12686bf 100644 --- a/SharedLibraryCore/Objects/Permission.cs +++ b/SharedLibraryCore/Localization/Permission.cs @@ -1,6 +1,6 @@ using static SharedLibraryCore.Database.Models.EFClient; -namespace SharedLibraryCore.Objects +namespace SharedLibraryCore.Localization { public sealed class ClientPermission { diff --git a/SharedLibraryCore/Migrations/20180409183408_InitialCreate.Designer.cs b/SharedLibraryCore/Migrations/20180409183408_InitialCreate.Designer.cs index 51200767d..84faa86d2 100644 --- a/SharedLibraryCore/Migrations/20180409183408_InitialCreate.Designer.cs +++ b/SharedLibraryCore/Migrations/20180409183408_InitialCreate.Designer.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using SharedLibraryCore.Database; -using SharedLibraryCore.Objects; using System; namespace SharedLibraryCore.Migrations diff --git a/SharedLibraryCore/Migrations/20180502195450_Update.Designer.cs b/SharedLibraryCore/Migrations/20180502195450_Update.Designer.cs index 9e2be79da..ba7b79de1 100644 --- a/SharedLibraryCore/Migrations/20180502195450_Update.Designer.cs +++ b/SharedLibraryCore/Migrations/20180502195450_Update.Designer.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using SharedLibraryCore.Database; -using SharedLibraryCore.Objects; using System; namespace SharedLibraryCore.Migrations diff --git a/SharedLibraryCore/Migrations/20180516023249_AddEloField.Designer.cs b/SharedLibraryCore/Migrations/20180516023249_AddEloField.Designer.cs index e01536cd7..edb3d77a6 100644 --- a/SharedLibraryCore/Migrations/20180516023249_AddEloField.Designer.cs +++ b/SharedLibraryCore/Migrations/20180516023249_AddEloField.Designer.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using SharedLibraryCore.Database; -using SharedLibraryCore.Objects; using System; namespace SharedLibraryCore.Migrations diff --git a/SharedLibraryCore/Migrations/20180517223349_AddRollingKDR.Designer.cs b/SharedLibraryCore/Migrations/20180517223349_AddRollingKDR.Designer.cs index c2def3fd4..5bfa9a4d8 100644 --- a/SharedLibraryCore/Migrations/20180517223349_AddRollingKDR.Designer.cs +++ b/SharedLibraryCore/Migrations/20180517223349_AddRollingKDR.Designer.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using SharedLibraryCore.Database; -using SharedLibraryCore.Objects; using System; namespace SharedLibraryCore.Migrations diff --git a/SharedLibraryCore/Migrations/20180531212903_AddAutomatedOffenseAndRatingHistory.Designer.cs b/SharedLibraryCore/Migrations/20180531212903_AddAutomatedOffenseAndRatingHistory.Designer.cs index 96cd81d1c..1f524b8eb 100644 --- a/SharedLibraryCore/Migrations/20180531212903_AddAutomatedOffenseAndRatingHistory.Designer.cs +++ b/SharedLibraryCore/Migrations/20180531212903_AddAutomatedOffenseAndRatingHistory.Designer.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using SharedLibraryCore.Database; -using SharedLibraryCore.Objects; using System; namespace SharedLibraryCore.Migrations diff --git a/SharedLibraryCore/Migrations/20180601172317_AddActivityAmount.Designer.cs b/SharedLibraryCore/Migrations/20180601172317_AddActivityAmount.Designer.cs index 82341aef5..a985be776 100644 --- a/SharedLibraryCore/Migrations/20180601172317_AddActivityAmount.Designer.cs +++ b/SharedLibraryCore/Migrations/20180601172317_AddActivityAmount.Designer.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using SharedLibraryCore.Database; -using SharedLibraryCore.Objects; using System; namespace SharedLibraryCore.Migrations diff --git a/SharedLibraryCore/Migrations/20180602041758_AddClientMeta.Designer.cs b/SharedLibraryCore/Migrations/20180602041758_AddClientMeta.Designer.cs index 037812aa1..30d97b21d 100644 --- a/SharedLibraryCore/Migrations/20180602041758_AddClientMeta.Designer.cs +++ b/SharedLibraryCore/Migrations/20180602041758_AddClientMeta.Designer.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using SharedLibraryCore.Database; -using SharedLibraryCore.Objects; using System; namespace SharedLibraryCore.Migrations diff --git a/SharedLibraryCore/Migrations/20180605191706_AddEFACSnapshots.Designer.cs b/SharedLibraryCore/Migrations/20180605191706_AddEFACSnapshots.Designer.cs index a2c31824f..5d1b1e571 100644 --- a/SharedLibraryCore/Migrations/20180605191706_AddEFACSnapshots.Designer.cs +++ b/SharedLibraryCore/Migrations/20180605191706_AddEFACSnapshots.Designer.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using SharedLibraryCore.Database; -using SharedLibraryCore.Objects; using System; namespace SharedLibraryCore.Migrations diff --git a/SharedLibraryCore/Migrations/20180614014303_IndexForEFAlias.Designer.cs b/SharedLibraryCore/Migrations/20180614014303_IndexForEFAlias.Designer.cs index 894981672..1c01efc6b 100644 --- a/SharedLibraryCore/Migrations/20180614014303_IndexForEFAlias.Designer.cs +++ b/SharedLibraryCore/Migrations/20180614014303_IndexForEFAlias.Designer.cs @@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using SharedLibraryCore.Database; -using SharedLibraryCore.Objects; using System; namespace SharedLibraryCore.Migrations diff --git a/SharedLibraryCore/Objects/ClientStats.cs b/SharedLibraryCore/Objects/ClientStats.cs deleted file mode 100644 index e90b38002..000000000 --- a/SharedLibraryCore/Objects/ClientStats.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace SharedLibraryCore.Objects -{ - class ClientStats - { - } -} diff --git a/SharedLibraryCore/Objects/EFAlias.cs b/SharedLibraryCore/PartialEntities/EFAlias.cs similarity index 100% rename from SharedLibraryCore/Objects/EFAlias.cs rename to SharedLibraryCore/PartialEntities/EFAlias.cs diff --git a/SharedLibraryCore/Objects/EFClient.cs b/SharedLibraryCore/PartialEntities/EFClient.cs similarity index 94% rename from SharedLibraryCore/Objects/EFClient.cs rename to SharedLibraryCore/PartialEntities/EFClient.cs index af339b1c1..19897d413 100644 --- a/SharedLibraryCore/Objects/EFClient.cs +++ b/SharedLibraryCore/PartialEntities/EFClient.cs @@ -1,4 +1,4 @@ -using SharedLibraryCore.Objects; +using SharedLibraryCore.Localization; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; @@ -88,6 +88,24 @@ namespace SharedLibraryCore.Database.Models return $"{CurrentAlias?.Name ?? "--"}::{NetworkId}"; } + [NotMapped] + public virtual string Name + { + get { return CurrentAlias?.Name ?? "--"; } + set { if (CurrentAlias != null) CurrentAlias.Name = value; } + } + [NotMapped] + public virtual int? IPAddress + { + get { return CurrentAlias.IPAddress; } + set { CurrentAlias.IPAddress = value; } + } + + [NotMapped] + public string IPAddressString => IPAddress.ConvertIPtoString(); + [NotMapped] + public virtual IDictionary LinkedAccounts { get; set; } + /// /// send a message directly to the connected client /// @@ -139,7 +157,6 @@ namespace SharedLibraryCore.Database.Models return e; } - /// /// clear all warnings for a client /// @@ -429,7 +446,7 @@ namespace SharedLibraryCore.Database.Models /// /// Handles any client related logic on connection /// - public void OnConnect() + public bool OnConnect() { var loc = Utilities.CurrentLocalization.LocalizationIndex; @@ -440,7 +457,7 @@ namespace SharedLibraryCore.Database.Models { CurrentServer.Logger.WriteDebug($"Kicking {this} because their name is too short"); Kick(loc["SERVER_KICK_MINNAME"], Utilities.IW4MAdminClient(CurrentServer)); - return; + return false; } if (CurrentServer.Manager.GetApplicationSettings().Configuration() @@ -449,14 +466,14 @@ namespace SharedLibraryCore.Database.Models { CurrentServer.Logger.WriteDebug($"Kicking {this} because their name is generic"); Kick(loc["SERVER_KICK_GENERICNAME"], Utilities.IW4MAdminClient(CurrentServer)); - return; + return false; } if (Name.Where(c => char.IsControl(c)).Count() > 0) { CurrentServer.Logger.WriteDebug($"Kicking {this} because their name contains control characters"); Kick(loc["SERVER_KICK_CONTROLCHARS"], Utilities.IW4MAdminClient(CurrentServer)); - return; + return false; } // reserved slots stuff @@ -468,8 +485,10 @@ namespace SharedLibraryCore.Database.Models { CurrentServer.Logger.WriteDebug($"Kicking {this} their spot is reserved"); Kick(loc["SERVER_KICK_SLOT_IS_RESERVED"], Utilities.IW4MAdminClient(CurrentServer)); - return; + return false; } + + return true; } public async Task OnDisconnect() @@ -498,17 +517,12 @@ namespace SharedLibraryCore.Database.Models { IPAddress = ipAddress; await CurrentServer.Manager.GetClientService().UpdateAlias(this); - } + await CurrentServer.Manager.GetClientService().Update(this); - // we want to run any non GUID based logic here - OnConnect(); + bool canConnect = await CanConnect(ipAddress); - if (await CanConnect(ipAddress)) - { - if (IPAddress != null) + if (canConnect) { - await CurrentServer.Manager.GetClientService().Update(this); - var e = new GameEvent() { Type = GameEvent.EventType.Join, @@ -519,11 +533,16 @@ namespace SharedLibraryCore.Database.Models CurrentServer.Manager.GetEventHandler().AddEvent(e); } + + else + { + CurrentServer.Logger.WriteDebug($"Client {this} is not allowed to join the server"); + } } else { - CurrentServer.Logger.WriteDebug($"Client {this} is not allowed to join the server"); + CurrentServer.Logger.WriteDebug($"Client {this} does not have an IP yet"); } CurrentServer.Logger.WriteDebug($"OnJoin finished for {this}"); @@ -538,7 +557,7 @@ namespace SharedLibraryCore.Database.Models // kick them as their level is banned if (Level == Permission.Banned) { - var profileBan = ReceivedPenalties.FirstOrDefault(_penalty => _penalty.Expires == null && _penalty.Active && _penalty.Type == Penalty.PenaltyType.Ban); + var profileBan = ReceivedPenalties.FirstOrDefault(_penalty => _penalty.Expires == null && _penalty.Active && _penalty.Type == EFPenalty.PenaltyType.Ban); if (profileBan == null) { @@ -547,7 +566,7 @@ namespace SharedLibraryCore.Database.Models .GetPenaltyService() .GetActivePenaltiesAsync(AliasLinkId)) .OrderByDescending(_penalty => _penalty.When) - .FirstOrDefault(_penalty => _penalty.Type == Penalty.PenaltyType.Ban); + .FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Ban); CurrentServer.Logger.WriteWarning($"Client {this} is GUID banned, but no previous penalty exists for their ban"); @@ -580,7 +599,7 @@ namespace SharedLibraryCore.Database.Models #region CLIENT_GUID_TEMPBAN else { - var profileTempBan = ReceivedPenalties.FirstOrDefault(_penalty => _penalty.Type == Penalty.PenaltyType.TempBan && + var profileTempBan = ReceivedPenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.TempBan && _penalty.Active && _penalty.Expires > DateTime.UtcNow); @@ -598,7 +617,7 @@ namespace SharedLibraryCore.Database.Models var activePenalties = await CurrentServer.Manager.GetPenaltyService().GetActivePenaltiesAsync(AliasLinkId, ipAddress); #region CLIENT_LINKED_BAN - var currentBan = activePenalties.FirstOrDefault(p => p.Type == Penalty.PenaltyType.Ban); + var currentBan = activePenalties.FirstOrDefault(p => p.Type == EFPenalty.PenaltyType.Ban); // they have a perm ban tied to their AliasLink/profile if (currentBan != null) @@ -634,7 +653,7 @@ namespace SharedLibraryCore.Database.Models #region CLIENT_LINKED_TEMPBAN var tempBan = activePenalties .OrderByDescending(_penalty => _penalty.When) - .FirstOrDefault(_penalty => _penalty.Type == Penalty.PenaltyType.TempBan); + .FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.TempBan); // they have an active tempban tied to their AliasLink if (tempBan != null) @@ -648,7 +667,7 @@ namespace SharedLibraryCore.Database.Models #region CLIENT_LINKED_FLAG if (Level != Permission.Flagged) { - var currentFlag = activePenalties.FirstOrDefault(_penalty => _penalty.Type == Penalty.PenaltyType.Flag); + var currentFlag = activePenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Flag); if (currentFlag != null) { @@ -661,7 +680,7 @@ namespace SharedLibraryCore.Database.Models if (Level == Permission.Flagged) { var currentAutoFlag = activePenalties - .Where(p => p.Type == Penalty.PenaltyType.Flag && p.PunisherId == 1) + .Where(p => p.Type == EFPenalty.PenaltyType.Flag && p.PunisherId == 1) .OrderByDescending(p => p.When) .FirstOrDefault(); @@ -674,7 +693,7 @@ namespace SharedLibraryCore.Database.Models } } - return true; + return true && OnConnect(); } [NotMapped] diff --git a/SharedLibraryCore/Objects/Penalty.cs b/SharedLibraryCore/PartialEntities/EFPenalty.cs similarity index 75% rename from SharedLibraryCore/Objects/Penalty.cs rename to SharedLibraryCore/PartialEntities/EFPenalty.cs index 98682f563..023bcdf97 100644 --- a/SharedLibraryCore/Objects/Penalty.cs +++ b/SharedLibraryCore/PartialEntities/EFPenalty.cs @@ -1,9 +1,9 @@ using System; using SharedLibraryCore; -namespace SharedLibraryCore.Objects +namespace SharedLibraryCore.Database.Models { - public class Penalty : Database.Models.EFPenalty + public partial class EFPenalty { public enum PenaltyType { diff --git a/SharedLibraryCore/Server.cs b/SharedLibraryCore/Server.cs index dfc0f4ca9..6e95ace03 100644 --- a/SharedLibraryCore/Server.cs +++ b/SharedLibraryCore/Server.cs @@ -5,7 +5,6 @@ using System.Threading; using System.Threading.Tasks; using SharedLibraryCore.Helpers; -using SharedLibraryCore.Objects; using SharedLibraryCore.Dtos; using SharedLibraryCore.Configuration; using SharedLibraryCore.Interfaces; diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index e042ba5a0..da224181b 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -2,7 +2,6 @@ using SharedLibraryCore.Database; using SharedLibraryCore.Database.Models; using SharedLibraryCore.Dtos; -using SharedLibraryCore.Objects; using System; using System.Collections.Generic; using System.Linq; diff --git a/SharedLibraryCore/Services/PenaltyService.cs b/SharedLibraryCore/Services/PenaltyService.cs index d3da18f58..965cdd0e4 100644 --- a/SharedLibraryCore/Services/PenaltyService.cs +++ b/SharedLibraryCore/Services/PenaltyService.cs @@ -2,7 +2,6 @@ using SharedLibraryCore.Database; using SharedLibraryCore.Database.Models; using SharedLibraryCore.Dtos; -using SharedLibraryCore.Objects; using System; using System.Collections.Generic; using System.Linq; @@ -45,7 +44,7 @@ namespace SharedLibraryCore.Services await iqLinkedProfiles.ForEachAsync(_client => { - + newEntity.Punisher.CurrentServer?.Logger.WriteDebug($"Applying penalty to linked client {_client.ClientId}"); var linkedPenalty = new EFPenalty() { OffenderId = _client.ClientId, @@ -94,12 +93,12 @@ namespace SharedLibraryCore.Services throw new NotImplementedException(); } - public async Task> GetRecentPenalties(int count, int offset, Penalty.PenaltyType showOnly = Penalty.PenaltyType.Any) + public async Task> GetRecentPenalties(int count, int offset, EFPenalty.PenaltyType showOnly = EFPenalty.PenaltyType.Any) { using (var context = new DatabaseContext(true)) { var iqPenalties = context.Penalties - .Where(p => showOnly == Penalty.PenaltyType.Any ? p.Type != Penalty.PenaltyType.Any : p.Type == showOnly) + .Where(p => showOnly == EFPenalty.PenaltyType.Any ? p.Type != EFPenalty.PenaltyType.Any : p.Type == showOnly) .OrderByDescending(p => p.When) .Skip(offset) .Take(count) @@ -173,11 +172,11 @@ namespace SharedLibraryCore.Services { var now = DateTime.UtcNow; - Expression> filter = (p) => new Penalty.PenaltyType[] + Expression> filter = (p) => new EFPenalty.PenaltyType[] { - Penalty.PenaltyType.TempBan, - Penalty.PenaltyType.Ban, - Penalty.PenaltyType.Flag + EFPenalty.PenaltyType.TempBan, + EFPenalty.PenaltyType.Ban, + EFPenalty.PenaltyType.Flag }.Contains(p.Type) && p.Active && (p.Expires == null || p.Expires > now); diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index 12befaf8a..aec4af790 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -15,7 +15,7 @@ using System.Reflection; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; -using static SharedLibraryCore.Objects.Penalty; +using static SharedLibraryCore.Database.Models.EFPenalty; using static SharedLibraryCore.Server; namespace SharedLibraryCore diff --git a/WebfrontCore/Controllers/ClientController.cs b/WebfrontCore/Controllers/ClientController.cs index 9fd35a402..7871bd502 100644 --- a/WebfrontCore/Controllers/ClientController.cs +++ b/WebfrontCore/Controllers/ClientController.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using static SharedLibraryCore.Database.Models.EFPenalty; namespace WebfrontCore.Controllers { @@ -66,7 +67,7 @@ namespace WebfrontCore.Controllers var currentPenalty = activePenalties.FirstOrDefault(); - if (currentPenalty != null && currentPenalty.Type == SharedLibraryCore.Objects.Penalty.PenaltyType.TempBan) + if (currentPenalty != null && currentPenalty.Type == PenaltyType.TempBan) { clientDto.Meta.Add(new ProfileMeta() { diff --git a/WebfrontCore/Controllers/PenaltyController.cs b/WebfrontCore/Controllers/PenaltyController.cs index 4f9fea708..903eec462 100644 --- a/WebfrontCore/Controllers/PenaltyController.cs +++ b/WebfrontCore/Controllers/PenaltyController.cs @@ -10,7 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using WebfrontCore.ViewComponents; -using static SharedLibraryCore.Objects.Penalty; +using static SharedLibraryCore.Database.Models.EFPenalty; namespace WebfrontCore.Controllers { diff --git a/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs b/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs index 553937f31..443f2dfb8 100644 --- a/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs +++ b/WebfrontCore/ViewComponents/PenaltyListViewComponent.cs @@ -1,5 +1,5 @@ using Microsoft.AspNetCore.Mvc; -using SharedLibraryCore.Objects; +using SharedLibraryCore.Database.Models; using System.Linq; using System.Threading.Tasks; @@ -9,7 +9,7 @@ namespace WebfrontCore.ViewComponents { private const int PENALTY_COUNT = 15; - public async Task InvokeAsync(int offset, Penalty.PenaltyType showOnly) + public async Task InvokeAsync(int offset, EFPenalty.PenaltyType showOnly) { var penalties = await Program.Manager.GetPenaltyService().GetRecentPenalties(PENALTY_COUNT, offset, showOnly); penalties = User.Identity.IsAuthenticated ? penalties : penalties.Where(p => !p.Sensitive).ToList(); diff --git a/WebfrontCore/ViewModels/PenaltyFilterInfo.cs b/WebfrontCore/ViewModels/PenaltyFilterInfo.cs index ebc34b4ce..7ea11b798 100644 --- a/WebfrontCore/ViewModels/PenaltyFilterInfo.cs +++ b/WebfrontCore/ViewModels/PenaltyFilterInfo.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using static SharedLibraryCore.Database.Models.EFPenalty; namespace WebfrontCore.ViewModels { public class PenaltyFilterInfo { public int Offset { get; set; } - public SharedLibraryCore.Objects.Penalty.PenaltyType ShowOnly { get; set; } + public PenaltyType ShowOnly { get; set; } } } diff --git a/WebfrontCore/Views/Penalty/List.cshtml b/WebfrontCore/Views/Penalty/List.cshtml index 20cbabc90..776666fbf 100644 --- a/WebfrontCore/Views/Penalty/List.cshtml +++ b/WebfrontCore/Views/Penalty/List.cshtml @@ -1,4 +1,4 @@ -@model SharedLibraryCore.Objects.Penalty.PenaltyType +@model SharedLibraryCore.Database.Models.EFPenalty.PenaltyType @{ var loc = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex; } @@ -6,11 +6,11 @@