From 40be4bdf4d479ec4e85c425dd9672c19ec346813 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Wed, 14 Mar 2018 13:22:04 -0500 Subject: [PATCH] more config updates --- .../Configuration/ApplicationConfiguration.cs | 5 +- .../Configuration/MapConfiguration.cs | 16 ++ SharedLibrary/Map.cs | 15 +- SharedLibrary/Server.cs | 69 +---- SharedLibrary/SharedLibrary.csproj | 1 + WebfrontCore/Application/Config/maps.cfg | 44 ---- WebfrontCore/Application/Config/messages.cfg | 8 - WebfrontCore/Application/Config/rules.cfg | 6 - .../Application/ConfigurationGenerater.cs | 1 - WebfrontCore/Application/Manager.cs | 13 +- WebfrontCore/Application/Server.cs | 11 +- WebfrontCore/IW4MAdminSettings.json | 241 ++++++++++++++++++ WebfrontCore/WebfrontCore.csproj | 2 +- 13 files changed, 285 insertions(+), 147 deletions(-) create mode 100644 SharedLibrary/Configuration/MapConfiguration.cs delete mode 100644 WebfrontCore/Application/Config/maps.cfg delete mode 100644 WebfrontCore/Application/Config/messages.cfg delete mode 100644 WebfrontCore/Application/Config/rules.cfg diff --git a/SharedLibrary/Configuration/ApplicationConfiguration.cs b/SharedLibrary/Configuration/ApplicationConfiguration.cs index 2ff91c838..74b964dc7 100644 --- a/SharedLibrary/Configuration/ApplicationConfiguration.cs +++ b/SharedLibrary/Configuration/ApplicationConfiguration.cs @@ -12,6 +12,9 @@ namespace SharedLibrary.Configuration public string DiscordInviteCode { get; set; } public string IPHubAPIKey { get; set; } public List Servers { get; set; } - + public int AutoMessagePeriod { get; set; } + public List AutoMessages { get; set; } + public List Rules { get; set; } + public List Maps { get; set; } } } diff --git a/SharedLibrary/Configuration/MapConfiguration.cs b/SharedLibrary/Configuration/MapConfiguration.cs new file mode 100644 index 000000000..db37b5f1a --- /dev/null +++ b/SharedLibrary/Configuration/MapConfiguration.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using static SharedLibrary.Server; + +namespace SharedLibrary.Configuration +{ + public class MapConfiguration + { + public Game Game { get; set; } + public List Maps { get; set; } + } +} diff --git a/SharedLibrary/Map.cs b/SharedLibrary/Map.cs index a41494a85..a527a8089 100644 --- a/SharedLibrary/Map.cs +++ b/SharedLibrary/Map.cs @@ -5,18 +5,9 @@ namespace SharedLibrary { public class Map { - public Map(String N, String A) - { - Name = N; - Alias = A; - } + public String Name { get; set; } + public String Alias { get; set; } - public String Name { get; private set; } - public String Alias { get; private set; } - - public override string ToString() - { - return Alias; - } + public override string ToString() => Alias; } } diff --git a/SharedLibrary/Server.cs b/SharedLibrary/Server.cs index 897f10ba9..4ba8122a2 100644 --- a/SharedLibrary/Server.cs +++ b/SharedLibrary/Server.cs @@ -39,13 +39,11 @@ namespace SharedLibrary Players = new List(new Player[18]); Reports = new List(); - PlayerHistory = new Queue(); + PlayerHistory = new Queue(); ChatHistory = new List(); - //Configuration = new ConfigurationManager(this.GetType()); NextMessage = 0; InitializeTokens(); InitializeAutoMessages(); - InitializeMaps(); InitializeRules(); } @@ -255,24 +253,7 @@ namespace SharedLibrary protected void InitializeMaps() { Maps = new List(); - - IFile mapfile = new IFile($"{Utilities.OperatingDirectory}config/maps.cfg"); - String[] _maps = mapfile.ReadAllLines(); - mapfile.Close(); - if (_maps.Length > 2) // readAll returns minimum one empty string - { - foreach (String m in _maps) - { - String[] m2 = m.Split(':'); - if (m2.Length > 1) - { - Map map = new Map(m2[0].Trim(), m2[1].Trim()); - Maps.Add(map); - } - } - } - else - Logger.WriteInfo("Maps configuration appears to be empty - skipping..."); + Maps.AddRange(Manager.GetApplicationSettings().Maps.First(m => m.Game == GameName).Maps); } /// @@ -283,34 +264,7 @@ namespace SharedLibrary { BroadcastMessages = new List(); - IFile messageCFG = new IFile($"{Utilities.OperatingDirectory}config/messages.cfg"); - String[] lines = messageCFG.ReadAllLines(); - messageCFG.Close(); - - if (lines.Length < 2) //readAll returns minimum one empty string - { - Logger.WriteInfo("Messages configuration appears empty - skipping..."); - return; - } - - int mTime = -1; - int.TryParse(lines[0], out mTime); - - if (MessageTime == -1) - MessageTime = 60; - else - MessageTime = mTime; - - foreach (String l in lines) - { - if (lines[0] != l && l.Length > 1) - BroadcastMessages.Add(l); - } - - messageCFG.Close(); - - //if (Program.Version != Program.latestVersion && Program.latestVersion != 0) - // messages.Add("^5IW4M Admin ^7is outdated. Please ^5update ^7to version " + Program.latestVersion); + BroadcastMessages.AddRange(Manager.GetApplicationSettings().AutoMessages); } /// @@ -321,21 +275,7 @@ namespace SharedLibrary { Rules = new List(); - IFile ruleFile = new IFile($"{Utilities.OperatingDirectory}config/rules.cfg"); - String[] _rules = ruleFile.ReadAllLines(); - ruleFile.Close(); - if (_rules.Length > 2) // readAll returns minimum one empty string - { - foreach (String r in _rules) - { - if (r.Length > 1) - Rules.Add(r); - } - } - else - Logger.WriteInfo("Rules configuration appears empty - skipping..."); - - ruleFile.Close(); + Rules.AddRange(Manager.GetApplicationSettings().Rules); } public ConfigurationManager Configuration { get; private set; } @@ -392,7 +332,6 @@ namespace SharedLibrary protected string IP; protected int Port; protected string FSGame; - protected int MessageTime; protected int NextMessage; protected int ConnectionErrors; protected List BroadcastMessages; diff --git a/SharedLibrary/SharedLibrary.csproj b/SharedLibrary/SharedLibrary.csproj index fb43854f3..4eff7270b 100644 --- a/SharedLibrary/SharedLibrary.csproj +++ b/SharedLibrary/SharedLibrary.csproj @@ -146,6 +146,7 @@ + diff --git a/WebfrontCore/Application/Config/maps.cfg b/WebfrontCore/Application/Config/maps.cfg deleted file mode 100644 index 14317d6b2..000000000 --- a/WebfrontCore/Application/Config/maps.cfg +++ /dev/null @@ -1,44 +0,0 @@ -mp_rust:Rust -mp_highrise:Highrise -mp_terminal:Terminal -mp_crash:Crash -mp_nightshift:Skidrow -mp_quarry:Quarry -mp_afghan:Afghan -mp_derail:Derail -mp_estate:Estate -mp_favela:Favela -mp_highrise:Highrise -mp_invasion:Invasion -mp_checkpoint:Karachi -mp_quarry:Quarry -mp_rundown:Rundown -mp_boneyard:Scrapyard -mp_nightshift:Skidrow -mp_subbase:Sub Base -mp_underpass:Underpass -mp_brecourt:Wasteland -mp_overgrown:Overgrown -mp_strike:Strike -mp_vacant:Vacant -mp_abandon:Carnival -mp_trailerpark:Trailer Park -mp_fuel2:Fuel -mp_storm:Storm -mp_complex:Bailout -mp_compact:Salvage -mp_nuked:Nuketown -iw4_credits:IW4 Credits -mp_killhouse:Killhouse -mp_bog_sh:Bog -mp_cargoship_sh:Freighter -mp_shipment:Shipment -mp_shipment_long:Shipment - Long -mp_rust_long:Rust - Long -mp_firingrange:Firing Range -mp_storm_spring:Chemical Plant -mp_fav_tropical:Favela - Tropical -mp_estate_tropical:Estate - Tropical -mp_crash_tropical:Crash - Tropical -mp_bloc_sh:Forgotten City -mp_raidmax:^1L^23^33^4T^5M^6A^75^8T^93^0R \ No newline at end of file diff --git a/WebfrontCore/Application/Config/messages.cfg b/WebfrontCore/Application/Config/messages.cfg deleted file mode 100644 index c72ab1b78..000000000 --- a/WebfrontCore/Application/Config/messages.cfg +++ /dev/null @@ -1,8 +0,0 @@ -60 -Over ^5{{TOTALPLAYTIME}} ^7man hours have been played on this server! -This server uses ^5IW4M Admin v{{VERSION}} ^7get it at ^5raidmax.org/IW4MAdmin -^5IW4M Admin ^7sees ^5YOU! -This server has harvested the information of ^5{{TOTALPLAYERS}} ^7players! -Cheaters are ^1unwelcome ^7 on this server -Did you know 8/10 people agree with unverified statistics? -^5{{TOTALKILLS}} ^7innocent people have been murdered in this server! \ No newline at end of file diff --git a/WebfrontCore/Application/Config/rules.cfg b/WebfrontCore/Application/Config/rules.cfg deleted file mode 100644 index 71e9fe9a8..000000000 --- a/WebfrontCore/Application/Config/rules.cfg +++ /dev/null @@ -1,6 +0,0 @@ -Cheating/Exploiting is not allowed -Respect other players -Administrators have the final say -No Racism or excessive trolling -Keep grenade launcher use to a minimum -Balance teams at ALL times \ No newline at end of file diff --git a/WebfrontCore/Application/ConfigurationGenerater.cs b/WebfrontCore/Application/ConfigurationGenerater.cs index 4603858d6..697900369 100644 --- a/WebfrontCore/Application/ConfigurationGenerater.cs +++ b/WebfrontCore/Application/ConfigurationGenerater.cs @@ -44,7 +44,6 @@ namespace IW4MAdmin { continue; } - } Console.Write("Enter server RCON password: "); diff --git a/WebfrontCore/Application/Manager.cs b/WebfrontCore/Application/Manager.cs index a95d3a73f..1aeababa9 100644 --- a/WebfrontCore/Application/Manager.cs +++ b/WebfrontCore/Application/Manager.cs @@ -111,12 +111,17 @@ namespace IW4MAdmin BuildConfiguration(); var settings = AppSettings.Get(); - if (settings == null) + if (settings?.Servers == null) { - settings = ConfigurationGenerator.GenerateApplicationConfig(); - settings.Servers = ConfigurationGenerator.GenerateServerConfig(new List()); + var newSettings = ConfigurationGenerator.GenerateApplicationConfig(); + newSettings.Servers = ConfigurationGenerator.GenerateServerConfig(new List()); + newSettings.AutoMessagePeriod = settings.AutoMessagePeriod; + newSettings.AutoMessages = settings.AutoMessages; + newSettings.Rules = settings.Rules; + newSettings.Maps = settings.Maps; + settings = newSettings; - var appConfigJSON = JsonConvert.SerializeObject(settings, Formatting.Indented); + var appConfigJSON = JsonConvert.SerializeObject(newSettings, Formatting.Indented); File.WriteAllText($"{AppDomain.CurrentDomain.BaseDirectory}IW4MAdminSettings.json", appConfigJSON); BuildConfiguration(); } diff --git a/WebfrontCore/Application/Server.cs b/WebfrontCore/Application/Server.cs index 3f000ef01..36e85375c 100644 --- a/WebfrontCore/Application/Server.cs +++ b/WebfrontCore/Application/Server.cs @@ -465,7 +465,7 @@ namespace IW4MAdmin playerCountStart = DateTime.Now; } - if (LastMessage.TotalSeconds > MessageTime && BroadcastMessages.Count > 0 && ClientNum > 0) + if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().AutoMessagePeriod && BroadcastMessages.Count > 0 && ClientNum > 0) { await Broadcast(Utilities.ProcessMessageToken(Manager.GetMessageTokens(), BroadcastMessages[NextMessage])); NextMessage = NextMessage == (BroadcastMessages.Count - 1) ? 0 : NextMessage + 1; @@ -588,8 +588,10 @@ namespace IW4MAdmin Website = "this server's website"; } + InitializeMaps(); + this.Hostname = hostname.Value.StripColors(); - this.CurrentMap = Maps.Find(m => m.Name == mapname.Value) ?? new Map(mapname.Value, mapname.Value); + this.CurrentMap = Maps.Find(m => m.Name == mapname.Value) ?? new Map() { Alias = mapname.Value, Name = mapname.Value }; this.MaxClients = maxplayers.Value; this.FSGame = game.Value; @@ -619,7 +621,7 @@ namespace IW4MAdmin } #endif - string mainPath = (GameName == Game.IW4 && onelog.Value >=0) ? "userraw" : "main"; + string mainPath = (GameName == Game.IW4 && onelog.Value >= 0) ? "userraw" : "main"; string logPath = (game.Value == "" || onelog?.Value == 1) ? $"{basepath.Value.Replace('\\', Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{mainPath}{Path.DirectorySeparatorChar}{logfile.Value}" : @@ -643,7 +645,6 @@ namespace IW4MAdmin Logger.WriteInfo($"Log file is {logPath}"); #if !DEBUG await Broadcast("IW4M Admin is now ^2ONLINE"); - #endif } @@ -753,7 +754,7 @@ namespace IW4MAdmin FSGame = (await this.GetDvarAsync("fs_game")).Value.StripColors(); string mapname = this.GetDvarAsync("mapname").Result.Value; - CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map(mapname, mapname); + CurrentMap = Maps.Find(m => m.Name == mapname) ?? new Map() { Alias = mapname, Name = mapname }; // todo: make this more efficient ((ApplicationManager)(Manager)).AdministratorIPs = (await new GenericRepository().FindAsync(c => c.Level > Player.Permission.Trusted)) diff --git a/WebfrontCore/IW4MAdminSettings.json b/WebfrontCore/IW4MAdminSettings.json index e69de29bb..007e4e4fe 100644 --- a/WebfrontCore/IW4MAdminSettings.json +++ b/WebfrontCore/IW4MAdminSettings.json @@ -0,0 +1,241 @@ +{ + "AutoMessagePeriod": 60, + "AutoMessages": [ + "Over ^5{{TOTALPLAYTIME}} ^7man hours have been played on this server!", + "This server uses ^5IW4M Admin v{{VERSION}} ^7get it at ^5raidmax.org/IW4MAdmin", + "^5IW4M Admin ^7sees ^5YOU!", + "This server has harvested the information of ^5{{TOTALPLAYERS}} ^7players!", + "Cheaters are ^1unwelcome ^7 on this server", + "Did you know 8/10 people agree with unverified statistics?", + "^5{{TOTALKILLS}} ^7innocent people have been murdered in this server!" + ], + "Rules": [ + "Cheating/Exploiting is not allowed", + "Respect other players", + "Administrators have the final say", + "No Racism or excessive trolling", + "Keep grenade launcher use to a minimum", + "Balance teams at ALL times" + ], + "Maps": [ + { + "Game": "IW4", + "Maps": [ + { + "Alias": "Rust", + "Name": "mp_rust" + }, + + { + "Alias": "Highrise", + "Name": "mp_highrise" + }, + + { + "Alias": "Terminal", + "Name": "mp_terminal" + }, + + { + "Alias": "Crash", + "Name": "mp_crash" + }, + + { + "Alias": "Skidrow", + "Name": "mp_nightshift" + }, + + { + "Alias": "Quarry", + "Name": "mp_quarry" + }, + + { + "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": "IW4 Credits", + "Name": "iw4_credits" + }, + + { + "Alias": "Killhouse", + "Name": "mp_killhouse" + }, + + { + "Alias": "Bog", + "Name": "mp_bog_sh" + }, + + { + "Alias": "Freighter", + "Name": "mp_cargoship_sh" + }, + + { + "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": "Favela - Tropical", + "Name": "mp_fav_tropical" + }, + + { + "Alias": "Estate - Tropical", + "Name": "mp_estate_tropical" + }, + + { + "Alias": "Crash - Tropical", + "Name": "mp_crash_tropical" + }, + + { + "Alias": "Forgotten City", + "Name": "mp_bloc_sh" + } + ] + } + ] +} \ No newline at end of file diff --git a/WebfrontCore/WebfrontCore.csproj b/WebfrontCore/WebfrontCore.csproj index 5ce3046d9..35289b27b 100644 --- a/WebfrontCore/WebfrontCore.csproj +++ b/WebfrontCore/WebfrontCore.csproj @@ -70,7 +70,7 @@ - +