Пример #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();
						}
					}
				}
			}
		}
Пример #2
0
        static void InitializeLicenseSystem()
        {
            SetWindowPos(MyConsole, 0, 100, 100, 0, 0, SWP_NOSIZE);

            Console.WindowHeight = Console.LargestWindowHeight - 20;
            Console.WindowWidth = Console.LargestWindowWidth - 20;
            Helpers.Out.startLogger();

            Configuration = new ConfigurationData(@"Settings/configuration.ini");

            conManager = new ConnectionManager.SocketManager();
            conManager.init(int.Parse(Configuration.data["con.socket"]), int.Parse(Configuration.data["con.max_servers"]), int.Parse(Configuration.data["con.con_per_ip"]), new GamePacketParser(), true);

            licenseRequester = new LicenseRequester(conManager);

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

            conManager.initializeConnectionRequests();
            while (Console.ReadLine() != "exit")
            {

            }
            Helpers.Out.stopLogger();
        }
Пример #3
0
        //private DateTime lastActivity;
        //private static readonly int MAX_IDLE_CONNECTION_TIME = 0x493e0; //300.000 0x493e0
        //private static Random rnd = new Random();
        //private DateTime timeConnected;
        //private ConnectionState state;

        public DatabaseClient(DatabaseManager dbManager, int id)
        {
            this.dbManager = dbManager;
            //this.connectionID = id;
            //this.lastActivity = DateTime.Now;
            //this.state = ConnectionState.Closed;
            this.connection = new MySqlConnection(dbManager.getConnectionString());
            //this.connection.StateChange += new StateChangeEventHandler(this.connecionStateChanged);
        }
Пример #4
0
 /// <summary>
 /// Creates a new database client with the given database manager
 /// </summary>
 /// <param name="dbManager">The manager which contains this item</param>
 public DatabaseClient(DatabaseManager dbManager, int id)
 {
     this.dbManager = dbManager;
     this.connectionID = id;
     this.creatonTime = DateTime.Now.AddMinutes(randomLive.Next(1,60));
     state = ConnectionState.Closed;
     connection = new MySqlConnection(
         dbManager.getConnectionString());
     connection.StateChange += connecionStateChanged;
 }
        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);
            }
        }
Пример #6
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();

                        }
                    }
                }
            }
        }
Пример #7
0
 public MySqlClient(DatabaseManager dbManager)
 {
     this.dbManager = dbManager;
     this.connection = new MySqlConnection(dbManager.getConnectionString());
 }
Пример #8
0
 public MySqlClient(DatabaseManager dbManager, int id)
 {
     this.dbManager = dbManager;
     this.connection = new MySqlConnection();
 }
Пример #9
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 { }
        }
Пример #10
0
 public MsSQLClient(DatabaseManager dbManager, int id)
 {
     this.dbManager = dbManager;
     this.connection = new SqlConnection(dbManager.getConnectionString());
 }
Пример #11
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);
			}
        }