internal static void Initialize()
        {
            Console.Clear();
            DateTime Start = DateTime.Now;
            SystemMute = false;

            IrcEnabled = false;
            ServerStarted = DateTime.Now;
            Console.Title = "Loading Butterfly Emulator";
            DefaultEncoding = Encoding.Default;
            Logging.WriteLine(PrettyVersion);

            Logging.WriteLine("");
            Logging.WriteLine("");

            cultureInfo = CultureInfo.CreateSpecificCulture("en-GB");
            LanguageLocale.Init();

            try
            {
                ChatCommandRegister.Init();
                PetCommandHandeler.Init();
                PetLocale.Init();
                Configuration = new ConfigurationData(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath,@"Settings/configuration.ini"));

               /* if (ButterflyEnvironment.GetConfig().data["db.password"].Length == 0)
                {
                    throw new ArgumentException("For security reasons, your MySQL password cannot be left blank. Change your password to start the server.");
                }*/

                if (ButterflyEnvironment.GetConfig().data["db.password"] == "changeme")
                {
                    throw new ArgumentException("Your MySQL password may not be 'changeme'.\nChange your password to start the server.");
                }

                DateTime Starts = DateTime.Now;
                Logging.WriteLine("Connecting to database...");

                dbType = GetConfig().data.ContainsKey("db.mssql") && GetConfig().data["db.mssql"] == "true" ? DatabaseType.MSSQL : DatabaseType.MySQL;

                manager = new DatabaseManager(uint.Parse(ButterflyEnvironment.GetConfig().data["db.pool.maxsize"]), int.Parse(ButterflyEnvironment.GetConfig().data["db.pool.minsize"]), dbType);
                manager.setServerDetails(
                    ButterflyEnvironment.GetConfig().data["db.hostname"],
                    uint.Parse(ButterflyEnvironment.GetConfig().data["db.port"]),
                    ButterflyEnvironment.GetConfig().data["db.username"],
                    ButterflyEnvironment.GetConfig().data["db.password"],
                    ButterflyEnvironment.GetConfig().data["db.name"]);
                manager.init();

                TimeSpan TimeUsed2 = DateTime.Now - Starts;
                Logging.WriteLine("Connected to database! (" + TimeUsed2.Seconds + " s, " + TimeUsed2.Milliseconds + " ms)");

                LanguageLocale.InitSwearWord();

                Game = new Game(int.Parse(ButterflyEnvironment.GetConfig().data["game.tcp.conlimit"]));
                Game.ContinueLoading();

                ConnectionManager = new ConnectionHandeling(int.Parse(ButterflyEnvironment.GetConfig().data["game.tcp.port"]),
                    int.Parse(ButterflyEnvironment.GetConfig().data["game.tcp.conlimit"]),
                    int.Parse(ButterflyEnvironment.GetConfig().data["game.tcp.conperip"]),
                    ButterflyEnvironment.GetConfig().data["game.tcp.enablenagles"].ToLower() == "true");
                ConnectionManager.init();

                ConnectionManager.Start();

                StaticClientMessageHandler.Initialize();
                ClientMessageFactory.Init();

                string[] arrayshit = ButterflyEnvironment.GetConfig().data["mus.tcp.allowedaddr"].Split(Convert.ToChar(","));

                MusSystem = new MusSocket(ButterflyEnvironment.GetConfig().data["mus.tcp.bindip"], int.Parse(ButterflyEnvironment.GetConfig().data["mus.tcp.port"]), arrayshit, 0);

                //InitIRC();

                groupsEnabled = false;
                if (Configuration.data.ContainsKey("groups.enabled"))
                {
                    if (Configuration.data["groups.enabled"] == "true")
                    {
                        groupsEnabled = true;
                    }
                }

                useSSO = true;
                if (Configuration.data.ContainsKey("auth.ssodisabled"))
                {
                    if (Configuration.data["auth.ssodisabled"] == "false")
                    {
                        useSSO = false;
                    }
                }

                TimeSpan TimeUsed = DateTime.Now - Start;

                Logging.WriteLine("ENVIRONMENT -> READY! (" + TimeUsed.Seconds + " s, " + TimeUsed.Milliseconds + " ms)");
                isLive = true;
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Logging.WriteLine("Server is debugging: Console writing enabled");
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Logging.WriteLine("Server is not debugging: Console writing disabled");
                    Logging.DisablePrimaryWriting(false);
                }

                //Console.Beep();

                //Logging.LogCriticalException("FATAIL FAILURE");

            }
            catch (KeyNotFoundException e)
            {
                Logging.WriteLine("Please check your configuration file - some values appear to be missing.");
                Logging.WriteLine("Press any key to shut down ...");
                Logging.WriteLine(e.ToString());
                Console.ReadKey(true);
                ButterflyEnvironment.Destroy();

                return;
            }
            catch (InvalidOperationException e)
            {
                Logging.WriteLine("Failed to initialize ButterflyEmulator: " + e.Message);
                Logging.WriteLine("Press any key to shut down ...");

                Console.ReadKey(true);
                ButterflyEnvironment.Destroy();

                return;
            }

            catch (Exception e)
            {
                Console.WriteLine("Fatal error during startup: " + e.ToString());
                Console.WriteLine("Press a key to exit");

                Console.ReadKey();
                Environment.Exit(1);
            }
        }
示例#2
0
        internal static void Initialize()
        {
			Console.WriteLine("Initializing environment...");
			Console.WriteLine();
			Console.WriteLine();

            Stopwatch startWatch = Program.startWatch;

            isDebugging = System.Diagnostics.Debugger.IsAttached;

            rnd = new Random();
            ServerStarted = DateTime.Now;
            DefaultEncoding = Encoding.GetEncoding("ISO-8859-1");

            cultureInfo = CultureInfo.CreateSpecificCulture("en-GB");
            LanguageLocale.Init();

			try
			{
				ChatCommandRegister.Init();
				PetCommandHandeler.Init();
				PetLocale.Init();
                LanguageLocale.InitSwearWord();
				Stopwatch moduleWatch = new Stopwatch();

				memoryRespository = new MemoryRespository(10);

				DirectoryInfo logDirInfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\Logs");
				foreach (FileInfo file in logDirInfo.GetFiles())
				{
					file.Delete();
				}

				Configuration = new ConfigurationData(Path.Combine(System.Windows.Forms.Application.StartupPath, @"Settings/configuration.ini"));

				Game = new Game(Configuration.ReadInt("game.tcp.conlimit"));
				Console.WriteLine("Pre-init -> ({0} ms)", startWatch.ElapsedMilliseconds);
			
				Console.Write("Connecting to database -> ");
				moduleWatch.Start();

				manager = new DatabaseManager(Configuration.ReadUInt("db.pool.maxsize"), Configuration.ReadInt("db.pool.minsize"), DatabaseType.MySQL);
				manager.setServerDetails();
				manager.init();

				using (IQueryAdapter dbClient = manager.getQueryreactor())
				{
					Console.WriteLine("({0} ms)", moduleWatch.ElapsedMilliseconds);
					moduleWatch.Restart();
					Game.ContinueLoading(dbClient);
					moduleWatch.Restart();

					ConnectionManager = new ConnectionHandeling(Configuration.ReadInt("game.tcp.port"),
						Configuration.ReadInt("game.tcp.conlimit"),
						Configuration.ReadInt("game.tcp.conperip"),
						Configuration.ReadBool("game.tcp.enablenagles"));

					ConnectionManager.init();
					ConnectionManager.Start();

					DataSocket.SetupListener(42);
					DataSocket.Start();
					Console.WriteLine("Socket -> READY! ({0} ms)", moduleWatch.ElapsedMilliseconds);
					moduleWatch.Restart();

					StaticClientMessageHandler.Initialize();
					ClientMessageFactory.Init();

                    MusSystem = new MusSocket(Configuration.ReadInt("mus.tcp.port"), 500);
					MusSystem.WaitForConnections();

					useSSO = Configuration.ReadBool("auth.ssodisabled");

                    GlobalCrypto = new HabboEncryption.HabboEncryption();

					Console.WriteLine("MUS socket -> READY! ({0} ms)", moduleWatch.ElapsedMilliseconds);
				}

				Logging.WriteLine("ENVIRONMENT -> READY! (" + startWatch.ElapsedMilliseconds + " ms)");

				if (ButterflyEnvironment.isDebugging)
				{
					Console.ForegroundColor = ConsoleColor.Yellow;
					Logging.WriteLine("Server is debugging: Console writing enabled");
					Console.ForegroundColor = ConsoleColor.White;
					Logging.DisabledState = false;
				}
				else
				{
					Logging.WriteLine("Server is not debugging: Console writing disabled");
					Logging.DisablePrimaryWriting(false);
				}

				Console.Title = "Butterfly Emulator";
			}
			catch (ModuleInitializationException e)
			{
				Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Failed to initialize Butterfly Emulator:");
				Console.WriteLine(e.Message);
				Console.WriteLine();
				Console.WriteLine("Press any key to exit");
				Console.ReadKey();
				Environment.Exit(0);
			}
			catch (KeyNotFoundException e)
			{
				Console.ForegroundColor = ConsoleColor.Red;
				Console.WriteLine("Please check your configuration file - some values appear to be missing.");
				Console.WriteLine("Press any key to shut down ...");
				Console.WriteLine(e.ToString());
				Console.ReadKey(true);
				Environment.Exit(0);
			}
			catch (InvalidOperationException e)
			{
				Console.ForegroundColor = ConsoleColor.Red;
				Console.WriteLine("Failed to initialize ButterflyEmulator: " + e.Message);
				Console.WriteLine("Press any key to shut down ...");

				Console.ReadKey(true);
				Environment.Exit(0);
			}

			catch (Exception e)
			{
				Console.ForegroundColor = ConsoleColor.Red;
				Console.WriteLine("Fatal error during startup: " + e.ToString());
				Console.WriteLine("Press a key to exit");

				Console.ReadKey();
				Environment.Exit(1);
			}
        }