/// <summary> /// Main Void, Initializes the Emulator. /// </summary> internal static void Initialize() { Console.Title = "Yupi Emulator | Starting [...]"; YupiServerStartDateTime = DateTime.Now; YupiServerTextEncoding = Encoding.Default; MutedUsersByFilter = new Dictionary <uint, uint>(); ChatEmotions.Initialize(); CultureInfo = CultureInfo.CreateSpecificCulture("en-GB"); YupiRootDirectory = Directory.GetParent(Directory.GetParent(Environment.CurrentDirectory).FullName).FullName; YupiVariablesDirectory = Path.Combine(YupiRootDirectory, "Variables"); try { ServerConfigurationSettings.Load(Path.Combine(YupiVariablesDirectory, "Settings/main.ini")); ServerConfigurationSettings.Load(Path.Combine(YupiVariablesDirectory, "Settings/Welcome/settings.ini"), true); if (uint.Parse(ServerConfigurationSettings.Data["db.pool.maxsize"]) > MaxRecommendedMySqlConnections) { YupiWriterManager.WriteLine("MySQL Max Conn is High!, Recommended Value: " + MaxRecommendedMySqlConnections, "Yupi.Data", ConsoleColor.DarkYellow); } MySqlConnectionStringBuilder mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder { Server = ServerConfigurationSettings.Data["db.hostname"], Port = uint.Parse(ServerConfigurationSettings.Data["db.port"]), UserID = ServerConfigurationSettings.Data["db.username"], Password = ServerConfigurationSettings.Data["db.password"], Database = ServerConfigurationSettings.Data["db.name"], MinimumPoolSize = uint.Parse(ServerConfigurationSettings.Data["db.pool.minsize"]), MaximumPoolSize = uint.Parse(ServerConfigurationSettings.Data["db.pool.maxsize"]), Pooling = true, AllowZeroDateTime = true, ConvertZeroDateTime = true, DefaultCommandTimeout = 300, ConnectionTimeout = 10 }; YupiDatabaseManager = new BasicDatabaseManager(mySqlConnectionStringBuilder); using (IQueryAdapter queryReactor = GetDatabaseManager().GetQueryReactor()) { DatabaseSettings = new ServerDatabaseSettings(queryReactor); PetCommandHandler.Init(queryReactor); PetLocale.Init(queryReactor); OfflineMessages = new Dictionary <uint, List <OfflineMessage> >(); OfflineMessage.InitOfflineMessages(queryReactor); } YupiLogManager.Init(MethodBase.GetCurrentMethod().DeclaringType); ConsoleCleanTimeInterval = int.Parse(ServerConfigurationSettings.Data["console.clear.time"]); ConsoleTimerOn = bool.Parse(ServerConfigurationSettings.Data["console.clear.enabled"]); FriendRequestLimit = (uint)int.Parse(ServerConfigurationSettings.Data["client.maxrequests"]); LibraryParser.Incoming = new Dictionary <int, LibraryParser.StaticRequestHandler>(); LibraryParser.Library = new Dictionary <string, string>(); LibraryParser.Outgoing = new Dictionary <string, int>(); LibraryParser.Config = new Dictionary <string, string>(); LibraryParser.ReleaseName = ServerConfigurationSettings.Data["client.build"]; LibraryParser.RegisterLibrary(); LibraryParser.RegisterOutgoing(); LibraryParser.RegisterIncoming(); LibraryParser.RegisterConfig(); Plugins = new Dictionary <string, IPlugin>(); ICollection <IPlugin> plugins = LoadPlugins(); if (plugins != null) { foreach (IPlugin item in plugins.Where(item => item != null)) { Plugins.Add(item.PluginName, item); YupiWriterManager.WriteLine("Loaded Plugin: " + item.PluginName + " ServerVersion: " + item.PluginVersion, "Yupi.Plugins", ConsoleColor.DarkBlue); } } ServerExtraSettings.RunExtraSettings(); FurnitureDataManager.SetCache(); CrossDomainSettings.Set(); GameServer = new HabboHotel(int.Parse(ServerConfigurationSettings.Data["game.tcp.conlimit"])); GameServer.ContinueLoading(); FurnitureDataManager.Clear(); if (ServerConfigurationSettings.Data.ContainsKey("server.lang")) { ServerLanguage = ServerConfigurationSettings.Data["server.lang"]; } ServerLanguageVariables = new ServerLanguageSettings(ServerLanguage); YupiWriterManager.WriteLine("Loaded " + ServerLanguageVariables.Count() + " Languages Vars", "Yupi.Boot"); if (plugins != null) { foreach (IPlugin plugin in plugins) { plugin?.message_void(); } } if (ConsoleTimerOn) { YupiWriterManager.WriteLine("Console Clear ConsoleRefreshTimer is Enabled, with " + ConsoleCleanTimeInterval + " Seconds.", "Yupi.Boot"); } ClientMessageFactory.Init(); YupiUserConnectionManager = new ConnectionHandler(int.Parse(ServerConfigurationSettings.Data["game.tcp.port"]), int.Parse(ServerConfigurationSettings.Data["game.tcp.conlimit"]), int.Parse(ServerConfigurationSettings.Data["game.tcp.conperip"]), ServerConfigurationSettings.Data["game.tcp.antiddos"].ToLower() == "true", ServerConfigurationSettings.Data["game.tcp.enablenagles"].ToLower() == "true"); YupiWriterManager.WriteLine("Server Started at Port " + ServerConfigurationSettings.Data["game.tcp.port"] + " and Address " + ServerConfigurationSettings.Data["game.tcp.bindip"], "Yupi.Boot"); if (LibraryParser.Config["Crypto.Enabled"] == "true") { Handler.Initialize(LibraryParser.Config["Crypto.RSA.N"], LibraryParser.Config["Crypto.RSA.D"], LibraryParser.Config["Crypto.RSA.E"]); YupiWriterManager.WriteLine("Started RSA crypto service", "Yupi.Crypto"); } else { YupiWriterManager.WriteLine("The encryption system is disabled.", "Yupi.Crypto", ConsoleColor.DarkYellow); } LibraryParser.Initialize(); if (ConsoleTimerOn) { ConsoleRefreshTimer = new Timer { Interval = ConsoleCleanTimeInterval }; ConsoleRefreshTimer.Elapsed += ConsoleRefreshTimerElapsed; ConsoleRefreshTimer.Start(); } if (ServerConfigurationSettings.Data.ContainsKey("game.multithread.enabled")) { SeparatedTasksInMainLoops = ServerConfigurationSettings.Data["game.multithread.enabled"] == "true"; } if (ServerConfigurationSettings.Data.ContainsKey("client.multithread.enabled")) { SeparatedTasksInGameClientManager = ServerConfigurationSettings.Data["client.multithread.enabled"] == "true"; } if (ServerConfigurationSettings.Data.ContainsKey("debug.packet")) { PacketDebugMode = ServerConfigurationSettings.Data["debug.packet"] == "true"; } YupiWriterManager.WriteLine("Yupi Emulator ready.", "Yupi.Boot"); IsLive = true; } catch (Exception e) { YupiWriterManager.WriteLine("Error When Starting Yupi Environment!" + Environment.NewLine + e.Message, "Yupi.Boot", ConsoleColor.Red); YupiWriterManager.WriteLine("Please press Y to get more details or press other Key to Exit", "Yupi.Boot", ConsoleColor.Red); ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.Y) { Console.WriteLine(); YupiWriterManager.WriteLine( Environment.NewLine + "[Message] Error Details: " + Environment.NewLine + e.StackTrace + Environment.NewLine + e.InnerException + Environment.NewLine + e.TargetSite + Environment.NewLine + "[Message] Press Any Key To Exit", "Yupi.Boot", ConsoleColor.Red); Console.ReadKey(); } Environment.Exit(1); } }