internal static void Destroy() { MercuryEnvironment.isLive = false; Logging.WriteLine("Destroying MercuryEnvironment...", ConsoleColor.Gray); if (MercuryEnvironment.GetGame() != null) { MercuryEnvironment.GetGame().Destroy(); MercuryEnvironment.GetGame().GetPixelManager().Destroy(); MercuryEnvironment.Game = null; } if (MercuryEnvironment.GetConnectionManager() != null) { Logging.WriteLine("Destroying ConnectionManager...", ConsoleColor.Gray); MercuryEnvironment.GetConnectionManager().Destroy(); } if (MercuryEnvironment.manager != null) { try { Logging.WriteLine("Destroying DatabaseManager...", ConsoleColor.Gray); MercuryEnvironment.manager.Destroy(); } catch { } } Logging.WriteLine("Closing...", ConsoleColor.Gray); Thread.Sleep(500); Environment.Exit(1); }
internal static void Initialize() { DateTime now = DateTime.Now; MercuryEnvironment.ServerStarted = DateTime.Now; Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WindowWidth = 120; Console.WindowHeight = 36; Console.Clear(); Console.WriteLine(); Console.WriteLine(@" _______ _______ __ __ "); Console.WriteLine(@" | | |.-----.----.----.--.--.----.--.--.| ___|.--------.--.--.| |.---.-.| |_.-----.----."); Console.WriteLine(@" | || -__| _| __| | | _| | || ___|| | | || || _ || _| _ | _|"); Console.WriteLine(@" |__|_|__||_____|__| |____|_____|__| |___ ||_______||__|__|__|_____||__||___._||____|_____|__| "); Console.WriteLine(@" |_____| "); Console.WriteLine(); Console.WriteLine(" Mercury Emulator v" + PrettyBuild); Console.WriteLine(" based on Plus, developed by Finn."); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(" " + PrettyRelease); Console.Title = "Mercury Emulator | Loading [...]"; MercuryEnvironment.DefaultEncoding = Encoding.Default; Console.WriteLine(""); MercuryEnvironment.cultureInfo = CultureInfo.CreateSpecificCulture("en-GB"); TextHandling.replaceDecimal(); try { MercuryEnvironment.Configuration = new ConfigurationData(Path.Combine(Application.StartupPath, "config.ini"), false); MySqlConnectionStringBuilder mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder(); mySqlConnectionStringBuilder.Server = (MercuryEnvironment.GetConfig().data["db.hostname"]); mySqlConnectionStringBuilder.Port = (uint.Parse(MercuryEnvironment.GetConfig().data["db.port"])); mySqlConnectionStringBuilder.UserID = (MercuryEnvironment.GetConfig().data["db.username"]); mySqlConnectionStringBuilder.Password = (MercuryEnvironment.GetConfig().data["db.password"]); mySqlConnectionStringBuilder.Database = (MercuryEnvironment.GetConfig().data["db.name"]); mySqlConnectionStringBuilder.MinimumPoolSize = (uint.Parse(MercuryEnvironment.GetConfig().data["db.pool.minsize"])); mySqlConnectionStringBuilder.MaximumPoolSize = (uint.Parse(MercuryEnvironment.GetConfig().data["db.pool.maxsize"])); mySqlConnectionStringBuilder.Pooling = (true); mySqlConnectionStringBuilder.AllowZeroDateTime = (true); mySqlConnectionStringBuilder.ConvertZeroDateTime = (true); mySqlConnectionStringBuilder.DefaultCommandTimeout = (300u); mySqlConnectionStringBuilder.ConnectionTimeout = (10u); MySqlConnectionStringBuilder mySqlConnectionStringBuilder2 = mySqlConnectionStringBuilder; MercuryEnvironment.manager = new DatabaseManager(mySqlConnectionStringBuilder2.ToString()); using (IQueryAdapter queryreactor = MercuryEnvironment.GetDatabaseManager().getQueryreactor()) { ConfigData = new ConfigData(queryreactor); PetLocale.Init(queryreactor); OfflineMessages = new Dictionary<uint, List<OfflineMessage>>(); OfflineMessage.InitOfflineMessages(queryreactor); GiftWrappers = new GiftWrappers(queryreactor); } FriendRequestLimit = checked((uint)int.Parse(MercuryEnvironment.GetConfig().data["client.maxrequests"])); Game = new Game(int.Parse(GetConfig().data["game.tcp.conlimit"])); Game.ContinueLoading(); if (ExtraSettings.RunExtraSettings()) { Logging.WriteLine("Loaded an Extra Settings file.", ConsoleColor.DarkCyan); } 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()); MercuryEnvironment.ConnectionManager.init(); MercuryEnvironment.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(MercuryEnvironment.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; } isLive = true; } catch (KeyNotFoundException) { Logging.WriteLine("Something is missing in your configuration", ConsoleColor.Red); Logging.WriteLine("Please type a key to shut down ...", ConsoleColor.Gray); Console.ReadKey(true); MercuryEnvironment.Destroy(); } catch (InvalidOperationException ex) { Logging.WriteLine("Something wrong happened: " + ex.Message, ConsoleColor.Red); Logging.WriteLine("Please type a key to shut down...", ConsoleColor.Gray); Console.ReadKey(true); MercuryEnvironment.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); } }