mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
implement new eventing system
This commit is contained in:
@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Events.Management;
|
||||
using SharedLibraryCore.Helpers;
|
||||
using SharedLibraryCore.Services;
|
||||
using WebfrontCore.Controllers.API.Dtos;
|
||||
@ -136,6 +137,16 @@ namespace WebfrontCore.Controllers.API
|
||||
? HttpContext.Request.Headers["X-Forwarded-For"].ToString()
|
||||
: HttpContext.Connection.RemoteIpAddress.ToString()
|
||||
});
|
||||
|
||||
Manager.QueueEvent(new LoginEvent
|
||||
{
|
||||
Source = this,
|
||||
LoginSource = LoginEvent.LoginSourceType.Webfront,
|
||||
EntityId = Client.ClientId.ToString(),
|
||||
Identifier = HttpContext.Request.Headers.ContainsKey("X-Forwarded-For")
|
||||
? HttpContext.Request.Headers["X-Forwarded-For"].ToString()
|
||||
: HttpContext.Connection.RemoteIpAddress?.ToString()
|
||||
});
|
||||
|
||||
return Ok();
|
||||
}
|
||||
@ -165,6 +176,16 @@ namespace WebfrontCore.Controllers.API
|
||||
? HttpContext.Request.Headers["X-Forwarded-For"].ToString()
|
||||
: HttpContext.Connection.RemoteIpAddress.ToString()
|
||||
});
|
||||
|
||||
Manager.QueueEvent(new LogoutEvent
|
||||
{
|
||||
Source = this,
|
||||
LoginSource = LoginEvent.LoginSourceType.Webfront,
|
||||
EntityId = Client.ClientId.ToString(),
|
||||
Identifier = HttpContext.Request.Headers.ContainsKey("X-Forwarded-For")
|
||||
? HttpContext.Request.Headers["X-Forwarded-For"].ToString()
|
||||
: HttpContext.Connection.RemoteIpAddress?.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
|
@ -91,7 +91,7 @@ namespace WebfrontCore.Controllers.API
|
||||
var start = DateTime.Now;
|
||||
Client.CurrentServer = foundServer;
|
||||
|
||||
var commandEvent = new GameEvent()
|
||||
var commandEvent = new GameEvent
|
||||
{
|
||||
Type = GameEvent.EventType.Command,
|
||||
Owner = foundServer,
|
||||
|
@ -47,4 +47,4 @@ namespace WebfrontCore.Controllers
|
||||
return View(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using SharedLibraryCore.Events.Management;
|
||||
using SharedLibraryCore.Helpers;
|
||||
|
||||
namespace WebfrontCore.Controllers
|
||||
@ -72,6 +73,16 @@ namespace WebfrontCore.Controllers
|
||||
? HttpContext.Request.Headers["X-Forwarded-For"].ToString()
|
||||
: HttpContext.Connection.RemoteIpAddress?.ToString()
|
||||
});
|
||||
|
||||
Manager.QueueEvent(new LoginEvent
|
||||
{
|
||||
Source = this,
|
||||
LoginSource = LoginEvent.LoginSourceType.Webfront,
|
||||
EntityId = privilegedClient.ClientId.ToString(),
|
||||
Identifier = HttpContext.Request.Headers.ContainsKey("X-Forwarded-For")
|
||||
? HttpContext.Request.Headers["X-Forwarded-For"].ToString()
|
||||
: HttpContext.Connection.RemoteIpAddress?.ToString()
|
||||
});
|
||||
|
||||
return Ok(Localization["WEBFRONT_ACTION_LOGIN_SUCCESS"].FormatExt(privilegedClient.CleanedName));
|
||||
}
|
||||
@ -99,6 +110,16 @@ namespace WebfrontCore.Controllers
|
||||
? HttpContext.Request.Headers["X-Forwarded-For"].ToString()
|
||||
: HttpContext.Connection.RemoteIpAddress?.ToString()
|
||||
});
|
||||
|
||||
Manager.QueueEvent(new LogoutEvent
|
||||
{
|
||||
Source = this,
|
||||
LoginSource = LoginEvent.LoginSourceType.Webfront,
|
||||
EntityId = Client.ClientId.ToString(),
|
||||
Identifier = HttpContext.Request.Headers.ContainsKey("X-Forwarded-For")
|
||||
? HttpContext.Request.Headers["X-Forwarded-For"].ToString()
|
||||
: HttpContext.Connection.RemoteIpAddress?.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
|
@ -7,7 +7,6 @@ using SharedLibraryCore.Interfaces;
|
||||
using SharedLibraryCore.QueryHelper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using IW4MAdmin.Plugins.Stats.Helpers;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Configuration;
|
||||
@ -41,12 +40,12 @@ namespace WebfrontCore.Controllers
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var server = Manager.GetServers().FirstOrDefault(server => server.ToString() == serverId);
|
||||
var server = Manager.GetServers().FirstOrDefault(server => server.Id == serverId) as IGameServer;
|
||||
long? matchedServerId = null;
|
||||
|
||||
if (server != null)
|
||||
{
|
||||
matchedServerId = StatManager.GetIdForServer(server);
|
||||
matchedServerId = server.LegacyDatabaseId;
|
||||
}
|
||||
|
||||
hitInfo.TotalRankedClients = await _serverDataViewer.RankedClientsCountAsync(matchedServerId, token);
|
||||
|
@ -3,9 +3,8 @@ using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using WebfrontCore.Middleware;
|
||||
|
||||
@ -14,33 +13,36 @@ namespace WebfrontCore
|
||||
public class Program
|
||||
{
|
||||
public static IManager Manager;
|
||||
public static IServiceCollection Services;
|
||||
public static IServiceProvider ApplicationServiceProvider;
|
||||
private static IWebHost _webHost;
|
||||
|
||||
public static Task Init(IManager mgr, IServiceProvider existingServiceProvider, IServiceCollection services, CancellationToken cancellationToken)
|
||||
public static IServiceProvider InitializeServices(Action<IServiceCollection> registerDependenciesAction, string bindUrl)
|
||||
{
|
||||
Services = services;
|
||||
Manager = mgr;
|
||||
ApplicationServiceProvider = existingServiceProvider;
|
||||
var config = Manager.GetApplicationSettings().Configuration();
|
||||
Manager.MiddlewareActionHandler.Register(null, new CustomCssAccentMiddlewareAction("#007ACC", "#fd7e14", config.WebfrontPrimaryColor, config.WebfrontSecondaryColor), "custom_css_accent");
|
||||
return BuildWebHost().RunAsync(cancellationToken);
|
||||
_webHost = BuildWebHost(registerDependenciesAction, bindUrl);
|
||||
Manager = _webHost.Services.GetRequiredService<IManager>();
|
||||
return _webHost.Services;
|
||||
}
|
||||
|
||||
private static IWebHost BuildWebHost()
|
||||
public static Task GetWebHostTask(CancellationToken cancellationToken)
|
||||
{
|
||||
var config = _webHost.Services.GetRequiredService<ApplicationConfiguration>();
|
||||
Manager.MiddlewareActionHandler.Register(null,
|
||||
new CustomCssAccentMiddlewareAction("#007ACC", "#fd7e14", config.WebfrontPrimaryColor,
|
||||
config.WebfrontSecondaryColor), "custom_css_accent");
|
||||
|
||||
return _webHost?.RunAsync(cancellationToken);
|
||||
}
|
||||
|
||||
private static IWebHost BuildWebHost(Action<IServiceCollection> registerDependenciesAction, string bindUrl)
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
return new WebHostBuilder()
|
||||
#if DEBUG
|
||||
.UseContentRoot(Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\..\", "WebfrontCore")))
|
||||
#else
|
||||
.UseContentRoot(SharedLibraryCore.Utilities.OperatingDirectory)
|
||||
#endif
|
||||
.UseUrls(Manager.GetApplicationSettings().Configuration().WebfrontBindUrl)
|
||||
.UseUrls(bindUrl)
|
||||
.UseKestrel()
|
||||
.ConfigureServices(registerDependenciesAction)
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Data.Abstractions;
|
||||
using Data.Helpers;
|
||||
using IW4MAdmin.Plugins.Stats.Helpers;
|
||||
using Stats.Client.Abstractions;
|
||||
using Stats.Config;
|
||||
using WebfrontCore.Controllers.API.Validation;
|
||||
@ -64,23 +65,8 @@ namespace WebfrontCore
|
||||
}
|
||||
|
||||
// Add framework services.
|
||||
var mvcBuilder = services.AddMvc(_options => _options.SuppressAsyncSuffixInActionNames = false)
|
||||
.AddFluentValidation()
|
||||
.ConfigureApplicationPartManager(_partManager =>
|
||||
{
|
||||
foreach (var assembly in pluginAssemblies())
|
||||
{
|
||||
if (assembly.FullName.Contains("Views"))
|
||||
{
|
||||
_partManager.ApplicationParts.Add(new CompiledRazorAssemblyPart(assembly));
|
||||
}
|
||||
|
||||
else if (assembly.FullName.Contains("Web"))
|
||||
{
|
||||
_partManager.ApplicationParts.Add(new AssemblyPart(assembly));
|
||||
}
|
||||
}
|
||||
});
|
||||
var mvcBuilder = services.AddMvc(options => options.SuppressAsyncSuffixInActionNames = false);
|
||||
services.AddFluentValidationAutoValidation().AddFluentValidationClientsideAdapters();
|
||||
|
||||
#if DEBUG
|
||||
{
|
||||
@ -109,42 +95,13 @@ namespace WebfrontCore
|
||||
options.Events.OnSignedIn += ClaimsPermissionRemoval.OnSignedIn;
|
||||
});
|
||||
|
||||
services.AddSingleton(Program.Manager);
|
||||
services.AddSingleton<IResourceQueryHelper<ChatSearchQuery, MessageResponse>, ChatResourceQueryHelper>();
|
||||
services.AddTransient<IValidator<FindClientRequest>, FindClientRequestValidator>();
|
||||
services.AddSingleton<IResourceQueryHelper<FindClientRequest, FindClientResult>, ClientService>();
|
||||
services.AddSingleton<IResourceQueryHelper<StatsInfoRequest, StatsInfoResult>, StatsResourceQueryHelper>();
|
||||
services.AddSingleton<IResourceQueryHelper<StatsInfoRequest, AdvancedStatsInfo>, AdvancedClientStatsResourceQueryHelper>();
|
||||
services.AddScoped(sp =>
|
||||
Program.ApplicationServiceProvider
|
||||
.GetRequiredService<IResourceQueryHelper<ClientResourceRequest, ClientResourceResponse>>());
|
||||
services.AddSingleton(typeof(IDataValueCache<,>), typeof(DataValueCache<,>));
|
||||
// todo: this needs to be handled more gracefully
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<DefaultSettings>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<ILoggerFactory>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IConfigurationHandlerFactory>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IDatabaseContextFactory>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IAuditInformationRepository>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<ITranslationLookup>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IEnumerable<IManagerCommand>>());
|
||||
#pragma warning disable CS0618
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IMetaService>());
|
||||
#pragma warning restore CS0618
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IMetaServiceV2>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<ApplicationConfiguration>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<ClientService>());
|
||||
services.AddSingleton<IResourceQueryHelper<BanInfoRequest, BanInfo>, BanInfoResourceQueryHelper>();
|
||||
services.AddSingleton(
|
||||
Program.ApplicationServiceProvider.GetRequiredService<IServerDistributionCalculator>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider
|
||||
.GetRequiredService<IConfigurationHandler<DefaultSettings>>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider
|
||||
.GetRequiredService<IGeoLocationService>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider
|
||||
.GetRequiredService<StatsConfiguration>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IServerDataViewer>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IInteractionRegistration>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IRemoteCommandService>());
|
||||
services.AddSingleton<IResourceQueryHelper<BanInfoRequest, BanInfo>, BanInfoResourceQueryHelper>();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
Reference in New Issue
Block a user