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); } }
internal static void Initialize() { Console.Clear(); CyberEnvironment.ServerStarted = DateTime.Now; Console.SetWindowSize(120, 40); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); Console.WriteLine(@" ____ _ _ ___ ____ ____ ____ _ _ _ _ _ ____ ___ ____ ____ "); Console.WriteLine(@" | \_/ |__] |___ |__/ |___ |\/| | | | |__| | | | |__/ "); Console.WriteLine(@" |___ | |__] |___ | \ |___ | | |__| |___ | | | |__| | \ "); Console.WriteLine(); Console.WriteLine(" Cyber Emulator - Version: " + PrettyBuild); Console.WriteLine(" based on Plus, developed by Kessiler Rodrigues."); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" " + PrettyRelease); Console.Title = "Cyber Emulator | Loading data [...]"; CyberEnvironment.DefaultEncoding = Encoding.Default; Console.WriteLine(""); CyberEnvironment.cultureInfo = CultureInfo.CreateSpecificCulture("en-GB"); TextHandling.replaceDecimal(); try { CyberEnvironment.Configuration = new ConfigurationData(Path.Combine(Application.StartupPath, "config.ini"), false); MySqlConnectionStringBuilder mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder(); mySqlConnectionStringBuilder.Server = (CyberEnvironment.GetConfig().data["db.hostname"]); mySqlConnectionStringBuilder.Port = (uint.Parse(CyberEnvironment.GetConfig().data["db.port"])); mySqlConnectionStringBuilder.UserID = (CyberEnvironment.GetConfig().data["db.username"]); mySqlConnectionStringBuilder.Password = (CyberEnvironment.GetConfig().data["db.password"]); mySqlConnectionStringBuilder.Database = (CyberEnvironment.GetConfig().data["db.name"]); mySqlConnectionStringBuilder.MinimumPoolSize = (uint.Parse(CyberEnvironment.GetConfig().data["db.pool.minsize"])); mySqlConnectionStringBuilder.MaximumPoolSize = (uint.Parse(CyberEnvironment.GetConfig().data["db.pool.maxsize"])); mySqlConnectionStringBuilder.Pooling = (true); mySqlConnectionStringBuilder.AllowZeroDateTime = (true); mySqlConnectionStringBuilder.ConvertZeroDateTime = (true); mySqlConnectionStringBuilder.DefaultCommandTimeout = (300u); mySqlConnectionStringBuilder.ConnectionTimeout = (10u); CyberEnvironment.manager = new DatabaseManager(mySqlConnectionStringBuilder.ToString()); using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { ConfigData = new ConfigData(queryreactor); PetLocale.Init(queryreactor); OfflineMessages = new Dictionary <uint, List <OfflineMessage> >(); OfflineMessage.InitOfflineMessages(queryreactor); GiftWrappers = new GiftWrappers(queryreactor); } FriendRequestLimit = (uint)int.Parse(CyberEnvironment.GetConfig().data["client.maxrequests"]); if (ExtraSettings.RunExtraSettings()) { Logging.WriteLine("Loaded an extra settings file."); } Game = new Game(int.Parse(GetConfig().data["game.tcp.conlimit"])); Game.start(); ConnectionManager = new ConnectionHandling(int.Parse(GetConfig().data["game.tcp.port"]), int.Parse(GetConfig().data["game.tcp.conlimit"]), int.Parse(GetConfig().data["game.tcp.conperip"]), GetConfig().data["game.tcp.enablenagles"].ToLower() == "true"); HabboCrypto.Initialize(new RsaKeyHolder()); CyberEnvironment.ConnectionManager.init(); CyberEnvironment.ConnectionManager.Start(); StaticClientMessageHandler.Initialize(); string[] allowedIps = GetConfig().data["mus.tcp.allowedaddr"].Split(';'); MusSystem = new MusSocket(GetConfig().data["mus.tcp.bindip"], int.Parse(GetConfig().data["mus.tcp.port"]), allowedIps, 0); if (Configuration.data.ContainsKey("StaffAlert.MinRank")) { StaffAlertMinRank = uint.Parse(CyberEnvironment.GetConfig().data["StaffAlert.MinRank"]); } if (Configuration.data.ContainsKey("SeparatedTasksInMainLoops.enabled") && Configuration.data["SeparatedTasksInMainLoops.enabled"] == "true") { SeparatedTasksInMainLoops = true; } if (Configuration.data.ContainsKey("SeparatedTasksInGameClientManager.enabled") && Configuration.data["SeparatedTasksInGameClientManager.enabled"] == "true") { SeparatedTasksInGameClientManager = true; } Logging.WriteLine("Game was succesfully loaded."); isLive = true; } catch (KeyNotFoundException ex) { Logging.WriteLine("Something is missing in your configuration", ConsoleColor.Red); Logging.WriteLine(ex.ToString(), ConsoleColor.Yellow); Logging.WriteLine("Please type a key to shut down ...", ConsoleColor.Gray); Console.ReadKey(true); CyberEnvironment.Destroy(); } catch (InvalidOperationException ex1) { Logging.WriteLine("Something wrong happened: " + ex1.Message, ConsoleColor.Red); Logging.WriteLine(ex1.ToString(), ConsoleColor.Yellow); Logging.WriteLine("Please type a key to shut down...", ConsoleColor.Gray); Console.ReadKey(true); CyberEnvironment.Destroy(); } catch (Exception ex2) { Logging.WriteLine("An exception got caught: " + ex2.Message, ConsoleColor.Red); Logging.WriteLine("Type a key to know more about the error", ConsoleColor.Gray); Console.ReadKey(); Logging.WriteLine(ex2.ToString(), ConsoleColor.Yellow); Logging.WriteLine("Please type a ket to shut down...", ConsoleColor.Gray); Console.ReadKey(); Environment.Exit(1); } }