Exemplo n.º 1
0
        private void UpdateRoomIcon(Client Client, Request Request)
        {
            if (!Client.GetUser().IsInRoom)
            {
                return;
            }

            int Q = Request.PopWiredInt32();

            if (!Client.GetUser().GetRoom().GetRoomEngine().HasRights(Client.GetUser().HabboId, Rooms.RightsType.Founder))
            {
                return;
            }

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

            int BackgroundIcon = Request.PopWiredInt32();

            if (BackgroundIcon < 1 || BackgroundIcon > 24)
            {
                BackgroundIcon = 1;
            }

            int ForegroundIcon = Request.PopWiredInt32();

            if (ForegroundIcon < 0 || ForegroundIcon > 11)
            {
                ForegroundIcon = 0;
            }

            int IconsAmount = Request.PopWiredInt32();

            for (int i = 0; i < IconsAmount; i++)
            {
                int SlotId = Request.PopWiredInt32();
                int Icon = Request.PopWiredInt32();

                if (SlotId < 0 || SlotId > 10 || Icon < 1 || Icon > 27)
                {
                    continue;
                }

                if (!Icons.ContainsKey(SlotId))
                {
                    Icons.Add(SlotId, Icon);
                }
            }

            int x = 0;

            StringBuilder Query = new StringBuilder();

            foreach (KeyValuePair<int, int> kvp in Icons)
            {
                if (x < Icons.Count)
                {
                    Query.Append(',');
                }

                Query.Append(kvp.Key);
                Query.Append('.');
                Query.Append(kvp.Value);

                x++;
            }

            Client.GetUser().GetRoom().Icon = new RoomIcon(Client.GetUser().GetRoom().Id, BackgroundIcon, ForegroundIcon, Query.ToString());

            Response Response = new Response();
            Response.Initialize(457);
            Response.AppendInt32(Client.GetUser().RoomId);
            Response.AppendBoolean(true);
            Response.Initialize(456);
            Response.AppendInt32(Client.GetUser().RoomId);
            Client.SendResponse(Response);

            Response Data = new Response(454);
            Data.AppendBoolean(false);
            Client.GetUser().GetRoom().GetNavigatorResponse(Data, false);
            Client.SendRoomResponse(Data);

            using (QueryReactor Reactor = BrickEngine.GetQueryReactor())
            {
                Reactor.SetQuery("UPDATE private_rooms SET nav_icon_bg = @bg, nav_icon_fg = @fg, nav_icons = @icons WHERE id = @roomid LIMIT 1");
                Reactor.AddParam("bg", BackgroundIcon);
                Reactor.AddParam("fg", ForegroundIcon);
                Reactor.AddParam("icons", Query.ToString());
                Reactor.AddParam("roomid", Client.GetUser().RoomId);
                Reactor.ExcuteQuery();
            }
        }
Exemplo n.º 2
0
        private void EndEditRoom(Client Client, Request Request)
        {
            if (!Client.GetUser().IsInRoom)
            {
                return;
            }

            int RoomId = Request.PopWiredInt32();

            VirtualRoom Room = BrickEngine.GetRoomReactor().GetVirtualRoom(RoomId, RoomRunningState.Alive);

            if (Room == null)
            {
                return;
            }

            if (!Room.GetRoomEngine().HasRights(Client.GetUser().HabboId, Rooms.RightsType.Founder))
            {
                return;
            }

            string Name = BrickEngine.CleanString(Request.PopFixedString());
            string Description = BrickEngine.CleanString(Request.PopFixedString());
            int DoorState = Request.PopWiredInt32();
            string Password = BrickEngine.CleanString(Request.PopFixedString());
            int LimitUsers = Request.PopWiredInt32();

            int CategoryId = Request.PopWiredInt32();

            PrivateCategory Category = BrickEngine.GetNavigatorManager().GetPrivateCategory(CategoryId);

            if (Category == null)
            {
                CategoryId = 0;
            }

            if (Client.GetUser().Rank < Category.RankAllowed)
            {
                Client.Notif("You're not allowed to use this category.", false);
                CategoryId = 0;
            }

            int TagAmount = Request.PopWiredInt32();

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

            for (int i = 0; i < TagAmount; i++)
            {
                string Tag = BrickEngine.CleanString(Request.PopFixedString()).Trim().ToLower();

                if (Tag.Length > 32)
                {
                    Tag = Tag.Substring(0, 32);
                }

                if (Tag.Length > 0 && !Tags.Contains(Tag))
                {
                    Tags.Add(Tag);
                }
            }

            Boolean AllowPets = (Request.PlainReadBytes(1)[0].ToString() == "65");
            Request.AdvancePointer(1);

            Boolean AllowPetsEat = (Request.PlainReadBytes(1)[0].ToString() == "65");
            Request.AdvancePointer(1);

            Boolean AllowWalkthough = (Request.PlainReadBytes(1)[0].ToString() == "65");
            Request.AdvancePointer(1);

            Boolean AllowHideWall = (Request.PlainReadBytes(1)[0].ToString() == "65");
            Request.AdvancePointer(1);

            int WallThick = Request.PopWiredInt32();

            if (WallThick < -2 || WallThick > 1)
            {
                WallThick = 0;
            }

            int FloorThick = Request.PopWiredInt32();

            if (FloorThick < -2 || FloorThick > 1)
            {
                FloorThick = 0;
            }

            if (Name.Length > 60)
            {
                Name = Name.Substring(0, 60);
            }

            if (Description.Length > 128)
            {
                Description = Description.Substring(0, 128);
            }

            if (Password.Length > 64)
            {
                Password = Password.Substring(0, 64);
            }

            if (LimitUsers > Client.GetUser().GetRoom().GetRoomModel().LimitUsers)
            {
                LimitUsers = Client.GetUser().GetRoom().GetRoomModel().LimitUsers;
            }

            if (DoorState == 2 && Password.Length <= 0)
            {
                DoorState = 0;
            }

            Dictionary<string, Object> Params = new Dictionary<string, object>();

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

            if (!Room.Name.Equals(Name))
            {
                Commands.Add("name = @name");
                Params.Add("name", Name);
                Room.Name = Name;
            }

            if (!Room.Description.Equals(Description))
            {
                Commands.Add("description = @desc");
                Params.Add("desc", Description);
                Room.Description = Description;
            }

            if (!Room.DoorState.Equals(DoorState))
            {
                Commands.Add("door_state = @door");
                Params.Add("door", DoorState);
                Room.DoorState = DoorState;
            }

            if (!Room.Password.Equals(Password))
            {
                Commands.Add("password = @pw");
                Params.Add("pw", Password);
                Room.Password = Password;
            }

            if (!Room.LimitUsers.Equals(LimitUsers))
            {
                Commands.Add("limit_users = @limit");
                Params.Add("limit", LimitUsers);
                Room.LimitUsers = LimitUsers;
            }

            if (!Room.CategoryId.Equals(CategoryId))
            {
                Commands.Add("category_id = @catid");
                Params.Add("catid", CategoryId);
                Room.CategoryId = CategoryId;
            }

            if (!Room.Tags.Equals(Tags))
            {
                string SplittedTags = string.Empty;

                int x = 0;

                foreach (string Tag in Tags)
                {
                    if (x > 0)
                    {
                        SplittedTags += ',';
                    }

                    SplittedTags += Tag.ToLower();

                    x++;
                }

                Commands.Add("tags = @tags");
                Params.Add("tags", SplittedTags.ToString());
                Room.Tags = Tags;
            }

            if (!Room.AllowPets.Equals(AllowPets))
            {
                Commands.Add("allow_pets = @allow_pets");
                Params.Add("allow_pets", AllowPets ? 1 : 0);
                Room.AllowPets = AllowPets;
            }

            if (!Room.AllowPetsEat.Equals(AllowPetsEat))
            {
                Commands.Add("allow_pets_eat = @allow_pets_eat");
                Params.Add("allow_pets_eat", AllowPetsEat ? 1 : 0);
                Room.AllowPetsEat = AllowPetsEat;
            }

            if (!Room.AllowWalkthough.Equals(AllowWalkthough))
            {
                Commands.Add("allow_walkthough = @allow_walkthough");
                Params.Add("allow_walkthough", AllowWalkthough ? 1 : 0);
                Room.AllowWalkthough = AllowWalkthough;
            }

            if (!Room.AllowHideWall.Equals(AllowHideWall))
            {
                Commands.Add("allow_hidewall = @allow_hidewall");
                Params.Add("allow_hidewall", AllowHideWall ? 1 : 0);
                Room.AllowHideWall = AllowHideWall;
            }

            if (!Room.WallThick.Equals(WallThick))
            {
                Commands.Add("walls_thick = @walls_thick");
                Params.Add("walls_thick", WallThick);
                Room.WallThick = WallThick;
            }

            if (!Room.FloorThick.Equals(FloorThick))
            {
                Commands.Add("floors_thick = @floors_thick");
                Params.Add("floors_thick", FloorThick);
                Room.FloorThick = FloorThick;
            }

            Response Data = new Response(454);
            Data.AppendBoolean(true);
            Room.GetNavigatorResponse(Data, false);
            Client.SendRoomResponse(Data);

            Response Response = new Response();
            Response.Initialize(467);
            Response.AppendInt32(Client.GetUser().RoomId);
            Response.Initialize(456);
            Response.AppendInt32(Client.GetUser().RoomId);
            Client.SendResponse(Response);

            Response RoomStruct = new Response(472);
            RoomStruct.AppendBoolean(AllowHideWall);
            RoomStruct.AppendInt32(WallThick);
            RoomStruct.AppendInt32(FloorThick);
            Client.SendRoomResponse(RoomStruct);

            if (Commands.Count > 0)
            {
                using (QueryReactor Reactor = BrickEngine.GetQueryReactor())
                {
                    StringBuilder Builder = new StringBuilder();
                    Builder.Append("UPDATE private_rooms SET ");

                    int i = 0;

                    foreach (string Command in Commands)
                    {
                        i++;
                        Builder.Append(Command);

                        if (i < Commands.Count)
                        {
                            Builder.Append(", ");
                        }
                    }

                    Builder.Append(" WHERE id = @roomid LIMIT 1");

                    Reactor.SetQuery(Builder.ToString());

                    foreach (KeyValuePair<string, Object> kvp in Params)
                    {
                        Reactor.AddParam(kvp.Key, kvp.Value);
                    }

                    Reactor.AddParam("roomid", Room.Id);

                    Reactor.ExcuteQuery();
                }
            }
        }
Exemplo n.º 3
0
        private void Wave(Client Client, Request Request)
        {
            if (!Client.GetUser().IsInRoom)
            {
                return;
            }

            Response Response = new Response(481);
            Response.AppendInt32(Client.GetUser().GetRoomUser().VirtualId);

            Client.SendRoomResponse(Response);
        }
Exemplo n.º 4
0
        private void UpdateEvent(Client Client, Request Request)
        {
            if (!Client.GetUser().IsInRoom)
            {
                return;
            }

            if (!Client.GetUser().GetRoom().GetRoomEngine().HasRights(Client.GetUser().HabboId, Rooms.RightsType.Founder))
            {
                return;
            }

            int CategoryId = Request.PopWiredInt32();
            string Name = BrickEngine.CleanString(Request.PopFixedString());
            string Description = BrickEngine.CleanString(Request.PopFixedString());
            int TagCount = Request.PopWiredInt32();

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

            for (int i = 0; i < TagCount; i++)
            {
                Tags.Add(BrickEngine.CleanString(Request.PopFixedString()));
            }

            RoomEvent Event = null;

            if (Client.GetUser().GetRoom().Event == null)
            {
                Event = new RoomEvent(Client.GetUser().RoomId, Name, Description, CategoryId, Tags);

                Client.GetUser().GetRoom().Event = Event;

                // Friends alert
                BrickEngine.GetMessengerHandler().AlertFriends(Client.GetUser().HabboId, BrickEngine.GetMessengerHandler().GetAchievedResponse(Client.GetUser().HabboId, false, Name));
            }
            else
            {
                Event = Client.GetUser().GetRoom().Event;

                Event.Name = Name;
                Event.Description = Description;
                Event.Tags = Tags;
            }

            Response Response = new Response(370);
            Event.GetResponse(Response);

            Client.SendRoomResponse(Response);
        }
Exemplo n.º 5
0
        private void UpdateBadge(Client Client, Request Request)
        {
            var Badges = BrickEngine.GetBadgeHandler().GetBadgesForUser(Client.GetUser().HabboId);;

            // Null every badge ready for update
            foreach (Badge Badge in Badges)
            {
                Badge.SlotId = 0;
            }

            // Check new badge updates
            while (Request.RemainingLength > 0)
            {
                int SlotId = Request.PopWiredInt32();
                string Badge = Request.PopFixedString();

                Badge SelectedBadge = BrickEngine.GetBadgeHandler().GetBadge(Badge, Client.GetUser().HabboId);

                if (SelectedBadge != null)
                {
                    SelectedBadge.SlotId = SlotId;
                }
            }

            // Cache Equiped Badges Again for Update
            var Equiped = BrickEngine.GetBadgeHandler().GetEquipedBadges(Client.GetUser().HabboId);

            // Send update response
            Response Response = new Response(228);
            Response.AppendInt32(Client.GetUser().HabboId);
            Response.AppendInt32(Equiped.Count);

            foreach (Badge Badge in Equiped)
            {
                Response.AppendInt32(Badge.SlotId);
                Response.AppendStringWithBreak(Badge.BadgeCode);
            }

            if (Client.GetUser().IsInRoom)
            {
                Client.SendRoomResponse(Response);
            }
            else
            {
                Client.SendResponse(Response);
            }

            foreach (Badge Badge in Badges)
            {
                using (QueryReactor Reactor = BrickEngine.GetQueryReactor())
                {
                    Reactor.SetQuery("UPDATE user_badges SET slot_id = @slotid WHERE badge = @badge AND user_id = @habboid LIMIT 1");
                    Reactor.AddParam("slotid", Badge.SlotId);
                    Reactor.AddParam("badge", Badge.BadgeCode);
                    Reactor.AddParam("habboid", Client.GetUser().HabboId);
                    Reactor.ExcuteQuery();
                }
            }
        }
Exemplo n.º 6
0
        private void RespectUser(Client Client, Request Request)
        {
            if (!Client.GetUser().IsInRoom)
            {
                return;
            }

            if (Client.GetUser().RespectLeft < 0)
            {
                return;
            }

            int HabboId = Request.PopWiredInt32();

            VirtualRoomUser TriggeredUser = Client.GetUser().GetRoom().GetRoomEngine().GetUserByHabboId(HabboId);

            if (TriggeredUser == null)
            {
                return;
            }

            TriggeredUser.GetClient().GetUser().RespectGained++;

            Response Response = new Response(440);
            Response.AppendInt32(HabboId);
            Response.AppendInt32(TriggeredUser.GetClient().GetUser().RespectGained);
            Client.SendRoomResponse(Response);

            Client.GetUser().RespectLeft--;
            Client.GetUser().RespectGiven++;

            // Update TriggeredUser
            using (QueryReactor Reactor = BrickEngine.GetQueryReactor())
            {
                Reactor.SetQuery("UPDATE users SET respect_gained = respect_gained + 1 WHERE id = @habboid LIMIT 1");
                Reactor.AddParam("habboid", HabboId);
                Reactor.ExcuteQuery();
            }

            // Update Left
            using (QueryReactor Reactor = BrickEngine.GetQueryReactor())
            {
                Reactor.SetQuery("UPDATE users SET respect_left = respect_left - 1 WHERE id = @habboid LIMIT 1");
                Reactor.AddParam("habboid", Client.GetUser().HabboId);
                Reactor.ExcuteQuery();
            }

            // Update Given
            using (QueryReactor Reactor = BrickEngine.GetQueryReactor())
            {
                Reactor.SetQuery("UPDATE users SET respect_given = respect_given + 1 WHERE id = @habboid LIMIT 1");
                Reactor.AddParam("habboid", Client.GetUser().HabboId);
                Reactor.ExcuteQuery();
            }
        }
Exemplo n.º 7
0
        private void EndTyping(Client Client, Request Request)
        {
            if (!Client.GetUser().IsInRoom)
            {
                return;
            }

            Response Response = new Response(361);
            Response.AppendInt32(Client.GetUser().GetRoomUser().VirtualId);
            Response.AppendBoolean(false);

            Client.SendRoomResponse(Response);
        }
Exemplo n.º 8
0
        private void Dance(Client Client, Request Request)
        {
            if (!Client.GetUser().IsInRoom)
            {
                return;
            }

            int DanceId = Request.PopWiredInt32();

            Client.GetUser().GetRoomUser().DanceId = DanceId;

            Response Response = new Response(480);
            Response.AppendInt32(Client.GetUser().GetRoomUser().VirtualId);
            Response.AppendInt32(DanceId);

            Client.SendRoomResponse(Response);
        }
Exemplo n.º 9
0
        private void ChangeName(Client Client, Request Request)
        {
            string Username = BrickEngine.CleanString(Request.PopFixedString());

            Boolean UpdatedName = false;

            if (!Client.GetUser().Username.ToLower().Equals(Username.ToLower()))
            {
                foreach (VirtualRoom Room in BrickEngine.GetRoomReactor().GetMe(Client.GetUser().HabboId))
                {
                    if (Room.InternalState.Equals(RoomRunningState.Alive))
                    {
                        Boolean IsMatch = false;

                        if (Regex.IsMatch(Room.Name.ToLower(), Client.GetUser().Username.ToLower()))
                        {
                            Room.Name = Room.Name.Replace(Client.GetUser().Username, Username);
                            IsMatch = true;
                        }

                        if (Regex.IsMatch(Room.Description.ToLower(), Client.GetUser().Username.ToLower()))
                        {
                            Room.Description = Room.Description.Replace(Client.GetUser().Username, Username);
                            IsMatch = true;
                        }

                        if (IsMatch)
                        {
                            using (QueryReactor Reactor = BrickEngine.GetQueryReactor())
                            {
                                Reactor.SetQuery("UPDATE private_rooms SET name = @name, description = @desc WHERE id = @roomid LIMIT 1");
                                Reactor.AddParam("name", Room.Name);
                                Reactor.AddParam("desc", Room.Description);
                                Reactor.AddParam("roomid", Room.Id);
                                Reactor.ExcuteQuery();
                            }

                            Response Data = new Response(454);
                            Data.AppendBoolean(true);
                            Room.GetNavigatorResponse(Data, false);
                            Client.SendRoomResponse(Data);
                        }
                    }
                }

                Client.GetUser().Username = Username;
                Client.GetUser().RefreshUser();

                Client.Notif("Successfully changed name, reload your room to see changes.", false);

                if (Client.GetUser().EnableShowOnline)
                {
                    lock (Client.GetUser().MessengerLocker)
                    {
                        BrickEngine.GetMessengerHandler().AlertStatusFriends(Client.GetUser(), true);
                    }
                }

                UpdatedName = true;
            }

            Client.GetUser().ProgressedNewbie = true;

            Response Response = new Response();
            Response.Initialize(571);
            Response.AppendBoolean(false);
            Response.AppendStringWithBreak(Username);
            Response.AppendBoolean(false);
            Response.Initialize(570);
            Response.AppendBoolean(false);
            Response.AppendStringWithBreak(Username);
            Response.AppendBoolean(false);
            Client.SendResponse(Response);

            BrickEngine.GetAchievementReactor().UpdateUsersAchievement(Client, 4);

            using (QueryReactor Reactor = BrickEngine.GetQueryReactor())
            {
                Reactor.SetQuery("UPDATE users SET changed_name = '1' WHERE id = @habboid");
                Reactor.AddParam("habboid", Client.GetUser().HabboId);
                Reactor.ExcuteQuery();
            }

            if (UpdatedName)
            {
                using (QueryReactor Reactor = BrickEngine.GetQueryReactor())
                {
                    Reactor.SetQuery("UPDATE users SET username = @username WHERE id = @habboid");
                    Reactor.AddParam("habboid", Client.GetUser().HabboId);
                    Reactor.AddParam("username", Username);
                    Reactor.ExcuteQuery();
                }
            }
        }