Compare commits

...

115 Commits

Author SHA1 Message Date
914b37b20a temporarily disable ftp release integration to bypass unknown Error: connect ETIMEDOUT *:21 (control socket) 2021-11-01 21:28:00 -05:00
755c149495 update welcome plugin to bypass api lookup limitation 2021-11-01 17:06:17 -05:00
bbcbc4c042 cleanup and enhance penalty handling 2021-10-31 11:57:32 -05:00
f3bead8eb5 reduce timeout when master api is down 2021-10-30 19:42:07 -05:00
7eb45f2bc9 fix issue with detecting bans on accounts with new ips when implicit linking is disabled 2021-10-20 11:16:35 -05:00
5837885653 post webfront url to master 2021-10-19 21:33:21 -05:00
761d156209 Merge branch 'master' into release/pre 2021-10-19 20:45:05 -05:00
77f04058de merge default settings up 2021-10-19 20:40:40 -05:00
1317102d00 add script injection to the config to import custom webfront scripts (ie google tracking) 2021-10-19 20:17:10 -05:00
a2c7d92162 fix issue on about page with duplicate server names or inactive servers 2021-10-19 20:02:31 -05:00
b2afc410f2 improve about page layout 2021-10-16 13:30:26 -05:00
5b3420b97a default about page to enabled 2021-10-10 10:57:27 -05:00
74bb3da459 add option to toggle about page/make some checks on displayed rules 2021-10-10 10:44:18 -05:00
3916278422 Add about/community info guidelines/social page 2021-10-09 21:11:47 -05:00
a01543c89b deactivate penalties while unlinking an account if implicit account linking is disabled 2021-09-30 10:28:04 -05:00
694431d789 fix profile display with implicit linked accounts enabled 2021-09-18 22:31:56 -05:00
d5f978858d set sv_sayname on connection restore 2021-09-18 18:28:37 -05:00
e80753a4d3 make connection attempts for CoD configurable as "ServerConnectionAttempts" 2021-09-18 18:25:02 -05:00
d4fb75d07c add check to determine whether to include color codes when checking name length 2021-09-18 18:10:47 -05:00
e97119211f fix source issue on home page 2021-09-17 11:23:57 -05:00
87985b3e68 cap client name for new flow 2021-09-17 11:19:17 -05:00
33c63f01db add raw file editing to configuration page in webfront 2021-09-16 16:27:40 -05:00
68c1151191 add tooltip timestamp to max concurrent players 2021-09-14 18:12:20 -05:00
54e39fabb1 fix client history issue with empty database 2021-09-10 11:27:46 -05:00
a4f0726b32 Merge remote-tracking branch 'origin/release/pre' into release/pre 2021-09-06 11:37:30 -05:00
05e228633d fix searching name resulting in incorrect results 2021-09-06 11:37:15 -05:00
e267bd95da Update IW6x parser to automatically find the log file. (#216)
* Update ParserIW6x.js
2021-09-05 10:45:28 -05:00
c7fab5d36c removed commented code and show current alias for ip search 2021-09-05 10:43:48 -05:00
1f8b7cde3f test linking fix 2021-09-04 12:33:25 -05:00
c5f9a68102 implement client server connection tracking persistence 2021-08-31 18:21:40 -05:00
eff8a29a39 version css for webfront 2021-08-31 18:07:07 -05:00
0191c8b7a7 bugfix for edge case of linking alias to new account 2021-08-31 09:53:01 -05:00
fa6524c3b1 fix issue with display server with no saved player history 2021-08-31 08:44:15 -05:00
5b11196b29 bundle js by version so webfront updates don't need a cache refresh 2021-08-30 20:30:06 -05:00
3b7a22edef tweak player history hover format 2021-08-29 20:47:25 -05:00
deff4f2947 persist client count history data across reboots and allow for configurable timespan 2021-08-29 13:10:10 -05:00
02e5e78f67 update iw5 parser to work around filesytem dvar limitation 2021-08-28 17:56:41 -05:00
162006da29 use new cache signature 2021-08-27 21:05:30 -05:00
27e9ecfd9d support homepath in pluto t6 2021-08-27 20:47:06 -05:00
da301bef40 Exclude accidental dotnet bundle command comment 2021-08-26 17:37:01 -05:00
a815bcbff5 Add max concurrent players over 24 hours badge to home 2021-08-26 17:35:05 -05:00
19a49504b8 display "since last connection" as per server on top stats instead of last connection to any servers 2021-08-25 17:47:57 -05:00
3bb87dffb0 Merge branch 'release/pre' of https://github.com/RaidMax/IW4M-Admin into release/pre 2021-08-25 11:07:32 -05:00
02942e5c03 Add support for IW5 (#213) 2021-08-25 11:06:52 -05:00
8c5ff440db Updated T6 AC GSC (#214)
* PlutoT6 AC GSC Updated

PlutoT6's GSC modding capabilities changed, this allows us to bring the script on parity with the IW4x one. The following things changed:
*  Script no longer replaces stock GSC since custom GSC files are now supported.
* The Script now captures the last time the client used his attack button; this is used to detect trigger bots.
* Cleaned up the code a bit

* Create README.MD

Basic installation guide.
2021-08-25 11:06:46 -05:00
a0b7781e66 properly unban accounts associated with IP with toggle 2021-08-25 11:02:37 -05:00
596272a3de tweak linking behavior 2021-08-21 10:40:03 -05:00
b83ea57579 fix another thing 2021-08-16 18:28:00 -05:00
75f68b6385 remove other changes 2021-08-16 17:13:17 -05:00
d5e4d083c5 renable dotnet bundle cuz that was the real issue. 2021-08-16 17:02:47 -05:00
602ec66afe more pipeline test plz work 2021-08-16 16:53:58 -05:00
435b079b94 testing again for CLI Version 2021-08-16 16:46:18 -05:00
a4eec5981f specify explicit .net cli sdk version for pipeline 2021-08-16 13:50:22 -05:00
0b6e261dbb fix more issues with implicit link toggle 2021-08-16 13:20:54 -05:00
7e1221f467 fix small issue with new toggle 2021-08-14 20:43:20 -05:00
a6b0911af9 make implicit account linking a feature toggle 2021-08-14 17:55:28 -05:00
fa66381193 small fixes 2021-08-14 11:30:15 -05:00
67c2406325 fix issues with last release 2021-07-12 14:57:44 -05:00
e2ea5c6ce0 support hostnames for server config 2021-07-11 17:26:30 -05:00
5ef00d6dae tweak headshot detection for CSGO 2021-07-11 09:58:02 -05:00
5921098dce detect headshots for CSGO on advanced stats
track say_team events for CSGO
2021-07-10 21:37:51 -05:00
31ee71260a use default settings for maps and quick messages config (remove from IW4MAdminSettings) 2021-07-09 16:50:33 -05:00
ed8067a4a2 add offline messaging feature 2021-07-08 21:12:09 -05:00
e2116712e7 pass x-forwarded-for to properly log proxied login/logout 2021-07-05 16:08:13 -05:00
8b06da5783 use different api for country code/flag that support https 2021-07-02 10:04:56 -05:00
33a427bb8a add country flag and name to profile 2021-07-01 21:58:09 -05:00
c9d7a957dc add reset anticheat metric (!rsa) for issue #177 2021-07-01 13:12:19 -05:00
9c6ff6f353 use right game for estimated score 2021-07-01 13:06:31 -05:00
7444cb6472 actually fix steam id parsing 2021-07-01 10:14:58 -05:00
c7e5c9c8dd parse steam id properly for source games 2021-07-01 09:10:56 -05:00
0256fc35d2 add login/logout events to change tracker
default guest profile to minimum permissions
2021-06-30 21:13:25 -05:00
0019ed8dde fix run as command config not being honored properly 2021-06-30 18:10:45 -05:00
56aec53e72 fix bad key lookup in manager 2021-06-30 14:01:41 -05:00
1b773f21c6 fix alignment for long server names 2021-06-30 10:44:43 -05:00
bccbcce3c1 add lobby rating to home
add gametype (WIP) to home
misc UI tweaks
2021-06-30 09:57:07 -05:00
fc0bed2405 show "out of" ranked players for stats command 2021-06-29 17:14:25 -05:00
16cfb33109 improvements and consistencies to the top stats, most played and top players commands 2021-06-29 15:35:56 -05:00
42979dc5ae Use string for AC snapshot weapon and hit location
Add webfront logging
2021-06-29 15:02:01 -05:00
95cbc85144 fix issue with selecting wrong parser during setup
add minimum name length option
fix issue with stats spm
2021-06-27 20:31:39 -05:00
9cbca390fe Merge branch 'release/pre' of https://github.com/RaidMax/IW4M-Admin into release/pre 2021-06-16 08:55:56 -05:00
38c0c81451 Added CSGO maps (#210)
Added all current default CSGO maps (Competitive, Wingman, Casual, War Games, Retakes, Danger Zone)
2021-06-16 08:54:49 -05:00
af4630ecb9 Additional CSGO compatibility improvements 2021-06-16 08:53:50 -05:00
dbceb23823 fix issue with custom event registration 2021-06-16 08:51:22 -05:00
e628ac0e9e improve CS:GO compatibility 2021-06-11 11:52:30 -05:00
3a1e8359c2 add one log indicator for games (Pluto IW5) that don't log to mods folder even when fs_game is specified. 2021-06-07 16:58:36 -05:00
c397fd5479 update pluto iw5 parser for new version
fix issue with finding players with color codes in name
2021-06-06 13:40:58 -05:00
16e1bbb1b5 fix bug with additional group mapping key 2021-06-03 13:21:34 -05:00
eff1fe237d Fix null pointer exception (#207) 2021-06-03 10:52:27 -05:00
b09ce46ff9 Merge branch 'release/pre' of https://github.com/RaidMax/IW4M-Admin into release/pre 2021-06-03 10:51:19 -05:00
be08d49f0a add initial CS:GO support 2021-06-03 10:51:03 -05:00
b9fb274db6 Update ParserPT6.js (#206) 2021-05-15 09:22:34 -05:00
9488f754d4 Fix stupid idiot things 2021-05-15 09:20:49 -05:00
1595c1fa99 Initial implementation of configuration support for script plugins 2021-05-14 21:52:55 -05:00
4d21680d59 small issue fix with api and more checks for welcome tags 2021-05-04 19:01:09 -05:00
127af98b00 fix issue with help and dynamically loaded plugins with commands 2021-04-30 12:37:55 -05:00
21a9eb8716 Update DefaultSettings.json (T4, IW5, S1x) (#202)
* Update DefaultSettings.json
2021-04-30 12:35:38 -05:00
f1593e2f99 fix issue with chat message search 2021-04-18 09:17:01 -05:00
74dbc3572f Added WaW bot guid (#200)
may be PlutoniumT4 only.
2021-04-16 13:48:52 -05:00
e6d149736a Added T4 weapon names. (#198) 2021-04-16 13:47:58 -05:00
a034394610 Merge branch 'release/pre' of https://github.com/RaidMax/IW4M-Admin into release/pre 2021-04-16 13:38:34 -05:00
34e7d69110 Add RCon support for S1x 2021-04-16 13:35:51 -05:00
4b686e5fdd Update Plutonium T4 Parser [v0.2]
Static version string
2021-04-08 09:36:32 -05:00
0428453426 Update Pluto T4 Parser
Uses new static version string.
2021-04-08 09:36:32 -05:00
e80e5d6a70 remove test code 2021-04-07 09:53:32 -05:00
22cf3081e1 update parser for Plutonium T4 2021-04-07 09:50:41 -05:00
76a18d9797 add parser support for Plutonium T4 2021-04-07 09:33:49 -05:00
fc13363c9c add user agent header for vpn detection issue #195 2021-04-07 08:47:42 -05:00
f916c51bc0 fix issue with iw5 weapon prefix not being removed properly 2021-04-01 13:12:47 -05:00
21087d6c25 remove whitespace on alias display and client name search 2021-03-31 11:20:32 -05:00
c84e374274 fix issue with client api for issue #191 2021-03-27 19:01:27 -05:00
e777a68105 properly pass game name to game string config finder.
add weapon prefix to weapon name parser for (iw5).
add some iw3 game strings
2021-03-23 21:42:26 -05:00
1f9c80e23b strip colors from header penalty on profile 2021-03-23 21:42:26 -05:00
33371a6d28 Added iw6 aliases (#184) 2021-03-23 21:42:26 -05:00
8530444ffa Added T7 aliases (#186)
1. T7 aliases by @mikzyy
2. Highrise for IW5 which is still in beta
2021-03-23 13:14:11 -05:00
2512b9f251 Added iw6 aliases (#184) 2021-01-20 12:43:44 -06:00
210 changed files with 30924 additions and 2384 deletions

4
.gitignore vendored
View File

@ -245,4 +245,6 @@ launchSettings.json
/Tests/ApplicationTests/Files/replay.json
/GameLogServer/game_log_server_env
.idea/*
*.db
*.db
/Data/IW4MAdmin_Migration.db-shm
/Data/IW4MAdmin_Migration.db-wal

View File

@ -22,7 +22,7 @@ namespace IW4MAdmin.Application.API.Master
public int Uptime { get; set; }
/// <summary>
/// Specifices the version of the instance
/// Specifies the version of the instance
/// </summary>
[JsonProperty("version")]
[JsonConverter(typeof(BuildNumberJsonConverter))]
@ -33,5 +33,11 @@ namespace IW4MAdmin.Application.API.Master
/// </summary>
[JsonProperty("servers")]
public List<ApiServer> Servers { get; set; }
/// <summary>
/// Url IW4MAdmin is listening on
/// </summary>
[JsonProperty("webfront_url")]
public string WebfrontUrl { get; set; }
}
}

View File

@ -48,6 +48,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Integrations\Cod\Integrations.Cod.csproj" />
<ProjectReference Include="..\Integrations\Source\Integrations.Source.csproj" />
<ProjectReference Include="..\SharedLibraryCore\SharedLibraryCore.csproj">
<Private>true</Private>
</ProjectReference>

View File

@ -1,7 +1,7 @@
using IW4MAdmin.Application.EventParsers;
using IW4MAdmin.Application.Extensions;
using IW4MAdmin.Application.Misc;
using IW4MAdmin.Application.RconParsers;
using IW4MAdmin.Application.RConParsers;
using SharedLibraryCore;
using SharedLibraryCore.Commands;
using SharedLibraryCore.Configuration;
@ -220,15 +220,15 @@ namespace IW4MAdmin.Application
public async Task UpdateServerStates()
{
// store the server hash code and task for it
var runningUpdateTasks = new Dictionary<long, Task>();
var runningUpdateTasks = new Dictionary<long, (Task task, CancellationTokenSource tokenSource, DateTime startTime)>();
while (!_tokenSource.IsCancellationRequested)
{
// select the server ids that have completed the update task
var serverTasksToRemove = runningUpdateTasks
.Where(ut => ut.Value.Status == TaskStatus.RanToCompletion ||
ut.Value.Status == TaskStatus.Canceled ||
ut.Value.Status == TaskStatus.Faulted)
.Where(ut => ut.Value.task.Status == TaskStatus.RanToCompletion ||
ut.Value.task.Status == TaskStatus.Canceled || // we want to cancel if a task takes longer than 5 minutes
ut.Value.task.Status == TaskStatus.Faulted || DateTime.Now - ut.Value.startTime > TimeSpan.FromMinutes(5))
.Select(ut => ut.Key)
.ToList();
@ -239,9 +239,14 @@ namespace IW4MAdmin.Application
IsInitialized = true;
}
// remove the update tasks as they have completd
foreach (long serverId in serverTasksToRemove)
// remove the update tasks as they have completed
foreach (var serverId in serverTasksToRemove.Where(serverId => runningUpdateTasks.ContainsKey(serverId)))
{
if (!runningUpdateTasks[serverId].tokenSource.Token.IsCancellationRequested)
{
runningUpdateTasks[serverId].tokenSource.Cancel();
}
runningUpdateTasks.Remove(serverId);
}
@ -249,11 +254,16 @@ namespace IW4MAdmin.Application
var serverIds = Servers.Select(s => s.EndPoint).Except(runningUpdateTasks.Select(r => r.Key)).ToList();
foreach (var server in Servers.Where(s => serverIds.Contains(s.EndPoint)))
{
runningUpdateTasks.Add(server.EndPoint, Task.Run(async () =>
var tokenSource = new CancellationTokenSource();
runningUpdateTasks.Add(server.EndPoint, (Task.Run(async () =>
{
try
{
await server.ProcessUpdatesAsync(_tokenSource.Token);
if (runningUpdateTasks.ContainsKey(server.EndPoint))
{
await server.ProcessUpdatesAsync(_tokenSource.Token)
.WithWaitCancellation(runningUpdateTasks[server.EndPoint].tokenSource.Token);
}
}
catch (Exception e)
@ -268,7 +278,7 @@ namespace IW4MAdmin.Application
{
server.IsInitialized = true;
}
}));
}, tokenSource.Token), tokenSource, DateTime.Now));
}
try
@ -347,9 +357,7 @@ namespace IW4MAdmin.Application
_appConfig.AutoMessages = defaultConfig.AutoMessages;
_appConfig.GlobalRules = defaultConfig.GlobalRules;
_appConfig.Maps = defaultConfig.Maps;
_appConfig.DisallowedClientNames = defaultConfig.DisallowedClientNames;
_appConfig.QuickMessages = defaultConfig.QuickMessages;
//if (newConfig.Servers == null)
{
@ -390,6 +398,18 @@ namespace IW4MAdmin.Application
await ConfigHandler.Save();
}
#pragma warning disable 618
if (_appConfig.Maps != null)
{
_appConfig.Maps = null;
}
if (_appConfig.QuickMessages != null)
{
_appConfig.QuickMessages = null;
}
#pragma warning restore 618
var validator = new ApplicationConfigurationValidator();
var validationResult = validator.Validate(_appConfig);
@ -404,7 +424,7 @@ namespace IW4MAdmin.Application
foreach (var serverConfig in _appConfig.Servers)
{
Migration.ConfigurationMigration.ModifyLogPath020919(serverConfig);
ConfigurationMigration.ModifyLogPath020919(serverConfig);
if (serverConfig.RConParserVersion == null || serverConfig.EventParserVersion == null)
{
@ -585,6 +605,11 @@ namespace IW4MAdmin.Application
return _servers.SelectMany(s => s.Clients).ToList().Where(p => p != null).ToList();
}
public EFClient FindActiveClient(EFClient client) =>client.ClientNumber < 0 ?
GetActiveClients()
.FirstOrDefault(c => c.NetworkId == client.NetworkId) ?? client :
client;
public ClientService GetClientService()
{
return ClientSvc;

View File

@ -0,0 +1,78 @@
using System;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Models.Client;
using Data.Models.Misc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace IW4MAdmin.Application.Commands
{
public class OfflineMessageCommand : Command
{
private readonly IDatabaseContextFactory _contextFactory;
private readonly ILogger _logger;
private const short MaxLength = 1024;
public OfflineMessageCommand(CommandConfiguration config, ITranslationLookup layout,
IDatabaseContextFactory contextFactory, ILogger<IDatabaseContextFactory> logger) : base(config, layout)
{
Name = "offlinemessage";
Description = _translationLookup["COMMANDS_OFFLINE_MESSAGE_DESC"];
Alias = "om";
Permission = EFClient.Permission.Moderator;
RequiresTarget = true;
_contextFactory = contextFactory;
_logger = logger;
}
public override async Task ExecuteAsync(GameEvent gameEvent)
{
if (gameEvent.Data.Length > MaxLength)
{
gameEvent.Origin.Tell(_translationLookup["COMMANDS_OFFLINE_MESSAGE_TOO_LONG"].FormatExt(MaxLength));
return;
}
if (gameEvent.Target.ClientId == gameEvent.Origin.ClientId)
{
gameEvent.Origin.Tell(_translationLookup["COMMANDS_OFFLINE_MESSAGE_SELF"].FormatExt(MaxLength));
return;
}
if (gameEvent.Target.IsIngame)
{
gameEvent.Origin.Tell(_translationLookup["COMMANDS_OFFLINE_MESSAGE_INGAME"].FormatExt(gameEvent.Target.Name));
return;
}
await using var context = _contextFactory.CreateContext(enableTracking: false);
var server = await context.Servers.FirstAsync(srv => srv.EndPoint == gameEvent.Owner.ToString());
var newMessage = new EFInboxMessage()
{
SourceClientId = gameEvent.Origin.ClientId,
DestinationClientId = gameEvent.Target.ClientId,
ServerId = server.Id,
Message = gameEvent.Data,
};
try
{
context.Set<EFInboxMessage>().Add(newMessage);
await context.SaveChangesAsync();
gameEvent.Origin.Tell(_translationLookup["COMMANDS_OFFLINE_MESSAGE_SUCCESS"]);
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not save offline message {@Message}", newMessage);
throw;
}
}
}
}

View File

@ -0,0 +1,79 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
using EFClient = Data.Models.Client.EFClient;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace IW4MAdmin.Application.Commands
{
public class ReadMessageCommand : Command
{
private readonly IDatabaseContextFactory _contextFactory;
private readonly ILogger _logger;
public ReadMessageCommand(CommandConfiguration config, ITranslationLookup layout,
IDatabaseContextFactory contextFactory, ILogger<IDatabaseContextFactory> logger) : base(config, layout)
{
Name = "readmessage";
Description = _translationLookup["COMMANDS_READ_MESSAGE_DESC"];
Alias = "rm";
Permission = EFClient.Permission.Flagged;
_contextFactory = contextFactory;
_logger = logger;
}
public override async Task ExecuteAsync(GameEvent gameEvent)
{
try
{
await using var context = _contextFactory.CreateContext();
var inboxItems = await context.InboxMessages
.Include(message => message.SourceClient)
.ThenInclude(client => client.CurrentAlias)
.Where(message => message.DestinationClientId == gameEvent.Origin.ClientId)
.Where(message => !message.IsDelivered)
.ToListAsync();
if (!inboxItems.Any())
{
gameEvent.Origin.Tell(_translationLookup["COMMANDS_READ_MESSAGE_NONE"]);
return;
}
var index = 1;
foreach (var inboxItem in inboxItems)
{
await gameEvent.Origin.Tell(_translationLookup["COMMANDS_READ_MESSAGE_SUCCESS"]
.FormatExt($"{index}/{inboxItems.Count}", inboxItem.SourceClient.CurrentAlias.Name))
.WaitAsync();
foreach (var messageFragment in inboxItem.Message.FragmentMessageForDisplay())
{
await gameEvent.Origin.Tell(messageFragment).WaitAsync();
}
index++;
}
inboxItems.ForEach(item => { item.IsDelivered = true; });
context.UpdateRange(inboxItems);
await context.SaveChangesAsync();
}
catch (Exception ex)
{
logger.LogError(ex, "Could not retrieve offline messages for {Client}", gameEvent.Origin.ToString());
throw;
}
}
}
}

View File

@ -3,7 +3,13 @@
"Using": [
"Serilog.Sinks.File"
],
"MinimumLevel": "Information",
"MinimumLevel": {
"Default": "Information",
"Override": {
"System": "Warning",
"Microsoft": "Warning"
}
},
"WriteTo": [
{
"Name": "File",

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.Configuration
{
public class ScriptPluginConfiguration : Dictionary<string, Dictionary<string, object>>, IBaseConfiguration
{
public string Name() => nameof(ScriptPluginConfiguration);
public IBaseConfiguration Generate()
{
return new ScriptPluginConfiguration();
}
}
}

View File

@ -1,4 +1,4 @@
{
{
"AutoMessagePeriod": 60,
"AutoMessages": [
"This server uses ^5IW4M Admin v{{VERSION}} ^7get it at ^5raidmax.org/IW4MAdmin",
@ -169,6 +169,18 @@
"Alias": "Asylum",
"Name": "mp_asylum"
},
{
"Alias": "Banzai",
"Name": "mp_kwai"
},
{
"Alias": "Battery",
"Name": "mp_drum"
},
{
"Alias": "Breach",
"Name": "mp_bgate"
},
{
"Alias": "Castle",
"Name": "mp_castle"
@ -177,6 +189,10 @@
"Alias": "Cliffside",
"Name": "mp_shrine"
},
{
"Alias": "Corrosion",
"Name": "mp_stalingrad"
},
{
"Alias": "Courtyard",
"Name": "mp_courtyard"
@ -190,60 +206,52 @@
"Name": "mp_downfall"
},
{
"Alias": "Hanger",
"Alias": "Hangar",
"Name": "mp_hangar"
},
{
"Alias": "Makin",
"Name": "mp_makin"
},
{
"Alias": "Outskirts",
"Name": "mp_outskirts"
},
{
"Alias": "Roundhouse",
"Name": "mp_roundhouse"
},
{
"Alias": "Upheaval",
"Name": "mp_suburban"
},
{
"Alias": "Knee Deep",
"Name": "mp_kneedeep"
},
{
"Alias": "Makin",
"Name": "mp_makin"
},
{
"Alias": "Makin Day",
"Name": "mp_makin_day"
},
{
"Alias": "Nightfire",
"Name": "mp_nachtfeuer"
},
{
"Alias": "Outskirts",
"Name": "mp_outskirts"
},
{
"Alias": "Revolution",
"Name": "mp_vodka"
},
{
"Alias": "Roundhouse",
"Name": "mp_roundhouse"
},
{
"Alias": "Seelow",
"Name": "mp_seelow"
},
{
"Alias": "Station",
"Name": "mp_subway"
},
{
"Alias": "Banzai",
"Name": "mp_kwai"
},
{
"Alias": "Corrosion",
"Name": "mp_stalingrad"
},
{
"Alias": "Sub Pens",
"Name": "mp_docks"
},
{
"Alias": "Battery",
"Name": "mp_drum"
},
{
"Alias": "Breach",
"Name": "mp_bgate"
},
{
"Alias": "Revolution",
"Name": "mp_vodka"
"Alias": "Upheaval",
"Name": "mp_suburban"
}
]
},
@ -427,8 +435,8 @@
"Name": "oilrig"
},
{
"Name": "Village",
"Alias": "co_hunted"
"Alias": "Village",
"Name": "co_hunted"
}
]
},
@ -687,6 +695,14 @@
{
"Alias": "Terminal",
"Name": "mp_terminal_cls"
},
{
"Alias": "Rust",
"Name": "mp_rust"
},
{
"Alias": "Highrise",
"Name": "mp_highrise"
}
]
},
@ -846,6 +862,546 @@
"Name": "zm_transit"
}
]
},
{
"Game": "T7",
"Maps": [
{
"Alias": "Evac",
"Name": "mp_apartments"
},
{
"Alias": "Aquarium",
"Name": "mp_biodome"
},
{
"Alias": "Exodus",
"Name": "mp_chinatown"
},
{
"Alias": "Hunted",
"Name": "mp_ethiopia"
},
{
"Alias": "Havoc",
"Name": "mp_havoc"
},
{
"Alias": "Infection",
"Name": "mp_infection"
},
{
"Alias": "Metro",
"Name": "mp_metro"
},
{
"Alias": "Redwood",
"Name": "mp_redwood"
},
{
"Alias": "Combine",
"Name": "mp_sector"
},
{
"Alias": "Breach",
"Name": "mp_spire"
},
{
"Alias": "Stronghold",
"Name": "mp_stronghold"
},
{
"Alias": "Fringe",
"Name": "mp_veiled"
},
{
"Alias": "Nuk3town",
"Name": "mp_nuketown_x"
},
{
"Alias": "Gauntlet",
"Name": "mp_crucible"
},
{
"Alias": "Rise",
"Name": "mp_rise"
},
{
"Alias": "Skyjacked",
"Name": "mp_skyjacked"
},
{
"Alias": "Splash",
"Name": "mp_waterpark"
},
{
"Alias": "Spire",
"Name": "mp_aerospace"
},
{
"Alias": "Verge",
"Name": "mp_banzai"
},
{
"Alias": "Rift",
"Name": "mp_conduit"
},
{
"Alias": "Knockout",
"Name": "mp_kung_fu"
},
{
"Alias": "Rumble",
"Name": "mp_arena"
},
{
"Alias": "Cyrogen",
"Name": "mp_cryogen"
},
{
"Alias": "Empire",
"Name": "mp_rome"
},
{
"Alias": "Berserk",
"Name": "mp_shrine"
},
{
"Alias": "Rupture",
"Name": "mp_city"
},
{
"Alias": "Micro",
"Name": "mp_miniature"
},
{
"Alias": "Citadel",
"Name": "mp_ruins"
},
{
"Alias": "Outlaw",
"Name": "mp_western"
}
]
},
{
"Game": "IW6",
"Maps": [
{
"Alias": "Prison Break",
"Name": "mp_prisonbreak"
},
{
"Alias": "Octane",
"Name": "mp_dart"
},
{
"Alias": "Tremor",
"Name": "mp_lonestar"
},
{
"Alias": "Freight",
"Name": "mp_frag"
},
{
"Alias": "Whiteout",
"Name": "mp_snow"
},
{
"Alias": "Stormfront",
"Name": "mp_fahrenheit"
},
{
"Alias": "Siege",
"Name": "mp_hashima"
},
{
"Alias": "Warhawk",
"Name": "mp_warhawk"
},
{
"Alias": "Sovereign",
"Name": "mp_sovereign"
},
{
"Alias": "Overload",
"Name": "mp_zebra"
},
{
"Alias": "Stonehaven",
"Name": "mp_skeleton"
},
{
"Alias": "Chasm",
"Name": "mp_chasm"
},
{
"Alias": "Flooded",
"Name": "mp_flooded"
},
{
"Alias": "Strikezone",
"Name": "mp_strikezone"
},
{
"Alias": "Free Fall",
"Name": "mp_descent_new"
},
{
"Alias": "Unearthed",
"Name": "mp_dome_ns"
},
{
"Alias": "Collision",
"Name": "mp_ca_impact"
},
{
"Alias": "Behemoth",
"Name": "mp_ca_behemoth"
},
{
"Alias": "Ruins",
"Name": "mp_battery3"
},
{
"Alias": "Pharaoh",
"Name": "mp_dig"
},
{
"Alias": "Favela",
"Name": "mp_favela_iw6"
},
{
"Alias": "Mutiny",
"Name": "mp_pirate"
},
{
"Alias": "Departed",
"Name": "mp_zulu"
},
{
"Alias": "Dynasty",
"Name": "mp_conflict"
},
{
"Alias": "Goldrush",
"Name": "mp_mine"
},
{
"Alias": "Showtime",
"Name": "mp_shipment_ns"
},
{
"Alias": "Subzero",
"Name": "mp_zerosub"
},
{
"Alias": "Ignition",
"Name": "mp_boneyard_ns"
},
{
"Alias": "Containment",
"Name": "mp_ca_red_river"
},
{
"Alias": "Bayview",
"Name": "mp_ca_rumble"
},
{
"Alias": "Fog",
"Name": "mp_swamp"
},
{
"Alias": "Point of Contact",
"Name": "mp_alien_town"
},
{
"Alias": "Nightfall",
"Name": "mp_alien_armory"
},
{
"Alias": "Mayday",
"Name": "mp_alien_beacon"
},
{
"Alias": "Awakening",
"Name": "mp_alien_dlc3"
},
{
"Alias": "Exodus",
"Name": "mp_alien_last"
}
]
},
{
"Game": "SHG1",
"Maps": [
{
"Alias": "Ascend",
"Name": "mp_refraction"
},
{
"Alias": "Bio Lab",
"Name": "mp_lab2"
},
{
"Alias": "Comeback",
"Name": "mp_comeback"
},
{
"Alias": "Defender",
"Name": "mp_laser2"
},
{
"Alias": "Detroit",
"Name": "mp_detroit"
},
{
"Alias": "Greenband",
"Name": "mp_greenband"
},
{
"Alias": "Horizon",
"Name": "mp_levity"
},
{
"Alias": "Instinct",
"Name": "mp_instinct"
},
{
"Alias": "Recovery",
"Name": "mp_recovery"
},
{
"Alias": "Retreat",
"Name": "mp_venus"
},
{
"Alias": "Riot",
"Name": "mp_prison"
},
{
"Alias": "Solar",
"Name": "mp_solar"
},
{
"Alias": "Terrace",
"Name": "mp_terrace"
},
{
"Alias": "Atlas Gorge",
"Name": "mp_dam"
},
{
"Alias": "Chop Shop",
"Name": "mp_spark"
},
{
"Alias": "Climate",
"Name": "mp_climate_3"
},
{
"Alias": "Compound",
"Name": "mp_sector17"
},
{
"Alias": "Core",
"Name": "mp_lost"
},
{
"Alias": "Drift",
"Name": "mp_torqued"
},
{
"Alias": "Fracture",
"Name": "mp_fracture"
},
{
"Alias": "Kremlin",
"Name": "mp_kremlin"
},
{
"Alias": "Overload",
"Name": "mp_lair"
},
{
"Alias": "Parliament",
"Name": "mp_bigben2"
},
{
"Alias": "Perplex",
"Name": "mp_perplex_1"
},
{
"Alias": "Quarantine",
"Name": "mp_liberty"
},
{
"Alias": "Sideshow",
"Name": "mp_clowntown3"
},
{
"Alias": "Site 244",
"Name": "mp_blackbox"
},
{
"Alias": "Skyrise",
"Name": "mp_highrise2"
},
{
"Alias": "Swarn",
"Name": "mp_seoul2"
},
{
"Alias": "Urban",
"Name": "mp_urban"
}
]
},
{
"Game": "CSGO",
"Maps": [
{
"Name": "ar_baggage",
"Alias": "Baggage"
},
{
"Name": "ar_dizzy",
"Alias": "Dizzy"
},
{
"Name": "ar_lunacy",
"Alias": "Lunacy"
},
{
"Name": "ar_monastery",
"Alias": "Monastery"
},
{
"Name": "ar_shoots",
"Alias": "Shoots"
},
{
"Name": "cs_agency",
"Alias": "Agency"
},
{
"Name": "cs_assault",
"Alias": "Assault"
},
{
"Name": "cs_italy",
"Alias": "Italy"
},
{
"Name": "cs_militia",
"Alias": "Militia"
},
{
"Name": "cs_office",
"Alias": "Office"
},
{
"Name": "de_ancient",
"Alias": "Ancient"
},
{
"Name": "de_bank",
"Alias": "Bank"
},
{
"Name": "de_cache",
"Alias": "Cache"
},
{
"Name": "de_calavera",
"Alias": "Calavera"
},
{
"Name": "de_canals",
"Alias": "Canals"
},
{
"Name": "de_cbble",
"Alias": "Cobblestone"
},
{
"Name": "de_dust2",
"Alias": "Dust II"
},
{
"Name": "de_grind",
"Alias": "Grind"
},
{
"Name": "de_inferno",
"Alias": "Inferno"
},
{
"Name": "de_lake",
"Alias": "Lake"
},
{
"Name": "de_mirage",
"Alias": "Mirage"
},
{
"Name": "de_mocha",
"Alias": "Mocha"
},
{
"Name": "de_nuke",
"Alias": "Nuke"
},
{
"Name": "de_overpass",
"Alias": "Overpass"
},
{
"Name": "de_pitstop",
"Alias": "Pitstop"
},
{
"Name": "de_safehouse",
"Alias": "Safehouse"
},
{
"Name": "de_shortdust",
"Alias": "Shortdust"
},
{
"Name": "de_shortnuke",
"Alias": "Shortnuke"
},
{
"Name": "de_stmarc",
"Alias": "St. Marc"
},
{
"Name": "de_sugarcane",
"Alias": "Sugarcane"
},
{
"Name": "de_train",
"Alias": "Train"
},
{
"Name": "de_vertigo",
"Alias": "Vertigo"
},
{
"Name": "dz_blacksite",
"Alias": "Blacksite"
},
{
"Name": "dz_frostbite",
"Alias": "Frostbite"
},
{
"Name": "dz_sirocco",
"Alias": "Sirocco"
}
]
}
],
"GameStrings": {
@ -920,6 +1476,103 @@
"artillery": "Precision Airstrike",
"player": "",
"attach": ""
}
},
"IW3": {
"torso_upper": "Upper Torso",
"torso_lower": "Lower Torso",
"right_leg_upper": "Upper Right Leg",
"right_leg_lower": "Lower Right Leg",
"right_hand": "Right Hand",
"right_foot": "Right Foot",
"right_arm_upper": "Upper Right Arm",
"right_arm_lower": "Lower Right Arm",
"left_leg_upper": "Upper Left Leg",
"left_leg_lower": "Lower Left Leg",
"left_hand": "Left Hand",
"left_foot": "Left Foot",
"left_arm_upper": "Upper Left Arm",
"left_arm_lower": "Lower Left Arm",
"acog": "ACOG Sight",
"gl": "Grenade Launcher",
"reflex": "Red Dot Sight",
"grip": "Grip",
"m4": "M4 Carbine",
"m40a3": "M40A3",
"ak47": "AK-47",
"ak74u": "AK-74u",
"rpg": "RPG-7",
"deserteagle": "Desert Eagle",
"deserteaglegold": "Desert Eagle Gold",
"m16": "M16A4",
"g36c": "G36C",
"uzi": "Mini-Uzi",
"m60e4": "M60E4",
"mp5": "MP5",
"barrett": "Barrett .50cal",
"mp44": "MP44",
"remington700": "R700",
"rpd": "RDP",
"saw": " M249 SAW",
"usp": "USP .45",
"winchester1200": "W1200",
"concussion": "Stun",
"melee": "Knife",
"Frag" : "Grenade",
"airstrike": "Airstrike",
"helicopter": "Attack Helicopter",
"player": "",
"attach": ""
},
"T4": {
"torso_upper": "Upper Torso",
"torso_lower": "Lower Torso",
"right_leg_upper": "Upper Right Leg",
"right_leg_lower": "Lower Right Leg",
"right_hand": "Right Hand",
"right_foot": "Right Foot",
"right_arm_upper": "Upper Right Arm",
"right_arm_lower": "Lower Right Arm",
"left_leg_upper": "Upper Left Leg",
"left_leg_lower": "Lower Left Leg",
"left_hand": "Left Hand",
"left_foot": "Left Foot",
"left_arm_upper": "Upper Left Arm",
"left_arm_lower": "Lower Left Arm",
"gl": "Rifle Grenade",
"bigammo": "Round Drum",
"scoped": "Sniper Scope",
"telescopic": "Telescopic Sight",
"aperture": "Aperture Sight",
"flash": "Flash Hider",
"silenced": "Silencer",
"molotov": "Molotov Cocktail",
"sticky": "N° 74 ST",
"m2": "M2 Flamethrower",
"artillery": "Artillery Strike",
"dog": "Attack Dogs",
"colt": "Colt M1911",
"357magnum": ".357 Magnum",
"walther": "Walther P38",
"tokarev": "Tokarev TT-33",
"shotgun": "M1897 Trench Gun",
"doublebarreledshotgun": "Double-Barreled Shotgun",
"mp40": "MP40",
"type100smg": "Type 100",
"ppsh": "PPSh-41",
"svt40": "SVT-40",
"gewehr43": "Gewehr 43",
"m1garand": "M1 Garand",
"stg44": "STG-44",
"m1carbine": "M1A1 Carbine",
"type99lmg": "Type 99",
"bar": "BAR",
"dp28": "DP-28",
"mg42": "MG42",
"fg42": "FG42",
"30cal": "Browning M1919",
"type99rifle": "Arisaka",
"mosinrifle": "Mosin-Nagant",
"ptrs41":"PTRS-41"
}
}
}

View File

@ -17,6 +17,8 @@ namespace IW4MAdmin.Application.EventParsers
private readonly Dictionary<string, (string, Func<string, IEventParserConfiguration, GameEvent, GameEvent>)> _customEventRegistrations;
private readonly ILogger _logger;
private readonly ApplicationConfiguration _appConfig;
private readonly Dictionary<ParserRegex, GameEvent.EventType> _regexMap;
private readonly Dictionary<string, GameEvent.EventType> _eventTypeMap;
public BaseEventParser(IParserRegexFactory parserRegexFactory, ILogger logger, ApplicationConfiguration appConfig)
{
@ -78,7 +80,28 @@ namespace IW4MAdmin.Application.EventParsers
Configuration.Kill.AddMapping(ParserRegex.GroupType.MeansOfDeath, 12);
Configuration.Kill.AddMapping(ParserRegex.GroupType.HitLocation, 13);
Configuration.MapChange.Pattern = @".*InitGame.*";
Configuration.MapEnd.Pattern = @".*(?:ExitLevel|ShutdownGame).*";
Configuration.Time.Pattern = @"^ *(([0-9]+):([0-9]+) |^[0-9]+ )";
_regexMap = new Dictionary<ParserRegex, GameEvent.EventType>
{
{Configuration.Say, GameEvent.EventType.Say},
{Configuration.Kill, GameEvent.EventType.Kill},
{Configuration.MapChange, GameEvent.EventType.MapChange},
{Configuration.MapEnd, GameEvent.EventType.MapEnd}
};
_eventTypeMap = new Dictionary<string, GameEvent.EventType>
{
{"say", GameEvent.EventType.Say},
{"sayteam", GameEvent.EventType.Say},
{"K", GameEvent.EventType.Kill},
{"D", GameEvent.EventType.Damage},
{"J", GameEvent.EventType.PreConnect},
{"Q", GameEvent.EventType.PreDisconnect},
};
}
public IEventParserConfiguration Configuration { get; set; }
@ -91,6 +114,28 @@ namespace IW4MAdmin.Application.EventParsers
public string Name { get; set; } = "Call of Duty";
private (GameEvent.EventType type, string eventKey) GetEventTypeFromLine(string logLine)
{
var lineSplit = logLine.Split(';');
if (lineSplit.Length > 1)
{
var type = lineSplit[0];
return _eventTypeMap.ContainsKey(type) ? (_eventTypeMap[type], type): (GameEvent.EventType.Unknown, lineSplit[0]);
}
foreach (var (key, value) in _regexMap)
{
var result = key.PatternMatcher.Match(logLine);
if (result.Success)
{
return (value, null);
}
}
return (GameEvent.EventType.Unknown, null);
}
public virtual GameEvent GenerateGameEvent(string logLine)
{
var timeMatch = Configuration.Time.PatternMatcher.Match(logLine);
@ -104,7 +149,7 @@ namespace IW4MAdmin.Application.EventParsers
.Values
.Skip(2)
// this converts the timestamp into seconds passed
.Select((_value, index) => long.Parse(_value.ToString()) * (index == 0 ? 60 : 1))
.Select((value, index) => long.Parse(value.ToString()) * (index == 0 ? 60 : 1))
.Sum();
}
@ -114,33 +159,34 @@ namespace IW4MAdmin.Application.EventParsers
}
// we want to strip the time from the log line
logLine = logLine.Substring(timeMatch.Values.First().Length);
logLine = logLine.Substring(timeMatch.Values.First().Length).Trim();
}
string[] lineSplit = logLine.Split(';');
string eventType = lineSplit[0];
var eventParseResult = GetEventTypeFromLine(logLine);
var eventType = eventParseResult.type;
_logger.LogDebug(logLine);
if (eventType == "say" || eventType == "sayteam")
if (eventType == GameEvent.EventType.Say)
{
var matchResult = Configuration.Say.PatternMatcher.Match(logLine);
if (matchResult.Success)
{
string message = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.Message]]
.ToString()
var message = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.Message]]
.Replace("\x15", "")
.Trim();
if (message.Length > 0)
{
string originIdString = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
string originName = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
var originIdString = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
var originName = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginName]];
long originId = originIdString.IsBotGuid() ?
var originId = originIdString.IsBotGuid() ?
originName.GenerateGuidFromString() :
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
int clientNumber = int.Parse(matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
var clientNumber = int.Parse(matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
if (message.StartsWith(_appConfig.CommandPrefix) || message.StartsWith(_appConfig.BroadcastCommandPrefix))
{
@ -172,26 +218,26 @@ namespace IW4MAdmin.Application.EventParsers
}
}
if (eventType == "K")
if (eventType == GameEvent.EventType.Kill)
{
var match = Configuration.Kill.PatternMatcher.Match(logLine);
if (match.Success)
{
string originIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
string targetIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString();
string originName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
string targetName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetName]].ToString();
var originIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
var targetIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]];
var originName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginName]];
var targetName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetName]];
long originId = originIdString.IsBotGuid() ?
var originId = originIdString.IsBotGuid() ?
originName.GenerateGuidFromString() :
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
long targetId = targetIdString.IsBotGuid() ?
var targetId = targetIdString.IsBotGuid() ?
targetName.GenerateGuidFromString() :
targetIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
int originClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
int targetClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
var originClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
var targetClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
return new GameEvent()
{
@ -206,26 +252,26 @@ namespace IW4MAdmin.Application.EventParsers
}
}
if (eventType == "D")
if (eventType == GameEvent.EventType.Damage)
{
var match = Configuration.Damage.PatternMatcher.Match(logLine);
if (match.Success)
{
string originIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
string targetIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString();
string originName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
string targetName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetName]].ToString();
var originIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
var targetIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]];
var originName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginName]];
var targetName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetName]];
long originId = originIdString.IsBotGuid() ?
var originId = originIdString.IsBotGuid() ?
originName.GenerateGuidFromString() :
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
long targetId = targetIdString.IsBotGuid() ?
var targetId = targetIdString.IsBotGuid() ?
targetName.GenerateGuidFromString() :
targetIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
int originClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
int targetClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
var originClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
var targetClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
return new GameEvent()
{
@ -240,16 +286,16 @@ namespace IW4MAdmin.Application.EventParsers
}
}
if (eventType == "J")
if (eventType == GameEvent.EventType.PreConnect)
{
var match = Configuration.Join.PatternMatcher.Match(logLine);
if (match.Success)
{
string originIdString = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
string originName = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
var originIdString = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
var originName = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]];
long networkId = originIdString.IsBotGuid() ?
var networkId = originIdString.IsBotGuid() ?
originName.GenerateGuidFromString() :
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
@ -261,10 +307,10 @@ namespace IW4MAdmin.Application.EventParsers
{
CurrentAlias = new EFAlias()
{
Name = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].ToString().TrimNewLine(),
Name = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].TrimNewLine(),
},
NetworkId = networkId,
ClientNumber = Convert.ToInt32(match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
ClientNumber = Convert.ToInt32(match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]),
State = EFClient.ClientState.Connecting,
},
Extra = originIdString,
@ -276,16 +322,16 @@ namespace IW4MAdmin.Application.EventParsers
}
}
if (eventType == "Q")
if (eventType == GameEvent.EventType.PreDisconnect)
{
var match = Configuration.Quit.PatternMatcher.Match(logLine);
if (match.Success)
{
string originIdString = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
string originName = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
var originIdString = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
var originName = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]];
long networkId = originIdString.IsBotGuid() ?
var networkId = originIdString.IsBotGuid() ?
originName.GenerateGuidFromString() :
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
@ -297,10 +343,10 @@ namespace IW4MAdmin.Application.EventParsers
{
CurrentAlias = new EFAlias()
{
Name = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].ToString().TrimNewLine()
Name = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].TrimNewLine()
},
NetworkId = networkId,
ClientNumber = Convert.ToInt32(match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
ClientNumber = Convert.ToInt32(match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]),
State = EFClient.ClientState.Disconnecting
},
RequiredEntity = GameEvent.EventRequiredEntity.None,
@ -311,7 +357,7 @@ namespace IW4MAdmin.Application.EventParsers
}
}
if (eventType.Contains("ExitLevel") || eventType.Contains("ShutdownGame"))
if (eventType == GameEvent.EventType.MapEnd)
{
return new GameEvent()
{
@ -325,9 +371,9 @@ namespace IW4MAdmin.Application.EventParsers
};
}
if (eventType.Contains("InitGame"))
if (eventType == GameEvent.EventType.MapChange)
{
string dump = eventType.Replace("InitGame: ", "");
var dump = logLine.Replace("InitGame: ", "");
return new GameEvent()
{
@ -342,26 +388,37 @@ namespace IW4MAdmin.Application.EventParsers
};
}
if (_customEventRegistrations.ContainsKey(eventType))
if (eventParseResult.eventKey == null || !_customEventRegistrations.ContainsKey(eventParseResult.eventKey))
{
var eventModifier = _customEventRegistrations[eventType];
try
return new GameEvent()
{
return eventModifier.Item2(logLine, Configuration, new GameEvent()
{
Type = GameEvent.EventType.Other,
Data = logLine,
Subtype = eventModifier.Item1,
GameTime = gameTime,
Source = GameEvent.EventSource.Log
});
}
Type = GameEvent.EventType.Unknown,
Data = logLine,
Origin = Utilities.IW4MAdminClient(),
Target = Utilities.IW4MAdminClient(),
RequiredEntity = GameEvent.EventRequiredEntity.None,
GameTime = gameTime,
Source = GameEvent.EventSource.Log
};
}
catch (Exception e)
var eventModifier = _customEventRegistrations[eventParseResult.eventKey];
try
{
return eventModifier.Item2(logLine, Configuration, new GameEvent()
{
_logger.LogError(e, $"Could not handle custom event generation");
}
Type = GameEvent.EventType.Other,
Data = logLine,
Subtype = eventModifier.Item1,
GameTime = gameTime,
Source = GameEvent.EventSource.Log
});
}
catch (Exception e)
{
_logger.LogError(e, "Could not handle custom event generation");
}
return new GameEvent()

View File

@ -1,5 +1,6 @@
using SharedLibraryCore.Interfaces;
using System.Globalization;
using SharedLibraryCore;
namespace IW4MAdmin.Application.EventParsers
{
@ -17,6 +18,8 @@ namespace IW4MAdmin.Application.EventParsers
public ParserRegex Damage { get; set; }
public ParserRegex Action { get; set; }
public ParserRegex Time { get; set; }
public ParserRegex MapChange { get; set; }
public ParserRegex MapEnd { get; set; }
public NumberStyles GuidNumberStyle { get; set; } = NumberStyles.HexNumber;
public DynamicEventParserConfiguration(IParserRegexFactory parserRegexFactory)
@ -28,6 +31,8 @@ namespace IW4MAdmin.Application.EventParsers
Damage = parserRegexFactory.CreateParserRegex();
Action = parserRegexFactory.CreateParserRegex();
Time = parserRegexFactory.CreateParserRegex();
MapChange = parserRegexFactory.CreateParserRegex();
MapEnd = parserRegexFactory.CreateParserRegex();
}
}
}

View File

@ -22,7 +22,7 @@ namespace IW4MAdmin.Application.Factories
/// </summary>
/// <param name="translationLookup"></param>
/// <param name="rconConnectionFactory"></param>
public GameServerInstanceFactory(ITranslationLookup translationLookup,
public GameServerInstanceFactory(ITranslationLookup translationLookup,
IMetaService metaService,
IServiceProvider serviceProvider)
{
@ -39,7 +39,10 @@ namespace IW4MAdmin.Application.Factories
/// <returns></returns>
public Server CreateServer(ServerConfiguration config, IManager manager)
{
return new IW4MServer(config, _translationLookup, _metaService, _serviceProvider, _serviceProvider.GetRequiredService<IClientNoticeMessageFormatter>(), _serviceProvider.GetRequiredService<ILookupCache<EFServer>>());
return new IW4MServer(config,
_serviceProvider.GetRequiredService<CommandConfiguration>(), _translationLookup, _metaService,
_serviceProvider, _serviceProvider.GetRequiredService<IClientNoticeMessageFormatter>(),
_serviceProvider.GetRequiredService<ILookupCache<EFServer>>());
}
}
}
}

View File

@ -1,7 +1,13 @@
using IW4MAdmin.Application.RCon;
using System;
using System.Net;
using SharedLibraryCore.Interfaces;
using System.Text;
using Integrations.Cod;
using Integrations.Source;
using Integrations.Source.Interfaces;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SharedLibraryCore.Configuration;
namespace IW4MAdmin.Application.Factories
{
@ -10,28 +16,31 @@ namespace IW4MAdmin.Application.Factories
/// </summary>
internal class RConConnectionFactory : IRConConnectionFactory
{
private static readonly Encoding gameEncoding = Encoding.GetEncoding("windows-1252");
private readonly ILogger<RConConnection> _logger;
private static readonly Encoding GameEncoding = Encoding.GetEncoding("windows-1252");
private readonly IServiceProvider _serviceProvider;
/// <summary>
/// Base constructor
/// </summary>
/// <param name="logger"></param>
public RConConnectionFactory(ILogger<RConConnection> logger)
public RConConnectionFactory(IServiceProvider serviceProvider)
{
_logger = logger;
_serviceProvider = serviceProvider;
}
/// <summary>
/// creates a new rcon connection instance
/// </summary>
/// <param name="ipAddress">ip address of the server</param>
/// <param name="port">port of the server</param>
/// <param name="password">rcon password of the server</param>
/// <returns></returns>
public IRConConnection CreateConnection(string ipAddress, int port, string password)
/// <inheritdoc/>
public IRConConnection CreateConnection(IPEndPoint ipEndpoint, string password, string rconEngine)
{
return new RConConnection(ipAddress, port, password, _logger, gameEncoding);
return rconEngine switch
{
"COD" => new CodRConConnection(ipEndpoint, password,
_serviceProvider.GetRequiredService<ILogger<CodRConConnection>>(), GameEncoding,
_serviceProvider.GetRequiredService<ApplicationConfiguration>()?.ServerConnectionAttempts ?? 6),
"Source" => new SourceRConConnection(
_serviceProvider.GetRequiredService<ILogger<SourceRConConnection>>(),
_serviceProvider.GetRequiredService<IRConClientFactory>(), ipEndpoint, password),
_ => throw new ArgumentException($"No supported RCon engine available for '{rconEngine}'")
};
}
}
}
}

View File

@ -13,6 +13,7 @@ namespace IW4MAdmin.Application
{
private readonly EventLog _eventLog;
private readonly ILogger _logger;
private readonly IEventPublisher _eventPublisher;
private static readonly GameEvent.EventType[] overrideEvents = new[]
{
GameEvent.EventType.Connect,
@ -21,10 +22,11 @@ namespace IW4MAdmin.Application
GameEvent.EventType.Stop
};
public GameEventHandler(ILogger<GameEventHandler> logger)
public GameEventHandler(ILogger<GameEventHandler> logger, IEventPublisher eventPublisher)
{
_eventLog = new EventLog();
_logger = logger;
_eventPublisher = eventPublisher;
}
public void HandleEvent(IManager manager, GameEvent gameEvent)
@ -32,6 +34,7 @@ namespace IW4MAdmin.Application
if (manager.IsRunning || overrideEvents.Contains(gameEvent.Type))
{
EventApi.OnGameEvent(gameEvent);
_eventPublisher.Publish(gameEvent);
Task.Factory.StartNew(() => manager.ExecuteEvent(gameEvent));
}
else

View File

@ -11,6 +11,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
@ -22,6 +23,7 @@ using Serilog.Context;
using static SharedLibraryCore.Database.Models.EFClient;
using Data.Models;
using Data.Models.Server;
using Microsoft.EntityFrameworkCore;
using static Data.Models.Client.EFClient;
namespace IW4MAdmin
@ -39,9 +41,11 @@ namespace IW4MAdmin
private readonly IServiceProvider _serviceProvider;
private readonly IClientNoticeMessageFormatter _messageFormatter;
private readonly ILookupCache<EFServer> _serverCache;
private readonly CommandConfiguration _commandConfiguration;
public IW4MServer(
ServerConfiguration serverConfiguration,
CommandConfiguration commandConfiguration,
ITranslationLookup lookup,
IMetaService metaService,
IServiceProvider serviceProvider,
@ -58,6 +62,7 @@ namespace IW4MAdmin
_serviceProvider = serviceProvider;
_messageFormatter = messageFormatter;
_serverCache = serverCache;
_commandConfiguration = commandConfiguration;
}
public override async Task<EFClient> OnClientConnected(EFClient clientFromLog)
@ -74,6 +79,8 @@ namespace IW4MAdmin
client = await Manager.GetClientService().Create(clientFromLog);
}
client.CopyAdditionalProperties(clientFromLog);
// this is only a temporary version until the IPAddress is transmitted
client.CurrentAlias = new EFAlias()
{
@ -156,7 +163,7 @@ namespace IW4MAdmin
{
try
{
C = await SharedLibraryCore.Commands.CommandProcessing.ValidateCommand(E, Manager.GetApplicationSettings().Configuration());
C = await SharedLibraryCore.Commands.CommandProcessing.ValidateCommand(E, Manager.GetApplicationSettings().Configuration(), _commandConfiguration);
}
catch (CommandException e)
@ -303,6 +310,11 @@ namespace IW4MAdmin
Console.WriteLine(loc["MANAGER_CONNECTION_REST"].FormatExt($"[{IP}:{Port}]"));
}
if (!string.IsNullOrEmpty(CustomSayName))
{
await this.SetDvarAsync("sv_sayname", CustomSayName);
}
Throttled = false;
}
@ -336,7 +348,26 @@ namespace IW4MAdmin
E.Origin.Tag = clientTag.LinkedMeta.Value;
}
await E.Origin.OnJoin(E.Origin.IPAddress);
try
{
var factory = _serviceProvider.GetRequiredService<IDatabaseContextFactory>();
await using var context = factory.CreateContext();
var messageCount = await context.InboxMessages
.CountAsync(msg => msg.DestinationClientId == E.Origin.ClientId && !msg.IsDelivered);
if (messageCount > 0)
{
E.Origin.Tell(_translationLookup["SERVER_JOIN_OFFLINE_MESSAGES"]);
}
}
catch (Exception ex)
{
ServerLogger.LogError(ex, "Could not get offline message count for {Client}", E.Origin.ToString());
throw;
}
await E.Origin.OnJoin(E.Origin.IPAddress, Manager.GetApplicationSettings().Configuration().EnableImplicitAccountLinking);
}
}
@ -436,7 +467,7 @@ namespace IW4MAdmin
Link = E.Target.AliasLink
};
var addedPenalty = await Manager.GetPenaltyService().Create(newPenalty);
await Manager.GetPenaltyService().Create(newPenalty);
E.Target.SetLevel(Permission.Flagged, E.Origin);
}
@ -588,7 +619,7 @@ namespace IW4MAdmin
{
try
{
message = Manager.GetApplicationSettings().Configuration()
message = _serviceProvider.GetRequiredService<DefaultSettings>()
.QuickMessages
.First(_qm => _qm.Game == GameName)
.Messages[E.Data.Substring(1)];
@ -694,11 +725,11 @@ namespace IW4MAdmin
private async Task OnClientUpdate(EFClient origin)
{
var client = GetClientsAsList().FirstOrDefault(_client => _client.Equals(origin));
var client = Manager.GetActiveClients().FirstOrDefault(c => c.NetworkId == origin.NetworkId);
if (client == null)
{
ServerLogger.LogWarning("{origin} expected to exist in client list for update, but they do not", origin.ToString());
ServerLogger.LogWarning("{Origin} expected to exist in client list for update, but they do not", origin.ToString());
return;
}
@ -712,7 +743,7 @@ namespace IW4MAdmin
{
try
{
await client.OnJoin(origin.IPAddress);
await client.OnJoin(origin.IPAddress, Manager.GetApplicationSettings().Configuration().EnableImplicitAccountLinking);
}
catch (Exception e)
@ -724,11 +755,11 @@ namespace IW4MAdmin
}
}
else if ((client.IPAddress != null && client.State == ClientState.Disconnecting) ||
else if (client.IPAddress != null && client.State == ClientState.Disconnecting ||
client.Level == Permission.Banned)
{
ServerLogger.LogWarning("{client} state is Unknown (probably kicked), but they are still connected. trying to kick again...", origin.ToString());
await client.CanConnect(client.IPAddress);
ServerLogger.LogWarning("{Client} state is Unknown (probably kicked), but they are still connected. trying to kick again...", origin.ToString());
await client.CanConnect(client.IPAddress, Manager.GetApplicationSettings().Configuration().EnableImplicitAccountLinking);
}
}
@ -739,11 +770,11 @@ namespace IW4MAdmin
/// array index 2 = updated clients
/// </summary>
/// <returns></returns>
async Task<IList<EFClient>[]> PollPlayersAsync()
async Task<List<EFClient>[]> PollPlayersAsync()
{
var currentClients = GetClientsAsList();
var statusResponse = (await this.GetStatusAsync());
var polledClients = statusResponse.Item1.AsEnumerable();
var polledClients = statusResponse.Clients.AsEnumerable();
if (Manager.GetApplicationSettings().Configuration().IgnoreBots)
{
@ -753,10 +784,12 @@ namespace IW4MAdmin
var connectingClients = polledClients.Except(currentClients);
var updatedClients = polledClients.Except(connectingClients).Except(disconnectingClients);
UpdateMap(statusResponse.Item2);
UpdateGametype(statusResponse.Item3);
UpdateMap(statusResponse.Map);
UpdateGametype(statusResponse.GameType);
UpdateHostname(statusResponse.Hostname);
UpdateMaxPlayers(statusResponse.MaxClients);
return new List<EFClient>[]
return new []
{
connectingClients.ToList(),
disconnectingClients.ToList(),
@ -764,8 +797,10 @@ namespace IW4MAdmin
};
}
private async Task<long> GetIdForServer(Server server)
public override async Task<long> GetIdForServer(Server server = null)
{
server ??= this;
if ($"{server.IP}:{server.Port.ToString()}" == "66.150.121.184:28965")
{
return 886229536;
@ -803,6 +838,36 @@ namespace IW4MAdmin
}
}
private void UpdateHostname(string hostname)
{
if (string.IsNullOrEmpty(hostname) || Hostname == hostname)
{
return;
}
using(LogContext.PushProperty("Server", ToString()))
{
ServerLogger.LogDebug("Updating hostname to {HostName}", hostname);
}
Hostname = hostname;
}
private void UpdateMaxPlayers(int? maxPlayers)
{
if (maxPlayers == null || maxPlayers == MaxClients)
{
return;
}
using(LogContext.PushProperty("Server", ToString()))
{
ServerLogger.LogDebug("Updating max clients to {MaxPlayers}", maxPlayers);
}
MaxClients = maxPlayers.Value;
}
private async Task ShutdownInternal()
{
foreach (var client in GetClientsAsList())
@ -942,10 +1007,13 @@ namespace IW4MAdmin
LastMessage = DateTime.Now - start;
lastCount = DateTime.Now;
var appConfig = _serviceProvider.GetService<ApplicationConfiguration>();
// update the player history
if ((lastCount - playerCountStart).TotalMinutes >= PlayerHistory.UpdateInterval)
if (lastCount - playerCountStart >= appConfig.ServerDataCollectionInterval)
{
while (ClientHistory.Count > ((60 / PlayerHistory.UpdateInterval) * 12)) // 12 times a hour for 12 hours
var maxItems = Math.Ceiling(appConfig.MaxClientHistoryTime.TotalMinutes /
appConfig.ServerDataCollectionInterval.TotalMinutes);
while ( ClientHistory.Count > maxItems)
{
ClientHistory.Dequeue();
}
@ -1002,20 +1070,31 @@ namespace IW4MAdmin
public async Task Initialize()
{
try
{
ResolvedIpEndPoint = new IPEndPoint((await Dns.GetHostAddressesAsync(IP)).First(), Port);
}
catch (Exception ex)
{
ServerLogger.LogWarning(ex, "Could not resolve hostname or IP for RCon connection {IP}:{Port}", IP, Port);
ResolvedIpEndPoint = new IPEndPoint(IPAddress.Parse(IP), Port);
}
RconParser = Manager.AdditionalRConParsers
.FirstOrDefault(_parser => _parser.Version == ServerConfig.RConParserVersion);
EventParser = Manager.AdditionalEventParsers
.FirstOrDefault(_parser => _parser.Version == ServerConfig.EventParserVersion);
RconParser = RconParser ?? Manager.AdditionalRConParsers[0];
EventParser = EventParser ?? Manager.AdditionalEventParsers[0];
RconParser ??= Manager.AdditionalRConParsers[0];
EventParser ??= Manager.AdditionalEventParsers[0];
RemoteConnection = RConConnectionFactory.CreateConnection(ResolvedIpEndPoint, Password, RconParser.RConEngine);
RemoteConnection.SetConfiguration(RconParser);
var version = await this.GetMappedDvarValueOrDefaultAsync<string>("version");
Version = version.Value;
GameName = Utilities.GetGame(version?.Value ?? RconParser.Version);
GameName = Utilities.GetGame(version.Value ?? RconParser.Version);
if (GameName == Game.UKN)
{
@ -1043,8 +1122,9 @@ namespace IW4MAdmin
string mapname = (await this.GetMappedDvarValueOrDefaultAsync<string>("mapname", infoResponse: infoResponse)).Value;
int maxplayers = (await this.GetMappedDvarValueOrDefaultAsync<int>("sv_maxclients", infoResponse: infoResponse)).Value;
string gametype = (await this.GetMappedDvarValueOrDefaultAsync<string>("g_gametype", "gametype", infoResponse)).Value;
var basepath = (await this.GetMappedDvarValueOrDefaultAsync<string>("fs_basepath"));
var basegame = (await this.GetMappedDvarValueOrDefaultAsync<string>("fs_basegame"));
var basepath = await this.GetMappedDvarValueOrDefaultAsync<string>("fs_basepath");
var basegame = await this.GetMappedDvarValueOrDefaultAsync<string>("fs_basegame");
var homepath = await this.GetMappedDvarValueOrDefaultAsync<string>("fs_homepath");
var game = (await this.GetMappedDvarValueOrDefaultAsync<string>("fs_game", infoResponse: infoResponse));
var logfile = await this.GetMappedDvarValueOrDefaultAsync<string>("g_log");
var logsync = await this.GetMappedDvarValueOrDefaultAsync<int>("g_logsync");
@ -1080,8 +1160,14 @@ namespace IW4MAdmin
{
Manager.GetApplicationSettings().Configuration().ContactUri = Website;
}
var defaultConfig = _serviceProvider.GetRequiredService<DefaultSettings>();
var gameMaps = defaultConfig?.Maps?.FirstOrDefault(map => map.Game == GameName);
InitializeMaps();
if (gameMaps != null)
{
Maps.AddRange(gameMaps.Maps);
}
WorkingDirectory = basepath.Value;
this.Hostname = hostname;
@ -1139,15 +1225,16 @@ namespace IW4MAdmin
{
BaseGameDirectory = basegame.Value,
BasePathDirectory = basepath.Value,
HomePathDirectory = homepath.Value,
GameDirectory = EventParser.Configuration.GameDirectory ?? "",
ModDirectory = game.Value ?? "",
LogFile = logfile.Value,
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows),
IsOneLog = RconParser.IsOneLog
};
LogPath = GenerateLogPath(logInfo);
ServerLogger.LogInformation("Game log information {@logInfo}", logInfo);
if (!File.Exists(LogPath) && ServerConfig.GameLogServerUrl == null)
{
Console.WriteLine(loc["SERVER_ERROR_DNE"].FormatExt(LogPath));
@ -1172,7 +1259,7 @@ namespace IW4MAdmin
public Uri[] GenerateUriForLog(string logPath, string gameLogServerUrl)
{
var logUri = new Uri(logPath);
var logUri = new Uri(logPath, UriKind.Absolute);
if (string.IsNullOrEmpty(gameLogServerUrl))
{
@ -1188,21 +1275,31 @@ namespace IW4MAdmin
public static string GenerateLogPath(LogPathGeneratorInfo logInfo)
{
string logPath;
string workingDirectory = logInfo.BasePathDirectory;
var workingDirectory = logInfo.BasePathDirectory;
bool IsValidGamePath (string path)
{
var baseGameIsDirectory = !string.IsNullOrWhiteSpace(path) &&
path.IndexOfAny(Utilities.DirectorySeparatorChars) != -1;
bool baseGameIsDirectory = !string.IsNullOrWhiteSpace(logInfo.BaseGameDirectory) &&
logInfo.BaseGameDirectory.IndexOfAny(Utilities.DirectorySeparatorChars) != -1;
var baseGameIsRelative = path.FixDirectoryCharacters()
.Equals(logInfo.GameDirectory.FixDirectoryCharacters(), StringComparison.InvariantCultureIgnoreCase);
bool baseGameIsRelative = logInfo.BaseGameDirectory.FixDirectoryCharacters()
.Equals(logInfo.GameDirectory.FixDirectoryCharacters(), StringComparison.InvariantCultureIgnoreCase);
return baseGameIsDirectory && !baseGameIsRelative;
}
// we want to see if base game is provided and it 'looks' like a directory
if (baseGameIsDirectory && !baseGameIsRelative)
if (IsValidGamePath(logInfo.HomePathDirectory))
{
workingDirectory = logInfo.HomePathDirectory;
}
else if (IsValidGamePath(logInfo.BaseGameDirectory))
{
workingDirectory = logInfo.BaseGameDirectory;
}
if (string.IsNullOrWhiteSpace(logInfo.ModDirectory))
if (string.IsNullOrWhiteSpace(logInfo.ModDirectory) || logInfo.IsOneLog)
{
logPath = Path.Combine(workingDirectory, logInfo.GameDirectory, logInfo.LogFile);
}
@ -1224,12 +1321,9 @@ namespace IW4MAdmin
public override async Task Warn(string reason, EFClient targetClient, EFClient targetOrigin)
{
// ensure player gets warned if command not performed on them in game
targetClient = targetClient.ClientNumber < 0 ?
Manager.GetActiveClients()
.FirstOrDefault(c => c.ClientId == targetClient?.ClientId) ?? targetClient :
targetClient;
var activeClient = Manager.FindActiveClient(targetClient);
var newPenalty = new EFPenalty()
var newPenalty = new EFPenalty
{
Type = EFPenalty.PenaltyType.Warning,
Expires = DateTime.UtcNow,
@ -1239,31 +1333,28 @@ namespace IW4MAdmin
Link = targetClient.AliasLink
};
ServerLogger.LogDebug("Creating warn penalty for {targetClient}", targetClient.ToString());
ServerLogger.LogDebug("Creating warn penalty for {TargetClient}", targetClient.ToString());
await newPenalty.TryCreatePenalty(Manager.GetPenaltyService(), ServerLogger);
if (targetClient.IsIngame)
if (activeClient.IsIngame)
{
if (targetClient.Warnings >= 4)
if (activeClient.Warnings >= 4)
{
targetClient.Kick(loc["SERVER_WARNLIMT_REACHED"], Utilities.IW4MAdminClient(this));
activeClient.Kick(loc["SERVER_WARNLIMT_REACHED"], Utilities.IW4MAdminClient(this));
return;
}
// todo: move to translation sheet
string message = $"^1{loc["SERVER_WARNING"]} ^7[^3{targetClient.Warnings}^7]: ^3{targetClient.Name}^7, {reason}";
targetClient.CurrentServer.Broadcast(message);
var message = loc["COMMANDS_WARNING_FORMAT"]
.FormatExt(activeClient.Warnings, activeClient.Name, reason);
activeClient.CurrentServer.Broadcast(message);
}
}
public override async Task Kick(string reason, EFClient targetClient, EFClient originClient, EFPenalty previousPenalty)
{
targetClient = targetClient.ClientNumber < 0 ?
Manager.GetActiveClients()
.FirstOrDefault(c => c.ClientId == targetClient?.ClientId) ?? targetClient :
targetClient;
var activeClient = Manager.FindActiveClient(targetClient);
var newPenalty = new EFPenalty()
var newPenalty = new EFPenalty
{
Type = EFPenalty.PenaltyType.Kick,
Expires = DateTime.UtcNow,
@ -1273,69 +1364,64 @@ namespace IW4MAdmin
Link = targetClient.AliasLink
};
ServerLogger.LogDebug("Creating kick penalty for {targetClient}", targetClient.ToString());
ServerLogger.LogDebug("Creating kick penalty for {TargetClient}", targetClient.ToString());
await newPenalty.TryCreatePenalty(Manager.GetPenaltyService(), ServerLogger);
if (targetClient.IsIngame)
if (activeClient.IsIngame)
{
var e = new GameEvent()
var gameEvent = new GameEvent
{
Type = GameEvent.EventType.PreDisconnect,
Origin = targetClient,
Origin = activeClient,
Owner = this
};
Manager.AddEvent(e);
Manager.AddEvent(gameEvent);
var formattedKick = string.Format(RconParser.Configuration.CommandPrefixes.Kick,
targetClient.ClientNumber,
activeClient.TemporalClientNumber,
_messageFormatter.BuildFormattedMessage(RconParser.Configuration,
newPenalty,
previousPenalty));
await targetClient.CurrentServer.ExecuteCommandAsync(formattedKick);
ServerLogger.LogDebug("Executing tempban kick command for {ActiveClient}", activeClient.ToString());
await activeClient.CurrentServer.ExecuteCommandAsync(formattedKick);
}
}
public override async Task TempBan(string Reason, TimeSpan length, EFClient targetClient, EFClient originClient)
public override async Task TempBan(string reason, TimeSpan length, EFClient targetClient, EFClient originClient)
{
// ensure player gets kicked if command not performed on them in the same server
targetClient = targetClient.ClientNumber < 0 ?
Manager.GetActiveClients()
.FirstOrDefault(c => c.ClientId == targetClient?.ClientId) ?? targetClient :
targetClient;
var activeClient = Manager.FindActiveClient(targetClient);
var newPenalty = new EFPenalty()
var newPenalty = new EFPenalty
{
Type = EFPenalty.PenaltyType.TempBan,
Expires = DateTime.UtcNow + length,
Offender = targetClient,
Offense = Reason,
Offense = reason,
Punisher = originClient,
Link = targetClient.AliasLink
};
ServerLogger.LogDebug("Creating tempban penalty for {targetClient}", targetClient.ToString());
ServerLogger.LogDebug("Creating tempban penalty for {TargetClient}", targetClient.ToString());
await newPenalty.TryCreatePenalty(Manager.GetPenaltyService(), ServerLogger);
if (targetClient.IsIngame)
if (activeClient.IsIngame)
{
var formattedKick = string.Format(RconParser.Configuration.CommandPrefixes.Kick,
targetClient.ClientNumber,
activeClient.TemporalClientNumber,
_messageFormatter.BuildFormattedMessage(RconParser.Configuration, newPenalty));
ServerLogger.LogDebug("Executing tempban kick command for {targetClient}", targetClient.ToString());
await targetClient.CurrentServer.ExecuteCommandAsync(formattedKick);
ServerLogger.LogDebug("Executing tempban kick command for {ActiveClient}", activeClient.ToString());
await activeClient.CurrentServer.ExecuteCommandAsync(formattedKick);
}
}
public override async Task Ban(string reason, EFClient targetClient, EFClient originClient, bool isEvade = false)
{
// ensure player gets kicked if command not performed on them in the same server
targetClient = targetClient.ClientNumber < 0 ?
Manager.GetActiveClients()
.FirstOrDefault(c => c.ClientId == targetClient?.ClientId) ?? targetClient :
targetClient;
var activeClient = Manager.FindActiveClient(targetClient);
EFPenalty newPenalty = new EFPenalty()
var newPenalty = new EFPenalty
{
Type = EFPenalty.PenaltyType.Ban,
Expires = null,
@ -1346,41 +1432,42 @@ namespace IW4MAdmin
IsEvadedOffense = isEvade
};
ServerLogger.LogDebug("Creating ban penalty for {targetClient}", targetClient.ToString());
targetClient.SetLevel(Permission.Banned, originClient);
ServerLogger.LogDebug("Creating ban penalty for {TargetClient}", targetClient.ToString());
activeClient.SetLevel(Permission.Banned, originClient);
await newPenalty.TryCreatePenalty(Manager.GetPenaltyService(), ServerLogger);
if (targetClient.IsIngame)
if (activeClient.IsIngame)
{
ServerLogger.LogDebug("Attempting to kicking newly banned client {targetClient}", targetClient.ToString());
ServerLogger.LogDebug("Attempting to kicking newly banned client {ActiveClient}", activeClient.ToString());
var formattedString = string.Format(RconParser.Configuration.CommandPrefixes.Kick,
targetClient.ClientNumber,
activeClient.TemporalClientNumber,
_messageFormatter.BuildFormattedMessage(RconParser.Configuration, newPenalty));
await targetClient.CurrentServer.ExecuteCommandAsync(formattedString);
await activeClient.CurrentServer.ExecuteCommandAsync(formattedString);
}
}
override public async Task Unban(string reason, EFClient Target, EFClient Origin)
public override async Task Unban(string reason, EFClient targetClient, EFClient originClient)
{
var unbanPenalty = new EFPenalty()
var unbanPenalty = new EFPenalty
{
Type = EFPenalty.PenaltyType.Unban,
Expires = DateTime.Now,
Offender = Target,
Offender = targetClient,
Offense = reason,
Punisher = Origin,
Punisher = originClient,
When = DateTime.UtcNow,
Active = true,
Link = Target.AliasLink
Link = targetClient.AliasLink
};
ServerLogger.LogDebug("Creating unban penalty for {targetClient}", Target.ToString());
Target.SetLevel(Permission.User, Origin);
await Manager.GetPenaltyService().RemoveActivePenalties(Target.AliasLink.AliasLinkId);
ServerLogger.LogDebug("Creating unban penalty for {targetClient}", targetClient.ToString());
targetClient.SetLevel(Permission.User, originClient);
await Manager.GetPenaltyService().RemoveActivePenalties(targetClient.AliasLink.AliasLinkId);
await Manager.GetPenaltyService().Create(unbanPenalty);
}
override public void InitializeTokens()
public override void InitializeTokens()
{
Manager.GetMessageTokens().Add(new MessageToken("TOTALPLAYERS", (Server s) => Task.Run(async () => (await Manager.GetClientService().GetTotalClientsAsync()).ToString())));
Manager.GetMessageTokens().Add(new MessageToken("VERSION", (Server s) => Task.FromResult(Application.Program.Version.ToString())));

View File

@ -19,11 +19,13 @@ using SharedLibraryCore.Services;
using Stats.Dtos;
using System;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Helpers;
using Integrations.Source.Extensions;
using IW4MAdmin.Application.Extensions;
using IW4MAdmin.Application.Localization;
using Microsoft.Extensions.Logging;
@ -184,6 +186,8 @@ namespace IW4MAdmin.Application
? WebfrontCore.Program.Init(ServerManager, serviceProvider, services, ServerManager.CancellationToken)
: Task.CompletedTask;
var collectionService = serviceProvider.GetRequiredService<IServerDataCollector>();
// we want to run this one on a manual thread instead of letting the thread pool handle it,
// because we can't exit early from waiting on console input, and it prevents us from restarting
var inputThread = new Thread(async () => await ReadConsoleInput(logger));
@ -194,7 +198,8 @@ namespace IW4MAdmin.Application
ServerManager.Start(),
webfrontTask,
serviceProvider.GetRequiredService<IMasterCommunication>()
.RunUploadStatus(ServerManager.CancellationToken)
.RunUploadStatus(ServerManager.CancellationToken),
collectionService.BeginCollectionAsync(cancellationToken: ServerManager.CancellationToken)
};
logger.LogDebug("Starting webfront and input tasks");
@ -270,6 +275,7 @@ namespace IW4MAdmin.Application
// register the native commands
foreach (var commandType in typeof(SharedLibraryCore.Commands.QuitCommand).Assembly.GetTypes()
.Concat(typeof(Program).Assembly.GetTypes().Where(type => type.Namespace == "IW4MAdmin.Application.Commands"))
.Where(_command => _command.BaseType == typeof(Command)))
{
defaultLogger.LogDebug("Registered native command type {name}", commandType.Name);
@ -331,11 +337,18 @@ namespace IW4MAdmin.Application
// setup the static resources (config/master api/translations)
var serviceCollection = new ServiceCollection();
var appConfigHandler = new BaseConfigurationHandler<ApplicationConfiguration>("IW4MAdminSettings");
var defaultConfigHandler = new BaseConfigurationHandler<DefaultSettings>("DefaultSettings");
var defaultConfig = defaultConfigHandler.Configuration();
var appConfig = appConfigHandler.Configuration();
var masterUri = Utilities.IsDevelopment
? new Uri("http://127.0.0.1:8080")
: appConfig?.MasterUrl ?? new ApplicationConfiguration().MasterUrl;
var masterRestClient = RestClient.For<IMasterApi>(masterUri);
var httpClient = new HttpClient
{
BaseAddress = masterUri,
Timeout = TimeSpan.FromSeconds(15)
};
var masterRestClient = RestClient.For<IMasterApi>(httpClient);
var translationLookup = Configure.Initialize(Utilities.DefaultLogger, masterRestClient, appConfig);
if (appConfig == null)
@ -359,6 +372,7 @@ namespace IW4MAdmin.Application
serviceCollection
.AddBaseLogger(appConfig)
.AddSingleton(defaultConfig)
.AddSingleton<IServiceCollection>(_serviceProvider => serviceCollection)
.AddSingleton<IConfigurationHandler<DefaultSettings>, BaseConfigurationHandler<DefaultSettings>>()
.AddSingleton((IConfigurationHandler<ApplicationConfiguration>) appConfigHandler)
@ -393,6 +407,7 @@ namespace IW4MAdmin.Application
.AddSingleton<IResourceQueryHelper<ClientPaginationRequest, UpdatedAliasResponse>,
UpdatedAliasResourceQueryHelper>()
.AddSingleton<IResourceQueryHelper<ChatSearchQuery, MessageResponse>, ChatResourceQueryHelper>()
.AddSingleton<IResourceQueryHelper<ClientPaginationRequest, ConnectionHistoryResponse>, ConnectionsResourceQueryHelper>()
.AddTransient<IParserPatternMatcher, ParserPatternMatcher>()
.AddSingleton<IRemoteAssemblyHandler, RemoteAssemblyHandler>()
.AddSingleton<IMasterCommunication, MasterCommunication>()
@ -405,6 +420,9 @@ namespace IW4MAdmin.Application
.AddSingleton<IHitInfoBuilder, HitInfoBuilder>()
.AddSingleton(typeof(ILookupCache<>), typeof(LookupCache<>))
.AddSingleton(typeof(IDataValueCache<,>), typeof(DataValueCache<,>))
.AddSingleton<IServerDataViewer, ServerDataViewer>()
.AddSingleton<IServerDataCollector, ServerDataCollector>()
.AddSingleton<IEventPublisher, EventPublisher>()
.AddSingleton(translationLookup)
.AddDatabaseContextOptions(appConfig);
@ -417,6 +435,8 @@ namespace IW4MAdmin.Application
serviceCollection.AddSingleton<IEventHandler, GameEventHandler>();
}
serviceCollection.AddSource();
return serviceCollection;
}

View File

@ -0,0 +1,60 @@
using System.Linq;
using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SharedLibraryCore.Dtos.Meta.Responses;
using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.QueryHelper;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace IW4MAdmin.Application.Meta
{
public class
ConnectionsResourceQueryHelper : IResourceQueryHelper<ClientPaginationRequest, ConnectionHistoryResponse>
{
private readonly ILogger _logger;
private readonly IDatabaseContextFactory _contextFactory;
public ConnectionsResourceQueryHelper(ILogger<ConnectionsResourceQueryHelper> logger,
IDatabaseContextFactory contextFactory)
{
_contextFactory = contextFactory;
_logger = logger;
}
public async Task<ResourceQueryHelperResult<ConnectionHistoryResponse>> QueryResource(
ClientPaginationRequest query)
{
_logger.LogDebug("{Class} {@Request}", nameof(ConnectionsResourceQueryHelper), query);
await using var context = _contextFactory.CreateContext(enableTracking: false);
var iqConnections = context.ConnectionHistory.AsNoTracking()
.Where(history => query.ClientId == history.ClientId)
.Where(history => history.CreatedDateTime < query.Before)
.OrderByDescending(history => history.CreatedDateTime);
var connections = await iqConnections.Select(history => new ConnectionHistoryResponse
{
MetaId = history.ClientConnectionId,
ClientId = history.ClientId,
Type = MetaType.ConnectionHistory,
ShouldDisplay = true,
When = history.CreatedDateTime,
ServerName = history.Server.HostName,
ConnectionType = history.ConnectionType
})
.ToListAsync();
_logger.LogDebug("{Class} retrieved {Number} items", nameof(ConnectionsResourceQueryHelper),
connections.Count);
return new ResourceQueryHelperResult<ConnectionHistoryResponse>
{
Results = connections
};
}
}
}

View File

@ -20,11 +20,14 @@ namespace IW4MAdmin.Application.Meta
private readonly IResourceQueryHelper<ClientPaginationRequest, ReceivedPenaltyResponse> _receivedPenaltyHelper;
private readonly IResourceQueryHelper<ClientPaginationRequest, AdministeredPenaltyResponse> _administeredPenaltyHelper;
private readonly IResourceQueryHelper<ClientPaginationRequest, UpdatedAliasResponse> _updatedAliasHelper;
private readonly IResourceQueryHelper<ClientPaginationRequest, ConnectionHistoryResponse>
_connectionHistoryHelper;
public MetaRegistration(ILogger<MetaRegistration> logger, IMetaService metaService, ITranslationLookup transLookup, IEntityService<EFClient> clientEntityService,
IResourceQueryHelper<ClientPaginationRequest, ReceivedPenaltyResponse> receivedPenaltyHelper,
IResourceQueryHelper<ClientPaginationRequest, AdministeredPenaltyResponse> administeredPenaltyHelper,
IResourceQueryHelper<ClientPaginationRequest, UpdatedAliasResponse> updatedAliasHelper)
IResourceQueryHelper<ClientPaginationRequest, UpdatedAliasResponse> updatedAliasHelper,
IResourceQueryHelper<ClientPaginationRequest, ConnectionHistoryResponse> connectionHistoryHelper)
{
_logger = logger;
_transLookup = transLookup;
@ -33,6 +36,7 @@ namespace IW4MAdmin.Application.Meta
_receivedPenaltyHelper = receivedPenaltyHelper;
_administeredPenaltyHelper = administeredPenaltyHelper;
_updatedAliasHelper = updatedAliasHelper;
_connectionHistoryHelper = connectionHistoryHelper;
}
public void Register()
@ -41,6 +45,7 @@ namespace IW4MAdmin.Application.Meta
_metaService.AddRuntimeMeta<ClientPaginationRequest, ReceivedPenaltyResponse>(MetaType.ReceivedPenalty, GetReceivedPenaltiesMeta);
_metaService.AddRuntimeMeta<ClientPaginationRequest, AdministeredPenaltyResponse>(MetaType.Penalized, GetAdministeredPenaltiesMeta);
_metaService.AddRuntimeMeta<ClientPaginationRequest, UpdatedAliasResponse>(MetaType.AliasUpdate, GetUpdatedAliasMeta);
_metaService.AddRuntimeMeta<ClientPaginationRequest, ConnectionHistoryResponse>(MetaType.ConnectionHistory, GetConnectionHistoryMeta);
}
private async Task<IEnumerable<InformationResponse>> GetProfileMeta(ClientPaginationRequest request)
@ -163,5 +168,11 @@ namespace IW4MAdmin.Application.Meta
var aliases = await _updatedAliasHelper.QueryResource(request);
return aliases.Results;
}
private async Task<IEnumerable<ConnectionHistoryResponse>> GetConnectionHistoryMeta(ClientPaginationRequest request)
{
var connections = await _connectionHistoryHelper.QueryResource(request);
return connections.Results;
}
}
}

View File

@ -1,10 +1,12 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Dtos.Meta.Responses;
using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces;
@ -21,11 +23,14 @@ namespace IW4MAdmin.Application.Meta
{
private readonly ILogger _logger;
private readonly IDatabaseContextFactory _contextFactory;
private readonly ApplicationConfiguration _appConfig;
public ReceivedPenaltyResourceQueryHelper(ILogger<ReceivedPenaltyResourceQueryHelper> logger, IDatabaseContextFactory contextFactory)
public ReceivedPenaltyResourceQueryHelper(ILogger<ReceivedPenaltyResourceQueryHelper> logger,
IDatabaseContextFactory contextFactory, ApplicationConfiguration appConfig)
{
_contextFactory = contextFactory;
_logger = logger;
_appConfig = appConfig;
}
public async Task<ResourceQueryHelperResult<ReceivedPenaltyResponse>> QueryResource(ClientPaginationRequest query)
@ -35,15 +40,40 @@ namespace IW4MAdmin.Application.Meta
var linkId = await ctx.Clients.AsNoTracking()
.Where(_client => _client.ClientId == query.ClientId)
.Select(_client => _client.AliasLinkId)
.Select(_client => new {_client.AliasLinkId, _client.CurrentAliasId })
.FirstOrDefaultAsync();
var iqPenalties = ctx.Penalties.AsNoTracking()
.Where(_penalty => _penalty.OffenderId == query.ClientId || (linkedPenaltyType.Contains(_penalty.Type) && _penalty.LinkId == linkId))
.Where(_penalty => _penalty.When < query.Before)
.OrderByDescending(_penalty => _penalty.When);
.Where(_penalty => _penalty.OffenderId == query.ClientId ||
linkedPenaltyType.Contains(_penalty.Type) && _penalty.LinkId == linkId.AliasLinkId);
var penalties = await iqPenalties
IQueryable<EFPenalty> iqIpLinkedPenalties = null;
if (!_appConfig.EnableImplicitAccountLinking)
{
var usedIps = await ctx.Aliases.AsNoTracking()
.Where(alias => (alias.LinkId == linkId.AliasLinkId || alias.AliasId == linkId.CurrentAliasId) && alias.IPAddress != null)
.Select(alias => alias.IPAddress).ToListAsync();
var aliasedIds = await ctx.Aliases.AsNoTracking().Where(alias => usedIps.Contains(alias.IPAddress))
.Select(alias => alias.LinkId)
.ToListAsync();
iqIpLinkedPenalties = ctx.Penalties.AsNoTracking()
.Where(penalty =>
linkedPenaltyType.Contains(penalty.Type) && aliasedIds.Contains(penalty.LinkId));
}
var iqAllPenalties = iqPenalties;
if (iqIpLinkedPenalties != null)
{
iqAllPenalties = iqPenalties.Union(iqIpLinkedPenalties);
}
var penalties = await iqAllPenalties
.Where(_penalty => _penalty.When < query.Before)
.OrderByDescending(_penalty => _penalty.When)
.Take(query.Count)
.Select(_penalty => new ReceivedPenaltyResponse()
{

View File

@ -4,8 +4,6 @@ using System.Threading;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Models.Client.Stats;
using SharedLibraryCore.Database;
using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.Migration
{

View File

@ -0,0 +1,44 @@
using System;
using Microsoft.Extensions.Logging;
using SharedLibraryCore;
using SharedLibraryCore.Interfaces;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace IW4MAdmin.Application.Misc
{
public class EventPublisher : IEventPublisher
{
public event EventHandler<GameEvent> OnClientDisconnect;
public event EventHandler<GameEvent> OnClientConnect;
private readonly ILogger _logger;
public EventPublisher(ILogger<EventPublisher> logger)
{
_logger = logger;
}
public void Publish(GameEvent gameEvent)
{
_logger.LogDebug("Handling publishing event of type {EventType}", gameEvent.Type);
try
{
if (gameEvent.Type == GameEvent.EventType.Connect)
{
OnClientConnect?.Invoke(this, gameEvent);
}
if (gameEvent.Type == GameEvent.EventType.Disconnect)
{
OnClientDisconnect?.Invoke(this, gameEvent);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not publish event of type {EventType}", gameEvent.Type);
}
}
}
}

View File

@ -19,6 +19,12 @@ namespace IW4MAdmin.Application.Misc
/// </summary>
public string BasePathDirectory { get; set; } = "";
/// <summary>
/// directory for local storage
/// <remarks>fs_homepath</remarks>
/// </summary>
public string HomePathDirectory { get; set; } = "";
/// <summary>
/// overide game directory
/// <remarks>plugin driven</remarks>
@ -41,5 +47,11 @@ namespace IW4MAdmin.Application.Misc
/// indicates if running on windows
/// </summary>
public bool IsWindows { get; set; } = true;
/// <summary>
/// indicates that the game does not log to the mods folder (when mod is loaded),
/// but rather always to the fs_basegame directory
/// </summary>
public bool IsOneLog { get; set; }
}
}

View File

@ -179,7 +179,8 @@ namespace IW4MAdmin.Application.Misc
Id = s.EndPoint,
Port = (short)s.Port,
IPAddress = s.IP
}).ToList()
}).ToList(),
WebfrontUrl = _appConfig.WebfrontUrl
};
Response<ResultMessage> response = null;

View File

@ -168,6 +168,7 @@ namespace IW4MAdmin.Application.Misc
}
}
_scriptEngine.SetValue("_configHandler", new ScriptPluginConfigurationWrapper(Name, _scriptEngine));
await OnLoadAsync(manager);
try

View File

@ -0,0 +1,90 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using IW4MAdmin.Application.Configuration;
using Jint;
using Jint.Native;
using Newtonsoft.Json.Linq;
namespace IW4MAdmin.Application.Misc
{
public class ScriptPluginConfigurationWrapper
{
private readonly BaseConfigurationHandler<ScriptPluginConfiguration> _handler;
private readonly ScriptPluginConfiguration _config;
private readonly string _pluginName;
private readonly Engine _scriptEngine;
public ScriptPluginConfigurationWrapper(string pluginName, Engine scriptEngine)
{
_handler = new BaseConfigurationHandler<ScriptPluginConfiguration>("ScriptPluginSettings");
_config = _handler.Configuration() ??
(ScriptPluginConfiguration) new ScriptPluginConfiguration().Generate();
_pluginName = pluginName;
_scriptEngine = scriptEngine;
}
private static int? AsInteger(double d)
{
return int.TryParse(d.ToString(CultureInfo.InvariantCulture), out var parsed) ? parsed : (int?) null;
}
public async Task SetValue(string key, object value)
{
var castValue = value;
if (value is double d)
{
castValue = AsInteger(d) ?? value;
}
if (value is object[] array && array.All(item => item is double d && AsInteger(d) != null))
{
castValue = array.Select(item => AsInteger((double)item)).ToArray();
}
if (!_config.ContainsKey(_pluginName))
{
_config.Add(_pluginName, new Dictionary<string, object>());
}
var plugin = _config[_pluginName];
if (plugin.ContainsKey(key))
{
plugin[key] = castValue;
}
else
{
plugin.Add(key, castValue);
}
_handler.Set(_config);
await _handler.Save();
}
public JsValue GetValue(string key)
{
if (!_config.ContainsKey(_pluginName))
{
return JsValue.Undefined;
}
if (!_config[_pluginName].ContainsKey(key))
{
return JsValue.Undefined;
}
var item = _config[_pluginName][key];
if (item is JArray array)
{
item = array.ToObject<List<dynamic>>();
}
return JsValue.FromObject(_scriptEngine, item);
}
}
}

View File

@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Models;
using Data.Models.Client;
using Data.Models.Client.Stats.Reference;
using Data.Models.Server;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.Misc
{
/// <inheritdoc/>
public class ServerDataCollector : IServerDataCollector
{
private readonly ILogger _logger;
private readonly IManager _manager;
private readonly IDatabaseContextFactory _contextFactory;
private readonly ApplicationConfiguration _appConfig;
private readonly IEventPublisher _eventPublisher;
private bool _inProgress;
private TimeSpan _period;
public ServerDataCollector(ILogger<ServerDataCollector> logger, ApplicationConfiguration appConfig,
IManager manager, IDatabaseContextFactory contextFactory, IEventPublisher eventPublisher)
{
_logger = logger;
_appConfig = appConfig;
_manager = manager;
_contextFactory = contextFactory;
_eventPublisher = eventPublisher;
_eventPublisher.OnClientConnect += SaveConnectionInfo;
_eventPublisher.OnClientDisconnect += SaveConnectionInfo;
}
~ServerDataCollector()
{
_eventPublisher.OnClientConnect -= SaveConnectionInfo;
_eventPublisher.OnClientDisconnect -= SaveConnectionInfo;
}
public async Task BeginCollectionAsync(TimeSpan? period = null, CancellationToken cancellationToken = default)
{
if (_inProgress)
{
throw new InvalidOperationException($"{nameof(ServerDataCollector)} is already collecting data");
}
_logger.LogDebug("Initializing data collection with {Name}", nameof(ServerDataCollector));
_inProgress = true;
_period = period ?? (Utilities.IsDevelopment
? TimeSpan.FromMinutes(1)
: _appConfig.ServerDataCollectionInterval);
while (!cancellationToken.IsCancellationRequested)
{
try
{
await Task.Delay(_period, cancellationToken);
_logger.LogDebug("{Name} is collecting server data", nameof(ServerDataCollector));
var data = await BuildCollectionData(cancellationToken);
await SaveData(data, cancellationToken);
}
catch (TaskCanceledException)
{
_logger.LogInformation("Shutdown requested for {Name}", nameof(ServerDataCollector));
return;
}
catch (Exception ex)
{
_logger.LogError(ex, "Unexpected error encountered collecting server data for {Name}",
nameof(ServerDataCollector));
}
}
}
private async Task<IEnumerable<EFServerSnapshot>> BuildCollectionData(CancellationToken token)
{
var data = await Task.WhenAll(_manager.GetServers()
.Select(async server => new EFServerSnapshot
{
CapturedAt = DateTime.UtcNow,
PeriodBlock = (int) (DateTimeOffset.UtcNow - DateTimeOffset.UnixEpoch).TotalMinutes,
ServerId = await server.GetIdForServer(),
MapId = await GetOrCreateMap(server.CurrentMap.Name, (Reference.Game) server.GameName, token),
ClientCount = server.ClientNum
}));
return data;
}
private async Task<int> GetOrCreateMap(string mapName, Reference.Game game, CancellationToken token)
{
await using var context = _contextFactory.CreateContext();
var existingMap =
await context.Maps.FirstOrDefaultAsync(map => map.Name == mapName && map.Game == game, token);
if (existingMap != null)
{
return existingMap.MapId;
}
var newMap = new EFMap
{
Name = mapName,
Game = game
};
context.Maps.Add(newMap);
await context.SaveChangesAsync(token);
return newMap.MapId;
}
private async Task SaveData(IEnumerable<EFServerSnapshot> snapshots, CancellationToken token)
{
await using var context = _contextFactory.CreateContext();
context.ServerSnapshots.AddRange(snapshots);
await context.SaveChangesAsync(token);
}
private void SaveConnectionInfo(object sender, GameEvent gameEvent)
{
using var context = _contextFactory.CreateContext(enableTracking: false);
context.ConnectionHistory.Add(new EFClientConnectionHistory
{
ClientId = gameEvent.Origin.ClientId,
ServerId = gameEvent.Owner.GetIdForServer().Result,
ConnectionType = gameEvent.Type == GameEvent.EventType.Connect
? Reference.ConnectionType.Connect
: Reference.ConnectionType.Disconnect
});
context.SaveChanges();
}
}
}

View File

@ -0,0 +1,161 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Data.Abstractions;
using Data.Models.Client;
using Data.Models.Server;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace IW4MAdmin.Application.Misc
{
/// <inheritdoc/>
public class ServerDataViewer : IServerDataViewer
{
private readonly ILogger _logger;
private readonly IDataValueCache<EFServerSnapshot, (int?, DateTime?)> _snapshotCache;
private readonly IDataValueCache<EFClient, (int, int)> _serverStatsCache;
private readonly IDataValueCache<EFServerSnapshot, List<ClientHistoryInfo>> _clientHistoryCache;
private readonly TimeSpan? _cacheTimeSpan =
Utilities.IsDevelopment ? TimeSpan.FromSeconds(1) : (TimeSpan?) TimeSpan.FromMinutes(1);
public ServerDataViewer(ILogger<ServerDataViewer> logger, IDataValueCache<EFServerSnapshot, (int?, DateTime?)> snapshotCache,
IDataValueCache<EFClient, (int, int)> serverStatsCache,
IDataValueCache<EFServerSnapshot, List<ClientHistoryInfo>> clientHistoryCache)
{
_logger = logger;
_snapshotCache = snapshotCache;
_serverStatsCache = serverStatsCache;
_clientHistoryCache = clientHistoryCache;
}
public async Task<(int?, DateTime?)> MaxConcurrentClientsAsync(long? serverId = null, TimeSpan? overPeriod = null,
CancellationToken token = default)
{
_snapshotCache.SetCacheItem(async (snapshots, cancellationToken) =>
{
var oldestEntry = overPeriod.HasValue
? DateTime.UtcNow - overPeriod.Value
: DateTime.UtcNow.AddDays(-1);
int? maxClients;
DateTime? maxClientsTime;
if (serverId != null)
{
var clients = await snapshots.Where(snapshot => snapshot.ServerId == serverId)
.Where(snapshot => snapshot.CapturedAt >= oldestEntry)
.OrderByDescending(snapshot => snapshot.ClientCount)
.Select(snapshot => new
{
snapshot.ClientCount,
snapshot.CapturedAt
})
.FirstOrDefaultAsync(cancellationToken);
maxClients = clients?.ClientCount;
maxClientsTime = clients?.CapturedAt;
}
else
{
var clients = await snapshots.Where(snapshot => snapshot.CapturedAt >= oldestEntry)
.GroupBy(snapshot => snapshot.PeriodBlock)
.Select(grp => new
{
ClientCount = grp.Sum(snapshot => (int?) snapshot.ClientCount),
Time = grp.Max(snapshot => (DateTime?) snapshot.CapturedAt)
})
.OrderByDescending(snapshot => snapshot.ClientCount)
.FirstOrDefaultAsync(cancellationToken);
maxClients = clients?.ClientCount;
maxClientsTime = clients?.Time;
}
_logger.LogDebug("Max concurrent clients since {Start} is {Clients}", oldestEntry, maxClients);
return (maxClients, maxClientsTime);
}, nameof(MaxConcurrentClientsAsync), _cacheTimeSpan);
try
{
return await _snapshotCache.GetCacheItem(nameof(MaxConcurrentClientsAsync), token);
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not retrieve data for {Name}", nameof(MaxConcurrentClientsAsync));
return (null, null);
}
}
public async Task<(int, int)> ClientCountsAsync(TimeSpan? overPeriod = null, CancellationToken token = default)
{
_serverStatsCache.SetCacheItem(async (set, cancellationToken) =>
{
var count = await set.CountAsync(cancellationToken);
var startOfPeriod =
DateTime.UtcNow.AddHours(-overPeriod?.TotalHours ?? -24);
var recentCount = await set.CountAsync(client => client.LastConnection >= startOfPeriod,
cancellationToken);
return (count, recentCount);
}, nameof(_serverStatsCache), _cacheTimeSpan);
try
{
return await _serverStatsCache.GetCacheItem(nameof(_serverStatsCache), token);
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not retrieve data for {Name}", nameof(ClientCountsAsync));
return (0, 0);
}
}
public async Task<IEnumerable<ClientHistoryInfo>> ClientHistoryAsync(TimeSpan? overPeriod = null, CancellationToken token = default)
{
_clientHistoryCache.SetCacheItem(async (set, cancellationToken) =>
{
var oldestEntry = overPeriod.HasValue
? DateTime.UtcNow - overPeriod.Value
: DateTime.UtcNow.AddHours(-12);
var history = await set.Where(snapshot => snapshot.CapturedAt >= oldestEntry)
.Select(snapshot =>
new
{
snapshot.ServerId,
snapshot.CapturedAt,
snapshot.ClientCount
})
.OrderBy(snapshot => snapshot.CapturedAt)
.ToListAsync(cancellationToken);
return history.GroupBy(snapshot => snapshot.ServerId).Select(byServer => new ClientHistoryInfo
{
ServerId = byServer.Key,
ClientCounts = byServer.Select(snapshot => new ClientCountSnapshot()
{Time = snapshot.CapturedAt, ClientCount = snapshot.ClientCount}).ToList()
}).ToList();
}, nameof(_clientHistoryCache), TimeSpan.MaxValue);
try
{
return await _clientHistoryCache.GetCacheItem(nameof(_clientHistoryCache), token);
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not retrieve data for {Name}", nameof(ClientHistoryAsync));
return Enumerable.Empty<ClientHistoryInfo>();
}
}
}
}

View File

@ -13,7 +13,7 @@ using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Server;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace IW4MAdmin.Application.RconParsers
namespace IW4MAdmin.Application.RConParsers
{
public class BaseRConParser : IRConParser
{
@ -56,6 +56,7 @@ namespace IW4MAdmin.Application.RconParsers
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarDefaultValue, 3);
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarLatchedValue, 4);
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarDomain, 5);
Configuration.Dvar.AddMapping(ParserRegex.GroupType.AdditionalGroup, int.MaxValue);
Configuration.StatusHeader.Pattern = "num +score +ping +guid +name +lastmsg +address +qport +rate *";
Configuration.GametypeStatus.Pattern = "";
@ -73,11 +74,13 @@ namespace IW4MAdmin.Application.RconParsers
public Game GameName { get; set; } = Game.COD;
public bool CanGenerateLogPath { get; set; } = true;
public string Name { get; set; } = "Call of Duty";
public string RConEngine { get; set; } = "COD";
public bool IsOneLog { get; set; }
public async Task<string[]> ExecuteCommandAsync(IRConConnection connection, string command)
{
var response = await connection.SendQueryAsync(StaticHelpers.QueryType.COMMAND, command);
return response.Skip(1).ToArray();
return response.Where(item => item != Configuration.CommandPrefixes.RConResponse).ToArray();
}
public async Task<Dvar<T>> GetDvarAsync<T>(IRConConnection connection, string dvarName, T fallbackValue = default)
@ -128,7 +131,7 @@ namespace IW4MAdmin.Application.RconParsers
return new Dvar<T>()
{
Name = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarName]].Value,
Name = dvarName,
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)),
@ -136,53 +139,55 @@ namespace IW4MAdmin.Application.RconParsers
};
}
public virtual async Task<(List<EFClient>, string, string)> GetStatusAsync(IRConConnection connection)
public virtual async Task<IStatusResponse> GetStatusAsync(IRConConnection connection)
{
string[] response = await connection.SendQueryAsync(StaticHelpers.QueryType.COMMAND_STATUS);
var response = await connection.SendQueryAsync(StaticHelpers.QueryType.COMMAND_STATUS);
_logger.LogDebug("Status Response {response}", string.Join(Environment.NewLine, response));
return (ClientsFromStatus(response), MapFromStatus(response), GameTypeFromStatus(response));
return new StatusResponse
{
Clients = ClientsFromStatus(response).ToArray(),
Map = GetValueFromStatus<string>(response, ParserRegex.GroupType.RConStatusMap, Configuration.MapStatus.Pattern),
GameType = GetValueFromStatus<string>(response, ParserRegex.GroupType.RConStatusGametype, Configuration.GametypeStatus.Pattern),
Hostname = GetValueFromStatus<string>(response, ParserRegex.GroupType.RConStatusHostname, Configuration.HostnameStatus.Pattern),
MaxClients = GetValueFromStatus<int?>(response, ParserRegex.GroupType.RConStatusMaxPlayers, Configuration.MaxPlayersStatus.Pattern)
};
}
private string MapFromStatus(string[] response)
private T GetValueFromStatus<T>(IEnumerable<string> response, ParserRegex.GroupType groupType, string groupPattern)
{
string map = null;
if (string.IsNullOrEmpty(groupPattern))
{
return default;
}
string value = null;
foreach (var line in response)
{
var regex = Regex.Match(line, Configuration.MapStatus.Pattern);
var regex = Regex.Match(line, groupPattern);
if (regex.Success)
{
map = regex.Groups[Configuration.MapStatus.GroupMapping[ParserRegex.GroupType.RConStatusMap]].ToString();
value = regex.Groups[Configuration.MapStatus.GroupMapping[groupType]].ToString();
}
}
return map;
}
private string GameTypeFromStatus(string[] response)
{
if (string.IsNullOrWhiteSpace(Configuration.GametypeStatus.Pattern))
if (value == null)
{
return null;
return default;
}
string gametype = null;
foreach (var line in response)
if (typeof(T) == typeof(int?))
{
var regex = Regex.Match(line, Configuration.GametypeStatus.Pattern);
if (regex.Success)
{
gametype = regex.Groups[Configuration.GametypeStatus.GroupMapping[ParserRegex.GroupType.RConStatusGametype]].ToString();
}
return (T)Convert.ChangeType(int.Parse(value), Nullable.GetUnderlyingType(typeof(T)));
}
return gametype;
return (T)Convert.ChangeType(value, typeof(T));
}
public async Task<bool> SetDvarAsync(IRConConnection connection, string dvarName, object dvarValue)
{
string dvarString = (dvarValue is string str)
? $"{dvarName} \"{str}\""
: $"{dvarName} {dvarValue.ToString()}";
: $"{dvarName} {dvarValue}";
return (await connection.SendQueryAsync(StaticHelpers.QueryType.SET_DVAR, dvarString)).Length > 0;
}
@ -212,10 +217,15 @@ namespace IW4MAdmin.Application.RconParsers
continue;
}
int clientNumber = int.Parse(match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConClientNumber]]);
int score = int.Parse(match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConScore]]);
var clientNumber = int.Parse(match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConClientNumber]]);
var score = 0;
if (Configuration.Status.GroupMapping[ParserRegex.GroupType.RConScore] > 0)
{
score = int.Parse(match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConScore]]);
}
int ping = 999;
var ping = 999;
// their state can be CNCT, ZMBI etc
if (match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConPing]].Length <= 3)
@ -224,7 +234,7 @@ namespace IW4MAdmin.Application.RconParsers
}
long networkId;
string name = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConName]].TrimNewLine();
var name = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConName]].TrimNewLine();
string networkIdString;
var ip = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConIpAddress]].Split(':')[0].ConvertToIP();
@ -258,6 +268,17 @@ namespace IW4MAdmin.Application.RconParsers
client.SetAdditionalProperty("BotGuid", networkIdString);
if (Configuration.Status.GroupMapping.ContainsKey(ParserRegex.GroupType.AdditionalGroup))
{
var additionalGroupIndex =
Configuration.Status.GroupMapping[ParserRegex.GroupType.AdditionalGroup];
if (match.Values.Length > additionalGroupIndex)
{
client.SetAdditionalProperty("ConnectionClientId", match.Values[additionalGroupIndex]);
}
}
StatusPlayers.Add(client);
}
}

View File

@ -1,13 +1,13 @@
using Microsoft.Extensions.Logging;
using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.RconParsers
namespace IW4MAdmin.Application.RConParsers
{
/// <summary>
/// empty implementation of the IW4RConParser
/// allows script plugins to generate dynamic RCon parsers
/// </summary>
sealed internal class DynamicRConParser : BaseRConParser
internal sealed class DynamicRConParser : BaseRConParser
{
public DynamicRConParser(ILogger<BaseRConParser> logger, IParserRegexFactory parserRegexFactory) : base(logger, parserRegexFactory)
{

View File

@ -4,7 +4,7 @@ using SharedLibraryCore.RCon;
using System.Collections.Generic;
using System.Globalization;
namespace IW4MAdmin.Application.RconParsers
namespace IW4MAdmin.Application.RConParsers
{
/// <summary>
/// generic implementation of the IRConParserConfiguration
@ -16,6 +16,8 @@ namespace IW4MAdmin.Application.RconParsers
public ParserRegex Status { get; set; }
public ParserRegex MapStatus { get; set; }
public ParserRegex GametypeStatus { get; set; }
public ParserRegex HostnameStatus { get; set; }
public ParserRegex MaxPlayersStatus { get; set; }
public ParserRegex Dvar { get; set; }
public ParserRegex StatusHeader { get; set; }
public string ServerNotRunningResponse { get; set; }
@ -34,6 +36,8 @@ namespace IW4MAdmin.Application.RconParsers
GametypeStatus = parserRegexFactory.CreateParserRegex();
Dvar = parserRegexFactory.CreateParserRegex();
StatusHeader = parserRegexFactory.CreateParserRegex();
HostnameStatus = parserRegexFactory.CreateParserRegex();
MaxPlayersStatus = parserRegexFactory.CreateParserRegex();
}
}
}

View File

@ -0,0 +1,15 @@
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.RConParsers
{
/// <inheritdoc cref="IStatusResponse"/>
public class StatusResponse : IStatusResponse
{
public string Map { get; set; }
public string GameType { get; set; }
public string Hostname { get; set; }
public int? MaxClients { get; set; }
public EFClient[] Clients { get; set; }
}
}

View File

@ -0,0 +1,10 @@
using System;
namespace Data.Abstractions
{
public class IAuditFields
{
DateTime CreatedDateTime { get; set; }
DateTime? UpdatedDateTime { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
@ -6,7 +7,7 @@ namespace Data.Abstractions
{
public interface IDataValueCache<T, V> where T : class
{
void SetCacheItem(Func<DbSet<T>, Task<V>> itemGetter, string keyName, TimeSpan? expirationTime = null);
Task<V> GetCacheItem(string keyName);
void SetCacheItem(Func<DbSet<T>, CancellationToken, Task<V>> itemGetter, string keyName, TimeSpan? expirationTime = null);
Task<V> GetCacheItem(string keyName, CancellationToken token = default);
}
}

View File

@ -7,6 +7,7 @@ using Data.Models;
using Data.Models.Client;
using Data.Models.Client.Stats;
using Data.Models.Client.Stats.Reference;
using Data.Models.Misc;
using Data.Models.Server;
namespace Data.Context
@ -35,6 +36,14 @@ namespace Data.Context
public DbSet<EFWeapon> Weapons { get; set; }
public DbSet<EFWeaponAttachment> WeaponAttachments { get; set; }
public DbSet<EFMap> Maps { get; set; }
#endregion
#region MISC
public DbSet<EFInboxMessage> InboxMessages { get; set; }
public DbSet<EFServerSnapshot> ServerSnapshots { get;set; }
public DbSet<EFClientConnectionHistory> ConnectionHistory { get; set; }
#endregion
@ -121,11 +130,15 @@ namespace Data.Context
.OnDelete(DeleteBehavior.SetNull);
});
modelBuilder.Entity<EFClientConnectionHistory>(ent => ent.HasIndex(history => history.CreatedDateTime));
// force full name for database conversion
modelBuilder.Entity<EFClient>().ToTable("EFClients");
modelBuilder.Entity<EFAlias>().ToTable("EFAlias");
modelBuilder.Entity<EFAliasLink>().ToTable("EFAliasLinks");
modelBuilder.Entity<EFPenalty>().ToTable("EFPenalties");
modelBuilder.Entity<EFServerSnapshot>().ToTable(nameof(EFServerSnapshot));
modelBuilder.Entity<EFClientConnectionHistory>().ToTable(nameof(EFClientConnectionHistory));
Models.Configuration.StatsModelConfiguration.Configure(modelBuilder);

View File

@ -8,61 +8,9 @@
<PackageId>RaidMax.IW4MAdmin.Data</PackageId>
<Title>RaidMax.IW4MAdmin.Data</Title>
<Authors />
<PackageVersion>1.0.7</PackageVersion>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Migrations\MySql\20210210221342_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\MySql\20210210221342_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210224014503_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Postgresql\20210224014503_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210224030227_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Postgresql\20210224030227_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210224031245_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Postgresql\20210224031245_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210227041237_AddPerformancePercentileToClientStats.cs" />
<Compile Remove="Migrations\Postgresql\20210227041237_AddPerformancePercentileToClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210227161333_AddPerformancePercentileToClientStats.cs" />
<Compile Remove="Migrations\Postgresql\20210227161333_AddPerformancePercentileToClientStats.Designer.cs" />
<Compile Remove="Migrations\Postgresql\20210307163752_AddRankingHistory.cs" />
<Compile Remove="Migrations\Postgresql\20210307163752_AddRankingHistory.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210209205243_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210209205243_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210209205948_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210209205948_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210209211745_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210209211745_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210209212725_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210209212725_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210210020314_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210210020314_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210210140835_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210210140835_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210210154738_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210210154738_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210210163803_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210210163803_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210210193852_AddAdditionaClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210210193852_AddAdditionaClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210211033835_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210211033835_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210219013429_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210219013429_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210220171950_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210220171950_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210223163022_AddAdditionalClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210223163022_AddAdditionalClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210226215929_AddPerformancePercentileToClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210226215929_AddPerformancePercentileToClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210227160800_AddPerformancePercentileToClientStats.cs" />
<Compile Remove="Migrations\Sqlite\20210227160800_AddPerformancePercentileToClientStats.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210305033616_AddRankingHistory.cs" />
<Compile Remove="Migrations\Sqlite\20210305033616_AddRankingHistory.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210305033846_AddRankingHistory.cs" />
<Compile Remove="Migrations\Sqlite\20210305033846_AddRankingHistory.Designer.cs" />
<Compile Remove="Migrations\Sqlite\20210306223712_AddRankingHistory.cs" />
<Compile Remove="Migrations\Sqlite\20210306223712_AddRankingHistory.Designer.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.10">

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.EntityFrameworkCore;
@ -19,36 +20,39 @@ namespace Data.Helpers
public string Key { get; set; }
public DateTime LastRetrieval { get; set; }
public TimeSpan ExpirationTime { get; set; }
public Func<DbSet<T>, Task<V>> Getter { get; set; }
public Func<DbSet<T>, CancellationToken, Task<V>> Getter { get; set; }
public V Value { get; set; }
public bool IsExpired => (DateTime.Now - LastRetrieval.Add(ExpirationTime)).TotalSeconds > 0;
public bool IsExpired => ExpirationTime != TimeSpan.MaxValue &&
(DateTime.Now - LastRetrieval.Add(ExpirationTime)).TotalSeconds > 0;
}
public DataValueCache(ILogger<DataValueCache<T, V>> logger, IDatabaseContextFactory contextFactory)
{
_logger = logger;
_contextFactory = contextFactory;
}
public void SetCacheItem(Func<DbSet<T>, Task<V>> getter, string key, TimeSpan? expirationTime = null)
public void SetCacheItem(Func<DbSet<T>, CancellationToken, Task<V>> getter, string key,
TimeSpan? expirationTime = null)
{
if (_cacheStates.ContainsKey(key))
{
_logger.LogDebug("Cache key {key} is already added", key);
return;
}
var state = new CacheState()
{
Key = key,
Getter = getter,
ExpirationTime = expirationTime ?? TimeSpan.FromMinutes(DefaultExpireMinutes)
};
_cacheStates.Add(key, state);
}
public async Task<V> GetCacheItem(string keyName)
public async Task<V> GetCacheItem(string keyName, CancellationToken cancellationToken = default)
{
if (!_cacheStates.ContainsKey(keyName))
{
@ -57,21 +61,21 @@ namespace Data.Helpers
var state = _cacheStates[keyName];
if (state.IsExpired)
if (state.IsExpired || state.Value == null)
{
await RunCacheUpdate(state);
await RunCacheUpdate(state, cancellationToken);
}
return state.Value;
}
private async Task RunCacheUpdate(CacheState state)
private async Task RunCacheUpdate(CacheState state, CancellationToken token)
{
try
{
await using var context = _contextFactory.CreateContext(false);
var set = context.Set<T>();
var value = await state.Getter(set);
var value = await state.Getter(set, token);
state.Value = value;
state.LastRetrieval = DateTime.Now;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.MySql
{
public partial class AddWeaponReferenceToEFClientKill : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "WeaponReference",
table: "EFClientKills",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "WeaponReference",
table: "EFClientKills");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.MySql
{
public partial class AddWeaponReferenceAndServerIdToEFACSnapshot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<long>(
name: "ServerId",
table: "EFACSnapshot",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "WeaponReference",
table: "EFACSnapshot",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_EFACSnapshot_ServerId",
table: "EFACSnapshot",
column: "ServerId");
migrationBuilder.AddForeignKey(
name: "FK_EFACSnapshot_EFServers_ServerId",
table: "EFACSnapshot",
column: "ServerId",
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_EFACSnapshot_EFServers_ServerId",
table: "EFACSnapshot");
migrationBuilder.DropIndex(
name: "IX_EFACSnapshot_ServerId",
table: "EFACSnapshot");
migrationBuilder.DropColumn(
name: "ServerId",
table: "EFACSnapshot");
migrationBuilder.DropColumn(
name: "WeaponReference",
table: "EFACSnapshot");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.MySql
{
public partial class AddHitLocationReferenceToEFACSnapshot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "HitLocationReference",
table: "EFACSnapshot",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "HitLocationReference",
table: "EFACSnapshot");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.MySql
{
public partial class AddEFInboxMessage : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "InboxMessages",
columns: table => new
{
InboxMessageId = table.Column<int>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
CreatedDateTime = table.Column<DateTime>(nullable: false),
UpdatedDateTime = table.Column<DateTime>(nullable: true),
SourceClientId = table.Column<int>(nullable: false),
DestinationClientId = table.Column<int>(nullable: false),
ServerId = table.Column<long>(nullable: true),
Message = table.Column<string>(nullable: true),
IsDelivered = table.Column<bool>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_InboxMessages", x => x.InboxMessageId);
table.ForeignKey(
name: "FK_InboxMessages_EFClients_DestinationClientId",
column: x => x.DestinationClientId,
principalTable: "EFClients",
principalColumn: "ClientId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_InboxMessages_EFServers_ServerId",
column: x => x.ServerId,
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_InboxMessages_EFClients_SourceClientId",
column: x => x.SourceClientId,
principalTable: "EFClients",
principalColumn: "ClientId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_InboxMessages_DestinationClientId",
table: "InboxMessages",
column: "DestinationClientId");
migrationBuilder.CreateIndex(
name: "IX_InboxMessages_ServerId",
table: "InboxMessages",
column: "ServerId");
migrationBuilder.CreateIndex(
name: "IX_InboxMessages_SourceClientId",
table: "InboxMessages",
column: "SourceClientId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "InboxMessages");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.MySql
{
public partial class AddEFServerSnapshot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "EFServerSnapshot",
columns: table => new
{
ServerSnapshotId = table.Column<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Active = table.Column<bool>(nullable: false),
CapturedAt = table.Column<DateTime>(nullable: false),
PeriodBlock = table.Column<int>(nullable: false),
ServerId = table.Column<long>(nullable: false),
MapId = table.Column<int>(nullable: false),
ClientCount = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EFServerSnapshot", x => x.ServerSnapshotId);
table.ForeignKey(
name: "FK_EFServerSnapshot_EFMaps_MapId",
column: x => x.MapId,
principalTable: "EFMaps",
principalColumn: "MapId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_EFServerSnapshot_EFServers_ServerId",
column: x => x.ServerId,
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_EFServerSnapshot_MapId",
table: "EFServerSnapshot",
column: "MapId");
migrationBuilder.CreateIndex(
name: "IX_EFServerSnapshot_ServerId",
table: "EFServerSnapshot",
column: "ServerId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "EFServerSnapshot");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,62 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.MySql
{
public partial class AddEFClientConnectionHistory : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "EFClientConnectionHistory",
columns: table => new
{
ClientConnectionId = table.Column<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
CreatedDateTime = table.Column<DateTime>(nullable: false),
UpdatedDateTime = table.Column<DateTime>(nullable: true),
ClientId = table.Column<int>(nullable: false),
ServerId = table.Column<long>(nullable: false),
ConnectionType = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EFClientConnectionHistory", x => x.ClientConnectionId);
table.ForeignKey(
name: "FK_EFClientConnectionHistory_EFClients_ClientId",
column: x => x.ClientId,
principalTable: "EFClients",
principalColumn: "ClientId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_EFClientConnectionHistory_EFServers_ServerId",
column: x => x.ServerId,
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_EFClientConnectionHistory_ClientId",
table: "EFClientConnectionHistory",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_EFClientConnectionHistory_CreatedDateTime",
table: "EFClientConnectionHistory",
column: "CreatedDateTime");
migrationBuilder.CreateIndex(
name: "IX_EFClientConnectionHistory_ServerId",
table: "EFClientConnectionHistory",
column: "ServerId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "EFClientConnectionHistory");
}
}
}

View File

@ -95,6 +95,38 @@ namespace Data.Migrations.MySql
b.ToTable("EFClients");
});
modelBuilder.Entity("Data.Models.Client.EFClientConnectionHistory", b =>
{
b.Property<long>("ClientConnectionId")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("ConnectionType")
.HasColumnType("int");
b.Property<DateTime>("CreatedDateTime")
.HasColumnType("datetime(6)");
b.Property<long>("ServerId")
.HasColumnType("bigint");
b.Property<DateTime?>("UpdatedDateTime")
.HasColumnType("datetime(6)");
b.HasKey("ClientConnectionId");
b.HasIndex("ClientId");
b.HasIndex("CreatedDateTime");
b.HasIndex("ServerId");
b.ToTable("EFClientConnectionHistory");
});
modelBuilder.Entity("Data.Models.Client.EFClientKill", b =>
{
b.Property<long>("KillId")
@ -146,6 +178,9 @@ namespace Data.Migrations.MySql
b.Property<int>("Weapon")
.HasColumnType("int");
b.Property<string>("WeaponReference")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<DateTime>("When")
.HasColumnType("datetime(6)");
@ -237,6 +272,9 @@ namespace Data.Migrations.MySql
b.Property<int>("HitLocation")
.HasColumnType("int");
b.Property<string>("HitLocationReference")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<int>("HitOriginId")
.HasColumnType("int");
@ -255,6 +293,9 @@ namespace Data.Migrations.MySql
b.Property<double>("RecoilOffset")
.HasColumnType("double");
b.Property<long?>("ServerId")
.HasColumnType("bigint");
b.Property<double>("SessionAngleOffset")
.HasColumnType("double");
@ -279,6 +320,9 @@ namespace Data.Migrations.MySql
b.Property<int>("WeaponId")
.HasColumnType("int");
b.Property<string>("WeaponReference")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<DateTime>("When")
.HasColumnType("datetime(6)");
@ -294,6 +338,8 @@ namespace Data.Migrations.MySql
b.HasIndex("LastStrainAngleId");
b.HasIndex("ServerId");
b.ToTable("EFACSnapshot");
});
@ -921,6 +967,44 @@ namespace Data.Migrations.MySql
b.ToTable("EFPenalties");
});
modelBuilder.Entity("Data.Models.Misc.EFInboxMessage", b =>
{
b.Property<int>("InboxMessageId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<DateTime>("CreatedDateTime")
.HasColumnType("datetime(6)");
b.Property<int>("DestinationClientId")
.HasColumnType("int");
b.Property<bool>("IsDelivered")
.HasColumnType("tinyint(1)");
b.Property<string>("Message")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<long?>("ServerId")
.HasColumnType("bigint");
b.Property<int>("SourceClientId")
.HasColumnType("int");
b.Property<DateTime?>("UpdatedDateTime")
.HasColumnType("datetime(6)");
b.HasKey("InboxMessageId");
b.HasIndex("DestinationClientId");
b.HasIndex("ServerId");
b.HasIndex("SourceClientId");
b.ToTable("InboxMessages");
});
modelBuilder.Entity("Data.Models.Server.EFServer", b =>
{
b.Property<long>("ServerId")
@ -949,6 +1033,39 @@ namespace Data.Migrations.MySql
b.ToTable("EFServers");
});
modelBuilder.Entity("Data.Models.Server.EFServerSnapshot", b =>
{
b.Property<long>("ServerSnapshotId")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<bool>("Active")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("CapturedAt")
.HasColumnType("datetime(6)");
b.Property<int>("ClientCount")
.HasColumnType("int");
b.Property<int>("MapId")
.HasColumnType("int");
b.Property<int>("PeriodBlock")
.HasColumnType("int");
b.Property<long>("ServerId")
.HasColumnType("bigint");
b.HasKey("ServerSnapshotId");
b.HasIndex("MapId");
b.HasIndex("ServerId");
b.ToTable("EFServerSnapshot");
});
modelBuilder.Entity("Data.Models.Server.EFServerStatistics", b =>
{
b.Property<int>("StatisticId")
@ -1024,6 +1141,21 @@ namespace Data.Migrations.MySql
.IsRequired();
});
modelBuilder.Entity("Data.Models.Client.EFClientConnectionHistory", b =>
{
b.HasOne("Data.Models.Client.EFClient", "Client")
.WithMany()
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Data.Models.Client.EFClientKill", b =>
{
b.HasOne("Data.Models.Client.EFClient", "Attacker")
@ -1103,6 +1235,10 @@ namespace Data.Migrations.MySql
.HasForeignKey("LastStrainAngleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId");
});
modelBuilder.Entity("Data.Models.Client.Stats.EFClientHitStatistic", b =>
@ -1264,6 +1400,40 @@ namespace Data.Migrations.MySql
.IsRequired();
});
modelBuilder.Entity("Data.Models.Misc.EFInboxMessage", b =>
{
b.HasOne("Data.Models.Client.EFClient", "DestinationClient")
.WithMany()
.HasForeignKey("DestinationClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId");
b.HasOne("Data.Models.Client.EFClient", "SourceClient")
.WithMany()
.HasForeignKey("SourceClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Data.Models.Server.EFServerSnapshot", b =>
{
b.HasOne("Data.Models.Client.Stats.Reference.EFMap", "Map")
.WithMany()
.HasForeignKey("MapId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Data.Models.Server.EFServerStatistics", b =>
{
b.HasOne("Data.Models.Server.EFServer", "Server")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.Postgresql
{
public partial class AddWeaponReferenceToEFClientKill : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "WeaponReference",
table: "EFClientKills",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "WeaponReference",
table: "EFClientKills");
}
}
}

View File

@ -0,0 +1,52 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.Postgresql
{
public partial class AddWeaponReferenceAndServerIdToEFACSnapshot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<long>(
name: "ServerId",
table: "EFACSnapshot",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "WeaponReference",
table: "EFACSnapshot",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_EFACSnapshot_ServerId",
table: "EFACSnapshot",
column: "ServerId");
migrationBuilder.AddForeignKey(
name: "FK_EFACSnapshot_EFServers_ServerId",
table: "EFACSnapshot",
column: "ServerId",
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_EFACSnapshot_EFServers_ServerId",
table: "EFACSnapshot");
migrationBuilder.DropIndex(
name: "IX_EFACSnapshot_ServerId",
table: "EFACSnapshot");
migrationBuilder.DropColumn(
name: "ServerId",
table: "EFACSnapshot");
migrationBuilder.DropColumn(
name: "WeaponReference",
table: "EFACSnapshot");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.Postgresql
{
public partial class AddHitLocationReferenceToEFACSnapshot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "HitLocationReference",
table: "EFACSnapshot",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "HitLocationReference",
table: "EFACSnapshot");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Data.Migrations.Postgresql
{
public partial class AddEFInboxMessage : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "InboxMessages",
columns: table => new
{
InboxMessageId = table.Column<int>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
CreatedDateTime = table.Column<DateTime>(nullable: false),
UpdatedDateTime = table.Column<DateTime>(nullable: true),
SourceClientId = table.Column<int>(nullable: false),
DestinationClientId = table.Column<int>(nullable: false),
ServerId = table.Column<long>(nullable: true),
Message = table.Column<string>(nullable: true),
IsDelivered = table.Column<bool>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_InboxMessages", x => x.InboxMessageId);
table.ForeignKey(
name: "FK_InboxMessages_EFClients_DestinationClientId",
column: x => x.DestinationClientId,
principalTable: "EFClients",
principalColumn: "ClientId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_InboxMessages_EFServers_ServerId",
column: x => x.ServerId,
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_InboxMessages_EFClients_SourceClientId",
column: x => x.SourceClientId,
principalTable: "EFClients",
principalColumn: "ClientId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_InboxMessages_DestinationClientId",
table: "InboxMessages",
column: "DestinationClientId");
migrationBuilder.CreateIndex(
name: "IX_InboxMessages_ServerId",
table: "InboxMessages",
column: "ServerId");
migrationBuilder.CreateIndex(
name: "IX_InboxMessages_SourceClientId",
table: "InboxMessages",
column: "SourceClientId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "InboxMessages");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Data.Migrations.Postgresql
{
public partial class AddEFServerSnapshot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "EFServerSnapshot",
columns: table => new
{
ServerSnapshotId = table.Column<long>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
Active = table.Column<bool>(nullable: false),
CapturedAt = table.Column<DateTime>(nullable: false),
PeriodBlock = table.Column<int>(nullable: false),
ServerId = table.Column<long>(nullable: false),
MapId = table.Column<int>(nullable: false),
ClientCount = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EFServerSnapshot", x => x.ServerSnapshotId);
table.ForeignKey(
name: "FK_EFServerSnapshot_EFMaps_MapId",
column: x => x.MapId,
principalTable: "EFMaps",
principalColumn: "MapId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_EFServerSnapshot_EFServers_ServerId",
column: x => x.ServerId,
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_EFServerSnapshot_MapId",
table: "EFServerSnapshot",
column: "MapId");
migrationBuilder.CreateIndex(
name: "IX_EFServerSnapshot_ServerId",
table: "EFServerSnapshot",
column: "ServerId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "EFServerSnapshot");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,62 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Data.Migrations.Postgresql
{
public partial class AddEFClientConnectionHistory : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "EFClientConnectionHistory",
columns: table => new
{
ClientConnectionId = table.Column<long>(nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
CreatedDateTime = table.Column<DateTime>(nullable: false),
UpdatedDateTime = table.Column<DateTime>(nullable: true),
ClientId = table.Column<int>(nullable: false),
ServerId = table.Column<long>(nullable: false),
ConnectionType = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EFClientConnectionHistory", x => x.ClientConnectionId);
table.ForeignKey(
name: "FK_EFClientConnectionHistory_EFClients_ClientId",
column: x => x.ClientId,
principalTable: "EFClients",
principalColumn: "ClientId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_EFClientConnectionHistory_EFServers_ServerId",
column: x => x.ServerId,
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_EFClientConnectionHistory_ClientId",
table: "EFClientConnectionHistory",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_EFClientConnectionHistory_CreatedDateTime",
table: "EFClientConnectionHistory",
column: "CreatedDateTime");
migrationBuilder.CreateIndex(
name: "IX_EFClientConnectionHistory_ServerId",
table: "EFClientConnectionHistory",
column: "ServerId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "EFClientConnectionHistory");
}
}
}

View File

@ -99,6 +99,39 @@ namespace Data.Migrations.Postgresql
b.ToTable("EFClients");
});
modelBuilder.Entity("Data.Models.Client.EFClientConnectionHistory", b =>
{
b.Property<long>("ClientConnectionId")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn);
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int>("ConnectionType")
.HasColumnType("integer");
b.Property<DateTime>("CreatedDateTime")
.HasColumnType("timestamp without time zone");
b.Property<long>("ServerId")
.HasColumnType("bigint");
b.Property<DateTime?>("UpdatedDateTime")
.HasColumnType("timestamp without time zone");
b.HasKey("ClientConnectionId");
b.HasIndex("ClientId");
b.HasIndex("CreatedDateTime");
b.HasIndex("ServerId");
b.ToTable("EFClientConnectionHistory");
});
modelBuilder.Entity("Data.Models.Client.EFClientKill", b =>
{
b.Property<long>("KillId")
@ -151,6 +184,9 @@ namespace Data.Migrations.Postgresql
b.Property<int>("Weapon")
.HasColumnType("integer");
b.Property<string>("WeaponReference")
.HasColumnType("text");
b.Property<DateTime>("When")
.HasColumnType("timestamp without time zone");
@ -244,6 +280,9 @@ namespace Data.Migrations.Postgresql
b.Property<int>("HitLocation")
.HasColumnType("integer");
b.Property<string>("HitLocationReference")
.HasColumnType("text");
b.Property<int>("HitOriginId")
.HasColumnType("integer");
@ -262,6 +301,9 @@ namespace Data.Migrations.Postgresql
b.Property<double>("RecoilOffset")
.HasColumnType("double precision");
b.Property<long?>("ServerId")
.HasColumnType("bigint");
b.Property<double>("SessionAngleOffset")
.HasColumnType("double precision");
@ -286,6 +328,9 @@ namespace Data.Migrations.Postgresql
b.Property<int>("WeaponId")
.HasColumnType("integer");
b.Property<string>("WeaponReference")
.HasColumnType("text");
b.Property<DateTime>("When")
.HasColumnType("timestamp without time zone");
@ -301,6 +346,8 @@ namespace Data.Migrations.Postgresql
b.HasIndex("LastStrainAngleId");
b.HasIndex("ServerId");
b.ToTable("EFACSnapshot");
});
@ -944,6 +991,45 @@ namespace Data.Migrations.Postgresql
b.ToTable("EFPenalties");
});
modelBuilder.Entity("Data.Models.Misc.EFInboxMessage", b =>
{
b.Property<int>("InboxMessageId")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn);
b.Property<DateTime>("CreatedDateTime")
.HasColumnType("timestamp without time zone");
b.Property<int>("DestinationClientId")
.HasColumnType("integer");
b.Property<bool>("IsDelivered")
.HasColumnType("boolean");
b.Property<string>("Message")
.HasColumnType("text");
b.Property<long?>("ServerId")
.HasColumnType("bigint");
b.Property<int>("SourceClientId")
.HasColumnType("integer");
b.Property<DateTime?>("UpdatedDateTime")
.HasColumnType("timestamp without time zone");
b.HasKey("InboxMessageId");
b.HasIndex("DestinationClientId");
b.HasIndex("ServerId");
b.HasIndex("SourceClientId");
b.ToTable("InboxMessages");
});
modelBuilder.Entity("Data.Models.Server.EFServer", b =>
{
b.Property<long>("ServerId")
@ -972,6 +1058,40 @@ namespace Data.Migrations.Postgresql
b.ToTable("EFServers");
});
modelBuilder.Entity("Data.Models.Server.EFServerSnapshot", b =>
{
b.Property<long>("ServerSnapshotId")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn);
b.Property<bool>("Active")
.HasColumnType("boolean");
b.Property<DateTime>("CapturedAt")
.HasColumnType("timestamp without time zone");
b.Property<int>("ClientCount")
.HasColumnType("integer");
b.Property<int>("MapId")
.HasColumnType("integer");
b.Property<int>("PeriodBlock")
.HasColumnType("integer");
b.Property<long>("ServerId")
.HasColumnType("bigint");
b.HasKey("ServerSnapshotId");
b.HasIndex("MapId");
b.HasIndex("ServerId");
b.ToTable("EFServerSnapshot");
});
modelBuilder.Entity("Data.Models.Server.EFServerStatistics", b =>
{
b.Property<int>("StatisticId")
@ -1049,6 +1169,21 @@ namespace Data.Migrations.Postgresql
.IsRequired();
});
modelBuilder.Entity("Data.Models.Client.EFClientConnectionHistory", b =>
{
b.HasOne("Data.Models.Client.EFClient", "Client")
.WithMany()
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Data.Models.Client.EFClientKill", b =>
{
b.HasOne("Data.Models.Client.EFClient", "Attacker")
@ -1128,6 +1263,10 @@ namespace Data.Migrations.Postgresql
.HasForeignKey("LastStrainAngleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId");
});
modelBuilder.Entity("Data.Models.Client.Stats.EFClientHitStatistic", b =>
@ -1289,6 +1428,40 @@ namespace Data.Migrations.Postgresql
.IsRequired();
});
modelBuilder.Entity("Data.Models.Misc.EFInboxMessage", b =>
{
b.HasOne("Data.Models.Client.EFClient", "DestinationClient")
.WithMany()
.HasForeignKey("DestinationClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId");
b.HasOne("Data.Models.Client.EFClient", "SourceClient")
.WithMany()
.HasForeignKey("SourceClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Data.Models.Server.EFServerSnapshot", b =>
{
b.HasOne("Data.Models.Client.Stats.Reference.EFMap", "Map")
.WithMany()
.HasForeignKey("MapId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Data.Models.Server.EFServerStatistics", b =>
{
b.HasOne("Data.Models.Server.EFServer", "Server")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.Sqlite
{
public partial class AddWeaponReferenceToEFClientKill : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "WeaponReference",
table: "EFClientKills",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "WeaponReference",
table: "EFClientKills");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,162 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.Sqlite
{
public partial class AddWeaponReferenceAndServerIdToEFACSnapshot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"PRAGMA foreign_keys = 0;
CREATE TABLE sqlitestudio_temp_table AS SELECT *
FROM EFACSnapshot;
DROP TABLE EFACSnapshot;
CREATE TABLE EFACSnapshot (
Active INTEGER NOT NULL,
TimeSinceLastEvent INTEGER NOT NULL,
SnapshotId INTEGER NOT NULL
CONSTRAINT PK_EFACSnapshot PRIMARY KEY AUTOINCREMENT,
ClientId INTEGER NOT NULL,
ServerId INTEGER CONSTRAINT FK_EFACSnapshot_EFServers_ServerId REFERENCES EFServers (ServerId) ON DELETE RESTRICT,
[When] TEXT NOT NULL,
CurrentSessionLength INTEGER NOT NULL,
EloRating REAL NOT NULL,
SessionScore INTEGER NOT NULL,
SessionSPM REAL NOT NULL,
Hits INTEGER NOT NULL,
Kills INTEGER NOT NULL,
Deaths INTEGER NOT NULL,
CurrentStrain REAL NOT NULL,
StrainAngleBetween REAL NOT NULL,
SessionAngleOffset REAL NOT NULL,
LastStrainAngleId INTEGER NOT NULL,
HitOriginId INTEGER NOT NULL,
HitDestinationId INTEGER NOT NULL,
Distance REAL NOT NULL,
CurrentViewAngleId INTEGER,
WeaponId INTEGER NOT NULL,
WeaponReference TEXT,
HitLocation INTEGER NOT NULL,
HitType INTEGER NOT NULL,
RecoilOffset REAL NOT NULL
DEFAULT 0.0,
SessionAverageSnapValue REAL NOT NULL
DEFAULT 0.0,
SessionSnapHits INTEGER NOT NULL
DEFAULT 0,
CONSTRAINT FK_EFACSnapshot_EFClients_ClientId FOREIGN KEY (
ClientId
)
REFERENCES EFClients (ClientId) ON DELETE CASCADE,
CONSTRAINT FK_EFACSnapshot_Vector3_CurrentViewAngleId FOREIGN KEY (
CurrentViewAngleId
)
REFERENCES Vector3 (Vector3Id) ON DELETE RESTRICT,
CONSTRAINT FK_EFACSnapshot_Vector3_HitDestinationId FOREIGN KEY (
HitDestinationId
)
REFERENCES Vector3 (Vector3Id) ON DELETE CASCADE,
CONSTRAINT FK_EFACSnapshot_Vector3_HitOriginId FOREIGN KEY (
HitOriginId
)
REFERENCES Vector3 (Vector3Id) ON DELETE CASCADE,
CONSTRAINT FK_EFACSnapshot_Vector3_LastStrainAngleId FOREIGN KEY (
LastStrainAngleId
)
REFERENCES Vector3 (Vector3Id) ON DELETE CASCADE
);
INSERT INTO EFACSnapshot (
Active,
TimeSinceLastEvent,
SnapshotId,
ClientId,
[When],
CurrentSessionLength,
EloRating,
SessionScore,
SessionSPM,
Hits,
Kills,
Deaths,
CurrentStrain,
StrainAngleBetween,
SessionAngleOffset,
LastStrainAngleId,
HitOriginId,
HitDestinationId,
Distance,
CurrentViewAngleId,
WeaponId,
HitLocation,
HitType,
RecoilOffset,
SessionAverageSnapValue,
SessionSnapHits
)
SELECT Active,
TimeSinceLastEvent,
SnapshotId,
ClientId,
""When"",
CurrentSessionLength,
EloRating,
SessionScore,
SessionSPM,
Hits,
Kills,
Deaths,
CurrentStrain,
StrainAngleBetween,
SessionAngleOffset,
LastStrainAngleId,
HitOriginId,
HitDestinationId,
Distance,
CurrentViewAngleId,
WeaponId,
HitLocation,
HitType,
RecoilOffset,
SessionAverageSnapValue,
SessionSnapHits
FROM sqlitestudio_temp_table;
DROP TABLE sqlitestudio_temp_table;
CREATE INDEX IX_EFACSnapshot_ClientId ON EFACSnapshot (
""ClientId""
);
CREATE INDEX IX_EFACSnapshot_CurrentViewAngleId ON EFACSnapshot (
""CurrentViewAngleId""
);
CREATE INDEX IX_EFACSnapshot_HitDestinationId ON EFACSnapshot (
""HitDestinationId""
);
CREATE INDEX IX_EFACSnapshot_HitOriginId ON EFACSnapshot (
""HitOriginId""
);
CREATE INDEX IX_EFACSnapshot_LastStrainAngleId ON EFACSnapshot (
""LastStrainAngleId""
);
CREATE INDEX IX_EFACSnapshot_ServerId ON EFACSnapshot (
""_ServerId""
);
PRAGMA foreign_keys = 1;
");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.Sqlite
{
public partial class AddHitLocationReferenceToEFACSnapshot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "HitLocationReference",
table: "EFACSnapshot",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "HitLocationReference",
table: "EFACSnapshot");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,69 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.Sqlite
{
public partial class AddEFInboxMessage : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "InboxMessages",
columns: table => new
{
InboxMessageId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
CreatedDateTime = table.Column<DateTime>(nullable: false),
UpdatedDateTime = table.Column<DateTime>(nullable: true),
SourceClientId = table.Column<int>(nullable: false),
DestinationClientId = table.Column<int>(nullable: false),
ServerId = table.Column<long>(nullable: true),
Message = table.Column<string>(nullable: true),
IsDelivered = table.Column<bool>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_InboxMessages", x => x.InboxMessageId);
table.ForeignKey(
name: "FK_InboxMessages_EFClients_DestinationClientId",
column: x => x.DestinationClientId,
principalTable: "EFClients",
principalColumn: "ClientId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_InboxMessages_EFServers_ServerId",
column: x => x.ServerId,
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_InboxMessages_EFClients_SourceClientId",
column: x => x.SourceClientId,
principalTable: "EFClients",
principalColumn: "ClientId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_InboxMessages_DestinationClientId",
table: "InboxMessages",
column: "DestinationClientId");
migrationBuilder.CreateIndex(
name: "IX_InboxMessages_ServerId",
table: "InboxMessages",
column: "ServerId");
migrationBuilder.CreateIndex(
name: "IX_InboxMessages_SourceClientId",
table: "InboxMessages",
column: "SourceClientId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "InboxMessages");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.Sqlite
{
public partial class AddEFServerSnapshot : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "EFServerSnapshot",
columns: table => new
{
ServerSnapshotId = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Active = table.Column<bool>(nullable: false),
CapturedAt = table.Column<DateTime>(nullable: false),
PeriodBlock = table.Column<int>(nullable: false),
ServerId = table.Column<long>(nullable: false),
MapId = table.Column<int>(nullable: false),
ClientCount = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EFServerSnapshot", x => x.ServerSnapshotId);
table.ForeignKey(
name: "FK_EFServerSnapshot_EFMaps_MapId",
column: x => x.MapId,
principalTable: "EFMaps",
principalColumn: "MapId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_EFServerSnapshot_EFServers_ServerId",
column: x => x.ServerId,
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_EFServerSnapshot_MapId",
table: "EFServerSnapshot",
column: "MapId");
migrationBuilder.CreateIndex(
name: "IX_EFServerSnapshot_ServerId",
table: "EFServerSnapshot",
column: "ServerId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "EFServerSnapshot");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,61 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations.Sqlite
{
public partial class AddEFClientConnectionHistory : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "EFClientConnectionHistory",
columns: table => new
{
ClientConnectionId = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
CreatedDateTime = table.Column<DateTime>(nullable: false),
UpdatedDateTime = table.Column<DateTime>(nullable: true),
ClientId = table.Column<int>(nullable: false),
ServerId = table.Column<long>(nullable: false),
ConnectionType = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EFClientConnectionHistory", x => x.ClientConnectionId);
table.ForeignKey(
name: "FK_EFClientConnectionHistory_EFClients_ClientId",
column: x => x.ClientId,
principalTable: "EFClients",
principalColumn: "ClientId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_EFClientConnectionHistory_EFServers_ServerId",
column: x => x.ServerId,
principalTable: "EFServers",
principalColumn: "ServerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_EFClientConnectionHistory_ClientId",
table: "EFClientConnectionHistory",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_EFClientConnectionHistory_CreatedDateTime",
table: "EFClientConnectionHistory",
column: "CreatedDateTime");
migrationBuilder.CreateIndex(
name: "IX_EFClientConnectionHistory_ServerId",
table: "EFClientConnectionHistory",
column: "ServerId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "EFClientConnectionHistory");
}
}
}

View File

@ -94,6 +94,38 @@ namespace Data.Migrations.Sqlite
b.ToTable("EFClients");
});
modelBuilder.Entity("Data.Models.Client.EFClientConnectionHistory", b =>
{
b.Property<long>("ClientConnectionId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("ClientId")
.HasColumnType("INTEGER");
b.Property<int>("ConnectionType")
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedDateTime")
.HasColumnType("TEXT");
b.Property<long>("ServerId")
.HasColumnType("INTEGER");
b.Property<DateTime?>("UpdatedDateTime")
.HasColumnType("TEXT");
b.HasKey("ClientConnectionId");
b.HasIndex("ClientId");
b.HasIndex("CreatedDateTime");
b.HasIndex("ServerId");
b.ToTable("EFClientConnectionHistory");
});
modelBuilder.Entity("Data.Models.Client.EFClientKill", b =>
{
b.Property<long>("KillId")
@ -145,6 +177,9 @@ namespace Data.Migrations.Sqlite
b.Property<int>("Weapon")
.HasColumnType("INTEGER");
b.Property<string>("WeaponReference")
.HasColumnType("TEXT");
b.Property<DateTime>("When")
.HasColumnType("TEXT");
@ -236,6 +271,9 @@ namespace Data.Migrations.Sqlite
b.Property<int>("HitLocation")
.HasColumnType("INTEGER");
b.Property<string>("HitLocationReference")
.HasColumnType("TEXT");
b.Property<int>("HitOriginId")
.HasColumnType("INTEGER");
@ -254,6 +292,9 @@ namespace Data.Migrations.Sqlite
b.Property<double>("RecoilOffset")
.HasColumnType("REAL");
b.Property<long?>("ServerId")
.HasColumnType("INTEGER");
b.Property<double>("SessionAngleOffset")
.HasColumnType("REAL");
@ -278,6 +319,9 @@ namespace Data.Migrations.Sqlite
b.Property<int>("WeaponId")
.HasColumnType("INTEGER");
b.Property<string>("WeaponReference")
.HasColumnType("TEXT");
b.Property<DateTime>("When")
.HasColumnType("TEXT");
@ -293,6 +337,8 @@ namespace Data.Migrations.Sqlite
b.HasIndex("LastStrainAngleId");
b.HasIndex("ServerId");
b.ToTable("EFACSnapshot");
});
@ -920,6 +966,44 @@ namespace Data.Migrations.Sqlite
b.ToTable("EFPenalties");
});
modelBuilder.Entity("Data.Models.Misc.EFInboxMessage", b =>
{
b.Property<int>("InboxMessageId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedDateTime")
.HasColumnType("TEXT");
b.Property<int>("DestinationClientId")
.HasColumnType("INTEGER");
b.Property<bool>("IsDelivered")
.HasColumnType("INTEGER");
b.Property<string>("Message")
.HasColumnType("TEXT");
b.Property<long?>("ServerId")
.HasColumnType("INTEGER");
b.Property<int>("SourceClientId")
.HasColumnType("INTEGER");
b.Property<DateTime?>("UpdatedDateTime")
.HasColumnType("TEXT");
b.HasKey("InboxMessageId");
b.HasIndex("DestinationClientId");
b.HasIndex("ServerId");
b.HasIndex("SourceClientId");
b.ToTable("InboxMessages");
});
modelBuilder.Entity("Data.Models.Server.EFServer", b =>
{
b.Property<long>("ServerId")
@ -948,6 +1032,39 @@ namespace Data.Migrations.Sqlite
b.ToTable("EFServers");
});
modelBuilder.Entity("Data.Models.Server.EFServerSnapshot", b =>
{
b.Property<long>("ServerSnapshotId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("Active")
.HasColumnType("INTEGER");
b.Property<DateTime>("CapturedAt")
.HasColumnType("TEXT");
b.Property<int>("ClientCount")
.HasColumnType("INTEGER");
b.Property<int>("MapId")
.HasColumnType("INTEGER");
b.Property<int>("PeriodBlock")
.HasColumnType("INTEGER");
b.Property<long>("ServerId")
.HasColumnType("INTEGER");
b.HasKey("ServerSnapshotId");
b.HasIndex("MapId");
b.HasIndex("ServerId");
b.ToTable("EFServerSnapshot");
});
modelBuilder.Entity("Data.Models.Server.EFServerStatistics", b =>
{
b.Property<int>("StatisticId")
@ -1023,6 +1140,21 @@ namespace Data.Migrations.Sqlite
.IsRequired();
});
modelBuilder.Entity("Data.Models.Client.EFClientConnectionHistory", b =>
{
b.HasOne("Data.Models.Client.EFClient", "Client")
.WithMany()
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Data.Models.Client.EFClientKill", b =>
{
b.HasOne("Data.Models.Client.EFClient", "Attacker")
@ -1102,6 +1234,10 @@ namespace Data.Migrations.Sqlite
.HasForeignKey("LastStrainAngleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId");
});
modelBuilder.Entity("Data.Models.Client.Stats.EFClientHitStatistic", b =>
@ -1263,6 +1399,40 @@ namespace Data.Migrations.Sqlite
.IsRequired();
});
modelBuilder.Entity("Data.Models.Misc.EFInboxMessage", b =>
{
b.HasOne("Data.Models.Client.EFClient", "DestinationClient")
.WithMany()
.HasForeignKey("DestinationClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId");
b.HasOne("Data.Models.Client.EFClient", "SourceClient")
.WithMany()
.HasForeignKey("SourceClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Data.Models.Server.EFServerSnapshot", b =>
{
b.HasOne("Data.Models.Client.Stats.Reference.EFMap", "Map")
.WithMany()
.HasForeignKey("MapId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Data.Models.Server.EFServer", "Server")
.WithMany()
.HasForeignKey("ServerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Data.Models.Server.EFServerStatistics", b =>
{
b.HasOne("Data.Models.Server.EFServer", "Server")

View File

@ -1,9 +1,10 @@
using System;
using System.ComponentModel.DataAnnotations;
using Data.Abstractions;
namespace Stats.Models
{
public class AuditFields
public class AuditFields : IAuditFields
{
[Required]
public DateTime CreatedDateTime { get; set; } = DateTime.UtcNow;

View File

@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Data.Models.Server;
using Stats.Models;
namespace Data.Models.Client
{
public class EFClientConnectionHistory : AuditFields
{
[Key]
public long ClientConnectionId { get; set; }
public int ClientId { get; set; }
[ForeignKey(nameof(ClientId))]
public EFClient Client { get;set; }
public long ServerId { get; set; }
[ForeignKey(nameof(ServerId))]
public EFServer Server { get;set; }
public Reference.ConnectionType ConnectionType { get; set; }
}
}

View File

@ -18,7 +18,9 @@ namespace Data.Models.Client
public int HitLoc { get; set; }
public int DeathType { get; set; }
public int Damage { get; set; }
[Obsolete]
public int Weapon { get; set; }
public string WeaponReference { get; set; }
public Vector3 KillOrigin { get; set; }
public Vector3 DeathOrigin { get; set; }
public Vector3 ViewAngles { get; set; }

View File

@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Numerics;
using Data.Models.Server;
namespace Data.Models.Client.Stats
{
@ -17,7 +18,9 @@ namespace Data.Models.Client.Stats
public int ClientId { get; set; }
[ForeignKey("ClientId")]
public EFClient Client { get; set; }
public long? ServerId { get; set; }
[ForeignKey(nameof(ServerId))]
public EFServer Server { get; set; }
public DateTime When { get; set; }
public int CurrentSessionLength { get; set; }
public int TimeSinceLastEvent { get; set; }
@ -46,8 +49,11 @@ namespace Data.Models.Client.Stats
public int CurrentViewAngleId { get; set; }
[ForeignKey("CurrentViewAngleId")]
public Vector3 CurrentViewAngle { get; set; }
[Obsolete]
public int WeaponId { get; set; }
public string WeaponReference { get; set; }
public int HitLocation { get; set; }
public string HitLocationReference { get; set; }
public int HitType { get; set; }
public virtual ICollection<EFACSnapshotVector3> PredictedViewAngles { get; set; }
@ -55,5 +61,7 @@ namespace Data.Models.Client.Stats
public string CapturedViewAngles => PredictedViewAngles?.Count > 0 ?
string.Join(", ", PredictedViewAngles.OrderBy(_angle => _angle.ACSnapshotVector3Id).Select(_angle => _angle.Vector.ToString())) :
"";
[NotMapped] public string ServerName => Server?.HostName ?? "--";
}
}

View File

@ -0,0 +1,35 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Data.Models.Client;
using Data.Models.Server;
using Stats.Models;
namespace Data.Models.Misc
{
public class EFInboxMessage : AuditFields
{
[Key]
public int InboxMessageId { get; set; }
[Required]
public int SourceClientId { get; set; }
[ForeignKey(nameof(SourceClientId))]
public EFClient SourceClient { get; set; }
[Required]
public int DestinationClientId { get; set; }
[ForeignKey(nameof(DestinationClientId))]
public EFClient DestinationClient { get; set; }
public long? ServerId { get; set; }
[ForeignKey(nameof(ServerId))]
public EFServer Server { get; set; }
public string Message { get; set; }
public bool IsDelivered { get; set; }
}
}

View File

@ -13,7 +13,15 @@
T4 = 5,
T5 = 6,
T6 = 7,
T7 = 8
T7 = 8,
SHG1 = 9,
CSGO = 10
}
public enum ConnectionType
{
Connect,
Disconnect
}
}
}

View File

@ -0,0 +1,36 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Data.Models.Client.Stats.Reference;
namespace Data.Models.Server
{
public class EFServerSnapshot : SharedEntity
{
[Key]
public long ServerSnapshotId { get; set; }
public DateTime CapturedAt { get; set; }
/// <summary>
/// Specifies at which time block during a period the snapshot occured
/// | 1:00 | 1:05 | 1:10 |
/// | 5 minutes | 5 minutes | 5 minutes |
/// | 0 | 1 | 2 |
/// </summary>
public int PeriodBlock { get; set; }
[Required]
public long ServerId { get; set; }
[ForeignKey(nameof(ServerId))]
public EFServer Server { get; set; }
public int MapId { get; set; }
[ForeignKey(nameof(MapId))]
public EFMap Map { get; set; }
public int ClientCount { get; set; }
}
}

View File

@ -5,7 +5,7 @@ namespace Data.Models
{
public class SharedEntity : IPropertyExtender
{
private readonly ConcurrentDictionary<string, object> _additionalProperties;
private ConcurrentDictionary<string, object> _additionalProperties;
/// <summary>
/// indicates if the entity is active
@ -33,5 +33,10 @@ namespace Data.Models
_additionalProperties.TryAdd(name, value);
}
}
public void CopyAdditionalProperties(SharedEntity source)
{
_additionalProperties = source._additionalProperties;
}
}
}

View File

@ -139,35 +139,35 @@ steps:
archiveFile: '$(Build.ArtifactStagingDirectory)/IW4MAdmin-$(Build.BuildNumber).zip'
replaceExistingArchive: true
- task: FtpUpload@2
displayName: 'Upload zip file to website'
inputs:
credentialsOption: 'inputs'
serverUrl: '$(FTPUrl)'
username: '$(FTPUsername)'
password: '$(FTPPassword)'
rootDirectory: '$(Build.ArtifactStagingDirectory)'
filePatterns: '*.zip'
remoteDirectory: 'IW4MAdmin/Download'
clean: false
cleanContents: false
preservePaths: false
trustSSL: false
#- task: FtpUpload@2
# displayName: 'Upload zip file to website'
# inputs:
# credentialsOption: 'inputs'
# serverUrl: '$(FTPUrl)'
# username: '$(FTPUsername)'
# password: '$(FTPPassword)'
# rootDirectory: '$(Build.ArtifactStagingDirectory)'
# filePatterns: '*.zip'
# remoteDirectory: 'IW4MAdmin/Download'
# clean: false
# cleanContents: false
# preservePaths: false
# trustSSL: false
- task: FtpUpload@2
displayName: 'Upload version info to website'
inputs:
credentialsOption: 'inputs'
serverUrl: '$(FTPUrl)'
username: '$(FTPUsername)'
password: '$(FTPPassword)'
rootDirectory: '$(Build.ArtifactStagingDirectory)'
filePatterns: 'version_$(releaseType).txt'
remoteDirectory: 'IW4MAdmin'
clean: false
cleanContents: false
preservePaths: false
trustSSL: false
#- task: FtpUpload@2
# displayName: 'Upload version info to website'
# inputs:
# credentialsOption: 'inputs'
# serverUrl: '$(FTPUrl)'
# username: '$(FTPUsername)'
# password: '$(FTPPassword)'
# rootDirectory: '$(Build.ArtifactStagingDirectory)'
# filePatterns: 'version_$(releaseType).txt'
# remoteDirectory: 'IW4MAdmin'
# clean: false
# cleanContents: false
# preservePaths: false
# trustSSL: false
- task: GitHubRelease@1
displayName: 'Make GitHub release'

View File

@ -0,0 +1,23 @@
# IW5
This expands IW4M-Admins's Anti-cheat to Plutonium IW5
## Installation
Add ``_customcallbacks.gsc`` into the scripts folder. (%localappdata%\Plutonium\storage\iw5\scripts)
For more info check out Chase's [how-to guide](https://forum.plutonium.pw/topic/10738/tutorial-loading-custom-gsc-scripts).
You need to add this to you ``StatsPluginSettings.json`` found in your IW4M-Admin configuration folder.
```
"IW5": {
"Recoil": [
"iw5_1887_mp.*",
"turret_minigun_mp"
],
"Button": [
".*akimbo.*"
]
}
```
[Example](https://imgur.com/Ji9AafI)

View File

@ -0,0 +1,249 @@
#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
#include common_scripts\utility;
init()
{
Print("IW4MADMIN Anti-Cheat Loaded");
SetDvarIfUninitialized( "sv_customcallbacks", true );
SetDvarIfUninitialized( "sv_framewaittime", 0.05 );
SetDvarIfUninitialized( "sv_additionalwaittime", 0.1 );
SetDvarIfUninitialized( "sv_maxstoredframes", 12 );
SetDvarIfUninitialized( "sv_printradarupdates", 0 );
SetDvarIfUninitialized( "sv_printradar_updateinterval", 500 );
SetDvarIfUninitialized( "sv_iw4madmin_url", "http://127.0.0.1:1624" );
level thread onPlayerConnect();
if (getDvarInt("sv_printradarupdates") == 1)
{
level thread runRadarUpdates();
}
level waittill( "prematch_over" );
level.callbackPlayerKilled = ::Callback_PlayerKilled;
level.callbackPlayerDamage = ::Callback_PlayerDamage;
level.callbackPlayerDisconnect = ::Callback_PlayerDisconnect;
}
onPlayerConnect( player )
{
for( ;; )
{
level waittill( "connected", player );
player setClientDvar("cl_demo_enabled", 1);
player thread waitForFrameThread();
player thread waitForAttack();
}
}
waitForAttack()
{
self endon( "disconnect" );
self.lastAttackTime = 0;
for( ;; )
{
self notifyOnPlayerCommand( "player_shot", "+attack" );
self waittill( "player_shot" );
self.lastAttackTime = getTime();
}
}
runRadarUpdates()
{
interval = int(getDvar("sv_printradar_updateinterval"));
for ( ;; )
{
for ( i = 0; i <= 17; i++ )
{
player = level.players[i];
if ( isDefined( player ) )
{
payload = player.guid + ";" + player.origin + ";" + player getPlayerAngles() + ";" + player.team + ";" + player.kills + ";" + player.deaths + ";" + player.score + ";" + player GetCurrentWeapon() + ";" + player.health + ";" + isAlive(player) + ";" + player.timePlayed["total"];
logPrint( "LiveRadar;" + payload + "\n" );
}
}
wait( interval / 1000 );
}
}
hitLocationToBone( hitloc )
{
switch( hitloc )
{
case "helmet":
return "j_helmet";
case "head":
return "j_head";
case "neck":
return "j_neck";
case "torso_upper":
return "j_spineupper";
case "torso_lower":
return "j_spinelower";
case "right_arm_upper":
return "j_shoulder_ri";
case "left_arm_upper":
return "j_shoulder_le";
case "right_arm_lower":
return "j_elbow_ri";
case "left_arm_lower":
return "j_elbow_le";
case "right_hand":
return "j_wrist_ri";
case "left_hand":
return "j_wrist_le";
case "right_leg_upper":
return "j_hip_ri";
case "left_leg_upper":
return "j_hip_le";
case "right_leg_lower":
return "j_knee_ri";
case "left_leg_lower":
return "j_knee_le";
case "right_foot":
return "j_ankle_ri";
case "left_foot":
return "j_ankle_le";
default:
return "tag_origin";
}
}
waitForFrameThread()
{
self endon( "disconnect" );
self.currentAnglePosition = 0;
self.anglePositions = [];
for (i = 0; i < getDvarInt( "sv_maxstoredframes" ); i++)
{
self.anglePositions[i] = self getPlayerAngles();
}
for( ;; )
{
self.anglePositions[self.currentAnglePosition] = self getPlayerAngles();
wait( getDvarFloat( "sv_framewaittime" ) );
self.currentAnglePosition = (self.currentAnglePosition + 1) % getDvarInt( "sv_maxstoredframes" );
}
}
waitForAdditionalAngles( logString, beforeFrameCount, afterFrameCount )
{
currentIndex = self.currentAnglePosition;
wait( 0.05 * afterFrameCount );
self.angleSnapshot = [];
for( j = 0; j < self.anglePositions.size; j++ )
{
self.angleSnapshot[j] = self.anglePositions[j];
}
anglesStr = "";
collectedFrames = 0;
i = currentIndex - beforeFrameCount;
while (collectedFrames < beforeFrameCount)
{
fixedIndex = i;
if (i < 0)
{
fixedIndex = self.angleSnapshot.size - abs(i);
}
anglesStr += self.angleSnapshot[int(fixedIndex)] + ":";
collectedFrames++;
i++;
}
if (i == currentIndex)
{
anglesStr += self.angleSnapshot[i] + ":";
i++;
}
collectedFrames = 0;
while (collectedFrames < afterFrameCount)
{
fixedIndex = i;
if (i > self.angleSnapshot.size - 1)
{
fixedIndex = i % self.angleSnapshot.size;
}
anglesStr += self.angleSnapshot[int(fixedIndex)] + ":";
collectedFrames++;
i++;
}
lastAttack = int(getTime()) - int(self.lastAttackTime);
isAlive = isAlive(self);
logPrint(logString + ";" + anglesStr + ";" + isAlive + ";" + lastAttack + "\n" );
}
vectorScale( vector, scale )
{
return ( vector[0] * scale, vector[1] * scale, vector[2] * scale );
}
Process_Hit( type, attacker, sHitLoc, sMeansOfDeath, iDamage, sWeapon )
{
if (sMeansOfDeath == "MOD_FALLING" || !isPlayer(attacker))
{
return;
}
victim = self;
_attacker = attacker;
if ( !isPlayer( attacker ) && isDefined( attacker.owner ) )
{
_attacker = attacker.owner;
}
else if( !isPlayer( attacker ) && sMeansOfDeath == "MOD_FALLING" )
{
_attacker = victim;
}
location = victim GetTagOrigin( hitLocationToBone( sHitLoc ) );
isKillstreakKill = !isPlayer( attacker ) || isKillstreakWeapon( sWeapon );
logLine = "Script" + type + ";" + _attacker.guid + ";" + victim.guid + ";" + _attacker GetTagOrigin("tag_eye") + ";" + location + ";" + iDamage + ";" + sWeapon + ";" + sHitLoc + ";" + sMeansOfDeath + ";" + _attacker getPlayerAngles() + ";" + int(gettime()) + ";" + isKillstreakKill + ";" + _attacker playerADS() + ";0;0";
attacker thread waitForAdditionalAngles( logLine, 2, 2 );
}
Callback_PlayerDamage( eInflictor, attacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime )
{
if ( self.health - iDamage > 0 )
{
isFriendlyFire = level.teamBased && isDefined( attacker ) && ( self != attacker ) && isDefined( attacker.team ) && ( self.pers[ "team" ] == attacker.team );
if ( !isFriendlyFire )
{
self Process_Hit( "Damage", attacker, sHitLoc, sMeansOfDeath, iDamage, sWeapon );
}
}
self maps\mp\gametypes\_damage::Callback_PlayerDamage( eInflictor, attacker, iDamage, iDFlags, sMeansOfDeath, sWeapon, vPoint, vDir, sHitLoc, psOffsetTime );
}
Callback_PlayerKilled( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration )
{
Process_Hit( "Kill", attacker, sHitLoc, sMeansOfDeath, iDamage, sWeapon );
self maps\mp\gametypes\_damage::Callback_PlayerKilled( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration );
}
Callback_PlayerDisconnect()
{
level notify( "disconnected", self );
self maps\mp\gametypes\_playerlogic::Callback_PlayerDisconnect();
}

35
GameFiles/PT6/README.MD Normal file
View File

@ -0,0 +1,35 @@
# T6
This brings IW4M-Admins's Anti-cheat to Plutonium T6
The following limitations are known:
* Can't get the recoil from weapons fire; you have to disable this detection type manually.
* in extreme cases it can produce false positives for Snap and Offset detection.
## Installation
Move `_customcallbacks.gsc` to `%localappdata%\Plutonium\storage\t6\scripts\mp\`
Add this to the WeaponNameParserConfigurations List in the StatsPluginSettings.json file:
```
{
"Game": "T6",
"Delimiters": [
"_",
"+"
],
"WeaponSuffix": "mp",
"WeaponPrefix": null
}
```
Now create the following entry for __EVERY__ T6 server you are using this on in the ServerDetectionTypes list:
```
"1270014976": [
"Offset",
"Strain",
"Snap"
]
```

View File

@ -3,24 +3,6 @@
#include common_scripts\utility;
init()
{
level.clientid = 0;
level thread onplayerconnect();
level thread IW4MA_init();
}
onplayerconnect()
{
for ( ;; )
{
level waittill( "connecting", player );
player.clientid = level.clientid;
level.clientid++;
}
}
IW4MA_init()
{
SetDvarIfUninitialized( "sv_customcallbacks", true );
SetDvarIfUninitialized( "sv_framewaittime", 0.05 );
@ -29,53 +11,52 @@ IW4MA_init()
SetDvarIfUninitialized( "sv_printradarupdates", 0 );
SetDvarIfUninitialized( "sv_printradar_updateinterval", 500 );
SetDvarIfUninitialized( "sv_iw4madmin_url", "http://127.0.0.1:1624" );
level thread IW4MA_onPlayerConnect();
level thread onPlayerConnect();
if (getDvarInt("sv_printradarupdates") == 1)
{
level thread runRadarUpdates();
}
level waittill( "prematch_over" );
level.callbackPlayerKilled = ::Callback_PlayerKilled;
level.callbackPlayerDamage = ::Callback_PlayerDamage;
level.callbackPlayerDisconnect = ::Callback_PlayerDisconnect;
}
//Does not exist in T6
//It's called slightly different in T6
//set_dvar_if_unset(dvar, val, reset)
SetDvarIfUninitialized(dvar, val)
{
curval = getDvar(dvar);
if (curval == "")
SetDvar(dvar,val);
set_dvar_if_unset(dvar,val);
}
IW4MA_onPlayerConnect( player )
onPlayerConnect( player )
{
for( ;; )
{
level waittill( "connected", player );
player thread waitForFrameThread();
//player thread waitForAttack();
player thread waitForAttack();
}
}
//Does not work in T6
/*waitForAttack()
//Got added to T6 on April 2020
waitForAttack()
{
self endon( "disconnect" );
self.lastAttackTime = 0;
for( ;; )
{
self notifyOnPlayerCommand( "player_shot", "+attack" );
self waittill( "player_shot" );
self.lastAttackTime = getTime();
}
}*/
}
runRadarUpdates()
{
@ -95,7 +76,7 @@ runRadarUpdates()
}
wait( interval / 1000 );
}
}
}
hitLocationToBone( hitloc )
@ -144,7 +125,7 @@ hitLocationToBone( hitloc )
waitForFrameThread()
{
self endon( "disconnect" );
self.currentAnglePosition = 0;
self.anglePositions = [];
@ -152,7 +133,7 @@ waitForFrameThread()
{
self.anglePositions[i] = self getPlayerAngles();
}
for( ;; )
{
self.anglePositions[self.currentAnglePosition] = self getPlayerAngles();
@ -165,9 +146,9 @@ waitForAdditionalAngles( logString, beforeFrameCount, afterFrameCount )
{
currentIndex = self.currentAnglePosition;
wait( 0.05 * afterFrameCount );
self.angleSnapshot = [];
for( j = 0; j < self.anglePositions.size; j++ )
{
self.angleSnapshot[j] = self.anglePositions[j];
@ -209,7 +190,7 @@ waitForAdditionalAngles( logString, beforeFrameCount, afterFrameCount )
i++;
}
lastAttack = 100;//int(getTime()) - int(self.lastAttackTime);
lastAttack = int(getTime()) - int(self.lastAttackTime);
isAlive = isAlive(self);
logPrint(logString + ";" + anglesStr + ";" + isAlive + ";" + lastAttack + "\n" );
@ -261,7 +242,7 @@ Callback_PlayerDamage( eInflictor, attacker, iDamage, iDFlags, sMeansOfDeath, sW
{
return;
}
if ( self.health - iDamage > 0 )
{
self Process_Hit( "Damage", attacker, sHitLoc, sMeansOfDeath, iDamage, sWeapon );

View File

@ -45,6 +45,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ScriptPlugins", "ScriptPlug
Plugins\ScriptPlugins\SampleScriptPluginCommand.js = Plugins\ScriptPlugins\SampleScriptPluginCommand.js
Plugins\ScriptPlugins\SharedGUIDKick.js = Plugins\ScriptPlugins\SharedGUIDKick.js
Plugins\ScriptPlugins\VPNDetection.js = Plugins\ScriptPlugins\VPNDetection.js
Plugins\ScriptPlugins\ParserPlutoniumT4.js = Plugins\ScriptPlugins\ParserPlutoniumT4.js
Plugins\ScriptPlugins\ParserS1x.js = Plugins\ScriptPlugins\ParserS1x.js
Plugins\ScriptPlugins\ParserCSGO.js = Plugins\ScriptPlugins\ParserCSGO.js
Plugins\ScriptPlugins\ParserCSGOSM.js = Plugins\ScriptPlugins\ParserCSGOSM.js
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutomessageFeed", "Plugins\AutomessageFeed\AutomessageFeed.csproj", "{F5815359-CFC7-44B4-9A3B-C04BACAD5836}"
@ -57,6 +61,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationTests", "Tests\A
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Data", "Data\Data.csproj", "{81689023-E55E-48ED-B7A8-53F4E21BBF2D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Integrations", "Integrations", "{A2AE33B4-0830-426A-9E11-951DAB12BE5B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Integrations.Cod", "Integrations\Cod\Integrations.Cod.csproj", "{A9348433-58C1-4B9C-8BB7-088B02529D9D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Integrations.Source", "Integrations\Source\Integrations.Source.csproj", "{9512295B-3045-40E0-9B7E-2409F2173E9D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -360,6 +370,54 @@ Global
{81689023-E55E-48ED-B7A8-53F4E21BBF2D}.Release|x86.Build.0 = Release|Any CPU
{81689023-E55E-48ED-B7A8-53F4E21BBF2D}.Prerelease|Any CPU.ActiveCfg = Prerelease|Any CPU
{81689023-E55E-48ED-B7A8-53F4E21BBF2D}.Prerelease|Any CPU.Build.0 = Prerelease|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Debug|x64.ActiveCfg = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Debug|x64.Build.0 = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Debug|x86.ActiveCfg = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Debug|x86.Build.0 = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Prerelease|Mixed Platforms.ActiveCfg = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Prerelease|Mixed Platforms.Build.0 = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Prerelease|x64.ActiveCfg = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Prerelease|x64.Build.0 = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Prerelease|x86.ActiveCfg = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Prerelease|x86.Build.0 = Debug|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Release|Any CPU.Build.0 = Release|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Release|x64.ActiveCfg = Release|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Release|x64.Build.0 = Release|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Release|x86.ActiveCfg = Release|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Release|x86.Build.0 = Release|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Prerelease|Any CPU.ActiveCfg = Prerelease|Any CPU
{A9348433-58C1-4B9C-8BB7-088B02529D9D}.Prerelease|Any CPU.Build.0 = Prerelease|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Debug|x64.ActiveCfg = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Debug|x64.Build.0 = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Debug|x86.ActiveCfg = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Debug|x86.Build.0 = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Prerelease|Mixed Platforms.ActiveCfg = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Prerelease|Mixed Platforms.Build.0 = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Prerelease|x64.ActiveCfg = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Prerelease|x64.Build.0 = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Prerelease|x86.ActiveCfg = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Prerelease|x86.Build.0 = Debug|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Release|Any CPU.Build.0 = Release|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Release|x64.ActiveCfg = Release|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Release|x64.Build.0 = Release|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Release|x86.ActiveCfg = Release|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Release|x86.Build.0 = Release|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Prerelease|Any CPU.ActiveCfg = Prerelease|Any CPU
{9512295B-3045-40E0-9B7E-2409F2173E9D}.Prerelease|Any CPU.Build.0 = Prerelease|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -374,6 +432,8 @@ Global
{F5815359-CFC7-44B4-9A3B-C04BACAD5836} = {26E8B310-269E-46D4-A612-24601F16065F}
{00A1FED2-2254-4AF7-A5DB-2357FA7C88CD} = {26E8B310-269E-46D4-A612-24601F16065F}
{581FA7AF-FEF6-483C-A7D0-2D13EF50801B} = {3065279E-17F0-4CE0-AF5B-014E04263D77}
{A9348433-58C1-4B9C-8BB7-088B02529D9D} = {A2AE33B4-0830-426A-9E11-951DAB12BE5B}
{9512295B-3045-40E0-9B7E-2409F2173E9D} = {A2AE33B4-0830-426A-9E11-951DAB12BE5B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {84F8F8E0-1F73-41E0-BD8D-BB6676E2EE87}

View File

@ -1,8 +1,4 @@
using SharedLibraryCore;
using SharedLibraryCore.Exceptions;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.RCon;
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
@ -14,30 +10,36 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Serilog.Context;
using SharedLibraryCore;
using SharedLibraryCore.Exceptions;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.RCon;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace IW4MAdmin.Application.RCon
namespace Integrations.Cod
{
/// <summary>
/// implementation of IRConConnection
/// </summary>
public class RConConnection : IRConConnection
public class CodRConConnection : IRConConnection
{
static readonly ConcurrentDictionary<EndPoint, ConnectionState> ActiveQueries = new ConcurrentDictionary<EndPoint, ConnectionState>();
public IPEndPoint Endpoint { get; private set; }
public string RConPassword { get; private set; }
public IPEndPoint Endpoint { get; }
public string RConPassword { get; }
private IRConParser parser;
private IRConParserConfiguration config;
private readonly ILogger _log;
private readonly Encoding _gameEncoding;
private readonly int _retryAttempts;
public RConConnection(string ipAddress, int port, string password, ILogger<RConConnection> log, Encoding gameEncoding)
public CodRConConnection(IPEndPoint ipEndpoint, string password, ILogger<CodRConConnection> log, Encoding gameEncoding, int retryAttempts)
{
Endpoint = new IPEndPoint(IPAddress.Parse(ipAddress), port);
_gameEncoding = gameEncoding;
RConPassword = password;
_gameEncoding = gameEncoding;
_log = log;
Endpoint = ipEndpoint;
_retryAttempts = retryAttempts;
}
public void SetConfiguration(IRConParser parser)
@ -137,7 +139,7 @@ namespace IW4MAdmin.Application.RCon
_log.LogInformation(
"Retrying RCon message ({connectionAttempts}/{allowedConnectionFailures} attempts) with parameters {payload}",
connectionState.ConnectionAttempts,
StaticHelpers.AllowedConnectionFails, parameters);
_retryAttempts, parameters);
}
}
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
@ -155,7 +157,7 @@ namespace IW4MAdmin.Application.RCon
bool exceptionCaught = false;
_log.LogDebug("Sending {payloadLength} bytes to [{endpoint}] ({connectionAttempts}/{allowedConnectionFailures})",
payload.Length, Endpoint, connectionState.ConnectionAttempts, StaticHelpers.AllowedConnectionFails);
payload.Length, Endpoint, connectionState.ConnectionAttempts, _retryAttempts);
try
{
@ -173,7 +175,7 @@ namespace IW4MAdmin.Application.RCon
catch
{
// we want to retry with a delay
if (connectionState.ConnectionAttempts < StaticHelpers.AllowedConnectionFails)
if (connectionState.ConnectionAttempts < _retryAttempts)
{
exceptionCaught = true;
await Task.Delay(StaticHelpers.SocketTimeout(connectionState.ConnectionAttempts));
@ -468,4 +470,4 @@ namespace IW4MAdmin.Application.RCon
ActiveQueries[this.Endpoint].OnSentData.Set();
}
}
}
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Net.Sockets;
using System.Threading;
namespace IW4MAdmin.Application.RCon
namespace Integrations.Cod
{
/// <summary>
/// used to keep track of the udp connection state
@ -28,4 +28,4 @@ namespace IW4MAdmin.Application.RCon
public SocketAsyncEventArgs ReceiveEventArgs { get; set; } = new SocketAsyncEventArgs();
public DateTime LastQuery { get; set; } = DateTime.Now;
}
}
}

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Integrations.Cod</AssemblyName>
<RootNamespace>Integrations.Cod</RootNamespace>
<Configurations>Debug;Release;Prerelease</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Prerelease' ">
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\SharedLibraryCore\SharedLibraryCore.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,15 @@
using Integrations.Source.Interfaces;
using Microsoft.Extensions.DependencyInjection;
namespace Integrations.Source.Extensions
{
public static class IntegrationServicesExtensions
{
public static IServiceCollection AddSource(this IServiceCollection services)
{
services.AddSingleton<IRConClientFactory, RConClientFactory>();
return services;
}
}
}

View File

@ -0,0 +1,48 @@
using System.Text;
namespace Integrations.Source.Extensions
{
public static class SourceExtensions
{
public static string ReplaceUnfriendlyCharacters(this string source)
{
var result = new StringBuilder();
var quoteStart = false;
var quoteIndex = 0;
var index = 0;
foreach (var character in source)
{
if (character == '%')
{
result.Append('‰');
}
else if ((character == '"' || character == '\'') && index + 1 != source.Length)
{
if (quoteIndex > 0)
{
result.Append(!quoteStart ? "«" : "»");
quoteStart = !quoteStart;
}
else
{
result.Append('"');
}
quoteIndex++;
}
else
{
result.Append(character);
}
index++;
}
return result.ToString();
}
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Integrations.Source</AssemblyName>
<RootNamespace>Integrations.Source</RootNamespace>
<Configurations>Debug;Release;Prerelease</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Prerelease' ">
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RconSharp" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SharedLibraryCore\SharedLibraryCore.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
using System.Net;
using RconSharp;
namespace Integrations.Source.Interfaces
{
public interface IRConClientFactory
{
RconClient CreateClient(IPEndPoint ipEndPoint);
}
}

View File

@ -0,0 +1,14 @@
using System.Net;
using Integrations.Source.Interfaces;
using RconSharp;
namespace Integrations.Source
{
public class RConClientFactory : IRConClientFactory
{
public RconClient CreateClient(IPEndPoint ipEndPoint)
{
return RconClient.Create(ipEndPoint.Address.ToString(), ipEndPoint.Port);
}
}
}

View File

@ -0,0 +1,186 @@
using System;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Integrations.Source.Extensions;
using Integrations.Source.Interfaces;
using Microsoft.Extensions.Logging;
using RconSharp;
using Serilog.Context;
using SharedLibraryCore;
using SharedLibraryCore.Exceptions;
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.RCon;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace Integrations.Source
{
public class SourceRConConnection : IRConConnection
{
private readonly ILogger _logger;
private readonly string _password;
private readonly IPEndPoint _ipEndPoint;
private readonly IRConClientFactory _rconClientFactory;
private readonly SemaphoreSlim _activeQuery;
private static readonly TimeSpan FloodDelay = TimeSpan.FromMilliseconds(250);
private static readonly TimeSpan ConnectionTimeout = TimeSpan.FromSeconds(30);
private DateTime _lastQuery = DateTime.Now;
private RconClient _rconClient;
private bool _authenticated;
private bool _needNewSocket = true;
public SourceRConConnection(ILogger<SourceRConConnection> logger, IRConClientFactory rconClientFactory,
IPEndPoint ipEndPoint, string password)
{
_rconClientFactory = rconClientFactory;
_password = password;
_logger = logger;
_ipEndPoint = ipEndPoint;
_activeQuery = new SemaphoreSlim(1, 1);
}
~SourceRConConnection()
{
_activeQuery.Dispose();
}
public async Task<string[]> SendQueryAsync(StaticHelpers.QueryType type, string parameters = "")
{
try
{
await _activeQuery.WaitAsync();
await WaitForAvailable();
if (_needNewSocket)
{
try
{
_rconClient?.Disconnect();
}
catch
{
// ignored
}
_rconClient = _rconClientFactory.CreateClient(_ipEndPoint);
_authenticated = false;
_needNewSocket = false;
}
using (LogContext.PushProperty("Server", _ipEndPoint.ToString()))
{
_logger.LogDebug("Connecting to RCon socket");
}
await TryConnectAndAuthenticate().WithTimeout(ConnectionTimeout);
var multiPacket = false;
if (type == StaticHelpers.QueryType.COMMAND_STATUS)
{
parameters = "status";
multiPacket = true;
}
parameters = parameters.ReplaceUnfriendlyCharacters();
parameters = parameters.StripColors();
using (LogContext.PushProperty("Server", _ipEndPoint.ToString()))
{
_logger.LogDebug("Sending query {Type} with parameters \"{Parameters}\"", type, parameters);
}
var response = await _rconClient.ExecuteCommandAsync(parameters, multiPacket)
.WithTimeout(ConnectionTimeout);
using (LogContext.PushProperty("Server", $"{_ipEndPoint}"))
{
_logger.LogDebug("Received RCon response {Response}", response);
}
var split = response.TrimEnd('\n').Split('\n');
return split.Take(split.Length - 1).ToArray();
}
catch (TaskCanceledException)
{
_needNewSocket = true;
throw new NetworkException("Timeout while attempting to communicate with server");
}
catch (SocketException ex)
{
using (LogContext.PushProperty("Server", _ipEndPoint.ToString()))
{
_logger.LogError(ex, "Socket exception encountered while attempting to communicate with server");
}
_needNewSocket = true;
throw new NetworkException("Socket exception encountered while attempting to communicate with server");
}
catch (Exception ex) when (ex.GetType() != typeof(NetworkException) &&
ex.GetType() != typeof(ServerException))
{
using (LogContext.PushProperty("Server", _ipEndPoint.ToString()))
{
_logger.LogError(ex, "Could not execute RCon query {Parameters}", parameters);
}
throw new NetworkException("Unable to communicate with server");
}
finally
{
if (_activeQuery.CurrentCount == 0)
{
_activeQuery.Release();
}
_lastQuery = DateTime.Now;
}
}
private async Task WaitForAvailable()
{
var diff = DateTime.Now - _lastQuery;
if (diff < FloodDelay)
{
await Task.Delay(FloodDelay - diff);
}
}
private async Task TryConnectAndAuthenticate()
{
if (!_authenticated)
{
using (LogContext.PushProperty("Server", _ipEndPoint.ToString()))
{
_logger.LogDebug("Authenticating to RCon socket");
}
await _rconClient.ConnectAsync().WithTimeout(ConnectionTimeout);
_authenticated = await _rconClient.AuthenticateAsync(_password).WithTimeout(ConnectionTimeout);
if (!_authenticated)
{
using (LogContext.PushProperty("Server", _ipEndPoint.ToString()))
{
_logger.LogError("Could not login to server");
}
throw new ServerException("Could not authenticate to server with provided password");
}
}
}
public void SetConfiguration(IRConParser config)
{
}
}
}

Some files were not shown because too many files have changed in this diff Show More