Пример #1
0
        public MoodlightData(int ItemId)
        {
            this.ItemId = ItemId;

            DataRow Row = null;

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT enabled,current_preset,preset_one,preset_two,preset_three FROM room_items_moodlight WHERE item_id = '" + ItemId + "' LIMIT 1");
                Row = dbClient.GetRow();
            }

            if (Row == null)
            {
                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.RunQuery("INSERT INTO `room_items_moodlight` (item_id,enabled,current_preset,preset_one,preset_two,preset_three) VALUES (" + ItemId + ",0,1,'#000000,255,0','#000000,255,0','#000000,255,0')");
                    dbClient.SetQuery("SELECT enabled,current_preset,preset_one,preset_two,preset_three FROM room_items_moodlight WHERE item_id=" + ItemId + " LIMIT 1");
                    Row = dbClient.GetRow();
                }
            }

            Enabled       = ButterflyEnvironment.EnumToBool(Row["enabled"].ToString());
            CurrentPreset = Convert.ToInt32(Row["current_preset"]);
            Presets       = new List <MoodlightPreset>();

            Presets.Add(GeneratePreset(Convert.ToString(Row["preset_one"])));
            Presets.Add(GeneratePreset(Convert.ToString(Row["preset_two"])));
            Presets.Add(GeneratePreset(Convert.ToString(Row["preset_three"])));
        }
Пример #2
0
        public void Execute(GameClient Session, Room Room, RoomUser UserRoom, string[] Params)
        {
            string Map  = "";
            string Line = "";

            for (int y = 0; y < Room.GetGameMap().Model.MapSizeY; y++)
            {
                Line = "";
                for (int x = 0; x < Room.GetGameMap().Model.MapSizeX; x++)
                {
                    if (x >= Room.GetGameMap().Model.MapSizeX || y >= Room.GetGameMap().Model.MapSizeY)
                    {
                        Line += "x";
                    }
                    else
                    {
                        if (Room.GetGameMap().Model.SqState[x, y] == SquareState.BLOCKED || Room.GetGameMap().GetCoordinatedItems(new Point(x, y)).Count == 0)
                        {
                            Line += "x";//x
                        }
                        else
                        {
                            Line += this.parseInvers(Room.GetGameMap().Model.SqFloorHeight[x, y]);
                        }
                    }
                }
                Map += Line + Convert.ToChar(13);
            }

            Map = Map.TrimEnd(Convert.ToChar(13));

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("REPLACE INTO room_models_customs VALUES (@id, @doorX, @doorY, @doorZ, @doorDir, @heightmap, @murheight)");
                dbClient.AddParameter("id", Room.Id);
                dbClient.AddParameter("doorX", Room.GetGameMap().Model.DoorX);
                dbClient.AddParameter("doorY", Room.GetGameMap().Model.DoorY);
                dbClient.AddParameter("doorZ", Room.GetGameMap().Model.DoorZ);
                dbClient.AddParameter("doorDir", Room.GetGameMap().Model.DoorOrientation);
                dbClient.AddParameter("heightmap", Map);
                dbClient.AddParameter("murheight", Room.GetGameMap().Model.MurHeight);
                dbClient.RunQuery();
                dbClient.RunQuery("UPDATE rooms SET model_name = 'model_custom' WHERE id = " + Room.Id + " LIMIT 1");
            }

            List <RoomUser> UsersToReturn = Room.GetRoomUserManager().GetRoomUsers().ToList();

            ButterflyEnvironment.GetGame().GetRoomManager().UnloadRoom(Room);


            foreach (RoomUser User in UsersToReturn)
            {
                if (User == null || User.GetClient() == null)
                {
                    continue;
                }

                User.GetClient().SendPacket(new RoomForwardComposer(Room.Id));
            }
        }
 public static void GetAchievementLevels(out Dictionary <string, Achievement> achievements)
 {
     achievements = new Dictionary <string, Achievement>();
     using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
     {
         dbClient.SetQuery("SELECT * FROM achievements");
         foreach (DataRow dataRow in dbClient.GetTable().Rows)
         {
             int              Id        = Convert.ToInt32(dataRow["id"]);
             string           Category  = (string)dataRow["category"];
             string           GroupName = (string)dataRow["group_name"];
             AchievementLevel Level     = new AchievementLevel((int)dataRow["level"], (int)dataRow["reward_pixels"], (int)dataRow["reward_points"], (int)dataRow["progress_needed"]);
             if (!achievements.ContainsKey(GroupName))
             {
                 Achievement achievement = new Achievement(Id, GroupName, Category);
                 achievement.AddLevel(Level);
                 achievements.Add(GroupName, achievement);
             }
             else
             {
                 achievements[GroupName].AddLevel(Level);
             }
         }
     }
 }
Пример #4
0
        internal void OnNewFriendship(uint friendID)
        {
            GameClient friend = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUserID(friendID);

            MessengerBuddy newFriend;

            if (friend == null || friend.GetHabbo() == null)
            {
                DataRow dRow;
                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                {
                    dbClient.setQuery("SELECT username,motto,look,last_online FROM users WHERE id = " + friendID);
                    dRow = dbClient.getRow();
                }

                newFriend = new MessengerBuddy(friendID, (string)dRow["username"], (string)dRow["look"], (string)dRow["motto"], (string)dRow["last_online"]);
            }
            else
            {
                Habbo user = friend.GetHabbo();
                newFriend = new MessengerBuddy(friendID, user.Username, user.Look, user.Motto, string.Empty);
                newFriend.UpdateUser(friend);
            }

            if (!friends.ContainsKey(friendID))
            {
                friends.Add(friendID, newFriend);
            }

            GetClient().SendMessage(SerializeUpdate(newFriend));
        }
Пример #5
0
        internal void RemoveInventoryItem(int ItemId, int Count = 1)
        {
            RolePlayInventoryItem Item = GetInventoryItem(ItemId);

            if (Item == null)
            {
                return;
            }

            if (Item.Count > Count)
            {
                Item.Count = Item.Count - Count;

                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                    dbClient.RunQuery("UPDATE user_rpitems SET count = count - '" + Count + "' WHERE id = '" + Item.Id + "' LIMIT 1");
            }
            else
            {
                this._inventory.TryRemove(ItemId, out Item);

                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                    dbClient.RunQuery("DELETE FROM user_rpitems WHERE id = '" + Item.Id + "' LIMIT 1");
            }

            this.SendWebPacket(new RemoveItemInventoryRpComposer(ItemId, Count));
        }
Пример #6
0
        public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet)
        {
            if (Session == null || Session.GetHabbo() == null)
            {
                return;
            }

            DataRow Row     = null;
            int     OfferId = Packet.PopInt();

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT `furni_id`, `item_id`, `user_id`, `extra_data`, `offer_id`, `state`, `timestamp`, `limited_number`, `limited_stack` FROM `catalog_marketplace_offers` WHERE `offer_id` = @OfferId LIMIT 1");
                dbClient.AddParameter("OfferId", OfferId);
                Row = dbClient.GetRow();
            }

            if (Row == null)
            {
                Session.SendPacket(new MarketplaceCancelOfferResultComposer(OfferId, false));
                return;
            }

            if (Convert.ToString(Row["state"]) == "2")
            {
                Session.SendPacket(new MarketplaceCancelOfferResultComposer(OfferId, false));
                return;
            }

            if (Convert.ToInt32(Row["user_id"]) != Session.GetHabbo().Id)
            {
                Session.SendPacket(new MarketplaceCancelOfferResultComposer(OfferId, false));
                return;
            }

            ItemData Item = null;

            if (!ButterflyEnvironment.GetGame().GetItemManager().GetItem(Convert.ToInt32(Row["item_id"]), out Item))
            {
                Session.SendPacket(new MarketplaceCancelOfferResultComposer(OfferId, false));
                return;
            }

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("DELETE FROM `catalog_marketplace_offers` WHERE `offer_id` = @OfferId AND `user_id` = @UserId LIMIT 1");
                dbClient.AddParameter("OfferId", OfferId);
                dbClient.AddParameter("UserId", Session.GetHabbo().Id);
                dbClient.RunQuery();
            }

            Item GiveItem = ItemFactory.CreateSingleItem(Item, Session.GetHabbo(), Convert.ToString(Row["extra_data"]), Convert.ToInt32(Row["furni_id"]), Convert.ToInt32(Row["limited_number"]), Convert.ToInt32(Row["limited_stack"]));

            if (GiveItem != null)
            {
                Session.GetHabbo().GetInventoryComponent().TryAddItem(GiveItem);
                Session.SendPacket(new FurniListNotificationComposer(GiveItem.Id, 1));
            }
            Session.SendPacket(new MarketplaceCancelOfferResultComposer(OfferId, true));
        }
Пример #7
0
        public void SendInstantMessage(int ToId, string Message)
        {
            if (!this.FriendshipExists(ToId))
            {
                this.GetClient().SendPacket(new InstantMessageErrorComposer(6, ToId));
                return;
            }

            GameClient Client = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUserID(ToId);

            if (Client == null || Client.GetHabbo() == null || Client.GetHabbo().GetMessenger() == null)
            {
                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("INSERT INTO `messenger_offline_messages` (`to_id`, `from_id`, `message`, `timestamp`) VALUES (@tid, @fid, @msg, UNIX_TIMESTAMP())");
                    dbClient.AddParameter("tid", ToId);
                    dbClient.AddParameter("fid", GetClient().GetHabbo().Id);
                    dbClient.AddParameter("msg", Message);
                    dbClient.RunQuery();
                }
                return;
            }

            Client.SendPacket(new NewConsoleMessageComposer(this.UserId, Message));
        }
Пример #8
0
        public void OnNewFriendship(int friendID)
        {
            GameClient     clientByUserId = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUserID(friendID);
            MessengerBuddy friend;

            if (clientByUserId == null || clientByUserId.GetHabbo() == null)
            {
                DataRow row;
                using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    queryreactor.SetQuery("SELECT username FROM users WHERE id = " + friendID);
                    row = queryreactor.GetRow();
                }
                if (row == null)
                {
                    return;
                }

                friend = new MessengerBuddy(friendID, (string)row["username"], "", 0);
            }
            else
            {
                Habbo habbo = clientByUserId.GetHabbo();
                friend = new MessengerBuddy(friendID, habbo.Username, habbo.Look, 0);
                friend.UpdateUser();
            }
            if (!this.friends.ContainsKey(friendID))
            {
                this.friends.Add(friendID, friend);
            }
            this.GetClient().SendPacket(SerializeUpdate(friend));
        }
Пример #9
0
        public void LoadMessagePresets()
        {
            this.UserMessagePresets.Clear();
            this.RoomMessagePresets.Clear();
            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT type,message FROM moderation_presets WHERE enabled = '1'");
                DataTable table = dbClient.GetTable();
                foreach (DataRow dataRow in table.Rows)
                {
                    string str = (string)dataRow["message"];
                    switch (dataRow["type"].ToString().ToLower())
                    {
                    case "message":
                        this.UserMessagePresets.Add(str);
                        continue;

                    case "roommessage":
                        this.RoomMessagePresets.Add(str);
                        continue;

                    default:
                        continue;
                    }
                }
            }
        }
Пример #10
0
        public static void PerformRoomAction(GameClient ModSession, int RoomId, bool KickUsers, bool LockRoom, bool InappropriateRoom)
        {
            Room room = ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(RoomId);

            if (room == null)
            {
                return;
            }

            if (LockRoom)
            {
                room.RoomData.State = 1;
                room.RoomData.Name  = "Cet appart ne respect par les conditions d'utilisation";
                using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                    queryreactor.RunQuery("UPDATE rooms SET state = 'locked' WHERE id = " + room.Id);
            }
            if (InappropriateRoom)
            {
                room.RoomData.Name        = ButterflyEnvironment.GetLanguageManager().TryGetValue("moderation.room.roomclosed", ModSession.Langue);
                room.RoomData.Description = ButterflyEnvironment.GetLanguageManager().TryGetValue("moderation.room.roomclosed", ModSession.Langue);
                room.ClearTags();
                room.RoomData.Tags.Clear();
                using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                    queryreactor.RunQuery("UPDATE rooms SET caption = 'Cet appart ne respect par les conditions dutilisation', description = 'Cet appart ne respect par les conditions dutilisation', tags = '' WHERE id = " + room.Id);
            }
            if (KickUsers)
            {
                room.onRoomKick();
            }

            room.SendPacket(new GetGuestRoomResultComposer(ModSession, room.RoomData, false, false));
        }
Пример #11
0
        public void Init()
        {
            if (this._styles.Count > 0)
            {
                this._styles.Clear();
            }

            DataTable Table = null;

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `room_chat_styles`;");
                Table = dbClient.GetTable();

                if (Table != null)
                {
                    foreach (DataRow Row in Table.Rows)
                    {
                        if (!this._styles.ContainsKey(Convert.ToInt32(Row["id"])))
                        {
                            this._styles.Add(Convert.ToInt32(Row["id"]), new ChatStyle(Convert.ToInt32(Row["id"]), Convert.ToString(Row["name"]), Convert.ToString(Row["required_right"])));
                        }
                    }
                }
            }
        }
Пример #12
0
        internal void AddInventoryItem(int pItemId, int pCount = 1)
        {
            RPItem RPItem = ButterflyEnvironment.GetGame().GetRoleplayManager().GetItemManager().GetItem(pItemId);

            if (RPItem == null)
            {
                return;
            }

            RolePlayInventoryItem Item = GetInventoryItem(pItemId);

            if (Item == null)
            {
                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("INSERT INTO `user_rpitems` (`user_id`, `rp_id`, `item_id`, `count`) VALUES ('" + this._id + "', '" + this._rpId + "', '" + pItemId + "', '" + pCount + "')");
                    int Id = Convert.ToInt32(dbClient.InsertQuery());
                    this._inventory.TryAdd(pItemId, new RolePlayInventoryItem(Id, pItemId, pCount));
                }
            }
            else
            {
                Item.Count += pCount;
                using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                    dbClient.RunQuery("UPDATE user_rpitems SET count = count + '" + pCount + "' WHERE id = '" + Item.Id + "' LIMIT 1");
            }


            this.SendWebPacket(new AddInventoryItemRpComposer(RPItem, pCount));
        }
Пример #13
0
        public void LoadTicketResolution()
        {
            this.TicketResolution1.Clear();
            this.TicketResolution2.Clear();
            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM moderation_resolution");
                DataTable table = dbClient.GetTable();
                foreach (DataRow dataRow in table.Rows)
                {
                    TicketResolution str = new TicketResolution((string)dataRow["Titre"], (string)dataRow["Soustitre"], (int)dataRow["ban_hours"], (int)dataRow["enablemute"], (int)dataRow["mute_hours"], (int)dataRow["reminder"], (string)dataRow["message"]);
                    switch (dataRow["type"].ToString())
                    {
                    case "Sexual":
                        this.TicketResolution1.Add(str);
                        continue;

                    case "PII":
                        this.TicketResolution2.Add(str);
                        continue;

                    default:
                        continue;
                    }
                }
            }
        }
Пример #14
0
        public static int GetTeleRoomId(int TeleId, Room pRoom)
        {
            if (pRoom == null)
            {
                return(0);
            }
            if (pRoom.GetRoomItemHandler() == null)
            {
                return(0);
            }
            if (pRoom.GetRoomItemHandler().GetItem(TeleId) != null)
            {
                return(pRoom.Id);
            }

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("SELECT room_id FROM items WHERE id = " + TeleId + " LIMIT 1");
                DataRow row = queryreactor.GetRow();
                if (row == null)
                {
                    return(0);
                }
                else
                {
                    return(Convert.ToInt32(row[0]));
                }
            }
        }
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            int    GroupId = Packet.PopInt();
            string Name    = ButterflyEnvironment.GetGame().GetChatManager().GetFilter().CheckMessage(Packet.PopString());
            string Desc    = ButterflyEnvironment.GetGame().GetChatManager().GetFilter().CheckMessage(Packet.PopString());

            Group Group = null;

            if (!ButterflyEnvironment.GetGame().GetGroupManager().TryGetGroup(GroupId, out Group))
            {
                return;
            }

            if (Group.CreatorId != Session.GetHabbo().Id)
            {
                return;
            }

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("UPDATE `groups` SET `name`= @name, `desc` = @desc WHERE `id` = @groupId LIMIT 1");
                dbClient.AddParameter("name", Name);
                dbClient.AddParameter("desc", Desc);
                dbClient.AddParameter("groupId", GroupId);
                dbClient.RunQuery();
            }

            Group.Name        = Name;
            Group.Description = Desc;

            Session.SendPacket(new GroupInfoComposer(Group, Session));
        }
Пример #16
0
        public void ProcessOfflineMessages()
        {
            DataTable GetMessages = null;

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `messenger_offline_messages` WHERE `to_id` = @id;");
                dbClient.AddParameter("id", this.UserId);
                GetMessages = dbClient.GetTable();

                if (GetMessages != null)
                {
                    GameClient Client = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUserID(this.UserId);
                    if (Client == null)
                    {
                        return;
                    }

                    foreach (DataRow Row in GetMessages.Rows)
                    {
                        Client.SendPacket(new NewConsoleMessageComposer(Convert.ToInt32(Row["from_id"]), Convert.ToString(Row["message"]), (ButterflyEnvironment.GetUnixTimestamp() - Convert.ToInt32(Row["timestamp"]))));
                    }

                    dbClient.SetQuery("DELETE FROM `messenger_offline_messages` WHERE `to_id` = @id");
                    dbClient.AddParameter("id", this.UserId);
                    dbClient.RunQuery();
                }
            }
        }
Пример #17
0
        internal MoodlightData(uint ItemId)
        {
            this.ItemId = ItemId;

            DataRow Row;

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("SELECT enabled,current_preset,preset_one,preset_two,preset_three FROM items_moodlight WHERE item_id = " + ItemId);
                Row = dbClient.getRow();
            }

            if (Row == null)
            {
                throw new NullReferenceException("No moodlightdata found in the database");
            }

            this.Enabled       = ButterflyEnvironment.EnumToBool(Row["enabled"].ToString());
            this.CurrentPreset = (int)Row["current_preset"];
            this.Presets       = new List <MoodlightPreset>();

            this.Presets.Add(GeneratePreset((string)Row["preset_one"]));
            this.Presets.Add(GeneratePreset((string)Row["preset_two"]));
            this.Presets.Add(GeneratePreset((string)Row["preset_three"]));
        }
Пример #18
0
        public void CloseAll()
        {
            StringBuilder stringBuilder = new StringBuilder();

            foreach (GameClient client in this.GetClients.ToList())
            {
                if (client == null)
                {
                    continue;
                }

                if (client.GetHabbo() != null)
                {
                    try
                    {
                        stringBuilder.Append(client.GetHabbo().GetQueryString);
                    }
                    catch
                    {
                    }
                }
            }
            try
            {
                if (stringBuilder.Length > 0)
                {
                    using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                        queryreactor.RunQuery((stringBuilder).ToString());
                }
            }
            catch (Exception ex)
            {
                Logging.HandleException(ex, "GameClientManager.CloseAll()");
            }
            Console.WriteLine("Done saving users inventory!");
            Console.WriteLine("Closing server connections...");
            try
            {
                foreach (GameClient client in this.GetClients.ToList())
                {
                    if (client == null || client.GetConnection() == null)
                    {
                        continue;
                    }
                    try
                    {
                        client.GetConnection().Dispose();
                    }
                    catch
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.LogCriticalException((ex).ToString());
            }
            this._clients.Clear();
            Console.WriteLine("Connections closed!");
        }
Пример #19
0
        public void Execute(GameClient Session, Room Room, RoomUser UserRoom, string[] Params)
        {
            if (Params.Length < 2)
            {
                return;
            }

            string   PhotoId     = Params[1];
            int      ItemPhotoId = 4581;
            ItemData ItemData    = null;

            if (!ButterflyEnvironment.GetGame().GetItemManager().GetItem(ItemPhotoId, out ItemData))
            {
                return;
            }

            int    Time      = ButterflyEnvironment.GetUnixTimestamp();
            string ExtraData = "{\"w\":\"" + "/photos/" + PhotoId + ".png" + "\", \"n\":\"" + Session.GetHabbo().Username + "\", \"s\":\"" + Session.GetHabbo().Id + "\", \"u\":\"" + "0" + "\", \"t\":\"" + Time + "000" + "\"}";

            Item Item = ItemFactory.CreateSingleItemNullable(ItemData, Session.GetHabbo(), ExtraData);

            Session.GetHabbo().GetInventoryComponent().TryAddItem(Item);
            //Session.SendPacket(new FurniListUpdateComposer());

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("INSERT INTO user_photos (user_id,photo,time) VALUES ('" + Session.GetHabbo().Id + "', @photoid, '" + Time + "');");
                queryreactor.AddParameter("photoid", PhotoId);
                queryreactor.RunQuery();
            }

            Session.SendNotification(ButterflyEnvironment.GetLanguageManager().TryGetValue("notif.buyphoto.valide", Session.Langue));
        }
Пример #20
0
        public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet)
        {
            int CreditsOwed = 0;

            DataTable Table = null;

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT `asking_price` FROM `catalog_marketplace_offers` WHERE `user_id` = '" + Session.GetHabbo().Id + "' AND `state` = '2'");
                Table = dbClient.GetTable();
            }

            if (Table != null)
            {
                foreach (DataRow row in Table.Rows)
                {
                    CreditsOwed += Convert.ToInt32(row["asking_price"]);
                }

                if (CreditsOwed >= 1)
                {
                    Session.GetHabbo().WibboPoints += CreditsOwed;
                    Session.SendPacket(new HabboActivityPointNotificationComposer(Session.GetHabbo().WibboPoints, 0, 105));

                    using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                    {
                        dbClient.RunQuery("DELETE FROM `catalog_marketplace_offers` WHERE `user_id` = '" + Session.GetHabbo().Id + "' AND `state` = '2'");
                        dbClient.RunQuery("UPDATE users SET vip_points = vip_points + " + CreditsOwed + " WHERE id = " + Session.GetHabbo().Id);
                    }
                }
            }
        }
Пример #21
0
        internal void FlushSettings()
        {
            List <ServerMessage> messages = new List <ServerMessage>();

            lock (GetRoomItemHandler().mFloorItems)
            {
                foreach (RoomItem Item in GetRoomItemHandler().mFloorItems.Values)
                {
                    ServerMessage Message = new ServerMessage(94);
                    Message.AppendRawUInt(Item.Id);
                    Message.AppendStringWithBreak("");
                    Message.AppendBoolean(false);
                    messages.Add(Message);
                }
            }


            lock (GetRoomItemHandler().mWallItems)
            {
                foreach (RoomItem Item in GetRoomItemHandler().mWallItems.Values)
                {
                    ServerMessage Message = new ServerMessage(84);
                    Message.AppendRawUInt(Item.Id);
                    Message.AppendStringWithBreak("");
                    Message.AppendBoolean(false);
                    messages.Add(Message);
                }
            }

            SendMessage(messages);


            mCycleEnded = true;
            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                GetRoomItemHandler().SaveFurniture(dbClient);

            Tags.Clear();
            UsersWithRights.Clear();
            Bans.Clear();
            ActiveTrades.Clear();


            if (GotFreeze())
            {
                freeze = new Freeze(this);
            }
            if (GotBanzai())
            {
                banzai = new BattleBanzai(this);
            }
            if (GotSoccer())
            {
                soccer = new Soccer(this);
            }
            if (gameItemHandler != null)
            {
                gameItemHandler = new GameItemHandler(this);
            }
        }
Пример #22
0
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            if (!Session.GetHabbo().InRoom)
            {
                return;
            }

            int BotId = Packet.PopInt();

            if (BotId <= 0)
            {
                return;
            }

            Room Room = Session.GetHabbo().CurrentRoom;

            if (Room == null || !Room.CheckRights(Session, true))
            {
                return;
            }

            RoomUser BotUser = null;

            if (!Room.GetRoomUserManager().TryGetBot(BotId, out BotUser))
            {
                RoomUser TargetUser = Session.GetHabbo().CurrentRoom.GetRoomUserManager().GetRoomUserByHabboId(BotId);
                if (TargetUser == null)
                {
                    return;
                }

                //Check some values first, please!
                if (TargetUser.GetClient() == null || TargetUser.GetClient().GetHabbo() == null)
                {
                    return;
                }

                //Update the targets PetId.
                TargetUser.transfbot = false;

                //Quickly remove the old user instance.
                Room.SendPacket(new UserRemoveComposer(TargetUser.VirtualId));

                //Add the new one, they won't even notice a thing!!11 8-)
                Room.SendPacket(new UsersComposer(TargetUser));
                return;
            }

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("UPDATE `bots` SET `room_id` = '0' WHERE `id` = @id LIMIT 1");
                dbClient.AddParameter("id", BotId);
                dbClient.RunQuery();
            }

            Session.GetHabbo().GetInventoryComponent().TryAddBot(new Bot(BotUser.BotData.Id, BotUser.BotData.OwnerId, BotUser.BotData.Name, BotUser.BotData.Motto, BotUser.BotData.Look, BotUser.BotData.Gender, BotUser.BotData.WalkingEnabled, BotUser.BotData.AutomaticChat, BotUser.BotData.ChatText, BotUser.BotData.SpeakingInterval, BotUser.BotData.IsDancing, BotUser.BotData.Enable, BotUser.BotData.Handitem, BotUser.BotData.Status));
            Session.SendPacket(new BotInventoryComposer(Session.GetHabbo().GetInventoryComponent().GetBots()));
            Room.GetRoomUserManager().RemoveBot(BotUser.VirtualId, false);
        }
Пример #23
0
        internal ServerMessage SerializeSearchResults(string SearchQuery)
        {
            DataTable Data = new DataTable();

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                if (SearchQuery.Length > 0)
                {
                    if (dbClient.dbType == Database_Manager.Database.DatabaseType.MySQL)
                    {
                        dbClient.setQuery("SELECT rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE owner = @query AND roomtype = 'private' " +
                                          "UNION ALL " +
                                          "SELECT rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE caption = @query AND roomtype = 'private' " +
                                          "ORDER BY active_users DESC LIMIT 50");
                    }
                    else
                    {
                        dbClient.setQuery("SELECT TOP 50 rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE owner = @query AND roomtype = 'private' " +
                                          "UNION ALL " +
                                          "SELECT rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE caption = @query AND roomtype = 'private' " +
                                          "ORDER BY active_users DESC");
                    }
                    dbClient.addParameter("query", SearchQuery);
                    Data = dbClient.getTable();
                }
            }

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

            if (Data != null)
            {
                foreach (DataRow Row in Data.Rows)
                {
                    RoomData RData = ButterflyEnvironment.GetGame().GetRoomManager().FetchRoomData(Convert.ToUInt32(Row["id"]), Row);
                    Results.Add(RData);
                }
            }

            ServerMessage Message = new ServerMessage(451);

            Message.AppendInt32(1);
            Message.AppendInt32(9);
            Message.AppendStringWithBreak(SearchQuery);
            Message.AppendInt32(Results.Count);

            int i = 0;

            foreach (RoomData Room in Results)
            {
                if (i > 0)
                {
                    Message.AppendInt32(0);
                }
                Room.Serialize(Message, false);
                i++;
            }

            return(Message);
        }
Пример #24
0
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            Session.GetHabbo().GetBadgeComponent().ResetSlots();
            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                queryreactor.RunQuery("UPDATE user_badges SET badge_slot = '0' WHERE user_id = '" + Session.GetHabbo().Id + "' AND badge_slot != '0'");

            for (int i = 0; i < 5; i++)
            {
                int    Slot  = Packet.PopInt();
                string Badge = Packet.PopString();

                if (string.IsNullOrEmpty(Badge))
                {
                    continue;
                }
                if (!Session.GetHabbo().GetBadgeComponent().HasBadge(Badge) || Slot < 1 || Slot > 5)
                {
                    continue;
                }

                Session.GetHabbo().GetBadgeComponent().GetBadge(Badge).Slot = Slot;
                using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    queryreactor.SetQuery(string.Concat(new object[4] {
                        "UPDATE user_badges SET badge_slot = ", Slot, " WHERE badge_id = @badge AND user_id = ", Session.GetHabbo().Id
                    }));
                    queryreactor.AddParameter("badge", Badge);
                    queryreactor.RunQuery();
                }
            }
            ButterflyEnvironment.GetGame().GetQuestManager().ProgressUserQuest(Session, QuestType.PROFILE_BADGE, 0);
            ServerPacket Message = new ServerPacket(ServerPacketHeader.HabboUserBadgesMessageComposer);

            Message.WriteInteger(Session.GetHabbo().Id);
            Message.WriteInteger(Session.GetHabbo().GetBadgeComponent().EquippedCount);

            int BadgeCount = 0;

            foreach (Badge badge in Session.GetHabbo().GetBadgeComponent().BadgeList.Values)
            {
                if (badge.Slot > 0)
                {
                    BadgeCount++;
                    if (BadgeCount > 5)
                    {
                        break;
                    }
                    Message.WriteInteger(badge.Slot);
                    Message.WriteString(badge.Code);
                }
            }

            if (Session.GetHabbo().InRoom&& ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId) != null)
            {
                ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId).SendPacket(Message);
            }

            Session.SendPacket(Message);
        }
Пример #25
0
 public void UpdateUses()
 {
     this.CurrentUses += 1;
     using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
     {
         dbClient.RunQuery("UPDATE `catalog_vouchers` SET `current_uses` = `current_uses` + '1' WHERE `voucher` = '" + this._code + "' LIMIT 1");
     }
 }
Пример #26
0
 internal static void SaveAchievement(Achievement achievement)
 {
     using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
     {
         dbClient.setQuery("UPDATE achievement_info SET level = " + achievement.Level + ", progress = " + achievement.Progress);
         dbClient.runQuery();
     }
 }
Пример #27
0
        public void Parse(GameClient Session, ClientPacket Packet)
        {
            if (!Session.GetHabbo().InRoom)
            {
                return;
            }

            Room Room = null;

            if (!ButterflyEnvironment.GetGame().GetRoomManager().TryGetRoom(Session.GetHabbo().CurrentRoomId, out Room))
            {
                return;
            }

            RoomUser PetUser = null;

            if (!Room.GetRoomUserManager().TryGetPet(Packet.PopInt(), out PetUser))
            {
                return;
            }

            if (PetUser.PetData == null || PetUser.PetData.OwnerId != Session.GetHabbo().Id || PetUser.PetData.Type != 13)
            {
                return;
            }

            //Fetch the furniture Id for the pets current saddle.
            int SaddleId = ItemUtility.GetSaddleId(PetUser.PetData.Saddle);

            //Remove the saddle from the pet.
            PetUser.PetData.Saddle = 0;

            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.RunQuery("UPDATE `user_pets` SET `have_saddle` = '0' WHERE `id` = '" + PetUser.PetData.PetId + "' LIMIT 1");
            }

            //Give the saddle back to the user.
            ItemData ItemData = null;

            if (!ButterflyEnvironment.GetGame().GetItemManager().GetItem(SaddleId, out ItemData))
            {
                return;
            }

            Item Item = ItemFactory.CreateSingleItemNullable(ItemData, Session.GetHabbo(), "");

            if (Item != null)
            {
                Session.GetHabbo().GetInventoryComponent().TryAddItem(Item);
                Session.SendPacket(new FurniListNotificationComposer(Item.Id, 1));
                Session.SendPacket(new PurchaseOKComposer());
            }

            //Update the Pet and the Pet figure information.
            Room.SendPacket(new UsersComposer(PetUser));
            Room.SendPacket(new PetHorseFigureInformationComposer(PetUser));
        }
Пример #28
0
        public void Execute(GameClient Session, Room Room, RoomUser UserRoom, string[] Params)
        {
            if (Params.Length != 2)
            {
                UserRoom.SendWhisperChat(ButterflyEnvironment.GetLanguageManager().TryGetValue("roomsell.error.1", Session.Langue));
                return;
            }

            if (!int.TryParse(Params[1], out int Prix))
            {
                UserRoom.SendWhisperChat(ButterflyEnvironment.GetLanguageManager().TryGetValue("roomsell.error.2", Session.Langue));
                return;
            }
            if (Prix < 1)
            {
                UserRoom.SendWhisperChat(ButterflyEnvironment.GetLanguageManager().TryGetValue("roomsell.error.3", Session.Langue));
                return;
            }
            if (Prix > 99999999)
            {
                UserRoom.SendWhisperChat(ButterflyEnvironment.GetLanguageManager().TryGetValue("roomsell.error.4", Session.Langue));
                return;
            }

            if (Room.RoomData.Group != null)
            {
                UserRoom.SendWhisperChat(ButterflyEnvironment.GetLanguageManager().TryGetValue("roomsell.error.5", Session.Langue));
                return;
            }

            if (Room.RoomData.SellPrice > 0)
            {
                UserRoom.SendWhisperChat(ButterflyEnvironment.GetLanguageManager().TryGetValue("roomsell.error.6", Session.Langue));
                return;
            }

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("UPDATE rooms SET price= @price WHERE id = @roomid LIMIT 1");
                queryreactor.AddParameter("roomid", Room.Id);
                queryreactor.AddParameter("price", Prix);
                queryreactor.RunQuery();
            }

            Room.RoomData.SellPrice = Prix;

            UserRoom.SendWhisperChat(string.Format(ButterflyEnvironment.GetLanguageManager().TryGetValue("roomsell.valide", Session.Langue), Prix));

            foreach (RoomUser user in Room.GetRoomUserManager().GetUserList().ToList())
            {
                if (user == null || user.IsBot)
                {
                    continue;
                }

                user.SendWhisperChat(string.Format(ButterflyEnvironment.GetLanguageManager().TryGetValue("roomsell.warn", Session.Langue), Prix));
            }
        }
Пример #29
0
        public void LoadInventory()
        {
            this._UserItems.Clear();
            DataTable table1;

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("SELECT items.id, items.base_item, items.extra_data, items_limited.limited_number, items_limited.limited_stack FROM items LEFT JOIN items_limited ON (items_limited.item_id = items.id) WHERE items.user_id = @userid AND items.room_id = '0'");

                queryreactor.AddParameter("userid", this.UserId);
                table1 = queryreactor.GetTable();
            }
            foreach (DataRow dataRow in table1.Rows)
            {
                int    Id        = Convert.ToInt32(dataRow[0]);
                int    BaseItem  = Convert.ToInt32(dataRow[1]);
                string ExtraData = DBNull.Value.Equals(dataRow[2]) ? string.Empty : (string)dataRow[2];
                int    Limited   = DBNull.Value.Equals(dataRow[3]) ? 0 : Convert.ToInt32(dataRow[3]);
                int    LimitedTo = DBNull.Value.Equals(dataRow[4]) ? 0 : Convert.ToInt32(dataRow[4]);

                Item userItem = new Item(Id, 0, BaseItem, ExtraData, Limited, LimitedTo, 0, 0, 0.0, 0, "", null);
                this._UserItems.TryAdd(Id, userItem);
            }

            this._petsItems.Clear();
            DataTable table2;

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("SELECT id, user_id, room_id, name, type, race, color, expirience, energy, nutrition, respect, createstamp, x, y, z, have_saddle, hairdye, pethair, anyone_ride FROM user_pets WHERE user_id = " + this.UserId + " AND room_id = 0");
                table2 = queryreactor.GetTable();
            }
            if (table2 != null)
            {
                foreach (DataRow Row in table2.Rows)
                {
                    Pet pet = new Pet(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), Convert.ToInt32(Row["room_id"]), (string)Row["name"], Convert.ToInt32(Row["type"]), (string)Row["race"], (string)Row["color"], (int)Row["expirience"], (int)Row["energy"], (int)Row["nutrition"], (int)Row["respect"], (double)Row["createstamp"], (int)Row["x"], (int)Row["y"], (double)Row["z"], (int)Row["have_saddle"], (int)Row["hairdye"], (int)Row["pethair"], (string)(Row["anyone_ride"]) == "1");
                    this._petsItems.TryAdd(pet.PetId, pet);
                }
            }

            this._botItems.Clear();
            DataTable dBots;

            using (IQueryAdapter queryreactor = ButterflyEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                queryreactor.SetQuery("SELECT * FROM bots WHERE user_id = " + this.UserId + " AND room_id = 0");
                dBots = queryreactor.GetTable();
            }
            if (dBots == null)
            {
                return;
            }
            foreach (DataRow Row in dBots.Rows)
            {
                this._botItems.TryAdd(Convert.ToInt32(Row["id"]), new Bot(Convert.ToInt32(Row["id"]), Convert.ToInt32(Row["user_id"]), (string)Row["name"], (string)Row["motto"], (string)Row["look"], (string)Row["gender"], (string)Row["walk_enabled"] == "1", (string)Row["chat_enabled"] == "1", (string)Row["chat_text"], (int)Row["chat_seconds"], (string)Row["is_dancing"] == "1", (int)Row["enable"], (int)Row["handitem"], Convert.ToInt32((string)Row["status"])));
            }
        }
Пример #30
0
        internal static ServerMessage SerializeUserInfo(uint UserId)
        {
            using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("SELECT id, username, online FROM users WHERE id = " + UserId + "");
                DataRow User = dbClient.getRow();

                dbClient.setQuery("SELECT reg_timestamp, login_timestamp, cfhs, cfhs_abusive, cautions, bans FROM user_info WHERE user_id = " + UserId + "");
                DataRow Info = dbClient.getRow();

                if (User == null)
                {
                    throw new NullReferenceException("No user found in database");
                }

                ServerMessage Message = new ServerMessage(533);

                Message.AppendUInt(Convert.ToUInt32(User["id"]));
                Message.AppendStringWithBreak((string)User["username"]);

                if (Info != null)
                {
                    Message.AppendInt32((int)Math.Ceiling((ButterflyEnvironment.GetUnixTimestamp() - (Double)Info["reg_timestamp"]) / 60));
                    Message.AppendInt32((int)Math.Ceiling((ButterflyEnvironment.GetUnixTimestamp() - (Double)Info["login_timestamp"]) / 60));
                }
                else
                {
                    Message.AppendInt32(0);
                    Message.AppendInt32(0);
                }

                if (User["online"].ToString() == "1")
                {
                    Message.AppendBoolean(true);
                }
                else
                {
                    Message.AppendBoolean(false);
                }

                if (Info != null)
                {
                    Message.AppendInt32((int)Info["cfhs"]);
                    Message.AppendInt32((int)Info["cfhs_abusive"]);
                    Message.AppendInt32((int)Info["cautions"]);
                    Message.AppendInt32((int)Info["bans"]);
                }
                else
                {
                    Message.AppendInt32(0); // cfhs
                    Message.AppendInt32(0); // abusive cfhs
                    Message.AppendInt32(0); // cautions
                    Message.AppendInt32(0); // bans
                }

                return(Message);
            }
        }