/// <summary> /// Dispose all background worker for the thread to dispose. /// </summary> public static void Dispose() { if (Listener != null) { Listener.Dispose(); } if (RCONListener != null) { RCONListener.Dispose(); } if (SCONListener != null) { SCONListener.Dispose(); } NancyImpl.Stop(); if (Logger != null) { Logger.Dispose(); } }
public void Initialize() { Logging.WriteLine("█▀▀▀█ █ █ █ █ █ ▀ █▀▀▀ █ █ ▀▀█▀▀", ConsoleColor.Yellow); Logging.WriteLine("▀▀▀▄▄ █▀▄ █▄▄█ █ ▀█▀ █ ▀█ █▀▀█ █ ", ConsoleColor.Yellow); Logging.WriteLine("█▄▄▄█ ▀ ▀ ▄▄▄█ ▀▀▀ ▀▀▀ ▀▀▀▀ ▀ ▀ ▀ ", ConsoleColor.Yellow); Logging.WriteLine(Skylight.Version, ConsoleColor.Yellow); Logging.WriteBlank(); Logging.WriteLine(Licence.WelcomeMessage, ConsoleColor.Green); Logging.WriteBlank(); try { Skylight.ServerStarted = Stopwatch.StartNew(); Skylight.ConfigurationData = new ConfigurationData("config.conf"); Logging.Write("Connecting to database... ", ConsoleColor.White); try { DatabaseServer DatabaseServer = new DatabaseServer(Skylight.GetConfig()["db.hostname"], uint.Parse(Skylight.GetConfig()["db.port"]), Skylight.GetConfig()["db.username"], Skylight.GetConfig()["db.password"]); Database Database = new Database(Skylight.GetConfig()["db.name"], uint.Parse(Skylight.GetConfig()["db.pool.minsize"]), uint.Parse(Skylight.GetConfig()["db.pool.maxsize"])); Skylight.DatabaseManager = new DatabaseManager(DatabaseServer, Database); using (DatabaseClient dbClient = Skylight.DatabaseManager.GetClient()) { //WHAT AN LOVLY COMMAND WE HAVE OVER HERE! =D dbClient.ExecuteQuery(@"DROP PROCEDURE IF EXISTS parse_activity_points; CREATE PROCEDURE parse_activity_points(bound VARCHAR(255), bound2 VARCHAR(255)) BEGIN DECLARE id INT DEFAULT 0; DECLARE value TEXT; DECLARE occurance INT DEFAULT 0; DECLARE i INT DEFAULT 0; DECLARE splitted_value TEXT; DECLARE splitted_value_2 TEXT; DECLARE splitted_value_3 TEXT; DECLARE done INT DEFAULT 0; DECLARE cur1 CURSOR FOR SELECT users.id, users.activity_points FROM users; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; DROP TEMPORARY TABLE IF EXISTS activity_points_parsed_data; CREATE TEMPORARY TABLE activity_points_parsed_data(`id` INT NOT NULL,`value` VARCHAR(255) NOT NULL,`value2` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`,`value`)) ENGINE=Memory; OPEN cur1; read_loop: LOOP FETCH cur1 INTO id, value; IF done THEN LEAVE read_loop; END IF; SET occurance = (SELECT LENGTH(value) - LENGTH(REPLACE(value, bound, '')) +1); SET i=1; WHILE i <= occurance DO SET splitted_value = (SELECT REPLACE(SUBSTRING(SUBSTRING_INDEX(value, bound, i), LENGTH(SUBSTRING_INDEX(value, bound, i - 1)) + 1), bound, '')); SET splitted_value_2 = (SELECT REPLACE(SUBSTRING(SUBSTRING_INDEX(splitted_value, bound2, 1), LENGTH(SUBSTRING_INDEX(splitted_value, bound2, 1 - 1)) + 1), bound2, '')); SET splitted_value_3 = (SELECT REPLACE(SUBSTRING(SUBSTRING_INDEX(splitted_value, bound2, 2), LENGTH(SUBSTRING_INDEX(splitted_value, bound2, 2 - 1)) + 1), bound2, '')); IF splitted_value_3 = '' THEN SET splitted_value_3 = splitted_value_2, splitted_value_2 = '0'; END IF; INSERT INTO activity_points_parsed_data VALUES (id, splitted_value_2, splitted_value_3) ON DUPLICATE KEY UPDATE value2 = value2 + splitted_value_3; SET i = i + 1; END WHILE; END LOOP; CLOSE cur1; END;"); } } catch (MySqlException ex) { Logging.WriteLine("failed!", ConsoleColor.Red); Skylight.ExceptionShutdown(ex); return; } Logging.WriteLine("completed!", ConsoleColor.Green); Skylight.LateQueryManager = new LateQueryManager(); Skylight.PublicToken = new BigInteger(DiffieHellman.GenerateRandomHexString(15), 16).ToString(); Skylight.HabboCrypto = new HabboCrypto(n, e, d); using (DatabaseClient dbClient = Skylight.GetDatabaseManager().GetClient()) { dbClient.AddParamWithValue("bannerData", Skylight.HabboCrypto.Prime + ":" + Skylight.HabboCrypto.Generator); dbClient.ExecuteQuery("UPDATE users SET online = '0'; UPDATE rooms SET users_now = '0'; UPDATE server_settings SET banner_data = @bannerData;"); } Skylight.TargetRevision = RevisionUtilies.StringToRevision(Skylight.GetConfig()["game.revision"]); Skylight.MultiRevisionSupport = TextUtilies.StringToBool(Skylight.GetConfig()["game.mrs.enabled"]); Skylight.PacketManager = BasicUtilies.GetRevisionPacketManager(Skylight.Revision); //needed for stuff Skylight.PacketManager.Initialize(); Skylight.Game = new Game(); Skylight.Game.Init(); if (Skylight.GetConfig()["game.efpfr.enabled"] == "1") { Skylight.ExternalFlashPolicyFileRequestPort = true; Skylight.FlashPolicyFileRequestListener = new FlashPolicyFileRequestListener(Skylight.GetConfig()["game.efpfr.bindip"], int.Parse(Skylight.GetConfig()["game.efpfr.port"])); Skylight.FlashPolicyFileRequestListener.Start(); } Skylight.SocketsManager = new SocketsManager(Skylight.GetConfig()["game.tcp.bindip"], int.Parse(Skylight.GetConfig()["game.tcp.port"]), int.Parse(Skylight.GetConfig()["game.tcp.conlimit"])); foreach (string key in Skylight.ConfigurationData.GetChildKeys("game.tcp.extra")) { Skylight.SocketsManager.AddListener(new SocketsListener(Skylight.SocketsManager, Skylight.GetConfig()["game.tcp.extra." + key + ".bindip"], int.Parse(Skylight.GetConfig()["game.tcp.extra." + key + ".port"]), RevisionUtilies.StringToRevision(Skylight.GetConfig()["game.tcp.extra." + key + ".revision"]), RevisionUtilies.StringToCrypto(Skylight.GetConfig().TryGet("game.tcp.extra." + key + ".crypto")))); } Skylight.SocketsManager.Start(); if (Skylight.GetConfig()["rcon.tcp.enabled"] == "1") { Skylight.RCONListener = new RCONListener(Skylight.GetConfig()["rcon.tcp.bindip"], int.Parse(Skylight.GetConfig()["rcon.tcp.port"]), Skylight.GetConfig()["rcon.tcp.allowedips"]); Skylight.RCONListener.Start(); } if (Skylight.GetConfig()["mus.tcp.enabled"] == "1") { Skylight.MUSListener = new MUSListener(Skylight.GetConfig()["mus.tcp.bindip"], int.Parse(Skylight.GetConfig()["mus.tcp.port"])); Skylight.MUSListener.Start(); } TimeSpan bootTime = Skylight.Uptime; Logging.WriteLine("READY! (" + bootTime.Seconds + " s, " + bootTime.Milliseconds + " ms)", ConsoleColor.Green); } catch (Exception ex) { Logging.WriteLine("FAILED TO BOOT! ", ConsoleColor.Red); Skylight.ExceptionShutdown(ex); } }