From 8a0b6c97317e22524a09b4a6e884aa4707166d18 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Wed, 15 Feb 2023 19:57:58 -0800 Subject: [PATCH] fix: Deletes unsupported WebStatus (#1341) --- Projects/UOContent/Misc/WebStatus.cs | 193 --------------------------- 1 file changed, 193 deletions(-) delete mode 100644 Projects/UOContent/Misc/WebStatus.cs diff --git a/Projects/UOContent/Misc/WebStatus.cs b/Projects/UOContent/Misc/WebStatus.cs deleted file mode 100644 index 0ca406f9b..000000000 --- a/Projects/UOContent/Misc/WebStatus.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Net; -using System.Text; -using Server.Guilds; -using Server.Network; - -namespace Server.Misc -{ - public class StatusPage : Timer - { - public static readonly bool Enabled = false; - - private static HttpListener _Listener; - - private static string _StatusPage = string.Empty; - private static byte[] _StatusBuffer = Array.Empty(); - - private static readonly object _StatusLock = new(); - - public StatusPage() : base(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds(60.0)) - { - } - - public static void Initialize() - { - if (!Enabled) - { - return; - } - - new StatusPage().Start(); - - Listen(); - } - - private static void Listen() - { - if (!HttpListener.IsSupported) - { - return; - } - - if (_Listener == null) - { - _Listener = new HttpListener(); - _Listener.Prefixes.Add("http://*:80/status/"); - _Listener.Start(); - } - else if (!_Listener.IsListening) - { - _Listener.Start(); - } - - if (_Listener.IsListening) - { - _Listener.BeginGetContext(ListenerCallback, null); - } - } - - private static void ListenerCallback(IAsyncResult result) - { - try - { - var context = _Listener.EndGetContext(result); - - byte[] buffer; - - lock (_StatusLock) - { - buffer = _StatusBuffer; - } - - context.Response.ContentLength64 = buffer.Length; - context.Response.OutputStream.Write(buffer, 0, buffer.Length); - context.Response.OutputStream.Close(); - } - catch - { - // ignored - } - - Listen(); - } - - private static string Encode(string input) - { - var sb = new StringBuilder(input); - - sb.Replace("&", "&"); - sb.Replace("<", "<"); - sb.Replace(">", ">"); - sb.Replace("\"", """); - sb.Replace("'", "'"); - - return sb.ToString(); - } - - protected override void OnTick() - { - if (!Directory.Exists("web")) - { - Directory.CreateDirectory("web"); - } - - using (var op = new StreamWriter("web/status.html")) - { - op.WriteLine(""); - op.WriteLine(""); - op.WriteLine(" "); - op.WriteLine($" {ServerList.ServerName} Server Status"); - op.WriteLine(" "); - op.WriteLine(" "); - op.WriteLine(" "); - op.WriteLine("

ModernUO Server Status

"); - op.WriteLine("

Online clients

"); - op.WriteLine(" "); - op.WriteLine( - " " - ); - - var index = 0; - - foreach (var m in TcpServer.Instances.Where(state => state.Mobile != null).Select(state => state.Mobile)) - { - ++index; - - var g = m.Guild as Guild; - - op.Write($" "); - } - - op.WriteLine(" "); - op.WriteLine("
NameLocationKillsKarma/Fame
"); - - if (g != null) - { - op.Write(Encode(m.Name)); - op.Write(" ["); - - var title = m.GuildTitle; - - title = title?.Trim() ?? string.Empty; - - if (title.Length > 0) - { - op.Write(Encode(title)); - op.Write(", "); - } - - op.Write(Encode(g.Abbreviation)); - - op.Write(']'); - } - else - { - op.Write(Encode(m.Name)); - } - - op.Write(""); - op.Write(m.X); - op.Write(", "); - op.Write(m.Y); - op.Write(", "); - op.Write(m.Z); - op.Write(" ("); - op.Write(m.Map); - op.Write(")"); - op.Write(m.Kills); - op.Write(""); - op.Write(m.Karma); - op.Write(" / "); - op.Write(m.Fame); - op.WriteLine("
"); - op.WriteLine(" "); - op.WriteLine(""); - } - - lock (_StatusLock) - { - _StatusPage = File.ReadAllText("web/status.html"); - _StatusBuffer = Encoding.UTF8.GetBytes(_StatusPage); - } - } - } -}