diff --git a/Plugins/SimpleStats/Helpers/StatManager.cs b/Plugins/SimpleStats/Helpers/StatManager.cs index b69778b90..d55a06d41 100644 --- a/Plugins/SimpleStats/Helpers/StatManager.cs +++ b/Plugins/SimpleStats/Helpers/StatManager.cs @@ -247,7 +247,7 @@ namespace StatsPlugin.Helpers //statsSvc.KillStatsSvc.Insert(kill); //await statsSvc.KillStatsSvc.SaveChangesAsync(); - if (attacker.CurrentServer.Config.EnableAntiCheat) + if(Manager.GetApplicationSettings().EnableAntiCheat) { async Task executePenalty(Cheat.DetectionPenaltyResult penalty) { diff --git a/Plugins/SimpleStats/Plugin.cs b/Plugins/SimpleStats/Plugin.cs index 189bddeac..b647d5b92 100644 --- a/Plugins/SimpleStats/Plugin.cs +++ b/Plugins/SimpleStats/Plugin.cs @@ -92,6 +92,7 @@ namespace StatsPlugin int deaths = clientStats.Sum(c => c.Deaths); double kdr = Math.Round(kills / (double)deaths, 2); double skill = Math.Round(clientStats.Sum(c => c.Skill) / clientStats.Count, 2); + double spm = Math.Round(clientStats.Sum(c => c.SPM), 1); double chestRatio = 0; double abdomenRatio = 0; @@ -135,6 +136,11 @@ namespace StatsPlugin Value = skill }, new ProfileMeta() + { + Key = "Score Per Minute", + Value = spm + }, + new ProfileMeta() { Key = "Chest Ratio", Value = chestRatio, diff --git a/Plugins/SimpleStats/StatsPlugin.csproj b/Plugins/SimpleStats/StatsPlugin.csproj index b7eefa518..9b478c4c3 100644 --- a/Plugins/SimpleStats/StatsPlugin.csproj +++ b/Plugins/SimpleStats/StatsPlugin.csproj @@ -150,7 +150,11 @@ SharedLibrary - + + + 1.1.2 + + copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\" diff --git a/SharedLibrary/Commands/NativeCommands.cs b/SharedLibrary/Commands/NativeCommands.cs index 32cb62d34..9b3a9b69f 100644 --- a/SharedLibrary/Commands/NativeCommands.cs +++ b/SharedLibrary/Commands/NativeCommands.cs @@ -424,9 +424,9 @@ namespace SharedLibrary.Commands if (newPerm == Player.Permission.Owner && E.Origin.Level != Player.Permission.Console) newPerm = Player.Permission.Banned; - if (newPerm == Player.Permission.Owner && !E.Owner.Config.AllowMultipleOwners) + if (newPerm == Player.Permission.Owner && !E.Owner.Manager.GetApplicationSettings().EnableMultipleOwners) { - await E.Origin.Tell("There can only be 1 owner. Modify your server configuration if multiple owners are required"); + await E.Origin.Tell("There can only be 1 owner. Modify your appsettings if multiple owners are required"); return; } @@ -1033,13 +1033,15 @@ namespace SharedLibrary.Commands #endif process.StartInfo.FileName = $"{process.StartInfo.WorkingDirectory}\\iw4x.exe"; process.StartInfo.Arguments = commandLine.Substring(6); - process.StartInfo.UserName = E.Owner.Config.RestartUsername; + + /*process.StartInfo.UserName = E.Owner.ServerConfig.RestartUsername; var pw = new System.Security.SecureString(); - foreach (char c in E.Owner.Config.RestartPassword) + foreach (char c in E.Owner.ServerConfig.RestartPassword) pw.AppendChar(c); process.StartInfo.Password = pw; + */ process.Start(); } diff --git a/SharedLibrary/Configuration/ApplicationConfiguration.cs b/SharedLibrary/Configuration/ApplicationConfiguration.cs new file mode 100644 index 000000000..2ff91c838 --- /dev/null +++ b/SharedLibrary/Configuration/ApplicationConfiguration.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SharedLibrary.Configuration +{ + public class ApplicationConfiguration + { + public bool EnableMultipleOwners { get; set; } + public bool EnableTrustedRank { get; set; } + public bool EnableClientVPNs { get; set; } + public bool EnableAntiCheat { get; set; } + public bool EnableDiscordLink { get; set; } + public string DiscordInviteCode { get; set; } + public string IPHubAPIKey { get; set; } + public List Servers { get; set; } + + } +} diff --git a/SharedLibrary/Configuration/ServerConfiguration.cs b/SharedLibrary/Configuration/ServerConfiguration.cs new file mode 100644 index 000000000..922f406c3 --- /dev/null +++ b/SharedLibrary/Configuration/ServerConfiguration.cs @@ -0,0 +1,9 @@ +namespace SharedLibrary.Configuration +{ + public class ServerConfiguration + { + public string IPAddress { get; set; } + public short Port { get; set; } + public string Password { get; set; } + } +} diff --git a/SharedLibrary/Interfaces/IManager.cs b/SharedLibrary/Interfaces/IManager.cs index f0e6aab33..421592e8c 100644 --- a/SharedLibrary/Interfaces/IManager.cs +++ b/SharedLibrary/Interfaces/IManager.cs @@ -3,6 +3,8 @@ using SharedLibrary.Objects; using SharedLibrary.Database.Models; using SharedLibrary.Services; using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using SharedLibrary.Configuration; namespace SharedLibrary.Interfaces { @@ -16,6 +18,7 @@ namespace SharedLibrary.Interfaces IList GetCommands(); IList GetMessageTokens(); IList GetActiveClients(); + ApplicationConfiguration GetApplicationSettings(); ClientService GetClientService(); AliasService GetAliasService(); PenaltyService GetPenaltyService(); diff --git a/SharedLibrary/Server.cs b/SharedLibrary/Server.cs index aebc96a2a..897f10ba9 100644 --- a/SharedLibrary/Server.cs +++ b/SharedLibrary/Server.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using SharedLibrary.Helpers; using SharedLibrary.Objects; using SharedLibrary.Dtos; +using SharedLibrary.Configuration; namespace SharedLibrary { @@ -30,11 +31,11 @@ namespace SharedLibrary public Server(Interfaces.IManager mgr, ServerConfiguration config) { Password = config.Password; - IP = config.IP; + IP = config.IPAddress; Port = config.Port; Manager = mgr; Logger = Manager.GetLogger(); - Config = config; + ServerConfig = config; Players = new List(new Player[18]); Reports = new List(); @@ -360,7 +361,7 @@ namespace SharedLibrary // Objects public Interfaces.IManager Manager { get; protected set; } public Interfaces.ILogger Logger { get; private set; } - public ServerConfiguration Config { get; private set; } + public ServerConfiguration ServerConfig { get; private set; } public List Maps { get; protected set; } public List Rules { get; protected set; } public List Reports { get; set; } diff --git a/SharedLibrary/ServerConfiguration.cs b/SharedLibrary/ServerConfiguration.cs deleted file mode 100644 index f819320ae..000000000 --- a/SharedLibrary/ServerConfiguration.cs +++ /dev/null @@ -1,23 +0,0 @@ -using SharedLibrary.Interfaces; - -namespace SharedLibrary -{ - public class ServerConfiguration : Serialize - { - public string IP; - public int Port; - public string Password; - public string FtpPrefix; - public bool AllowMultipleOwners; - public bool AllowTrustedRank; - public string RestartUsername; - public string RestartPassword; - public bool EnableAntiCheat; - public bool AllowClientVpn; - - public override string Filename() - { - return $"{Utilities.OperatingDirectory}config/servers/{IP}_{Port}.cfg"; - } - } -} diff --git a/SharedLibrary/SharedLibrary.csproj b/SharedLibrary/SharedLibrary.csproj index c1606a531..fb43854f3 100644 --- a/SharedLibrary/SharedLibrary.csproj +++ b/SharedLibrary/SharedLibrary.csproj @@ -146,6 +146,7 @@ + @@ -198,7 +199,7 @@ - + @@ -226,6 +227,9 @@ 6.2.0 + + 1.1.2 + 11.0.1 diff --git a/WebfrontCore/Application/ConfigurationGenerater.cs b/WebfrontCore/Application/ConfigurationGenerater.cs new file mode 100644 index 000000000..4603858d6 --- /dev/null +++ b/WebfrontCore/Application/ConfigurationGenerater.cs @@ -0,0 +1,96 @@ +using SharedLibrary; +using SharedLibrary.Configuration; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace IW4MAdmin +{ + class ConfigurationGenerator + { + public static List GenerateServerConfig(List configList) + { + + var newConfig = new ServerConfiguration(); + + while (string.IsNullOrEmpty(newConfig.IPAddress)) + { + try + { + Console.Write("Enter server IP Address: "); + string input = Console.ReadLine(); + IPAddress.Parse(input); + newConfig.IPAddress = input; + } + + catch (Exception) + { + continue; + } + } + + while (newConfig.Port == 0) + { + try + { + Console.Write("Enter server port: "); + newConfig.Port = Int16.Parse(Console.ReadLine()); + } + + catch (Exception) + { + continue; + } + + } + + Console.Write("Enter server RCON password: "); + newConfig.Password = Console.ReadLine(); + + configList.Add(newConfig); + + Console.Write("Configuration saved, add another? [y/n]:"); + if (Console.ReadLine().ToLower().First() == 'y') + GenerateServerConfig(configList); + + return configList; + } + + public static ApplicationConfiguration GenerateApplicationConfig() + { + var config = new ApplicationConfiguration(); + + Console.Write("Enable multiple owners? [y/n]: "); + config.EnableMultipleOwners = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y'; + + Console.Write("Enable trusted rank? [y/n]: "); + config.EnableTrustedRank = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y'; + + Console.Write("Enable server-side anti-cheat [y/n]: "); + config.EnableAntiCheat = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y'; + + Console.Write("Enable client VPNS [y/n]: "); + config.EnableClientVPNs = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y'; + + if (!config.EnableClientVPNs) + { + Console.Write("Enter iphub.info api key: "); + config.IPHubAPIKey = Console.ReadLine(); + } + + Console.Write("Display Discord link on webfront [y/n]: "); + config.EnableDiscordLink = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y'; + + if (config.EnableDiscordLink) + { + Console.Write("Enter Discord invite link: "); + config.DiscordInviteCode = Console.ReadLine(); + } + + return config; + } + } +} diff --git a/WebfrontCore/Application/Manager.cs b/WebfrontCore/Application/Manager.cs index 48e41bb77..a95d3a73f 100644 --- a/WebfrontCore/Application/Manager.cs +++ b/WebfrontCore/Application/Manager.cs @@ -13,6 +13,11 @@ using SharedLibrary.Exceptions; using SharedLibrary.Objects; using SharedLibrary.Services; using WebfrontCore.Application.API; +using Microsoft.Extensions.Configuration; +using WebfrontCore; +using SharedLibrary.Configuration; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace IW4MAdmin { @@ -32,6 +37,7 @@ namespace IW4MAdmin ClientService ClientSvc; AliasService AliasSvc; PenaltyService PenaltySvc; + IConfigurationRoot AppSettings; #if FTP_LOG const int UPDATE_FREQUENCY = 700; #else @@ -40,7 +46,7 @@ namespace IW4MAdmin private ApplicationManager() { - Logger = new Logger($@"{SharedLibrary.Utilities.OperatingDirectory}Logs{Path.DirectorySeparatorChar}IW4MAdmin.log"); + Logger = new Logger($@"{Utilities.OperatingDirectory}Logs{Path.DirectorySeparatorChar}IW4MAdmin.log"); _servers = new List(); Commands = new List(); TaskStatuses = new List(); @@ -52,6 +58,13 @@ namespace IW4MAdmin ServerEventOccurred += EventAPI.OnServerEventOccurred; } + private void BuildConfiguration() + { + AppSettings = new ConfigurationBuilder() + .AddJsonFile($"{AppDomain.CurrentDomain.BaseDirectory}IW4MAdminSettings.json") + .Build(); + } + public IList GetServers() { return Servers; @@ -95,15 +108,21 @@ namespace IW4MAdmin #endregion #region CONFIG - var Configs = Directory.EnumerateFiles($"{Program.OperatingDirectory}config/servers").Where(x => x.Contains(".cfg")); + BuildConfiguration(); + var settings = AppSettings.Get(); - if (Configs.Count() == 0) - ServerConfigurationGenerator.Generate(); - - foreach (var file in Configs) + if (settings == null) { - var Conf = ServerConfiguration.Read(file); + settings = ConfigurationGenerator.GenerateApplicationConfig(); + settings.Servers = ConfigurationGenerator.GenerateServerConfig(new List()); + var appConfigJSON = JsonConvert.SerializeObject(settings, Formatting.Indented); + File.WriteAllText($"{AppDomain.CurrentDomain.BaseDirectory}IW4MAdminSettings.json", appConfigJSON); + BuildConfiguration(); + } + + foreach (var Conf in settings.Servers) + { try { var ServerInstance = new IW4MServer(this, Conf); @@ -126,7 +145,7 @@ namespace IW4MAdmin catch (ServerException e) { - Logger.WriteError($"Not monitoring server {Conf.IP}:{Conf.Port} due to uncorrectable errors"); + Logger.WriteError($"Not monitoring server {Conf.IPAddress}:{Conf.Port} due to uncorrectable errors"); if (e.GetType() == typeof(DvarException)) Logger.WriteDebug($"Could not get the dvar value for {(e as DvarException).Data["dvar_name"]} (ensure the server has a map loaded)"); else if (e.GetType() == typeof(NetworkException)) @@ -260,5 +279,7 @@ namespace IW4MAdmin public ClientService GetClientService() => ClientSvc; public AliasService GetAliasService() => AliasSvc; public PenaltyService GetPenaltyService() => PenaltySvc; + + public ApplicationConfiguration GetApplicationSettings() => AppSettings.Get(); } } diff --git a/WebfrontCore/Application/Misc/VPNCheck.cs b/WebfrontCore/Application/Misc/VPNCheck.cs index 8fceb7376..9aadef511 100644 --- a/WebfrontCore/Application/Misc/VPNCheck.cs +++ b/WebfrontCore/Application/Misc/VPNCheck.cs @@ -9,7 +9,7 @@ namespace WebfrontCore.Application.Misc { public class VPNCheck { - public static async Task UsingVPN(string ip) + public static async Task UsingVPN(string ip, string apiKey) { #if DEBUG return false; @@ -18,7 +18,7 @@ namespace WebfrontCore.Application.Misc { using (var RequestClient = new System.Net.Http.HttpClient()) { - RequestClient.DefaultRequestHeaders.Add("X-Key", Startup.Configuration["VPN:APIKey"]); + RequestClient.DefaultRequestHeaders.Add("X-Key", apiKey); string response = await RequestClient.GetStringAsync($"http://v2.api.iphub.info/ip/{ip}"); var responseJson = JsonConvert.DeserializeObject(response); int blockType = Convert.ToInt32(responseJson["block"]); diff --git a/WebfrontCore/Application/Server.cs b/WebfrontCore/Application/Server.cs index 25c12baa7..3f000ef01 100644 --- a/WebfrontCore/Application/Server.cs +++ b/WebfrontCore/Application/Server.cs @@ -14,6 +14,7 @@ using SharedLibrary.Services; using SharedLibrary.Database.Models; using SharedLibrary.Dtos; using WebfrontCore.Application.Misc; +using SharedLibrary.Configuration; namespace IW4MAdmin { @@ -143,7 +144,8 @@ namespace IW4MAdmin await ExecuteEvent(new Event(Event.GType.Connect, "", player, null, this)); - if (Config.AllowClientVpn && await VPNCheck.UsingVPN(player.IPAddressString)) + if (!Manager.GetApplicationSettings().EnableClientVPNs && + await VPNCheck.UsingVPN(player.IPAddressString, Manager.GetApplicationSettings().IPHubAPIKey)) { await player.Kick("VPNs are not allowed on this server", new Player() { ClientId = 1 }); } @@ -621,7 +623,7 @@ namespace IW4MAdmin string logPath = (game.Value == "" || onelog?.Value == 1) ? $"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" : - $"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}"; + $"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{game.Value.Replace('/', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{logfile.Value}"; if (!File.Exists(logPath)) { @@ -661,7 +663,7 @@ namespace IW4MAdmin await E.Origin.Tell($"There are ^5{Reports.Count} ^7recent reports"); // give trusted rank - if (Config.AllowTrustedRank && + if (Manager.GetApplicationSettings().EnableTrustedRank && E.Origin.TotalConnectionTime / 60.0 >= 2880 && E.Origin.Level < Player.Permission.Trusted && E.Origin.Level != Player.Permission.Flagged) diff --git a/WebfrontCore/Application/ServerConfigurationGenerator.cs b/WebfrontCore/Application/ServerConfigurationGenerator.cs deleted file mode 100644 index 06272d354..000000000 --- a/WebfrontCore/Application/ServerConfigurationGenerator.cs +++ /dev/null @@ -1,90 +0,0 @@ -using SharedLibrary; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; - -namespace IW4MAdmin -{ - class ServerConfigurationGenerator - { - public static ServerConfiguration Generate() - { - string IP = String.Empty; - int Port = 0; - string Password; - bool AllowMultipleOwners; - bool AllowTrustedRank; - bool AntiCheat; - bool AllowVpns; - - while (IP == String.Empty) - { - try - { - Console.Write("Enter server IP: "); - string input = Console.ReadLine(); - IPAddress.Parse(input); - IP = input; - } - - catch (Exception) - { - continue; - } - } - - while (Port == 0) - { - try - { - Console.Write("Enter server port: "); - Port = Int32.Parse(Console.ReadLine()); - } - - catch (Exception) - { - continue; - } - } - - Console.Write("Enter server RCON password: "); - Password = Console.ReadLine(); - - Console.Write("Allow multiple owners? [y/n]: "); - AllowMultipleOwners = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y'; - - Console.Write("Allow trusted rank? [y/n]: "); - AllowTrustedRank = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y'; - - Console.Write("Allow server-side anti-cheat [y/n]: "); - AntiCheat = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y'; - - Console.Write("Allow client VPNS [y/n]: "); - AllowVpns = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y'; - - var config = new ServerConfiguration() - { - IP = IP, - Password = Password, - Port = Port, - AllowMultipleOwners = AllowMultipleOwners, - AllowTrustedRank = AllowTrustedRank, - RestartPassword = "", - RestartUsername = "", - EnableAntiCheat = AntiCheat, - AllowClientVpn = AllowVpns - }; - - config.Write(); - - Console.Write("Configuration saved, add another? [y/n]:"); - if (Console.ReadLine().ToLower().First() == 'y') - Generate(); - - return config; - } - } -} diff --git a/WebfrontCore/Controllers/BaseController.cs b/WebfrontCore/Controllers/BaseController.cs index f6c835df3..d841372d3 100644 --- a/WebfrontCore/Controllers/BaseController.cs +++ b/WebfrontCore/Controllers/BaseController.cs @@ -22,7 +22,7 @@ namespace WebfrontCore.Controllers Manager.AdministratorIPs.Contains(context.HttpContext.Connection.RemoteIpAddress.ToString().ConvertToIP()); ViewBag.Authorized = Authorized; ViewBag.Url = Startup.Configuration["Web:Address"]; - ViewBag.DiscordLink = Startup.Configuration["Discord:InviteLink"]; + ViewBag.DiscordLink = Manager.GetApplicationSettings().DiscordInviteCode; base.OnActionExecuting(context); } } diff --git a/WebfrontCore/IW4MAdminSettings.json b/WebfrontCore/IW4MAdminSettings.json new file mode 100644 index 000000000..e69de29bb diff --git a/WebfrontCore/Startup.cs b/WebfrontCore/Startup.cs index 0f738ab60..5b392f480 100644 --- a/WebfrontCore/Startup.cs +++ b/WebfrontCore/Startup.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using SharedLibrary.Configuration; namespace WebfrontCore { @@ -16,8 +17,7 @@ namespace WebfrontCore { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false) .AddEnvironmentVariables(); Configuration = builder.Build(); diff --git a/WebfrontCore/Views/Shared/_Layout.cshtml b/WebfrontCore/Views/Shared/_Layout.cshtml index 6c5571e51..2266d6020 100644 --- a/WebfrontCore/Views/Shared/_Layout.cshtml +++ b/WebfrontCore/Views/Shared/_Layout.cshtml @@ -34,9 +34,9 @@ - @if (ViewBag.DiscordLink != string.Empty) + @if (!string.IsNullOrEmpty(ViewBag.DiscordLink)) { - + }
diff --git a/WebfrontCore/WebfrontCore.csproj b/WebfrontCore/WebfrontCore.csproj index b278416e2..5ce3046d9 100644 --- a/WebfrontCore/WebfrontCore.csproj +++ b/WebfrontCore/WebfrontCore.csproj @@ -63,6 +63,12 @@ + + + PreserveNewest + + + diff --git a/WebfrontCore/appsettings.Release.json b/WebfrontCore/appsettings.Release.json deleted file mode 100644 index 138ffa654..000000000 --- a/WebfrontCore/appsettings.Release.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "Logging": { - "IncludeScopes": false, - "LogLevel": { - "Default": "Trace", - "System": "Information", - "Microsoft": "None" - } - }, - "Web": { - "Address": "127.0.0.1:5000" - }, - "VPN": { - "APIKey": "" - }, - "IW4MAdmin": { - }, - "Discord": { - "InviteLink" : "" - } -} diff --git a/WebfrontCore/appsettings.json b/WebfrontCore/appsettings.json index c9faf19b7..407850b38 100644 --- a/WebfrontCore/appsettings.json +++ b/WebfrontCore/appsettings.json @@ -9,13 +9,5 @@ }, "Web": { "Address": "http://127.0.0.1:5000" - }, - "VPN": { - "APIKey": "" - }, - "IW4MAdmin": { - }, - "Discord": { - "InviteLink" : "" } }