private static void InitUCS() { if (!Directory.Exists("logs")) { Console.WriteLine("Folder \"logs/\" does not exist. Let me create one.."); Directory.CreateDirectory("logs"); } if (Convert.ToBoolean(Utils.parseConfigString("UCSList"))) { Ucslist.Start(); } new ResourcesManager(); new ObjectManager(); new Gateway().Start(); if (Convert.ToBoolean(Utils.parseConfigString("apiManager"))) { new ApiManager(); } if (Convert.ToBoolean(Utils.parseConfigString("apiManagerPro"))) { if (ConfigurationManager.AppSettings["ApiKey"] == "ucs") { var ch = Utils.GenerateApi(); ConfigurationManager.AppSettings.Set("ApiKey", ch); Console.WriteLine("Your Random API key : {0}", ch); } var ws = new ApiManagerPro(ApiManagerPro.SendResponse, "http://+:" + Utils.ParseConfigInt("proDebugPort") + "/" + Utils.parseConfigString("ApiKey") + "/"); Console.WriteLine("Your API key : {0}", Utils.parseConfigString("ApiKey")); ws.Run(); } Debugger.SetLogLevel(Utils.ParseConfigInt("loggingLevel")); Logger.SetLogLevel(Utils.ParseConfigInt("loggingLevel")); InitProgramThreads(); if (Utils.ParseConfigInt("loggingLevel") >= 5) { Debugger.WriteLine("\t", null, 5); Debugger.WriteLine("Played ID's:", null, 5, ConsoleColor.Cyan); ResourcesManager.GetAllPlayerIds() .ForEach(id => Debugger.WriteLine("\t" + id, null, 5, ConsoleColor.Cyan)); Debugger.WriteLine("\t", null, 5); } Console.WriteLine("Server started on port " + Port + ". Let's play Clash of Clans!"); if (Convert.ToBoolean(Utils.parseConfigString("consoleCommand"))) { new Menu(); } else { Application.Run(new UCSManager()); } }
public void Save(Alliance alliance) { Debugger.WriteLine("Starting saving clan " + alliance.GetAllianceName() + " from memory to database at " + DateTime.Now); using (var context = new ucsdbEntities(m_vConnectionString)) { context.Configuration.AutoDetectChangesEnabled = false; context.Configuration.ValidateOnSaveEnabled = false; var c = context.clan.Find((int)alliance.GetAllianceId()); if (c != null) { c.LastUpdateTime = DateTime.Now; c.Data = alliance.SaveToJSON(); context.Entry(c).State = EntityState.Modified; } else { context.clan.Add( new clan { ClanId = alliance.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = alliance.SaveToJSON() } ); } context.SaveChanges(); Debugger.WriteLine("Finished saving clan " + alliance.GetAllianceName() + " from memory to database at " + DateTime.Now); } }
/// <summary> /// Loader of the ObjectManager class, which is neccessary for all UCS functionality. /// </summary> public ObjectManager() { m_vTimerCanceled = false; m_vDatabase = new DatabaseManager(); NpcLevels = new Dictionary <int, string>(); DataTables = new DataTables(); m_vAlliances = new Dictionary <long, Alliance>(); LoadFingerPrint(); using (var sr = new StreamReader(@"Gamefiles/starting_home.json")) m_vHomeDefault = sr.ReadToEnd(); m_vDatabase.CheckConnection(); m_vAvatarSeed = m_vDatabase.GetMaxPlayerId() + 1; m_vAllianceSeed = m_vDatabase.GetMaxAllianceId() + 1; LoadGameFiles(); LoadNpcLevels(); Debugger.WriteLine("[UCS] Loading and saving all alliances to memory"); GetAllAlliancesFromDB(); //Prevent UpdateLeague error due to UpdateLeague using CSV var TimerItem = new Timer(Save, null, 30000, 30000); new Timer(Restart, null, 10800000, 0); TimerReference = TimerItem; m_vRandomSeed = new Random(); Console.WriteLine("[UCS] Database Sync started successfully"); }
public ApiManagerPro(string[] prefixes, Func <HttpListenerRequest, string> method) { try { if (!HttpListener.IsSupported) { throw new NotSupportedException( "Windows XP SP2, Server 2003 or higher needed.Please Disable Api Manager"); } if (prefixes == null || prefixes.Length == 0) { throw new ArgumentException("prefixes"); } if (method == null) { throw new ArgumentException("method"); } foreach (var s in prefixes) { _listener.Prefixes.Add(s); } _responderMethod = method; _listener.Start(); } catch (Exception e) { Debugger.WriteLine("Exception at ApiManagerPro", e, 4, ConsoleColor.DarkRed); } }
private void PacketProcessing() { while (m_vIsRunning) { m_vWaitHandle.WaitOne(); Message p; while (m_vPackets.TryDequeue(out p)) { var pl = p.Client.GetLevel(); var player = ""; if (pl != null) { player += " (" + pl.GetPlayerAvatar().GetId() + ", " + pl.GetPlayerAvatar().GetAvatarName() + ")"; } try { Debugger.WriteLine("[R] " + p.GetMessageType() + " " + p.GetType().Name + player); p.Decode(); p.Process(pl); //Debugger.WriteLine("finished processing of message " + p.GetType().Name + player); } catch (Exception ex) { Debugger.WriteLine( "An exception occured during processing of message " + p.GetType().Name + player, ex, 4, ConsoleColor.Red); } } } }
/// <summary> /// This function return all alliances in database, in a list<>. /// </summary> /// <returns> /// Return a list<> containing all alliances. /// </returns> public List <Alliance> GetAllAlliances() { var alliances = new List <Alliance>(); try { using (var db = new ucsdbEntities(m_vConnectionString)) { var a = db.clan; var count = 0; foreach (var c in a) { var alliance = new Alliance(); alliance.LoadFromJSON(c.Data); alliances.Add(alliance); if (count++ >= 200) { break; } } } } catch (Exception ex) { Debugger.WriteLine("[UCS] An exception occured during GetAlliance processing:", ex); } return(alliances); }
/// <summary> /// This function process packets. /// </summary> void PacketProcessing() { while (m_vIsRunning) { m_vWaitHandle.WaitOne(); Message p; while (m_vPackets.TryDequeue(out p)) { var pl = p.Client.GetLevel(); var player = ""; if (pl != null) { player += " (" + pl.GetPlayerAvatar().GetId() + ", " + pl.GetPlayerAvatar().GetAvatarName() + ")"; } try { Debugger.WriteLine("[UCS] Processing " + p.GetType().Name + player); p.Decode(); p.Process(pl); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Debugger.WriteLine( "[UCS] An exception occured during processing of message " + p.GetType().Name + player, ex); Console.ResetColor(); } } } }
/// <summary> /// This function create a new player in the database, with default parameters. /// </summary> /// <param name="l">The level of the player.</param> public void CreateAccount(Level l) { try { Debugger.WriteLine("[UCS][UCSDB] Saving new account to database (player id: " + l.GetPlayerAvatar().GetId() + ")"); using (var db = new ucsdbEntities(m_vConnectionString)) { db.player.Add( new player { PlayerId = l.GetPlayerAvatar().GetId(), AccountStatus = l.GetAccountStatus(), AccountPrivileges = l.GetAccountPrivileges(), LastUpdateTime = l.GetTime(), IPAddress = l.GetIPAddress(), Avatar = l.GetPlayerAvatar().SaveToJSON(), GameObjects = l.SaveToJSON() } ); db.SaveChanges(); } } catch (Exception ex) { Debugger.WriteLine("[UCS][UCSDB] An exception occured during CreateAccount processing :", ex); } }
public ConcurrentDictionary <long, Level> GetAllPlayers() { ConcurrentDictionary <long, Level> players = new ConcurrentDictionary <long, Level>(); try { using (ucsdbEntities db = new ucsdbEntities(m_vConnectionString)) { DbSet <player> a = db.player; int count = 0; foreach (player c in a) { Level pl = new Level(); players.TryAdd(pl.GetPlayerAvatar().GetId(), pl); if (count++ >= 500) { break; } } Debugger.WriteLine("[UCS] The server loaded " + count + " players"); } } catch (Exception ex) { Debugger.WriteLine("[UCS] An exception occured during GetPlayers processing:", ex); } return(players); }
/// <summary> /// This function return all alliances in database, in a list<>. /// </summary> /// <returns> /// Return a list<> containing all alliances. /// </returns> public List <Alliance> GetAllAlliances() { List <Alliance> alliances = new List <Alliance>(); try { using (ucsdbEntities db = new ucsdbEntities(m_vConnectionString)) { DbSet <clan> a = db.clan; int count = 0; foreach (clan c in a) { Alliance alliance = new Alliance(); alliance.LoadFromJSON(c.Data); alliances.Add(alliance); if (count++ >= 500) { break; } } Debugger.WriteLine("[UCS] The server loaded " + count + " alliances"); } } catch (Exception ex) { Debugger.WriteLine("[UCS] An exception occured during GetAlliance processing:", ex); } return(alliances); }
public Level GetAccount(long playerId) { Level level = null; try { using (ucsdbEntities ucsdbEntities = new ucsdbEntities(this.m_vConnectionString)) { player player = ucsdbEntities.player.Find(new object[] { playerId }); if (player != null) { level = new Level(); level.SetAccountStatus(player.AccountStatus); level.SetAccountPrivileges(player.AccountPrivileges); level.SetTime(player.LastUpdateTime); level.SetIPAddress(player.IPAddress); level.GetPlayerAvatar().LoadFromJSON(player.Avatar); level.LoadFromJSON(player.GameObjects); } } } catch (Exception ex) { Debugger.WriteLine("[CRS] An exception occured during GetAccount processing :", ex, 4); } return(level); }
/// <summary> /// This function get the player data. /// </summary> /// <param name="playerId">The (int64) ID of the player.</param> /// <returns>The level of the player.</returns> public Level GetAccount(long playerId) { Level account = null; try { using (var db = new ucsdbEntities(m_vConnectionString)) { var p = db.player.Find(playerId); if (p != null) { account = new Level(); account.SetAccountStatus(p.AccountStatus); account.SetAccountPrivileges(p.AccountPrivileges); account.SetTime(p.LastUpdateTime); account.SetIPAddress(p.IPAddress); account.GetPlayerAvatar().LoadFromJSON(p.Avatar); account.LoadFromJSON(p.GameObjects); } } } catch (Exception ex) { Debugger.WriteLine("[UCS][UCSDB] An exception occured during GetAccount processing :", ex); } return(account); }
public Alliance GetAlliance(long allianceId) { Alliance alliance = null; try { using (ucsdbEntities ucsdbEntities = new ucsdbEntities(this.m_vConnectionString)) { clan clan = ucsdbEntities.clan.Find(new object[] { allianceId }); if (clan != null) { alliance = new Alliance(); alliance.LoadFromJSON(clan.Data); } } } catch (Exception ex) { Debugger.WriteLine("[CRS] An exception occured during GetAlliance processing :", ex, 4); } return(alliance); }
public void Save(List <Level> avatars) { Debugger.WriteLine("[M] Starting saving players from memory to database at " + DateTime.Now.ToString()); try { using (var context = new Database.ucsdbEntities(m_vConnectionString)) { context.Configuration.AutoDetectChangesEnabled = false; context.Configuration.ValidateOnSaveEnabled = false; int transactionCount = 0; foreach (Level pl in avatars) { lock (pl) { var p = context.player.Find(pl.GetPlayerAvatar().GetId()); if (p != null) { p.LastUpdateTime = pl.GetTime(); p.AccountStatus = pl.GetAccountStatus(); p.AccountPrivileges = pl.GetAccountPrivileges(); p.Avatar = pl.GetPlayerAvatar().SaveToJSON(); p.GameObjects = pl.SaveToJSON(); context.Entry(p).State = EntityState.Modified; } else { context.player.Add( new Database.player { PlayerId = pl.GetPlayerAvatar().GetId(), AccountStatus = pl.GetAccountStatus(), AccountPrivileges = pl.GetAccountPrivileges(), LastUpdateTime = pl.GetTime(), Avatar = pl.GetPlayerAvatar().SaveToJSON(), GameObjects = pl.SaveToJSON() } ); } } transactionCount++; if (transactionCount >= 500) { context.SaveChanges(); transactionCount = 0; } } context.SaveChanges(); } Debugger.WriteLine("[D] Finished saving players from memory to database at " + DateTime.Now.ToString()); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Debugger.WriteLine("[W] An exception occured during Save processing for avatars:", ex); Console.ResetColor(); } }
public void Save(List <Level> avatars) { try { using (ucsdbEntities ucsdbEntities = new ucsdbEntities(this.m_vConnectionString)) { ucsdbEntities.Configuration.AutoDetectChangesEnabled = false; ucsdbEntities.Configuration.ValidateOnSaveEnabled = false; int num = 0; foreach (Level current in avatars) { Level obj = current; lock (obj) { player player = ucsdbEntities.player.Find(new object[] { current.GetPlayerAvatar().GetId() }); if (player != null) { player.LastUpdateTime = current.GetTime(); player.AccountStatus = current.GetAccountStatus(); player.AccountPrivileges = current.GetAccountPrivileges(); player.IPAddress = current.GetIPAddress(); player.Avatar = current.GetPlayerAvatar().SaveToJSON(); player.GameObjects = current.SaveToJSON(); ucsdbEntities.Entry <player>(player).State = System.Data.Entity.EntityState.Modified; } else { ucsdbEntities.player.Add(new player { PlayerId = current.GetPlayerAvatar().GetId(), AccountStatus = current.GetAccountStatus(), AccountPrivileges = current.GetAccountPrivileges(), LastUpdateTime = current.GetTime(), IPAddress = current.GetIPAddress(), Avatar = current.GetPlayerAvatar().SaveToJSON(), GameObjects = current.SaveToJSON() }); } } } num++; if (num >= 500) { ucsdbEntities.SaveChanges(); num = 0; } ucsdbEntities.SaveChanges(); } } catch (Exception ex) { Debugger.WriteLine("[CRS] An exception occured during Save processing for avatars :", ex, 4); } }
public void Save(List <Level> avatars) { try { using (var context = new ucsdbEntities(m_vConnectionString)) { context.Configuration.AutoDetectChangesEnabled = false; context.Configuration.ValidateOnSaveEnabled = false; var transactionCount = 0; foreach (var pl in avatars) { lock (pl) { var p = context.player.Find(pl.GetPlayerAvatar().GetId()); if (p != null) { p.LastUpdateTime = pl.GetTime(); p.AccountStatus = pl.GetAccountStatus(); p.AccountPrivileges = pl.GetAccountPrivileges(); p.IPAddress = pl.GetIPAddress(); p.Avatar = pl.GetPlayerAvatar().SaveToJSON(); p.GameObjects = pl.SaveToJSON(); context.Entry(p).State = EntityState.Modified; } else { context.player.Add( new player { PlayerId = pl.GetPlayerAvatar().GetId(), AccountStatus = pl.GetAccountStatus(), AccountPrivileges = pl.GetAccountPrivileges(), LastUpdateTime = pl.GetTime(), IPAddress = pl.GetIPAddress(), Avatar = pl.GetPlayerAvatar().SaveToJSON(), GameObjects = pl.SaveToJSON() } ); } } } transactionCount++; if (transactionCount >= 500) { context.SaveChanges(); transactionCount = 0; } context.SaveChanges(); } Debugger.WriteLine("[UCS][UCSDB] All players in memory has been saved to database at " + DateTime.Now); } catch (Exception ex) { Debugger.WriteLine("[UCS][UCSDB] An exception occured during Save processing for avatars :", ex); } }
public void Save(List <Alliance> alliances) { Debugger.WriteLine("[M] Starting saving alliances from memory to database at " + DateTime.Now.ToString()); try { using (var context = new Database.ucsdbEntities(m_vConnectionString)) { context.Configuration.AutoDetectChangesEnabled = false; context.Configuration.ValidateOnSaveEnabled = false; int transactionCount = 0; foreach (Alliance alliance in alliances) { lock (alliance) { var c = context.clan.Find((int)alliance.GetAllianceId()); if (c != null) { c.LastUpdateTime = DateTime.Now; c.Data = alliance.SaveToJSON(); context.Entry(c).State = EntityState.Modified; } else { context.clan.Add( new Database.clan { ClanId = alliance.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = alliance.SaveToJSON() } ); } } transactionCount++; if (transactionCount >= 500) { context.SaveChanges(); transactionCount = 0; } } context.SaveChanges(); } Debugger.WriteLine("[D] Finished saving alliances from memory to database at " + DateTime.Now.ToString()); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Debugger.WriteLine("[W] An exception occured during Save processing for alliances:", ex); Console.ResetColor(); } }
/// <summary> /// This function save a specific alliance in the database. /// </summary> /// <param name="alliances">The Alliance of the alliance.</param> public void Save(List <Alliance> alliances) { try { using (var context = new ucsdbEntities(m_vConnectionString)) { context.Configuration.AutoDetectChangesEnabled = false; context.Configuration.ValidateOnSaveEnabled = false; var transactionCount = 0; foreach (var alliance in alliances) { lock (alliance) { var c = context.clan.Find((int)alliance.GetAllianceId()); if (c != null) { c.LastUpdateTime = DateTime.Now; c.Data = alliance.SaveToJSON(); context.Entry(c).State = EntityState.Modified; } else { context.clan.Add( new clan { ClanId = alliance.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = alliance.SaveToJSON() } ); } } } transactionCount++; if (transactionCount >= 500) { context.SaveChanges(); context.SaveChanges(); context.SaveChanges(); transactionCount = 0; } context.SaveChanges(); } Debugger.WriteLine("[UCS] All alliances in memory has been saved to database at " + DateTime.Now); } catch (Exception ex) { Debugger.WriteLine("[UCS] An exception occured during Save processing for alliances :", ex); } }
public void Save(List <Alliance> alliances) { try { using (ucsdbEntities ucsdbEntities = new ucsdbEntities(this.m_vConnectionString)) { ucsdbEntities.Configuration.AutoDetectChangesEnabled = false; ucsdbEntities.Configuration.ValidateOnSaveEnabled = false; int num = 0; foreach (Alliance current in alliances) { Alliance obj = current; lock (obj) { clan clan = ucsdbEntities.clan.Find(new object[] { (int)current.GetAllianceId() }); if (clan != null) { clan.LastUpdateTime = DateTime.Now; clan.Data = current.SaveToJSON(); ucsdbEntities.Entry <clan>(clan).State = System.Data.Entity.EntityState.Modified; } else { ucsdbEntities.clan.Add(new clan { ClanId = current.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = current.SaveToJSON() }); } } } num++; if (num >= 500) { ucsdbEntities.SaveChanges(); num = 0; } ucsdbEntities.SaveChanges(); } } catch (Exception ex) { Debugger.WriteLine("[CRS] An exception occured during Save processing for alliances :", ex, 4); } }
private static void InitProgramThreads() { Debugger.WriteLine("\t", null, 5); Debugger.WriteLine("Server Thread's:", null, 5, ConsoleColor.Blue); var programThreads = new List <Thread>(); for (var i = 0; i < int.Parse(ConfigurationManager.AppSettings["programThreadCount"]); i++) { var pt = new ProgramThread(); programThreads.Add(new Thread(pt.Start)); programThreads[i].Start(); Debugger.WriteLine("\tServer Running On Thread " + i, null, 5, ConsoleColor.Blue); } Console.ResetColor(); }
public static void DropClient(long socketHandle) { try { Client client; ResourcesManager.m_vClients.TryRemove(socketHandle, out client); if (client.GetLevel() != null) { ResourcesManager.LogPlayerOut(client.GetLevel()); } } catch (Exception ex) { Debugger.WriteLine("[CRS] Error dropping client: ", ex, 4); } }
public static void DropClient(long socketHandle) { try { Client c; m_vClients.TryRemove(socketHandle, out c); if (c.GetLevel() != null) { LogPlayerOut(c.GetLevel()); } } catch (Exception ex) { Debugger.WriteLine("Error when droping client \t : ", ex, 4, ConsoleColor.Red); } }
/// <summary> /// This function drop a client from m_vClients list. /// </summary> /// <param name="socketHandle">The (Int64) SocketHandle ID of the client.</param> public static void DropClient(long socketHandle) { /* TEMPORARY AS CLIENTS CAN ISSUE A CRASH IF NOT DROPPED PROPERLY */ try { Client c; m_vClients.TryRemove(socketHandle, out c); if (c.GetLevel() != null) { LogPlayerOut(c.GetLevel()); } } catch (Exception e) { Debugger.WriteLine("[UCS] Error dropping client: ", e, 4); } }
public ApiManagerPro(string[] prefixes, Func <HttpListenerRequest, string> method) { try { foreach (var s in prefixes) { _listener.Prefixes.Add(s); } _responderMethod = method; _listener.Start(); } catch (Exception e) { Debugger.WriteLine("Exception at ApiManagerPro: ", e, 4); } }
public void Save(Level avatar) { Debugger.WriteLine( "Starting saving player " + avatar.GetPlayerAvatar().GetAvatarName() + " from memory to database at " + DateTime.Now, null, 5, ConsoleColor.DarkGreen); var context = new ucsdbEntities(m_vConnectionString); context.Configuration.AutoDetectChangesEnabled = false; context.Configuration.ValidateOnSaveEnabled = false; context = avatar.SaveToDatabse(context); context.SaveChanges(); Debugger.WriteLine( "Finished saving player " + avatar.GetPlayerAvatar().GetAvatarName() + " from memory to database at " + DateTime.Now, null, 5, ConsoleColor.DarkGreen); }
/// <summary> /// This function drop a client from m_vClients list. /// </summary> /// <param name="socketHandle">The (Int64) SocketHandle ID of the client.</param> public static void DropClient(long socketHandle) { try { Client c; m_vClients.TryRemove(socketHandle, out c); if (c.GetLevel() != null) { LogPlayerOut(c.GetLevel()); } } catch (Exception e) { Debugger.WriteLine("[UCS] Error dropping client: ", e, 4); } }
private static void CheckClients() { foreach (var c in GetConnectedClients()) { if (!c.IsClientSocketConnected()) { DropClient(c.GetSocketHandle()); try { c.Socket.Shutdown(SocketShutdown.Both); c.Socket.Close(); } catch (Exception ex) { Debugger.WriteLine("Error when dropping client.. : ", ex, 4, ConsoleColor.Red); } } } }
public void CreateAlliance(Alliance a) { try { using (ucsdbEntities ucsdbEntities = new ucsdbEntities(this.m_vConnectionString)) { ucsdbEntities.clan.Add(new clan { ClanId = a.GetAllianceId(), LastUpdateTime = DateTime.Now, Data = a.SaveToJSON() }); ucsdbEntities.SaveChanges(); } } catch (Exception ex) { Debugger.WriteLine("[CRS] An exception occured during CreateAlliance processing :", ex, 4); } }
/// <summary> /// This function save a specific player in the database. /// </summary> /// <param name="avatar">The level of the player.</param> public void Save(Level avatar) { Debugger.WriteLine( "Starting saving player " + avatar.GetPlayerAvatar().GetAvatarName() + " from memory to database at " + DateTime.Now, null, 4); var context = new ucsdbEntities(m_vConnectionString); context.Configuration.AutoDetectChangesEnabled = false; context.Configuration.ValidateOnSaveEnabled = false; var p = context.player.Find(avatar.GetPlayerAvatar().GetId()); if (p != null) { p.LastUpdateTime = avatar.GetTime(); p.AccountStatus = avatar.GetAccountStatus(); p.AccountPrivileges = avatar.GetAccountPrivileges(); p.IPAddress = avatar.GetIPAddress(); p.Avatar = avatar.GetPlayerAvatar().SaveToJSON(); p.GameObjects = avatar.SaveToJSON(); context.Entry(p).State = EntityState.Modified; } else { context.player.Add( new player { PlayerId = avatar.GetPlayerAvatar().GetId(), AccountStatus = avatar.GetAccountStatus(), AccountPrivileges = avatar.GetAccountPrivileges(), LastUpdateTime = avatar.GetTime(), IPAddress = avatar.GetIPAddress(), Avatar = avatar.GetPlayerAvatar().SaveToJSON(), GameObjects = avatar.SaveToJSON() } ); } context.SaveChanges(); Debugger.WriteLine( "Finished saving player " + avatar.GetPlayerAvatar().GetAvatarName() + " from memory to database at " + DateTime.Now, null, 4); }
public void Run() { try { ThreadPool.QueueUserWorkItem(o => { try { Console.WriteLine("Pro API Manager : Online"); while (_listener.IsListening) { ThreadPool.QueueUserWorkItem(c => { var ctx = c as HttpListenerContext; try { Debugger.WriteLine("New API Request!", null, 5); var rstr = _responderMethod(ctx.Request); var buf = Encoding.UTF8.GetBytes(rstr); ctx.Response.ContentLength64 = buf.Length; ctx.Response.OutputStream.Write(buf, 0, buf.Length); } finally { ctx.Response.OutputStream.Close(); } }, _listener.GetContext()); } } catch (Exception ex) { Console.WriteLine("APIManagerPro : Error when starting API => " + ex); } }); } catch (Exception ex) { Console.WriteLine("Exception in run at A.A.S : " + ex); } }