Compare commits

...

47 Commits

Author SHA1 Message Date
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
Edo
d164ef2eab Removed tempbanclient (#187)
Removed tempbanclient because Tekno has "weird" internal DB that manages temp bans it it would interfere with iw4m
2021-03-23 10:36:33 -05:00
e2ed57f674 prevent autoflag from running player has been manually unflagged 2021-03-23 10:34:44 -05:00
824b1c0990 prevent loading of privileged clients page for issue #188 2021-03-23 10:28:17 -05:00
a8b331a5e5 prevent missing config from causing stats error
small advanced stats fixes
2021-03-23 10:16:27 -05:00
802ec8cea5 Added iw6 aliases (#184) 2021-03-23 08:14:07 -05:00
2313c4357b add removal of obsolete plugins 2021-03-22 11:46:32 -05:00
c5375b661b huge commit for advanced stats feature.
broke data out into its own library.
may be breaking changes with existing plugins
2021-03-22 11:09:25 -05:00
db2e1deb2f modify rule shortcut to just have 1 list 2021-02-27 09:40:25 -06:00
191a68e7dd revert unintended commit file 2021-01-24 13:30:22 -06:00
c4f19e94ef implement custom tag (descriptor) feature
allow override of level names through configuration
few small fixes/improvements
2021-01-24 11:47:19 -06:00
c419d80b57 preemptive checks 2021-01-17 22:12:18 -06:00
23a33ba489 implement more robust command api and login
improve web console command response reliability and consistency
2021-01-17 21:58:18 -06:00
dd3ebf6b34 increase buffer size for rcon connection 2021-01-17 20:04:32 -06:00
28373b9325 implement admin "privacy" for issue #185 2021-01-09 12:37:20 -06:00
843c01061d update 'uptime' output
use translations for certain webfront page meta that was neglected
update plutonium parsers to not use new line in notices as it is not supported
2021-01-08 19:21:23 -06:00
5cb2d05f33 add preset rules, configurable time spans, and separate rule shortcut for issue #180 2020-12-31 18:48:58 -06:00
5a288dafc1 update shared library core version and plugins 2020-12-20 19:23:14 -06:00
4afc478076 fix issue with view stats and reset stats failing
fix issue with set level returning wrong error message if setting a client to the same level they're currently at
update CoD4x parser version
update nuget packages
2020-12-16 13:11:30 -06:00
928cbef845 resolve bot guid issue with T5
remove unneeded check for CNCT state
2020-12-14 21:10:50 -06:00
02b910234a add official T4/WaW support for issue #178
CoD4x parser tweak to parse full guid as decimal
2020-12-13 20:33:37 -06:00
f03626c3ae Another tweak for CoD4x rcon parsing. 2020-12-12 21:43:27 -06:00
554 changed files with 20689 additions and 3078 deletions

View File

@ -25,13 +25,13 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Jint" Version="3.0.0-beta-1632" /> <PackageReference Include="Jint" Version="3.0.0-beta-1632" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.7"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.10">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.7" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.10" />
<PackageReference Include="RestEase" Version="1.5.0" /> <PackageReference Include="RestEase" Version="1.5.1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.1" /> <PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>
@ -39,7 +39,6 @@
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection> <ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
<TieredCompilation>true</TieredCompilation> <TieredCompilation>true</TieredCompilation>
<LangVersion>Latest</LangVersion> <LangVersion>Latest</LangVersion>
<StartupObject></StartupObject>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Prerelease|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Prerelease|AnyCPU'">
@ -49,6 +48,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Integrations\Cod\Integrations.Cod.csproj" />
<ProjectReference Include="..\Integrations\Source\Integrations.Source.csproj" />
<ProjectReference Include="..\SharedLibraryCore\SharedLibraryCore.csproj"> <ProjectReference Include="..\SharedLibraryCore\SharedLibraryCore.csproj">
<Private>true</Private> <Private>true</Private>
</ProjectReference> </ProjectReference>
@ -60,7 +61,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<None Update="Configuration\LoggingConfiguration.json"> <None Update="Configuration\LoggingConfiguration.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>

View File

@ -1,12 +1,11 @@
using IW4MAdmin.Application.EventParsers; using IW4MAdmin.Application.EventParsers;
using IW4MAdmin.Application.Extensions; using IW4MAdmin.Application.Extensions;
using IW4MAdmin.Application.Misc; using IW4MAdmin.Application.Misc;
using IW4MAdmin.Application.RconParsers; using IW4MAdmin.Application.RConParsers;
using SharedLibraryCore; using SharedLibraryCore;
using SharedLibraryCore.Commands; using SharedLibraryCore.Commands;
using SharedLibraryCore.Configuration; using SharedLibraryCore.Configuration;
using SharedLibraryCore.Configuration.Validation; using SharedLibraryCore.Configuration.Validation;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.Models; using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Exceptions; using SharedLibraryCore.Exceptions;
using SharedLibraryCore.Helpers; using SharedLibraryCore.Helpers;
@ -21,6 +20,8 @@ using System.Reflection;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.Abstractions;
using Data.Context;
using IW4MAdmin.Application.Migration; using IW4MAdmin.Application.Migration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -72,6 +73,7 @@ namespace IW4MAdmin.Application
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
private readonly ChangeHistoryService _changeHistoryService; private readonly ChangeHistoryService _changeHistoryService;
private readonly ApplicationConfiguration _appConfig; private readonly ApplicationConfiguration _appConfig;
public ConcurrentDictionary<long, GameEvent> ProcessingEvents { get; } = new ConcurrentDictionary<long, GameEvent>();
public ApplicationManager(ILogger<ApplicationManager> logger, IMiddlewareActionHandler actionHandler, IEnumerable<IManagerCommand> commands, public ApplicationManager(ILogger<ApplicationManager> logger, IMiddlewareActionHandler actionHandler, IEnumerable<IManagerCommand> commands,
ITranslationLookup translationLookup, IConfigurationHandler<CommandConfiguration> commandConfiguration, ITranslationLookup translationLookup, IConfigurationHandler<CommandConfiguration> commandConfiguration,
@ -115,6 +117,8 @@ namespace IW4MAdmin.Application
public async Task ExecuteEvent(GameEvent newEvent) public async Task ExecuteEvent(GameEvent newEvent)
{ {
ProcessingEvents.TryAdd(newEvent.Id, newEvent);
// the event has failed already // the event has failed already
if (newEvent.Failed) if (newEvent.Failed)
{ {
@ -175,6 +179,29 @@ namespace IW4MAdmin.Application
} }
skip: skip:
if (newEvent.Type == EventType.Command && newEvent.ImpersonationOrigin == null)
{
var correlatedEvents =
ProcessingEvents.Values.Where(ev =>
ev.CorrelationId == newEvent.CorrelationId && ev.Id != newEvent.Id)
.ToList();
await Task.WhenAll(correlatedEvents.Select(ev =>
ev.WaitAsync(Utilities.DefaultCommandTimeout, CancellationToken)));
newEvent.Output.AddRange(correlatedEvents.SelectMany(ev => ev.Output));
foreach (var correlatedEvent in correlatedEvents)
{
ProcessingEvents.Remove(correlatedEvent.Id, out _);
}
}
// we don't want to remove events that are correlated to command
if (ProcessingEvents.Values.ToList()?.Count(gameEvent => gameEvent.CorrelationId == newEvent.CorrelationId) == 1)
{
ProcessingEvents.Remove(newEvent.Id, out _);
}
// tell anyone waiting for the output that we're done // tell anyone waiting for the output that we're done
newEvent.Complete(); newEvent.Complete();
OnGameEventExecuted?.Invoke(this, newEvent); OnGameEventExecuted?.Invoke(this, newEvent);
@ -193,15 +220,15 @@ namespace IW4MAdmin.Application
public async Task UpdateServerStates() public async Task UpdateServerStates()
{ {
// store the server hash code and task for it // 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) while (!_tokenSource.IsCancellationRequested)
{ {
// select the server ids that have completed the update task // select the server ids that have completed the update task
var serverTasksToRemove = runningUpdateTasks var serverTasksToRemove = runningUpdateTasks
.Where(ut => ut.Value.Status == TaskStatus.RanToCompletion || .Where(ut => ut.Value.task.Status == TaskStatus.RanToCompletion ||
ut.Value.Status == TaskStatus.Canceled || ut.Value.task.Status == TaskStatus.Canceled || // we want to cancel if a task takes longer than 5 minutes
ut.Value.Status == TaskStatus.Faulted) ut.Value.task.Status == TaskStatus.Faulted || DateTime.Now - ut.Value.startTime > TimeSpan.FromMinutes(5))
.Select(ut => ut.Key) .Select(ut => ut.Key)
.ToList(); .ToList();
@ -212,9 +239,14 @@ namespace IW4MAdmin.Application
IsInitialized = true; IsInitialized = true;
} }
// remove the update tasks as they have completd // remove the update tasks as they have completed
foreach (long serverId in serverTasksToRemove) foreach (var serverId in serverTasksToRemove)
{ {
if (!runningUpdateTasks[serverId].tokenSource.Token.IsCancellationRequested)
{
runningUpdateTasks[serverId].tokenSource.Cancel();
}
runningUpdateTasks.Remove(serverId); runningUpdateTasks.Remove(serverId);
} }
@ -222,11 +254,12 @@ namespace IW4MAdmin.Application
var serverIds = Servers.Select(s => s.EndPoint).Except(runningUpdateTasks.Select(r => r.Key)).ToList(); 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))) 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 try
{ {
await server.ProcessUpdatesAsync(_tokenSource.Token); await server.ProcessUpdatesAsync(_tokenSource.Token).WithWaitCancellation(runningUpdateTasks[server.EndPoint].tokenSource.Token);
} }
catch (Exception e) catch (Exception e)
@ -241,7 +274,7 @@ namespace IW4MAdmin.Application
{ {
server.IsInitialized = true; server.IsInitialized = true;
} }
})); }, tokenSource.Token), tokenSource, DateTime.Now));
} }
try try
@ -265,6 +298,15 @@ namespace IW4MAdmin.Application
IsRunning = true; IsRunning = true;
ExternalIPAddress = await Utilities.GetExternalIP(); ExternalIPAddress = await Utilities.GetExternalIP();
#region DATABASE
_logger.LogInformation("Beginning database migration sync");
Console.WriteLine(_translationLookup["MANAGER_MIGRATION_START"]);
await ContextSeed.Seed(_serviceProvider.GetRequiredService<IDatabaseContextFactory>(), _tokenSource.Token);
await DatabaseHousekeeping.RemoveOldRatings(_serviceProvider.GetRequiredService<IDatabaseContextFactory>(), _tokenSource.Token);
_logger.LogInformation("Finished database migration sync");
Console.WriteLine(_translationLookup["MANAGER_MIGRATION_END"]);
#endregion
#region PLUGINS #region PLUGINS
foreach (var plugin in Plugins) foreach (var plugin in Plugins)
{ {
@ -305,7 +347,7 @@ namespace IW4MAdmin.Application
// copy over default config if it doesn't exist // copy over default config if it doesn't exist
if (!_appConfig.Servers?.Any() ?? true) if (!_appConfig.Servers?.Any() ?? true)
{ {
var defaultConfig = new BaseConfigurationHandler<DefaultConfiguration>("DefaultSettings").Configuration(); var defaultConfig = new BaseConfigurationHandler<DefaultSettings>("DefaultSettings").Configuration();
//ConfigHandler.Set((ApplicationConfiguration)new ApplicationConfiguration().Generate()); //ConfigHandler.Set((ApplicationConfiguration)new ApplicationConfiguration().Generate());
//var newConfig = ConfigHandler.Configuration(); //var newConfig = ConfigHandler.Configuration();
@ -398,15 +440,6 @@ namespace IW4MAdmin.Application
#endregion #endregion
#region DATABASE
_logger.LogInformation("Beginning database migration sync");
Console.WriteLine(_translationLookup["MANAGER_MIGRATION_START"]);
await ContextSeed.Seed(_serviceProvider.GetRequiredService<IDatabaseContextFactory>(), _tokenSource.Token);
await DatabaseHousekeeping.RemoveOldRatings(_serviceProvider.GetRequiredService<IDatabaseContextFactory>(), _tokenSource.Token);
_logger.LogInformation("Finished database migration sync");
Console.WriteLine(_translationLookup["MANAGER_MIGRATION_END"]);
#endregion
#region COMMANDS #region COMMANDS
if (await ClientSvc.HasOwnerAsync(_tokenSource.Token)) if (await ClientSvc.HasOwnerAsync(_tokenSource.Token))
{ {
@ -491,7 +524,7 @@ namespace IW4MAdmin.Application
// add the start event for this server // add the start event for this server
var e = new GameEvent() var e = new GameEvent()
{ {
Type = GameEvent.EventType.Start, Type = EventType.Start,
Data = $"{ServerInstance.GameName} started", Data = $"{ServerInstance.GameName} started",
Owner = ServerInstance Owner = ServerInstance
}; };

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, "AutoMessagePeriod": 60,
"AutoMessages": [ "AutoMessages": [
"This server uses ^5IW4M Admin v{{VERSION}} ^7get it at ^5raidmax.org/IW4MAdmin", "This server uses ^5IW4M Admin v{{VERSION}} ^7get it at ^5raidmax.org/IW4MAdmin",
@ -16,7 +16,13 @@
"Keep grenade launcher use to a minimum", "Keep grenade launcher use to a minimum",
"Balance teams at ALL times" "Balance teams at ALL times"
], ],
"DisallowedClientNames": [ "Unknown Soldier", "VickNet", "UnknownSoldier", "CHEATER", "Play77" ], "DisallowedClientNames": [
"Unknown Soldier",
"VickNet",
"UnknownSoldier",
"CHEATER",
"Play77"
],
"QuickMessages": [ "QuickMessages": [
{ {
"Game": "IW4", "Game": "IW4",
@ -163,6 +169,18 @@
"Alias": "Asylum", "Alias": "Asylum",
"Name": "mp_asylum" "Name": "mp_asylum"
}, },
{
"Alias": "Banzai",
"Name": "mp_kwai"
},
{
"Alias": "Battery",
"Name": "mp_drum"
},
{
"Alias": "Breach",
"Name": "mp_bgate"
},
{ {
"Alias": "Castle", "Alias": "Castle",
"Name": "mp_castle" "Name": "mp_castle"
@ -171,6 +189,10 @@
"Alias": "Cliffside", "Alias": "Cliffside",
"Name": "mp_shrine" "Name": "mp_shrine"
}, },
{
"Alias": "Corrosion",
"Name": "mp_stalingrad"
},
{ {
"Alias": "Courtyard", "Alias": "Courtyard",
"Name": "mp_courtyard" "Name": "mp_courtyard"
@ -184,60 +206,52 @@
"Name": "mp_downfall" "Name": "mp_downfall"
}, },
{ {
"Alias": "Hanger", "Alias": "Hangar",
"Name": "mp_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", "Alias": "Knee Deep",
"Name": "mp_kneedeep" "Name": "mp_kneedeep"
}, },
{
"Alias": "Makin",
"Name": "mp_makin"
},
{
"Alias": "Makin Day",
"Name": "mp_makin_day"
},
{ {
"Alias": "Nightfire", "Alias": "Nightfire",
"Name": "mp_nachtfeuer" "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", "Alias": "Station",
"Name": "mp_subway" "Name": "mp_subway"
}, },
{
"Alias": "Banzai",
"Name": "mp_kwai"
},
{
"Alias": "Corrosion",
"Name": "mp_stalingrad"
},
{ {
"Alias": "Sub Pens", "Alias": "Sub Pens",
"Name": "mp_docks" "Name": "mp_docks"
}, },
{ {
"Alias": "Battery", "Alias": "Upheaval",
"Name": "mp_drum" "Name": "mp_suburban"
},
{
"Alias": "Breach",
"Name": "mp_bgate"
},
{
"Alias": "Revolution",
"Name": "mp_vodka"
} }
] ]
}, },
@ -248,222 +262,178 @@
"Alias": "Rust", "Alias": "Rust",
"Name": "mp_rust" "Name": "mp_rust"
}, },
{ {
"Alias": "Terminal", "Alias": "Terminal",
"Name": "mp_terminal" "Name": "mp_terminal"
}, },
{ {
"Alias": "Crash", "Alias": "Crash",
"Name": "mp_crash" "Name": "mp_crash"
}, },
{ {
"Alias": "Afghan", "Alias": "Afghan",
"Name": "mp_afghan" "Name": "mp_afghan"
}, },
{ {
"Alias": "Derail", "Alias": "Derail",
"Name": "mp_derail" "Name": "mp_derail"
}, },
{ {
"Alias": "Estate", "Alias": "Estate",
"Name": "mp_estate" "Name": "mp_estate"
}, },
{ {
"Alias": "Favela", "Alias": "Favela",
"Name": "mp_favela" "Name": "mp_favela"
}, },
{ {
"Alias": "Highrise", "Alias": "Highrise",
"Name": "mp_highrise" "Name": "mp_highrise"
}, },
{ {
"Alias": "Invasion", "Alias": "Invasion",
"Name": "mp_invasion" "Name": "mp_invasion"
}, },
{ {
"Alias": "Karachi", "Alias": "Karachi",
"Name": "mp_checkpoint" "Name": "mp_checkpoint"
}, },
{ {
"Alias": "Quarry", "Alias": "Quarry",
"Name": "mp_quarry" "Name": "mp_quarry"
}, },
{ {
"Alias": "Rundown", "Alias": "Rundown",
"Name": "mp_rundown" "Name": "mp_rundown"
}, },
{ {
"Alias": "Scrapyard", "Alias": "Scrapyard",
"Name": "mp_boneyard" "Name": "mp_boneyard"
}, },
{ {
"Alias": "Skidrow", "Alias": "Skidrow",
"Name": "mp_nightshift" "Name": "mp_nightshift"
}, },
{ {
"Alias": "Sub Base", "Alias": "Sub Base",
"Name": "mp_subbase" "Name": "mp_subbase"
}, },
{ {
"Alias": "Underpass", "Alias": "Underpass",
"Name": "mp_underpass" "Name": "mp_underpass"
}, },
{ {
"Alias": "Wasteland", "Alias": "Wasteland",
"Name": "mp_brecourt" "Name": "mp_brecourt"
}, },
{ {
"Alias": "Overgrown", "Alias": "Overgrown",
"Name": "mp_overgrown" "Name": "mp_overgrown"
}, },
{ {
"Alias": "Strike", "Alias": "Strike",
"Name": "mp_strike" "Name": "mp_strike"
}, },
{ {
"Alias": "Vacant", "Alias": "Vacant",
"Name": "mp_vacant" "Name": "mp_vacant"
}, },
{ {
"Alias": "Carnival", "Alias": "Carnival",
"Name": "mp_abandon" "Name": "mp_abandon"
}, },
{ {
"Alias": "Trailer Park", "Alias": "Trailer Park",
"Name": "mp_trailerpark" "Name": "mp_trailerpark"
}, },
{ {
"Alias": "Fuel", "Alias": "Fuel",
"Name": "mp_fuel2" "Name": "mp_fuel2"
}, },
{ {
"Alias": "Storm", "Alias": "Storm",
"Name": "mp_storm" "Name": "mp_storm"
}, },
{ {
"Alias": "Bailout", "Alias": "Bailout",
"Name": "mp_complex" "Name": "mp_complex"
}, },
{ {
"Alias": "Salvage", "Alias": "Salvage",
"Name": "mp_compact" "Name": "mp_compact"
}, },
{ {
"Alias": "Nuketown", "Alias": "Nuketown",
"Name": "mp_nuked" "Name": "mp_nuked"
}, },
{ {
"Alias": "Test map", "Alias": "Test map",
"Name": "iw4_credits" "Name": "iw4_credits"
}, },
{ {
"Alias": "Killhouse", "Alias": "Killhouse",
"Name": "mp_killhouse" "Name": "mp_killhouse"
}, },
{ {
"Alias": "Bog", "Alias": "Bog",
"Name": "mp_bog_sh" "Name": "mp_bog_sh"
}, },
{ {
"Alias": "Freighter", "Alias": "Freighter",
"Name": "mp_cargoship_sh" "Name": "mp_cargoship_sh"
}, },
{ {
"Alias": "Cargoship", "Alias": "Cargoship",
"Name": "mp_cargoship" "Name": "mp_cargoship"
}, },
{ {
"Alias": "Shipment", "Alias": "Shipment",
"Name": "mp_shipment" "Name": "mp_shipment"
}, },
{ {
"Alias": "Shipment - Long", "Alias": "Shipment - Long",
"Name": "mp_shipment_long" "Name": "mp_shipment_long"
}, },
{ {
"Alias": "Rust - Long", "Alias": "Rust - Long",
"Name": "mp_rust_long" "Name": "mp_rust_long"
}, },
{ {
"Alias": "Firing Range", "Alias": "Firing Range",
"Name": "mp_firingrange" "Name": "mp_firingrange"
}, },
{ {
"Alias": "Chemical Plant", "Alias": "Chemical Plant",
"Name": "mp_storm_spring" "Name": "mp_storm_spring"
}, },
{ {
"Alias": "Tropical Favela", "Alias": "Tropical Favela",
"Name": "mp_fav_tropical" "Name": "mp_fav_tropical"
}, },
{ {
"Alias": "Tropical Estate", "Alias": "Tropical Estate",
"Name": "mp_estate_tropical" "Name": "mp_estate_tropical"
}, },
{ {
"Alias": "Tropical Crash", "Alias": "Tropical Crash",
"Name": "mp_crash_tropical" "Name": "mp_crash_tropical"
}, },
{ {
"Alias": "Forgotten City", "Alias": "Forgotten City",
"Name": "mp_bloc_sh" "Name": "mp_bloc_sh"
}, },
{ {
"Alias": "Crossfire", "Alias": "Crossfire",
"Name": "mp_cross_fire" "Name": "mp_cross_fire"
}, },
{ {
"Alias": "Bloc", "Alias": "Bloc",
"Name": "mp_bloc" "Name": "mp_bloc"
}, },
{ {
"Alias": "Oilrig", "Alias": "Oilrig",
"Name": "oilrig" "Name": "oilrig"
}, },
{ {
"Name": "Village", "Name": "Village",
"Alias": "co_hunted" "Alias": "co_hunted"
@ -519,7 +489,7 @@
}, },
{ {
"Alias": "Havana", "Alias": "Havana",
"Name": "mp_cairo" "Name": "mp_cairo"
}, },
{ {
"Alias": "Hazard", "Alias": "Hazard",
@ -725,6 +695,10 @@
{ {
"Alias": "Terminal", "Alias": "Terminal",
"Name": "mp_terminal_cls" "Name": "mp_terminal_cls"
},
{
"Alias": "Rust",
"Name": "mp_rust"
} }
] ]
}, },
@ -884,6 +858,451 @@
"Name": "zm_transit" "Name": "zm_transit"
} }
] ]
},
{
"Game": "IW6",
"Maps": [
{
"Alias": "Prision 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"
}
]
} }
] ],
"GameStrings": {
"IW4": {
"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",
"eotech": "Holographic Sight",
"fmj": "FMJ",
"gl": "Grenade Launcher",
"heartbeat": "Heartbeat Sensor",
"reflex": "Red Dot Sight",
"rof": "Rapid Fire",
"thermal": "Thermal",
"xmags": "Extended Mags",
"m4": "M4A1",
"m40a3": "M40A3",
"ak47": "AK-47",
"ak47classic": "AK-47 Classic",
"fn2000": "F2000",
"masada": "ACR",
"famas": "FAMAS",
"fal": "FAL",
"scar": "SCAR-H",
"tavor": "TAR-21",
"m16": "M16A4",
"mp5k": "MP5K",
"ump45": "UMP45",
"kriss": "Vector",
"uzi": "Mini-Uzi",
"rpd": "RPD",
"sa80": "L86 LSW",
"mg4": "MG4",
"aug": "AUG HBAR",
"cheytac": "Intervention",
"barrett": "Barrett .50cal",
"wa2000": "WA2000",
"m21": "M21 EBR",
"pp2000": "PP2000",
"glock": "G18",
"beretta": "M93 Raffica",
"tmp": "TMP",
"spas12": "SPAS-12",
"aa12": "AA-12",
"model1887": "Model 1887",
"usp": "USP .45",
"coltanaconda": ".44 Magnum",
"deserteagle": "Desert Eagle",
"deserteaglegold": "Desert Eagle Gold",
"at4": "AT4-HS",
"m79": "Thumper",
"rpg": "RPG-7",
"concussion": "Stun",
"throwingknife": "Throwing Knife",
"ffar": "Airstrike",
"pavelow": "Pave Low",
"cobra": "Attack Helicopter",
"ac130": "AC-130",
"remotemissile": "Predator Missile",
"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

@ -5,6 +5,7 @@ using SharedLibraryCore.Interfaces;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Data.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Server; using static SharedLibraryCore.Server;
using ILogger = Microsoft.Extensions.Logging.ILogger; using ILogger = Microsoft.Extensions.Logging.ILogger;
@ -16,6 +17,8 @@ namespace IW4MAdmin.Application.EventParsers
private readonly Dictionary<string, (string, Func<string, IEventParserConfiguration, GameEvent, GameEvent>)> _customEventRegistrations; private readonly Dictionary<string, (string, Func<string, IEventParserConfiguration, GameEvent, GameEvent>)> _customEventRegistrations;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ApplicationConfiguration _appConfig; 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) public BaseEventParser(IParserRegexFactory parserRegexFactory, ILogger logger, ApplicationConfiguration appConfig)
{ {
@ -77,7 +80,28 @@ namespace IW4MAdmin.Application.EventParsers
Configuration.Kill.AddMapping(ParserRegex.GroupType.MeansOfDeath, 12); Configuration.Kill.AddMapping(ParserRegex.GroupType.MeansOfDeath, 12);
Configuration.Kill.AddMapping(ParserRegex.GroupType.HitLocation, 13); 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]+ )"; 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; } public IEventParserConfiguration Configuration { get; set; }
@ -90,47 +114,79 @@ namespace IW4MAdmin.Application.EventParsers
public string Name { get; set; } = "Call of Duty"; 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, null);
}
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) public virtual GameEvent GenerateGameEvent(string logLine)
{ {
var timeMatch = Configuration.Time.PatternMatcher.Match(logLine); var timeMatch = Configuration.Time.PatternMatcher.Match(logLine);
int gameTime = 0; var gameTime = 0L;
if (timeMatch.Success) if (timeMatch.Success)
{ {
gameTime = timeMatch if (timeMatch.Values[0].Contains(":"))
.Values {
.Skip(2) gameTime = timeMatch
// this converts the timestamp into seconds passed .Values
.Select((_value, index) => int.Parse(_value.ToString()) * (index == 0 ? 60 : 1)) .Skip(2)
.Sum(); // this converts the timestamp into seconds passed
.Select((value, index) => long.Parse(value.ToString()) * (index == 0 ? 60 : 1))
.Sum();
}
else
{
gameTime = long.Parse(timeMatch.Values[0]);
}
// we want to strip the time from the log line // 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(';'); var eventParseResult = GetEventTypeFromLine(logLine);
string eventType = lineSplit[0]; var eventType = eventParseResult.type;
if (eventType == "say" || eventType == "sayteam") _logger.LogDebug(logLine);
if (eventType == GameEvent.EventType.Say)
{ {
var matchResult = Configuration.Say.PatternMatcher.Match(logLine); var matchResult = Configuration.Say.PatternMatcher.Match(logLine);
if (matchResult.Success) if (matchResult.Success)
{ {
string message = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.Message]] var message = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.Message]]
.ToString()
.Replace("\x15", "") .Replace("\x15", "")
.Trim(); .Trim();
if (message.Length > 0) if (message.Length > 0)
{ {
string originIdString = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString(); var originIdString = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
string originName = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginName]].ToString(); var originName = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginName]];
long originId = originIdString.IsBotGuid() ? var originId = originIdString.IsBotGuid() ?
originName.GenerateGuidFromString() : originName.GenerateGuidFromString() :
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle); 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)) if (message.StartsWith(_appConfig.CommandPrefix) || message.StartsWith(_appConfig.BroadcastCommandPrefix))
{ {
@ -162,26 +218,26 @@ namespace IW4MAdmin.Application.EventParsers
} }
} }
if (eventType == "K") if (eventType == GameEvent.EventType.Kill)
{ {
var match = Configuration.Kill.PatternMatcher.Match(logLine); var match = Configuration.Kill.PatternMatcher.Match(logLine);
if (match.Success) if (match.Success)
{ {
string originIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString(); var originIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
string targetIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString(); var targetIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]];
string originName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginName]].ToString(); var originName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginName]];
string targetName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetName]].ToString(); var targetName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetName]];
long originId = originIdString.IsBotGuid() ? var originId = originIdString.IsBotGuid() ?
originName.GenerateGuidFromString() : originName.GenerateGuidFromString() :
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID); originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
long targetId = targetIdString.IsBotGuid() ? var targetId = targetIdString.IsBotGuid() ?
targetName.GenerateGuidFromString() : targetName.GenerateGuidFromString() :
targetIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID); targetIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
int originClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]); var originClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
int targetClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]); var targetClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
return new GameEvent() return new GameEvent()
{ {
@ -196,26 +252,26 @@ namespace IW4MAdmin.Application.EventParsers
} }
} }
if (eventType == "D") if (eventType == GameEvent.EventType.Damage)
{ {
var match = Configuration.Damage.PatternMatcher.Match(logLine); var match = Configuration.Damage.PatternMatcher.Match(logLine);
if (match.Success) if (match.Success)
{ {
string originIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString(); var originIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
string targetIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString(); var targetIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]];
string originName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginName]].ToString(); var originName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginName]];
string targetName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetName]].ToString(); var targetName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetName]];
long originId = originIdString.IsBotGuid() ? var originId = originIdString.IsBotGuid() ?
originName.GenerateGuidFromString() : originName.GenerateGuidFromString() :
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID); originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
long targetId = targetIdString.IsBotGuid() ? var targetId = targetIdString.IsBotGuid() ?
targetName.GenerateGuidFromString() : targetName.GenerateGuidFromString() :
targetIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID); targetIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
int originClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]); var originClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
int targetClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]); var targetClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
return new GameEvent() return new GameEvent()
{ {
@ -230,16 +286,16 @@ namespace IW4MAdmin.Application.EventParsers
} }
} }
if (eventType == "J") if (eventType == GameEvent.EventType.PreConnect)
{ {
var match = Configuration.Join.PatternMatcher.Match(logLine); var match = Configuration.Join.PatternMatcher.Match(logLine);
if (match.Success) if (match.Success)
{ {
string originIdString = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString(); var originIdString = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
string originName = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].ToString(); var originName = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]];
long networkId = originIdString.IsBotGuid() ? var networkId = originIdString.IsBotGuid() ?
originName.GenerateGuidFromString() : originName.GenerateGuidFromString() :
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle); originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
@ -251,10 +307,10 @@ namespace IW4MAdmin.Application.EventParsers
{ {
CurrentAlias = new EFAlias() 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, 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, State = EFClient.ClientState.Connecting,
}, },
Extra = originIdString, Extra = originIdString,
@ -266,16 +322,16 @@ namespace IW4MAdmin.Application.EventParsers
} }
} }
if (eventType == "Q") if (eventType == GameEvent.EventType.PreDisconnect)
{ {
var match = Configuration.Quit.PatternMatcher.Match(logLine); var match = Configuration.Quit.PatternMatcher.Match(logLine);
if (match.Success) if (match.Success)
{ {
string originIdString = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString(); var originIdString = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
string originName = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].ToString(); var originName = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]];
long networkId = originIdString.IsBotGuid() ? var networkId = originIdString.IsBotGuid() ?
originName.GenerateGuidFromString() : originName.GenerateGuidFromString() :
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle); originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
@ -287,10 +343,10 @@ namespace IW4MAdmin.Application.EventParsers
{ {
CurrentAlias = new EFAlias() 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, 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 State = EFClient.ClientState.Disconnecting
}, },
RequiredEntity = GameEvent.EventRequiredEntity.None, RequiredEntity = GameEvent.EventRequiredEntity.None,
@ -301,7 +357,7 @@ namespace IW4MAdmin.Application.EventParsers
} }
} }
if (eventType.Contains("ExitLevel")) if (eventType == GameEvent.EventType.MapEnd)
{ {
return new GameEvent() return new GameEvent()
{ {
@ -315,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() return new GameEvent()
{ {
@ -332,26 +388,37 @@ namespace IW4MAdmin.Application.EventParsers
}; };
} }
if (_customEventRegistrations.ContainsKey(eventType)) if (eventParseResult.eventKey == null || !_customEventRegistrations.ContainsKey(eventParseResult.eventKey))
{ {
var eventModifier = _customEventRegistrations[eventType]; return new GameEvent()
try
{ {
return eventModifier.Item2(logLine, Configuration, new GameEvent() Type = GameEvent.EventType.Unknown,
{ Data = logLine,
Type = GameEvent.EventType.Other, Origin = Utilities.IW4MAdminClient(),
Data = logLine, Target = Utilities.IW4MAdminClient(),
Subtype = eventModifier.Item1, RequiredEntity = GameEvent.EventRequiredEntity.None,
GameTime = gameTime, GameTime = gameTime,
Source = GameEvent.EventSource.Log 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() return new GameEvent()

View File

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

View File

@ -1,6 +1,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Data.MigrationContext;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
@ -10,7 +11,6 @@ using Serilog;
using Serilog.Events; using Serilog.Events;
using SharedLibraryCore; using SharedLibraryCore;
using SharedLibraryCore.Configuration; using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.MigrationContext;
using ILogger = Serilog.ILogger; using ILogger = Serilog.ILogger;
namespace IW4MAdmin.Application.Extensions namespace IW4MAdmin.Application.Extensions
@ -32,13 +32,12 @@ namespace IW4MAdmin.Application.Extensions
.ReadFrom.Configuration(configuration) .ReadFrom.Configuration(configuration)
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning); .MinimumLevel.Override("Microsoft", LogEventLevel.Warning);
if (Utilities.IsDevelopment) if (Utilities.IsDevelopment)
{ {
loggerConfig = loggerConfig.WriteTo.Console( loggerConfig = loggerConfig.WriteTo.Console(
outputTemplate: outputTemplate:
"[{Timestamp:yyyy-MM-dd HH:mm:ss.fff} {Server} {Level:u3}] {Message:lj}{NewLine}{Exception}") "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff} {Server} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Debug(); .MinimumLevel.Debug();
} }
@ -67,10 +66,10 @@ namespace IW4MAdmin.Application.Extensions
{DataSource = Path.Join(currentPath, "Database", "Database.db")}; {DataSource = Path.Join(currentPath, "Database", "Database.db")};
var connectionString = connectionStringBuilder.ToString(); var connectionString = connectionStringBuilder.ToString();
var builder = new DbContextOptionsBuilder<SqliteDatabaseContext>() services.AddSingleton(sp => (DbContextOptions) new DbContextOptionsBuilder<SqliteDatabaseContext>()
.UseSqlite(connectionString); .UseSqlite(connectionString)
.UseLoggerFactory(sp.GetRequiredService<ILoggerFactory>())
services.AddSingleton((DbContextOptions) builder.Options); .EnableSensitiveDataLogging().Options);
return services; return services;
} }
@ -90,7 +89,11 @@ namespace IW4MAdmin.Application.Extensions
services.AddSingleton(sp => services.AddSingleton(sp =>
(DbContextOptions) new DbContextOptionsBuilder<PostgresqlDatabaseContext>() (DbContextOptions) new DbContextOptionsBuilder<PostgresqlDatabaseContext>()
.UseNpgsql(appConfig.ConnectionString + (appendTimeout ? ";Command Timeout=0" : ""), .UseNpgsql(appConfig.ConnectionString + (appendTimeout ? ";Command Timeout=0" : ""),
postgresqlOptions => postgresqlOptions.EnableRetryOnFailure()) postgresqlOptions =>
{
postgresqlOptions.EnableRetryOnFailure();
postgresqlOptions.SetPostgresVersion(new Version("9.4"));
})
.UseLoggerFactory(sp.GetRequiredService<ILoggerFactory>()).Options); .UseLoggerFactory(sp.GetRequiredService<ILoggerFactory>()).Options);
return services; return services;
default: default:

View File

@ -1,9 +1,9 @@
using System; using System;
using Data.Abstractions;
using Data.Context;
using Data.MigrationContext;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SharedLibraryCore.Configuration; using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database;
using SharedLibraryCore.Database.MigrationContext;
using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.Factories namespace IW4MAdmin.Application.Factories
{ {

View File

@ -1,4 +1,6 @@
using System; using System;
using Data.Abstractions;
using Data.Models.Server;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using SharedLibraryCore; using SharedLibraryCore;
using SharedLibraryCore.Configuration; using SharedLibraryCore.Configuration;
@ -37,7 +39,7 @@ namespace IW4MAdmin.Application.Factories
/// <returns></returns> /// <returns></returns>
public Server CreateServer(ServerConfiguration config, IManager manager) public Server CreateServer(ServerConfiguration config, IManager manager)
{ {
return new IW4MServer(config, _translationLookup, _metaService, _serviceProvider, _serviceProvider.GetRequiredService<IClientNoticeMessageFormatter>()); return new IW4MServer(config, _translationLookup, _metaService, _serviceProvider, _serviceProvider.GetRequiredService<IClientNoticeMessageFormatter>(), _serviceProvider.GetRequiredService<ILookupCache<EFServer>>());
} }
} }
} }

View File

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

View File

@ -6,9 +6,9 @@ using SharedLibraryCore.Interfaces;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Data.Models.Client;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Database.Models.EFClient;
namespace IW4MAdmin.Application.Factories namespace IW4MAdmin.Application.Factories
{ {
@ -32,7 +32,7 @@ namespace IW4MAdmin.Application.Factories
public IManagerCommand CreateScriptCommand(string name, string alias, string description, string permission, public IManagerCommand CreateScriptCommand(string name, string alias, string description, string permission,
bool isTargetRequired, IEnumerable<(string, bool)> args, Action<GameEvent> executeAction) bool isTargetRequired, IEnumerable<(string, bool)> args, Action<GameEvent> executeAction)
{ {
var permissionEnum = Enum.Parse<Permission>(permission); var permissionEnum = Enum.Parse<EFClient.Permission>(permission);
var argsArray = args.Select(_arg => new CommandArgument var argsArray = args.Select(_arg => new CommandArgument
{ {
Name = _arg.Item1, Name = _arg.Item1,

View File

@ -15,10 +15,14 @@ using System.Runtime.InteropServices;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Serilog.Context; using Serilog.Context;
using static SharedLibraryCore.Database.Models.EFClient; using static SharedLibraryCore.Database.Models.EFClient;
using Data.Models;
using Data.Models.Server;
using static Data.Models.Client.EFClient;
namespace IW4MAdmin namespace IW4MAdmin
{ {
@ -29,18 +33,20 @@ namespace IW4MAdmin
private readonly ITranslationLookup _translationLookup; private readonly ITranslationLookup _translationLookup;
private readonly IMetaService _metaService; private readonly IMetaService _metaService;
private const int REPORT_FLAG_COUNT = 4; private const int REPORT_FLAG_COUNT = 4;
private int lastGameTime = 0; private long lastGameTime = 0;
public int Id { get; private set; } public int Id { get; private set; }
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
private readonly IClientNoticeMessageFormatter _messageFormatter; private readonly IClientNoticeMessageFormatter _messageFormatter;
private readonly ILookupCache<EFServer> _serverCache;
public IW4MServer( public IW4MServer(
ServerConfiguration serverConfiguration, ServerConfiguration serverConfiguration,
ITranslationLookup lookup, ITranslationLookup lookup,
IMetaService metaService, IMetaService metaService,
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
IClientNoticeMessageFormatter messageFormatter) : base(serviceProvider.GetRequiredService<ILogger<Server>>(), IClientNoticeMessageFormatter messageFormatter,
ILookupCache<EFServer> serverCache) : base(serviceProvider.GetRequiredService<ILogger<Server>>(),
serviceProvider.GetRequiredService<SharedLibraryCore.Interfaces.ILogger>(), serviceProvider.GetRequiredService<SharedLibraryCore.Interfaces.ILogger>(),
serverConfiguration, serverConfiguration,
serviceProvider.GetRequiredService<IManager>(), serviceProvider.GetRequiredService<IManager>(),
@ -51,6 +57,7 @@ namespace IW4MAdmin
_metaService = metaService; _metaService = metaService;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_messageFormatter = messageFormatter; _messageFormatter = messageFormatter;
_serverCache = serverCache;
} }
public override async Task<EFClient> OnClientConnected(EFClient clientFromLog) public override async Task<EFClient> OnClientConnected(EFClient clientFromLog)
@ -67,6 +74,8 @@ namespace IW4MAdmin
client = await Manager.GetClientService().Create(clientFromLog); client = await Manager.GetClientService().Create(clientFromLog);
} }
client.CopyAdditionalProperties(clientFromLog);
// this is only a temporary version until the IPAddress is transmitted // this is only a temporary version until the IPAddress is transmitted
client.CurrentAlias = new EFAlias() client.CurrentAlias = new EFAlias()
{ {
@ -154,7 +163,8 @@ namespace IW4MAdmin
catch (CommandException e) catch (CommandException e)
{ {
ServerLogger.LogWarning(e, "Error validating command from event {@event}", E); ServerLogger.LogWarning(e, "Error validating command from event {@event}",
new { E.Type, E.Data, E.Message, E.Subtype, E.IsRemote, E.CorrelationId });
E.FailReason = GameEvent.EventFailReason.Invalid; E.FailReason = GameEvent.EventFailReason.Invalid;
} }
@ -249,6 +259,28 @@ namespace IW4MAdmin
{ {
ServerLogger.LogDebug("processing event of type {type}", E.Type); ServerLogger.LogDebug("processing event of type {type}", E.Type);
if (E.Type == GameEvent.EventType.Start)
{
var existingServer = (await _serverCache
.FirstAsync(server => server.Id == EndPoint));
var serverId = await GetIdForServer(E.Owner);
if (existingServer == null)
{
var server = new EFServer()
{
Port = Port,
EndPoint = ToString(),
ServerId = serverId,
GameName = (Reference.Game?)GameName,
HostName = Hostname
};
await _serverCache.AddAsync(server);
}
}
if (E.Type == GameEvent.EventType.ConnectionLost) if (E.Type == GameEvent.EventType.ConnectionLost)
{ {
var exception = E.Extra as Exception; var exception = E.Extra as Exception;
@ -299,6 +331,13 @@ namespace IW4MAdmin
Time = DateTime.UtcNow Time = DateTime.UtcNow
}); });
var clientTag = await _metaService.GetPersistentMeta(EFMeta.ClientTag, E.Origin);
if (clientTag?.LinkedMeta != null)
{
E.Origin.Tag = clientTag.LinkedMeta.Value;
}
await E.Origin.OnJoin(E.Origin.IPAddress); await E.Origin.OnJoin(E.Origin.IPAddress);
} }
} }
@ -444,10 +483,10 @@ namespace IW4MAdmin
await Manager.GetPenaltyService().Create(newReport); await Manager.GetPenaltyService().Create(newReport);
int reportNum = await Manager.GetClientService().GetClientReportCount(E.Target.ClientId); var reportNum = await Manager.GetClientService().GetClientReportCount(E.Target.ClientId);
bool isAutoFlagged = await Manager.GetClientService().IsAutoFlagged(E.Target.ClientId); var canBeAutoFlagged = await Manager.GetClientService().CanBeAutoFlagged(E.Target.ClientId);
if (!E.Target.IsPrivileged() && reportNum >= REPORT_FLAG_COUNT && !isAutoFlagged) if (!E.Target.IsPrivileged() && reportNum >= REPORT_FLAG_COUNT && canBeAutoFlagged)
{ {
E.Target.Flag( E.Target.Flag(
Utilities.CurrentLocalization.LocalizationIndex["SERVER_AUTO_FLAG_REPORT"] Utilities.CurrentLocalization.LocalizationIndex["SERVER_AUTO_FLAG_REPORT"]
@ -702,11 +741,11 @@ namespace IW4MAdmin
/// array index 2 = updated clients /// array index 2 = updated clients
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
async Task<IList<EFClient>[]> PollPlayersAsync() async Task<List<EFClient>[]> PollPlayersAsync()
{ {
var currentClients = GetClientsAsList(); var currentClients = GetClientsAsList();
var statusResponse = (await this.GetStatusAsync()); var statusResponse = (await this.GetStatusAsync());
var polledClients = statusResponse.Item1.AsEnumerable(); var polledClients = statusResponse.Clients.AsEnumerable();
if (Manager.GetApplicationSettings().Configuration().IgnoreBots) if (Manager.GetApplicationSettings().Configuration().IgnoreBots)
{ {
@ -716,10 +755,12 @@ namespace IW4MAdmin
var connectingClients = polledClients.Except(currentClients); var connectingClients = polledClients.Except(currentClients);
var updatedClients = polledClients.Except(connectingClients).Except(disconnectingClients); var updatedClients = polledClients.Except(connectingClients).Except(disconnectingClients);
UpdateMap(statusResponse.Item2); UpdateMap(statusResponse.Map);
UpdateGametype(statusResponse.Item3); UpdateGametype(statusResponse.GameType);
UpdateHostname(statusResponse.Hostname);
UpdateMaxPlayers(statusResponse.MaxClients);
return new List<EFClient>[] return new []
{ {
connectingClients.ToList(), connectingClients.ToList(),
disconnectingClients.ToList(), disconnectingClients.ToList(),
@ -727,6 +768,25 @@ namespace IW4MAdmin
}; };
} }
private async Task<long> GetIdForServer(Server server)
{
if ($"{server.IP}:{server.Port.ToString()}" == "66.150.121.184:28965")
{
return 886229536;
}
// todo: this is not stable and will need to be migrated again...
long id = HashCode.Combine(server.IP, server.Port);
id = id < 0 ? Math.Abs(id) : id;
var serverId = (await _serverCache
.FirstAsync(_server => _server.ServerId == server.EndPoint ||
_server.EndPoint == server.ToString() ||
_server.ServerId == id))?.ServerId;
return !serverId.HasValue ? id : serverId.Value;
}
private void UpdateMap(string mapname) private void UpdateMap(string mapname)
{ {
if (!string.IsNullOrEmpty(mapname)) if (!string.IsNullOrEmpty(mapname))
@ -747,6 +807,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() private async Task ShutdownInternal()
{ {
foreach (var client in GetClientsAsList()) foreach (var client in GetClientsAsList())
@ -955,11 +1045,12 @@ namespace IW4MAdmin
RconParser = RconParser ?? Manager.AdditionalRConParsers[0]; RconParser = RconParser ?? Manager.AdditionalRConParsers[0];
EventParser = EventParser ?? Manager.AdditionalEventParsers[0]; EventParser = EventParser ?? Manager.AdditionalEventParsers[0];
RemoteConnection = RConConnectionFactory.CreateConnection(IP, Port, Password, RconParser.RConEngine);
RemoteConnection.SetConfiguration(RconParser); RemoteConnection.SetConfiguration(RconParser);
var version = await this.GetMappedDvarValueOrDefaultAsync<string>("version"); var version = await this.GetMappedDvarValueOrDefaultAsync<string>("version");
Version = version.Value; Version = version.Value;
GameName = Utilities.GetGame(version?.Value ?? RconParser.Version); GameName = Utilities.GetGame(version.Value ?? RconParser.Version);
if (GameName == Game.UKN) if (GameName == Game.UKN)
{ {
@ -1105,6 +1196,7 @@ namespace IW4MAdmin
this, this,
GenerateUriForLog(LogPath, ServerConfig.GameLogServerUrl?.AbsoluteUri), gameLogReaderFactory); GenerateUriForLog(LogPath, ServerConfig.GameLogServerUrl?.AbsoluteUri), gameLogReaderFactory);
await _serverCache.InitializeAsync();
_ = Task.Run(() => LogEvent.PollForChanges()); _ = Task.Run(() => LogEvent.PollForChanges());
if (!Utilities.IsDevelopment) if (!Utilities.IsDevelopment)
@ -1115,7 +1207,7 @@ namespace IW4MAdmin
public Uri[] GenerateUriForLog(string logPath, string gameLogServerUrl) public Uri[] GenerateUriForLog(string logPath, string gameLogServerUrl)
{ {
var logUri = new Uri(logPath); var logUri = new Uri(logPath, UriKind.Absolute);
if (string.IsNullOrEmpty(gameLogServerUrl)) if (string.IsNullOrEmpty(gameLogServerUrl))
{ {
@ -1230,8 +1322,12 @@ namespace IW4MAdmin
Manager.AddEvent(e); Manager.AddEvent(e);
var temporalClientId = targetClient.GetAdditionalProperty<string>("ConnectionClientId");
var parsedClientId = string.IsNullOrEmpty(temporalClientId) ? (int?)null : int.Parse(temporalClientId);
var clientNumber = parsedClientId ?? targetClient.ClientNumber;
var formattedKick = string.Format(RconParser.Configuration.CommandPrefixes.Kick, var formattedKick = string.Format(RconParser.Configuration.CommandPrefixes.Kick,
targetClient.ClientNumber, clientNumber,
_messageFormatter.BuildFormattedMessage(RconParser.Configuration, _messageFormatter.BuildFormattedMessage(RconParser.Configuration,
newPenalty, newPenalty,
previousPenalty)); previousPenalty));
@ -1262,8 +1358,12 @@ namespace IW4MAdmin
if (targetClient.IsIngame) if (targetClient.IsIngame)
{ {
var temporalClientId = targetClient.GetAdditionalProperty<string>("ConnectionClientId");
var parsedClientId = string.IsNullOrEmpty(temporalClientId) ? (int?)null : int.Parse(temporalClientId);
var clientNumber = parsedClientId ?? targetClient.ClientNumber;
var formattedKick = string.Format(RconParser.Configuration.CommandPrefixes.Kick, var formattedKick = string.Format(RconParser.Configuration.CommandPrefixes.Kick,
targetClient.ClientNumber, clientNumber,
_messageFormatter.BuildFormattedMessage(RconParser.Configuration, newPenalty)); _messageFormatter.BuildFormattedMessage(RconParser.Configuration, newPenalty));
ServerLogger.LogDebug("Executing tempban kick command for {targetClient}", targetClient.ToString()); ServerLogger.LogDebug("Executing tempban kick command for {targetClient}", targetClient.ToString());
await targetClient.CurrentServer.ExecuteCommandAsync(formattedKick); await targetClient.CurrentServer.ExecuteCommandAsync(formattedKick);
@ -1296,8 +1396,13 @@ namespace IW4MAdmin
if (targetClient.IsIngame) if (targetClient.IsIngame)
{ {
ServerLogger.LogDebug("Attempting to kicking newly banned client {targetClient}", targetClient.ToString()); ServerLogger.LogDebug("Attempting to kicking newly banned client {targetClient}", targetClient.ToString());
var temporalClientId = targetClient.GetAdditionalProperty<string>("ConnectionClientId");
var parsedClientId = string.IsNullOrEmpty(temporalClientId) ? (int?)null : int.Parse(temporalClientId);
var clientNumber = parsedClientId ?? targetClient.ClientNumber;
var formattedString = string.Format(RconParser.Configuration.CommandPrefixes.Kick, var formattedString = string.Format(RconParser.Configuration.CommandPrefixes.Kick,
targetClient.ClientNumber, clientNumber,
_messageFormatter.BuildFormattedMessage(RconParser.Configuration, newPenalty)); _messageFormatter.BuildFormattedMessage(RconParser.Configuration, newPenalty));
await targetClient.CurrentServer.ExecuteCommandAsync(formattedString); await targetClient.CurrentServer.ExecuteCommandAsync(formattedString);
} }

View File

@ -17,16 +17,23 @@ using SharedLibraryCore.QueryHelper;
using SharedLibraryCore.Repositories; using SharedLibraryCore.Repositories;
using SharedLibraryCore.Services; using SharedLibraryCore.Services;
using Stats.Dtos; using Stats.Dtos;
using StatsWeb;
using System; using System;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.Abstractions;
using Data.Helpers;
using Integrations.Source.Extensions;
using IW4MAdmin.Application.Extensions; using IW4MAdmin.Application.Extensions;
using IW4MAdmin.Application.Localization; using IW4MAdmin.Application.Localization;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ILogger = Microsoft.Extensions.Logging.ILogger; using ILogger = Microsoft.Extensions.Logging.ILogger;
using IW4MAdmin.Plugins.Stats.Client.Abstractions;
using IW4MAdmin.Plugins.Stats.Client;
using Stats.Client.Abstractions;
using Stats.Client;
using Stats.Helpers;
namespace IW4MAdmin.Application namespace IW4MAdmin.Application
{ {
@ -68,7 +75,10 @@ namespace IW4MAdmin.Application
private static async void OnCancelKey(object sender, ConsoleCancelEventArgs e) private static async void OnCancelKey(object sender, ConsoleCancelEventArgs e)
{ {
ServerManager?.Stop(); ServerManager?.Stop();
await ApplicationTask; if (ApplicationTask != null)
{
await ApplicationTask;
}
} }
/// <summary> /// <summary>
@ -77,7 +87,7 @@ namespace IW4MAdmin.Application
/// <returns></returns> /// <returns></returns>
private static async Task LaunchAsync(string[] args) private static async Task LaunchAsync(string[] args)
{ {
restart: restart:
ITranslationLookup translationLookup = null; ITranslationLookup translationLookup = null;
var logger = BuildDefaultLogger<Program>(new ApplicationConfiguration()); var logger = BuildDefaultLogger<Program>(new ApplicationConfiguration());
Utilities.DefaultLogger = logger; Utilities.DefaultLogger = logger;
@ -89,11 +99,12 @@ namespace IW4MAdmin.Application
// do any needed housekeeping file/folder migrations // do any needed housekeeping file/folder migrations
ConfigurationMigration.MoveConfigFolder10518(null); ConfigurationMigration.MoveConfigFolder10518(null);
ConfigurationMigration.CheckDirectories(); ConfigurationMigration.CheckDirectories();
ConfigurationMigration.RemoveObsoletePlugins20210322();
logger.LogDebug("Configuring services..."); logger.LogDebug("Configuring services...");
services = ConfigureServices(args); services = ConfigureServices(args);
serviceProvider = services.BuildServiceProvider(); serviceProvider = services.BuildServiceProvider();
var versionChecker = serviceProvider.GetRequiredService<IMasterCommunication>(); var versionChecker = serviceProvider.GetRequiredService<IMasterCommunication>();
ServerManager = (ApplicationManager)serviceProvider.GetRequiredService<IManager>(); ServerManager = (ApplicationManager) serviceProvider.GetRequiredService<IManager>();
translationLookup = serviceProvider.GetRequiredService<ITranslationLookup>(); translationLookup = serviceProvider.GetRequiredService<ITranslationLookup>();
await versionChecker.CheckVersion(); await versionChecker.CheckVersion();
@ -102,8 +113,12 @@ namespace IW4MAdmin.Application
catch (Exception e) catch (Exception e)
{ {
string failMessage = translationLookup == null ? "Failed to initialize IW4MAdmin" : translationLookup["MANAGER_INIT_FAIL"]; string failMessage = translationLookup == null
string exitMessage = translationLookup == null ? "Press enter to exit..." : translationLookup["MANAGER_EXIT"]; ? "Failed to initialize IW4MAdmin"
: translationLookup["MANAGER_INIT_FAIL"];
string exitMessage = translationLookup == null
? "Press enter to exit..."
: translationLookup["MANAGER_EXIT"];
logger.LogCritical(e, "Failed to initialize IW4MAdmin"); logger.LogCritical(e, "Failed to initialize IW4MAdmin");
Console.WriteLine(failMessage); Console.WriteLine(failMessage);
@ -117,7 +132,8 @@ namespace IW4MAdmin.Application
{ {
if (translationLookup != null) if (translationLookup != null)
{ {
Console.WriteLine(translationLookup[configException.Message].FormatExt(configException.ConfigurationFileName)); Console.WriteLine(translationLookup[configException.Message]
.FormatExt(configException.ConfigurationFileName));
} }
foreach (string error in configException.Errors) foreach (string error in configException.Errors)
@ -145,7 +161,9 @@ namespace IW4MAdmin.Application
catch (Exception e) catch (Exception e)
{ {
logger.LogCritical(e, "Failed to launch IW4MAdmin"); logger.LogCritical(e, "Failed to launch IW4MAdmin");
string failMessage = translationLookup == null ? "Failed to launch IW4MAdmin" : translationLookup["MANAGER_INIT_FAIL"]; string failMessage = translationLookup == null
? "Failed to launch IW4MAdmin"
: translationLookup["MANAGER_INIT_FAIL"];
Console.WriteLine($"{failMessage}: {e.GetExceptionInfo()}"); Console.WriteLine($"{failMessage}: {e.GetExceptionInfo()}");
} }
@ -163,9 +181,9 @@ namespace IW4MAdmin.Application
/// <returns></returns> /// <returns></returns>
private static async Task RunApplicationTasksAsync(ILogger logger, IServiceCollection services) private static async Task RunApplicationTasksAsync(ILogger logger, IServiceCollection services)
{ {
var webfrontTask = ServerManager.GetApplicationSettings().Configuration().EnableWebFront ? var webfrontTask = ServerManager.GetApplicationSettings().Configuration().EnableWebFront
WebfrontCore.Program.Init(ServerManager, serviceProvider, services, ServerManager.CancellationToken) : ? WebfrontCore.Program.Init(ServerManager, serviceProvider, services, ServerManager.CancellationToken)
Task.CompletedTask; : Task.CompletedTask;
// we want to run this one on a manual thread instead of letting the thread pool handle it, // 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 // because we can't exit early from waiting on console input, and it prevents us from restarting
@ -176,14 +194,15 @@ namespace IW4MAdmin.Application
{ {
ServerManager.Start(), ServerManager.Start(),
webfrontTask, webfrontTask,
serviceProvider.GetRequiredService<IMasterCommunication>().RunUploadStatus(ServerManager.CancellationToken) serviceProvider.GetRequiredService<IMasterCommunication>()
.RunUploadStatus(ServerManager.CancellationToken)
}; };
logger.LogDebug("Starting webfront and input tasks"); logger.LogDebug("Starting webfront and input tasks");
await Task.WhenAll(tasks); await Task.WhenAll(tasks);
logger.LogInformation("Shutdown completed successfully"); logger.LogInformation("Shutdown completed successfully");
Console.Write(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_SHUTDOWN_SUCCESS"]); Console.WriteLine(Utilities.CurrentLocalization.LocalizationIndex["MANAGER_SHUTDOWN_SUCCESS"]);
} }
@ -228,7 +247,8 @@ namespace IW4MAdmin.Application
} }
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ } {
}
} }
private static IServiceCollection HandlePluginRegistration(ApplicationConfiguration appConfig, private static IServiceCollection HandlePluginRegistration(ApplicationConfiguration appConfig,
@ -251,27 +271,38 @@ namespace IW4MAdmin.Application
// register the native commands // register the native commands
foreach (var commandType in typeof(SharedLibraryCore.Commands.QuitCommand).Assembly.GetTypes() foreach (var commandType in typeof(SharedLibraryCore.Commands.QuitCommand).Assembly.GetTypes()
.Where(_command => _command.BaseType == typeof(Command))) .Where(_command => _command.BaseType == typeof(Command)))
{ {
defaultLogger.LogDebug("Registered native command type {name}", commandType.Name); defaultLogger.LogDebug("Registered native command type {name}", commandType.Name);
serviceCollection.AddSingleton(typeof(IManagerCommand), commandType); serviceCollection.AddSingleton(typeof(IManagerCommand), commandType);
} }
// register the plugin implementations // register the plugin implementations
var pluginImplementations = pluginImporter.DiscoverAssemblyPluginImplementations(); var (plugins, commands, configurations) = pluginImporter.DiscoverAssemblyPluginImplementations();
foreach (var pluginType in pluginImplementations.Item1) foreach (var pluginType in plugins)
{ {
defaultLogger.LogDebug("Registered plugin type {name}", pluginType.FullName); defaultLogger.LogDebug("Registered plugin type {name}", pluginType.FullName);
serviceCollection.AddSingleton(typeof(IPlugin), pluginType); serviceCollection.AddSingleton(typeof(IPlugin), pluginType);
} }
// register the plugin commands // register the plugin commands
foreach (var commandType in pluginImplementations.Item2) foreach (var commandType in commands)
{ {
defaultLogger.LogDebug("Registered plugin command type {name}", commandType.FullName); defaultLogger.LogDebug("Registered plugin command type {name}", commandType.FullName);
serviceCollection.AddSingleton(typeof(IManagerCommand), commandType); serviceCollection.AddSingleton(typeof(IManagerCommand), commandType);
} }
foreach (var configurationType in configurations)
{
defaultLogger.LogDebug("Registered plugin config type {name}", configurationType.Name);
var configInstance = (IBaseConfiguration) Activator.CreateInstance(configurationType);
var handlerType = typeof(BaseConfigurationHandler<>).MakeGenericType(configurationType);
var handlerInstance = Activator.CreateInstance(handlerType, new[] {configInstance.Name()});
var genericInterfaceType = typeof(IConfigurationHandler<>).MakeGenericType(configurationType);
serviceCollection.AddSingleton(genericInterfaceType, handlerInstance);
}
// register any script plugins // register any script plugins
foreach (var scriptPlugin in pluginImporter.DiscoverScriptPlugins()) foreach (var scriptPlugin in pluginImporter.DiscoverScriptPlugins())
{ {
@ -281,10 +312,9 @@ namespace IW4MAdmin.Application
// register any eventable types // register any eventable types
foreach (var assemblyType in typeof(Program).Assembly.GetTypes() foreach (var assemblyType in typeof(Program).Assembly.GetTypes()
.Where(_asmType => typeof(IRegisterEvent).IsAssignableFrom(_asmType)) .Where(_asmType => typeof(IRegisterEvent).IsAssignableFrom(_asmType))
.Union(pluginImplementations .Union(plugins.SelectMany(_asm => _asm.Assembly.GetTypes())
.Item1.SelectMany(_asm => _asm.Assembly.GetTypes()) .Distinct()
.Distinct() .Where(_asmType => typeof(IRegisterEvent).IsAssignableFrom(_asmType))))
.Where(_asmType => typeof(IRegisterEvent).IsAssignableFrom(_asmType))))
{ {
var instance = Activator.CreateInstance(assemblyType) as IRegisterEvent; var instance = Activator.CreateInstance(assemblyType) as IRegisterEvent;
serviceCollection.AddSingleton(instance); serviceCollection.AddSingleton(instance);
@ -307,7 +337,7 @@ namespace IW4MAdmin.Application
? new Uri("http://127.0.0.1:8080") ? new Uri("http://127.0.0.1:8080")
: appConfig?.MasterUrl ?? new ApplicationConfiguration().MasterUrl; : appConfig?.MasterUrl ?? new ApplicationConfiguration().MasterUrl;
var masterRestClient = RestClient.For<IMasterApi>(masterUri); var masterRestClient = RestClient.For<IMasterApi>(masterUri);
var translationLookup = Configure.Initialize(Utilities.DefaultLogger, masterRestClient, appConfig); var translationLookup = Configure.Initialize(Utilities.DefaultLogger, masterRestClient, appConfig);
if (appConfig == null) if (appConfig == null)
{ {
@ -316,12 +346,22 @@ namespace IW4MAdmin.Application
appConfigHandler.Save(); appConfigHandler.Save();
} }
// register override level names
foreach (var (key, value) in appConfig.OverridePermissionLevelNames)
{
if (!Utilities.PermissionLevelOverrides.ContainsKey(key))
{
Utilities.PermissionLevelOverrides.Add(key, value);
}
}
// build the dependency list // build the dependency list
HandlePluginRegistration(appConfig, serviceCollection, masterRestClient); HandlePluginRegistration(appConfig, serviceCollection, masterRestClient);
serviceCollection serviceCollection
.AddBaseLogger(appConfig) .AddBaseLogger(appConfig)
.AddSingleton<IServiceCollection>(_serviceProvider => serviceCollection) .AddSingleton<IServiceCollection>(_serviceProvider => serviceCollection)
.AddSingleton<IConfigurationHandler<DefaultSettings>, BaseConfigurationHandler<DefaultSettings>>()
.AddSingleton((IConfigurationHandler<ApplicationConfiguration>) appConfigHandler) .AddSingleton((IConfigurationHandler<ApplicationConfiguration>) appConfigHandler)
.AddSingleton( .AddSingleton(
new BaseConfigurationHandler<CommandConfiguration>("CommandConfiguration") as new BaseConfigurationHandler<CommandConfiguration>("CommandConfiguration") as
@ -360,6 +400,12 @@ namespace IW4MAdmin.Application
.AddSingleton<IManager, ApplicationManager>() .AddSingleton<IManager, ApplicationManager>()
.AddSingleton<SharedLibraryCore.Interfaces.ILogger, Logger>() .AddSingleton<SharedLibraryCore.Interfaces.ILogger, Logger>()
.AddSingleton<IClientNoticeMessageFormatter, ClientNoticeMessageFormatter>() .AddSingleton<IClientNoticeMessageFormatter, ClientNoticeMessageFormatter>()
.AddSingleton<IClientStatisticCalculator, HitCalculator>()
.AddSingleton<IServerDistributionCalculator, ServerDistributionCalculator>()
.AddSingleton<IWeaponNameParser, WeaponNameParser>()
.AddSingleton<IHitInfoBuilder, HitInfoBuilder>()
.AddSingleton(typeof(ILookupCache<>), typeof(LookupCache<>))
.AddSingleton(typeof(IDataValueCache<,>), typeof(DataValueCache<,>))
.AddSingleton(translationLookup) .AddSingleton(translationLookup)
.AddDatabaseContextOptions(appConfig); .AddDatabaseContextOptions(appConfig);
@ -372,6 +418,8 @@ namespace IW4MAdmin.Application
serviceCollection.AddSingleton<IEventHandler, GameEventHandler>(); serviceCollection.AddSingleton<IEventHandler, GameEventHandler>();
} }
serviceCollection.AddSource();
return serviceCollection; return serviceCollection;
} }

View File

@ -1,8 +1,9 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.Abstractions;
using Data.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Dtos.Meta.Responses; using SharedLibraryCore.Dtos.Meta.Responses;
using SharedLibraryCore.Helpers; using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;

View File

@ -1,10 +1,10 @@
using System; using System.Linq;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.Abstractions;
using Data.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SharedLibraryCore; using SharedLibraryCore;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Dtos.Meta.Responses; using SharedLibraryCore.Dtos.Meta.Responses;
using SharedLibraryCore.Helpers; using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;

View File

@ -6,6 +6,7 @@ using SharedLibraryCore.Interfaces;
using SharedLibraryCore.QueryHelper; using SharedLibraryCore.QueryHelper;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ILogger = Microsoft.Extensions.Logging.ILogger; using ILogger = Microsoft.Extensions.Logging.ILogger;

View File

@ -85,5 +85,20 @@ namespace IW4MAdmin.Application.Migration
config.ManualLogPath = null; config.ManualLogPath = null;
} }
} }
public static void RemoveObsoletePlugins20210322()
{
var files = new[] {"StatsWeb.dll", "StatsWeb.Views.dll"};
foreach (var file in files)
{
var path = Path.Join(Utilities.OperatingDirectory, "Plugins", file);
if (File.Exists(path))
{
File.Delete(path);
}
}
}
} }
} }

View File

@ -2,7 +2,8 @@
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using IW4MAdmin.Plugins.Stats.Models; using Data.Abstractions;
using Data.Models.Client.Stats;
using SharedLibraryCore.Database; using SharedLibraryCore.Database;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;

View File

@ -22,6 +22,11 @@ namespace IW4MAdmin.Application.Misc
Build(); Build();
} }
public BaseConfigurationHandler() : this(typeof(T).Name)
{
}
public string FileName { get; } public string FileName { get; }
public void Build() public void Build()

View File

@ -2,9 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Data.Models;
using SharedLibraryCore; using SharedLibraryCore;
using SharedLibraryCore.Configuration; using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.Misc namespace IW4MAdmin.Application.Misc

View File

@ -7,8 +7,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ILogger = Microsoft.Extensions.Logging.ILogger; using ILogger = Microsoft.Extensions.Logging.ILogger;
using Data.Models;
namespace IW4MAdmin.Application.Misc namespace IW4MAdmin.Application.Misc
{ {
@ -29,7 +31,7 @@ namespace IW4MAdmin.Application.Misc
_contextFactory = contextFactory; _contextFactory = contextFactory;
} }
public async Task AddPersistentMeta(string metaKey, string metaValue, EFClient client) public async Task AddPersistentMeta(string metaKey, string metaValue, EFClient client, EFMeta linkedMeta = null)
{ {
// this seems to happen if the client disconnects before they've had time to authenticate and be added // this seems to happen if the client disconnects before they've had time to authenticate and be added
if (client.ClientId < 1) if (client.ClientId < 1)
@ -48,6 +50,7 @@ namespace IW4MAdmin.Application.Misc
{ {
existingMeta.Value = metaValue; existingMeta.Value = metaValue;
existingMeta.Updated = DateTime.UtcNow; existingMeta.Updated = DateTime.UtcNow;
existingMeta.LinkedMetaId = linkedMeta?.MetaId;
} }
else else
@ -57,13 +60,98 @@ namespace IW4MAdmin.Application.Misc
ClientId = client.ClientId, ClientId = client.ClientId,
Created = DateTime.UtcNow, Created = DateTime.UtcNow,
Key = metaKey, Key = metaKey,
Value = metaValue Value = metaValue,
LinkedMetaId = linkedMeta?.MetaId
}); });
} }
await ctx.SaveChangesAsync(); await ctx.SaveChangesAsync();
} }
public async Task AddPersistentMeta(string metaKey, string metaValue)
{
await using var ctx = _contextFactory.CreateContext();
var existingMeta = await ctx.EFMeta
.Where(meta => meta.Key == metaKey)
.Where(meta => meta.ClientId == null)
.ToListAsync();
var matchValues = existingMeta
.Where(meta => meta.Value == metaValue)
.ToArray();
if (matchValues.Any())
{
foreach (var meta in matchValues)
{
_logger.LogDebug("Updating existing meta with key {key} and id {id}", meta.Key, meta.MetaId);
meta.Value = metaValue;
meta.Updated = DateTime.UtcNow;
}
await ctx.SaveChangesAsync();
}
else
{
_logger.LogDebug("Adding new meta with key {key}", metaKey);
ctx.EFMeta.Add(new EFMeta()
{
Created = DateTime.UtcNow,
Key = metaKey,
Value = metaValue
});
await ctx.SaveChangesAsync();
}
}
public async Task RemovePersistentMeta(string metaKey, EFClient client)
{
await using var context = _contextFactory.CreateContext();
var existingMeta = await context.EFMeta
.FirstOrDefaultAsync(meta => meta.Key == metaKey && meta.ClientId == client.ClientId);
if (existingMeta == null)
{
_logger.LogDebug("No meta with key {key} found for client id {id}", metaKey, client.ClientId);
return;
}
_logger.LogDebug("Removing meta for key {key} with id {id}", metaKey, existingMeta.MetaId);
context.EFMeta.Remove(existingMeta);
await context.SaveChangesAsync();
}
public async Task RemovePersistentMeta(string metaKey, string metaValue = null)
{
await using var context = _contextFactory.CreateContext(enableTracking: false);
var existingMeta = await context.EFMeta
.Where(meta => meta.Key == metaKey)
.Where(meta => meta.ClientId == null)
.ToListAsync();
if (metaValue == null)
{
_logger.LogDebug("Removing all meta for key {key} with ids [{ids}] ", metaKey, string.Join(", ", existingMeta.Select(meta => meta.MetaId)));
existingMeta.ForEach(meta => context.Remove(existingMeta));
await context.SaveChangesAsync();
return;
}
var foundMeta = existingMeta.FirstOrDefault(meta => meta.Value == metaValue);
if (foundMeta != null)
{
_logger.LogDebug("Removing meta for key {key} with id {id}", metaKey, foundMeta.MetaId);
context.Remove(foundMeta);
await context.SaveChangesAsync();
}
}
public async Task<EFMeta> GetPersistentMeta(string metaKey, EFClient client) public async Task<EFMeta> GetPersistentMeta(string metaKey, EFClient client)
{ {
await using var ctx = _contextFactory.CreateContext(enableTracking: false); await using var ctx = _contextFactory.CreateContext(enableTracking: false);
@ -76,11 +164,34 @@ namespace IW4MAdmin.Application.Misc
MetaId = _meta.MetaId, MetaId = _meta.MetaId,
Key = _meta.Key, Key = _meta.Key,
ClientId = _meta.ClientId, ClientId = _meta.ClientId,
Value = _meta.Value Value = _meta.Value,
LinkedMetaId = _meta.LinkedMetaId,
LinkedMeta = _meta.LinkedMetaId != null ? new EFMeta()
{
MetaId = _meta.LinkedMeta.MetaId,
Key = _meta.LinkedMeta.Key,
Value = _meta.LinkedMeta.Value
} : null
}) })
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
} }
public async Task<IEnumerable<EFMeta>> GetPersistentMeta(string metaKey)
{
await using var context = _contextFactory.CreateContext(enableTracking: false);
return await context.EFMeta
.Where(meta => meta.Key == metaKey)
.Where(meta => meta.ClientId == null)
.Select(meta => new EFMeta
{
MetaId = meta.MetaId,
Key = meta.Key,
ClientId = meta.ClientId,
Value = meta.Value,
})
.ToListAsync();
}
public void AddRuntimeMeta<T, V>(MetaType metaKey, Func<T, Task<IEnumerable<V>>> metaAction) where T : PaginationRequest where V : IClientMeta public void AddRuntimeMeta<T, V>(MetaType metaKey, Func<T, Task<IEnumerable<V>>> metaAction) where T : PaginationRequest where V : IClientMeta
{ {
if (!_metaActions.ContainsKey(metaKey)) if (!_metaActions.ContainsKey(metaKey))

View File

@ -63,11 +63,12 @@ namespace IW4MAdmin.Application.Misc
/// discovers all the C# assembly plugins and commands /// discovers all the C# assembly plugins and commands
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public (IEnumerable<Type>, IEnumerable<Type>) DiscoverAssemblyPluginImplementations() public (IEnumerable<Type>, IEnumerable<Type>, IEnumerable<Type>) DiscoverAssemblyPluginImplementations()
{ {
string pluginDir = $"{Utilities.OperatingDirectory}{PLUGIN_DIR}{Path.DirectorySeparatorChar}"; var pluginDir = $"{Utilities.OperatingDirectory}{PLUGIN_DIR}{Path.DirectorySeparatorChar}";
var pluginTypes = Enumerable.Empty<Type>(); var pluginTypes = Enumerable.Empty<Type>();
var commandTypes = Enumerable.Empty<Type>(); var commandTypes = Enumerable.Empty<Type>();
var configurationTypes = Enumerable.Empty<Type>();
if (Directory.Exists(pluginDir)) if (Directory.Exists(pluginDir))
{ {
@ -92,10 +93,17 @@ namespace IW4MAdmin.Application.Misc
.Where(_assemblyType => _assemblyType.IsClass && _assemblyType.BaseType == typeof(Command)); .Where(_assemblyType => _assemblyType.IsClass && _assemblyType.BaseType == typeof(Command));
_logger.LogDebug("Discovered {count} plugin commands", commandTypes.Count()); _logger.LogDebug("Discovered {count} plugin commands", commandTypes.Count());
configurationTypes = assemblies
.SelectMany(asm => asm.GetTypes())
.Where(asmType =>
asmType.IsClass && asmType.GetInterface(nameof(IBaseConfiguration), false) != null);
_logger.LogDebug("Discovered {count} configuration implementations", configurationTypes.Count());
} }
} }
return (pluginTypes, commandTypes); return (pluginTypes, commandTypes, configurationTypes);
} }
private IEnumerable<Assembly> GetRemoteAssemblies() private IEnumerable<Assembly> GetRemoteAssemblies()

View File

@ -4,6 +4,7 @@ using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.Models.Client;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Database.Models.EFClient; using static SharedLibraryCore.Database.Models.EFClient;
using ILogger = Microsoft.Extensions.Logging.ILogger; using ILogger = Microsoft.Extensions.Logging.ILogger;
@ -18,7 +19,7 @@ namespace IW4MAdmin.Application.Misc
private readonly Action<GameEvent> _executeAction; private readonly Action<GameEvent> _executeAction;
private readonly ILogger _logger; private readonly ILogger _logger;
public ScriptCommand(string name, string alias, string description, bool isTargetRequired, Permission permission, public ScriptCommand(string name, string alias, string description, bool isTargetRequired, EFClient.Permission permission,
CommandArgument[] args, Action<GameEvent> executeAction, CommandConfiguration config, ITranslationLookup layout, ILogger<ScriptCommand> logger) CommandArgument[] args, Action<GameEvent> executeAction, CommandConfiguration config, ITranslationLookup layout, ILogger<ScriptCommand> logger)
: base(config, layout) : base(config, layout)
{ {

View File

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

@ -4,6 +4,7 @@ using SharedLibraryCore;
using SharedLibraryCore.Database.Models; using SharedLibraryCore.Database.Models;
using System; using System;
using System.Net; using System.Net;
using Data.Models;
using static SharedLibraryCore.Database.Models.EFClient; using static SharedLibraryCore.Database.Models.EFClient;
using static SharedLibraryCore.GameEvent; using static SharedLibraryCore.GameEvent;

View File

@ -8,11 +8,12 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using static SharedLibraryCore.Server; using static SharedLibraryCore.Server;
using ILogger = Microsoft.Extensions.Logging.ILogger; using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace IW4MAdmin.Application.RconParsers namespace IW4MAdmin.Application.RConParsers
{ {
public class BaseRConParser : IRConParser public class BaseRConParser : IRConParser
{ {
@ -55,6 +56,7 @@ namespace IW4MAdmin.Application.RconParsers
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarDefaultValue, 3); Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarDefaultValue, 3);
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarLatchedValue, 4); Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarLatchedValue, 4);
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarDomain, 5); 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.StatusHeader.Pattern = "num +score +ping +guid +name +lastmsg +address +qport +rate *";
Configuration.GametypeStatus.Pattern = ""; Configuration.GametypeStatus.Pattern = "";
@ -72,6 +74,7 @@ namespace IW4MAdmin.Application.RconParsers
public Game GameName { get; set; } = Game.COD; public Game GameName { get; set; } = Game.COD;
public bool CanGenerateLogPath { get; set; } = true; public bool CanGenerateLogPath { get; set; } = true;
public string Name { get; set; } = "Call of Duty"; public string Name { get; set; } = "Call of Duty";
public string RConEngine { get; set; } = "COD";
public async Task<string[]> ExecuteCommandAsync(IRConConnection connection, string command) public async Task<string[]> ExecuteCommandAsync(IRConConnection connection, string command)
{ {
@ -127,7 +130,7 @@ namespace IW4MAdmin.Application.RconParsers
return new Dvar<T>() 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)), Value = string.IsNullOrEmpty(value) ? default : (T)Convert.ChangeType(value, typeof(T)),
DefaultValue = string.IsNullOrEmpty(defaultValue) ? default : (T)Convert.ChangeType(defaultValue, typeof(T)), DefaultValue = string.IsNullOrEmpty(defaultValue) ? default : (T)Convert.ChangeType(defaultValue, typeof(T)),
LatchedValue = string.IsNullOrEmpty(latchedValue) ? default : (T)Convert.ChangeType(latchedValue, typeof(T)), LatchedValue = string.IsNullOrEmpty(latchedValue) ? default : (T)Convert.ChangeType(latchedValue, typeof(T)),
@ -135,53 +138,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)); _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) foreach (var line in response)
{ {
var regex = Regex.Match(line, Configuration.MapStatus.Pattern); var regex = Regex.Match(line, groupPattern);
if (regex.Success) if (regex.Success)
{ {
map = regex.Groups[Configuration.MapStatus.GroupMapping[ParserRegex.GroupType.RConStatusMap]].ToString(); value = regex.Groups[Configuration.MapStatus.GroupMapping[groupType]].ToString();
} }
} }
return map; if (value == null)
}
private string GameTypeFromStatus(string[] response)
{
if (string.IsNullOrWhiteSpace(Configuration.GametypeStatus.Pattern))
{ {
return null; return default;
} }
string gametype = null; if (typeof(T) == typeof(int?))
foreach (var line in response)
{ {
var regex = Regex.Match(line, Configuration.GametypeStatus.Pattern); return (T)Convert.ChangeType(int.Parse(value), Nullable.GetUnderlyingType(typeof(T)));
if (regex.Success)
{
gametype = regex.Groups[Configuration.GametypeStatus.GroupMapping[ParserRegex.GroupType.RConStatusGametype]].ToString();
}
} }
return gametype; return (T)Convert.ChangeType(value, typeof(T));
} }
public async Task<bool> SetDvarAsync(IRConConnection connection, string dvarName, object dvarValue) public async Task<bool> SetDvarAsync(IRConConnection connection, string dvarName, object dvarValue)
{ {
string dvarString = (dvarValue is string str) string dvarString = (dvarValue is string str)
? $"{dvarName} \"{str}\"" ? $"{dvarName} \"{str}\""
: $"{dvarName} {dvarValue.ToString()}"; : $"{dvarName} {dvarValue}";
return (await connection.SendQueryAsync(StaticHelpers.QueryType.SET_DVAR, dvarString)).Length > 0; return (await connection.SendQueryAsync(StaticHelpers.QueryType.SET_DVAR, dvarString)).Length > 0;
} }
@ -205,8 +210,7 @@ namespace IW4MAdmin.Application.RconParsers
if (match.Success) if (match.Success)
{ {
if (match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConPing]] == "ZMBI" || if (match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConPing]] == "ZMBI")
match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConPing]] == "CNCT")
{ {
_logger.LogDebug("Ignoring detected client {client} because they are zombie state", string.Join(",", match.Values)); _logger.LogDebug("Ignoring detected client {client} because they are zombie state", string.Join(",", match.Values));
continue; continue;
@ -226,12 +230,13 @@ namespace IW4MAdmin.Application.RconParsers
long networkId; long networkId;
string name = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConName]].TrimNewLine(); string name = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConName]].TrimNewLine();
string networkIdString; string networkIdString;
var ip = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConIpAddress]].Split(':')[0].ConvertToIP();
try try
{ {
networkIdString = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConNetworkId]]; networkIdString = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConNetworkId]];
networkId = networkIdString.IsBotGuid() ? networkId = networkIdString.IsBotGuid() || (ip == null && ping == 999) ?
name.GenerateGuidFromString() : name.GenerateGuidFromString() :
networkIdString.ConvertGuidToLong(Configuration.GuidNumberStyle); networkIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
} }
@ -241,8 +246,6 @@ namespace IW4MAdmin.Application.RconParsers
continue; continue;
} }
int? ip = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConIpAddress]].Split(':')[0].ConvertToIP();
var client = new EFClient() var client = new EFClient()
{ {
CurrentAlias = new EFAlias() CurrentAlias = new EFAlias()
@ -258,6 +261,11 @@ namespace IW4MAdmin.Application.RconParsers
}; };
client.SetAdditionalProperty("BotGuid", networkIdString); client.SetAdditionalProperty("BotGuid", networkIdString);
var additionalGroupIndex = Configuration.Status.GroupMapping[ParserRegex.GroupType.AdditionalGroup];
if (match.Values.Length > additionalGroupIndex)
{
client.SetAdditionalProperty("ConnectionClientId", match.Values[additionalGroupIndex]);
}
StatusPlayers.Add(client); StatusPlayers.Add(client);
} }

View File

@ -1,13 +1,13 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.RconParsers namespace IW4MAdmin.Application.RConParsers
{ {
/// <summary> /// <summary>
/// empty implementation of the IW4RConParser /// empty implementation of the IW4RConParser
/// allows script plugins to generate dynamic RCon parsers /// allows script plugins to generate dynamic RCon parsers
/// </summary> /// </summary>
sealed internal class DynamicRConParser : BaseRConParser internal sealed class DynamicRConParser : BaseRConParser
{ {
public DynamicRConParser(ILogger<BaseRConParser> logger, IParserRegexFactory parserRegexFactory) : base(logger, parserRegexFactory) 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.Collections.Generic;
using System.Globalization; using System.Globalization;
namespace IW4MAdmin.Application.RconParsers namespace IW4MAdmin.Application.RConParsers
{ {
/// <summary> /// <summary>
/// generic implementation of the IRConParserConfiguration /// generic implementation of the IRConParserConfiguration
@ -16,6 +16,8 @@ namespace IW4MAdmin.Application.RconParsers
public ParserRegex Status { get; set; } public ParserRegex Status { get; set; }
public ParserRegex MapStatus { get; set; } public ParserRegex MapStatus { get; set; }
public ParserRegex GametypeStatus { get; set; } public ParserRegex GametypeStatus { get; set; }
public ParserRegex HostnameStatus { get; set; }
public ParserRegex MaxPlayersStatus { get; set; }
public ParserRegex Dvar { get; set; } public ParserRegex Dvar { get; set; }
public ParserRegex StatusHeader { get; set; } public ParserRegex StatusHeader { get; set; }
public string ServerNotRunningResponse { get; set; } public string ServerNotRunningResponse { get; set; }
@ -34,6 +36,8 @@ namespace IW4MAdmin.Application.RconParsers
GametypeStatus = parserRegexFactory.CreateParserRegex(); GametypeStatus = parserRegexFactory.CreateParserRegex();
Dvar = parserRegexFactory.CreateParserRegex(); Dvar = parserRegexFactory.CreateParserRegex();
StatusHeader = 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,12 @@
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
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);
}
}

View File

@ -1,6 +1,6 @@
using SharedLibraryCore.Database; using Data.Context;
namespace SharedLibraryCore.Interfaces namespace Data.Abstractions
{ {
/// <summary> /// <summary>
/// describes the capabilities of the database context factory /// describes the capabilities of the database context factory

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Data.Abstractions
{
public interface ILookupCache<T> where T : class
{
Task InitializeAsync();
Task<T> AddAsync(T item);
Task<T> FirstAsync(Func<T, bool> query);
IEnumerable<T> GetAll();
}
}

View File

@ -1,4 +1,4 @@
namespace SharedLibraryCore.Interfaces namespace Data.Abstractions
{ {
/// <summary> /// <summary>
/// describes the capability of extending properties by name /// describes the capability of extending properties by name

View File

@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace Data.Abstractions
{
public interface IUniqueId
{
[NotMapped]
long Id { get; }
[NotMapped]
string Value { get; }
}
}

View File

@ -1,13 +1,12 @@
using Microsoft.EntityFrameworkCore; using System;
using SharedLibraryCore.Database.Models;
using System;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using SharedLibraryCore.Interfaces; using Data.Abstractions;
using static SharedLibraryCore.Database.Models.EFClient; using Data.Models;
using Data.Models.Client;
using Microsoft.EntityFrameworkCore;
namespace SharedLibraryCore.Database namespace Data.Context
{ {
public static class ContextSeed public static class ContextSeed
{ {
@ -30,7 +29,7 @@ namespace SharedLibraryCore.Database
Connections = 0, Connections = 0,
FirstConnection = DateTime.UtcNow, FirstConnection = DateTime.UtcNow,
LastConnection = DateTime.UtcNow, LastConnection = DateTime.UtcNow,
Level = Permission.Console, Level = EFClient.Permission.Console,
Masked = true, Masked = true,
NetworkId = 0, NetworkId = 0,
AliasLink = link, AliasLink = link,

View File

@ -0,0 +1,135 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Threading;
using System.Threading.Tasks;
using Data.Extensions;
using Data.Models;
using Data.Models.Client;
using Data.Models.Client.Stats;
using Data.Models.Client.Stats.Reference;
using Data.Models.Server;
namespace Data.Context
{
public abstract class DatabaseContext : DbContext
{
public DbSet<EFClient> Clients { get; set; }
public DbSet<EFAlias> Aliases { get; set; }
public DbSet<EFAliasLink> AliasLinks { get; set; }
public DbSet<EFPenalty> Penalties { get; set; }
public DbSet<EFMeta> EFMeta { get; set; }
public DbSet<EFChangeHistory> EFChangeHistory { get; set; }
#region STATS
public DbSet<Models.Vector3> Vector3s { get; set; }
public DbSet<EFACSnapshotVector3> SnapshotVector3s { get; set; }
public DbSet<EFACSnapshot> ACSnapshots { get; set; }
public DbSet<EFServer> Servers { get; set; }
public DbSet<EFClientKill> ClientKills { get; set; }
public DbSet<EFClientMessage> ClientMessages { get; set; }
public DbSet<EFServerStatistics> ServerStatistics { get; set; }
public DbSet<EFHitLocation> HitLocations { get; set; }
public DbSet<EFClientHitStatistic> HitStatistics { get; set; }
public DbSet<EFWeapon> Weapons { get; set; }
public DbSet<EFWeaponAttachment> WeaponAttachments { get; set; }
public DbSet<EFMap> Maps { get; set; }
#endregion
private void SetAuditColumns()
{
return;
}
public DatabaseContext()
{
if (!MigrationExtensions.IsMigration)
{
throw new InvalidOperationException();
}
}
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options)
{
}
protected DatabaseContext(DbContextOptions options) : base(options)
{
}
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess,
CancellationToken cancellationToken = default)
{
SetAuditColumns();
return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
public override int SaveChanges()
{
SetAuditColumns();
return base.SaveChanges();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// make network id unique
modelBuilder.Entity<EFClient>(entity => { entity.HasIndex(e => e.NetworkId).IsUnique(); });
modelBuilder.Entity<EFPenalty>(entity =>
{
entity.HasOne(p => p.Offender)
.WithMany(c => c.ReceivedPenalties)
.HasForeignKey(c => c.OffenderId)
.OnDelete(DeleteBehavior.Restrict);
entity.HasOne(p => p.Punisher)
.WithMany(p => p.AdministeredPenalties)
.HasForeignKey(c => c.PunisherId)
.OnDelete(DeleteBehavior.Restrict);
entity.Property(p => p.Expires)
.IsRequired(false);
});
modelBuilder.Entity<EFAliasLink>(entity =>
{
entity.HasMany(e => e.Children)
.WithOne(a => a.Link)
.HasForeignKey(k => k.LinkId)
.OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity<EFAlias>(ent =>
{
ent.Property(a => a.IPAddress).IsRequired(false);
ent.HasIndex(a => a.IPAddress);
ent.Property(a => a.Name).HasMaxLength(24);
ent.HasIndex(a => a.Name);
ent.Property(_alias => _alias.SearchableName).HasMaxLength(24);
ent.HasIndex(_alias => _alias.SearchableName);
ent.HasIndex(_alias => new {_alias.Name, _alias.IPAddress}).IsUnique();
});
modelBuilder.Entity<EFMeta>(ent =>
{
ent.HasIndex(_meta => _meta.Key);
ent.HasIndex(_meta => _meta.LinkedMetaId);
ent.HasOne(_meta => _meta.LinkedMeta)
.WithMany()
.OnDelete(DeleteBehavior.SetNull);
});
// 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");
Models.Configuration.StatsModelConfiguration.Configure(modelBuilder);
base.OnModelCreating(modelBuilder);
}
}
}

83
Data/Data.csproj Normal file
View File

@ -0,0 +1,83 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;Prerelease</Configurations>
<Platforms>AnyCPU</Platforms>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>RaidMax.IW4MAdmin.Data</PackageId>
<Title>RaidMax.IW4MAdmin.Data</Title>
<Authors />
<PackageVersion>1.0.1</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">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql" Version="4.1.7" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.10" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.10" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
namespace Data.Extensions
{
public static class MigrationExtensions
{
public static bool IsMigration => Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Migration";
}
}

View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Data.Abstractions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Data.Helpers
{
public class DataValueCache<T, V> : IDataValueCache<T, V> where T : class
{
private readonly ILogger _logger;
private readonly IDatabaseContextFactory _contextFactory;
private readonly Dictionary<string, CacheState> _cacheStates = new Dictionary<string, CacheState>();
private const int DefaultExpireMinutes = 15;
private class CacheState
{
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 V Value { get; set; }
public bool IsExpired => (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)
{
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)
{
if (!_cacheStates.ContainsKey(keyName))
{
throw new ArgumentException("No cache found for key {key}", keyName);
}
var state = _cacheStates[keyName];
if (state.IsExpired)
{
await RunCacheUpdate(state);
}
return state.Value;
}
private async Task RunCacheUpdate(CacheState state)
{
try
{
await using var context = _contextFactory.CreateContext(false);
var set = context.Set<T>();
var value = await state.Getter(set);
state.Value = value;
state.LastRetrieval = DateTime.Now;
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not get cached value for {key}", state.Key);
}
}
}
}

114
Data/Helpers/LookupCache.cs Normal file
View File

@ -0,0 +1,114 @@
using Data.Abstractions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace Data.Helpers
{
public class LookupCache<T> : ILookupCache<T> where T : class, IUniqueId
{
private readonly ILogger _logger;
private readonly IDatabaseContextFactory _contextFactory;
private Dictionary<long, T> _cachedItems;
private readonly SemaphoreSlim _onOperation = new SemaphoreSlim(1, 1);
public LookupCache(ILogger<LookupCache<T>> logger, IDatabaseContextFactory contextFactory)
{
_logger = logger;
_contextFactory = contextFactory;
}
public async Task<T> AddAsync(T item)
{
await _onOperation.WaitAsync();
T existingItem = null;
if (_cachedItems.ContainsKey(item.Id))
{
existingItem = _cachedItems[item.Id];
}
if (existingItem != null)
{
_logger.LogDebug("Cached item already added for {type} {id} {value}", typeof(T).Name, item.Id,
item.Value);
_onOperation.Release();
return existingItem;
}
try
{
_logger.LogDebug("Adding new {type} with {id} {value}", typeof(T).Name, item.Id, item.Value);
await using var context = _contextFactory.CreateContext();
context.Set<T>().Add(item);
await context.SaveChangesAsync();
_cachedItems.Add(item.Id, item);
return item;
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not add item to cache for {type}", typeof(T).Name);
throw new Exception("Could not add item to cache");
}
finally
{
if (_onOperation.CurrentCount == 0)
{
_onOperation.Release();
}
}
}
public async Task<T> FirstAsync(Func<T, bool> query)
{
await _onOperation.WaitAsync();
try
{
var cachedResult = _cachedItems.Values.Where(query);
if (cachedResult.Any())
{
return cachedResult.FirstOrDefault();
}
}
catch
{
}
finally
{
if (_onOperation.CurrentCount == 0)
{
_onOperation.Release(1);
}
}
return null;
}
public IEnumerable<T> GetAll()
{
return _cachedItems.Values;
}
public async Task InitializeAsync()
{
try
{
await using var context = _contextFactory.CreateContext();
_cachedItems = await context.Set<T>().ToDictionaryAsync(item => item.Id);
}
catch (Exception ex)
{
_logger.LogError(ex, "Could not initialize caching for {cacheType}", typeof(T).Name);
}
}
}
}

View File

@ -1,13 +1,15 @@
using System; using System;
using Data.Context;
using Data.Extensions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace SharedLibraryCore.Database.MigrationContext namespace Data.MigrationContext
{ {
public class MySqlDatabaseContext : DatabaseContext public class MySqlDatabaseContext : DatabaseContext
{ {
public MySqlDatabaseContext() public MySqlDatabaseContext()
{ {
if (!Utilities.IsMigration) if (!MigrationExtensions.IsMigration)
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
@ -20,7 +22,7 @@ namespace SharedLibraryCore.Database.MigrationContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
if (Utilities.IsMigration) if (MigrationExtensions.IsMigration)
{ {
optionsBuilder.UseMySql("Server=127.0.0.1;Database=IW4MAdmin_Migration;Uid=root;Pwd=password;") optionsBuilder.UseMySql("Server=127.0.0.1;Database=IW4MAdmin_Migration;Uid=root;Pwd=password;")
.EnableDetailedErrors(true) .EnableDetailedErrors(true)

View File

@ -1,13 +1,15 @@
using System; using System;
using Data.Context;
using Data.Extensions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace SharedLibraryCore.Database.MigrationContext namespace Data.MigrationContext
{ {
public class PostgresqlDatabaseContext : DatabaseContext public class PostgresqlDatabaseContext : DatabaseContext
{ {
public PostgresqlDatabaseContext() public PostgresqlDatabaseContext()
{ {
if (!Utilities.IsMigration) if (!MigrationExtensions.IsMigration)
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
@ -15,19 +17,18 @@ namespace SharedLibraryCore.Database.MigrationContext
public PostgresqlDatabaseContext(DbContextOptions options) : base(options) public PostgresqlDatabaseContext(DbContextOptions options) : base(options)
{ {
} }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
if (Utilities.IsMigration) if (MigrationExtensions.IsMigration)
{ {
optionsBuilder.UseNpgsql( optionsBuilder.UseNpgsql(
"Host=127.0.0.1;Database=IW4MAdmin_Migration;Username=postgres;Password=password;") "Host=127.0.0.1;Database=IW4MAdmin_Migration;Username=postgres;Password=password;",
options => options.SetPostgresVersion(new Version("9.4")))
.EnableDetailedErrors(true) .EnableDetailedErrors(true)
.EnableSensitiveDataLogging(true); .EnableSensitiveDataLogging(true);
} }
} }
} }
} }

View File

@ -1,13 +1,15 @@
using System; using System;
using Data.Context;
using Data.Extensions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace SharedLibraryCore.Database.MigrationContext namespace Data.MigrationContext
{ {
public class SqliteDatabaseContext : DatabaseContext public class SqliteDatabaseContext : DatabaseContext
{ {
public SqliteDatabaseContext() public SqliteDatabaseContext()
{ {
if (!Utilities.IsMigration) if (!MigrationExtensions.IsMigration)
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
@ -20,7 +22,7 @@ namespace SharedLibraryCore.Database.MigrationContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
if (Utilities.IsMigration) if (MigrationExtensions.IsMigration)
{ {
optionsBuilder.UseSqlite("Data Source=IW4MAdmin_Migration.db") optionsBuilder.UseSqlite("Data Source=IW4MAdmin_Migration.db")
.EnableDetailedErrors(true) .EnableDetailedErrors(true)

View File

@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database; using Data;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
using System; using System;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180409183408_InitialCreate")] [Migration("20180409183408_InitialCreate")]

View File

@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class InitialCreate : Migration public partial class InitialCreate : Migration
{ {

View File

@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database; using Data;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
using System; using System;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180502195450_Update")] [Migration("20180502195450_Update")]

View File

@ -2,7 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class Update : Migration public partial class Update : Migration
{ {

View File

@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database; using Data;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
using System; using System;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180516023249_AddEloField")] [Migration("20180516023249_AddEloField")]

View File

@ -2,7 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddEloField : Migration public partial class AddEloField : Migration
{ {

View File

@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database; using Data;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
using System; using System;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180517223349_AddRollingKDR")] [Migration("20180517223349_AddRollingKDR")]

View File

@ -2,7 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddRollingKDR : Migration public partial class AddRollingKDR : Migration
{ {

View File

@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
using System; using System;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180531212903_AddAutomatedOffenseAndRatingHistory")] [Migration("20180531212903_AddAutomatedOffenseAndRatingHistory")]

View File

@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddAutomatedOffenseAndRatingHistory : Migration public partial class AddAutomatedOffenseAndRatingHistory : Migration
{ {

View File

@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
using System; using System;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180601172317_AddActivityAmount")] [Migration("20180601172317_AddActivityAmount")]

View File

@ -2,7 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddActivityAmount : Migration public partial class AddActivityAmount : Migration
{ {

View File

@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
using System; using System;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180602041758_AddClientMeta")] [Migration("20180602041758_AddClientMeta")]

View File

@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddClientMeta : Migration public partial class AddClientMeta : Migration
{ {

View File

@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
using System; using System;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180605191706_AddEFACSnapshots")] [Migration("20180605191706_AddEFACSnapshots")]

View File

@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddEFACSnapshots : Migration public partial class AddEFACSnapshots : Migration
{ {

View File

@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage.Internal;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
using System; using System;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180614014303_IndexForEFAlias")] [Migration("20180614014303_IndexForEFAlias")]

View File

@ -2,7 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class IndexForEFAlias : Migration public partial class IndexForEFAlias : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180902035612_AddFractionAndIsKill")] [Migration("20180902035612_AddFractionAndIsKill")]

View File

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddFractionAndIsKill : Migration public partial class AddFractionAndIsKill : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180904154622_AddVisibilityPercentage")] [Migration("20180904154622_AddVisibilityPercentage")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddVisibilityPercentage : Migration public partial class AddVisibilityPercentage : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180907020706_AddVision")] [Migration("20180907020706_AddVision")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddVision : Migration public partial class AddVision : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180908004053_AddWhenToRating")] [Migration("20180908004053_AddWhenToRating")]

View File

@ -1,7 +1,7 @@
using System; using System;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddWhenToRating : Migration public partial class AddWhenToRating : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180910221749_AddRatingIndexes")] [Migration("20180910221749_AddRatingIndexes")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddRatingIndexes : Migration public partial class AddRatingIndexes : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180911184224_AddEFAliasNameIndex")] [Migration("20180911184224_AddEFAliasNameIndex")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddEFAliasNameIndex : Migration public partial class AddEFAliasNameIndex : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180911190823_AddEFAliasNameMaxLength24")] [Migration("20180911190823_AddEFAliasNameMaxLength24")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddEFAliasNameMaxLength24 : Migration public partial class AddEFAliasNameMaxLength24 : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180912015012_AddPreviousCurrentValueToEFChangeHistory")] [Migration("20180912015012_AddPreviousCurrentValueToEFChangeHistory")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddPreviousCurrentValueToEFChangeHistory : Migration public partial class AddPreviousCurrentValueToEFChangeHistory : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180915163111_AddIndexToMessageTimeSent")] [Migration("20180915163111_AddIndexToMessageTimeSent")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddIndexToMessageTimeSent : Migration public partial class AddIndexToMessageTimeSent : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180922231310_RemoveACSnapShot")] [Migration("20180922231310_RemoveACSnapShot")]

View File

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class RemoveACSnapShot : Migration public partial class RemoveACSnapShot : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20180922231600_ReaddACSnapshot")] [Migration("20180922231600_ReaddACSnapshot")]

View File

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class ReaddACSnapshot : Migration public partial class ReaddACSnapshot : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20181014171848_MakePenaltyExpirationNullable")] [Migration("20181014171848_MakePenaltyExpirationNullable")]

View File

@ -1,7 +1,7 @@
using System; using System;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class MakePenaltyExpirationNullable : Migration public partial class MakePenaltyExpirationNullable : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20181125193243_MakeClientIPNullable")] [Migration("20181125193243_MakeClientIPNullable")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class MakeClientIPNullable : Migration public partial class MakeClientIPNullable : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20181127144417_AddEndpointToEFServerUpdateServerIdType")] [Migration("20181127144417_AddEndpointToEFServerUpdateServerIdType")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddEndpointToEFServerUpdateServerIdType : Migration public partial class AddEndpointToEFServerUpdateServerIdType : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20181216214513_AddEvadePenaltyFlag")] [Migration("20181216214513_AddEvadePenaltyFlag")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddEvadePenaltyFlag : Migration public partial class AddEvadePenaltyFlag : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190222234742_AddIndexToEFMeta-KeyAndClientId")] [Migration("20190222234742_AddIndexToEFMeta-KeyAndClientId")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddIndexToEFMetaKeyAndClientId : Migration public partial class AddIndexToEFMetaKeyAndClientId : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190423142128_AddGameNameToEFServer")] [Migration("20190423142128_AddGameNameToEFServer")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddGameNameToEFServer : Migration public partial class AddGameNameToEFServer : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190615145212_AddAvgRecoilOffset")] [Migration("20190615145212_AddAvgRecoilOffset")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddAvgRecoilOffset : Migration public partial class AddAvgRecoilOffset : Migration
{ {

View File

@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SharedLibraryCore.Database.MigrationContext; using Data.MigrationContext;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
[DbContext(typeof(MySqlDatabaseContext))] [DbContext(typeof(MySqlDatabaseContext))]
[Migration("20190615214055_AddRecoilOffsetToSnapshot")] [Migration("20190615214055_AddRecoilOffsetToSnapshot")]

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace SharedLibraryCore.Migrations.MySql namespace Data.Migrations.MySql
{ {
public partial class AddRecoilOffsetToSnapshot : Migration public partial class AddRecoilOffsetToSnapshot : Migration
{ {

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