Example #1
0
        /// <summary>
        ///     Serializes the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        internal void Serialize(ServerMessage message)
        {
            message.StartArray();

            foreach (ClothingItem item1 in Clothing.Select(clothing1 => Yupi.GetGame().GetClothingManager().GetClothesInFurni(clothing1)))
            {
                foreach (int clothe in item1.Clothes)
                    message.AppendInteger(clothe);

                message.SaveArray();
            }

            message.EndArray();
            message.StartArray();

            foreach (ClothingItem item2 in Clothing.Select(clothing2 => Yupi.GetGame().GetClothingManager().GetClothesInFurni(clothing2)))
            {
                foreach (int clothe in item2.Clothes)
                    message.AppendString(item2.ItemName);

                message.SaveArray();
            }

            message.EndArray();
        }
        internal ServerMessage AppendEntrySubmitMessage(ServerMessage message, int status, Room room = null)
        {
            message.Init(LibraryParser.OutgoingRequest("CompetitionEntrySubmitResultMessageComposer"));

            message.AppendInteger(Id);
            message.AppendString(Name);
            message.AppendInteger(status);
            // 0 : roomSent - 1 : send room - 2 : confirm register - 3 : neededFurnis - 4 : doorClosed - 6 : acceptRules

            if (status != 3)
            {
                message.AppendInteger(0);
                message.AppendInteger(0);
            }
            else
            {
                message.StartArray();

                foreach (string furni in RequiredFurnis)
                {
                    message.AppendString(furni);
                    message.SaveArray();
                }

                message.EndArray();

                if (room == null)
                    message.AppendInteger(0);
                else
                {
                    message.StartArray();

                    foreach (string furni in RequiredFurnis)
                    {
                        if (!room.GetRoomItemHandler().HasFurniByItemName(furni))
                        {
                            message.AppendString(furni);
                            message.SaveArray();
                        }
                    }

                    message.EndArray();
                }
            }

            return message;
        }
Example #3
0
        internal static void GenerateMessage(ServerMessage message, TargetedOffer offer)
        {
            message.Init(LibraryParser.OutgoingRequest("TargetedOfferMessageComposer"));
            message.AppendInteger(1);
            message.AppendInteger(offer.Id);
            message.AppendString(offer.Identifier);
            message.AppendString(offer.Identifier);
            message.AppendInteger(offer.CostCredits);

            if (offer.CostDiamonds > 0)
            {
                message.AppendInteger(offer.CostDiamonds);
                message.AppendInteger(105);
            }
            else
            {
                message.AppendInteger(offer.CostDuckets);
                message.AppendInteger(0);
            }

            message.AppendInteger(offer.PurchaseLimit);

            int timeLeft = offer.ExpirationTime - Yupi.GetUnixTimeStamp();

            message.AppendInteger(timeLeft);
            message.AppendString(offer.Title);
            message.AppendString(offer.Description);
            message.AppendString(offer.Image);
            message.AppendString(string.Empty);
            message.StartArray();

            foreach (string product in offer.Products)
            {
                message.AppendString(product);
                message.SaveArray();
            }

            message.EndArray();
        }
Example #4
0
        /// <summary>
        ///     Serializes the room visits.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <returns>ServerMessage.</returns>
        internal static ServerMessage SerializeRoomVisits(uint userId)
        {
            ServerMessage serverMessage =
                new ServerMessage(LibraryParser.OutgoingRequest("ModerationToolRoomVisitsMessageComposer"));
            serverMessage.AppendInteger(userId);

            GameClient user = Yupi.GetGame().GetClientManager().GetClientByUserId(userId);

            if (user?.GetHabbo() == null)
            {
                serverMessage.AppendString("Not online");
                serverMessage.AppendInteger(0);
                return serverMessage;
            }

            serverMessage.AppendString(user.GetHabbo().UserName);
            serverMessage.StartArray();

            foreach (
                RoomData roomData in
                    user.GetHabbo()
                        .RecentlyVisitedRooms.Select(roomId => Yupi.GetGame().GetRoomManager().GenerateRoomData(roomId))
                        .Where(roomData => roomData != null))
            {
                serverMessage.AppendInteger(roomData.Id);
                serverMessage.AppendString(roomData.Name);

                serverMessage.AppendInteger(0); //hour
                serverMessage.AppendInteger(0); //min

                serverMessage.SaveArray();
            }

            serverMessage.EndArray();
            return serverMessage;
        }
Example #5
0
        /// <summary>
        ///     Serializes the recent rooms.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns>ServerMessage.</returns>
        internal ServerMessage SerializeRecentRooms(GameClient session)
        {
            ServerMessage serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("NavigatorListingsMessageComposer"));
            serverMessage.AppendInteger(7);
            serverMessage.AppendString(string.Empty);

            serverMessage.StartArray();

            foreach (RoomData roomData in session.GetHabbo().RecentlyVisitedRooms.Select(current => Yupi.GetGame().GetRoomManager().GenerateRoomData(current)))
            {
                roomData.Serialize(serverMessage);
                serverMessage.SaveArray();
            }

            serverMessage.EndArray();
            serverMessage.AppendBool(false);

            return serverMessage;
        }
Example #6
0
        /// <summary>
        ///     Serializes the flat categories.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns>ServerMessage.</returns>
        internal ServerMessage SerializeFlatCategories(GameClient session)
        {
            ServerMessage serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("FlatCategoriesMessageComposer"));
            serverMessage.StartArray();

            foreach (PublicCategory flatCat in PrivateCategories.Values)
            {
                serverMessage.Clear();

                if (flatCat == null)
                    continue;

                serverMessage.AppendInteger(flatCat.Id);
                serverMessage.AppendString(flatCat.Caption);
                serverMessage.AppendBool(flatCat.MinRank <= session.GetHabbo().Rank);
                serverMessage.AppendBool(false);
                serverMessage.AppendString("NONE");
                serverMessage.AppendString(string.Empty);
                serverMessage.AppendBool(false);

                serverMessage.SaveArray();
            }

            serverMessage.EndArray();

            return serverMessage;
        }
Example #7
0
        internal ServerMessage SerializeNewStaffPicks()
        {
            ServerMessage message = new ServerMessage();

            message.StartArray();

            foreach (PublicItem item in _publicItems.Values.Where(t => t.ParentId == -2))
            {
                message.Clear();

                if (item.RoomData == null)
                    continue;

                item.RoomData.Serialize(message);
                message.SaveArray();
            }

            message.EndArray();

            return message;
        }
Example #8
0
        /// <summary>
        /// Serializes the song inventory.
        /// </summary>
        /// <param name="songs">The songs.</param>
        /// <returns>ServerMessage.</returns>
        internal static ServerMessage SerializeSongInventory(HybridDictionary songs)
        {
            ServerMessage serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("SongsLibraryMessageComposer"));

            if (songs == null)
            {
                serverMessage.AppendInteger(0);

                return serverMessage;
            }

            serverMessage.StartArray();

            foreach (UserItem userItem in songs.Values)
            {
                if (userItem == null)
                {
                    serverMessage.Clear();
                    continue;
                }

                serverMessage.AppendInteger(userItem.Id);

                SongData song = SoundMachineSongManager.GetSong(userItem.SongCode);
                serverMessage.AppendInteger(song?.Id ?? 0);

                serverMessage.SaveArray();
            }

            serverMessage.EndArray();
            return serverMessage;
        }
Example #9
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;
                    }
            }
        }