Ejemplo n.º 1
0
        public void RestoreStatistics(DatabaseClient dbClient, int status)
        {
            Logging.Write(EssentialEnvironment.GetExternalText("emu_cleandb"));
            bool flag = true;

            try
            {
                if (int.Parse(Essential.GetConfig().data["debug"]) == 1)
                {
                    flag = false;
                }
            }
            catch
            {
            }
            if (flag)
            {
                dbClient.ExecuteQuery("UPDATE users SET online = '0' WHERE online != '0'");
                dbClient.ExecuteQuery("UPDATE rooms SET users_now = '0' WHERE users_now != '0'");
                dbClient.ExecuteQuery("UPDATE user_roomvisits SET exit_timestamp = UNIX_TIMESTAMP() WHERE exit_timestamp <= 0");
                dbClient.ExecuteQuery("UPDATE users SET websocket='0'");
                dbClient.ExecuteQuery(string.Concat(new object[]
                {
                    "UPDATE server_status SET status = '",
                    status,
                    "', users_online = '0', rooms_loaded = '0', server_ver = '",
                    Essential.PrettyVersion,
                    "', stamp = UNIX_TIMESTAMP() LIMIT 1;"
                }));
            }
            Logging.WriteLine("completed!", ConsoleColor.Green);
        }
Ejemplo n.º 2
0
 internal void method_4()
 {
     using (Class26 class26_ = this.class25_0.Class26_0)
     {
         IEnumerator enumerator;
         using (DatabaseClient @class = Essential.GetDatabase().GetClient())
         {
             enumerator = class26_.Values.GetEnumerator();
             try
             {
                 while (enumerator.MoveNext())
                 {
                     Room class2 = (Room)enumerator.Current;
                     class2.method_65(@class);
                 }
             }
             finally
             {
                 IDisposable disposable = enumerator as IDisposable;
                 if (disposable != null)
                 {
                     disposable.Dispose();
                 }
             }
         }
         if (Essential.GetConfig().data["emu.messages.roommgr"] == "1")
         {
             Console.WriteLine("[RoomMgr] Done with furniture saving, disposing rooms");
         }
         enumerator = class26_.Values.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 Room class2 = (Room)enumerator.Current;
                 try
                 {
                     class2.method_62();
                 }
                 catch
                 {
                 }
             }
         }
         finally
         {
             IDisposable disposable = enumerator as IDisposable;
             if (disposable != null)
             {
                 disposable.Dispose();
             }
         }
         if (Essential.GetConfig().data["emu.messages.roommgr"] == "1")
         {
             Console.WriteLine("[RoomMgr] Done disposing rooms!");
         }
     }
 }
Ejemplo n.º 3
0
        public Class114(string string_0, int int_2, int maxConnections, SocketsManager class113_1)
        {
            this.int_1    = Process.GetCurrentProcess().Id;
            this.socket_0 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint localEP = new IPEndPoint(IPAddress.Parse(Essential.GetConfig().data["game.tcp.bindip"]), int_2);

            this.socket_0.Bind(localEP);
            this.socket_0.Listen(133337);
            this.asyncCallback_0 = new AsyncCallback(this.method_4);
            this.class113_0      = class113_1;
            AntiDDosSystem.SetupTcpAuthorization(20000);
            Logging.WriteLine("Listening for connections on port: " + int_2 + " | Max connections is: 133337");
        }
        public void Handle(GameClient Session, ClientMessage Event)
        {
            int GameId = Event.PopWiredInt32();

            string UserAuthTicket = Essential.GetGame().GetGamesManager().CreateAuthTicket(Session.GetHabbo().Id);

            using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
            {
                // Check exist auth tokens and delete them.

                if (dbClient.ReadInt32("SELECT COUNT(token) FROM basejump_auth_tokens WHERE user_id = '" + Session.GetHabbo().Id + "' LIMIT 1") == 1)
                {
                    dbClient.ExecuteQuery("DELETE FROM `basejump_auth_tokens` WHERE `user_id`='" + Session.GetHabbo().Id + "'");
                }

                dbClient.AddParamWithValue("auth_token", UserAuthTicket);
                dbClient.AddParamWithValue("user_id", Session.GetHabbo().Id);
                dbClient.AddParamWithValue("expire", Essential.GetUnixTimestamp() + 1800); // +30 min expires

                dbClient.ExecuteQuery("INSERT INTO `basejump_auth_tokens` (`token`, `user_id`, `expire`) VALUES (@auth_token, @user_id, @expire)");
            }

            ServerMessage LoadGame = new ServerMessage(Outgoing.LoadGame);

            LoadGame.AppendInt32(GameId);
            LoadGame.AppendString(Session.GetHabbo().Id.ToString());          // ??
            LoadGame.AppendString(Session.ClientVar + "/games/BaseJump.swf"); // url
            LoadGame.AppendString("best");
            LoadGame.AppendString("showAll");
            LoadGame.AppendInt32(60);
            LoadGame.AppendInt32(10);
            LoadGame.AppendInt32(0);
            LoadGame.AppendInt32(6);
            LoadGame.AppendString("assetUrl");
            LoadGame.AppendString(Session.ClientVar + "/games/BasicAssets.swf");
            LoadGame.AppendString("habboHost");
            LoadGame.AppendString("http://fusees-private-httpd-fe-1");
            LoadGame.AppendString("accessToken");
            LoadGame.AppendString(UserAuthTicket);
            LoadGame.AppendString("gameServerHost");
            LoadGame.AppendString(Essential.GetConfig().data["game.tcp.bindip"]);
            LoadGame.AppendString("gameServerPort");
            LoadGame.AppendString(Essential.GetConfig().data["game.tcp.port"]);
            LoadGame.AppendString("socketPolicyPort");
            LoadGame.AppendString(Essential.GetConfig().data["game.tcp.port"]);
            Session.SendMessage(LoadGame);
        }
Ejemplo n.º 5
0
        public void Handle(GameClient Session, ClientMessage Event)
        {
            uint num = Event.PopWiredUInt();

            if (Essential.GetConfig().data["emu.messages.roommgr"] == "1")
            {
                Logging.WriteLine("[RoomMgr] Requesting Public Room [ID: " + num + "]");
            }
            RoomData @class = Essential.GetGame().GetRoomManager().method_12(num);

            Session.GetHabbo().uint_2 = num;
            Session.GetClientMessageHandler().method_5(num, "");

            /*   RoomData @class = Essential.GetGame().GetRoomManager().method_12(num);
             *             if (@class != null && !(@class.Type != "public"))
             *             {
             *                     Session.GetClientMessageHandler().method_5(num, "");
             *             }
             * else
             * {
             *
             * }
             */
        }
Ejemplo n.º 6
0
        private void PingTask()
        {
            int num = int.Parse(Essential.GetConfig().data["client.ping.interval"]);

            if (num <= 100)
            {
                throw new ArgumentException("Invalid configuration value for ping interval! Must be above 100 miliseconds.");
            }

            while (true)
            {
                try
                {
                    ServerMessage     Message = new ServerMessage(Outgoing.Ping); // Updated
                    List <GameClient> list    = new List <GameClient>();
                    List <GameClient> list2   = new List <GameClient>();
                    for (int i = 0; i < this.Clients.Length; i++)
                    {
                        GameClient @class = this.Clients[i];
                        if (@class != null)
                        {
                            if (@class.bool_0)
                            {
                                @class.bool_0 = false;
                                list2.Add(@class);
                            }
                            else
                            {
                                list.Add(@class);
                            }
                        }
                    }
                    foreach (GameClient @class in list)
                    {
                        /*try
                         * {
                         *  @class.Disconnect("PING");
                         * }
                         * catch
                         * {
                         * }*/
                    }
                    byte[] byte_ = Message.GetBytes();
                    foreach (GameClient @class in list2)
                    {
                        try
                        {
                            @class.GetConnection().SendData(byte_);
                        }
                        catch
                        {
                            //@class.Disconnect("PING ERROR");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logging.LogThreadException(ex.ToString(), "Connection checker task");
                }
                Thread.Sleep(num);
            }
        }
Ejemplo n.º 7
0
        public UserDataFactory(string ssoTicket, string ipAddress, bool getAllData)
        {
            if (string.IsNullOrEmpty(ssoTicket))
            {
                this.Validated = false;
            }
            else
            {
                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    dbClient.AddParamWithValue("auth_ticket", ssoTicket);
                    string str = "";
                    try
                    {
                        if (int.Parse(Essential.GetConfig().data["debug"]) == 1)
                        {
                            str = "";
                        }
                    }
                    catch { }

                    this.UserData = dbClient.ReadDataRow("SELECT * FROM users WHERE auth_ticket = @auth_ticket " + str + " LIMIT 1;");

                    if (this.UserData != null)
                    {
                        this.Validated = true;

                        uint id = (uint)this.UserData["Id"];

                        if (getAllData)
                        {
                            this.Achievements   = dbClient.ReadDataTable("SELECT achievement_id,achievement_level FROM user_achievements WHERE user_id = '" + id + "'");
                            this.Favorites      = dbClient.ReadDataTable("SELECT room_id FROM user_favorites WHERE user_id = '" + id + "'");
                            this.Ignores        = dbClient.ReadDataTable("SELECT ignore_id FROM user_ignores WHERE user_id = '" + id + "'");
                            this.Tags           = dbClient.ReadDataTable("SELECT tag FROM user_tags WHERE user_id = '" + id + "'");
                            this.Subscriptions  = dbClient.ReadDataTable("SELECT subscription_id, timestamp_activated, timestamp_expire FROM user_subscriptions WHERE user_id = '" + id + "'");
                            this.Badges         = dbClient.ReadDataTable("SELECT user_badges.badge_id,user_badges.badge_slot FROM user_badges WHERE user_id = " + id);
                            this.Items          = dbClient.ReadDataTable("SELECT items.Id,items.base_item,items.ltd_id,items.ltd_cnt,items.guild_data,items_extra_data.extra_data FROM items LEFT JOIN items_extra_data ON items_extra_data.item_id = items.Id WHERE room_id = 0 AND user_id = " + id);
                            this.Effects        = dbClient.ReadDataTable("SELECT user_effects.effect_id,user_effects.total_duration,user_effects.is_activated,user_effects.activated_stamp FROM user_effects WHERE user_id =  " + id);
                            this.Friends        = dbClient.ReadDataTable("SELECT users.Id,users.username,users.motto,users.look,users.last_online FROM users JOIN messenger_friendships ON users.Id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = '" + id + "'");
                            this.FriendRequests = dbClient.ReadDataTable("SELECT messenger_requests.Id,messenger_requests.from_id,users.username,users.gender,users.look FROM users JOIN messenger_requests ON users.Id = messenger_requests.from_id WHERE messenger_requests.to_id = '" + id + "'");

                            dbClient.AddParamWithValue("name", (string)this.UserData["username"]);

                            this.Rooms = dbClient.ReadDataTable("SELECT * FROM rooms WHERE owner = @name ORDER BY Id ASC LIMIT " + ServerConfiguration.RoomUserLimit);
                            this.Pets  = dbClient.ReadDataTable("SELECT Id, user_id, room_id, name, type, race, color, expirience, energy, nutrition, respect, createstamp, x, y, z FROM user_pets WHERE user_id = " + id + " AND room_id = 0");
                            this.Bots  = dbClient.ReadDataTable("SELECT * FROM user_bots WHERE owner_id = '" + id + "' AND room_id=0");

                            dbClient.ExecuteQuery(string.Concat(new object[]
                            {
                                "UPDATE users SET online = '1' WHERE Id = '",
                                id,
                                "' LIMIT 1; UPDATE user_info SET login_timestamp = '",
                                Essential.GetUnixTimestamp(),
                                "' WHERE user_id = '",
                                id,
                                "' LIMIT 1;"
                            }));
                            double loginStamp = Essential.GetUnixTimestamp();
                            this.LoginTime = loginStamp;
                            dbClient.ExecuteQuery("INSERT INTO user_clientsessions (`userId`,`login_timestamp`,`logout_timestamp`) VALUES ('" + id + "','" + loginStamp + "','0');");
                            //    @class.ExecuteQuery(string.Concat(new object[]
                            //{
                            //    "UPDATE users SET online = '1'" + /*auth_ticket = ''*/ "WHERE Id = '",
                            //    num,
                            //    "' LIMIT 1; UPDATE user_info SET login_timestamp = '",
                            //    Essential.GetUnixTimestamp(),
                            //    "' WHERE user_id = '",
                            //    num,
                            //    "' LIMIT 1;"
                            //}));
                            DataTable table;
                            DataTable table2;
                            //Profile Initialization - Might don't need all friends information, just the count but I didn't want to brake the system, so let them go..
                            //Altrough this is not the best perfomance scenario
                            table = dbClient.ReadDataTable("SELECT * FROM user_relationships WHERE requester_id = " + id);
                            uint target, rstatus;
                            List <Relationship.Relationship> relationships = new List <Relationship.Relationship>();
                            Dictionary <uint, uint>          tempRelationshipsDictionary = new Dictionary <uint, uint>();

                            foreach (DataRow row3 in table.Rows)
                            {
                                target  = Convert.ToUInt32(row3["target_id"]);
                                rstatus = Convert.ToUInt32(row3["relationshipstatus"]);
                                relationships.Add(new Relationship.Relationship(target, rstatus));
                            }
                            this.relationships = relationships;
                        }
                    }
                    else
                    {
                        this.Validated = false;
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public Game(int conns)
        {
            this.ClientManager = new GameClientManager(conns);

            if (Essential.GetConfig().data["client.ping.enabled"] == "1")
            {
                this.ClientManager.StartPingTask();
            }

            DateTime now = DateTime.Now;

            Logging.Write("Connecting to the database.. ");

            try
            {
                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    Logging.WriteLine("completed!", ConsoleColor.Green);

                    Essential.Game = this;
                    this.LoadServerSettings(dbClient);
                    this.BanManager           = new ModerationBanManager();
                    this.RoleManager          = new RoleManager();
                    this.HelpTool             = new HelpTool();
                    this.Catalog              = new Catalog();
                    this.Navigator            = new Navigator();
                    this.ItemManager          = new ItemManager();
                    this.RoomManager          = new RoomManager();
                    this.PixelManager         = new PixelManager();
                    this.AchievementManager   = new AchievementManager();
                    this.ModerationTool       = new ModerationTool();
                    this.BotManager           = new BotManager();
                    this.Marketplace          = new Marketplace();
                    this.QuestManager         = new QuestManager();
                    this.EssentialEnvironment = new EssentialEnvironment();
                    this.GamesManager         = new GamesManager();
                    this.Groups    = new Groups();
                    this.StormWars = new WarsData();
                    EssentialEnvironment.LoadExternalTexts(dbClient);

                    this.BanManager.Initialise(dbClient);

                    this.RoleManager.Initialize(dbClient);

                    this.HelpTool.method_0(dbClient);
                    this.HelpTool.method_3(dbClient);

                    this.ModerationTool.method_1(dbClient);
                    this.ModerationTool.method_2(dbClient);
                    this.ItemManager.Initialize(dbClient);
                    this.Catalog.Initialize(dbClient);
                    this.Catalog.InitializeCache();
                    PetRace.Init(dbClient);
                    this.Navigator.Initialize(dbClient);
                    this.RoomManager.method_8(dbClient);
                    this.RoomManager.method_0();
                    this.NavigatorCache = new NavigatorCache();
                    this.RoomManager.LoadMagicTiles(dbClient);
                    this.RoomManager.LoadBillboards(dbClient);
                    this.BotManager.Initialize(dbClient);
                    AchievementManager.Load(dbClient);
                    this.PixelManager.Initialize();
                    ChatCommandHandler.Initialize(dbClient);
                    this.QuestManager.Initialize();
                    // this.GamesManager.LoadGameLocales(dbClient);
                    // this.GamesManager.LoadPowerupPackages(dbClient);
                    Groups.Initialize(dbClient);
                    guideManager = new GuideManager(dbClient);
                    this.RestoreStatistics(dbClient, 1);
                }
            }
            catch (MySql.Data.MySqlClient.MySqlException e)
            {
                Logging.WriteLine("failed!", ConsoleColor.Red);
                Logging.WriteLine(e.Message + " Check the given configuration details in config.conf\r\n", ConsoleColor.Yellow);
                Essential.Destroy("", true, true);

                return;
            }

            this.task_0 = new Task(new Action(LowPriorityWorker.Work));
            this.task_0.Start();

            StartGameLoop();
        }
Ejemplo n.º 9
0
        public void HandleRequest(string Request, SocketConnection socket)
        {
            //Yes, i know, that's shitty coded, but it works. At least for me.. Do it better & don't hate me :)
            bool f = false;

            if (Request.StartsWith("GET"))
            {
                string[] Splits = Request.Split(' ');
                if (Request.Split(' ')[1].Equals("/"))
                {
                    socket.SendFile("web/index.html");
                }

                else if (Request.Split(' ')[1].StartsWith("/emu/console"))
                {
                    List <string> alreadySent = new List <string>();
                    if (Splits[1].Split('?')[1].StartsWith("key") && Splits[1].Split('?')[1].Split('=')[1] == Essential.GetConfig().data["web.key"])
                    {
                        try
                        {
                            string[] asdf = Essential.GetConsoleWriter().GetLines();
                            foreach (string line in asdf.ToList <string>())
                            {
                                socket.SendMessage(line + "\n");
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                    else
                    {
                        this.Close(socket);
                    }
                }
                else if (Request.Split(' ')[1].StartsWith("/emu/exceptions"))
                {
                    if (Splits[1].Split('?')[1].StartsWith("key") && Splits[1].Split('?')[1].Split('=')[1] == Essential.GetConfig().data["web.key"])
                    {
                        socket.SendFile("exceptions.err");
                    }
                    else
                    {
                        this.Close(socket);
                    }
                }
                else if (Request.Split(' ')[1].StartsWith("/emu/restart"))
                {
                    if (Splits[1].Split('?')[1].StartsWith("key") && Splits[1].Split('?')[1].Split('=')[1] == Essential.GetConfig().data["web.key"])
                    {
                        socket.SendMessage("Bye!");
                        this.Close(socket);
                        Console.Clear();
                        Core.Logging.Disable();
                        Essential.Destroy("Disposing.......", false);
                        Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
                        Environment.Exit(0);
                    }
                    else
                    {
                        this.Close(socket);
                    }
                }
                else if (Request.Split(' ')[1].StartsWith("/emu/console/clear"))
                {
                    if (Splits[1].Split('?')[1].StartsWith("key") && Splits[1].Split('?')[1].Split('=')[1] == Essential.GetConfig().data["web.key"])
                    {
                        Console.Clear();
                        Essential.GetConsoleWriter().ClearIt();
                    }
                    else
                    {
                        this.Close(socket);
                    }
                }
                else if (Request.Split(' ')[1].StartsWith("/api/furni"))
                {
                    if (Splits[1].Split('?')[1].StartsWith("name"))
                    {
                        FurniImage.HandleRequest(Splits[1].Split('?')[1].Split('=')[1], socket);
                    }
                    else
                    {
                        this.Close(socket);
                    }
                }
                {
                    socket.SendFile("web" + Request.Split(' ')[1]);
                }
            }
            else if (Request.StartsWith("POST"))
            {
                if (Request.Split(' ')[1].Equals("/"))
                {
                    socket.SendFile("web/index.html");
                }
                else
                {
                    socket.SendFile("web" + Request.Split(' ')[1]);
                }
            }
            if (!f)
            {
                this.Close(socket);
            }
        }