예제 #1
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);
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
파일: Plus.cs 프로젝트: Mereos/HabboEMU
        /// <summary>
        /// Main Void, Initializes the Emulator.
        /// </summary>
        internal static void Initialize()
        {
            #region Precheck

            Console.Title    = "CityRP está iniciando..";
            ServerStarted    = DateTime.Now;
            _defaultEncoding = Encoding.Default;

            #endregion Precheck

            #region Database Connection

            CultureInfo = CultureInfo.CreateSpecificCulture("en-GB");
            try
            {
                ConfigurationData.Load(Path.Combine(Application.StartupPath, "Settings/main.ini"), false);
                RoleplayData.Load(Path.Combine(Application.StartupPath, "Settings/Roleplay/settings.ini"), true);

                DatabaseConnectionType = ConfigurationData.Data["db.type"];
                var mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder
                {
                    Server                = (ConfigurationData.Data["db.hostname"]),
                    Port                  = (uint.Parse(ConfigurationData.Data["db.port"])),
                    UserID                = (ConfigurationData.Data["db.username"]),
                    Password              = (ConfigurationData.Data["db.password"]),
                    Database              = (ConfigurationData.Data["db.name"]),
                    MinimumPoolSize       = (uint.Parse(ConfigurationData.Data["db.pool.minsize"])),
                    MaximumPoolSize       = (uint.Parse(ConfigurationData.Data["db.pool.maxsize"])),
                    Pooling               = (true),
                    AllowZeroDateTime     = (true),
                    ConvertZeroDateTime   = (true),
                    DefaultCommandTimeout = (300),
                    ConnectionTimeout     = (10)
                };
                var mySqlConnectionStringBuilder2 = mySqlConnectionStringBuilder;
                Manager = new DatabaseManager(mySqlConnectionStringBuilder2.ToString(), DatabaseConnectionType);
                using (var queryReactor = GetDatabaseManager().GetQueryReactor())
                {
                    ConfigData = new ConfigData(queryReactor);
                    PetCommandHandler.Init(queryReactor);
                    PetLocale.Init(queryReactor);
                    OfflineMessages = new Dictionary <uint, List <OfflineMessage> >();
                    OfflineMessage.InitOfflineMessages(queryReactor);
                }

                #endregion Database Connection

                #region Packets Registering

                ConsoleTimer       = (int.Parse(ConfigurationData.Data["console.clear.time"]));
                ConsoleTimerOn     = (bool.Parse(ConfigurationData.Data["console.clear.enabled"]));
                FriendRequestLimit = ((uint)int.Parse(ConfigurationData.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.RegisterLibrary();
                LibraryParser.RegisterOutgoing();
                LibraryParser.RegisterIncoming();
                LibraryParser.RegisterConfig();

                #endregion Packets Registering

                #region Game Initalizer

                ExtraSettings.RunExtraSettings();
                CrossDomainPolicy.Set();
                _game = new Game(int.Parse(ConfigurationData.Data["game.tcp.conlimit"]));
                _game.GetNavigator().LoadNewPublicRooms();
                _game.ContinueLoading();

                #endregion Game Initalizer

                #region Languages Parser

                ServerLanguage = (Convert.ToString(ConfigurationData.Data["system.lang"]));
                _languages     = new Languages(ServerLanguage);

                #endregion Languages Parser

                #region Environment SetUp

                if (ConsoleTimerOn)
                {
                    Out.WriteLine("Console Clear Timer is enable with " + ConsoleTimer + " seconds.");
                }

                _connectionManager = new ConnectionHandling(int.Parse(ConfigurationData.Data["game.tcp.port"]),
                                                            int.Parse(ConfigurationData.Data["game.tcp.conlimit"]),
                                                            int.Parse(ConfigurationData.Data["game.tcp.conperip"]),
                                                            ConfigurationData.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"]);
                }

                _connectionManager.init();

                LibraryParser.Initialize();

                #endregion Environment SetUp

                #region Tasks and MusSystem

                if (ConsoleTimerOn)
                {
                    Timer = new Timer {
                        Interval = ConsoleTimer
                    };
                    Timer.Elapsed += TimerElapsed;
                    Timer.Start();
                }

                if (ConfigurationData.Data.ContainsKey("StaffAlert.MinRank"))
                {
                    StaffAlertMinRank = uint.Parse(ConfigurationData.Data["StaffAlert.MinRank"]);
                }

                if (ConfigurationData.Data.ContainsKey("SeparatedTasksInMainLoops.enabled") &&
                    ConfigurationData.Data["SeparatedTasksInMainLoops.enabled"] == "true")
                {
                    SeparatedTasksInMainLoops = true;
                }
                if (ConfigurationData.Data.ContainsKey("SeparatedTasksInGameClientManager.enabled") &&
                    ConfigurationData.Data["SeparatedTasksInGameClientManager.enabled"] == "true")
                {
                    SeparatedTasksInGameClientManager = true;
                }
                if (ConfigurationData.Data.ContainsKey("Debug"))
                {
                    if (ConfigurationData.Data["Debug"] == "true")
                    {
                        DebugMode = true;
                    }
                }

                TimeSpan TimeUsed = DateTime.Now - ServerStarted;

                Out.WriteLine("CityRP >> Started (" + TimeUsed.Seconds + "s, " + TimeUsed.Milliseconds + "ms)", "", ConsoleColor.Green);
                IsLive = true;

                using (var queryReactor = GetDatabaseManager().GetQueryReactor())
                {
                    queryReactor.RunFastQuery("UPDATE server_settings SET value = '1' WHERE variable = 'status'");
                }
            }
            catch (Exception e)
            {
                Out.WriteLine("Error in main.ini: Configuration file is invalid" + Environment.NewLine + e.Message, "", ConsoleColor.Red);
                Out.WriteLine("Please press Y to get more details or press other Key to Exit", "", ConsoleColor.Red);

                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Y)
                {
                    Console.WriteLine();
                    Out.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", "", ConsoleColor.Red);
                    Console.ReadKey();
                    Environment.Exit(1);
                }
                else
                {
                    Environment.Exit(1);
                }
            }

            #endregion Tasks and MusSystem
        }