예제 #1
0
        internal static UserData GetUserData(int UserId)
        {
            DataRow   dataRow;
            uint      num;
            DataRow   row;
            DataTable table;

            using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor())
            {
                queryreactor.setQuery("SELECT users.* FROM users WHERE users.id = @id");
                queryreactor.addParameter("id", UserId);
                dataRow = queryreactor.getRow();
                CyberEnvironment.GetGame().GetClientManager().LogClonesOut(Convert.ToUInt32(UserId));
                if (dataRow == null)
                {
                    UserData result = null;
                    return(result);
                }
                num = Convert.ToUInt32(dataRow["id"]);
                if (CyberEnvironment.GetGame().GetClientManager().GetClientByUserID(num) != null)
                {
                    UserData result = null;
                    return(result);
                }
                queryreactor.setQuery("SELECT group_id,rank FROM group_memberships WHERE user_id=" + UserId);
                queryreactor.getTable();
                queryreactor.setQuery("SELECT * FROM user_stats WHERE id=" + num + " LIMIT 1");
                row = queryreactor.getRow();
                queryreactor.setQuery("SELECT * FROM user_relationships WHERE user_id=@id");
                queryreactor.addParameter("id", num);
                table = queryreactor.getTable();
            }
            Dictionary <string, UserAchievement> achievements = new Dictionary <string, UserAchievement>();
            Dictionary <int, UserTalent>         talents      = new Dictionary <int, UserTalent>();
            List <uint>         favouritedRooms          = new List <uint>();
            List <uint>         ignores                  = new List <uint>();
            List <string>       tags                     = new List <string>();
            List <Badge>        badges                   = new List <Badge>();
            List <UserItem>     inventory                = new List <UserItem>();
            List <AvatarEffect> effects                  = new List <AvatarEffect>();
            Dictionary <uint, MessengerBuddy>   friends  = new Dictionary <uint, MessengerBuddy>();
            Dictionary <uint, MessengerRequest> requests = new Dictionary <uint, MessengerRequest>();
            HashSet <RoomData>             rooms         = new HashSet <RoomData>();
            Dictionary <uint, Pet>         pets          = new Dictionary <uint, Pet>();
            Dictionary <uint, int>         quests        = new Dictionary <uint, int>();
            Dictionary <uint, RoomBot>     bots          = new Dictionary <uint, RoomBot>();
            HashSet <GroupUser>            group         = new HashSet <GroupUser>();
            HashSet <uint>                 pollData      = new HashSet <uint>();
            Dictionary <int, Relationship> dictionary    = new Dictionary <int, Relationship>();

            foreach (DataRow dataRow2 in table.Rows)
            {
                dictionary.Add((int)dataRow2[0], new Relationship((int)dataRow2[0], (int)dataRow2[2], Convert.ToInt32(dataRow2[3].ToString())));
            }
            Habbo user = HabboFactory.GenerateHabbo(dataRow, row, group);

            dataRow = null;

            return(new UserData(num, achievements, talents, favouritedRooms, ignores, tags, null, badges, inventory, effects, friends, requests, rooms, pets, quests, user, bots, dictionary, pollData, 0));
        }
예제 #2
0
        /// <summary>
        /// Gets the user data.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <returns>UserData.</returns>
        internal static UserData GetUserData(int userId)
        {
            DataRow   dataRow;
            uint      num;
            DataRow   row;
            DataTable table;

            using (var queryReactor = Plus.GetDatabaseManager().GetQueryReactor())
            {
                queryReactor.SetQuery(string.Format("SELECT * FROM users WHERE id = '{0}'", userId));
                dataRow = queryReactor.GetRow();
                Plus.GetGame().GetClientManager().LogClonesOut(Convert.ToUInt32(userId));
                if (dataRow == null)
                {
                    return(null);
                }
                num = Convert.ToUInt32(dataRow["id"]);
                if (Plus.GetGame().GetClientManager().GetClientByUserId(num) != null)
                {
                    return(null);
                }
                queryReactor.SetQuery(string.Format("SELECT job_id,job_rank FROM rp_stats WHERE id={0}", userId));
                queryReactor.GetTable();
                queryReactor.SetQuery(string.Format("SELECT * FROM users_stats WHERE id={0} LIMIT 1", num));
                row = queryReactor.GetRow();

                if (row == null)
                {
                }
                queryReactor.SetQuery("SELECT * FROM users_relationships WHERE user_id=@id");
                queryReactor.AddParameter("id", num);
                table = queryReactor.GetTable();
            }
            var achievements    = new Dictionary <string, UserAchievement>();
            var talents         = new Dictionary <int, UserTalent>();
            var favouritedRooms = new List <uint>();
            var ignores         = new List <uint>();
            var tags            = new List <string>();
            var badges          = new List <Badge>();
            var inventory       = new List <UserItem>();
            var effects         = new List <AvatarEffect>();
            var friends         = new Dictionary <uint, MessengerBuddy>();
            var requests        = new Dictionary <uint, MessengerRequest>();
            var rooms           = new HashSet <RoomData>();
            var pets            = new Dictionary <uint, Pet>();
            var quests          = new Dictionary <uint, int>();
            var bots            = new Dictionary <uint, RoomBot>();
            var group           = new HashSet <GroupUser>();
            var pollData        = new HashSet <uint>();
            var dictionary      = table.Rows.Cast <DataRow>()
                                  .ToDictionary(dataRow2 => (int)dataRow2[0],
                                                dataRow2 =>
                                                new Relationship((int)dataRow2[0], (int)dataRow2[2], Convert.ToInt32(dataRow2[3].ToString())));
            var user = HabboFactory.GenerateHabbo(dataRow, row, group);

            dataRow = null;

            return(new UserData(num, achievements, talents, favouritedRooms, ignores, tags, null, badges, inventory,
                                effects, friends, requests, rooms, pets, quests, user, bots, dictionary, pollData, 0));
        }
예제 #3
0
        public static UserData GetUserData(int UserId)
        {
            DataRow   dUserInfo  = null;
            DataRow   UserInfo   = null;
            DataTable dRelations = null;
            DataTable dGroups    = null;

            using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `users` WHERE `id` = @id LIMIT 1");
                dbClient.AddParameter("id", UserId);
                dUserInfo = dbClient.getRow();

                QuasarEnvironment.GetGame().GetClientManager().LogClonesOut(Convert.ToInt32(UserId));

                if (dUserInfo == null)
                {
                    return(null);
                }

                if (QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId) != null)
                {
                    return(null);
                }


                dbClient.SetQuery("SELECT * FROM `user_info` WHERE `user_id` = '" + UserId + "' LIMIT 1");
                UserInfo = dbClient.getRow();
                if (UserInfo == null)
                {
                    dbClient.RunQuery("INSERT INTO `user_info` (`user_id`) VALUES ('" + UserId + "')");

                    dbClient.SetQuery("SELECT * FROM `user_info` WHERE `user_id` = '" + UserId + "' LIMIT 1");
                    UserInfo = dbClient.getRow();
                }

                dbClient.SetQuery("SELECT group_id,rank FROM group_memberships WHERE user_id=@id");
                dbClient.AddParameter("id", UserId);
                dGroups = dbClient.getTable();

                dbClient.SetQuery("SELECT `id`,`target`,`type` FROM user_relationships WHERE user_id=@id");
                dbClient.AddParameter("id", UserId);
                dRelations = dbClient.getTable();
            }

            ConcurrentDictionary <string, UserAchievement> Achievements = new ConcurrentDictionary <string, UserAchievement>();
            Dictionary <int, UserTalent> talents = new Dictionary <int, UserTalent>();
            List <int>   FavouritedRooms         = new List <int>();
            List <int>   Ignores = new List <int>();
            List <Badge> Badges  = new List <Badge>();
            Dictionary <int, MessengerBuddy>   Friends        = new Dictionary <int, MessengerBuddy>();
            Dictionary <int, MessengerRequest> FriendRequests = new Dictionary <int, MessengerRequest>();
            List <RoomData>                   Rooms           = new List <RoomData>();
            Dictionary <int, int>             Quests          = new Dictionary <int, int>();
            Dictionary <string, Subscription> subscriptions   = new Dictionary <string, Subscription>();

            Dictionary <int, Relationship> Relationships = new Dictionary <int, Relationship>();

            foreach (DataRow Row in dRelations.Rows)
            {
                if (!Relationships.ContainsKey(Convert.ToInt32(Row["id"])))
                {
                    Relationships.Add(Convert.ToInt32(Row["target"]), new Relationship(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["target"]), Convert.ToInt32(Row["type"].ToString())));
                }
            }

            Habbo user = HabboFactory.GenerateHabbo(dUserInfo, UserInfo);

            return(new UserData(UserId, Achievements, FavouritedRooms, Ignores, Badges, Friends, FriendRequests, Rooms, Quests, user, Relationships, talents, subscriptions));
        }
예제 #4
0
        public static UserData GetUserData(string SessionTicket, out byte errorCode)
        {
            int       UserId;
            DataRow   dUserInfo       = null;
            DataTable dAchievements   = null;
            DataTable dFavouriteRooms = null;
            DataTable dIgnores        = null;
            DataTable dBadges         = null;
            DataTable dEffects        = null;
            DataTable dFriends        = null;
            DataTable dRequests       = null;
            DataTable dRooms          = null;
            DataTable dQuests         = null;
            DataTable dRelations      = null;
            DataTable talentsTable    = null;
            DataRow   UserInfo        = null;
            DataTable Subscriptions   = null;

            using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `users` WHERE `auth_ticket` = @sso LIMIT 1");
                dbClient.AddParameter("sso", SessionTicket);
                dUserInfo = dbClient.getRow();

                if (dUserInfo == null)
                {
                    errorCode = 1;
                    return(null);
                }

                UserId = Convert.ToInt32(dUserInfo["id"]);
                if (QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId) != null)
                {
                    errorCode = 2;
                    QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId).Disconnect();
                    return(null);
                }

                dbClient.SetQuery("SELECT `group`,`level`,`progress` FROM `user_achievements` WHERE `userid` = '" + UserId + "'");
                dAchievements = dbClient.getTable();

                dbClient.SetQuery("SELECT room_id FROM user_favorites WHERE `user_id` = '" + UserId + "'");
                dFavouriteRooms = dbClient.getTable();

                dbClient.SetQuery("SELECT ignore_id FROM user_ignores WHERE `user_id` = '" + UserId + "'");
                dIgnores = dbClient.getTable();

                dbClient.SetQuery("SELECT `badge_id`,`badge_slot` FROM user_badges WHERE `user_id` = '" + UserId + "'");
                dBadges = dbClient.getTable();

                dbClient.SetQuery("SELECT `effect_id`,`total_duration`,`is_activated`,`activated_stamp` FROM user_effects WHERE `user_id` = '" + UserId + "'");
                dEffects = dbClient.getTable();

                dbClient.SetQuery(
                    "SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online " +
                    "FROM users " +
                    "JOIN messenger_friendships " +
                    "ON users.id = messenger_friendships.user_one_id " +
                    "WHERE messenger_friendships.user_two_id = " + UserId + " " +
                    "UNION ALL " +
                    "SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online " +
                    "FROM users " +
                    "JOIN messenger_friendships " +
                    "ON users.id = messenger_friendships.user_two_id " +
                    "WHERE messenger_friendships.user_one_id = " + UserId);
                dFriends = dbClient.getTable();

                dbClient.SetQuery("SELECT messenger_requests.from_id,messenger_requests.to_id,users.username FROM users JOIN messenger_requests ON users.id = messenger_requests.from_id WHERE messenger_requests.to_id = " + UserId);
                dRequests = dbClient.getTable();

                dbClient.SetQuery("SELECT * FROM rooms WHERE `owner` = '" + UserId + "' LIMIT 150");
                dRooms = dbClient.getTable();

                dbClient.SetQuery("SELECT * FROM users_talents WHERE userid = '" + UserId + "'");
                talentsTable = dbClient.getTable();

                dbClient.SetQuery("SELECT `quest_id`,`progress` FROM user_quests WHERE `user_id` = '" + UserId + "'");
                dQuests = dbClient.getTable();

                dbClient.SetQuery("SELECT * FROM `user_relationships` WHERE `user_id` = @id");
                dbClient.AddParameter("id", UserId);
                dRelations = dbClient.getTable();

                dbClient.SetQuery("SELECT * FROM user_subscriptions WHERE user_id = '" + UserId + "'");
                Subscriptions = dbClient.getTable();

                dbClient.SetQuery("SELECT * FROM `user_info` WHERE `user_id` = '" + UserId + "' LIMIT 1");
                UserInfo = dbClient.getRow();
                if (UserInfo == null)
                {
                    dbClient.RunQuery("INSERT INTO `user_info` (`user_id`) VALUES ('" + UserId + "')");

                    dbClient.SetQuery("SELECT * FROM `user_info` WHERE `user_id` = '" + UserId + "' LIMIT 1");
                    UserInfo = dbClient.getRow();
                }

                dbClient.runFastQuery("UPDATE users SET online='1' WHERE id=" + UserId + " LIMIT 1");
            }

            ConcurrentDictionary <string, UserAchievement> Achievements = new ConcurrentDictionary <string, UserAchievement>();

            foreach (DataRow dRow in dAchievements.Rows)
            {
                Achievements.TryAdd(Convert.ToString(dRow["group"]), new UserAchievement(Convert.ToString(dRow["group"]), Convert.ToInt32(dRow["level"]), Convert.ToInt32(dRow["progress"])));
            }

            List <int> favouritedRooms = new List <int>();

            foreach (DataRow dRow in dFavouriteRooms.Rows)
            {
                favouritedRooms.Add(Convert.ToInt32(dRow["room_id"]));
            }

            List <int> ignores = new List <int>();

            foreach (DataRow dRow in dIgnores.Rows)
            {
                ignores.Add(Convert.ToInt32(dRow["ignore_id"]));
            }

            List <Badge> badges = new List <Badge>();

            foreach (DataRow dRow in dBadges.Rows)
            {
                badges.Add(new Badge(Convert.ToString(dRow["badge_id"]), Convert.ToInt32(dRow["badge_slot"])));
            }

            Dictionary <int, MessengerBuddy> friends = new Dictionary <int, MessengerBuddy>();

            foreach (DataRow dRow in dFriends.Rows)
            {
                int    friendID         = Convert.ToInt32(dRow["id"]);
                string friendName       = Convert.ToString(dRow["username"]);
                string friendLook       = Convert.ToString(dRow["look"]);
                string friendMotto      = Convert.ToString(dRow["motto"]);
                int    friendLastOnline = Convert.ToInt32(dRow["last_online"]);
                bool   friendHideOnline = QuasarEnvironment.EnumToBool(dRow["hide_online"].ToString());
                bool   friendHideRoom   = QuasarEnvironment.EnumToBool(dRow["hide_inroom"].ToString());

                if (friendID == UserId)
                {
                    continue;
                }

                if (!friends.ContainsKey(friendID))
                {
                    friends.Add(friendID, new MessengerBuddy(friendID, friendName, friendLook, friendMotto, friendLastOnline, friendHideOnline, friendHideRoom));
                }
            }

            Dictionary <int, MessengerRequest> requests = new Dictionary <int, MessengerRequest>();

            foreach (DataRow dRow in dRequests.Rows)
            {
                int receiverID = Convert.ToInt32(dRow["from_id"]);
                int senderID   = Convert.ToInt32(dRow["to_id"]);

                string requestUsername = Convert.ToString(dRow["username"]);

                if (receiverID != UserId)
                {
                    if (!requests.ContainsKey(receiverID))
                    {
                        requests.Add(receiverID, new MessengerRequest(UserId, receiverID, requestUsername));
                    }
                }
                else
                {
                    if (!requests.ContainsKey(senderID))
                    {
                        requests.Add(senderID, new MessengerRequest(UserId, senderID, requestUsername));
                    }
                }
            }

            List <RoomData> rooms = new List <RoomData>();

            foreach (DataRow dRow in dRooms.Rows)
            {
                rooms.Add(QuasarEnvironment.GetGame().GetRoomManager().FetchRoomData(Convert.ToInt32(dRow["id"]), dRow));
            }

            Dictionary <int, int> quests = new Dictionary <int, int>();

            foreach (DataRow dRow in dQuests.Rows)
            {
                int questId = Convert.ToInt32(dRow["quest_id"]);

                if (quests.ContainsKey(questId))
                {
                    quests.Remove(questId);
                }

                quests.Add(questId, Convert.ToInt32(dRow["progress"]));
            }

            Dictionary <int, Relationship> Relationships = new Dictionary <int, Relationship>();

            foreach (DataRow Row in dRelations.Rows)
            {
                if (friends.ContainsKey(Convert.ToInt32(Row[2])))
                {
                    Relationships.Add(Convert.ToInt32(Row[2]), new Relationship(Convert.ToInt32(Row[0]), Convert.ToInt32(Row[2]), Convert.ToInt32(Row[3].ToString())));
                }
            }

            Dictionary <int, UserTalent> talents = new Dictionary <int, UserTalent>();

            if (talentsTable != null)
            {
                foreach (DataRow row in talentsTable.Rows)
                {
                    int num2  = (int)row["talent_id"];
                    int state = (int)row["talent_state"];

                    talents.Add(num2, new UserTalent(num2, state));
                }
            }

            Dictionary <string, Subscription> subscriptions = new Dictionary <string, Subscription>();

            foreach (DataRow dataRow in Subscriptions.Rows)
            {
                string str        = (string)dataRow["subscription_id"];
                int    TimeExpire = (int)dataRow["timestamp_expire"];

                subscriptions.Add(str, new Subscription(str, TimeExpire));
            }


            Habbo user = HabboFactory.GenerateHabbo(dUserInfo, UserInfo);

            dUserInfo       = null;
            dAchievements   = null;
            dFavouriteRooms = null;
            dIgnores        = null;
            dBadges         = null;
            dEffects        = null;
            dFriends        = null;
            dRequests       = null;
            dRooms          = null;
            dRelations      = null;

            errorCode = 0;
            return(new UserData(UserId, Achievements, favouritedRooms, ignores, badges, friends, requests, rooms, quests, user, Relationships, talents, subscriptions));
        }
예제 #5
0
        internal static UserData GetUserData(int userId)
        {
            DataRow   dUserInfo;
            DataRow   userInfo;
            DataTable dRelations;

            using (var dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery(
                    "SELECT `id`,`username`,`rank`,`motto`,`look`,`gender`,`last_online`,`credits`,`activity_points`,`home_room`,`block_newfriends`,`hide_online`,`hide_inroom`,`vip`,`account_created`,`vip_points`,`machine_id`,`volume`,`chat_preference`, `focus_preference`, `pets_muted`,`bots_muted`,`advertising_report_blocked`,`last_change`,`gotw_points`,`ignore_invites`,`time_muted`,`allow_gifts`,`friend_bar_state`,`disable_forced_effects`,`allow_mimic`,`rank_vip` FROM `users` WHERE `id` = @id LIMIT 1");
                dbClient.AddParameter("id", userId);
                dUserInfo = dbClient.GetRow();
                PlusEnvironment.GetGame().GetClientManager().LogClonesOut(Convert.ToInt32(userId));
                if (dUserInfo == null)
                {
                    return(null);
                }
                if (PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(userId) != null)
                {
                    return(null);
                }

                dbClient.SetQuery("SELECT * FROM `user_info` WHERE `user_id` = '" + userId + "' LIMIT 1");
                userInfo = dbClient.GetRow();
                if (userInfo == null)
                {
                    dbClient.RunQuery("INSERT INTO `user_info` (`user_id`) VALUES ('" + userId + "')");
                    dbClient.SetQuery("SELECT * FROM `user_info` WHERE `user_id` = '" + userId + "' LIMIT 1");
                    userInfo = dbClient.GetRow();
                }
                dbClient.SetQuery("SELECT group_id,rank FROM group_memberships WHERE user_id=@id");
                dbClient.AddParameter("id", userId);
                dbClient.GetTable();
                dbClient.SetQuery("SELECT `id`,`target`,`type` FROM user_relationships WHERE user_id=@id");
                dbClient.AddParameter("id", userId);
                dRelations = dbClient.GetTable();
            }

            var achievements    = new ConcurrentDictionary <string, UserAchievement>();
            var favouritedRooms = new List <int>();
            var badges          = new List <Badge>();
            var friends         = new Dictionary <int, MessengerBuddy>();
            var friendRequests  = new Dictionary <int, MessengerRequest>();
            var rooms           = new List <RoomData>();
            var quests          = new Dictionary <int, int>();
            var relationships   = new Dictionary <int, Relationship>();

            foreach (DataRow row in dRelations.Rows)
            {
                if (!relationships.ContainsKey(Convert.ToInt32(row["id"])))
                {
                    relationships.Add(Convert.ToInt32(row["target"]),
                                      new Relationship(Convert.ToInt32(row["id"]), Convert.ToInt32(row["target"]),
                                                       Convert.ToInt32(row["type"].ToString())));
                }
            }

            var user = HabboFactory.GenerateHabbo(dUserInfo, userInfo);

            return(new UserData(userId, achievements, favouritedRooms, badges, friends, friendRequests, rooms, quests, user,
                                relationships));
        }
예제 #6
0
        public static UserData GetUserData(string sessionTicket, out byte errorCode)
        {
            int       userId;
            DataRow   dUserInfo;
            DataTable dAchievements;
            DataTable dFavouriteRooms;
            DataTable dBadges;
            DataTable dFriends;
            DataTable dRequests;
            DataTable dRooms;
            DataTable dQuests;
            DataTable dRelations;
            DataRow   userInfo;

            using (var dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery(
                    "SELECT `id`,`username`,`rank`,`motto`,`look`,`gender`,`last_online`,`credits`,`activity_points`,`home_room`,`block_newfriends`,`hide_online`,`hide_inroom`,`vip`,`account_created`,`vip_points`,`machine_id`,`volume`,`chat_preference`,`focus_preference`, `pets_muted`,`bots_muted`,`advertising_report_blocked`,`last_change`,`gotw_points`,`ignore_invites`,`time_muted`,`allow_gifts`,`friend_bar_state`,`disable_forced_effects`,`allow_mimic`,`rank_vip` FROM `users` WHERE `auth_ticket` = @sso LIMIT 1");
                dbClient.AddParameter("sso", sessionTicket);
                dUserInfo = dbClient.GetRow();
                if (dUserInfo == null)
                {
                    errorCode = 1;
                    return(null);
                }

                userId = Convert.ToInt32(dUserInfo["id"]);
                if (PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(userId) != null)
                {
                    errorCode = 2;
                    PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(userId).Disconnect();
                    return(null);
                }

                dbClient.SetQuery("SELECT `group`,`level`,`progress` FROM `user_achievements` WHERE `userid` = '" + userId + "'");
                dAchievements = dbClient.GetTable();
                dbClient.SetQuery("SELECT room_id FROM user_favorites WHERE `user_id` = '" + userId + "'");
                dFavouriteRooms = dbClient.GetTable();
                dbClient.SetQuery("SELECT `badge_id`,`badge_slot` FROM user_badges WHERE `user_id` = '" + userId + "'");
                dBadges = dbClient.GetTable();
                dbClient.SetQuery(
                    "SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online " +
                    "FROM users " +
                    "JOIN messenger_friendships " +
                    "ON users.id = messenger_friendships.user_one_id " +
                    "WHERE messenger_friendships.user_two_id = " +
                    userId +
                    " " +
                    "UNION ALL " +
                    "SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online " +
                    "FROM users " +
                    "JOIN messenger_friendships " +
                    "ON users.id = messenger_friendships.user_two_id " +
                    "WHERE messenger_friendships.user_one_id = " +
                    userId);
                dFriends = dbClient.GetTable();
                dbClient.SetQuery(
                    "SELECT messenger_requests.from_id,messenger_requests.to_id,users.username FROM users JOIN messenger_requests ON users.id = messenger_requests.from_id WHERE messenger_requests.to_id = " +
                    userId);
                dRequests = dbClient.GetTable();
                dbClient.SetQuery("SELECT * FROM rooms WHERE `owner` = '" + userId + "' LIMIT 150");
                dRooms = dbClient.GetTable();
                dbClient.SetQuery("SELECT `quest_id`,`progress` FROM user_quests WHERE `user_id` = '" + userId + "'");
                dQuests = dbClient.GetTable();
                dbClient.SetQuery("SELECT `id`,`user_id`,`target`,`type` FROM `user_relationships` WHERE `user_id` = '" + userId +
                                  "'");
                dRelations = dbClient.GetTable();
                dbClient.SetQuery("SELECT * FROM `user_info` WHERE `user_id` = '" + userId + "' LIMIT 1");
                userInfo = dbClient.GetRow();
                if (userInfo == null)
                {
                    dbClient.RunQuery("INSERT INTO `user_info` (`user_id`) VALUES ('" + userId + "')");
                    dbClient.SetQuery("SELECT * FROM `user_info` WHERE `user_id` = '" + userId + "' LIMIT 1");
                    userInfo = dbClient.GetRow();
                }
                dbClient.RunQuery("UPDATE `users` SET `online` = '1', `auth_ticket` = '' WHERE `id` = '" + userId + "' LIMIT 1");
            }

            var achievements = new ConcurrentDictionary <string, UserAchievement>();

            foreach (DataRow dRow in dAchievements.Rows)
            {
                achievements.TryAdd(Convert.ToString(dRow["group"]),
                                    new UserAchievement(Convert.ToString(dRow["group"]), Convert.ToInt32(dRow["level"]),
                                                        Convert.ToInt32(dRow["progress"])));
            }

            var favouritedRooms = (from DataRow dRow in dFavouriteRooms.Rows select Convert.ToInt32(dRow["room_id"])).ToList();

            var badges = (from DataRow dRow in dBadges.Rows select new Badge(Convert.ToString(dRow["badge_id"]), Convert.ToInt32(dRow["badge_slot"]))).ToList();

            var friends = new Dictionary <int, MessengerBuddy>();

            foreach (DataRow dRow in dFriends.Rows)
            {
                var friendId         = Convert.ToInt32(dRow["id"]);
                var friendName       = Convert.ToString(dRow["username"]);
                var friendLook       = Convert.ToString(dRow["look"]);
                var friendMotto      = Convert.ToString(dRow["motto"]);
                var friendLastOnline = Convert.ToInt32(dRow["last_online"]);
                var friendHideOnline = PlusEnvironment.EnumToBool(dRow["hide_online"].ToString());
                var friendHideRoom   = PlusEnvironment.EnumToBool(dRow["hide_inroom"].ToString());

                if (friendId == userId)
                {
                    continue;
                }

                if (!friends.ContainsKey(friendId))
                {
                    friends.Add(friendId,
                                new MessengerBuddy(friendId, friendName, friendLook, friendMotto, friendLastOnline, friendHideOnline,
                                                   friendHideRoom));
                }
            }

            var requests = new Dictionary <int, MessengerRequest>();

            foreach (DataRow dRow in dRequests.Rows)
            {
                var receiverId      = Convert.ToInt32(dRow["from_id"]);
                var senderId        = Convert.ToInt32(dRow["to_id"]);
                var requestUsername = Convert.ToString(dRow["username"]);

                if (receiverId != userId)
                {
                    if (!requests.ContainsKey(receiverId))
                    {
                        requests.Add(receiverId, new MessengerRequest(userId, receiverId, requestUsername));
                    }
                }
                else
                {
                    if (!requests.ContainsKey(senderId))
                    {
                        requests.Add(senderId, new MessengerRequest(userId, senderId, requestUsername));
                    }
                }
            }

            var rooms = (from DataRow dRow in dRooms.Rows select PlusEnvironment.GetGame().GetRoomManager().FetchRoomData(Convert.ToInt32(dRow["id"]), dRow)).ToList();

            var quests = new Dictionary <int, int>();

            foreach (DataRow dRow in dQuests.Rows)
            {
                var questId = Convert.ToInt32(dRow["quest_id"]);
                if (quests.ContainsKey(questId))
                {
                    quests.Remove(questId);
                }
                quests.Add(questId, Convert.ToInt32(dRow["progress"]));
            }

            var relationships = new Dictionary <int, Relationship>();

            foreach (DataRow row in dRelations.Rows)
            {
                if (friends.ContainsKey(Convert.ToInt32(row[2])))
                {
                    relationships.Add(Convert.ToInt32(row[2]),
                                      new Relationship(Convert.ToInt32(row[0]), Convert.ToInt32(row[2]), Convert.ToInt32(row[3].ToString())));
                }
            }

            var user = HabboFactory.GenerateHabbo(dUserInfo, userInfo);

            errorCode = 0;

            return(new UserData(userId, achievements, favouritedRooms, badges, friends, requests, rooms, quests, user,
                                relationships));
        }
예제 #7
0
        public static UserData GetUserData(int UserId)
        {
            DataRow   dUserInfo  = null;
            DataRow   UserInfo   = null;
            DataTable dRelations = null;
            DataTable dBadges    = null;

            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT `id`,`username`,`rank`,`motto`,`look`,`gender`,`last_online`,`credits`,`activity_points`,`home_room`,`block_newfriends`,`hide_online`,`hide_inroom`,`account_created`,`vip_points`,`machine_id`,`volume`,`chat_preference`, `focus_preference`, `pets_muted`,`bots_muted`,`advertising_report_blocked`,`last_change`,`event_points`,`ignore_invites`,`time_muted`,`allow_gifts`,`friend_bar_state`,`disable_forced_effects`,`allow_mimic`,`rank_vip`,`colour` FROM `users` WHERE `id` = @id LIMIT 1");
                dbClient.AddParameter("id", UserId);
                dUserInfo = dbClient.getRow();

                PlusEnvironment.GetGame().GetClientManager().LogClonesOut(Convert.ToInt32(UserId));

                if (dUserInfo == null)
                {
                    return(null);
                }

                if (PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId) != null)
                {
                    return(null);
                }


                dbClient.SetQuery("SELECT * FROM `user_info` WHERE `user_id` = '" + UserId + "' LIMIT 1");
                UserInfo = dbClient.getRow();
                if (UserInfo == null)
                {
                    dbClient.RunQuery("INSERT INTO `user_info` (`user_id`) VALUES ('" + UserId + "')");

                    dbClient.SetQuery("SELECT * FROM `user_info` WHERE `user_id` = '" + UserId + "' LIMIT 1");
                    UserInfo = dbClient.getRow();
                }

                dbClient.SetQuery("SELECT `id`,`target`,`type` FROM user_relationships WHERE user_id=@id");
                dbClient.AddParameter("id", UserId);
                dRelations = dbClient.getTable();

                dbClient.SetQuery("SELECT `badge_id`,`badge_slot` FROM user_badges WHERE `user_id`=@id");
                dbClient.AddParameter("id", UserId);
                dBadges = dbClient.getTable();
            }

            ConcurrentDictionary <string, UserAchievement> Achievements = new ConcurrentDictionary <string, UserAchievement>();
            List <int> FavouritedRooms = new List <int>();
            List <int> Ignores         = new List <int>();

            List <Badge> Badges = new List <Badge>();

            foreach (DataRow Row in dBadges.Rows)
            {
                Badges.Add(new Badge(Convert.ToString(Row["badge_id"]), Convert.ToInt32(Row["badge_slot"])));
            }

            Dictionary <int, MessengerBuddy>   Friends        = new Dictionary <int, MessengerBuddy>();
            Dictionary <int, MessengerRequest> FriendRequests = new Dictionary <int, MessengerRequest>();
            List <RoomData>       Rooms  = new List <RoomData>();
            Dictionary <int, int> Quests = new Dictionary <int, int>();

            Dictionary <int, Relationship> Relationships = new Dictionary <int, Relationship>();

            foreach (DataRow Row in dRelations.Rows)
            {
                if (!Relationships.ContainsKey(Convert.ToInt32(Row["id"])))
                {
                    Relationships.Add(Convert.ToInt32(Row["target"]), new Relationship(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["target"]), Convert.ToInt32(Row["type"].ToString())));
                }
            }

            Habbo user = HabboFactory.GenerateHabbo(dUserInfo, UserInfo);

            return(new UserData(UserId, Achievements, FavouritedRooms, Ignores, Badges, Friends, FriendRequests, Rooms, Quests, user, Relationships, null));
        }
예제 #8
0
        internal static UserData GetUserData(string sessionTicket, string ip, out byte errorCode)
        {
            DataTable dataTable = null;
            DataRow   dataRow;
            uint      Userid;
            DataTable dataTable2;
            DataTable table;
            DataRow   row;
            DataTable dataTable3;
            DataTable dataTable4;
            DataTable dataTable5;
            DataRow   dataRow2;
            DataTable dataTable6;
            DataTable dataTable7;
            DataTable dataTable8;
            DataTable dataTable9;
            DataTable dataTable10;
            DataTable dataTable11;
            DataTable dataTable12;
            DataTable dataTable13;
            DataTable table2;
            DataTable dataTable14;
            DataTable dataTable15;

            using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor())
            {
                queryreactor.setQuery("SELECT * FROM users WHERE auth_ticket = @sso ");
                queryreactor.addParameter("sso", sessionTicket);
                queryreactor.addParameter("ipaddress", ip);
                dataRow = queryreactor.getRow();
                if (dataRow == null)
                {
                    errorCode = 1;
                    throw new UserDataNotFoundException(string.Format("No user found with ip {0} and sso {1}.", ip, sessionTicket));
                }
                Userid = Convert.ToUInt32(dataRow["id"]);
                queryreactor.runFastQuery("UPDATE users SET online='1' WHERE id=" + Userid + " LIMIT 1");
                if (CyberEnvironment.GetGame().GetClientManager().GetClientByUserID(Userid) != null)
                {
                    errorCode = 2;
                    CyberEnvironment.GetGame().GetClientManager().GetClientByUserID(Userid).Disconnect();
                    return(null);
                }
                queryreactor.setQuery("SELECT * FROM user_achievement WHERE userid = " + Userid);
                dataTable2 = queryreactor.getTable();
                queryreactor.setQuery("SELECT * FROM user_talents WHERE userid = " + Userid);
                table = queryreactor.getTable();
                queryreactor.setQuery("SELECT COUNT(*) FROM user_stats WHERE id=" + Userid);
                if (int.Parse(queryreactor.getString()) == 0)
                {
                    queryreactor.runFastQuery("INSERT INTO user_stats (id) VALUES (" + Userid + ");");
                }
                queryreactor.setQuery("SELECT * FROM user_stats WHERE id=" + Userid + " LIMIT 1");
                row = queryreactor.getRow();
                queryreactor.setQuery("SELECT room_id FROM user_favorites WHERE user_id = " + Userid);
                dataTable3 = queryreactor.getTable();
                queryreactor.setQuery("SELECT ignore_id FROM user_ignores WHERE user_id = " + Userid);
                dataTable4 = queryreactor.getTable();
                queryreactor.setQuery("SELECT tag FROM user_tags WHERE user_id = " + Userid);
                dataTable5 = queryreactor.getTable();
                queryreactor.setQuery("SELECT * FROM user_subscriptions WHERE user_id = " + Userid + " AND timestamp_expire > UNIX_TIMESTAMP() ORDER BY subscription_id DESC LIMIT 1");
                dataRow2 = queryreactor.getRow();
                queryreactor.setQuery("SELECT * FROM user_badges WHERE user_id = " + Userid);
                dataTable6 = queryreactor.getTable();
                queryreactor.setQuery("SELECT `items`.* , COALESCE(`items_groups`.`group_id`, 0) AS group_id FROM `items` LEFT OUTER JOIN `items_groups` ON `items`.`id` = `items_groups`.`id` WHERE room_id='0' AND user_id=" + Userid + " LIMIT 8000");
                dataTable7 = queryreactor.getTable();
                queryreactor.setQuery("SELECT * FROM user_effects WHERE user_id =  " + Userid);
                dataTable8 = queryreactor.getTable();
                queryreactor.setQuery("SELECT poll_id FROM user_polldata WHERE user_id = " + Userid + " GROUP BY poll_id;");
                dataTable9 = queryreactor.getTable();
                queryreactor.setQuery(string.Concat(new object[]
                {
                    "SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE messenger_friendships.user_two_id = ",
                    Userid,
                    " UNION ALL SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = ",
                    Userid
                }));
                dataTable10 = queryreactor.getTable();
                queryreactor.setQuery("SELECT * FROM user_stats WHERE id=" + Userid + " LIMIT 1");
                row = queryreactor.getRow();
                queryreactor.setQuery("SELECT messenger_requests.from_id,messenger_requests.to_id,users.username FROM users JOIN messenger_requests ON users.id = messenger_requests.from_id WHERE messenger_requests.to_id = " + Userid);
                dataTable11 = queryreactor.getTable();
                queryreactor.setQuery("SELECT * FROM rooms WHERE owner = @name LIMIT 150");
                queryreactor.addParameter("name", (string)dataRow["username"]);
                dataTable12 = queryreactor.getTable();
                queryreactor.setQuery("SELECT * FROM bots WHERE user_id = " + Userid + " AND room_id = 0 AND ai_type='pet'");
                dataTable13 = queryreactor.getTable();
                queryreactor.setQuery("SELECT * FROM user_quests WHERE user_id = " + Userid);
                table2 = queryreactor.getTable();
                queryreactor.setQuery("SELECT * FROM bots WHERE user_id=" + Userid + " AND room_id=0 AND ai_type='generic'");
                dataTable14 = queryreactor.getTable();
                queryreactor.setQuery("SELECT group_id,rank FROM group_memberships WHERE user_id=" + Userid);
                dataTable = queryreactor.getTable();
                queryreactor.setQuery(string.Concat(new object[]
                {
                    "UPDATE user_info SET login_timestamp = '",
                    CyberEnvironment.GetUnixTimestamp(),
                    "' WHERE user_id = ",
                    Userid,
                    " ; "
                }));
                queryreactor.addParameter("ip", ip);
                queryreactor.runQuery();
                queryreactor.setQuery("SELECT * FROM user_relationships WHERE user_id=@id");
                queryreactor.addParameter("id", Userid);
                dataTable15 = queryreactor.getTable();
                queryreactor.runFastQuery("UPDATE users SET online='1' WHERE id=" + Userid + " LIMIT 1");
            }
            Dictionary <string, UserAchievement> dictionary = new Dictionary <string, UserAchievement>();

            foreach (DataRow dataRow3 in dataTable2.Rows)
            {
                string          text     = (string)dataRow3["group"];
                int             level    = (int)dataRow3["level"];
                int             progress = (int)dataRow3["progress"];
                UserAchievement value    = new UserAchievement(text, level, progress);
                dictionary.Add(text, value);
            }
            Dictionary <int, UserTalent> dictionary2 = new Dictionary <int, UserTalent>();

            foreach (DataRow dataRow4 in table.Rows)
            {
                int        num2   = (int)dataRow4["talent_id"];
                int        state  = (int)dataRow4["talent_state"];
                UserTalent value2 = new UserTalent(num2, state);
                dictionary2.Add(num2, value2);
            }
            List <uint> list = new List <uint>();

            foreach (DataRow dataRow5 in dataTable3.Rows)
            {
                uint item = Convert.ToUInt32(dataRow5["room_id"]);
                list.Add(item);
            }
            List <uint> list2 = new List <uint>();

            foreach (DataRow dataRow6 in dataTable4.Rows)
            {
                uint item2 = Convert.ToUInt32(dataRow6["ignore_id"]);
                list2.Add(item2);
            }
            List <string> list3 = new List <string>();

            foreach (DataRow dataRow7 in dataTable5.Rows)
            {
                string item3 = dataRow7["tag"].ToString().Replace(" ", "");
                list3.Add(item3);
            }
            Subscription sub = null;

            if (dataRow2 != null)
            {
                sub = new Subscription((int)dataRow2["subscription_id"], (int)dataRow2["timestamp_activated"], (int)dataRow2["timestamp_expire"], (int)dataRow2["timestamp_lastgift"]);
            }
            Dictionary <uint, RoomBot> dictionary3 = new Dictionary <uint, RoomBot>();

            foreach (DataRow row2 in dataTable14.Rows)
            {
                RoomBot roomBot = BotManager.GenerateBotFromRow(row2);
                dictionary3.Add(roomBot.BotId, roomBot);
            }
            List <Badge> list4 = new List <Badge>();

            foreach (DataRow dataRow8 in dataTable6.Rows)
            {
                string code = (string)dataRow8["badge_id"];
                int    slot = (int)dataRow8["badge_slot"];
                list4.Add(new Badge(code, slot));
            }

            int miniMailCount = 0;

            try
            {
                DataRow Rowi;
                using (IQueryAdapter dbClient = CyberEnvironment.GetDatabaseManager().getQueryReactor())
                {
                    dbClient.setQuery("SELECT Count( IsReaded ) FROM xdrcms_minimail WHERE InBin = 0 AND IsReaded = 0 AND SenderId != " + Userid + " AND OwnerId = " + Userid);
                    Rowi = dbClient.getRow();
                }
                if (Rowi != null)
                {
                    // We are using aXDR CMS with MiniMail!
                    miniMailCount = int.Parse(Rowi[0].ToString());
                }
            }
            catch { }

            List <UserItem> list5 = new List <UserItem>();

            foreach (DataRow dataRow9 in dataTable7.Rows)
            {
                uint   id       = Convert.ToUInt32(dataRow9[0]);
                uint   baseItem = Convert.ToUInt32(dataRow9[3]);
                string extraData;
                if (!DBNull.Value.Equals(dataRow9[4]))
                {
                    extraData = (string)dataRow9[4];
                }
                else
                {
                    extraData = string.Empty;
                }
                uint   group    = Convert.ToUInt32(dataRow9["group_id"]);
                string songCode = (string)dataRow9["songcode"];
                list5.Add(new UserItem(id, baseItem, extraData, group, songCode));
            }
            List <AvatarEffect> list6 = new List <AvatarEffect>();

            foreach (DataRow dataRow10 in dataTable8.Rows)
            {
                int    effectId          = (int)dataRow10["effect_id"];
                int    totalDuration     = (int)dataRow10["total_duration"];
                bool   activated         = CyberEnvironment.EnumToBool((string)dataRow10["is_activated"]);
                double activateTimestamp = (double)dataRow10["activated_stamp"];
                list6.Add(new AvatarEffect(effectId, totalDuration, activated, activateTimestamp));
            }

            HashSet <uint> pollSuggested = new HashSet <uint>();

            foreach (DataRow Row in dataTable9.Rows)
            {
                uint pId = (uint)Row["poll_id"];
                pollSuggested.Add(pId);
            }

            Dictionary <uint, MessengerBuddy> dictionary4 = new Dictionary <uint, MessengerBuddy>();
            string arg_A3D_0 = (string)dataRow["username"];
            int    num3      = checked (dataTable10.Rows.Count - 700);

            if (num3 > 0)
            {
                using (IQueryAdapter queryreactor2 = CyberEnvironment.GetDatabaseManager().getQueryReactor())
                {
                    queryreactor2.runFastQuery(string.Concat(new object[]
                    {
                        "DELETE FROM messenger_friendships WHERE user_one_id=",
                        Userid,
                        " OR user_two_id=",
                        Userid,
                        " LIMIT ",
                        num3
                    }));
                    queryreactor2.setQuery(string.Concat(new object[]
                    {
                        "SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE messenger_friendships.user_two_id = ",
                        Userid,
                        " UNION ALL SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = ",
                        Userid
                    }));
                    dataTable10 = queryreactor2.getTable();
                }
            }
            foreach (DataRow dataRow12 in dataTable10.Rows)
            {
                uint   num4           = Convert.ToUInt32(dataRow12["id"]);
                string pUsername      = (string)dataRow12["username"];
                string pLook          = (string)dataRow12["look"];
                string pMotto         = (string)dataRow12["motto"];
                int    pLastOnline    = Convert.ToInt32(dataRow12["last_online"]);
                bool   pAppearOffline = CyberEnvironment.EnumToBool(dataRow12["hide_online"].ToString());
                bool   pHideInroom    = CyberEnvironment.EnumToBool(dataRow12["hide_inroom"].ToString());
                if (num4 != Userid && !dictionary4.ContainsKey(num4))
                {
                    dictionary4.Add(num4, new MessengerBuddy(num4, pUsername, pLook, pMotto, pLastOnline, pAppearOffline, pHideInroom));
                }
            }
            Dictionary <uint, MessengerRequest> dictionary5 = new Dictionary <uint, MessengerRequest>();

            foreach (DataRow dataRow13 in dataTable11.Rows)
            {
                uint   num5       = Convert.ToUInt32(dataRow13["from_id"]);
                uint   num6       = Convert.ToUInt32(dataRow13["to_id"]);
                string pUsername2 = (string)dataRow13["username"];
                if (num5 != Userid)
                {
                    if (!dictionary5.ContainsKey(num5))
                    {
                        dictionary5.Add(num5, new MessengerRequest(Userid, num5, pUsername2));
                    }
                }
                else
                {
                    if (!dictionary5.ContainsKey(num6))
                    {
                        dictionary5.Add(num6, new MessengerRequest(Userid, num6, pUsername2));
                    }
                }
            }
            HashSet <RoomData> list8 = new HashSet <RoomData>();

            foreach (DataRow dataRow14 in dataTable12.Rows)
            {
                uint roomId = Convert.ToUInt32(dataRow14["id"]);
                list8.Add(CyberEnvironment.GetGame().GetRoomManager().FetchRoomData(roomId, dataRow14));
            }
            Dictionary <uint, Pet> dictionary6 = new Dictionary <uint, Pet>();

            foreach (DataRow dataRow15 in dataTable13.Rows)
            {
                using (IQueryAdapter queryreactor3 = CyberEnvironment.GetDatabaseManager().getQueryReactor())
                {
                    queryreactor3.setQuery("SELECT * FROM bots_petdata WHERE id=" + dataRow15[0] + " LIMIT 1");
                    DataRow row3 = queryreactor3.getRow();
                    if (row3 != null)
                    {
                        Pet pet = Catalog.GeneratePetFromRow(dataRow15, row3);
                        dictionary6.Add(pet.PetId, pet);
                    }
                }
            }
            Dictionary <uint, int> dictionary7 = new Dictionary <uint, int>();

            foreach (DataRow dataRow16 in table2.Rows)
            {
                uint key    = Convert.ToUInt32(dataRow16["quest_id"]);
                int  value3 = (int)dataRow16["progress"];
                if (dictionary7.ContainsKey(key))
                {
                    dictionary7.Remove(key);
                }
                dictionary7.Add(key, value3);
            }
            HashSet <GroupUser> list9 = new HashSet <GroupUser>();

            foreach (DataRow dataRow17 in dataTable.Rows)
            {
                list9.Add(new GroupUser(Userid, (uint)dataRow17[0], (int)Convert.ToInt16(dataRow17[1])));
            }
            Dictionary <int, Relationship> dictionary8 = new Dictionary <int, Relationship>();

            foreach (DataRow dataRow18 in dataTable15.Rows)
            {
                dictionary8.Add((int)dataRow18[0], new Relationship((int)dataRow18[0], (int)dataRow18[2], Convert.ToInt32(dataRow18[3].ToString())));
            }
            Habbo user = HabboFactory.GenerateHabbo(dataRow, row, list9);

            dataRow     = null;
            dataTable2  = null;
            dataTable3  = null;
            dataTable4  = null;
            dataTable5  = null;
            dataRow2    = null;
            dataTable6  = null;
            dataTable7  = null;
            dataTable8  = null;
            dataTable10 = null;
            dataTable11 = null;
            dataTable12 = null;
            dataTable13 = null;
            dataTable14 = null;
            dataTable15 = null;
            dataTable9  = null;
            errorCode   = 0;
            return(new UserData(Userid, dictionary, dictionary2, list, list2, list3, sub, list4, list5, list6, dictionary4, dictionary5, list8, dictionary6, dictionary7, user, dictionary3, dictionary8, pollSuggested, miniMailCount));
        }
예제 #9
0
        internal static UserData GetUserData(string sessionTicket)
        {
            DataRow   dUserInfo;
            DataTable dFavouriteRooms;
            DataTable dEffects;
            DataTable dFriends;
            DataTable dRequests;
            UInt32    userID;

            using (IQueryAdapter dbClient = OtanixEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("SELECT * FROM users RIGHT JOIN user_tickets ON user_tickets.userid = users.id WHERE user_tickets.sessionticket = @sso");
                dbClient.addParameter("sso", sessionTicket);
                dUserInfo = dbClient.getRow();

                if (dUserInfo == null)
                {
                    // Si no existe el ticket; Este fallo no debería existir NUNCA.
                    return(null);
                }

                userID = Convert.ToUInt32(dUserInfo["id"]);

                if (OtanixEnvironment.GetGame().GetClientManager().GetClientByUserID(userID) != null)
                {
                    // Desconectamos al usuario conectado ya.
                    OtanixEnvironment.GetGame().GetClientManager().GetClientByUserID(userID).Disconnect();

                    dbClient.setQuery("SELECT * FROM users WHERE id = '" + userID + "'");
                    dUserInfo = dbClient.getRow();
                }

                // Manda las salas favoritas al Login, por lo tanto se queda aquí esto.
                dbClient.setQuery("SELECT room_id FROM user_favorites WHERE user_id = " + userID);
                dFavouriteRooms = dbClient.getTable();

                // Manda los efectos al conectarse, por lo tanto lo dejamos así.
                dbClient.setQuery("SELECT * FROM user_effects WHERE user_id =  " + userID + " GROUP by effect_id");
                dEffects = dbClient.getTable();

                // Los amigos son urgentes para conectarse
                dbClient.setQuery("SELECT users.id,users.username,users.motto,users.look,users.last_online " +
                                  "FROM users " +
                                  "JOIN messenger_friendships " +
                                  "ON users.id = messenger_friendships.sender " +
                                  "WHERE messenger_friendships.receiver = " + userID + " " +
                                  "UNION ALL " +
                                  "SELECT users.id,users.username,users.motto,users.look,users.last_online " +
                                  "FROM users " +
                                  "JOIN messenger_friendships " +
                                  "ON users.id = messenger_friendships.receiver " +
                                  "WHERE messenger_friendships.sender = " + userID + " LIMIT " + EmuSettings.FRIENDS_LIMIT);
                dFriends = dbClient.getTable();

                // Comprobamos si hay peticiones de amistad.
                dbClient.setQuery("SELECT messenger_requests.sender,messenger_requests.receiver,users.username " +
                                  "FROM users " +
                                  "JOIN messenger_requests " +
                                  "ON users.id = messenger_requests.sender " +
                                  "WHERE messenger_requests.receiver = " + userID + " LIMIT " + EmuSettings.FRIENDS_REQUEST_LIMIT);
                dRequests = dbClient.getTable();
            }

            List <uint> favouritedRooms = new List <uint>();

            foreach (DataRow dRow in dFavouriteRooms.Rows)
            {
                favouritedRooms.Add(Convert.ToUInt32(dRow["room_id"]));
            }

            List <AvatarEffect> effects = new List <AvatarEffect>();

            foreach (DataRow dRow in dEffects.Rows)
            {
                effects.Add(new AvatarEffect((int)dRow["effect_id"], (int)dRow["total_duration"], OtanixEnvironment.EnumToBool((string)dRow["is_activated"]), (double)dRow["activated_stamp"], (int)dRow["effect_count"]));
            }

            Dictionary <uint, MessengerBuddy> friends = new Dictionary <uint, MessengerBuddy>();

            foreach (DataRow dRow in dFriends.Rows)
            {
                if (Convert.ToUInt32(dRow["id"]) == userID)
                {
                    continue;
                }

                if (!friends.ContainsKey(Convert.ToUInt32(dRow["id"])))
                {
                    friends.Add(Convert.ToUInt32(dRow["id"]), new MessengerBuddy(Convert.ToUInt32(dRow["id"]), (string)dRow["username"], (string)dRow["look"], (string)dRow["motto"]));
                }
            }

            Dictionary <uint, MessengerRequest> requests = new Dictionary <uint, MessengerRequest>();

            foreach (DataRow dRow in dRequests.Rows)
            {
                if (Convert.ToUInt32(dRow["sender"]) != userID)
                {
                    if (!requests.ContainsKey(Convert.ToUInt32(dRow["sender"])))
                    {
                        requests.Add(Convert.ToUInt32(dRow["sender"]), new MessengerRequest(userID, Convert.ToUInt32(dRow["sender"]), (string)dRow["username"]));
                    }
                }
                else
                {
                    if (!requests.ContainsKey(Convert.ToUInt32(dRow["receiver"])))
                    {
                        requests.Add(Convert.ToUInt32(dRow["receiver"]), new MessengerRequest(userID, Convert.ToUInt32(dRow["receiver"]), (string)dRow["username"]));
                    }
                }
            }

            Habbo user = HabboFactory.GenerateHabbo(dUserInfo);

            dUserInfo       = null;
            dFavouriteRooms = null;
            dEffects        = null;
            dFriends        = null;
            dRequests       = null;

            return(new UserData(favouritedRooms, effects, friends, requests, user));
        }
예제 #10
0
        /// <summary>
        /// Gets the user data.
        /// </summary>
        /// <param name="sessionTicket">The session ticket.</param>
        /// <param name="ip">The ip.</param>
        /// <param name="errorCode">The error code.</param>
        /// <returns>UserData.</returns>
        /// <exception cref="UserDataNotFoundException"></exception>
        internal static UserData GetUserData(string sessionTicket, out uint errorCode)
        {
            uint userid = 0, miniMailCount = 0;

            errorCode = 1;

            DataTable groupsTable;
            DataRow   dataRow;
            DataTable achievementsTable;
            DataTable talentsTable;
            DataRow   statsTable;
            DataTable favoritesTable;
            DataTable ignoresTable;
            DataTable tagsTable;
            DataRow   subscriptionsRow;
            DataTable badgesTable;
            DataTable itemsTable;
            DataTable effectsTable;
            DataTable pollsTable;
            DataTable friendsTable;
            DataTable friendsRequestsTable;
            DataTable myRoomsTable;
            DataTable petsTable;
            DataTable questsTable;
            DataTable botsTable;
            DataTable relationShipsTable;

            try
            {
                using (var queryReactor = Plus.GetDatabaseManager().GetQueryReactor())
                {
                    queryReactor.SetQuery("SELECT * FROM users WHERE auth_ticket = @ticket");
                    queryReactor.AddParameter("ticket", sessionTicket);
                    dataRow = queryReactor.GetRow();
                    if (dataRow == null)
                    {
                        return(null);
                    }

                    errorCode = 0;
                    userid    = Convert.ToUInt32(dataRow["id"]);

                    //queryReactor.RunFastQuery(string.Format("UPDATE users SET online = '1' WHERE id = '{0}'", userid));
                    if (Plus.GetGame().GetClientManager().GetClientByUserId(userid) != null)
                    {
                        if (Plus.GetGame().GetClientManager().GetClientByUserId(userid).LoggingOut)
                        {
                            //Plus.GetGame().GetClientManager().GetClientByUserId(userid).Disconnect("Force logout");
                            return(null);
                        }
                        else
                        {
                            Plus.GetGame().GetClientManager().GetClientByUserId(userid).Disconnect("User connected in other place");
                        }
                    }

                    queryReactor.SetQuery(string.Format("SELECT `group`, `level`, progress FROM users_achievements WHERE userid = {0}", Convert.ToUInt32(userid)));
                    achievementsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT talent_id, talent_state FROM users_talents WHERE userid = {0}", Convert.ToUInt32(userid)));
                    talentsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT COUNT(*) FROM users_stats WHERE id = {0}", Convert.ToUInt32(userid)));
                    if (int.Parse(queryReactor.GetString()) == 0)
                    {
                        queryReactor.RunFastQuery(string.Format("INSERT INTO users_stats (id) VALUES ({0})", Convert.ToUInt32(userid)));
                    }

                    queryReactor.SetQuery(string.Format("SELECT room_id FROM users_favorites WHERE user_id = {0}", Convert.ToUInt32(userid)));
                    favoritesTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT ignore_id FROM users_ignores WHERE user_id = {0}", Convert.ToUInt32(userid)));
                    ignoresTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT tag FROM users_tags WHERE user_id = {0}", Convert.ToUInt32(userid)));
                    tagsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT subscription_id, timestamp_activated, timestamp_expire, timestamp_lastgift FROM users_subscriptions WHERE user_id = {0} AND timestamp_expire > UNIX_TIMESTAMP() ORDER BY subscription_id DESC LIMIT 1", Convert.ToUInt32(userid)));
                    subscriptionsRow = queryReactor.GetRow();

                    queryReactor.SetQuery(string.Format("SELECT * FROM users_badges WHERE user_id = {0}", Convert.ToUInt32(userid)));
                    badgesTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT `items_rooms`.* , COALESCE(`items_groups`.`group_id`, 0) AS group_id FROM `items_rooms` LEFT OUTER JOIN `items_groups` ON `items_rooms`.`id` = `items_groups`.`id` WHERE room_id='0' AND user_id={0} LIMIT 8000", Convert.ToUInt32(userid)));
                    itemsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT * FROM users_effects WHERE user_id = {0}", Convert.ToUInt32(userid)));
                    effectsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT poll_id FROM users_polls WHERE user_id = {0} GROUP BY poll_id;", Convert.ToUInt32(userid)));
                    pollsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE messenger_friendships.user_two_id = {0} UNION ALL SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = {0}", Convert.ToUInt32(userid)));
                    friendsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT * FROM users_stats WHERE id = {0}", Convert.ToUInt32(userid)));
                    statsTable = queryReactor.GetRow();

                    queryReactor.SetQuery(string.Format("SELECT messenger_requests.from_id,messenger_requests.to_id,users.Username FROM users JOIN messenger_requests ON users.id = messenger_requests.from_id WHERE messenger_requests.to_id = {0}", Convert.ToUInt32(userid)));
                    friendsRequestsTable = queryReactor.GetTable();

                    queryReactor.SetQuery("SELECT * FROM rooms_data WHERE owner = @name LIMIT 150");
                    queryReactor.AddParameter("name", dataRow["username"]);
                    myRoomsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT * FROM bots WHERE user_id = {0} AND room_id = 0 AND ai_type = 'fightpet'", Convert.ToUInt32(userid)));
                    petsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT quest_id, progress FROM users_quests_data WHERE user_id = {0}", Convert.ToUInt32(userid)));
                    questsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT * FROM bots WHERE user_id = {0} AND room_id=0 AND ai_type !='pet' AND ai_type != 'fightpet'", Convert.ToUInt32(userid)));
                    botsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("SELECT group_id,rank FROM groups_members WHERE user_id = {0}", Convert.ToUInt32(userid)));
                    groupsTable = queryReactor.GetTable();

                    queryReactor.SetQuery(string.Format("UPDATE users_info SET login_timestamp = '{1}' WHERE user_id = {0}", Convert.ToUInt32(userid), Plus.GetUnixTimeStamp()));
                    queryReactor.RunQuery();

                    queryReactor.SetQuery(string.Format("SELECT * FROM users_relationships WHERE user_id = {0}", Convert.ToUInt32(userid)));
                    relationShipsTable = queryReactor.GetTable();

                    queryReactor.RunFastQuery(string.Format("UPDATE users SET online='1' WHERE id = {0} LIMIT 1", Convert.ToUInt32(userid)));
                }

                var achievements = new Dictionary <string, UserAchievement>();
                foreach (DataRow row in achievementsTable.Rows)
                {
                    var text     = (string)row["group"];
                    var level    = (int)row["level"];
                    var progress = (int)row["progress"];
                    var value    = new UserAchievement(text, level, progress);
                    achievements.Add(text, value);
                }

                var talents = new Dictionary <int, UserTalent>();
                foreach (DataRow row in talentsTable.Rows)
                {
                    var num2   = (int)row["talent_id"];
                    var state  = (int)row["talent_state"];
                    var value2 = new UserTalent(num2, state);
                    talents.Add(num2, value2);
                }

                var favorites     = (from DataRow row in favoritesTable.Rows select(uint) row["room_id"]).ToList();
                var ignoreUsers   = (from DataRow row in ignoresTable.Rows select(uint) row["ignore_id"]).ToList();
                var tags          = (from DataRow row in tagsTable.Rows select row["tag"].ToString().Replace(" ", "")).ToList();
                var inventoryBots =
                    (from DataRow row2 in botsTable.Rows select BotManager.GenerateBotFromRow(row2)).ToDictionary(
                        roomBot => roomBot.BotId);
                var badges =
                    (from DataRow dataRow8 in badgesTable.Rows
                     select new Badge((string)dataRow8["badge_id"], (int)dataRow8["badge_slot"])).ToList();

                Subscription subscriptions = null;
                if (subscriptionsRow != null)
                {
                    subscriptions = new Subscription((int)subscriptionsRow["subscription_id"],
                                                     (int)subscriptionsRow["timestamp_activated"], (int)subscriptionsRow["timestamp_expire"],
                                                     (int)subscriptionsRow["timestamp_lastgift"]);
                }

                var items = new List <UserItem>();
                foreach (DataRow row in itemsTable.Rows)
                {
                    var id     = Convert.ToUInt32(row[0]);
                    var itemId = Convert.ToUInt32(row[3]);

                    if (!Plus.GetGame().GetItemManager().ContainsItem(itemId))
                    {
                        continue;
                    }

                    var extraData = !DBNull.Value.Equals(row[4]) ? (string)row[4] : string.Empty;

                    var group    = Convert.ToUInt32(row["group_id"]);
                    var songCode = (string)row["songcode"];
                    items.Add(new UserItem(id, itemId, extraData, group, songCode));
                }

                var effects = (from DataRow row in effectsTable.Rows
                               let effectId = (int)row["effect_id"]
                                              let totalDuration = (int)row["total_duration"]
                                                                  let activated = Plus.EnumToBool((string)row["is_activated"])
                                                                                  let activateTimestamp = (double)row["activated_stamp"]
                                                                                                          let type = Convert.ToInt16(row["type"])
                                                                                                                     select new AvatarEffect(effectId, totalDuration, activated, activateTimestamp, type)).ToList();

                var pollSuggested = new HashSet <uint>();
                foreach (uint pId in from DataRow row in pollsTable.Rows select(uint) row["poll_id"])
                {
                    pollSuggested.Add(pId);
                }

                var friends = new Dictionary <uint, MessengerBuddy>();
                var limit   = (friendsTable.Rows.Count - 10000);

                if (limit > 0)
                {
                    using (var queryreactor2 = Plus.GetDatabaseManager().GetQueryReactor())
                    {
                        queryreactor2.RunFastQuery(string.Concat("DELETE FROM messenger_friendships WHERE user_one_id=", userid, " OR user_two_id=", userid, " LIMIT ", limit));
                        queryreactor2.SetQuery(string.Concat("SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_one_id WHERE messenger_friendships.user_two_id = ", userid, " UNION ALL SELECT users.id,users.username,users.motto,users.look,users.last_online,users.hide_inroom,users.hide_online FROM users JOIN messenger_friendships ON users.id = messenger_friendships.user_two_id WHERE messenger_friendships.user_one_id = ", userid));
                        friendsTable = queryreactor2.GetTable();
                    }
                }

                foreach (DataRow row in friendsTable.Rows)
                {
                    var num4           = Convert.ToUInt32(row["id"]);
                    var pUsername      = (string)row["username"];
                    var pLook          = (string)row["look"];
                    var pMotto         = (string)row["motto"];
                    var pLastOnline    = Convert.ToInt32(row["last_online"]);
                    var pAppearOffline = Plus.EnumToBool(row["hide_online"].ToString());
                    var pHideInroom    = Plus.EnumToBool(row["hide_inroom"].ToString());
                    if (num4 != userid && !friends.ContainsKey(num4))
                    {
                        friends.Add(num4,
                                    new MessengerBuddy(num4, pUsername, pLook, pMotto, pLastOnline, pAppearOffline, pHideInroom));
                    }
                }

                var friendsRequests = new Dictionary <uint, MessengerRequest>();
                foreach (DataRow row in friendsRequestsTable.Rows)
                {
                    var num5       = Convert.ToUInt32(row["from_id"]);
                    var num6       = Convert.ToUInt32(row["to_id"]);
                    var pUsername2 = (string)row["Username"];
                    if (num5 != userid)
                    {
                        if (!friendsRequests.ContainsKey(num5))
                        {
                            friendsRequests.Add(num5, new MessengerRequest(userid, num5, pUsername2));
                        }
                        else if (!friendsRequests.ContainsKey(num6))
                        {
                            friendsRequests.Add(num6, new MessengerRequest(userid, num6, pUsername2));
                        }
                    }
                }

                var myRooms = new HashSet <RoomData>();
                foreach (DataRow row in myRoomsTable.Rows)
                {
                    var roomId = Convert.ToUInt32(row["id"]);
                    myRooms.Add(Plus.GetGame().GetRoomManager().FetchRoomData(roomId, row));
                }

                var pets = new Dictionary <uint, Pet>();
                foreach (DataRow row in petsTable.Rows)
                {
                    using (var queryreactor3 = Plus.GetDatabaseManager().GetQueryReactor())
                    {
                        queryreactor3.SetQuery(string.Format("SELECT * FROM pets_data WHERE id={0} LIMIT 1", row[0]));
                        var row3 = queryreactor3.GetRow();
                        if (row3 == null)
                        {
                            continue;
                        }
                        var pet = Catalog.GeneratePetFromRow(row, row3);
                        pets.Add(pet.PetId, pet);
                    }
                }

                var quests = new Dictionary <uint, int>();
                foreach (DataRow row in questsTable.Rows)
                {
                    var key    = Convert.ToUInt32(row["quest_id"]);
                    var value3 = (int)row["progress"];
                    if (quests.ContainsKey(key))
                    {
                        quests.Remove(key);
                    }
                    quests.Add(key, value3);
                }

                var groups = new HashSet <GroupUser>();
                foreach (DataRow row in groupsTable.Rows)
                {
                    groups.Add(new GroupUser(userid, (uint)row[0], Convert.ToInt16(row[1])));
                }

                var relationShips = relationShipsTable.Rows.Cast <DataRow>()
                                    .ToDictionary(row => (int)row[0],
                                                  row => new Relationship((int)row[0], (int)row[2], Convert.ToInt32(row[3].ToString())));

                var user = HabboFactory.GenerateHabbo(dataRow, statsTable, groups);
                dataRow              = null;
                achievementsTable    = null;
                favoritesTable       = null;
                ignoresTable         = null;
                tagsTable            = null;
                subscriptionsRow     = null;
                badgesTable          = null;
                itemsTable           = null;
                effectsTable         = null;
                friendsTable         = null;
                friendsRequestsTable = null;
                myRoomsTable         = null;
                petsTable            = null;
                botsTable            = null;
                relationShipsTable   = null;
                pollsTable           = null;

                errorCode = 0;
                if (user.Rank >= Plus.StaffAlertMinRank)
                {
                    friends.Add(0, new MessengerBuddy(0, "Staff Chat", "hr-831-45.fa-1206-91.sh-290-1331.ha-3129-100.hd-180-2.cc-3039-73.ch-3215-92.lg-270-73", string.Empty, 0, false, true));
                }
                //if (user.Rank >= 2)
                //    friends.Add(999999999, new MessengerBuddy(999999999, "VIP Chat", "hr-831-45.fa-1206-91.sh-290-1331.ha-3129-100.hd-180-2.cc-3039-73.ch-3215-92.lg-270-73", string.Empty, 999999999, false, true));

                return(new UserData(userid, achievements, talents, favorites, ignoreUsers, tags, subscriptions, badges,
                                    items, effects, friends, friendsRequests, myRooms, pets, quests, user, inventoryBots, relationShips,
                                    pollSuggested, miniMailCount));
            }
            catch (Exception e)
            {
                errorCode = 1;
                Out.WriteLine("An error occured when trying to login a user, could be possibly a error within the MySQL query.\n\n" + e.StackTrace, "", ConsoleColor.DarkRed);
                return(null);
            }
        }
예제 #11
0
        internal static UserData GetUserData(string sessionTicket, string ip, out byte errorCode)
        {
            DataRow dUserInfo;

            DataTable dAchievements;
            DataTable dFavouriteRooms;
            DataTable dIgnores;
            DataTable dTags;
            DataTable dSubscriptions;
            DataTable dBadges;
            DataTable dInventory;
            DataTable dEffects;
            DataTable dFriends;
            DataTable dRequests;
            DataTable dRooms;
            DataTable dPets;
            DataTable dQuests;
            //DataTable dSongs;
            DataRow dGroups = null;

            UInt32 userID;

            using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor())
            {
                if (PiciEnvironment.useSSO)
                {
                    dbClient.setQuery("SELECT * FROM users WHERE auth_ticket = @sso " +
                                      "AND ip_last = @ipaddress ");
                }
                else
                {
                    dbClient.setQuery("SELECT * FROM users WHERE auth_ticket = @sso " +
                                      "AND ip_last = @ipaddress ");
                }

                dbClient.addParameter("sso", sessionTicket);
                dbClient.addParameter("ipaddress", ip);
                dUserInfo = dbClient.getRow();


                if (dUserInfo == null)
                {
                    errorCode = 1;
                    return(null);
                    //Logging.LogException("No user found. Debug data: [" + sessionTicket + "], [" + ip + "]");
                    //thRow new UserDataNotFoundException(string.Format("No user found with ip {0} and sso {1}. Use SSO: {2} ", ip, sessionTicket, PiciEnvironment.useSSO.ToString()));
                }


                userID = Convert.ToUInt32(dUserInfo["id"]);
                if (PiciEnvironment.GetGame().GetClientManager().GetClientByUserID(userID) != null)
                {
                    errorCode = 2;
                    return(null);
                }

                string creditsTimestamp = (string)dUserInfo["lastdailycredits"];
                string todayTimestamp   = DateTime.Today.ToString("MM/dd");
                if (creditsTimestamp != todayTimestamp)
                {
                    dbClient.runFastQuery("UPDATE users SET credits = credits + 3000, daily_respect_points = 3, lastdailycredits = '" + todayTimestamp + "' WHERE id = " + userID);
                    dUserInfo["credits"] = (int)dUserInfo["credits"] + 3000;
                }

                dbClient.setQuery("SELECT * FROM user_achievement WHERE userid = " + userID);
                dAchievements = dbClient.getTable();

                dbClient.setQuery("SELECT room_id FROM user_favorites WHERE user_id = " + userID);
                dFavouriteRooms = dbClient.getTable();

                dbClient.setQuery("SELECT ignore_id FROM user_ignores WHERE user_id = " + userID);
                dIgnores = dbClient.getTable();

                dbClient.setQuery("SELECT tag FROM user_tags WHERE user_id = " + userID);
                dTags = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_subscriptions WHERE user_id = " + userID);
                dSubscriptions = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_badges WHERE user_id = " + userID);
                dBadges = dbClient.getTable();

                if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MySQL)
                {
                    dbClient.setQuery("CALL getuseritems(" + userID + ")");
                }
                else
                {
                    dbClient.setQuery("EXECUTE getuseritems " + userID + "");
                }
                dInventory = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_effects WHERE user_id =  " + userID);
                dEffects = dbClient.getTable();

                dbClient.setQuery("SELECT users.id,users.username,users.motto,users.look,users.last_online " +
                                  "FROM users " +
                                  "JOIN messenger_friendships " +
                                  "ON users.id = messenger_friendships.sender " +
                                  "WHERE messenger_friendships.receiver = " + userID + " " +
                                  "UNION ALL " +
                                  "SELECT users.id,users.username,users.motto,users.look,users.last_online " +
                                  "FROM users " +
                                  "JOIN messenger_friendships " +
                                  "ON users.id = messenger_friendships.receiver " +
                                  "WHERE messenger_friendships.sender = " + userID);
                dFriends = dbClient.getTable();

                dbClient.setQuery("SELECT messenger_requests.sender,messenger_requests.receiver,users.username " +
                                  "FROM users " +
                                  "JOIN messenger_requests " +
                                  "ON users.id = messenger_requests.sender " +
                                  "WHERE messenger_requests.receiver = " + userID);
                dRequests = dbClient.getTable();

                dbClient.setQuery("SELECT rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE owner = @name");
                dbClient.addParameter("name", (string)dUserInfo["username"]);
                dRooms = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_pets WHERE user_id = " + userID + " AND room_id = 0");
                dPets = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_quests WHERE user_id = " + userID + "");
                dQuests = dbClient.getTable();

                if (PiciEnvironment.groupsEnabled)
                {
                    dbClient.setQuery("SELECT groups_memberships.*, groups_details.* FROM groups_memberships " +
                                      "LEFT JOIN groups_details " +
                                      "ON groups_memberships.groupid = groups_details.id " +
                                      "WHERE groups_memberships.userid = " + userID + " AND groups_memberships.is_current = '1'");

                    dGroups = dbClient.getRow();
                }

                //dbClient.setQuery("SELECT item_id, song_id FROM user_items_songs WHERE user_id = " + userID);
                //dSongs = dbClient.getTable();


                /* dbClient.setQuery("UPDATE users SET ip_last = @ip WHERE id = " + userID + " LIMIT 1; " +
                 *                     "UPDATE user_info SET login_timestamp = '" + PiciEnvironment.GetUnixTimestamp() + "' WHERE user_id = " + userID + " LIMIT 1; " +
                 *                     "REPLACE INTO user_online VALUES (" + userID + "); " +
                 *                     "DELETE FROM user_tickets WHERE userid = " + userID + ";");*/

                dbClient.setQuery("UPDATE users SET ip_last = @ip WHERE id = " + userID + "; " +
                                  "UPDATE user_info SET login_timestamp = '" + PiciEnvironment.GetUnixTimestamp() + "' WHERE user_id = " + userID + " ; " +
                                  "");
                dbClient.addParameter("ip", ip);
                dbClient.runQuery();

                if (dbClient.dbType == Pici.Storage.Database.DatabaseType.MySQL)
                {
                    dbClient.runFastQuery("REPLACE INTO user_online VALUES (" + userID + ")");
                }
                else
                {
                    dbClient.runFastQuery("IF NOT EXISTS (SELECT userid FROM user_online WHERE userid = " + userID + ") " +
                                          "INSERT INTO user_online VALUES (" + userID + ")");
                }
            }

            Dictionary <string, UserAchievement> achievements = new Dictionary <string, UserAchievement>();

            string achievementGroup;
            int    achievementLevel;
            int    achievementProgress;

            foreach (DataRow dRow in dAchievements.Rows)
            {
                achievementGroup    = (string)dRow["group"];
                achievementLevel    = (int)dRow["level"];
                achievementProgress = (int)dRow["progress"];

                UserAchievement achievement = new UserAchievement(achievementGroup, achievementLevel, achievementProgress);
                achievements.Add(achievementGroup, achievement);
            }

            List <uint> favouritedRooms = new List <uint>();

            uint favoritedRoomID;

            foreach (DataRow dRow in dFavouriteRooms.Rows)
            {
                favoritedRoomID = Convert.ToUInt32(dRow["room_id"]);
                favouritedRooms.Add(favoritedRoomID);
            }


            List <uint> ignores = new List <uint>();

            uint ignoredUserID;

            foreach (DataRow dRow in dIgnores.Rows)
            {
                ignoredUserID = Convert.ToUInt32(dRow["ignore_id"]);
                ignores.Add(ignoredUserID);
            }


            List <string> tags = new List <string>();

            string tag;

            foreach (DataRow dRow in dTags.Rows)
            {
                tag = (string)dRow["tag"];
                tags.Add(tag);
            }

            Dictionary <string, Subscription> subscriptions = new Dictionary <string, Subscription>();

            string subscriptionID;
            int    expireTimestamp;

            foreach (DataRow dRow in dSubscriptions.Rows)
            {
                subscriptionID  = (string)dRow["subscription_id"];
                expireTimestamp = (int)dRow["timestamp_expire"];

                subscriptions.Add(subscriptionID, new Subscription(subscriptionID, expireTimestamp));
            }

            List <Badge> badges = new List <Badge>();

            string badgeID;
            int    slotID;

            foreach (DataRow dRow in dBadges.Rows)
            {
                badgeID = (string)dRow["badge_id"];
                slotID  = (int)dRow["badge_slot"];
                badges.Add(new Badge(badgeID, slotID));
            }


            List <UserItem> inventory = new List <UserItem>();

            uint   itemID;
            uint   baseItem;
            string extraData;

            foreach (DataRow dRow in dInventory.Rows)
            {
                itemID   = Convert.ToUInt32(dRow[0]);
                baseItem = Convert.ToUInt32(dRow[1]);
                if (!DBNull.Value.Equals(dRow[2]))
                {
                    extraData = (string)dRow[2];
                }
                else
                {
                    extraData = string.Empty;
                }

                inventory.Add(new UserItem(itemID, baseItem, extraData));
            }


            List <AvatarEffect> effects = new List <AvatarEffect>();

            int    effectID;
            int    duration;
            bool   isActivated;
            double activatedTimeStamp;

            foreach (DataRow dRow in dEffects.Rows)
            {
                effectID           = (int)dRow["effect_id"];
                duration           = (int)dRow["total_duration"];
                isActivated        = PiciEnvironment.EnumToBool((string)dRow["is_activated"]);
                activatedTimeStamp = (double)dRow["activated_stamp"];

                effects.Add(new AvatarEffect(effectID, duration, isActivated, activatedTimeStamp));
            }


            Dictionary <uint, MessengerBuddy> friends = new Dictionary <uint, MessengerBuddy>();

            string username = (string)dUserInfo["username"];

            UInt32 friendID;
            string friendName;
            string friendLook;
            string friendMotto;
            string friendLastOnline;

            foreach (DataRow dRow in dFriends.Rows)
            {
                friendID         = Convert.ToUInt32(dRow["id"]);
                friendName       = (string)dRow["username"];
                friendLook       = (string)dRow["look"];
                friendMotto      = (string)dRow["motto"];
                friendLastOnline = (string)dRow["last_online"];


                if (friendID == userID)
                {
                    continue;
                }


                if (!friends.ContainsKey(friendID))
                {
                    friends.Add(friendID, new MessengerBuddy(friendID, friendName, friendLook, friendMotto, friendLastOnline));
                }
            }

            Dictionary <uint, MessengerRequest> requests = new Dictionary <uint, MessengerRequest>();

            uint   receiverID;
            uint   senderID;
            string requestUsername;

            foreach (DataRow dRow in dRequests.Rows)
            {
                receiverID = Convert.ToUInt32(dRow["sender"]);
                senderID   = Convert.ToUInt32(dRow["receiver"]);

                requestUsername = (string)dRow["username"];

                if (receiverID != userID)
                {
                    if (!requests.ContainsKey(receiverID))
                    {
                        requests.Add(receiverID, new MessengerRequest(userID, receiverID, requestUsername));
                    }
                }
                else
                {
                    if (!requests.ContainsKey(senderID))
                    {
                        requests.Add(senderID, new MessengerRequest(userID, senderID, requestUsername));
                    }
                }
            }

            List <RoomData> rooms = new List <RoomData>();

            uint roomID;

            foreach (DataRow dRow in dRooms.Rows)
            {
                roomID = Convert.ToUInt32(dRow["id"]);
                rooms.Add(PiciEnvironment.GetGame().GetRoomManager().FetchRoomData(roomID, dRow));
            }


            Dictionary <uint, Pet> pets = new Dictionary <uint, Pet>();

            Pet pet;

            foreach (DataRow dRow in dPets.Rows)
            {
                pet = Catalog.GeneratePetFromRow(dRow);
                pets.Add(pet.PetId, pet);
            }



            Dictionary <uint, int> quests = new Dictionary <uint, int>();

            uint questId;
            int  progress;

            foreach (DataRow dRow in dQuests.Rows)
            {
                questId  = Convert.ToUInt32(dRow["quest_id"]);
                progress = (int)dRow["progress"];
                quests.Add(questId, progress);
            }

            Hashtable songs = new Hashtable();

            //uint songItemID;
            //uint songID;
            //foreach (DataRow dRow in dSongs.Rows)
            //{
            //    songItemID = (uint)dRow[0];
            //    songID = (uint)dRow[1];

            //    SongItem song = new SongItem(songItemID, songID);
            //    songs.Add(songItemID, song);
            //}

            Habbo user = HabboFactory.GenerateHabbo(dUserInfo, dGroups);

            dUserInfo       = null;
            dAchievements   = null;
            dFavouriteRooms = null;
            dIgnores        = null;
            dTags           = null;
            dSubscriptions  = null;
            dBadges         = null;
            dInventory      = null;
            dEffects        = null;
            dFriends        = null;
            dRequests       = null;
            dRooms          = null;
            dPets           = null;

            errorCode = 0;
            return(new UserData(userID, achievements, favouritedRooms, ignores, tags, subscriptions, badges, inventory, effects, friends, requests, rooms, pets, quests, songs, user));
        }
예제 #12
0
        internal static UserData GetUserData(int UserId)
        {
            byte    errorCode;
            DataRow dUserInfo;

            DataTable dAchievements;
            DataTable dFavouriteRooms;
            DataTable dIgnores;
            DataTable dTags;
            DataTable dSubscriptions;
            DataTable dBadges;
            DataTable dInventory;
            DataTable dEffects;
            DataTable dFriends;
            DataTable dRequests;
            DataTable dRooms;
            DataTable dPets;
            DataTable dQuests;
            //DataTable dSongs;

            int userID;

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("SELECT users.* FROM users WHERE users.id = @id");
                dbClient.addParameter("id", UserId);
                dUserInfo = dbClient.getRow();


                if (dUserInfo == null)
                {
                    errorCode = 1;
                    return(null);
                    //Logging.LogException("No user found. Debug data: [" + sessionTicket + "], [" + ip + "]");
                    //throw new UserDataNotFoundException(string.Format("No user found with ip {0} and sso {1}. Use SSO: {2} ", ip, sessionTicket, FirewindEnvironment.useSSO.ToString()));
                }


                userID = Convert.ToInt32(dUserInfo["id"]);
                if (FirewindEnvironment.GetGame().GetClientManager().GetClientByUserID(userID) != null)
                {
                    errorCode = 2;
                    return(null);
                }

                /**
                 * string creditsTimestamp = (string)dUserInfo["lastdailycredits"];
                 * string todayTimestamp = DateTime.Today.ToString("MM/dd");
                 * if (creditsTimestamp != todayTimestamp)
                 * {
                 *  dbClient.runFastQuery("UPDATE users SET credits = credits + 3000, daily_respect_points = 3, lastdailycredits = '" + todayTimestamp + "' WHERE id = " + userID);
                 *  dUserInfo["credits"] = (int)dUserInfo["credits"] + 3000;
                 * }
                 * ***/
                /**
                 * dbClient.setQuery("SELECT * FROM user_achievement WHERE userid = " + userID);
                 * dAchievements = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT room_id FROM user_favorites WHERE user_id = " + userID);
                 * dFavouriteRooms = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT ignore_id FROM user_ignores WHERE user_id = " + userID);
                 * dIgnores = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT tag FROM user_tags WHERE user_id = " + userID);
                 * dTags = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT * FROM user_subscriptions WHERE user_id = " + userID);
                 * dSubscriptions = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT * FROM user_badges WHERE user_id = " + userID);
                 * dBadges = dbClient.getTable();
                 *
                 * if (dbClient.dbType == Database_Manager.Database.DatabaseType.MySQL)
                 *  dbClient.setQuery("CALL getuseritems(" + userID + ")");
                 * else
                 *  dbClient.setQuery("EXECUTE getuseritems " + userID + "");
                 * dInventory = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT * FROM user_effects WHERE user_id =  " + userID);
                 * dEffects = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT users.id,users.username,users.motto,users.look,users.last_online " +
                 *                      "FROM users " +
                 *                      "JOIN messenger_friendships " +
                 *                      "ON users.id = messenger_friendships.sender " +
                 *                      "WHERE messenger_friendships.receiver = " + userID + " " +
                 *                      "UNION ALL " +
                 *                      "SELECT users.id,users.username,users.motto,users.look,users.last_online " +
                 *                      "FROM users " +
                 *                      "JOIN messenger_friendships " +
                 *                      "ON users.id = messenger_friendships.receiver " +
                 *                      "WHERE messenger_friendships.sender = " + userID);
                 * dFriends = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT messenger_requests.sender,messenger_requests.receiver,users.username " +
                 *                      "FROM users " +
                 *                      "JOIN messenger_requests " +
                 *                      "ON users.id = messenger_requests.sender " +
                 *                      "WHERE messenger_requests.receiver = " + userID);
                 * dRequests = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE owner = @name");
                 * dbClient.addParameter("name", (string)dUserInfo["username"]);
                 * dRooms = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT * FROM user_pets WHERE user_id = " + userID + " AND room_id = 0");
                 * dPets = dbClient.getTable();
                 *
                 * dbClient.setQuery("SELECT * FROM user_quests WHERE user_id = " + userID + "");
                 * dQuests = dbClient.getTable();
                 **/
            }

            Dictionary <string, UserAchievement> achievements = new Dictionary <string, UserAchievement>();


            /**
             *             string achievementGroup;
             * int achievementLevel;
             * int achievementProgress;
             * foreach (DataRow dRow in dAchievements.Rows)
             * {
             *  achievementGroup = (string)dRow["group"];
             *  achievementLevel = (int)dRow["level"];
             *  achievementProgress = (int)dRow["progress"];
             *
             *  UserAchievement achievement = new UserAchievement(achievementGroup, achievementLevel, achievementProgress);
             *  achievements.Add(achievementGroup, achievement);
             * }
             **/
            List <uint> favouritedRooms = new List <uint>();

            /**
             * uint favoritedRoomID;
             * foreach (DataRow dRow in dFavouriteRooms.Rows)
             * {
             *  favoritedRoomID = Convert.ToUInt32(dRow["room_id"]);
             *  favouritedRooms.Add(favoritedRoomID);
             * }
             **/

            List <int> ignores = new List <int>();

            /**
             * uint ignoredUserID;
             * foreach (DataRow dRow in dIgnores.Rows)
             * {
             *  ignoredUserID = Convert.ToUInt32(dRow["ignore_id"]);
             *  ignores.Add(ignoredUserID);
             * }
             *
             **/
            List <string> tags = new List <string>();

            /**
             * string tag;
             * foreach (DataRow dRow in dTags.Rows)
             * {
             *  tag = (string)dRow["tag"];
             *  tags.Add(tag);
             * }
             */
            Dictionary <string, Subscription> subscriptions = new Dictionary <string, Subscription>();

            /**
             * string subscriptionID;
             * int expireTimestamp;
             * foreach (DataRow dRow in dSubscriptions.Rows)
             * {
             *  subscriptionID = (string)dRow["subscription_id"];
             *  expireTimestamp = (int)dRow["timestamp_expire"];
             *
             *  subscriptions.Add(subscriptionID, new Subscription(subscriptionID, expireTimestamp));
             * }
             **/
            List <Badge> badges = new List <Badge>();

            /**
             * string badgeID;
             * int slotID;
             * foreach (DataRow dRow in dBadges.Rows)
             * {
             *  badgeID = (string)dRow["badge_id"];
             *  slotID = (int)dRow["badge_slot"];
             *  badges.Add(new Badge(badgeID, slotID));
             * }
             *
             **/
            List <UserItem> inventory = new List <UserItem>();

            /**
             * uint itemID;
             * uint baseItem;
             * string extraData;
             * foreach (DataRow dRow in dInventory.Rows)
             * {
             *  itemID = Convert.ToUInt32(dRow[0]);
             *  baseItem = Convert.ToUInt32(dRow[1]);
             *  if (!DBNull.Value.Equals(dRow[2]))
             *      extraData = (string)dRow[2];
             *  else
             *      extraData = string.Empty;
             *
             *  inventory.Add(new UserItem(itemID, baseItem, extraData));
             * }
             *
             **/
            List <AvatarEffect> effects = new List <AvatarEffect>();

            /**
             * int effectID;
             * int duration;
             * bool isActivated;
             * double activatedTimeStamp;
             * foreach (DataRow dRow in dEffects.Rows)
             * {
             *  effectID = (int)dRow["effect_id"];
             *  duration = (int)dRow["total_duration"];
             *  isActivated = FirewindEnvironment.EnumToBool((string)dRow["is_activated"]);
             *  activatedTimeStamp = (double)dRow["activated_stamp"];
             *
             *  effects.Add(new AvatarEffect(effectID, duration, isActivated, activatedTimeStamp));
             * }
             *
             **/
            Dictionary <int, MessengerBuddy> friends = new Dictionary <int, MessengerBuddy>();

            string username = (string)dUserInfo["username"];

            /**
             * UInt32 friendID;
             * string friendName;
             * string friendLook;
             * string friendMotto;
             * string friendLastOnline;
             * foreach (DataRow dRow in dFriends.Rows)
             * {
             *  friendID = Convert.ToUInt32(dRow["id"]);
             *  friendName = (string)dRow["username"];
             *  friendLook = (string)dRow["look"];
             *  friendMotto = (string)dRow["motto"];
             *  friendLastOnline = (string)dRow["last_online"];
             *
             *
             *  if (friendID == userID)
             *      continue;
             *
             *
             *  if (!friends.ContainsKey(friendID))
             *      friends.Add(friendID, new MessengerBuddy(friendID, friendName, friendLook, friendMotto, friendLastOnline));
             * }
             **/
            Dictionary <int, MessengerRequest> requests = new Dictionary <int, MessengerRequest>();

            /**
             * uint receiverID;
             * uint senderID;
             * string requestUsername;
             * foreach (DataRow dRow in dRequests.Rows)
             * {
             *  receiverID = Convert.ToUInt32(dRow["sender"]);
             *  senderID = Convert.ToUInt32(dRow["receiver"]);
             *
             *  requestUsername = (string)dRow["username"];
             *
             *  if (receiverID != userID)
             *  {
             *      if (!requests.ContainsKey(receiverID))
             *          requests.Add(receiverID, new MessengerRequest(userID, receiverID, requestUsername));
             *  }
             *  else
             *  {
             *      if (!requests.ContainsKey(senderID))
             *          requests.Add(senderID, new MessengerRequest(userID, senderID, requestUsername));
             *  }
             * }
             **/
            List <RoomData> rooms = new List <RoomData>();

            /**
             * uint roomID;
             * foreach (DataRow dRow in dRooms.Rows)
             * {
             *  roomID = Convert.ToUInt32(dRow["id"]);
             *  rooms.Add(FirewindEnvironment.GetGame().GetRoomManager().FetchRoomData(roomID, dRow));
             * }
             *
             **/
            Dictionary <uint, Pet>        pets = new Dictionary <uint, Pet>();
            Dictionary <int, RentableBot> bots = new Dictionary <int, RentableBot>();

            /**
             * Pet pet;
             * foreach (DataRow dRow in dPets.Rows)
             * {
             *  pet = Catalog.GeneratePetFromRow(dRow);
             *  pets.Add(pet.PetId, pet);
             * }
             *
             **/


            Dictionary <uint, int> quests = new Dictionary <uint, int>();

            /**
             * uint questId;
             * int progress;
             * foreach (DataRow dRow in dQuests.Rows)
             * {
             *  questId = Convert.ToUInt32(dRow["quest_id"]);
             *  progress = (int)dRow["progress"];
             *  quests.Add(questId, progress);
             * }
             **/
            Hashtable songs = new Hashtable();

            /**
             * //uint songItemID;
             * //uint songID;
             * //foreach (DataRow dRow in dSongs.Rows)
             * //{
             * //    songItemID = (uint)dRow[0];
             * //    songID = (uint)dRow[1];
             *
             * //    SongItem song = new SongItem(songItemID, songID);
             * //    songs.Add(songItemID, song);
             * //}
             **/
            Habbo user = HabboFactory.GenerateHabbo(dUserInfo);

            dUserInfo       = null;
            dAchievements   = null;
            dFavouriteRooms = null;
            dIgnores        = null;
            dTags           = null;
            dSubscriptions  = null;
            dBadges         = null;
            dInventory      = null;
            dEffects        = null;
            dFriends        = null;
            dRequests       = null;
            dRooms          = null;
            dPets           = null;

            errorCode = 0;
            return(new UserData(userID, achievements, favouritedRooms, ignores, tags, subscriptions, badges, inventory, effects, friends, requests, rooms, pets, quests, songs, user, bots));
        }
예제 #13
0
        internal static UserData GetUserData(string sessionTicket, string ip, out byte errorCode)
        {
            DataRow dUserInfo;

            DataTable dAchievements;
            DataTable dFavouriteRooms;
            DataTable dIgnores;
            DataTable dTags;
            DataTable dSubscriptions;
            DataTable dBadges;
            DataTable dInventory;
            DataTable dEffects;
            DataTable dFriends;
            DataTable dRequests;
            DataTable dRooms;
            DataTable dPets;
            DataTable dBots;
            DataTable dQuests;
            //DataTable dSongs;

            int userID;

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("SELECT * " +
                                  "FROM users " +
                                  "WHERE auth_ticket = @sso ");

                dbClient.addParameter("sso", sessionTicket);
                //dbClient.addParameter("ipaddress", ip);
                dUserInfo = dbClient.getRow();


                if (dUserInfo == null)
                {
                    errorCode = 1;
                    return(null);
                    //Logging.LogException("No user found. Debug data: [" + sessionTicket + "], [" + ip + "]");
                    //throw new UserDataNotFoundException(string.Format("No user found with ip {0} and sso {1}. Use SSO: {2} ", ip, sessionTicket, FirewindEnvironment.useSSO.ToString()));
                }


                userID = Convert.ToInt32(dUserInfo["id"]);
                if (FirewindEnvironment.GetGame().GetClientManager().GetClientByUserID(userID) != null)
                {
                    errorCode = 2;
                    return(null);
                }

                string creditsTimestamp = (string)dUserInfo["lastdailycredits"];
                string todayTimestamp   = DateTime.Today.ToString("MM/dd");
                if (creditsTimestamp != todayTimestamp)
                {
                    dbClient.runFastQuery(
                        "UPDATE users SET credits = credits + 3000, daily_respect_points = 3, lastdailycredits = '" +
                        todayTimestamp + "' WHERE id = " + userID);
                    dUserInfo["credits"] = (int)dUserInfo["credits"] + 3000;
                }

                dbClient.setQuery("SELECT * FROM user_achievement WHERE userid = " + userID);
                dAchievements = dbClient.getTable();

                dbClient.setQuery("SELECT room_id FROM user_favorites WHERE user_id = " + userID);
                dFavouriteRooms = dbClient.getTable();

                dbClient.setQuery("SELECT ignore_id FROM user_ignores WHERE user_id = " + userID);
                dIgnores = dbClient.getTable();

                dbClient.setQuery("SELECT tag FROM user_tags WHERE user_id = " + userID);
                dTags = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_subscriptions WHERE user_id = " + userID);
                dSubscriptions = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_badges WHERE user_id = " + userID);
                dBadges = dbClient.getTable();

                dbClient.setQuery("CALL getuseritems(" + userID + ")");
                dInventory = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_effects WHERE user_id =  " + userID);
                dEffects = dbClient.getTable();

                dbClient.setQuery("SELECT users.id,users.username,users.motto,users.look,users.last_online " +
                                  "FROM users " +
                                  "JOIN messenger_friendships " +
                                  "ON users.id = messenger_friendships.sender " +
                                  "WHERE messenger_friendships.receiver = " + userID + " " +
                                  "UNION ALL " +
                                  "SELECT users.id,users.username,users.motto,users.look,users.last_online " +
                                  "FROM users " +
                                  "JOIN messenger_friendships " +
                                  "ON users.id = messenger_friendships.receiver " +
                                  "WHERE messenger_friendships.sender = " + userID);
                dFriends = dbClient.getTable();

                dbClient.setQuery("SELECT messenger_requests.sender,messenger_requests.receiver,users.username " +
                                  "FROM users " +
                                  "JOIN messenger_requests " +
                                  "ON users.id = messenger_requests.sender " +
                                  "WHERE messenger_requests.receiver = " + userID);
                dRequests = dbClient.getTable();

                dbClient.setQuery(
                    "SELECT rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE owner = @name");
                dbClient.addParameter("name", (string)dUserInfo["username"]);
                dRooms = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_pets WHERE user_id = " + userID + " AND room_id = 0");
                dPets = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_bots WHERE user_id = " + userID + "");
                dBots = dbClient.getTable();

                dbClient.setQuery("SELECT * FROM user_quests WHERE user_id = " + userID + "");
                dQuests = dbClient.getTable();

                //dbClient.setQuery("SELECT item_id, song_id FROM user_items_songs WHERE user_id = " + userID);
                //dSongs = dbClient.getTable();


                /* dbClient.setQuery("UPDATE users SET ip_last = @ip WHERE id = " + userID + " LIMIT 1; " +
                 *                     "UPDATE user_info SET login_timestamp = '" + FirewindEnvironment.GetUnixTimestamp() + "' WHERE user_id = " + userID + " LIMIT 1; " +
                 *                     "REPLACE INTO user_online VALUES (" + userID + "); " +
                 *                     "DELETE FROM user_tickets WHERE userid = " + userID + ";");*/

                dbClient.setQuery("UPDATE users SET ip_last = @ip WHERE id = " + userID + "; " +
                                  "UPDATE user_info SET login_timestamp = '" + FirewindEnvironment.GetUnixTimestamp() +
                                  "' WHERE user_id = " + userID + " ; " +
                                  "");
                dbClient.addParameter("ip", ip);
                dbClient.runQuery();

                dbClient.runFastQuery("REPLACE INTO user_online VALUES (" + userID + ")");
            }

            Dictionary <string, UserAchievement> achievements = new Dictionary <string, UserAchievement>();

            string achievementGroup;
            int    achievementLevel;
            int    achievementProgress;

            foreach (DataRow dRow in dAchievements.Rows)
            {
                achievementGroup    = (string)dRow["group"];
                achievementLevel    = (int)dRow["level"];
                achievementProgress = (int)dRow["progress"];

                UserAchievement achievement = new UserAchievement(achievementGroup, achievementLevel, achievementProgress);
                achievements.Add(achievementGroup, achievement);
            }

            List <uint> favouritedRooms = new List <uint>();

            uint favoritedRoomID;

            foreach (DataRow dRow in dFavouriteRooms.Rows)
            {
                favoritedRoomID = Convert.ToUInt32(dRow["room_id"]);
                favouritedRooms.Add(favoritedRoomID);
            }


            List <int> ignores = new List <int>();

            int ignoredUserID;

            foreach (DataRow dRow in dIgnores.Rows)
            {
                ignoredUserID = Convert.ToInt32(dRow["ignore_id"]);
                ignores.Add(ignoredUserID);
            }


            List <string> tags = new List <string>();

            string tag;

            foreach (DataRow dRow in dTags.Rows)
            {
                tag = (string)dRow["tag"];
                tags.Add(tag);
            }

            Dictionary <string, Subscription> subscriptions = new Dictionary <string, Subscription>();

            string subscriptionID;
            int    expireTimestamp;

            foreach (DataRow dRow in dSubscriptions.Rows)
            {
                subscriptionID  = (string)dRow["subscription_id"];
                expireTimestamp = (int)dRow["timestamp_expire"];

                subscriptions.Add(subscriptionID, new Subscription(subscriptionID, expireTimestamp));
            }

            List <Badge> badges = new List <Badge>();

            string badgeID;
            int    slotID;

            foreach (DataRow dRow in dBadges.Rows)
            {
                badgeID = (string)dRow["badge_id"];
                slotID  = (int)dRow["badge_slot"];
                badges.Add(new Badge(badgeID, slotID));
            }


            List <UserItem> inventory = new List <UserItem>();

            uint   itemID;
            uint   baseItem;
            int    dataType;
            string extradata;
            int    extra;

            foreach (DataRow Row in dInventory.Rows)
            {
                itemID   = Convert.ToUInt32(Row[0]);
                baseItem = Convert.ToUInt32(Row[1]);

                IRoomItemData data;
                if (DBNull.Value.Equals(Row[2]))
                {
                    data  = new StringData("");
                    extra = 0;
                }
                else
                {
                    dataType  = Convert.ToInt32(Row[2]);
                    extradata = (string)Row[3];
                    extra     = Convert.ToInt32(Row[4]);
                    switch (dataType)
                    {
                    case 0:
                        data = new StringData(extradata);
                        break;

                    case 1:
                        data = new MapStuffData();
                        break;

                    case 2:
                        data = new StringArrayStuffData();
                        break;

                    case 3:
                        data = new StringIntData();
                        break;

                    default:
                        data = new StringData(extradata);
                        break;
                    }
                    try
                    {
                        data.Parse(extradata);
                    }
                    catch
                    {
                        Logging.LogException(string.Format("Error in furni data! Item ID: \"{0}\" and data: \"{1}\"", itemID, extradata.Replace(Convert.ToChar(1).ToString(), "[1]")));
                    }
                }

                inventory.Add(new UserItem(itemID, baseItem, data, extra));
            }


            List <AvatarEffect> effects = new List <AvatarEffect>();

            int    effectID;
            int    duration;
            bool   isActivated;
            double activatedTimeStamp;

            foreach (DataRow dRow in dEffects.Rows)
            {
                effectID           = (int)dRow["effect_id"];
                duration           = (int)dRow["total_duration"];
                isActivated        = Convert.ToInt32(dRow["is_activated"]) == 1;
                activatedTimeStamp = (double)dRow["activated_stamp"];

                effects.Add(new AvatarEffect(effectID, duration, isActivated, activatedTimeStamp));
            }


            Dictionary <int, MessengerBuddy> friends = new Dictionary <int, MessengerBuddy>();

            string username = (string)dUserInfo["username"];

            int    friendID;
            string friendName;
            string friendLook;
            string friendMotto;
            string friendLastOnline;

            foreach (DataRow dRow in dFriends.Rows)
            {
                friendID         = Convert.ToInt32(dRow["id"]);
                friendName       = (string)dRow["username"];
                friendLook       = (string)dRow["look"];
                friendMotto      = (string)dRow["motto"];
                friendLastOnline = Convert.ToString(dRow["last_online"]);


                if (friendID == userID)
                {
                    continue;
                }



                if (!friends.ContainsKey(friendID))
                {
                    friends.Add(friendID, new MessengerBuddy(friendID, friendName, friendLook, friendMotto, friendLastOnline));
                }
            }

            Dictionary <int, MessengerRequest> requests = new Dictionary <int, MessengerRequest>();

            int    receiverID;
            int    senderID;
            string requestUsername;

            foreach (DataRow dRow in dRequests.Rows)
            {
                receiverID = Convert.ToInt32(dRow["sender"]);
                senderID   = Convert.ToInt32(dRow["receiver"]);

                requestUsername = (string)dRow["username"];

                if (receiverID != userID)
                {
                    if (!requests.ContainsKey(receiverID))
                    {
                        requests.Add(receiverID, new MessengerRequest(userID, receiverID, requestUsername));
                    }
                }
                else
                {
                    if (!requests.ContainsKey(senderID))
                    {
                        requests.Add(senderID, new MessengerRequest(userID, senderID, requestUsername));
                    }
                }
            }

            List <RoomData> rooms = new List <RoomData>();

            uint roomID;

            foreach (DataRow dRow in dRooms.Rows)
            {
                roomID = Convert.ToUInt32(dRow["id"]);
                rooms.Add(FirewindEnvironment.GetGame().GetRoomManager().FetchRoomData(roomID, dRow));
            }


            Dictionary <uint, Pet> pets = new Dictionary <uint, Pet>();

            Pet pet;

            foreach (DataRow dRow in dPets.Rows)
            {
                pet = Catalog.GeneratePetFromRow(dRow);
                pets.Add(pet.PetId, pet);
            }

            Dictionary <int, RentableBot> bots = new Dictionary <int, RentableBot>();

            RentableBot bot;

            foreach (DataRow row in dBots.Rows)
            {
                bot = new RentableBot();

                bot.OwnerID  = Convert.ToInt32(row["user_id"]);
                bot.ID       = Convert.ToInt32(row["id"]);
                bot.Name     = Convert.ToString(row["name"]);
                bot.Gender   = Convert.ToChar(row["gender"]);
                bot.Figure   = Convert.ToString(row["figure"]);
                bot.Motto    = "1 week SpyBot";
                bot.TimeLeft = 604800; // 1 week

                bots.Add(bot.ID, bot);
            }

            Dictionary <uint, int> quests = new Dictionary <uint, int>();

            uint questId;
            int  progress;

            foreach (DataRow dRow in dQuests.Rows)
            {
                questId  = Convert.ToUInt32(dRow["quest_id"]);
                progress = (int)dRow["progress"];
                quests.Add(questId, progress);
            }

            Hashtable songs = new Hashtable();

            //uint songItemID;
            //uint songID;
            //foreach (DataRow dRow in dSongs.Rows)
            //{
            //    songItemID = (uint)dRow[0];
            //    songID = (uint)dRow[1];

            //    SongItem song = new SongItem(songItemID, songID);
            //    songs.Add(songItemID, song);
            //}

            Habbo user = HabboFactory.GenerateHabbo(dUserInfo);

            dUserInfo       = null;
            dAchievements   = null;
            dFavouriteRooms = null;
            dIgnores        = null;
            dTags           = null;
            dSubscriptions  = null;
            dBadges         = null;
            dInventory      = null;
            dEffects        = null;
            dFriends        = null;
            dRequests       = null;
            dRooms          = null;
            dPets           = null;

            errorCode = 0;
            return(new UserData(userID, achievements, favouritedRooms, ignores, tags, subscriptions, badges, inventory, effects, friends, requests, rooms, pets, quests, songs, user, bots));
        }