diff --git a/Application/Application.csproj b/Application/Application.csproj index 3c97ef03d..b7359761d 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -29,6 +29,7 @@ true + true diff --git a/Application/Server.cs b/Application/Server.cs index 28f131207..308c09e30 100644 --- a/Application/Server.cs +++ b/Application/Server.cs @@ -186,7 +186,7 @@ namespace IW4MAdmin // reserved slots stuff if ((MaxClients - ClientNum) < ServerConfig.ReservedSlotNumber && - ! player.IsPrivileged()) + !player.IsPrivileged()) { Logger.WriteDebug($"Kicking {polledPlayer} their spot is reserved"); string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, loc["SERVER_KICK_SLOT_IS_RESERVED"]); @@ -254,6 +254,7 @@ namespace IW4MAdmin } if (!Manager.GetApplicationSettings().Configuration().EnableClientVPNs && + Manager.GetApplicationSettings().Configuration().VpnExceptionIds?.FirstOrDefault(i => i == player.ClientId) != null && await VPNCheck.UsingVPN(player.IPAddressString, Manager.GetApplicationSettings().Configuration().IPHubAPIKey)) { await player.Kick(Utilities.CurrentLocalization.LocalizationIndex["SERVER_KICK_VPNS_NOTALLOWED"], new Player() { ClientId = 1 }); @@ -330,8 +331,8 @@ namespace IW4MAdmin public override async Task ExecuteEvent(GameEvent E) { bool canExecuteCommand = true; - await ProcessEvent(E); Manager.GetEventApi().OnServerEvent(this, E); + await ProcessEvent(E); Command C = null; if (E.Type == GameEvent.EventType.Command) @@ -989,6 +990,17 @@ namespace IW4MAdmin { // this is set only because they're still in the server. Target.Level = Player.Permission.Banned; + + // let the api know that a ban occured + Manager.GetEventHandler().AddEvent(new GameEvent() + { + Type = GameEvent.EventType.Ban, + Data = Message, + Origin = Origin, + Target = Target, + Owner = this + }); + #if !DEBUG string formattedString = String.Format(RconParser.GetCommandPrefixes().Kick, Target.ClientNumber, $"{loc["SERVER_BAN_TEXT"]} - ^5{Message} ^7({loc["SERVER_BAN_APPEAL"]} {Website})^7"); await Target.CurrentServer.ExecuteCommandAsync(formattedString); diff --git a/DiscordWebhook/DiscordWebhook.py b/DiscordWebhook/DiscordWebhook.py index 77c5554e8..e058b8442 100644 --- a/DiscordWebhook/DiscordWebhook.py +++ b/DiscordWebhook/DiscordWebhook.py @@ -2,6 +2,7 @@ import requests import time import json import collections +import os # the following classes model the discord webhook api parameters class WebhookAuthor(): @@ -45,13 +46,18 @@ class WebhookParams(): # gets the relative link to a user's profile def get_client_profile(profile_id): - return '{}/Client/ProfileAsync/{}'.format(base_url, str(profile_id)) + return u'{}/Client/ProfileAsync/{}'.format(base_url, profile_id) def get_client_profile_markdown(client_name, profile_id): - return '[{}]({})'.format(client_name, get_client_profile(profile_id)) + return u'[{}]({})'.format(client_name, get_client_profile(profile_id)) #todo: exception handling for opening the file -with open('config.json') as json_config_file: +if os.getenv("DEBUG"): + config_file_name = 'config.dev.json' +else: + config_file_name = 'config.json' + +with open(config_file_name) as json_config_file: json_config = json.load(json_config_file) # this should be an URL to an IP or FQN to an IW4MAdmin instance @@ -79,11 +85,11 @@ def get_new_events(): server_name = event['ownerEntity']['name'] if event['originEntity']: - origin_client_name = str(event['originEntity']['name']) + origin_client_name = event['originEntity']['name'] origin_client_id = int(event['originEntity']['id']) if event['targetEntity']: - target_client_name = str(event['targetEntity']['name']) or '' + target_client_name = event['targetEntity']['name'] or '' target_client_id = int(event['targetEntity']['id']) or 0 webhook_item = WebhookParams() @@ -146,7 +152,7 @@ def get_new_events(): elif event_type == 'Say': say_client_field = WebhookField('Player', get_client_profile_markdown(origin_client_name, origin_client_id)) - message_field = WebhookField('Message', str(event['extraInfo'])) + message_field = WebhookField('Message', event['extraInfo']) webhook_item_embed.title = 'Message From Player' webhook_item_embed.fields.append(say_client_field) @@ -181,8 +187,9 @@ def execute_webhook(data): if event['notify']: url = discord_webhook_notification_url - elif len(discord_webhook_information_url) > 0: - url = discord_webhook_information_url + else: + if len(discord_webhook_information_url) > 0: + url = discord_webhook_information_url if url : response = requests.post(url, @@ -197,8 +204,9 @@ def run(): try: new_events = get_new_events() execute_webhook(new_events) - except: + except Exception as e: print('failed to get new events ({})'.format(failed_count)) + print(e) failed_count += 1 time.sleep(5) diff --git a/DiscordWebhook/DiscordWebhook.pyproj b/DiscordWebhook/DiscordWebhook.pyproj index e0113872e..1a1ee7ea4 100644 --- a/DiscordWebhook/DiscordWebhook.pyproj +++ b/DiscordWebhook/DiscordWebhook.pyproj @@ -12,6 +12,10 @@ DiscordWebhook DiscordWebhook MSBuild|env|$(MSBuildProjectFullPath) + False + Standard Python launcher + False + DEBUG=True true diff --git a/Plugins/Stats/Config/StatsConfiguration.cs b/Plugins/Stats/Config/StatsConfiguration.cs index 232df85bf..07dccbace 100644 --- a/Plugins/Stats/Config/StatsConfiguration.cs +++ b/Plugins/Stats/Config/StatsConfiguration.cs @@ -9,6 +9,7 @@ namespace IW4MAdmin.Plugins.Stats.Config public bool EnableAntiCheat { get; set; } public List KillstreakMessages { get; set; } public List DeathstreakMessages { get; set; } + public int TopPlayersMinPlayTime { get; set; } public string Name() => "Stats"; public IBaseConfiguration Generate() { @@ -47,6 +48,8 @@ namespace IW4MAdmin.Plugins.Stats.Config }, }; + TopPlayersMinPlayTime = 3600 * 3; + return this; } } diff --git a/Plugins/Stats/Helpers/StatManager.cs b/Plugins/Stats/Helpers/StatManager.cs index 221959b8b..cf519359a 100644 --- a/Plugins/Stats/Helpers/StatManager.cs +++ b/Plugins/Stats/Helpers/StatManager.cs @@ -46,7 +46,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers var thirtyDaysAgo = DateTime.UtcNow.AddMonths(-1); var iqClientRatings = (from rating in context.Set() #if !DEBUG - where rating.ActivityAmount > 10800 + where rating.ActivityAmount >= Plugin.Config.Configuration().TopPlayersMinPlayTime #endif where rating.RatingHistory.Client.Level != Player.Permission.Banned where rating.RatingHistory.Client.LastConnection > thirtyDaysAgo diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index cca2cd52b..b7142e62a 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -217,15 +217,6 @@ namespace SharedLibraryCore.Commands { await E.Target.Ban(E.Data, E.Origin); await E.Origin.Tell($"^5{E.Target} ^7{Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_BAN_SUCCESS"]}"); - - E.Owner.Manager.GetEventHandler().AddEvent(new GameEvent() - { - Type = GameEvent.EventType.Ban, - Data = E.Data, - Origin = E.Origin, - Target = E.Target, - Owner = E.Owner - }); } else await E.Origin.Tell($"{Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_BAN_FAIL"]} {E.Target.Name}"); diff --git a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs index 4a6fa88dc..953b62efb 100644 --- a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs +++ b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs @@ -28,12 +28,13 @@ namespace SharedLibraryCore.Configuration public List AutoMessages { get; set; } public List GlobalRules { get; set; } public List Maps { get; set; } + public List VpnExceptionIds { get; set; } public IBaseConfiguration Generate() { var loc = Utilities.CurrentLocalization.LocalizationIndex; Id = Guid.NewGuid().ToString(); - + EnableWebFront = Utilities.PromptBool(loc["SETUP_ENABLE_WEBFRONT"]); EnableMultipleOwners = Utilities.PromptBool(loc["SETUP_ENABLE_MULTIOWN"]); EnableSteppedHierarchy = Utilities.PromptBool(loc["SETUP_ENABLE_STEPPEDPRIV"]); @@ -59,7 +60,7 @@ namespace SharedLibraryCore.Configuration SocialLinkTitle = Utilities.PromptString(loc["SETUP_SOCIAL_TITLE"]); SocialLinkAddress = Utilities.PromptString(loc["SETUP_SOCIAL_LINK"]); } - + VpnExceptionIds = new List(); RConPollRate = 5000; return this; diff --git a/SharedLibraryCore/SharedLibraryCore.csproj b/SharedLibraryCore/SharedLibraryCore.csproj index e0e0cdda3..c9da3cf31 100644 --- a/SharedLibraryCore/SharedLibraryCore.csproj +++ b/SharedLibraryCore/SharedLibraryCore.csproj @@ -17,8 +17,9 @@ - - + + + @@ -29,7 +30,7 @@ - + diff --git a/WebfrontCore/WebfrontCore.csproj b/WebfrontCore/WebfrontCore.csproj index e94b91e96..c46d99eb4 100644 --- a/WebfrontCore/WebfrontCore.csproj +++ b/WebfrontCore/WebfrontCore.csproj @@ -24,6 +24,7 @@ true + true @@ -44,7 +45,7 @@ - +