Exemplo n.º 1
0
		internal static void Save()
		{
			if (!MessageLoggerManager.enabled)
			{
				return;
			}
			lock (MessageLoggerManager.loggedMessages.SyncRoot)
			{
				int arg_28_0 = MessageLoggerManager.loggedMessages.Count;
				if (MessageLoggerManager.loggedMessages.Count > 0)
				{
					DatabaseManager databaseManager = new DatabaseManager(1u, 1u);
					using (IQueryAdapter queryreactor = databaseManager.getQueryreactor())
					{
						while (MessageLoggerManager.loggedMessages.Count > 0)
						{
							Message message = (Message)MessageLoggerManager.loggedMessages.Dequeue();
							queryreactor.setQuery("INSERT INTO system_packetlog (connectionid, timestamp, data) VALUES @connectionid @timestamp, @data");
							queryreactor.addParameter("connectionid", message.ConnectionID);
							queryreactor.addParameter("timestamp", message.GetTimestamp);
							queryreactor.addParameter("data", message.GetData);
							queryreactor.runQuery();
						}
					}
				}
			}
		}
Exemplo n.º 2
0
        internal static void Save()
        {
            if (!enabled)
                return;

            lock (loggedMessages.SyncRoot)
            {
                int totalMessages = loggedMessages.Count;

                if (loggedMessages.Count > 0)
                {
                    DatabaseManager dbManager = new DatabaseManager(1, 1, DatabaseType.MySQL);
                    //To-do: Init dbManager from configuration file

                    using (IQueryAdapter dbClient = dbManager.getQueryreactor())
                    {
                        while (loggedMessages.Count > 0)
                        {
                            Message message = (Message)loggedMessages.Dequeue();

                            dbClient.setQuery("INSERT INTO system_packetlog (connectionid, timestamp, data) VALUES @connectionid @timestamp, @data");
                            dbClient.addParameter("connectionid", message.ConnectionID);
                            dbClient.addParameter("timestamp", message.GetTimestamp);
                            dbClient.addParameter("data", message.GetData);

                            dbClient.runQuery();

                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        internal static void Initialize()
        {
            PrettyVersion = string.Format("Firewind {0}", Assembly.GetExecutingAssembly().GetName().Version);
            Console.Clear();
            DateTime Start = DateTime.Now;
            SystemMute = false;

            ServerStarted = DateTime.Now;

            Console.Title = "Firewind: Loading environment.";

            Logging.WriteWithColor("      _______ __                       __           __ ", ConsoleColor.Cyan);
            Logging.WriteWithColor("     |    ___|__|.----.-----.--.--.--.|__|.-----.--|  |", ConsoleColor.Cyan);
            Logging.WriteWithColor("     |    ___|  ||   _|  -__|  |  |  ||  ||     |  _  |", ConsoleColor.Cyan);
            Logging.WriteWithColor("     |___|   |__||__| |_____|________||__||__|__|_____|", ConsoleColor.Cyan);
            Logging.WriteLine("");
            Logging.WriteLine("==============================================================");

            DefaultEncoding = Encoding.Default;
            Logging.WriteLine("     " + PrettyVersion);
            Logging.WriteLine(string.Format("     Licenced to {0}", LicenseHolder));
            Logging.WriteLine(string.Format("     Maximum players: {0}", MaxUsers == 0 ? "Unlimited!" : MaxUsers.ToString()));

            Logging.WriteLine("");

            Logging.WriteLine("     Go to the GitHub repo for bug reporting/contributions!");
            cultureInfo = CultureInfo.CreateSpecificCulture("en-GB");
            IsDebugging = IsDebugging ? System.Diagnostics.Debugger.IsAttached : false;

            try
            {
                LanguageLocale.Init();
                ChatCommandRegister.Init();
                PetCommandHandeler.Init();
                PetLocale.Init();

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

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

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

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

                LanguageLocale.InitSwearWord();

                friendRequestLimit = (uint)(int.Parse(FirewindEnvironment.GetConfig().data["client.maxrequests"]));

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

                ConnectionManager = new ConnectionHandling(int.Parse(FirewindEnvironment.GetConfig().data["game.tcp.port"]),
                    MaxUsers,
                    int.Parse(FirewindEnvironment.GetConfig().data["game.tcp.conperip"]),
                    FirewindEnvironment.GetConfig().data["game.tcp.enablenagles"].ToLower() == "true");
                ConnectionManager.init();
                ConnectionManager.Start();

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

                string[] arrayshit = FirewindEnvironment.GetConfig().data["mus.tcp.allowedaddr"].Split(';');

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

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

                if (Configuration.data.ContainsKey("spambans.enabled"))
                {
                    if (Configuration.data["spambans.enabled"] == "true")
                    {
                        spamBans = true;
                        spamBans_limit = Convert.ToInt32(Configuration.data["spambans.limit"]);
                        Logging.WriteLine("Spam Bans enabled");
                    }
                }
                if (Configuration.data.ContainsKey("SeparatedTasksInMainLoops.enabled"))
                {
                    if (Configuration.data["SeparatedTasksInMainLoops.enabled"] == "true")
                    {
                        SeparatedTasksInMainLoops = true;
                        Logging.WriteLine("MultiTasking in MainLoop");
                    }
                }

                if (Configuration.data.ContainsKey("SeparatedTasksInGameClientManager.enabled"))
                {
                    if (Configuration.data["SeparatedTasksInGameClientManager.enabled"] == "true")
                    {
                        SeparatedTasksInGameClientManager = true;
                        Logging.WriteLine("MultiTasking in ClientManager");
                    }
                }

                TimeSpan TimeUsed = DateTime.Now - Start;

                Logging.WriteWithColor("Firewind -> READY! (" + TimeUsed.Seconds + " s, " + TimeUsed.Milliseconds + " ms)", ConsoleColor.Cyan);

                isLive = true;
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    Logging.WriteLine("Server is debugging: Console writing enabled", true);
                }
                else
                {
                    Logging.WriteLine("Server is not debugging: Console writing disabled", false);
                    Logging.DisablePrimaryWriting(false);
                }

            }
            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);
                FirewindEnvironment.Destroy();

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

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

                return;
            }

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

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

            // Check if this is habin or not
            try
            {
                using (IQueryAdapter dbClient = manager.getQueryreactor())
                {
                    dbClient.setQuery("SELECT column_name FROM information_schema.columns WHERE table_schema = '" + FirewindEnvironment.GetConfig().data["db.name"] + "' AND table_name = 'users' AND column_name = 'hpo'");
                    IsHabin = dbClient.findsResult();
                }
            }
            catch { }
        }
Exemplo n.º 4
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);
			}
        }