Esempio n. 1
0
        /// <summary>
        ///     Serializes the search result list statics.
        /// </summary>
        /// <param name="staticId">The static identifier.</param>
        /// <param name="direct">if set to <c>true</c> [direct].</param>
        /// <param name="message">The message.</param>
        /// <param name="session">The session.</param>
        /// <param name="opened"></param>
        /// <param name="showImage"></param>
        internal static void SerializeSearchResultListStatics(string staticId, bool direct, ServerMessage message, GameClient session, bool opened = false, bool showImage = false)
        {
            if (string.IsNullOrEmpty(staticId) || staticId == "official")
                staticId = "official_view";

            if (staticId != "hotel_view" && staticId != "roomads_view" && staticId != "myworld_view" && !staticId.StartsWith("category__") && staticId != "official_view")
            {
                message.AppendString(staticId);
                message.AppendString(string.Empty);
                message.AppendInteger(1);
                message.AppendBool(!opened); // staticId != "my" && staticId != "popular" && staticId != "official-root"
                message.AppendInteger(showImage ? 1 : 0);
            }

            KeyValuePair<RoomData, uint>[] rooms;

            switch (staticId)
            {
                case "hotel_view":
                    {
                        NavigatorCategory navCategory = Yupi.GetGame().GetNavigator().GetNavigatorCategory(staticId);

                        foreach (NavigatorSubCategory subCategory in navCategory.SubCategories)
                            SerializeSearchResultListStatics(subCategory.Caption, false, message, session, subCategory.IsOpened, subCategory.IsImage);

                        foreach (PublicCategory flat in Yupi.GetGame().GetNavigator().PrivateCategories.Values)
                            SerializeSearchResultListFlatcats(flat.Id, false, message);

                        break;
                    }
                case "official_view":
                    {
                        NavigatorCategory navCategory = Yupi.GetGame().GetNavigator().GetNavigatorCategory(staticId);

                        foreach (NavigatorSubCategory subCategory in navCategory.SubCategories)
                            SerializeSearchResultListStatics(subCategory.Caption, false, message, session, subCategory.IsOpened, subCategory.IsImage);

                    }
                    break;
                case "myworld_view":
                    {
                        NavigatorCategory navCategory = Yupi.GetGame().GetNavigator().GetNavigatorCategory(staticId);

                        foreach (NavigatorSubCategory subCategory in navCategory.SubCategories)
                            SerializeSearchResultListStatics(subCategory.Caption, false, message, session, subCategory.IsOpened, subCategory.IsImage);

                    }
                    break;
                case "roomads_view":
                    {
                        foreach (PublicCategory flat in Yupi.GetGame().GetNavigator().PrivateCategories.Values)
                            SerializePromotionsResultListFlatcats(flat.Id, false, message);

                        NavigatorCategory navCategory = Yupi.GetGame().GetNavigator().GetNavigatorCategory(staticId);

                        foreach (NavigatorSubCategory subCategory in navCategory.SubCategories)
                            SerializeSearchResultListStatics(subCategory.Caption, false, message, session, subCategory.IsOpened, subCategory.IsImage);

                        break;
                    }
                case "official-root":
                    {
                        message.AppendServerMessage(Yupi.GetGame().GetNavigator().NewPublicRooms);

                        break;
                    }
                case "staffpicks":
                    {
                        message.AppendServerMessage(Yupi.GetGame().GetNavigator().NewStaffPicks);

                        break;
                    }
                case "my":
                    {
                        int i = 0;

                        message.StartArray();

                        foreach (RoomData data in session.GetHabbo().UsersRooms)
                        {
                            if (data != null)
                            {
                                data.Serialize(message);

                                message.SaveArray();

                                if (i++ == (direct ? 100 : 8))
                                    break;
                            }
                        }

                        message.EndArray();

                        break;
                    }
                case "favorites":
                    {
                        if (session.GetHabbo().FavoriteRooms == null)
                        {
                            message.AppendInteger(0);

                            return;
                        }

                        int i = 0;

                        message.AppendInteger(session.GetHabbo().FavoriteRooms.Count > (direct ? 40 : 8)
                            ? (direct ? 40 : 8)
                            : session.GetHabbo().FavoriteRooms.Count);

                        foreach (
                            RoomData data in
                                session.GetHabbo()
                                    .FavoriteRooms.Select(dataId => Yupi.GetGame().GetRoomManager().GenerateRoomData(dataId))
                                    .Where(data => data != null))
                        {
                            data.Serialize(message);

                            i++;

                            if (i == (direct ? 40 : 8))
                                break;
                        }

                        break;
                    }
                case "friends_rooms":
                    {
                        int i = 0;

                        if (session?.GetHabbo() == null || session.GetHabbo().GetMessenger() == null ||
                            session.GetHabbo().GetMessenger().GetActiveFriendsRooms() == null)
                        {
                            message.AppendInteger(0);

                            return;
                        }

                        List<RoomData> roomsFriends =
                            session.GetHabbo()
                                .GetMessenger()
                                .GetActiveFriendsRooms()
                                .OrderByDescending(p => p.UsersNow)
                                .Take(direct ? 40 : 8)
                                .ToList();

                        message.AppendInteger(roomsFriends.Count);

                        foreach (RoomData data in roomsFriends.Where(data => data != null))
                        {
                            data.Serialize(message);

                            i++;

                            if (i == (direct ? 40 : 8))
                                break;
                        }

                        break;
                    }
                case "recommended":
                    {
                        break;
                    }
                case "popular":
                    {
                        rooms = Yupi.GetGame().GetRoomManager().GetActiveRooms();

                        if (rooms == null)
                        {
                            message.AppendInteger(0);

                            break;
                        }

                        message.AppendInteger(rooms.Length);

                        foreach (KeyValuePair<RoomData, uint> room in rooms)
                            room.Key.Serialize(message);

                        break;
                    }
                case "top_promotions":
                    {
                        rooms = Yupi.GetGame().GetRoomManager().GetEventRooms();

                        message.AppendInteger(rooms.Length);

                        foreach (KeyValuePair<RoomData, uint> room in rooms)
                            room.Key.Serialize(message);

                        break;
                    }
                case "my_groups":
                    {
                        int i = 0;

                        message.StartArray();

                        foreach (uint xGroupId in session.GetHabbo().MyGroups)
                        {
                            Group xGroup = Yupi.GetGame().GetGroupManager().GetGroup(xGroupId);

                            if (xGroup != null)
                            {
                                RoomData data = Yupi.GetGame().GetRoomManager().GenerateRoomData(xGroup.RoomId);

                                if (data != null)
                                {
                                    data.Serialize(message);
                                    message.SaveArray();

                                    if (i++ == (direct ? 40 : 8))
                                        break;
                                }
                            }
                        }

                        message.EndArray();

                        break;
                    }
                case "history":
                    {
                        int i = 0;

                        message.StartArray();

                        foreach (
                            RoomData roomData in
                                session.GetHabbo()
                                    .RecentlyVisitedRooms.Select(
                                        roomId => Yupi.GetGame().GetRoomManager().GenerateRoomData(roomId))
                                    .Where(roomData => roomData != null))
                        {
                            roomData.Serialize(message);
                            message.SaveArray();

                            if (i++ == (direct ? 40 : 8))
                                break;
                        }

                        message.EndArray();

                        break;
                    }
                default:
                    {
                        if (staticId.StartsWith("category__"))
                            SerializeSearchResultListFlatcats(
                                Yupi.GetGame()
                                    .GetNavigator()
                                    .GetFlatCatIdByName(staticId.Replace("category__", string.Empty)), true, message);
                        else
                            message.AppendInteger(0);

                        break;
                    }
            }
        }