public static void LogRoomException(string logText) { try { FileStream fileStream = new FileStream("exceptions_room.err", FileMode.Append, FileAccess.Write); byte[] bytes = Encoding.ASCII.GetBytes(string.Concat(new object[] { DateTime.Now, ": ", logText, "\r\n\r\n" })); fileStream.Write(bytes, 0, bytes.Length); fileStream.Close(); } catch (Exception) { Logging.WriteLine(DateTime.Now + ": " + logText); } Logging.WriteLine("Room exception has been saved", ConsoleColor.Red); ServerMessage Message = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108); Message.Init(r63aOutgoing.MessengerChatMessage); Message.AppendUInt(0); Message.AppendString("!!AUTOMATIC EXCEPTION REPORT!!\nRoom exception has been saved!"); foreach (GameClient sesion_ in Skylight.GetGame().GetGameClientManager().GetClients()) { try { if (sesion_ != null && sesion_.GetHabbo() != null) { if (sesion_.GetHabbo().HasPermission("acc_staffchat")) { sesion_.SendMessage(Message); } } } catch { } } }
public static void LogDDoS(string ip) { try { FileStream fileStream = new FileStream("ddos_protection.txt", FileMode.Append, FileAccess.Write); byte[] bytes = Encoding.ASCII.GetBytes(string.Concat(new object[] { DateTime.Now, ": ", "DDoS protection! IP " + ip + " has been detected from DDoS! Actions have been made!", "\r\n\r\n" })); fileStream.Write(bytes, 0, bytes.Length); fileStream.Close(); } catch (Exception) { } Logging.WriteLine("DDoS protection! IP " + ip + " has been detected from DDoS! Actions have been made!", ConsoleColor.Red); ServerMessage Message = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108); Message.Init(r63aOutgoing.MessengerChatMessage); Message.AppendUInt(0); Message.AppendString("!!AUTOMATIC DDOS REPORT!!\nWe are under attack!"); foreach (GameClient sesion_ in Skylight.GetGame().GetGameClientManager().GetClients()) { try { if (sesion_ != null && sesion_.GetHabbo() != null) { if (sesion_.GetHabbo().HasPermission("acc_staffchat")) { sesion_.SendMessage(Message); } } } catch { } } }
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); } }
public static void Destroy(bool close, bool takeBackup, bool backupCompress, bool restart) { if (Skylight.ServerShutdown) { return; } Skylight.ServerShutdown = true; try //we dont want shutdowns fails bcs of this { ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108); message.Init(r63aOutgoing.SendNotifFromAdmin); message.AppendString("ATTENTION:\r\nThe server is shutting down. All furniture placed in rooms/traded/bought after this message is on your own responsibillity."); byte[] data = message.GetBytes(); foreach (GameClient client in Skylight.GetGame().GetGameClientManager().GetClients()) { try //try send { if (client != null) { client.SendData(data); } } catch //ignore error { } } } catch //nothing special really { } if (Skylight.ExternalFlashPolicyFileRequestPort) { Logging.Write("Disposing efpfr listener... "); if (Skylight.FlashPolicyFileRequestListener != null) { Skylight.FlashPolicyFileRequestListener.Stop(); } Skylight.FlashPolicyFileRequestListener = null; Logging.WriteLine("DONE!", ConsoleColor.Green); } Logging.Write("Disposing socket manager... "); if (Skylight.SocketsManager != null) { Skylight.SocketsManager.Stop(); } Skylight.SocketsManager = null; Logging.WriteLine("DONE!", ConsoleColor.Green); Logging.Write("Disposing packet manager... "); if (Skylight.PacketManager != null) //release memory { Skylight.PacketManager.Clear(); } Skylight.PacketManager = null; Logging.WriteLine("DONE!", ConsoleColor.Green); Logging.Write("Disposing RCON... "); if (Skylight.RCONListener != null) { Skylight.RCONListener.Stop(); } Logging.WriteLine("DONE!", ConsoleColor.Green); Logging.Write("Disposing game... "); if (Skylight.Game != null) { Skylight.Game.Shutdown(); } Skylight.Game = null; Logging.WriteLine("DONE!", ConsoleColor.Green); if (takeBackup) { Logging.WriteLine("Taking backup... "); using (DatabaseClient dbClient = Skylight.GetDatabaseManager().GetClient()) { dbClient.TakeBackup(backupCompress); } Logging.WriteLine("DONE!", ConsoleColor.Green); } Logging.Write("Disposing database... "); if (Skylight.DatabaseManager != null) { MySqlConnection.ClearAllPools(); } Skylight.DatabaseManager = null; Logging.WriteLine("DONE!", ConsoleColor.Green); Logging.WriteLine(""); Logging.WriteLine("Server closed propriety!", ConsoleColor.Green); if (restart) { Process.Start(AppDomain.CurrentDomain.FriendlyName); } if (close) { Environment.Exit(0); } }