Пример #1
0
Файл: Yupi.cs Проект: dm5wg/Yupi
        /// <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);
                }
            }
        }
Пример #2
0
        /// <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);
            }
        }