Exemple #1
0
 private void Handler(string type)
 {
     try
     {
         if (type == "inmemclans")
         {
             jsonapp = Convert.ToString(ObjectManager.GetInMemoryAlliances().Count);
         }
         else if (type == "inmemplayers")
         {
             jsonapp = Convert.ToString(ResourcesManager.GetInMemoryLevels().Count);
         }
         else if (type == "onlineplayers")
         {
             jsonapp = Convert.ToString(ResourcesManager.GetOnlinePlayers().Count);
         }
         else if (type == "totalclients")
         {
             jsonapp = Convert.ToString(ResourcesManager.GetConnectedClients().Count);
         }
         else if (type == "all")
         {
             var json = new JsonApi
             {
                 UCS = new Dictionary <string, string>
                 {
                     { "PatchingServer", ConfigurationManager.AppSettings["patchingServer"] },
                     { "Maintenance", ConfigurationManager.AppSettings["maintenanceMode"] },
                     { "MaintenanceTimeLeft", ConfigurationManager.AppSettings["maintenanceTimeLeft"] },
                     { "ClientVersion", ConfigurationManager.AppSettings["clientVersion"] },
                     { "ServerVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString() },
                     { "OnlinePlayers", Convert.ToString(ResourcesManager.GetOnlinePlayers().Count) },
                     { "InMemoryPlayers", Convert.ToString(ResourcesManager.GetInMemoryLevels().Count) },
                     { "InMemoryClans", Convert.ToString(ObjectManager.GetInMemoryAlliances().Count) },
                     { "TotalConnectedClients", Convert.ToString(ResourcesManager.GetConnectedClients().Count) }
                 }
             };
             jsonapp = JsonConvert.SerializeObject(json);
             mime    = "application/json";
         }
         else if (type == "ram")
         {
             jsonapp = Performances.GetUsedMemory();
         }
         else
         {
             jsonapp = "OK";
         }
     }
     catch (Exception ex)
     {
         jsonapp = "An exception occured in UCS : \n" + ex;
     }
 }
Exemple #2
0
 public static void JsonMain()
 {
     try
     {
         var ucsVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
         var f          = new JsonApi
         {
             Ucs = new Dictionary <string, string>
             {
                 /*
                  * Only disabled til it's implemented
                  *
                  * {"StartingLevel", ConfigurationManager.AppSettings["startingLevel"]},
                  * {"StartingExperience", ConfigurationManager.AppSettings["startingExperience"]},
                  */
                 { "StartingGems", ConfigurationManager.AppSettings["startingGems"] },
                 { "StartingGold", ConfigurationManager.AppSettings["startingGold"] },
                 { "StartingElixir", ConfigurationManager.AppSettings["startingElixir"] },
                 { "StartingDarkElixir", ConfigurationManager.AppSettings["startingDarkElixir"] },
                 { "StartingTrophies", ConfigurationManager.AppSettings["startingTrophies"] },
                 { "StartingShieldTime", ConfigurationManager.AppSettings["startingShieldTime"] },
                 { "PatchingServer", ConfigurationManager.AppSettings["patchingServer"] },
                 { "Maintenance", ConfigurationManager.AppSettings["maintenanceMode"] },
                 { "MaintenanceTimeLeft", ConfigurationManager.AppSettings["maintenanceTimeLeft"] },
                 //{"ServerPort", ConfigurationManager.AppSettings["serverPort"]},
                 { "ClientVersion", ConfigurationManager.AppSettings["clientVersion"] },
                 { "ServerVersion", ucsVersion },
                 { "LoggingLevel", ConfigurationManager.AppSettings["loggingLevel"] },
                 //{"OldClientVersion", ConfigurationManager.AppSettings["oldClientVersion"]},
                 { "DatabaseType", ConfigurationManager.AppSettings["databaseConnectionName"] },
                 //{"ExpertPVE", ConfigurationManager.AppSettings["expertPve"]},
                 //{"SaveThreadCount", ConfigurationManager.AppSettings["saveThreadCount"]},
                 { "OnlinePlayers", Convert.ToString(ResourcesManager.GetOnlinePlayers().Count) },
                 { "InMemoryPlayers", Convert.ToString(ResourcesManager.GetInMemoryLevels().Count) },
                 { "InMemoryClans", Convert.ToString(ObjectManager.GetInMemoryAlliances().Count) },
                 //{"TotalClans", Convert.ToString(ObjectManager.GetInMemoryAlliances().Count)},
                 { "TotalConnectedClients", Convert.ToString(ResourcesManager.GetConnectedClients().Count) }
             }
         };
         jsonapp = JsonConvert.SerializeObject(f);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Exception in jsonmain for  A.A.S : " + ex);
         var e = new JsonApiE
         {
             Error = new Dictionary <string, string>
             {
                 { "Issue", Convert.ToString(ex) },
             }
         };
         jsonapp = JsonConvert.SerializeObject(e);
     }
 }
Exemple #3
0
        public Menu()
        {
            while (true)
            {
                Console.WriteLine("");
                var line = Console.ReadLine();
                if (line == "/startx")
                {
                    m_vMaintance = true;
                    Application.Run(new UCSManager());
                }
                else if (line == "/stopucslist")
                {
                    Ucslist.Stop();
                }
                else if (line == "/reloadfilter")
                {
                    Console.WriteLine("Filter Has Been Reload");
                    Message.ReloadChatFilterList();
                }
                else if (line == "/shutdown")
                {
                    foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                    {
                        var p = new ShutdownStartedMessage(onlinePlayer.GetClient());
                        p.SetCode(5);
                        PacketManager.ProcessOutgoingPacket(p);
                    }
                    Console.WriteLine("Message has been send to the user");
                }
                else if (line == "/clear")
                {
                    Console.Clear();
                }
                else if (line == "/restart")
                {
                    var mail = new AllianceMailStreamEntry();
                    mail.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                    mail.SetSenderId(0);
                    mail.SetSenderAvatarId(0);
                    mail.SetSenderName("System Manager");
                    mail.SetIsNew(0);
                    mail.SetAllianceId(0);
                    mail.SetAllianceBadgeData(0);
                    mail.SetAllianceName("Legendary Administrator");
                    mail.SetMessage("System is about to restart in a few moments.");
                    mail.SetSenderLevel(500);
                    mail.SetSenderLeagueId(22);

                    foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                    {
                        var pm = new GlobalChatLineMessage(onlinePlayer.GetClient());
                        var ps = new ShutdownStartedMessage(onlinePlayer.GetClient());
                        var p  = new AvatarStreamEntryMessage(onlinePlayer.GetClient());
                        ps.SetCode(5);
                        p.SetAvatarStreamEntry(mail);
                        pm.SetChatMessage("System is about to restart in a few moments.");
                        pm.SetPlayerId(0);
                        pm.SetLeagueId(22);
                        pm.SetPlayerName("System Manager");
                        PacketManager.ProcessOutgoingPacket(p);
                        PacketManager.ProcessOutgoingPacket(ps);
                        PacketManager.ProcessOutgoingPacket(pm);
                    }
                    Console.WriteLine("System Restarting....");
                    Program.RestartProgram();
                }
                else if (line == "/update")
                {
                    var           downloadUrl = "";
                    Version       newVersion  = null;
                    var           aboutUpdate = "";
                    var           xmlUrl      = "https://www.flamewall.net/ucs/system.xml";
                    XmlTextReader reader      = null;
                    try
                    {
                        reader = new XmlTextReader(xmlUrl);
                        reader.MoveToContent();
                        var elementName = "";
                        if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "appinfo"))
                        {
                            while (reader.Read())
                            {
                                if (reader.NodeType == XmlNodeType.Element)
                                {
                                    elementName = reader.Name;
                                }
                                else
                                {
                                    if ((reader.NodeType == XmlNodeType.Text) && reader.HasValue)
                                    {
                                        switch (elementName)
                                        {
                                        case "version":
                                            newVersion = new Version(reader.Value);
                                            break;

                                        case "url":
                                            downloadUrl = reader.Value;
                                            break;

                                        case "about":
                                            aboutUpdate = reader.Value;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                    var applicationVersion = Assembly.GetExecutingAssembly().GetName().Version;
                    if (applicationVersion.CompareTo(newVersion) < 0)
                    {
                        var str =
                            string.Format(
                                "New version found!\nYour version: {0}.\nNewest version: {1}. \nAdded in this version: {2}. ",
                                applicationVersion, newVersion, aboutUpdate);
                        if (DialogResult.No !=
                            MessageBox.Show(str + "\nWould you like to download this update?", "Check for updates",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                        {
                            try
                            {
                                Process.Start(downloadUrl);
                            }
                            catch {}
                            return;
                        }
                        ;
                    }
                    else
                    {
                        MessageBox.Show("Your version: " + applicationVersion + "  is up to date.", "Check for Updates",
                                        MessageBoxButtons.OK, MessageBoxIcon.None);
                    }
                }
                else if (line == "/status")
                {
                    var hostName = Dns.GetHostName();
                    var IPM      = Dns.GetHostByName(hostName).AddressList[0].ToString();
                    Console.WriteLine("Server IP : " + IPM + " on port 9339");
                    Console.WriteLine("Online Player : " + ResourcesManager.GetOnlinePlayers().Count);
                    Console.WriteLine("Connected Player : " + ResourcesManager.GetConnectedClients().Count);
                    Console.WriteLine("Starting Gold : " + int.Parse(ConfigurationManager.AppSettings["StartingGold"]));
                    Console.WriteLine("Starting Elixir : " +
                                      int.Parse(ConfigurationManager.AppSettings["StartingElixir"]));
                    Console.WriteLine("Starting Dark Elixir : " +
                                      int.Parse(ConfigurationManager.AppSettings["StartingDarkElixir"]));
                    Console.WriteLine("Starting Gems : " + int.Parse(ConfigurationManager.AppSettings["StartingGems"]));
                    Console.WriteLine("CoC Version : " + ConfigurationManager.AppSettings["ClientVersion"]);
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["useCustomPatch"]))
                    {
                        Console.WriteLine("Patch : Active");
                        Console.WriteLine("Patching Server : " + ConfigurationManager.AppSettings["patchingServer"]);
                    }
                    else
                    {
                        Console.WriteLine("Patch : Disable");
                    }
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["maintenanceMode"]))
                    {
                        Console.WriteLine("Maintance Mode : Active");
                        Console.WriteLine("Maintance time : " +
                                          Convert.ToInt32(ConfigurationManager.AppSettings["maintenanceTimeleft"]) +
                                          " Seconds");
                    }
                    else
                    {
                        Console.WriteLine("Maintance Mode : Disable");
                    }
                }
                else if (line == "/sysinfo")
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Server Status is now sent to all online players");
                    var mail = new AllianceMailStreamEntry();
                    mail.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                    mail.SetSenderId(0);
                    mail.SetSenderAvatarId(0);
                    mail.SetSenderName("System Manager");
                    mail.SetIsNew(0);
                    mail.SetAllianceId(0);
                    mail.SetAllianceBadgeData(0);
                    mail.SetAllianceName("Legendary Administrator");
                    mail.SetMessage("Latest Server Status:\nConnected Players:" +
                                    ResourcesManager.GetConnectedClients().Count + "\nIn Memory Alliances:" +
                                    ObjectManager.GetInMemoryAlliances().Count + "\nIn Memory Levels:" +
                                    ResourcesManager.GetInMemoryLevels().Count);
                    mail.SetSenderLeagueId(22);
                    mail.SetSenderLevel(500);

                    foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                    {
                        var p  = new AvatarStreamEntryMessage(onlinePlayer.GetClient());
                        var pm = new GlobalChatLineMessage(onlinePlayer.GetClient());
                        pm.SetChatMessage("Our current Server Status is now sent at your mailbox!");
                        pm.SetPlayerId(0);
                        pm.SetLeagueId(22);
                        pm.SetPlayerName("System Manager");
                        p.SetAvatarStreamEntry(mail);
                        PacketManager.ProcessOutgoingPacket(p);
                        PacketManager.ProcessOutgoingPacket(pm);
                    }
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else if (line == "/help")
                {
                    MenuList();
                }
                else
                {
                    MenuList();
                }
            }
        }
Exemple #4
0
        private void Handle(IAsyncResult result)
        {
            HttpListener        listener = (HttpListener)result.AsyncState;
            HttpListenerContext context  = listener.EndGetContext(result);


            HttpListenerRequest request = context.Request;
            // Obtain a response object.
            HttpListenerResponse response = context.Response;
            // Construct a response.
            string responseString = "<HTML><BODY><PRE>";

            /*
             * responseString += "Active Connections: ";
             * int connectedUsers = 0;
             * foreach(var client in ResourcesManager.GetConnectedClients())
             * {
             *  var socket = client.Socket;
             *  if(socket != null)
             *  {
             *      try
             *      {
             *          bool part1 = socket.Poll(1000, SelectMode.SelectRead);
             *          bool part2 = (socket.Available == 0);
             *          if (!(part1 && part2))
             *              connectedUsers++;
             *      }
             *      catch(Exception){}
             *  }
             * }
             * responseString += connectedUsers + "\n";
             */
            responseString += "Established Connections: " + ResourcesManager.GetConnectedClients().Count + "\n";

            responseString += "<details><summary>";
            responseString += "In Memory Levels: " + ResourcesManager.GetInMemoryLevels().Count + "</summary>";
            foreach (var account in ResourcesManager.GetInMemoryLevels())
            {
                responseString += "    " + account.GetPlayerAvatar().GetId() + ", " + account.GetPlayerAvatar().GetAvatarName() + " \n";
            }
            responseString += "</details>";

            responseString += "<details><summary>";
            responseString += "Online Players: " + ResourcesManager.GetOnlinePlayers().Count + "</summary>";
            foreach (var account in ResourcesManager.GetOnlinePlayers())
            {
                responseString += "    " + account.GetPlayerAvatar().GetId() + ", " + account.GetPlayerAvatar().GetAvatarName() + " \n";
            }
            responseString += "</details>";

            responseString += "<details><summary>";
            responseString += "In Memory Alliances: " + ObjectManager.GetInMemoryAlliances().Count + "</summary>";
            foreach (var alliance in ObjectManager.GetInMemoryAlliances())
            {
                responseString += "    " + alliance.GetAllianceId() + ", " + alliance.GetAllianceName() + " \n";
            }
            responseString += "</details>";

            responseString += "</PRE></BODY></HTML>";
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
            // Get a response stream and write the response to it.
            response.ContentLength64 = buffer.Length;
            System.IO.Stream output = response.OutputStream;
            output.Write(buffer, 0, buffer.Length);
            // You must close the output stream.
            output.Close();
        }
Exemple #5
0
        public Menu()
        {
            while (true)
            {
                Console.WriteLine("");
                string line = Console.ReadLine();
                if (line == "/shutdown")
                {
                    foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                    {
                        var p = new ShutdownStartedMessage(onlinePlayer.GetClient());
                        p.SetCode(5);
                        PacketManager.ProcessOutgoingPacket(p);
                    }
                    Console.WriteLine("Message has been send to the user");
                }
                else if (line == "/clear")
                {
                    Console.Clear();
                }
                else if (line == "/restart")
                {
                    AllianceMailStreamEntry mail = new AllianceMailStreamEntry();
                    mail.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                    mail.SetSenderId(0);
                    mail.SetSenderAvatarId(0);
                    mail.SetSenderName("System Manager");
                    mail.SetIsNew(0);
                    mail.SetAllianceId(0);
                    mail.SetAllianceBadgeData(0);
                    mail.SetAllianceName("Legendary Administrator");
                    mail.SetMessage("System is about to restart in a few moments.");
                    mail.SetSenderLevel(500);
                    mail.SetSenderLeagueId(22);

                    foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                    {
                        var pm = new GlobalChatLineMessage(onlinePlayer.GetClient());
                        var ps = new ShutdownStartedMessage(onlinePlayer.GetClient());
                        var p  = new AvatarStreamEntryMessage(onlinePlayer.GetClient());
                        ps.SetCode(5);
                        p.SetAvatarStreamEntry(mail);
                        pm.SetChatMessage("System is about to restart in a few moments.");
                        pm.SetPlayerId(0);
                        pm.SetLeagueId(22);
                        pm.SetPlayerName("System Manager");
                        PacketManager.ProcessOutgoingPacket(p);
                        PacketManager.ProcessOutgoingPacket(ps);
                        PacketManager.ProcessOutgoingPacket(pm);
                    }
                    Console.WriteLine("System Restarting....");
                    System.Diagnostics.Process.Start(@"tools\ucs-restart.bat");
                }
                else if (line == "/status")
                {
                    string hostName = Dns.GetHostName();
                    string IPM      = Dns.GetHostByName(hostName).AddressList[0].ToString();
                    Console.WriteLine("Server IP : " + IPM + " on port 9339");
                    Console.WriteLine("Players Online : " + ResourcesManager.GetOnlinePlayers().Count);
                    Console.WriteLine("Starting Gold : " + Int32.Parse(ConfigurationManager.AppSettings["StartingGold"]));
                    Console.WriteLine("Starting Elixir : " + Int32.Parse(ConfigurationManager.AppSettings["StartingElixir"]));
                    Console.WriteLine("Starting Dark Elixir : " + Int32.Parse(ConfigurationManager.AppSettings["StartingDarkElixir"]));
                    Console.WriteLine("Starting Gems : " + Int32.Parse(ConfigurationManager.AppSettings["StartingGems"]));
                    Console.WriteLine("CoC Version : " + ConfigurationManager.AppSettings["ClientVersion"]);
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["useCustomPatch"]))
                    {
                        Console.WriteLine("Patch : Active");
                        Console.WriteLine("Patching Server : " + ConfigurationManager.AppSettings["patchingServer"]);
                    }
                    else
                    {
                        Console.WriteLine("Patch : Disable");
                    }
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["maintenanceMode"]))
                    {
                        Console.WriteLine("Maintance Mode : Active");
                        Console.WriteLine("Maintance time : " + (Convert.ToInt32(ConfigurationManager.AppSettings["maintenanceTimeleft"])) + " Seconds");
                    }
                    else
                    {
                        Console.WriteLine("Maintance Mode : Disable");
                    }
                }
                else if (line == "/sysinfo")
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Server Status is now sent to all online players");
                    AllianceMailStreamEntry mail = new AllianceMailStreamEntry();
                    mail.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                    mail.SetSenderId(0);
                    mail.SetSenderAvatarId(0);
                    mail.SetSenderName("System Manager");
                    mail.SetIsNew(0);
                    mail.SetAllianceId(0);
                    mail.SetAllianceBadgeData(0);
                    mail.SetAllianceName("Legendary Administrator");
                    mail.SetMessage("Latest Server Status:\nConnected Players:" + ResourcesManager.GetConnectedClients().Count + "\nIn Memory Alliances:" + ObjectManager.GetInMemoryAlliances().Count + "\nIn Memory Levels:" + ResourcesManager.GetInMemoryLevels().Count);
                    mail.SetSenderLeagueId(22);
                    mail.SetSenderLevel(500);

                    foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                    {
                        var p  = new AvatarStreamEntryMessage(onlinePlayer.GetClient());
                        var pm = new GlobalChatLineMessage(onlinePlayer.GetClient());
                        pm.SetChatMessage("Our current Server Status is now sent at your mailbox!");
                        pm.SetPlayerId(0);
                        pm.SetLeagueId(22);
                        pm.SetPlayerName("System Manager");
                        p.SetAvatarStreamEntry(mail);
                        PacketManager.ProcessOutgoingPacket(p);
                        PacketManager.ProcessOutgoingPacket(pm);
                    }
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else if (line == "/help")
                {
                    Console.WriteLine("");
                    Console.WriteLine("Available commands :");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("/restart - This commands restart server and sending online player info about it.");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("/shutdown - This commands fully close the server with message after five minutes.");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("/status - This commands show informations about the server.");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("/clear - Clean the emulator screen");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("/help - This commands show a list of available commands.");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("/sysinfo - This command will send the current Server Status to all online players.");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Console.WriteLine("");
                    Console.WriteLine("Available commands :");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("/restart - This commands restart server and sending online player info about it.");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("/shutdown - This commands fully close the server with message after five minutes.");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("/status - This commands show informations about the server.");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("/clear - Clean the emulator screen");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("/help - This commands show a list of available commands.");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("/sysinfo - This command will send the current Server Status to all online players.");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
        }
Exemple #6
0
        private void Handle(IAsyncResult result)
        {
            var direction = "";
            var requestip = (HttpWebRequest)WebRequest.Create("http://checkip.dyndns.org/");

            requestip.UserAgent =
                "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2573.0 Safari/537.36";
            requestip.Method  = "GET";
            requestip.Referer = "http://ultrapowa.com/";
            using (var stream = new StreamReader(requestip.GetResponse().GetResponseStream()))
                direction = stream.ReadToEnd();

            //Search for the ip in the html
            var first = direction.IndexOf("Address: ") + 9;
            var last  = direction.LastIndexOf("</body>");

            direction = direction.Substring(first, last - first);
            var listener = (HttpListener)result.AsyncState;
            var context  = listener.EndGetContext(result);

            var request = context.Request;

            // Obtain a response object.
            var response = context.Response;

            // Construct a response.
            var responseString = "<HTML><BODY><PRE>";

            responseString += "Active Connections: ";
            var connectedUsers = 0;

            foreach (var client in ResourcesManager.GetConnectedClients())
            {
                var socket = client.Socket;
                if (socket != null)
                {
                    try
                    {
                        var part1 = socket.Poll(1000, SelectMode.SelectRead);
                        var part2 = socket.Available == 0;
                        if (!(part1 && part2))
                        {
                            connectedUsers++;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debugger.WriteLine("Error in ApiManager : ", ex, 4, ConsoleColor.Red);
                    }
                }
            }
            responseString += connectedUsers + "\n";

            responseString += "Established Connections: " + ResourcesManager.GetConnectedClients().Count + "\n";

            responseString += "<details><summary>";
            responseString += "In Memory Levels: " + ResourcesManager.GetInMemoryLevels().Count + "</summary>";
            foreach (var account in ResourcesManager.GetInMemoryLevels())
            {
                responseString += "    " + account.GetPlayerAvatar().GetId() + ", " +
                                  account.GetPlayerAvatar().GetAvatarName() + " \n";
            }
            responseString += "</details>";

            responseString += "<details><summary>";
            responseString += "Online Players: " + ResourcesManager.GetOnlinePlayers().Count + "</summary>";
            foreach (var account in ResourcesManager.GetOnlinePlayers())
            {
                responseString += "    " + account.GetPlayerAvatar().GetId() + ", " +
                                  account.GetPlayerAvatar().GetAvatarName() + " \n";
            }
            responseString += "</details>";

            responseString += "<details><summary>";
            responseString += "In Memory Alliances: " + ObjectManager.GetInMemoryAlliances().Count + "</summary>";
            foreach (var alliance in ObjectManager.GetInMemoryAlliances())
            {
                responseString += "    " + alliance.GetAllianceId() + ", " + alliance.GetAllianceName() + " \n";
            }
            responseString += "</details>";

            var hostName = Dns.GetHostName();
            var LIP      = Dns.GetHostByName(hostName).AddressList[0].ToString();

            responseString += "<center><p>Current local ip: " + LIP + "</p></center>";
            responseString += "<center><p>Current public ip: " + direction + "</p></center>";
            responseString +=
                "<center><img src='https://d14.usercdn.com/i/02212/ea18nj5uxcll.png' style='width: 25%; height: 50%'></img></center></PRE></BODY></HTML>";
            var buffer = Encoding.UTF8.GetBytes(responseString);

            // Get a response stream and write the response to it.
            response.ContentLength64 = buffer.Length;
            var output = response.OutputStream;

            output.Write(buffer, 0, buffer.Length);

            // You must close the output stream.
            output.Close();
        }