fixed unicode crap stuff in webhook

enable preview of tiered compiliation (faster startup)
ban events are sent to the API properly now
add vpn except id configuration
begin work on javascript plugin support
This commit is contained in:
RaidMax 2018-08-22 20:25:34 -05:00
parent b5939bbdaf
commit ac64d8d3c1
10 changed files with 49 additions and 27 deletions

View File

@ -29,6 +29,7 @@
<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
<TieredCompilation>true</TieredCompilation>
</PropertyGroup>
<ItemGroup>

View File

@ -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);

View File

@ -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)

View File

@ -12,6 +12,10 @@
<Name>DiscordWebhook</Name>
<RootNamespace>DiscordWebhook</RootNamespace>
<InterpreterId>MSBuild|env|$(MSBuildProjectFullPath)</InterpreterId>
<IsWindowsApplication>False</IsWindowsApplication>
<LaunchProvider>Standard Python launcher</LaunchProvider>
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
<Environment>DEBUG=True</Environment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>

View File

@ -9,6 +9,7 @@ namespace IW4MAdmin.Plugins.Stats.Config
public bool EnableAntiCheat { get; set; }
public List<StreakMessageConfiguration> KillstreakMessages { get; set; }
public List<StreakMessageConfiguration> 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;
}
}

View File

@ -46,7 +46,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
var thirtyDaysAgo = DateTime.UtcNow.AddMonths(-1);
var iqClientRatings = (from rating in context.Set<EFRating>()
#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

View File

@ -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}");

View File

@ -28,12 +28,13 @@ namespace SharedLibraryCore.Configuration
public List<string> AutoMessages { get; set; }
public List<string> GlobalRules { get; set; }
public List<MapConfiguration> Maps { get; set; }
public List<int> 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<int>();
RConPollRate = 5000;
return this;

View File

@ -17,8 +17,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1" />
<PackageReference Include="Jint" Version="3.0.0-beta-1249" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="2.1.1" />
@ -29,7 +30,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App"/>
<PackageReference Update="Microsoft.NETCore.App" />
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">

View File

@ -24,6 +24,7 @@
<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
<TieredCompilation>true</TieredCompilation>
</PropertyGroup>
<ItemGroup>
@ -44,7 +45,7 @@
<None Include="wwwroot\css\global.min.css" CopyToPublishDirectory="Always" />
<None Include="wwwroot\js\global.min.js" CopyToPublishDirectory="Always" />
<None Include="wwwroot\images\icon.png" CopyToPublishDirectory="Always" />
<None Include="wwwroot\images\icons\**\*.png" CopyToPublishDirectory="Always"/>
<None Include="wwwroot\images\icons\**\*.png" CopyToPublishDirectory="Always" />
<None Include="wwwroot\lib\open-iconic\font\fonts\open-iconic.ttf" CopyToPublishDirectory="Always" />
<None Include="wwwroot\lib\open-iconic\font\fonts\open-iconic.woff" CopyToPublishDirectory="Always" />
<None Include="wwwroot\lib\open-iconic\font\fonts\open-iconic.otf" CopyToPublishDirectory="Always" />