Compare commits
47 Commits
2020.12.02
...
2021.06.03
Author | SHA1 | Date | |
---|---|---|---|
eff1fe237d | |||
b09ce46ff9 | |||
be08d49f0a | |||
b9fb274db6 | |||
9488f754d4 | |||
1595c1fa99 | |||
4d21680d59 | |||
127af98b00 | |||
21a9eb8716 | |||
f1593e2f99 | |||
74dbc3572f | |||
e6d149736a | |||
a034394610 | |||
34e7d69110 | |||
4b686e5fdd | |||
0428453426 | |||
e80e5d6a70 | |||
22cf3081e1 | |||
76a18d9797 | |||
fc13363c9c | |||
f916c51bc0 | |||
21087d6c25 | |||
c84e374274 | |||
e777a68105 | |||
1f9c80e23b | |||
33371a6d28 | |||
d164ef2eab | |||
e2ed57f674 | |||
824b1c0990 | |||
a8b331a5e5 | |||
802ec8cea5 | |||
2313c4357b | |||
c5375b661b | |||
db2e1deb2f | |||
191a68e7dd | |||
c4f19e94ef | |||
c419d80b57 | |||
23a33ba489 | |||
dd3ebf6b34 | |||
28373b9325 | |||
843c01061d | |||
5cb2d05f33 | |||
5a288dafc1 | |||
4afc478076 | |||
928cbef845 | |||
02b910234a | |||
f03626c3ae |
@ -25,13 +25,13 @@
|
||||
|
||||
<ItemGroup>
|
||||
<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>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.7" />
|
||||
<PackageReference Include="RestEase" Version="1.5.0" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.10" />
|
||||
<PackageReference Include="RestEase" Version="1.5.1" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
@ -39,7 +39,6 @@
|
||||
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
|
||||
<TieredCompilation>true</TieredCompilation>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<StartupObject></StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Prerelease|AnyCPU'">
|
||||
@ -49,6 +48,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Integrations\Cod\Integrations.Cod.csproj" />
|
||||
<ProjectReference Include="..\Integrations\Source\Integrations.Source.csproj" />
|
||||
<ProjectReference Include="..\SharedLibraryCore\SharedLibraryCore.csproj">
|
||||
<Private>true</Private>
|
||||
</ProjectReference>
|
||||
@ -60,7 +61,7 @@
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Configuration\LoggingConfiguration.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
using IW4MAdmin.Application.EventParsers;
|
||||
using IW4MAdmin.Application.Extensions;
|
||||
using IW4MAdmin.Application.Misc;
|
||||
using IW4MAdmin.Application.RconParsers;
|
||||
using IW4MAdmin.Application.RConParsers;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Commands;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Configuration.Validation;
|
||||
using SharedLibraryCore.Database;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Exceptions;
|
||||
using SharedLibraryCore.Helpers;
|
||||
@ -21,6 +20,8 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Abstractions;
|
||||
using Data.Context;
|
||||
using IW4MAdmin.Application.Migration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -72,6 +73,7 @@ namespace IW4MAdmin.Application
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ChangeHistoryService _changeHistoryService;
|
||||
private readonly ApplicationConfiguration _appConfig;
|
||||
public ConcurrentDictionary<long, GameEvent> ProcessingEvents { get; } = new ConcurrentDictionary<long, GameEvent>();
|
||||
|
||||
public ApplicationManager(ILogger<ApplicationManager> logger, IMiddlewareActionHandler actionHandler, IEnumerable<IManagerCommand> commands,
|
||||
ITranslationLookup translationLookup, IConfigurationHandler<CommandConfiguration> commandConfiguration,
|
||||
@ -115,6 +117,8 @@ namespace IW4MAdmin.Application
|
||||
|
||||
public async Task ExecuteEvent(GameEvent newEvent)
|
||||
{
|
||||
ProcessingEvents.TryAdd(newEvent.Id, newEvent);
|
||||
|
||||
// the event has failed already
|
||||
if (newEvent.Failed)
|
||||
{
|
||||
@ -175,6 +179,29 @@ namespace IW4MAdmin.Application
|
||||
}
|
||||
|
||||
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
|
||||
newEvent.Complete();
|
||||
OnGameEventExecuted?.Invoke(this, newEvent);
|
||||
@ -193,15 +220,15 @@ namespace IW4MAdmin.Application
|
||||
public async Task UpdateServerStates()
|
||||
{
|
||||
// store the server hash code and task for it
|
||||
var runningUpdateTasks = new Dictionary<long, Task>();
|
||||
var runningUpdateTasks = new Dictionary<long, (Task task, CancellationTokenSource tokenSource, DateTime startTime)>();
|
||||
|
||||
while (!_tokenSource.IsCancellationRequested)
|
||||
{
|
||||
// select the server ids that have completed the update task
|
||||
var serverTasksToRemove = runningUpdateTasks
|
||||
.Where(ut => ut.Value.Status == TaskStatus.RanToCompletion ||
|
||||
ut.Value.Status == TaskStatus.Canceled ||
|
||||
ut.Value.Status == TaskStatus.Faulted)
|
||||
.Where(ut => ut.Value.task.Status == TaskStatus.RanToCompletion ||
|
||||
ut.Value.task.Status == TaskStatus.Canceled || // we want to cancel if a task takes longer than 5 minutes
|
||||
ut.Value.task.Status == TaskStatus.Faulted || DateTime.Now - ut.Value.startTime > TimeSpan.FromMinutes(5))
|
||||
.Select(ut => ut.Key)
|
||||
.ToList();
|
||||
|
||||
@ -212,9 +239,14 @@ namespace IW4MAdmin.Application
|
||||
IsInitialized = true;
|
||||
}
|
||||
|
||||
// remove the update tasks as they have completd
|
||||
foreach (long serverId in serverTasksToRemove)
|
||||
// remove the update tasks as they have completed
|
||||
foreach (var serverId in serverTasksToRemove)
|
||||
{
|
||||
if (!runningUpdateTasks[serverId].tokenSource.Token.IsCancellationRequested)
|
||||
{
|
||||
runningUpdateTasks[serverId].tokenSource.Cancel();
|
||||
}
|
||||
|
||||
runningUpdateTasks.Remove(serverId);
|
||||
}
|
||||
|
||||
@ -222,11 +254,12 @@ namespace IW4MAdmin.Application
|
||||
var serverIds = Servers.Select(s => s.EndPoint).Except(runningUpdateTasks.Select(r => r.Key)).ToList();
|
||||
foreach (var server in Servers.Where(s => serverIds.Contains(s.EndPoint)))
|
||||
{
|
||||
runningUpdateTasks.Add(server.EndPoint, Task.Run(async () =>
|
||||
var tokenSource = new CancellationTokenSource();
|
||||
runningUpdateTasks.Add(server.EndPoint, (Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await server.ProcessUpdatesAsync(_tokenSource.Token);
|
||||
await server.ProcessUpdatesAsync(_tokenSource.Token).WithWaitCancellation(runningUpdateTasks[server.EndPoint].tokenSource.Token);
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
@ -241,7 +274,7 @@ namespace IW4MAdmin.Application
|
||||
{
|
||||
server.IsInitialized = true;
|
||||
}
|
||||
}));
|
||||
}, tokenSource.Token), tokenSource, DateTime.Now));
|
||||
}
|
||||
|
||||
try
|
||||
@ -265,6 +298,15 @@ namespace IW4MAdmin.Application
|
||||
IsRunning = true;
|
||||
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
|
||||
foreach (var plugin in Plugins)
|
||||
{
|
||||
@ -305,7 +347,7 @@ namespace IW4MAdmin.Application
|
||||
// copy over default config if it doesn't exist
|
||||
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());
|
||||
//var newConfig = ConfigHandler.Configuration();
|
||||
|
||||
@ -398,15 +440,6 @@ namespace IW4MAdmin.Application
|
||||
|
||||
#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
|
||||
if (await ClientSvc.HasOwnerAsync(_tokenSource.Token))
|
||||
{
|
||||
@ -491,7 +524,7 @@ namespace IW4MAdmin.Application
|
||||
// add the start event for this server
|
||||
var e = new GameEvent()
|
||||
{
|
||||
Type = GameEvent.EventType.Start,
|
||||
Type = EventType.Start,
|
||||
Data = $"{ServerInstance.GameName} started",
|
||||
Owner = ServerInstance
|
||||
};
|
||||
|
15
Application/Configuration/ScriptPluginConfiguration.cs
Normal file
15
Application/Configuration/ScriptPluginConfiguration.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
{
|
||||
"AutoMessagePeriod": 60,
|
||||
"AutoMessages": [
|
||||
"This server uses ^5IW4M Admin v{{VERSION}} ^7get it at ^5raidmax.org/IW4MAdmin",
|
||||
@ -16,7 +16,13 @@
|
||||
"Keep grenade launcher use to a minimum",
|
||||
"Balance teams at ALL times"
|
||||
],
|
||||
"DisallowedClientNames": [ "Unknown Soldier", "VickNet", "UnknownSoldier", "CHEATER", "Play77" ],
|
||||
"DisallowedClientNames": [
|
||||
"Unknown Soldier",
|
||||
"VickNet",
|
||||
"UnknownSoldier",
|
||||
"CHEATER",
|
||||
"Play77"
|
||||
],
|
||||
"QuickMessages": [
|
||||
{
|
||||
"Game": "IW4",
|
||||
@ -163,6 +169,18 @@
|
||||
"Alias": "Asylum",
|
||||
"Name": "mp_asylum"
|
||||
},
|
||||
{
|
||||
"Alias": "Banzai",
|
||||
"Name": "mp_kwai"
|
||||
},
|
||||
{
|
||||
"Alias": "Battery",
|
||||
"Name": "mp_drum"
|
||||
},
|
||||
{
|
||||
"Alias": "Breach",
|
||||
"Name": "mp_bgate"
|
||||
},
|
||||
{
|
||||
"Alias": "Castle",
|
||||
"Name": "mp_castle"
|
||||
@ -171,6 +189,10 @@
|
||||
"Alias": "Cliffside",
|
||||
"Name": "mp_shrine"
|
||||
},
|
||||
{
|
||||
"Alias": "Corrosion",
|
||||
"Name": "mp_stalingrad"
|
||||
},
|
||||
{
|
||||
"Alias": "Courtyard",
|
||||
"Name": "mp_courtyard"
|
||||
@ -184,60 +206,52 @@
|
||||
"Name": "mp_downfall"
|
||||
},
|
||||
{
|
||||
"Alias": "Hanger",
|
||||
"Alias": "Hangar",
|
||||
"Name": "mp_hangar"
|
||||
},
|
||||
{
|
||||
"Alias": "Makin",
|
||||
"Name": "mp_makin"
|
||||
},
|
||||
{
|
||||
"Alias": "Outskirts",
|
||||
"Name": "mp_outskirts"
|
||||
},
|
||||
{
|
||||
"Alias": "Roundhouse",
|
||||
"Name": "mp_roundhouse"
|
||||
},
|
||||
{
|
||||
"Alias": "Upheaval",
|
||||
"Name": "mp_suburban"
|
||||
},
|
||||
{
|
||||
"Alias": "Knee Deep",
|
||||
"Name": "mp_kneedeep"
|
||||
},
|
||||
{
|
||||
"Alias": "Makin",
|
||||
"Name": "mp_makin"
|
||||
},
|
||||
{
|
||||
"Alias": "Makin Day",
|
||||
"Name": "mp_makin_day"
|
||||
},
|
||||
{
|
||||
"Alias": "Nightfire",
|
||||
"Name": "mp_nachtfeuer"
|
||||
},
|
||||
{
|
||||
"Alias": "Outskirts",
|
||||
"Name": "mp_outskirts"
|
||||
},
|
||||
{
|
||||
"Alias": "Revolution",
|
||||
"Name": "mp_vodka"
|
||||
},
|
||||
{
|
||||
"Alias": "Roundhouse",
|
||||
"Name": "mp_roundhouse"
|
||||
},
|
||||
{
|
||||
"Alias": "Seelow",
|
||||
"Name": "mp_seelow"
|
||||
},
|
||||
{
|
||||
"Alias": "Station",
|
||||
"Name": "mp_subway"
|
||||
},
|
||||
{
|
||||
"Alias": "Banzai",
|
||||
"Name": "mp_kwai"
|
||||
},
|
||||
{
|
||||
"Alias": "Corrosion",
|
||||
"Name": "mp_stalingrad"
|
||||
},
|
||||
{
|
||||
"Alias": "Sub Pens",
|
||||
"Name": "mp_docks"
|
||||
},
|
||||
{
|
||||
"Alias": "Battery",
|
||||
"Name": "mp_drum"
|
||||
},
|
||||
{
|
||||
"Alias": "Breach",
|
||||
"Name": "mp_bgate"
|
||||
},
|
||||
{
|
||||
"Alias": "Revolution",
|
||||
"Name": "mp_vodka"
|
||||
"Alias": "Upheaval",
|
||||
"Name": "mp_suburban"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -248,222 +262,178 @@
|
||||
"Alias": "Rust",
|
||||
"Name": "mp_rust"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Terminal",
|
||||
"Name": "mp_terminal"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Crash",
|
||||
"Name": "mp_crash"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Afghan",
|
||||
"Name": "mp_afghan"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Derail",
|
||||
"Name": "mp_derail"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Estate",
|
||||
"Name": "mp_estate"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Favela",
|
||||
"Name": "mp_favela"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Highrise",
|
||||
"Name": "mp_highrise"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Invasion",
|
||||
"Name": "mp_invasion"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Karachi",
|
||||
"Name": "mp_checkpoint"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Quarry",
|
||||
"Name": "mp_quarry"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Rundown",
|
||||
"Name": "mp_rundown"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Scrapyard",
|
||||
"Name": "mp_boneyard"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Skidrow",
|
||||
"Name": "mp_nightshift"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Sub Base",
|
||||
"Name": "mp_subbase"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Underpass",
|
||||
"Name": "mp_underpass"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Wasteland",
|
||||
"Name": "mp_brecourt"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Overgrown",
|
||||
"Name": "mp_overgrown"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Strike",
|
||||
"Name": "mp_strike"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Vacant",
|
||||
"Name": "mp_vacant"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Carnival",
|
||||
"Name": "mp_abandon"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Trailer Park",
|
||||
"Name": "mp_trailerpark"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Fuel",
|
||||
"Name": "mp_fuel2"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Storm",
|
||||
"Name": "mp_storm"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Bailout",
|
||||
"Name": "mp_complex"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Salvage",
|
||||
"Name": "mp_compact"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Nuketown",
|
||||
"Name": "mp_nuked"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Test map",
|
||||
"Name": "iw4_credits"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Killhouse",
|
||||
"Name": "mp_killhouse"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Bog",
|
||||
"Name": "mp_bog_sh"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Freighter",
|
||||
"Name": "mp_cargoship_sh"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Cargoship",
|
||||
"Name": "mp_cargoship"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Shipment",
|
||||
"Name": "mp_shipment"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Shipment - Long",
|
||||
"Name": "mp_shipment_long"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Rust - Long",
|
||||
"Name": "mp_rust_long"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Firing Range",
|
||||
"Name": "mp_firingrange"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Chemical Plant",
|
||||
"Name": "mp_storm_spring"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Tropical Favela",
|
||||
"Name": "mp_fav_tropical"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Tropical Estate",
|
||||
"Name": "mp_estate_tropical"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Tropical Crash",
|
||||
"Name": "mp_crash_tropical"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Forgotten City",
|
||||
"Name": "mp_bloc_sh"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Crossfire",
|
||||
"Name": "mp_cross_fire"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Bloc",
|
||||
"Name": "mp_bloc"
|
||||
},
|
||||
|
||||
{
|
||||
"Alias": "Oilrig",
|
||||
"Name": "oilrig"
|
||||
},
|
||||
|
||||
{
|
||||
"Name": "Village",
|
||||
"Alias": "co_hunted"
|
||||
@ -519,7 +489,7 @@
|
||||
},
|
||||
{
|
||||
"Alias": "Havana",
|
||||
"Name": "mp_cairo"
|
||||
"Name": "mp_cairo"
|
||||
},
|
||||
{
|
||||
"Alias": "Hazard",
|
||||
@ -725,6 +695,10 @@
|
||||
{
|
||||
"Alias": "Terminal",
|
||||
"Name": "mp_terminal_cls"
|
||||
},
|
||||
{
|
||||
"Alias": "Rust",
|
||||
"Name": "mp_rust"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -884,6 +858,451 @@
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Data.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static SharedLibraryCore.Server;
|
||||
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 ILogger _logger;
|
||||
private readonly ApplicationConfiguration _appConfig;
|
||||
private readonly Dictionary<ParserRegex, GameEvent.EventType> _regexMap;
|
||||
private readonly Dictionary<string, GameEvent.EventType> _eventTypeMap;
|
||||
|
||||
public BaseEventParser(IParserRegexFactory parserRegexFactory, ILogger logger, ApplicationConfiguration appConfig)
|
||||
{
|
||||
@ -77,7 +80,28 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
Configuration.Kill.AddMapping(ParserRegex.GroupType.MeansOfDeath, 12);
|
||||
Configuration.Kill.AddMapping(ParserRegex.GroupType.HitLocation, 13);
|
||||
|
||||
Configuration.MapChange.Pattern = @".*InitGame.*";
|
||||
Configuration.MapEnd.Pattern = @".*(?:ExitLevel|ShutdownGame).*";
|
||||
|
||||
Configuration.Time.Pattern = @"^ *(([0-9]+):([0-9]+) |^[0-9]+ )";
|
||||
|
||||
_regexMap = new Dictionary<ParserRegex, GameEvent.EventType>
|
||||
{
|
||||
{Configuration.Say, GameEvent.EventType.Say},
|
||||
{Configuration.Kill, GameEvent.EventType.Kill},
|
||||
{Configuration.MapChange, GameEvent.EventType.MapChange},
|
||||
{Configuration.MapEnd, GameEvent.EventType.MapEnd}
|
||||
};
|
||||
|
||||
_eventTypeMap = new Dictionary<string, GameEvent.EventType>
|
||||
{
|
||||
{"say", GameEvent.EventType.Say},
|
||||
{"sayteam", GameEvent.EventType.Say},
|
||||
{"K", GameEvent.EventType.Kill},
|
||||
{"D", GameEvent.EventType.Damage},
|
||||
{"J", GameEvent.EventType.PreConnect},
|
||||
{"Q", GameEvent.EventType.PreDisconnect},
|
||||
};
|
||||
}
|
||||
|
||||
public IEventParserConfiguration Configuration { get; set; }
|
||||
@ -90,47 +114,79 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
|
||||
public string Name { get; set; } = "Call of Duty";
|
||||
|
||||
private (GameEvent.EventType type, string eventKey) GetEventTypeFromLine(string logLine)
|
||||
{
|
||||
var lineSplit = logLine.Split(';');
|
||||
if (lineSplit.Length > 1)
|
||||
{
|
||||
var type = lineSplit[0];
|
||||
return _eventTypeMap.ContainsKey(type) ? (_eventTypeMap[type], type): (GameEvent.EventType.Unknown, 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)
|
||||
{
|
||||
var timeMatch = Configuration.Time.PatternMatcher.Match(logLine);
|
||||
int gameTime = 0;
|
||||
var gameTime = 0L;
|
||||
|
||||
if (timeMatch.Success)
|
||||
{
|
||||
gameTime = timeMatch
|
||||
.Values
|
||||
.Skip(2)
|
||||
// this converts the timestamp into seconds passed
|
||||
.Select((_value, index) => int.Parse(_value.ToString()) * (index == 0 ? 60 : 1))
|
||||
.Sum();
|
||||
if (timeMatch.Values[0].Contains(":"))
|
||||
{
|
||||
gameTime = timeMatch
|
||||
.Values
|
||||
.Skip(2)
|
||||
// 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
|
||||
logLine = logLine.Substring(timeMatch.Values.First().Length);
|
||||
logLine = logLine.Substring(timeMatch.Values.First().Length).Trim();
|
||||
}
|
||||
|
||||
string[] lineSplit = logLine.Split(';');
|
||||
string eventType = lineSplit[0];
|
||||
var eventParseResult = GetEventTypeFromLine(logLine);
|
||||
var eventType = eventParseResult.type;
|
||||
|
||||
if (eventType == "say" || eventType == "sayteam")
|
||||
_logger.LogDebug(logLine);
|
||||
|
||||
if (eventType == GameEvent.EventType.Say)
|
||||
{
|
||||
var matchResult = Configuration.Say.PatternMatcher.Match(logLine);
|
||||
|
||||
if (matchResult.Success)
|
||||
{
|
||||
string message = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.Message]]
|
||||
.ToString()
|
||||
var message = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.Message]]
|
||||
.Replace("\x15", "")
|
||||
.Trim();
|
||||
|
||||
if (message.Length > 0)
|
||||
{
|
||||
string originIdString = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
|
||||
string originName = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
|
||||
var originIdString = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
|
||||
var originName = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginName]];
|
||||
|
||||
long originId = originIdString.IsBotGuid() ?
|
||||
var originId = originIdString.IsBotGuid() ?
|
||||
originName.GenerateGuidFromString() :
|
||||
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
|
||||
|
||||
int clientNumber = int.Parse(matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
|
||||
var clientNumber = int.Parse(matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
|
||||
|
||||
if (message.StartsWith(_appConfig.CommandPrefix) || message.StartsWith(_appConfig.BroadcastCommandPrefix))
|
||||
{
|
||||
@ -162,26 +218,26 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
}
|
||||
}
|
||||
|
||||
if (eventType == "K")
|
||||
if (eventType == GameEvent.EventType.Kill)
|
||||
{
|
||||
var match = Configuration.Kill.PatternMatcher.Match(logLine);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
string originIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
|
||||
string targetIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString();
|
||||
string originName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
|
||||
string targetName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetName]].ToString();
|
||||
var originIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
|
||||
var targetIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]];
|
||||
var originName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginName]];
|
||||
var targetName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetName]];
|
||||
|
||||
long originId = originIdString.IsBotGuid() ?
|
||||
var originId = originIdString.IsBotGuid() ?
|
||||
originName.GenerateGuidFromString() :
|
||||
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
|
||||
long targetId = targetIdString.IsBotGuid() ?
|
||||
var targetId = targetIdString.IsBotGuid() ?
|
||||
targetName.GenerateGuidFromString() :
|
||||
targetIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
|
||||
|
||||
int originClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
|
||||
int targetClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
|
||||
var originClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
|
||||
var targetClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
|
||||
|
||||
return new GameEvent()
|
||||
{
|
||||
@ -196,26 +252,26 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
}
|
||||
}
|
||||
|
||||
if (eventType == "D")
|
||||
if (eventType == GameEvent.EventType.Damage)
|
||||
{
|
||||
var match = Configuration.Damage.PatternMatcher.Match(logLine);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
string originIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
|
||||
string targetIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString();
|
||||
string originName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
|
||||
string targetName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetName]].ToString();
|
||||
var originIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
|
||||
var targetIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]];
|
||||
var originName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginName]];
|
||||
var targetName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetName]];
|
||||
|
||||
long originId = originIdString.IsBotGuid() ?
|
||||
var originId = originIdString.IsBotGuid() ?
|
||||
originName.GenerateGuidFromString() :
|
||||
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
|
||||
long targetId = targetIdString.IsBotGuid() ?
|
||||
var targetId = targetIdString.IsBotGuid() ?
|
||||
targetName.GenerateGuidFromString() :
|
||||
targetIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
|
||||
|
||||
int originClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
|
||||
int targetClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
|
||||
var originClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
|
||||
var targetClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
|
||||
|
||||
return new GameEvent()
|
||||
{
|
||||
@ -230,16 +286,16 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
}
|
||||
}
|
||||
|
||||
if (eventType == "J")
|
||||
if (eventType == GameEvent.EventType.PreConnect)
|
||||
{
|
||||
var match = Configuration.Join.PatternMatcher.Match(logLine);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
string originIdString = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
|
||||
string originName = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
|
||||
var originIdString = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
|
||||
var originName = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]];
|
||||
|
||||
long networkId = originIdString.IsBotGuid() ?
|
||||
var networkId = originIdString.IsBotGuid() ?
|
||||
originName.GenerateGuidFromString() :
|
||||
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
|
||||
|
||||
@ -251,10 +307,10 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
{
|
||||
CurrentAlias = new EFAlias()
|
||||
{
|
||||
Name = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].ToString().TrimNewLine(),
|
||||
Name = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].TrimNewLine(),
|
||||
},
|
||||
NetworkId = networkId,
|
||||
ClientNumber = Convert.ToInt32(match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
|
||||
ClientNumber = Convert.ToInt32(match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]),
|
||||
State = EFClient.ClientState.Connecting,
|
||||
},
|
||||
Extra = originIdString,
|
||||
@ -266,16 +322,16 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
}
|
||||
}
|
||||
|
||||
if (eventType == "Q")
|
||||
if (eventType == GameEvent.EventType.PreDisconnect)
|
||||
{
|
||||
var match = Configuration.Quit.PatternMatcher.Match(logLine);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
string originIdString = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
|
||||
string originName = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
|
||||
var originIdString = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]];
|
||||
var originName = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]];
|
||||
|
||||
long networkId = originIdString.IsBotGuid() ?
|
||||
var networkId = originIdString.IsBotGuid() ?
|
||||
originName.GenerateGuidFromString() :
|
||||
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
|
||||
|
||||
@ -287,10 +343,10 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
{
|
||||
CurrentAlias = new EFAlias()
|
||||
{
|
||||
Name = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].ToString().TrimNewLine()
|
||||
Name = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].TrimNewLine()
|
||||
},
|
||||
NetworkId = networkId,
|
||||
ClientNumber = Convert.ToInt32(match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
|
||||
ClientNumber = Convert.ToInt32(match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]),
|
||||
State = EFClient.ClientState.Disconnecting
|
||||
},
|
||||
RequiredEntity = GameEvent.EventRequiredEntity.None,
|
||||
@ -301,7 +357,7 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
}
|
||||
}
|
||||
|
||||
if (eventType.Contains("ExitLevel"))
|
||||
if (eventType == GameEvent.EventType.MapEnd)
|
||||
{
|
||||
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()
|
||||
{
|
||||
@ -332,26 +388,37 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
};
|
||||
}
|
||||
|
||||
if (_customEventRegistrations.ContainsKey(eventType))
|
||||
if (eventParseResult.eventKey == null || !_customEventRegistrations.ContainsKey(eventParseResult.eventKey))
|
||||
{
|
||||
var eventModifier = _customEventRegistrations[eventType];
|
||||
|
||||
try
|
||||
return new GameEvent()
|
||||
{
|
||||
return eventModifier.Item2(logLine, Configuration, new GameEvent()
|
||||
{
|
||||
Type = GameEvent.EventType.Other,
|
||||
Data = logLine,
|
||||
Subtype = eventModifier.Item1,
|
||||
GameTime = gameTime,
|
||||
Source = GameEvent.EventSource.Log
|
||||
});
|
||||
}
|
||||
Type = GameEvent.EventType.Unknown,
|
||||
Data = logLine,
|
||||
Origin = Utilities.IW4MAdminClient(),
|
||||
Target = Utilities.IW4MAdminClient(),
|
||||
RequiredEntity = GameEvent.EventRequiredEntity.None,
|
||||
GameTime = gameTime,
|
||||
Source = GameEvent.EventSource.Log
|
||||
};
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
var eventModifier = _customEventRegistrations[eventParseResult.eventKey];
|
||||
|
||||
try
|
||||
{
|
||||
return eventModifier.Item2(logLine, Configuration, new GameEvent()
|
||||
{
|
||||
_logger.LogError(e, $"Could not handle custom event generation");
|
||||
}
|
||||
Type = GameEvent.EventType.Other,
|
||||
Data = logLine,
|
||||
Subtype = eventModifier.Item1,
|
||||
GameTime = gameTime,
|
||||
Source = GameEvent.EventSource.Log
|
||||
});
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Could not handle custom event generation");
|
||||
}
|
||||
|
||||
return new GameEvent()
|
||||
|
@ -1,5 +1,6 @@
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System.Globalization;
|
||||
using SharedLibraryCore;
|
||||
|
||||
namespace IW4MAdmin.Application.EventParsers
|
||||
{
|
||||
@ -17,6 +18,8 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
public ParserRegex Damage { get; set; }
|
||||
public ParserRegex Action { get; set; }
|
||||
public ParserRegex Time { get; set; }
|
||||
public ParserRegex MapChange { get; set; }
|
||||
public ParserRegex MapEnd { get; set; }
|
||||
public NumberStyles GuidNumberStyle { get; set; } = NumberStyles.HexNumber;
|
||||
|
||||
public DynamicEventParserConfiguration(IParserRegexFactory parserRegexFactory)
|
||||
@ -28,6 +31,8 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
Damage = parserRegexFactory.CreateParserRegex();
|
||||
Action = parserRegexFactory.CreateParserRegex();
|
||||
Time = parserRegexFactory.CreateParserRegex();
|
||||
MapChange = parserRegexFactory.CreateParserRegex();
|
||||
MapEnd = parserRegexFactory.CreateParserRegex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Data.MigrationContext;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -10,7 +11,6 @@ using Serilog;
|
||||
using Serilog.Events;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace IW4MAdmin.Application.Extensions
|
||||
@ -32,13 +32,12 @@ namespace IW4MAdmin.Application.Extensions
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning);
|
||||
|
||||
|
||||
if (Utilities.IsDevelopment)
|
||||
{
|
||||
loggerConfig = loggerConfig.WriteTo.Console(
|
||||
outputTemplate:
|
||||
"[{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();
|
||||
}
|
||||
|
||||
@ -67,10 +66,10 @@ namespace IW4MAdmin.Application.Extensions
|
||||
{DataSource = Path.Join(currentPath, "Database", "Database.db")};
|
||||
var connectionString = connectionStringBuilder.ToString();
|
||||
|
||||
var builder = new DbContextOptionsBuilder<SqliteDatabaseContext>()
|
||||
.UseSqlite(connectionString);
|
||||
|
||||
services.AddSingleton((DbContextOptions) builder.Options);
|
||||
services.AddSingleton(sp => (DbContextOptions) new DbContextOptionsBuilder<SqliteDatabaseContext>()
|
||||
.UseSqlite(connectionString)
|
||||
.UseLoggerFactory(sp.GetRequiredService<ILoggerFactory>())
|
||||
.EnableSensitiveDataLogging().Options);
|
||||
return services;
|
||||
}
|
||||
|
||||
@ -90,7 +89,11 @@ namespace IW4MAdmin.Application.Extensions
|
||||
services.AddSingleton(sp =>
|
||||
(DbContextOptions) new DbContextOptionsBuilder<PostgresqlDatabaseContext>()
|
||||
.UseNpgsql(appConfig.ConnectionString + (appendTimeout ? ";Command Timeout=0" : ""),
|
||||
postgresqlOptions => postgresqlOptions.EnableRetryOnFailure())
|
||||
postgresqlOptions =>
|
||||
{
|
||||
postgresqlOptions.EnableRetryOnFailure();
|
||||
postgresqlOptions.SetPostgresVersion(new Version("9.4"));
|
||||
})
|
||||
.UseLoggerFactory(sp.GetRequiredService<ILoggerFactory>()).Options);
|
||||
return services;
|
||||
default:
|
||||
|
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using Data.Abstractions;
|
||||
using Data.Context;
|
||||
using Data.MigrationContext;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Database;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
||||
namespace IW4MAdmin.Application.Factories
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Data.Abstractions;
|
||||
using Data.Models.Server;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Configuration;
|
||||
@ -37,7 +39,7 @@ namespace IW4MAdmin.Application.Factories
|
||||
/// <returns></returns>
|
||||
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>>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
using IW4MAdmin.Application.RCon;
|
||||
using System;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System.Text;
|
||||
using Integrations.Cod;
|
||||
using Integrations.Source;
|
||||
using Integrations.Source.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace IW4MAdmin.Application.Factories
|
||||
@ -10,16 +14,16 @@ namespace IW4MAdmin.Application.Factories
|
||||
/// </summary>
|
||||
internal class RConConnectionFactory : IRConConnectionFactory
|
||||
{
|
||||
private static readonly Encoding gameEncoding = Encoding.GetEncoding("windows-1252");
|
||||
private readonly ILogger<RConConnection> _logger;
|
||||
private static readonly Encoding GameEncoding = Encoding.GetEncoding("windows-1252");
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Base constructor
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
public RConConnectionFactory(ILogger<RConConnection> logger)
|
||||
public RConConnectionFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -29,9 +33,16 @@ namespace IW4MAdmin.Application.Factories
|
||||
/// <param name="port">port of the server</param>
|
||||
/// <param name="password">rcon password of the server</param>
|
||||
/// <returns></returns>
|
||||
public IRConConnection CreateConnection(string ipAddress, int port, string password)
|
||||
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}'")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -6,9 +6,9 @@ using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Data.Models.Client;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static SharedLibraryCore.Database.Models.EFClient;
|
||||
|
||||
namespace IW4MAdmin.Application.Factories
|
||||
{
|
||||
@ -32,7 +32,7 @@ namespace IW4MAdmin.Application.Factories
|
||||
public IManagerCommand CreateScriptCommand(string name, string alias, string description, string permission,
|
||||
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
|
||||
{
|
||||
Name = _arg.Item1,
|
||||
|
@ -15,10 +15,14 @@ using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Abstractions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog.Context;
|
||||
using static SharedLibraryCore.Database.Models.EFClient;
|
||||
using Data.Models;
|
||||
using Data.Models.Server;
|
||||
using static Data.Models.Client.EFClient;
|
||||
|
||||
namespace IW4MAdmin
|
||||
{
|
||||
@ -29,18 +33,20 @@ namespace IW4MAdmin
|
||||
private readonly ITranslationLookup _translationLookup;
|
||||
private readonly IMetaService _metaService;
|
||||
private const int REPORT_FLAG_COUNT = 4;
|
||||
private int lastGameTime = 0;
|
||||
private long lastGameTime = 0;
|
||||
|
||||
public int Id { get; private set; }
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IClientNoticeMessageFormatter _messageFormatter;
|
||||
private readonly ILookupCache<EFServer> _serverCache;
|
||||
|
||||
public IW4MServer(
|
||||
ServerConfiguration serverConfiguration,
|
||||
ITranslationLookup lookup,
|
||||
IMetaService metaService,
|
||||
IServiceProvider serviceProvider,
|
||||
IClientNoticeMessageFormatter messageFormatter) : base(serviceProvider.GetRequiredService<ILogger<Server>>(),
|
||||
IClientNoticeMessageFormatter messageFormatter,
|
||||
ILookupCache<EFServer> serverCache) : base(serviceProvider.GetRequiredService<ILogger<Server>>(),
|
||||
serviceProvider.GetRequiredService<SharedLibraryCore.Interfaces.ILogger>(),
|
||||
serverConfiguration,
|
||||
serviceProvider.GetRequiredService<IManager>(),
|
||||
@ -51,6 +57,7 @@ namespace IW4MAdmin
|
||||
_metaService = metaService;
|
||||
_serviceProvider = serviceProvider;
|
||||
_messageFormatter = messageFormatter;
|
||||
_serverCache = serverCache;
|
||||
}
|
||||
|
||||
public override async Task<EFClient> OnClientConnected(EFClient clientFromLog)
|
||||
@ -67,6 +74,8 @@ namespace IW4MAdmin
|
||||
client = await Manager.GetClientService().Create(clientFromLog);
|
||||
}
|
||||
|
||||
client.CopyAdditionalProperties(clientFromLog);
|
||||
|
||||
// this is only a temporary version until the IPAddress is transmitted
|
||||
client.CurrentAlias = new EFAlias()
|
||||
{
|
||||
@ -154,7 +163,8 @@ namespace IW4MAdmin
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -249,6 +259,28 @@ namespace IW4MAdmin
|
||||
{
|
||||
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)
|
||||
{
|
||||
var exception = E.Extra as Exception;
|
||||
@ -299,6 +331,13 @@ namespace IW4MAdmin
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -444,10 +483,10 @@ namespace IW4MAdmin
|
||||
|
||||
await Manager.GetPenaltyService().Create(newReport);
|
||||
|
||||
int reportNum = await Manager.GetClientService().GetClientReportCount(E.Target.ClientId);
|
||||
bool isAutoFlagged = await Manager.GetClientService().IsAutoFlagged(E.Target.ClientId);
|
||||
var reportNum = await Manager.GetClientService().GetClientReportCount(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(
|
||||
Utilities.CurrentLocalization.LocalizationIndex["SERVER_AUTO_FLAG_REPORT"]
|
||||
@ -702,11 +741,11 @@ namespace IW4MAdmin
|
||||
/// array index 2 = updated clients
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
async Task<IList<EFClient>[]> PollPlayersAsync()
|
||||
async Task<List<EFClient>[]> PollPlayersAsync()
|
||||
{
|
||||
var currentClients = GetClientsAsList();
|
||||
var statusResponse = (await this.GetStatusAsync());
|
||||
var polledClients = statusResponse.Item1.AsEnumerable();
|
||||
var polledClients = statusResponse.Clients.AsEnumerable();
|
||||
|
||||
if (Manager.GetApplicationSettings().Configuration().IgnoreBots)
|
||||
{
|
||||
@ -716,10 +755,12 @@ namespace IW4MAdmin
|
||||
var connectingClients = polledClients.Except(currentClients);
|
||||
var updatedClients = polledClients.Except(connectingClients).Except(disconnectingClients);
|
||||
|
||||
UpdateMap(statusResponse.Item2);
|
||||
UpdateGametype(statusResponse.Item3);
|
||||
UpdateMap(statusResponse.Map);
|
||||
UpdateGametype(statusResponse.GameType);
|
||||
UpdateHostname(statusResponse.Hostname);
|
||||
UpdateMaxPlayers(statusResponse.MaxClients);
|
||||
|
||||
return new List<EFClient>[]
|
||||
return new []
|
||||
{
|
||||
connectingClients.ToList(),
|
||||
disconnectingClients.ToList(),
|
||||
@ -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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
foreach (var client in GetClientsAsList())
|
||||
@ -955,11 +1045,12 @@ namespace IW4MAdmin
|
||||
RconParser = RconParser ?? Manager.AdditionalRConParsers[0];
|
||||
EventParser = EventParser ?? Manager.AdditionalEventParsers[0];
|
||||
|
||||
RemoteConnection = RConConnectionFactory.CreateConnection(IP, Port, Password, RconParser.RConEngine);
|
||||
RemoteConnection.SetConfiguration(RconParser);
|
||||
|
||||
var version = await this.GetMappedDvarValueOrDefaultAsync<string>("version");
|
||||
Version = version.Value;
|
||||
GameName = Utilities.GetGame(version?.Value ?? RconParser.Version);
|
||||
GameName = Utilities.GetGame(version.Value ?? RconParser.Version);
|
||||
|
||||
if (GameName == Game.UKN)
|
||||
{
|
||||
@ -1105,6 +1196,7 @@ namespace IW4MAdmin
|
||||
this,
|
||||
GenerateUriForLog(LogPath, ServerConfig.GameLogServerUrl?.AbsoluteUri), gameLogReaderFactory);
|
||||
|
||||
await _serverCache.InitializeAsync();
|
||||
_ = Task.Run(() => LogEvent.PollForChanges());
|
||||
|
||||
if (!Utilities.IsDevelopment)
|
||||
@ -1115,7 +1207,7 @@ namespace IW4MAdmin
|
||||
|
||||
public Uri[] GenerateUriForLog(string logPath, string gameLogServerUrl)
|
||||
{
|
||||
var logUri = new Uri(logPath);
|
||||
var logUri = new Uri(logPath, UriKind.Absolute);
|
||||
|
||||
if (string.IsNullOrEmpty(gameLogServerUrl))
|
||||
{
|
||||
@ -1230,8 +1322,12 @@ namespace IW4MAdmin
|
||||
|
||||
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,
|
||||
targetClient.ClientNumber,
|
||||
clientNumber,
|
||||
_messageFormatter.BuildFormattedMessage(RconParser.Configuration,
|
||||
newPenalty,
|
||||
previousPenalty));
|
||||
@ -1262,8 +1358,12 @@ namespace IW4MAdmin
|
||||
|
||||
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,
|
||||
targetClient.ClientNumber,
|
||||
clientNumber,
|
||||
_messageFormatter.BuildFormattedMessage(RconParser.Configuration, newPenalty));
|
||||
ServerLogger.LogDebug("Executing tempban kick command for {targetClient}", targetClient.ToString());
|
||||
await targetClient.CurrentServer.ExecuteCommandAsync(formattedKick);
|
||||
@ -1296,8 +1396,13 @@ namespace IW4MAdmin
|
||||
if (targetClient.IsIngame)
|
||||
{
|
||||
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,
|
||||
targetClient.ClientNumber,
|
||||
clientNumber,
|
||||
_messageFormatter.BuildFormattedMessage(RconParser.Configuration, newPenalty));
|
||||
await targetClient.CurrentServer.ExecuteCommandAsync(formattedString);
|
||||
}
|
||||
|
@ -17,16 +17,23 @@ using SharedLibraryCore.QueryHelper;
|
||||
using SharedLibraryCore.Repositories;
|
||||
using SharedLibraryCore.Services;
|
||||
using Stats.Dtos;
|
||||
using StatsWeb;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Abstractions;
|
||||
using Data.Helpers;
|
||||
using Integrations.Source.Extensions;
|
||||
using IW4MAdmin.Application.Extensions;
|
||||
using IW4MAdmin.Application.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
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
|
||||
{
|
||||
@ -68,7 +75,10 @@ namespace IW4MAdmin.Application
|
||||
private static async void OnCancelKey(object sender, ConsoleCancelEventArgs e)
|
||||
{
|
||||
ServerManager?.Stop();
|
||||
await ApplicationTask;
|
||||
if (ApplicationTask != null)
|
||||
{
|
||||
await ApplicationTask;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -77,7 +87,7 @@ namespace IW4MAdmin.Application
|
||||
/// <returns></returns>
|
||||
private static async Task LaunchAsync(string[] args)
|
||||
{
|
||||
restart:
|
||||
restart:
|
||||
ITranslationLookup translationLookup = null;
|
||||
var logger = BuildDefaultLogger<Program>(new ApplicationConfiguration());
|
||||
Utilities.DefaultLogger = logger;
|
||||
@ -89,11 +99,12 @@ namespace IW4MAdmin.Application
|
||||
// do any needed housekeeping file/folder migrations
|
||||
ConfigurationMigration.MoveConfigFolder10518(null);
|
||||
ConfigurationMigration.CheckDirectories();
|
||||
ConfigurationMigration.RemoveObsoletePlugins20210322();
|
||||
logger.LogDebug("Configuring services...");
|
||||
services = ConfigureServices(args);
|
||||
serviceProvider = services.BuildServiceProvider();
|
||||
var versionChecker = serviceProvider.GetRequiredService<IMasterCommunication>();
|
||||
ServerManager = (ApplicationManager)serviceProvider.GetRequiredService<IManager>();
|
||||
ServerManager = (ApplicationManager) serviceProvider.GetRequiredService<IManager>();
|
||||
translationLookup = serviceProvider.GetRequiredService<ITranslationLookup>();
|
||||
|
||||
await versionChecker.CheckVersion();
|
||||
@ -102,8 +113,12 @@ namespace IW4MAdmin.Application
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
string failMessage = translationLookup == null ? "Failed to initialize IW4MAdmin" : translationLookup["MANAGER_INIT_FAIL"];
|
||||
string exitMessage = translationLookup == null ? "Press enter to exit..." : translationLookup["MANAGER_EXIT"];
|
||||
string failMessage = translationLookup == null
|
||||
? "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");
|
||||
Console.WriteLine(failMessage);
|
||||
@ -117,7 +132,8 @@ namespace IW4MAdmin.Application
|
||||
{
|
||||
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)
|
||||
@ -145,7 +161,9 @@ namespace IW4MAdmin.Application
|
||||
catch (Exception e)
|
||||
{
|
||||
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()}");
|
||||
}
|
||||
|
||||
@ -163,9 +181,9 @@ namespace IW4MAdmin.Application
|
||||
/// <returns></returns>
|
||||
private static async Task RunApplicationTasksAsync(ILogger logger, IServiceCollection services)
|
||||
{
|
||||
var webfrontTask = ServerManager.GetApplicationSettings().Configuration().EnableWebFront ?
|
||||
WebfrontCore.Program.Init(ServerManager, serviceProvider, services, ServerManager.CancellationToken) :
|
||||
Task.CompletedTask;
|
||||
var webfrontTask = ServerManager.GetApplicationSettings().Configuration().EnableWebFront
|
||||
? WebfrontCore.Program.Init(ServerManager, serviceProvider, services, ServerManager.CancellationToken)
|
||||
: Task.CompletedTask;
|
||||
|
||||
// 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
|
||||
@ -176,14 +194,15 @@ namespace IW4MAdmin.Application
|
||||
{
|
||||
ServerManager.Start(),
|
||||
webfrontTask,
|
||||
serviceProvider.GetRequiredService<IMasterCommunication>().RunUploadStatus(ServerManager.CancellationToken)
|
||||
serviceProvider.GetRequiredService<IMasterCommunication>()
|
||||
.RunUploadStatus(ServerManager.CancellationToken)
|
||||
};
|
||||
|
||||
logger.LogDebug("Starting webfront and input tasks");
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
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)
|
||||
{ }
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static IServiceCollection HandlePluginRegistration(ApplicationConfiguration appConfig,
|
||||
@ -251,27 +271,38 @@ namespace IW4MAdmin.Application
|
||||
|
||||
// register the native commands
|
||||
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);
|
||||
serviceCollection.AddSingleton(typeof(IManagerCommand), commandType);
|
||||
}
|
||||
|
||||
// register the plugin implementations
|
||||
var pluginImplementations = pluginImporter.DiscoverAssemblyPluginImplementations();
|
||||
foreach (var pluginType in pluginImplementations.Item1)
|
||||
var (plugins, commands, configurations) = pluginImporter.DiscoverAssemblyPluginImplementations();
|
||||
foreach (var pluginType in plugins)
|
||||
{
|
||||
defaultLogger.LogDebug("Registered plugin type {name}", pluginType.FullName);
|
||||
serviceCollection.AddSingleton(typeof(IPlugin), pluginType);
|
||||
}
|
||||
|
||||
// register the plugin commands
|
||||
foreach (var commandType in pluginImplementations.Item2)
|
||||
foreach (var commandType in commands)
|
||||
{
|
||||
defaultLogger.LogDebug("Registered plugin command type {name}", commandType.FullName);
|
||||
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
|
||||
foreach (var scriptPlugin in pluginImporter.DiscoverScriptPlugins())
|
||||
{
|
||||
@ -281,10 +312,9 @@ namespace IW4MAdmin.Application
|
||||
// register any eventable types
|
||||
foreach (var assemblyType in typeof(Program).Assembly.GetTypes()
|
||||
.Where(_asmType => typeof(IRegisterEvent).IsAssignableFrom(_asmType))
|
||||
.Union(pluginImplementations
|
||||
.Item1.SelectMany(_asm => _asm.Assembly.GetTypes())
|
||||
.Distinct()
|
||||
.Where(_asmType => typeof(IRegisterEvent).IsAssignableFrom(_asmType))))
|
||||
.Union(plugins.SelectMany(_asm => _asm.Assembly.GetTypes())
|
||||
.Distinct()
|
||||
.Where(_asmType => typeof(IRegisterEvent).IsAssignableFrom(_asmType))))
|
||||
{
|
||||
var instance = Activator.CreateInstance(assemblyType) as IRegisterEvent;
|
||||
serviceCollection.AddSingleton(instance);
|
||||
@ -307,7 +337,7 @@ namespace IW4MAdmin.Application
|
||||
? new Uri("http://127.0.0.1:8080")
|
||||
: appConfig?.MasterUrl ?? new ApplicationConfiguration().MasterUrl;
|
||||
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)
|
||||
{
|
||||
@ -316,12 +346,22 @@ namespace IW4MAdmin.Application
|
||||
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
|
||||
HandlePluginRegistration(appConfig, serviceCollection, masterRestClient);
|
||||
|
||||
serviceCollection
|
||||
.AddBaseLogger(appConfig)
|
||||
.AddSingleton<IServiceCollection>(_serviceProvider => serviceCollection)
|
||||
.AddSingleton<IConfigurationHandler<DefaultSettings>, BaseConfigurationHandler<DefaultSettings>>()
|
||||
.AddSingleton((IConfigurationHandler<ApplicationConfiguration>) appConfigHandler)
|
||||
.AddSingleton(
|
||||
new BaseConfigurationHandler<CommandConfiguration>("CommandConfiguration") as
|
||||
@ -360,6 +400,12 @@ namespace IW4MAdmin.Application
|
||||
.AddSingleton<IManager, ApplicationManager>()
|
||||
.AddSingleton<SharedLibraryCore.Interfaces.ILogger, Logger>()
|
||||
.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)
|
||||
.AddDatabaseContextOptions(appConfig);
|
||||
|
||||
@ -372,6 +418,8 @@ namespace IW4MAdmin.Application
|
||||
serviceCollection.AddSingleton<IEventHandler, GameEventHandler>();
|
||||
}
|
||||
|
||||
serviceCollection.AddSource();
|
||||
|
||||
return serviceCollection;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Abstractions;
|
||||
using Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Dtos.Meta.Responses;
|
||||
using SharedLibraryCore.Helpers;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Abstractions;
|
||||
using Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Dtos.Meta.Responses;
|
||||
using SharedLibraryCore.Helpers;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
@ -6,6 +6,7 @@ using SharedLibraryCore.Interfaces;
|
||||
using SharedLibraryCore.QueryHelper;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Abstractions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
|
@ -85,5 +85,20 @@ namespace IW4MAdmin.Application.Migration
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using IW4MAdmin.Plugins.Stats.Models;
|
||||
using Data.Abstractions;
|
||||
using Data.Models.Client.Stats;
|
||||
using SharedLibraryCore.Database;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
||||
|
@ -22,6 +22,11 @@ namespace IW4MAdmin.Application.Misc
|
||||
Build();
|
||||
}
|
||||
|
||||
public BaseConfigurationHandler() : this(typeof(T).Name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public string FileName { get; }
|
||||
|
||||
public void Build()
|
||||
|
@ -2,9 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Data.Models;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
||||
namespace IW4MAdmin.Application.Misc
|
||||
|
@ -7,8 +7,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Abstractions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
using Data.Models;
|
||||
|
||||
namespace IW4MAdmin.Application.Misc
|
||||
{
|
||||
@ -29,7 +31,7 @@ namespace IW4MAdmin.Application.Misc
|
||||
_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
|
||||
if (client.ClientId < 1)
|
||||
@ -48,6 +50,7 @@ namespace IW4MAdmin.Application.Misc
|
||||
{
|
||||
existingMeta.Value = metaValue;
|
||||
existingMeta.Updated = DateTime.UtcNow;
|
||||
existingMeta.LinkedMetaId = linkedMeta?.MetaId;
|
||||
}
|
||||
|
||||
else
|
||||
@ -57,13 +60,98 @@ namespace IW4MAdmin.Application.Misc
|
||||
ClientId = client.ClientId,
|
||||
Created = DateTime.UtcNow,
|
||||
Key = metaKey,
|
||||
Value = metaValue
|
||||
Value = metaValue,
|
||||
LinkedMetaId = linkedMeta?.MetaId
|
||||
});
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
await using var ctx = _contextFactory.CreateContext(enableTracking: false);
|
||||
@ -76,11 +164,34 @@ namespace IW4MAdmin.Application.Misc
|
||||
MetaId = _meta.MetaId,
|
||||
Key = _meta.Key,
|
||||
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();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
if (!_metaActions.ContainsKey(metaKey))
|
||||
|
@ -63,11 +63,12 @@ namespace IW4MAdmin.Application.Misc
|
||||
/// discovers all the C# assembly plugins and commands
|
||||
/// </summary>
|
||||
/// <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 commandTypes = Enumerable.Empty<Type>();
|
||||
var configurationTypes = Enumerable.Empty<Type>();
|
||||
|
||||
if (Directory.Exists(pluginDir))
|
||||
{
|
||||
@ -92,10 +93,17 @@ namespace IW4MAdmin.Application.Misc
|
||||
.Where(_assemblyType => _assemblyType.IsClass && _assemblyType.BaseType == typeof(Command));
|
||||
|
||||
_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()
|
||||
|
@ -4,6 +4,7 @@ using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Models.Client;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static SharedLibraryCore.Database.Models.EFClient;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
@ -18,7 +19,7 @@ namespace IW4MAdmin.Application.Misc
|
||||
private readonly Action<GameEvent> _executeAction;
|
||||
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)
|
||||
: base(config, layout)
|
||||
{
|
||||
|
@ -168,6 +168,7 @@ namespace IW4MAdmin.Application.Misc
|
||||
}
|
||||
}
|
||||
|
||||
_scriptEngine.SetValue("_configHandler", new ScriptPluginConfigurationWrapper(Name, _scriptEngine));
|
||||
await OnLoadAsync(manager);
|
||||
|
||||
try
|
||||
|
90
Application/Misc/ScriptPluginConfigurationWrapper.cs
Normal file
90
Application/Misc/ScriptPluginConfigurationWrapper.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using SharedLibraryCore;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using System;
|
||||
using System.Net;
|
||||
using Data.Models;
|
||||
using static SharedLibraryCore.Database.Models.EFClient;
|
||||
using static SharedLibraryCore.GameEvent;
|
||||
|
||||
|
@ -8,11 +8,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static SharedLibraryCore.Server;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace IW4MAdmin.Application.RconParsers
|
||||
namespace IW4MAdmin.Application.RConParsers
|
||||
{
|
||||
public class BaseRConParser : IRConParser
|
||||
{
|
||||
@ -55,6 +56,7 @@ namespace IW4MAdmin.Application.RconParsers
|
||||
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarDefaultValue, 3);
|
||||
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarLatchedValue, 4);
|
||||
Configuration.Dvar.AddMapping(ParserRegex.GroupType.RConDvarDomain, 5);
|
||||
Configuration.Dvar.AddMapping(ParserRegex.GroupType.AdditionalGroup, int.MaxValue);
|
||||
|
||||
Configuration.StatusHeader.Pattern = "num +score +ping +guid +name +lastmsg +address +qport +rate *";
|
||||
Configuration.GametypeStatus.Pattern = "";
|
||||
@ -72,6 +74,7 @@ namespace IW4MAdmin.Application.RconParsers
|
||||
public Game GameName { get; set; } = Game.COD;
|
||||
public bool CanGenerateLogPath { get; set; } = true;
|
||||
public string Name { get; set; } = "Call of Duty";
|
||||
public string RConEngine { get; set; } = "COD";
|
||||
|
||||
public async Task<string[]> ExecuteCommandAsync(IRConConnection connection, string command)
|
||||
{
|
||||
@ -127,7 +130,7 @@ namespace IW4MAdmin.Application.RconParsers
|
||||
|
||||
return new Dvar<T>()
|
||||
{
|
||||
Name = match.Groups[Configuration.Dvar.GroupMapping[ParserRegex.GroupType.RConDvarName]].Value,
|
||||
Name = dvarName,
|
||||
Value = string.IsNullOrEmpty(value) ? default : (T)Convert.ChangeType(value, typeof(T)),
|
||||
DefaultValue = string.IsNullOrEmpty(defaultValue) ? default : (T)Convert.ChangeType(defaultValue, typeof(T)),
|
||||
LatchedValue = string.IsNullOrEmpty(latchedValue) ? default : (T)Convert.ChangeType(latchedValue, typeof(T)),
|
||||
@ -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));
|
||||
return (ClientsFromStatus(response), MapFromStatus(response), GameTypeFromStatus(response));
|
||||
return new StatusResponse
|
||||
{
|
||||
Clients = ClientsFromStatus(response).ToArray(),
|
||||
Map = GetValueFromStatus<string>(response, ParserRegex.GroupType.RConStatusMap, Configuration.MapStatus.Pattern),
|
||||
GameType = GetValueFromStatus<string>(response, ParserRegex.GroupType.RConStatusGametype, Configuration.GametypeStatus.Pattern),
|
||||
Hostname = GetValueFromStatus<string>(response, ParserRegex.GroupType.RConStatusHostname, Configuration.HostnameStatus.Pattern),
|
||||
MaxClients = GetValueFromStatus<int?>(response, ParserRegex.GroupType.RConStatusMaxPlayers, Configuration.MaxPlayersStatus.Pattern)
|
||||
};
|
||||
}
|
||||
|
||||
private string MapFromStatus(string[] response)
|
||||
private T GetValueFromStatus<T>(IEnumerable<string> response, ParserRegex.GroupType groupType, string groupPattern)
|
||||
{
|
||||
string map = null;
|
||||
if (string.IsNullOrEmpty(groupPattern))
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
string value = null;
|
||||
foreach (var line in response)
|
||||
{
|
||||
var regex = Regex.Match(line, Configuration.MapStatus.Pattern);
|
||||
var regex = Regex.Match(line, groupPattern);
|
||||
if (regex.Success)
|
||||
{
|
||||
map = regex.Groups[Configuration.MapStatus.GroupMapping[ParserRegex.GroupType.RConStatusMap]].ToString();
|
||||
value = regex.Groups[Configuration.MapStatus.GroupMapping[groupType]].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private string GameTypeFromStatus(string[] response)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Configuration.GametypeStatus.Pattern))
|
||||
if (value == null)
|
||||
{
|
||||
return null;
|
||||
return default;
|
||||
}
|
||||
|
||||
string gametype = null;
|
||||
foreach (var line in response)
|
||||
if (typeof(T) == typeof(int?))
|
||||
{
|
||||
var regex = Regex.Match(line, Configuration.GametypeStatus.Pattern);
|
||||
if (regex.Success)
|
||||
{
|
||||
gametype = regex.Groups[Configuration.GametypeStatus.GroupMapping[ParserRegex.GroupType.RConStatusGametype]].ToString();
|
||||
}
|
||||
return (T)Convert.ChangeType(int.Parse(value), Nullable.GetUnderlyingType(typeof(T)));
|
||||
}
|
||||
|
||||
return gametype;
|
||||
return (T)Convert.ChangeType(value, typeof(T));
|
||||
}
|
||||
|
||||
public async Task<bool> SetDvarAsync(IRConConnection connection, string dvarName, object dvarValue)
|
||||
{
|
||||
string dvarString = (dvarValue is string str)
|
||||
? $"{dvarName} \"{str}\""
|
||||
: $"{dvarName} {dvarValue.ToString()}";
|
||||
: $"{dvarName} {dvarValue}";
|
||||
|
||||
return (await connection.SendQueryAsync(StaticHelpers.QueryType.SET_DVAR, dvarString)).Length > 0;
|
||||
}
|
||||
@ -205,8 +210,7 @@ namespace IW4MAdmin.Application.RconParsers
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
if (match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConPing]] == "ZMBI" ||
|
||||
match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConPing]] == "CNCT")
|
||||
if (match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConPing]] == "ZMBI")
|
||||
{
|
||||
_logger.LogDebug("Ignoring detected client {client} because they are zombie state", string.Join(",", match.Values));
|
||||
continue;
|
||||
@ -226,12 +230,13 @@ namespace IW4MAdmin.Application.RconParsers
|
||||
long networkId;
|
||||
string name = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConName]].TrimNewLine();
|
||||
string networkIdString;
|
||||
var ip = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConIpAddress]].Split(':')[0].ConvertToIP();
|
||||
|
||||
try
|
||||
{
|
||||
networkIdString = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConNetworkId]];
|
||||
|
||||
networkId = networkIdString.IsBotGuid() ?
|
||||
networkId = networkIdString.IsBotGuid() || (ip == null && ping == 999) ?
|
||||
name.GenerateGuidFromString() :
|
||||
networkIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
|
||||
}
|
||||
@ -241,8 +246,6 @@ namespace IW4MAdmin.Application.RconParsers
|
||||
continue;
|
||||
}
|
||||
|
||||
int? ip = match.Values[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConIpAddress]].Split(':')[0].ConvertToIP();
|
||||
|
||||
var client = new EFClient()
|
||||
{
|
||||
CurrentAlias = new EFAlias()
|
||||
@ -258,6 +261,11 @@ namespace IW4MAdmin.Application.RconParsers
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
||||
namespace IW4MAdmin.Application.RconParsers
|
||||
namespace IW4MAdmin.Application.RConParsers
|
||||
{
|
||||
/// <summary>
|
||||
/// empty implementation of the IW4RConParser
|
||||
/// allows script plugins to generate dynamic RCon parsers
|
||||
/// </summary>
|
||||
sealed internal class DynamicRConParser : BaseRConParser
|
||||
internal sealed class DynamicRConParser : BaseRConParser
|
||||
{
|
||||
public DynamicRConParser(ILogger<BaseRConParser> logger, IParserRegexFactory parserRegexFactory) : base(logger, parserRegexFactory)
|
||||
{
|
@ -4,7 +4,7 @@ using SharedLibraryCore.RCon;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace IW4MAdmin.Application.RconParsers
|
||||
namespace IW4MAdmin.Application.RConParsers
|
||||
{
|
||||
/// <summary>
|
||||
/// generic implementation of the IRConParserConfiguration
|
||||
@ -16,6 +16,8 @@ namespace IW4MAdmin.Application.RconParsers
|
||||
public ParserRegex Status { get; set; }
|
||||
public ParserRegex MapStatus { get; set; }
|
||||
public ParserRegex GametypeStatus { get; set; }
|
||||
public ParserRegex HostnameStatus { get; set; }
|
||||
public ParserRegex MaxPlayersStatus { get; set; }
|
||||
public ParserRegex Dvar { get; set; }
|
||||
public ParserRegex StatusHeader { get; set; }
|
||||
public string ServerNotRunningResponse { get; set; }
|
||||
@ -34,6 +36,8 @@ namespace IW4MAdmin.Application.RconParsers
|
||||
GametypeStatus = parserRegexFactory.CreateParserRegex();
|
||||
Dvar = parserRegexFactory.CreateParserRegex();
|
||||
StatusHeader = parserRegexFactory.CreateParserRegex();
|
||||
HostnameStatus = parserRegexFactory.CreateParserRegex();
|
||||
MaxPlayersStatus = parserRegexFactory.CreateParserRegex();
|
||||
}
|
||||
}
|
||||
}
|
15
Application/RConParsers/StatusResponse.cs
Normal file
15
Application/RConParsers/StatusResponse.cs
Normal 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; }
|
||||
}
|
||||
}
|
12
Data/Abstractions/IDataValueCache.cs
Normal file
12
Data/Abstractions/IDataValueCache.cs
Normal 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);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using SharedLibraryCore.Database;
|
||||
using Data.Context;
|
||||
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
namespace Data.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// describes the capabilities of the database context factory
|
14
Data/Abstractions/ILookupCache.cs
Normal file
14
Data/Abstractions/ILookupCache.cs
Normal 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();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
namespace Data.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// describes the capability of extending properties by name
|
13
Data/Abstractions/IUniqueId.cs
Normal file
13
Data/Abstractions/IUniqueId.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Data.Abstractions
|
||||
{
|
||||
public interface IUniqueId
|
||||
{
|
||||
[NotMapped]
|
||||
long Id { get; }
|
||||
|
||||
[NotMapped]
|
||||
string Value { get; }
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using static SharedLibraryCore.Database.Models.EFClient;
|
||||
using Data.Abstractions;
|
||||
using Data.Models;
|
||||
using Data.Models.Client;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SharedLibraryCore.Database
|
||||
namespace Data.Context
|
||||
{
|
||||
public static class ContextSeed
|
||||
{
|
||||
@ -30,7 +29,7 @@ namespace SharedLibraryCore.Database
|
||||
Connections = 0,
|
||||
FirstConnection = DateTime.UtcNow,
|
||||
LastConnection = DateTime.UtcNow,
|
||||
Level = Permission.Console,
|
||||
Level = EFClient.Permission.Console,
|
||||
Masked = true,
|
||||
NetworkId = 0,
|
||||
AliasLink = link,
|
135
Data/Context/DatabaseContext.cs
Normal file
135
Data/Context/DatabaseContext.cs
Normal 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
83
Data/Data.csproj
Normal 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>
|
10
Data/Extensions/Extensions.cs
Normal file
10
Data/Extensions/Extensions.cs
Normal 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";
|
||||
}
|
||||
}
|
84
Data/Helpers/DataValueCache.cs
Normal file
84
Data/Helpers/DataValueCache.cs
Normal 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
114
Data/Helpers/LookupCache.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
using System;
|
||||
using Data.Context;
|
||||
using Data.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SharedLibraryCore.Database.MigrationContext
|
||||
namespace Data.MigrationContext
|
||||
{
|
||||
public class MySqlDatabaseContext : DatabaseContext
|
||||
{
|
||||
public MySqlDatabaseContext()
|
||||
{
|
||||
if (!Utilities.IsMigration)
|
||||
if (!MigrationExtensions.IsMigration)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
@ -20,7 +22,7 @@ namespace SharedLibraryCore.Database.MigrationContext
|
||||
|
||||
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;")
|
||||
.EnableDetailedErrors(true)
|
@ -1,13 +1,15 @@
|
||||
using System;
|
||||
using Data.Context;
|
||||
using Data.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SharedLibraryCore.Database.MigrationContext
|
||||
namespace Data.MigrationContext
|
||||
{
|
||||
public class PostgresqlDatabaseContext : DatabaseContext
|
||||
{
|
||||
public PostgresqlDatabaseContext()
|
||||
{
|
||||
if (!Utilities.IsMigration)
|
||||
if (!MigrationExtensions.IsMigration)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
@ -15,19 +17,18 @@ namespace SharedLibraryCore.Database.MigrationContext
|
||||
|
||||
public PostgresqlDatabaseContext(DbContextOptions options) : base(options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (Utilities.IsMigration)
|
||||
if (MigrationExtensions.IsMigration)
|
||||
{
|
||||
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)
|
||||
.EnableSensitiveDataLogging(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
using System;
|
||||
using Data.Context;
|
||||
using Data.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SharedLibraryCore.Database.MigrationContext
|
||||
namespace Data.MigrationContext
|
||||
{
|
||||
public class SqliteDatabaseContext : DatabaseContext
|
||||
{
|
||||
public SqliteDatabaseContext()
|
||||
{
|
||||
if (!Utilities.IsMigration)
|
||||
if (!MigrationExtensions.IsMigration)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
@ -20,7 +22,7 @@ namespace SharedLibraryCore.Database.MigrationContext
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (Utilities.IsMigration)
|
||||
if (MigrationExtensions.IsMigration)
|
||||
{
|
||||
optionsBuilder.UseSqlite("Data Source=IW4MAdmin_Migration.db")
|
||||
.EnableDetailedErrors(true)
|
@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||
using SharedLibraryCore.Database;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data;
|
||||
using Data.MigrationContext;
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180409183408_InitialCreate")]
|
@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||
using SharedLibraryCore.Database;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data;
|
||||
using Data.MigrationContext;
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180502195450_Update")]
|
@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class Update : Migration
|
||||
{
|
@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||
using SharedLibraryCore.Database;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data;
|
||||
using Data.MigrationContext;
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180516023249_AddEloField")]
|
@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddEloField : Migration
|
||||
{
|
@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||
using SharedLibraryCore.Database;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data;
|
||||
using Data.MigrationContext;
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180517223349_AddRollingKDR")]
|
@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddRollingKDR : Migration
|
||||
{
|
@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180531212903_AddAutomatedOffenseAndRatingHistory")]
|
@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddAutomatedOffenseAndRatingHistory : Migration
|
||||
{
|
@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180601172317_AddActivityAmount")]
|
@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddActivityAmount : Migration
|
||||
{
|
@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180602041758_AddClientMeta")]
|
@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddClientMeta : Migration
|
||||
{
|
@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180605191706_AddEFACSnapshots")]
|
@ -4,7 +4,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddEFACSnapshots : Migration
|
||||
{
|
@ -5,10 +5,10 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180614014303_IndexForEFAlias")]
|
@ -2,7 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class IndexForEFAlias : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180902035612_AddFractionAndIsKill")]
|
@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddFractionAndIsKill : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180904154622_AddVisibilityPercentage")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddVisibilityPercentage : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180907020706_AddVision")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddVision : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180908004053_AddWhenToRating")]
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddWhenToRating : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180910221749_AddRatingIndexes")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddRatingIndexes : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180911184224_AddEFAliasNameIndex")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddEFAliasNameIndex : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180911190823_AddEFAliasNameMaxLength24")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddEFAliasNameMaxLength24 : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180912015012_AddPreviousCurrentValueToEFChangeHistory")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddPreviousCurrentValueToEFChangeHistory : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180915163111_AddIndexToMessageTimeSent")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddIndexToMessageTimeSent : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180922231310_RemoveACSnapShot")]
|
@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class RemoveACSnapShot : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20180922231600_ReaddACSnapshot")]
|
@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class ReaddACSnapshot : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20181014171848_MakePenaltyExpirationNullable")]
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class MakePenaltyExpirationNullable : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20181125193243_MakeClientIPNullable")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class MakeClientIPNullable : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20181127144417_AddEndpointToEFServerUpdateServerIdType")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddEndpointToEFServerUpdateServerIdType : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20181216214513_AddEvadePenaltyFlag")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddEvadePenaltyFlag : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20190222234742_AddIndexToEFMeta-KeyAndClientId")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddIndexToEFMetaKeyAndClientId : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20190423142128_AddGameNameToEFServer")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddGameNameToEFServer : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20190615145212_AddAvgRecoilOffset")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddAvgRecoilOffset : Migration
|
||||
{
|
@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using SharedLibraryCore.Database.MigrationContext;
|
||||
using Data.MigrationContext;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
[DbContext(typeof(MySqlDatabaseContext))]
|
||||
[Migration("20190615214055_AddRecoilOffsetToSnapshot")]
|
@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace SharedLibraryCore.Migrations.MySql
|
||||
namespace Data.Migrations.MySql
|
||||
{
|
||||
public partial class AddRecoilOffsetToSnapshot : Migration
|
||||
{
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user