/// <summary> /// Main Void, Initializes the Emulator. /// </summary> internal static void Initialize() { Console.Title = "Yupi Emulator | Starting [...]"; ServerStarted = DateTime.Now; _defaultEncoding = 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); 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 = 300u, ConnectionTimeout = 10u }; Manager = new DatabaseManager(mySqlConnectionStringBuilder.ToString()); using (IQueryAdapter queryReactor = GetDatabaseManager().GetQueryReactor()) { ConfigData = new ServerDatabaseSettings(queryReactor); PetCommandHandler.Init(queryReactor); PetLocale.Init(queryReactor); OfflineMessages = new Dictionary<uint, List<OfflineMessage>>(); OfflineMessage.InitOfflineMessages(queryReactor); } ConsoleTimer = 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>(); if (ServerConfigurationSettings.Data.ContainsKey("client.build")) LibraryParser.ReleaseName = ServerConfigurationSettings.Data["client.build"]; else throw new Exception("Unable to Continue if No Release is configured to the Emulator Handle."); 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); Writer.WriteLine("Loaded Plugin: " + item.PluginName + " Version: " + item.PluginVersion, "Yupi.Plugins", ConsoleColor.DarkBlue); } } ServerExtraSettings.RunExtraSettings(); FurnitureDataManager.SetCache(); CrossDomainSettings.Set(); _game = new Game.Game(int.Parse(ServerConfigurationSettings.Data["game.tcp.conlimit"])); _game.GetNavigator().LoadNewPublicRooms(); _game.ContinueLoading(); FurnitureDataManager.Clear(); if (ServerConfigurationSettings.Data.ContainsKey("server.lang")) ServerLanguage = Convert.ToString(ServerConfigurationSettings.Data["server.lang"]); _languages = new ServerLanguageSettings(ServerLanguage); Writer.WriteLine("Loaded " + _languages.Count() + " Languages Vars", "Yupi.Interpreters"); if (plugins != null) foreach (IPlugin itemTwo in plugins) itemTwo?.message_void(); if (ConsoleTimerOn) Writer.WriteLine("Console Clear Timer is Enabled, with " + ConsoleTimer + " Seconds.", "Yupi.Boot"); ClientMessageFactory.Init(); Writer.WriteLine("Game server started at port " + int.Parse(ServerConfigurationSettings.Data["game.tcp.port"]), "Server.Game"); _connectionManager = 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"); if (LibraryParser.Config["Crypto.Enabled"] == "true") { Handler.Initialize(LibraryParser.Config["Crypto.RSA.N"], LibraryParser.Config["Crypto.RSA.D"], LibraryParser.Config["Crypto.RSA.E"]); Writer.WriteLine("Started RSA crypto service", "Yupi.Crypto"); } else Writer.WriteLine("The encryption system is disabled.", "Yupi.Crypto", ConsoleColor.DarkYellow); LibraryParser.Initialize(); if (ConsoleTimerOn) { Timer = new Timer { Interval = ConsoleTimer }; Timer.Elapsed += TimerElapsed; Timer.Start(); } if (ServerConfigurationSettings.Data.ContainsKey("StaffAlert.MinLevel")) StaffAlertMinRank = uint.Parse(ServerConfigurationSettings.Data["StaffAlert.MinLevel"]); 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")) if (ServerConfigurationSettings.Data["debug.packet"] == "true") PacketDebugMode = true; Writer.WriteLine("Yupi Emulator ready. Status: idle", "Yupi.Boot"); IsLive = true; } catch (Exception e) { Writer.WriteLine("Error When Starting Yupi Environment!" + Environment.NewLine + e.Message, "Yupi.Boot", ConsoleColor.Red); Writer.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(); Writer.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); } else Environment.Exit(1); } }
/// <summary> /// Main Void, Initializes the Emulator. /// </summary> internal static void Initialize() { Console.Title = "Yupi Emulator | Starting [...]"; ServerStarted = DateTime.Now; _defaultEncoding = 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); 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 = 300u, ConnectionTimeout = 10u }; Manager = new DatabaseManager(mySqlConnectionStringBuilder.ToString()); using (IQueryAdapter commitableQueryReactor = GetDatabaseManager().GetQueryReactor()) { ConfigData = new ServerDatabaseSettings(commitableQueryReactor); PetCommandHandler.Init(commitableQueryReactor); PetLocale.Init(commitableQueryReactor); OfflineMessages = new Dictionary <uint, List <OfflineMessage> >(); OfflineMessage.InitOfflineMessages(commitableQueryReactor); } ConsoleTimer = 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>(); if (ServerConfigurationSettings.Data.ContainsKey("client.build")) { LibraryParser.ReleaseName = ServerConfigurationSettings.Data["client.build"]; } else { throw new Exception("Unable to Continue if No Release is configured to the Emulator Handle."); } 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); Writer.WriteLine("Loaded Plugin: " + item.PluginName + " Version: " + item.PluginVersion, "Yupi.Plugins", ConsoleColor.DarkBlue); } } ServerExtraSettings.RunExtraSettings(); FurnitureDataManager.SetCache(); CrossDomainSettings.Set(); _game = new Game.Game(int.Parse(ServerConfigurationSettings.Data["game.tcp.conlimit"])); _game.GetNavigator().LoadNewPublicRooms(); _game.ContinueLoading(); FurnitureDataManager.Clear(); if (ServerConfigurationSettings.Data.ContainsKey("server.lang")) { ServerLanguage = Convert.ToString(ServerConfigurationSettings.Data["server.lang"]); } _languages = new ServerLanguageSettings(ServerLanguage); Writer.WriteLine("Loaded " + _languages.Count() + " Languages Vars", "Yupi.Interpreters"); if (plugins != null) { foreach (IPlugin itemTwo in plugins) { itemTwo?.message_void(); } } if (ConsoleTimerOn) { Writer.WriteLine("Console Clear Timer is Enabled, with " + ConsoleTimer + " Seconds.", "Yupi.Boot"); } ClientMessageFactory.Init(); Writer.WriteLine( "Game server started at port " + int.Parse(ServerConfigurationSettings.Data["game.tcp.port"]), "Server.Game"); _connectionManager = 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"); if (LibraryParser.Config["Crypto.Enabled"] == "true") { Handler.Initialize(LibraryParser.Config["Crypto.RSA.N"], LibraryParser.Config["Crypto.RSA.D"], LibraryParser.Config["Crypto.RSA.E"]); Writer.WriteLine("Started RSA crypto service", "Yupi.Crypto"); } else { Writer.WriteLine("The encryption system is disabled.", "Yupi.Crypto", ConsoleColor.DarkYellow); } LibraryParser.Initialize(); if (ConsoleTimerOn) { Timer = new Timer { Interval = ConsoleTimer }; Timer.Elapsed += TimerElapsed; Timer.Start(); } if (ServerConfigurationSettings.Data.ContainsKey("StaffAlert.MinLevel")) { StaffAlertMinRank = uint.Parse(ServerConfigurationSettings.Data["StaffAlert.MinLevel"]); } 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")) { if (ServerConfigurationSettings.Data["debug.packet"] == "true") { PacketDebugMode = true; } } Writer.WriteLine("Yupi Emulator ready. Status: idle", "Yupi.Boot"); IsLive = true; } catch (Exception e) { Writer.WriteLine("Error When Starting Yupi Environment!" + Environment.NewLine + e.Message, "Yupi.Boot", ConsoleColor.Red); Writer.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(); Writer.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); } else { Environment.Exit(1); } } }