diff --git a/Application/Application.csproj b/Application/Application.csproj index e328741d..38ee0c4a 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -6,7 +6,7 @@ 2.1.5 false RaidMax.IW4MAdmin.Application - 2.2.3.1 + 2.2.3.2 RaidMax Forever None IW4MAdmin @@ -31,8 +31,8 @@ true true - 2.2.3.1 - 2.2.3.1 + 2.2.3.2 + 2.2.3.2 diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index e03046b1..86c205ca 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -449,7 +449,7 @@ namespace IW4MAdmin client.Score = origin.Score; // update their IP if it hasn't been set yet - if (client.IPAddress == null) + if (client.IPAddress == null && !client.IsBot) { return client.OnJoin(origin.IPAddress); } diff --git a/Application/Localization/Configure.cs b/Application/Localization/Configure.cs index 2219e614..bf6a36d8 100644 --- a/Application/Localization/Configure.cs +++ b/Application/Localization/Configure.cs @@ -12,7 +12,7 @@ namespace IW4MAdmin.Application.Localization { public class Configure { - public static void Initialize(string customLocale) + public static void Initialize(string customLocale = null) { string currentLocale = string.IsNullOrEmpty(customLocale) ? CultureInfo.CurrentCulture.Name : customLocale; string[] localizationFiles = Directory.GetFiles(Path.Join(Utilities.OperatingDirectory, "Localization"), $"*.{currentLocale}.json"); diff --git a/Application/Main.cs b/Application/Main.cs index 2c0a0623..7b08fc0a 100644 --- a/Application/Main.cs +++ b/Application/Main.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading; using SharedLibraryCore.Localization; using IW4MAdmin.Application.Migration; +using SharedLibraryCore.Exceptions; namespace IW4MAdmin.Application { @@ -38,7 +39,15 @@ namespace IW4MAdmin.Application try { ServerManager = ApplicationManager.GetInstance(); - Localization.Configure.Initialize(ServerManager.GetApplicationSettings().Configuration()?.CustomLocale); + try + { + Localization.Configure.Initialize(ServerManager.GetApplicationSettings().Configuration().CustomLocale); + } + + catch (ServerException) + { + Localization.Configure.Initialize(); + } loc = Utilities.CurrentLocalization.LocalizationIndex; Console.CancelKeyPress += new ConsoleCancelEventHandler(OnCancelKey); @@ -107,7 +116,7 @@ namespace IW4MAdmin.Application var consoleTask = Task.Run(async () => { - String userInput; + string userInput; var Origin = Utilities.IW4MAdminClient(ServerManager.Servers[0]); do @@ -144,13 +153,16 @@ namespace IW4MAdmin.Application catch (Exception e) { - Console.WriteLine(loc["MANAGER_INIT_FAIL"]); + string failMessage = loc == null ? "Failed to initalize IW4MAdmin" : loc["MANAGER_INIT_FAIL"]; + string exitMessage = loc == null ? "Press any key to exit..." : loc["MANAGER_EXIT"]; + + Console.WriteLine(failMessage); while (e.InnerException != null) { e = e.InnerException; } Console.WriteLine(e.Message); - Console.WriteLine(loc["MANAGER_EXIT"]); + Console.WriteLine(exitMessage); Console.ReadKey(); return; } diff --git a/Application/Manager.cs b/Application/Manager.cs index 8b252583..81dcf08f 100644 --- a/Application/Manager.cs +++ b/Application/Manager.cs @@ -204,7 +204,8 @@ namespace IW4MAdmin.Application Running = true; #region DATABASE - using (var db = new DatabaseContext(GetApplicationSettings().Configuration()?.ConnectionString, GetApplicationSettings().Configuration()?.DatabaseProvider)) + using (var db = new DatabaseContext(GetApplicationSettings().Configuration()?.ConnectionString, + GetApplicationSettings().Configuration()?.DatabaseProvider)) { await new ContextSeed(db).Seed(); } diff --git a/Plugins/Login/Plugin.cs b/Plugins/Login/Plugin.cs index a1f737e6..d2deff4c 100644 --- a/Plugins/Login/Plugin.cs +++ b/Plugins/Login/Plugin.cs @@ -6,7 +6,6 @@ using SharedLibraryCore.Configuration; using SharedLibraryCore.Database.Models; using SharedLibraryCore.Exceptions; using SharedLibraryCore.Interfaces; -using SharedLibraryCore.Objects; namespace IW4MAdmin.Plugins.Login { @@ -23,7 +22,7 @@ namespace IW4MAdmin.Plugins.Login public Task OnEventAsync(GameEvent E, Server S) { - if (E.Remote || Config.RequirePrivilegedClientLogin == false) + if (E.IsRemote || Config.RequirePrivilegedClientLogin == false) return Task.CompletedTask; if (E.Type == GameEvent.EventType.Connect) diff --git a/SharedLibraryCore/Events/GameEvent.cs b/SharedLibraryCore/Events/GameEvent.cs index 4b1a779d..f068336d 100644 --- a/SharedLibraryCore/Events/GameEvent.cs +++ b/SharedLibraryCore/Events/GameEvent.cs @@ -188,7 +188,7 @@ namespace SharedLibraryCore public EFClient Origin; public EFClient Target; public Server Owner; - public Boolean Remote = false; + public bool IsRemote { get; set; } = false; public object Extra { get; set; } public ManualResetEventSlim OnProcessed { get; set; } public DateTime Time { get; set; } diff --git a/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs b/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs index ac6289ae..29656a2a 100644 --- a/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs +++ b/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Configuration; using Newtonsoft.Json; +using SharedLibraryCore.Exceptions; using SharedLibraryCore.Interfaces; using System; using System.Collections.Generic; @@ -40,7 +41,7 @@ namespace SharedLibraryCore.Configuration return File.WriteAllTextAsync(Path.Join(Utilities.OperatingDirectory, "Configuration", $"{Filename}.json"), appConfigJSON); } - public T Configuration() => _configuration; + public T Configuration() => _configuration == null ? throw new ServerException("Configuration is null") : _configuration; public void Set(T config) { diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index 67214d0b..8c904b4c 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -53,13 +53,6 @@ namespace SharedLibraryCore.Services private async Task UpdateAlias(string name, int? ip, EFClient entity, DatabaseContext context) { // entity is the tracked db context item - // todo: move this out -#if DEBUG == false - if (entity.IsBot) - { - return; - } -#endif // get all aliases by IP address and LinkId var iqAliases = context.Aliases .Include(a => a.Link) @@ -377,7 +370,8 @@ namespace SharedLibraryCore.Services ClientId = client.ClientId, Level = client.Level, Password = client.Password, - PasswordSalt = client.PasswordSalt + PasswordSalt = client.PasswordSalt, + NetworkId = client.NetworkId }; #if DEBUG == true diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index 651ec104..92626e9c 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -212,7 +212,7 @@ namespace SharedLibraryCore /// /// Shorthand gametype reported from server /// - public static String GetLocalizedGametype(String input) + public static string GetLocalizedGametype(String input) { switch (input) { @@ -284,7 +284,7 @@ namespace SharedLibraryCore public static int? ConvertToIP(this string str) { bool success = System.Net.IPAddress.TryParse(str, out System.Net.IPAddress ip); - return success && ip.GetAddressBytes().Count(_byte => _byte == 0) != 4 ? + return success && ip.GetAddressBytes().Count(_byte => _byte == 0) != 4 ? (int?)BitConverter.ToInt32(ip.GetAddressBytes(), 0) : null; } @@ -294,12 +294,12 @@ namespace SharedLibraryCore return !ip.HasValue ? "" : new System.Net.IPAddress(BitConverter.GetBytes(ip.Value)).ToString(); } - public static String GetTimePassed(DateTime start) + public static string GetTimePassed(DateTime start) { return GetTimePassed(start, true); } - public static String GetTimePassed(DateTime start, bool includeAgo) + public static string GetTimePassed(DateTime start, bool includeAgo) { TimeSpan Elapsed = DateTime.UtcNow - start; string ago = includeAgo ? $" {CurrentLocalization.LocalizationIndex["WEBFRONT_PENALTY_TEMPLATE_AGO"]}" : ""; @@ -480,10 +480,11 @@ namespace SharedLibraryCore /// description of the question's value /// default value to set if no input is entered /// - public static bool PromptBool(string question, string description = null, char? defaultValue = 'y') + public static bool PromptBool(string question, string description = null, bool defaultValue = true) { Console.Write($"{question}?{(string.IsNullOrEmpty(description) ? "" : $" ({description}) ")}[y/n]: "); - return (Console.ReadLine().ToLower().FirstOrDefault() as char? ?? defaultValue) == 'y'; + char response = Console.ReadLine().ToLower().FirstOrDefault(); + return response != 0 ? response == 'y' : defaultValue; } /// diff --git a/WebfrontCore/Controllers/AccountController.cs b/WebfrontCore/Controllers/AccountController.cs index 7cc598e0..9465f658 100644 --- a/WebfrontCore/Controllers/AccountController.cs +++ b/WebfrontCore/Controllers/AccountController.cs @@ -28,7 +28,8 @@ namespace WebfrontCore.Controllers { new Claim(ClaimTypes.NameIdentifier, client.Name), new Claim(ClaimTypes.Role, client.Level.ToString()), - new Claim(ClaimTypes.Sid, client.ClientId.ToString()) + new Claim(ClaimTypes.Sid, client.ClientId.ToString()), + new Claim(ClaimTypes.PrimarySid, client.NetworkId.ToString()) }; var claimsIdentity = new ClaimsIdentity(claims, "login"); diff --git a/WebfrontCore/Controllers/BaseController.cs b/WebfrontCore/Controllers/BaseController.cs index b3c435b8..02225beb 100644 --- a/WebfrontCore/Controllers/BaseController.cs +++ b/WebfrontCore/Controllers/BaseController.cs @@ -1,14 +1,14 @@ -using System; -using System.Linq; -using System.Security.Claims; -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; - +using SharedLibraryCore; using SharedLibraryCore.Database; using SharedLibraryCore.Database.Models; using SharedLibraryCore.Interfaces; -using SharedLibraryCore.Objects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; using WebfrontCore.ViewModels; namespace WebfrontCore.Controllers @@ -23,14 +23,19 @@ namespace WebfrontCore.Controllers private static readonly byte[] LocalHost = { 127, 0, 0, 1 }; private static string SocialLink; private static string SocialTitle; + protected List Pages; public BaseController() { if (Manager == null) + { Manager = Program.Manager; + } if (Localization == null) - Localization = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex; + { + Localization = Utilities.CurrentLocalization.LocalizationIndex; + } if (Manager.GetApplicationSettings().Configuration().EnableSocialLink && SocialLink == null) { @@ -38,6 +43,13 @@ namespace WebfrontCore.Controllers SocialTitle = Manager.GetApplicationSettings().Configuration().SocialLinkTitle; } + Pages = Manager.GetPageList().Pages + .Select(page => new Page + { + Name = page.Key, + Location = page.Value + }).ToList(); + ViewBag.Version = Manager.Version; } @@ -55,6 +67,7 @@ namespace WebfrontCore.Controllers try { Client.ClientId = Convert.ToInt32(base.User.Claims.First(c => c.Type == ClaimTypes.Sid).Value); + Client.NetworkId = User.Claims.First(_claim => _claim.Type == ClaimTypes.PrimarySid).Value.ConvertLong(); Client.Level = (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), User.Claims.First(c => c.Type == ClaimTypes.Role).Value); Client.CurrentAlias = new EFAlias() { Name = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value }; } @@ -82,18 +95,11 @@ namespace WebfrontCore.Controllers Authorized = Client.ClientId >= 0; ViewBag.Authorized = Authorized; - ViewBag.Url = Manager.GetApplicationSettings().Configuration().WebfrontBindUrl; + ViewBag.Url = Manager.GetApplicationSettings().Configuration().WebfrontUrl; ViewBag.User = Client; ViewBag.SocialLink = SocialLink ?? ""; ViewBag.SocialTitle = SocialTitle; - - // grab the pages from plugins - ViewBag.Pages = Manager.GetPageList().Pages - .Select(page => new Page - { - Name = page.Key, - Location = page.Value - }).ToList(); + ViewBag.Pages = Pages; base.OnActionExecuting(context); } diff --git a/WebfrontCore/Controllers/ConsoleController.cs b/WebfrontCore/Controllers/ConsoleController.cs index 4f7fd206..e85dacd0 100644 --- a/WebfrontCore/Controllers/ConsoleController.cs +++ b/WebfrontCore/Controllers/ConsoleController.cs @@ -33,6 +33,7 @@ namespace WebfrontCore.Controllers { ClientId = Client.ClientId, Level = Client.Level, + NetworkId = Client.NetworkId, CurrentServer = server, CurrentAlias = new EFAlias() { @@ -46,7 +47,7 @@ namespace WebfrontCore.Controllers Data = command, Origin = client, Owner = server, - Remote = true + IsRemote = true }; Manager.GetEventHandler().AddEvent(remoteEvent);