Exemple #1
0
        internal void AddOrExtendSubscription(int DurationSeconds, string type)
        {
            if (this.currentSubscription != null && this.currentSubscription.SubscriptionId == type)
            {
                currentSubscription.AddSubscriptionTime(DurationSeconds);
                
                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("UPDATE user_subscriptions SET timestamp_expire = " + currentSubscription.ExpireTime + " WHERE user_id = " + userID + " AND subscription_id = @subcrbr");
                    dbClient.addParameter("subcrbr", type);
                    dbClient.runQuery();
                }

                return;
            }

            int timestamp_created = ButterflyEnvironment.GetUnixTimestamp();
            int timestamp_exire = ButterflyEnvironment.GetUnixTimestamp() + DurationSeconds;

            currentSubscription = new Subscription(type, timestamp_exire);

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("REPLACE INTO user_subscriptions (user_id,subscription_id,timestamp_activated,timestamp_expire) VALUES (" + userID + ",@subcrbr," + timestamp_created + "," + timestamp_exire + ")");
                dbClient.addParameter("subcrbr", type);
                dbClient.runQuery();
            }
        }
Exemple #2
0
 public UserData(uint userID, Dictionary<string, UserAchievement> achievements, List<uint> favouritedRooms, List<uint> ignores,
     Subscription subscription, List<Badge> badges, List<UserItem> inventory, List<AvatarEffect> effects,
     Dictionary<uint, MessengerBuddy> friends, Dictionary<uint, MessengerRequest> requests, List<RoomData> rooms, Dictionary<uint, Pet> pets, Dictionary<uint, int> quests, Hashtable inventorySongs, Habbo user, Hashtable bots)
 {
     this.userID = userID;
     this.achievements = achievements;
     this.favouritedRooms = favouritedRooms;
     this.ignores = ignores;
     this.subscription = subscription;
     this.badges = badges;
     this.inventory = inventory;
     this.effects = effects;
     this.friends = friends;
     this.requests = requests;
     this.rooms = rooms;
     this.pets = pets;
     this.quests = quests;
     this.inventorySongs = inventorySongs;
     this.bots = bots;
     this.user = new HabboDataContainer(user);
 }
Exemple #3
0
        internal void AddOrExtendSubscription(string SubscriptionId, int DurationSeconds)
        {
            SubscriptionId = SubscriptionId.ToLower();

            if (Subscriptions.ContainsKey(SubscriptionId))
            {
                Subscription Sub = Subscriptions[SubscriptionId];
                if (Sub.IsValid())
                    Sub.ExtendSubscription(DurationSeconds);
                else
                    Sub.SetEndTime(((int)ButterflyEnvironment.GetUnixTimestamp() + DurationSeconds));

                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("UPDATE user_subscriptions SET timestamp_expire = " + Sub.ExpireTime + " WHERE user_id = " + UserId + " AND subscription_id = @subcrbr");
                    dbClient.addParameter("subcrbr", SubscriptionId);
                    dbClient.runQuery();
                }

                return;
            }

            int TimeCreated = (int)ButterflyEnvironment.GetUnixTimestamp();
            int TimeExpire = ((int)ButterflyEnvironment.GetUnixTimestamp() + DurationSeconds);

            Subscription NewSub = new Subscription(SubscriptionId, TimeExpire);

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("INSERT INTO user_subscriptions (user_id,subscription_id,timestamp_activated,timestamp_expire) VALUES (" + UserId + ",@subcrbr," + TimeCreated + "," + TimeExpire + ")");
                dbClient.addParameter("subcrbr", SubscriptionId);
                dbClient.runQuery();
            }

            Subscriptions.Add(NewSub.SubscriptionId.ToLower(), NewSub);
        }
Exemple #4
0
 internal void Destroy()
 {
     currentSubscription = null;
 }
Exemple #5
0
 internal SubscriptionManager(uint userID, UserData userData)
 {
     this.userID = userID;
     this.currentSubscription = userData.subscription;
 }
Exemple #6
0
        internal static UserData GetUserData(string sessionTicket, string ip, out byte errorCode, bool useSso)
        {
            uint userid;

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

            UInt32 userID;
            Habbo userData;
            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                if (!useSso || !ButterflyEnvironment.useSSO)
                {
                    dbClient.setQuery("SELECT userid " +
                    "FROM user_tickets " +
					"WHERE user_tickets.sessionticket = @sso LIMIT 1");
                }
                else
                {
                    dbClient.setQuery("SELECT userid " +
                                        "FROM user_tickets " +
                                        "WHERE user_tickets.sessionticket = @sso " +
                                        "AND ipaddress = @ipaddress ");

                }

                dbClient.addParameter("sso", sessionTicket);
                dbClient.addParameter("ipaddress", ip);
                userid = (uint)dbClient.getInteger();

                ButterflyEnvironment.GetGame().GetClientManager().LogClonesOut(userid);


                if (userid == 0)
                {
                    errorCode = 1;
                    return null;
                }

                userData = ButterflyEnvironment.GetGame().GetClientManager().GetHabboData(userid);
                
                if (userData == null)
                {
                    errorCode = 1;
                    return null;
                }

                userID = userid;

                if (ButterflyEnvironment.GetGame().GetClientManager().GetClientByUserID(userID) != null)
                {
                    errorCode = 2;
                    return null;
                }

                string creditsTimestamp = userData.creditsTimestamp;
                string todayTimestamp = DateTime.Today.ToString("MM/dd");
                if (creditsTimestamp != todayTimestamp)
                {
                    dbClient.runFastQuery("UPDATE users SET credits = credits + 3000, daily_respect_points = 10, daily_pet_respect_points = 5, lastdailycredits = '" + todayTimestamp + "' WHERE id = " + userID);
                    userData.Credits += 3000;
                    userData.creditsTimestamp = todayTimestamp;
                }

                dbClient.runFastQuery("UPDATE `users` SET online = '1' WHERE id = '" + userID + "';");

                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 * 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,messenger_friendships.relationship " +
                                        "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,messenger_friendships.relationship " +
                                        "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.*, users.id AS ownerid FROM rooms JOIN users ON (users.username = rooms.owner) WHERE rooms.owner = @name");
                dbClient.addParameter("name", userData.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();

                dbClient.setQuery("UPDATE user_info SET login_timestamp = '" + ButterflyEnvironment.GetUnixTimestamp() + "' WHERE user_id = " + userID + ";");
                dbClient.runQuery();

                dbClient.setQuery("SELECT * FROM bots WHERE owner_id = " + userID + " AND room_id = 0");
                dBots = dbClient.getTable();

                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<uint> ignores = new List<uint>();

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

            Subscription subscription = null;

            string subscriptionID;
            int expireTimestamp;
            
            if (dSubscriptions != null)
            {
                Subscription test;
                foreach (DataRow drow in dSubscriptions.Rows)
                {
                    subscriptionID = (string)drow["subscription_id"];
                    expireTimestamp = (int)drow["timestamp_expire"];

                    test = new Subscription(subscriptionID, expireTimestamp);
                    if (test.IsValid())
                    {
                        if (subscription == null || subscription.SubscriptionId != SubscriptionManager.SUBSCRIPTION_TYPE_VIP)
                        {
                            subscription = test;
                        }
                        else
                        {
                            subscription = test;
                        }
                    }
                }
            }
			string sub = ButterflyEnvironment.GetConfig().GetProperty("club.default");
            if (subscription == null && sub.Length != 0)
            {
                subscription = new Subscription(sub, ButterflyEnvironment.GetUnixTimestamp() + 7 * 24 * 3600);
            }

            List<Badge> badges = new List<Badge>();
            
            string badgeID;
            int slotID;
            foreach (DataRow dRow in dBadges.Rows)
            {
                int ID = (int)dRow["id"];
                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 = (uint)dRow[0];
                baseItem = (uint)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 = ButterflyEnvironment.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>();


            UInt32 friendID;
            string friendName;
            string friendLook;
            string friendMotto;
            string friendLastOnline;
            int relationship;
            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"];
                relationship = (int)dRow["relationship"];

                if (friendID == userID)
                    continue;


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

            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(ButterflyEnvironment.GetGame().GetRoomManager().FetchRoomData(roomID, dRow));
            }


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

            foreach (DataRow dRow in dPets.Rows)
            {
                Pet 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);
            //}

            Hashtable bots = new Hashtable();

            foreach (DataRow dRow in dBots.Rows)
            {
                RoomBot bot = ButterflyEnvironment.GetGame().GetBotManager().FetchBot(dRow);
                bots.Add(bot.BotId, bot);
            }

            dAchievements = null;
            dFavouriteRooms = null;
            dIgnores = 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, subscription, badges, inventory, effects, friends, requests, rooms, pets, quests, songs, userData, bots);
        }