From e64a216cc05bc6f2216b500586a4f106b4b35a11 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Mon, 13 Nov 2017 15:58:23 -0600 Subject: [PATCH] Miscellanous fixes --- Admin/Kayak.cs | 60 +++-- Admin/Logger.cs | 9 +- Admin/Manager.cs | 13 +- Admin/Server.cs | 17 +- Admin/lib/SharedLibrary.dll | Bin 111104 -> 111104 bytes Admin/webfront/chat.html | 33 ++- Plugins/EventAPI/Plugin.cs | 20 +- Plugins/SimpleStats/Chat/ChatDatabase.cs | 10 +- Plugins/SimpleStats/Chat/ChatHistoryPage.cs | 2 +- Plugins/SimpleStats/Plugin.cs | 244 +++++++++++--------- SharedLibrary/RCON.cs | 15 +- 11 files changed, 260 insertions(+), 163 deletions(-) diff --git a/Admin/Kayak.cs b/Admin/Kayak.cs index 6fcd90716..6b55748e2 100644 --- a/Admin/Kayak.cs +++ b/Admin/Kayak.cs @@ -15,7 +15,7 @@ namespace IW4MAdmin { // it looks like there's a library error in // Kayak.Http.HttpServerTransactionDelegate.OnError - if ((uint)e.HResult ==0x80004003) + if ((uint)e.HResult == 0x80004003) return; ApplicationManager.GetInstance().Logger.WriteWarning("Web service has encountered an error - " + e.Message); @@ -77,19 +77,39 @@ namespace IW4MAdmin catch (Exception e) { - ApplicationManager.GetInstance().Logger.WriteError($"Webfront error during request"); - ApplicationManager.GetInstance().Logger.WriteDebug($"Message: {e.Message}"); - ApplicationManager.GetInstance().Logger.WriteDebug($"Stack Trace: {e.StackTrace}"); - - response.OnResponse(new HttpResponseHead() + if (e.GetType() == typeof(FormatException)) { - Status = "500 Internal Server Error", - Headers = new Dictionary() + ApplicationManager.GetInstance().Logger.WriteWarning("Request parameter data format was incorrect"); + ApplicationManager.GetInstance().Logger.WriteDebug($"Request Path {request.Path}"); + ApplicationManager.GetInstance().Logger.WriteDebug($"Request Query String {request.QueryString}"); + + response.OnResponse(new HttpResponseHead() + { + Status = "400 Bad Request", + Headers = new Dictionary() + { + { "Content-Type", "text/html" }, + { "Content-Length", "0"}, + } + }, new BufferedProducer("")); + } + + else + { + ApplicationManager.GetInstance().Logger.WriteError($"Webfront error during request"); + ApplicationManager.GetInstance().Logger.WriteDebug($"Message: {e.Message}"); + ApplicationManager.GetInstance().Logger.WriteDebug($"Stack Trace: {e.StackTrace}"); + + response.OnResponse(new HttpResponseHead() + { + Status = "500 Internal Server Error", + Headers = new Dictionary() { { "Content-Type", "text/html" }, { "Content-Length", "0"}, } - }, new BufferedProducer("")); + }, new BufferedProducer("")); + } } } } @@ -98,7 +118,7 @@ namespace IW4MAdmin { ArraySegment data; - public BufferedProducer(string data) : this(data, Encoding.UTF8) { } + public BufferedProducer(string data) : this(data, Encoding.ASCII) { } public BufferedProducer(string data, Encoding encoding) : this(encoding.GetBytes(data)) { } public BufferedProducer(byte[] data) : this(new ArraySegment(data)) { } @@ -109,8 +129,17 @@ namespace IW4MAdmin public IDisposable Connect(IDataConsumer channel) { - channel?.OnData(data, null); - channel?.OnEnd(); + try + { + channel?.OnData(data, null); + channel?.OnEnd(); + } + + catch (Exception) + { + + } + return null; } } @@ -129,19 +158,20 @@ namespace IW4MAdmin public bool OnData(ArraySegment data, Action continuation) { - buffer?.Add(data); + // this should hopefully clean the non ascii characters out. + buffer?.Add(new ArraySegment(Encoding.ASCII.GetBytes(Encoding.ASCII.GetString(data.ToArray())))); return false; } public void OnError(Exception error) { - errorCallback?.Invoke(error); + // errorCallback?.Invoke(error); } public void OnEnd() { var str = buffer - .Select(b => Encoding.UTF8.GetString(b.Array, b.Offset, b.Count)) + .Select(b => Encoding.ASCII.GetString(b.Array, b.Offset, b.Count)) .Aggregate((result, next) => result + next); resultCallback(str); diff --git a/Admin/Logger.cs b/Admin/Logger.cs index d31c3020c..51a71d4b0 100644 --- a/Admin/Logger.cs +++ b/Admin/Logger.cs @@ -15,7 +15,8 @@ namespace IW4MAdmin Info, Debug, Warning, - Error + Error, + Assert } string FileName; @@ -72,5 +73,11 @@ namespace IW4MAdmin { Write(msg, LogType.Warning); } + + public void WriteAssert(bool condition, string msg) + { + if (!condition) + Write(msg, LogType.Assert); + } } } diff --git a/Admin/Manager.cs b/Admin/Manager.cs index d84098341..bc928cd42 100644 --- a/Admin/Manager.cs +++ b/Admin/Manager.cs @@ -131,11 +131,14 @@ namespace IW4MAdmin catch (ServerException e) { - Logger.WriteWarning($"Not monitoring server {Conf.IP}:{Conf.Port} due to uncorrectable errors"); + Logger.WriteError($"Not monitoring server {Conf.IP}:{Conf.Port} due to uncorrectable errors"); if (e.GetType() == typeof(DvarException)) - Logger.WriteError($"Could not get the dvar value for {(e as DvarException).Data["dvar_name"]} (ensure the server has a map loaded)"); + 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)) - Logger.WriteError(e.Message); + { + Logger.WriteDebug(e.Message); + Logger.WriteDebug($"Internal Exception: {e.Data["internal_exception"]}"); + } } }); } @@ -148,7 +151,7 @@ namespace IW4MAdmin Commands.Add(new CQuit("quit", "quit IW4MAdmin", "q", Player.Permission.Owner, 0, false)); Commands.Add(new CKick("kick", "kick a player by name. syntax: !kick .", "k", Player.Permission.Trusted, 2, true)); Commands.Add(new CSay("say", "broadcast message to all players. syntax: !say .", "s", Player.Permission.Moderator, 1, false)); - Commands.Add(new CTempBan("tempban", "temporarily ban a player for 1 hour. syntax: !tempban .", "tb", Player.Permission.Moderator, 2, true)); + Commands.Add(new CTempBan("tempban", "temporarily ban a player for for specified time (defaults to 1 hour). syntax: !tempban