From bd99add43420f8217db11ba5960e55f5e57e9b91 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Tue, 6 Jun 2017 22:45:21 -0500 Subject: [PATCH] Enable/Disable fast restart plugin via config Deleted legacy connection & heartbeat classes Hopefully fixed issues relating to certain web requests throwing recoverable error Modified Serializer class slightly --- Admin/Connection.cs | 56 ------------------ Admin/Heartbeat.cs | 24 -------- Admin/IW4M ADMIN.csproj | 4 +- Admin/Kayak.cs | 7 +-- Admin/Manager.cs | 2 +- Admin/WebService.cs | 24 +++++--- Admin/lib/SharedLibrary.dll | Bin 104448 -> 104448 bytes Auto Restart Plugin/Main.cs | 2 + FastRestartPlugin/Plugin.cs | 48 ++++++++++++++- .../Exceptions/SerializationException.cs | 13 ++++ SharedLibrary/Interfaces/ISerializable.cs | 25 +++++--- SharedLibrary/Server.cs | 5 ++ SharedLibrary/SharedLibrary.csproj | 1 + Votemap Plugin/Plugin.cs | 2 + 14 files changed, 106 insertions(+), 107 deletions(-) delete mode 100644 Admin/Connection.cs delete mode 100644 Admin/Heartbeat.cs create mode 100644 SharedLibrary/Exceptions/SerializationException.cs diff --git a/Admin/Connection.cs b/Admin/Connection.cs deleted file mode 100644 index 53a5511f8..000000000 --- a/Admin/Connection.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Net; -using System.IO; - -namespace IW4MAdmin -{ - class Connection - { - public Connection(String Loc) - { - Location = Loc; - ConnectionHandle = WebRequest.Create(Location); - ConnectionHandle.Proxy = null; - ConnectionHandle.Timeout = 1000; - } - - public String Read() - { - try - { - WebResponse Resp = ConnectionHandle.GetResponse(); - StreamReader data_in = new StreamReader(Resp.GetResponseStream()); - String result = data_in.ReadToEnd(); - - data_in.Close(); - Resp.Close(); - - return result; - } - - catch (System.Net.WebException) - { - return null; - } - } - - public void Request(String data) - { - try - { - WebResponse Resp = WebRequest.Create(data).GetResponse(); - Resp.Close(); - } - - catch (System.Net.WebException) - { - return; - } - } - - private String Location; - private WebRequest ConnectionHandle; - } -} diff --git a/Admin/Heartbeat.cs b/Admin/Heartbeat.cs deleted file mode 100644 index ee9e61a7e..000000000 --- a/Admin/Heartbeat.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using SharedLibrary; - -namespace IW4MAdmin -{ - class Heartbeat - { - public Heartbeat(Server I) - { - Handle = new Connection("http://raidmax.org/IW4M/Admin"); - } - - public void Send(Server S) - { - String URI = String.Format("http://raidmax.org/IW4M/Admin/heartbeat.php?port={0}&name={1}&map={2}&players={3}&version={4}&gametype={5}&servercount={6}", S.getPort(), S.getName(), S.CurrentMap.Name, S.getPlayers().Count, IW4MAdmin.Program.Version.ToString(), S.Gametype, Manager.GetInstance().Servers); - // blind fire - Handle.Request(URI); - } - - private Connection Handle; - } -} diff --git a/Admin/IW4M ADMIN.csproj b/Admin/IW4M ADMIN.csproj index a5dbb33aa..eb618931e 100644 --- a/Admin/IW4M ADMIN.csproj +++ b/Admin/IW4M ADMIN.csproj @@ -124,8 +124,6 @@ - - @@ -334,6 +332,8 @@ copy /Y "$(TargetDir)$(TargetName).exe" "$(SolutionDir)BUILD" copy /Y "$(TargetDir)IW4MAdmin.exe.config" "$(SolutionDir)BUILD" copy /Y "$(ProjectDir)lib\Kayak.dll" "$(SolutionDir)BUILD\lib" +xcopy /Y /I /E "$(ProjectDir)webfront\*" "$(SolutionDir)BUILD\Webfront" + if $(ConfigurationName) == Release powershell.exe -file "$(SolutionDir)DEPLOY\publish_nightly.ps1" 1.3 if $(ConfigurationName) == Release-Stable powershell.exe -file "$(SolutionDir)DEPLOY\publish_stable.ps1" 1.3 diff --git a/Admin/Kayak.cs b/Admin/Kayak.cs index 62afd74bc..1e9f18cd4 100644 --- a/Admin/Kayak.cs +++ b/Admin/Kayak.cs @@ -18,7 +18,7 @@ namespace IW4MAdmin if (e.InnerException != null) { - Manager.GetInstance().Logger.WriteDebug($"Inner Execption: {e.InnerException.Message}"); + Manager.GetInstance().Logger.WriteDebug($"Inner Exception: {e.InnerException.Message}"); Manager.GetInstance().Logger.WriteDebug($"Inner Stack Trace: {e.InnerException.StackTrace}"); } @@ -34,14 +34,13 @@ namespace IW4MAdmin { public void OnRequest(HttpRequestHead request, IDataProducer requestBody, IHttpResponseDelegate response, string IP) { - // Program.getManager().mainLog.Write("HTTP request received", SharedLibrary.Log.Level.Debug); NameValueCollection querySet = new NameValueCollection(); if (request.QueryString != null) querySet = System.Web.HttpUtility.ParseQueryString(SharedLibrary.Utilities.removeNastyChars(request.QueryString)); querySet.Set("IP", IP); - SharedLibrary.HttpResponse requestedPage = WebService.getPage(request.Path, querySet, request.Headers); + SharedLibrary.HttpResponse requestedPage = WebService.GetPage(request.Path, querySet, request.Headers); var headers = new HttpResponseHead() { @@ -102,7 +101,7 @@ namespace IW4MAdmin public void OnError(Exception error) { - errorCallback(error); + errorCallback?.Invoke(error); } public void OnEnd() diff --git a/Admin/Manager.cs b/Admin/Manager.cs index ac72bff73..2bbb95074 100644 --- a/Admin/Manager.cs +++ b/Admin/Manager.cs @@ -102,7 +102,7 @@ namespace IW4MAdmin } - webServiceTask = WebService.getScheduler(); + webServiceTask = WebService.GetScheduler(); WebThread = new Thread(webServiceTask.Start) { diff --git a/Admin/WebService.cs b/Admin/WebService.cs index a705da826..eb3f31692 100644 --- a/Admin/WebService.cs +++ b/Admin/WebService.cs @@ -1,12 +1,12 @@ -using System; +using Kayak; +using Kayak.Http; +using SharedLibrary; +using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using Kayak; -using Kayak.Http; using System.Net; +using System.Text; using System.Threading; -using SharedLibrary; namespace IW4MAdmin { @@ -14,7 +14,7 @@ namespace IW4MAdmin { public static IServer webService; - public static IScheduler getScheduler() + public static IScheduler GetScheduler() { var webScheduler = Kayak.KayakScheduler.Factory.Create(new Scheduler()); webService = KayakServer.Factory.CreateHttp(new Request(), webScheduler); @@ -30,14 +30,14 @@ namespace IW4MAdmin SharedLibrary.WebService.pageList.Add(new ConsoleJSON()); SharedLibrary.WebService.pageList.Add(new PubbansJSON()); - Thread scheduleThread = new Thread(() => { scheduleThreadStart(webScheduler, webService); }); + Thread scheduleThread = new Thread(() => { ScheduleThreadStart(webScheduler, webService); }); scheduleThread.Name = "Web Service Thread"; scheduleThread.Start(); return webScheduler; } - private static void scheduleThreadStart(IScheduler S, IServer ss) + private static void ScheduleThreadStart(IScheduler S, IServer ss) { try { @@ -65,8 +65,14 @@ namespace IW4MAdmin } } - public static HttpResponse getPage(string path, System.Collections.Specialized.NameValueCollection queryset, IDictionary headers) + public static HttpResponse GetPage(string path, System.Collections.Specialized.NameValueCollection queryset, IDictionary headers) { + if (SharedLibrary.WebService.pageList == null || SharedLibrary.WebService.pageList.Count == 0) + return new HttpResponse() { content = "Error: page list not initialized!", contentType = "text/plaintext" }; + + if (path == null) + return new HttpResponse() { content = "Error: no path specified", contentType = "text/plaintext" }; + IPage requestedPage = SharedLibrary.WebService.pageList.Find(x => x.getPath().ToLower() == path.ToLower()); if (requestedPage != null) diff --git a/Admin/lib/SharedLibrary.dll b/Admin/lib/SharedLibrary.dll index 893619a94b100a17a17ac4108c89627508f81c92..6afb5283a85bcc3224b19bae237ba935d5cd873f 100644 GIT binary patch delta 19025 zcmb_^cYIXU*7n+GlF4LdGA%QcHc2K85<&^R%RmSqEfgtIBy_2X6F@P*OlX3DfEy`d zNkEz+AcID@=pD)%QIX#CA_gfJuSgTIP<+>3XEK>{uiW?hR;fgZJE8v_SVk?QiN zS#4?SQa+o_id%qg@#un0f^ax>8u>W@w(9m$*4)=iTA^jn`mX42g|l(KGnO?Pc7Ycq z6tgRQpQ9a5bG%7x8b(_rc4Jq3a}&?0*ahFvl-H!#3jk`B6kE6zw^mhgf81o4BQr1f zwCUwxY@%;#rbflC@(;5IvPs-fH=h;pXX*}M#rz}0Y1~k60GsX`Q?Gz^Jd0gH3Y+;1 zK$sLhbC}quGC!lJlv#<}LLCEj=I0c#XC9|*vSo<{_o{dWfHw0q*EUFDU-G&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%j4BHSw05kr308vv5kpJ`%YRdhsW)Zfs_O(&ebOPkR#FDB;_9Vg%cQm3> zCT|~>G>BlmoCjE9NGf{{TNiBov5mnt16wh+QfynX?ZkEn+j(riVEYqWh%S}IV5^F) zKDHceow4O(b6_jPwgB5Z*tTH%4BJ6$-(tIl?EyBeGxQ9rjjcVl{@5mCTY&9dY@cJh zfbAYOo&IOmPJfpb>d&xGu$|LKNDy|0rDJ;*TNi8v*k)r}h0TNQ9Jc$|tcEkJBev1l zO0ez3b{m^M{0wWDiO>z(Xlx6yeS+;Iwj0>=#xtxnwt?8@VB3i8xUq*67j%ZH%D;+a z(_5Bz>&7NojGeo!I=}tam3Hr5&wG@A`n!ka6(g8N%NCSh9mg`5A=n)0a + { + public bool Enabled; + } + + public class CEnableFastRestart : Command + { + public CEnableFastRestart() : base("frenable", "enable fast restarting at the end of a map. syntax: !fre", "fre", Player.Permission.SeniorAdmin, 0, false) { } + + public override async Task ExecuteAsync(Event E) + { + FastRestartPlugin.Config = new FastRestartConfig() { Enabled = true }; + Serialize.Write($"config/fastrestartconfig_{E.Owner}.cfg", FastRestartPlugin.Config); + await E.Origin.Tell("Fast restarting is now enabled for this server"); + } + } + + public class CDisableFastRestart : Command + { + public CDisableFastRestart() : base("fredisable", "disable fast restarting at the end of a map. syntax: !frd", "frd", Player.Permission.SeniorAdmin, 0, false) { } + + public override async Task ExecuteAsync(Event E) + { + FastRestartPlugin.Config = new FastRestartConfig() { Enabled = false }; + Serialize.Write($"config/fastrestartconfig_{E.Owner}.cfg", FastRestartPlugin.Config); + await E.Origin.Tell("Fast restarting is now disabled for this server"); + } + } + public class FastRestartPlugin : IPlugin { bool MatchEnded; DateTime MatchEndTime; + public static FastRestartConfig Config; - public string Name { get { return "Fast Restart"; } } + public string Name { get { return "Fast Restarter"; } } public float Version { get { return 1.0f; } } @@ -28,27 +58,39 @@ namespace Plugin try { await S.GetDvarAsync("scr_intermission_time"); + Config = Serialize.Read($"config/fastrestartconfig_{E.Owner}.cfg"); } catch (SharedLibrary.Exceptions.DvarException) { await S.ExecuteCommandAsync("set scr_intermission_time 20"); } + + catch (SharedLibrary.Exceptions.SerializeException) + { + Config = new FastRestartConfig() { Enabled = false }; + Serialize.Write($"config/fastrestartconfig_{E.Owner}.cfg", Config); + } } } - public async Task OnLoadAsync() + public Task OnLoadAsync() { + return null; } public async Task OnTickAsync(Server S) { + if (!Config.Enabled) + return; + MatchEnded = (await S.GetDvarAsync("scr_gameended")).Value == 1; if (MatchEnded && MatchEndTime == DateTime.MinValue) MatchEndTime = DateTime.Now; - if (MatchEnded && (DateTime.Now - MatchEndTime).TotalSeconds > (await S.GetDvarAsync("scr_intermission_time")).Value - 5) + // I'm pretty sure the timelength from game ended to scoreboard popup is 2000ms + if (MatchEnded && (DateTime.Now - MatchEndTime).TotalSeconds >= ((await S.GetDvarAsync("scr_intermission_time")).Value - 2)) { await S.ExecuteCommandAsync("fast_restart"); MatchEndTime = DateTime.MinValue; diff --git a/SharedLibrary/Exceptions/SerializationException.cs b/SharedLibrary/Exceptions/SerializationException.cs new file mode 100644 index 000000000..8d6fb1999 --- /dev/null +++ b/SharedLibrary/Exceptions/SerializationException.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharedLibrary.Exceptions +{ + public class SerializeException : Exception + { + public SerializeException(string msg) : base(msg) { } + } +} diff --git a/SharedLibrary/Interfaces/ISerializable.cs b/SharedLibrary/Interfaces/ISerializable.cs index c3fd65a31..12f996aa9 100644 --- a/SharedLibrary/Interfaces/ISerializable.cs +++ b/SharedLibrary/Interfaces/ISerializable.cs @@ -11,11 +11,6 @@ namespace SharedLibrary.Interfaces void Write(); } - public class SerializeException : Exception - { - public SerializeException(string msg) : base(msg) { } - } - public class Serialize : ISerializable { public static T Read(string filename) @@ -28,7 +23,7 @@ namespace SharedLibrary.Interfaces catch (Exception e) { - throw new SerializeException($"Could not desialize file {filename}: {e.Message}"); + throw new Exceptions.SerializeException($"Could not desialize file {filename}: {e.Message}"); } } @@ -42,10 +37,24 @@ namespace SharedLibrary.Interfaces catch (Exception e) { - throw new SerializeException($"Could not serialize file {Filename()}: {e.Message}"); + throw new Exceptions.SerializeException($"Could not serialize file {Filename()}: {e.Message}"); } } - public virtual string Filename() { return this.ToString(); } + public static void Write(string filename, T data) + { + try + { + string configText = Newtonsoft.Json.JsonConvert.SerializeObject(data); + File.WriteAllText(filename, configText); + } + + catch (Exception e) + { + throw new Exceptions.SerializeException($"Could not serialize file {filename}: {e.Message}"); + } + } + + public virtual string Filename() { return ToString(); } } } diff --git a/SharedLibrary/Server.cs b/SharedLibrary/Server.cs index 3ca22091e..7a12ba56a 100644 --- a/SharedLibrary/Server.cs +++ b/SharedLibrary/Server.cs @@ -421,6 +421,11 @@ namespace SharedLibrary ruleFile.Close(); } + public override string ToString() + { + return $"{IP}_{Port}"; + } + /// /// Load up the built in commands /// diff --git a/SharedLibrary/SharedLibrary.csproj b/SharedLibrary/SharedLibrary.csproj index 50076431a..e677ad20e 100644 --- a/SharedLibrary/SharedLibrary.csproj +++ b/SharedLibrary/SharedLibrary.csproj @@ -71,6 +71,7 @@ + diff --git a/Votemap Plugin/Plugin.cs b/Votemap Plugin/Plugin.cs index 25f062614..6fa00f2ad 100644 --- a/Votemap Plugin/Plugin.cs +++ b/Votemap Plugin/Plugin.cs @@ -6,6 +6,7 @@ using SharedLibrary.Network; using SharedLibrary.Interfaces; using System.Threading.Tasks; +#if DEBUG namespace Votemap_Plugin { /// @@ -305,3 +306,4 @@ namespace Votemap_Plugin } } } +#endif \ No newline at end of file