private static void SerializePage(ServerMessage Message, CatalogPage Page, int TreeSize) { Message.AppendBoolean(Page.Visible); Message.AppendInt32(Page.Color); Message.AppendInt32(Page.Icon); Message.AppendInt32(Page.Id); Message.AppendStringWithBreak(Page.Caption + (Page.RequiredRight.Length > 0 ? "*" : string.Empty)); Message.AppendInt32(TreeSize); }
public static ServerMessage Compose(CatalogPage Page) { ServerMessage Message = new ServerMessage(OpcodesOut.CATALOG_PAGE); Message.AppendInt32(Page.Id); Message.AppendStringWithBreak(Page.Template); Message.AppendInt32(Page.PageStrings1.Count); foreach (string PageString in Page.PageStrings1) { Message.AppendStringWithBreak(PageString); } Message.AppendInt32(Page.PageStrings2.Count); foreach (string PageString in Page.PageStrings2) { Message.AppendStringWithBreak(PageString); } Message.AppendInt32(Page.Items.Count); foreach (CatalogItem Item in Page.Items) { Message.AppendUInt32(Item.Id); Message.AppendStringWithBreak(Item.DisplayName); Message.AppendInt32(Item.CostCredits); Message.AppendInt32(Item.CostActivityPoints); Message.AppendInt32(0); // other cost Message.AppendInt32(1); // unknown. Message.AppendStringWithBreak(Item.Definition.TypeLetter); Message.AppendUInt32(Item.Definition.SpriteId); Message.AppendStringWithBreak(Item.ShowPresetFlags ? Item.PresetFlags : string.Empty); // unknown Message.AppendInt32(Item.Amount); // amount Message.AppendInt32(-1); // unknown [for deals??] Message.AppendInt32(Item.ClubRestriction); // Added in RELEASE63-34159-34129-201106010852 } Message.AppendInt32(-1); return Message; }
private static void OnPurchase(Session Session, ClientMessage Message) { int PageId = Message.PopWiredInt32(); uint ItemId = Message.PopWiredUInt32(); string Data = Message.PopString(); CatalogPage Page = CatalogManager.GetCatalogPage(PageId); if (Page == null || Page.DummyPage || !Page.Visible || (Page.RequiredRight.Length > 0 && !Session.HasRight(Page.RequiredRight))) { return; } using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { switch (Page.Template) { default: CatalogItem Item = Page.GetItem(ItemId); if (Item == null || (Item.ClubRestriction == 1 && !Session.HasRight("club_regular")) || (Item.ClubRestriction == 2 && !Session.HasRight("club_vip"))) { return; } HandlePurchase(MySqlClient, Session, Item, Data); break; case "club_buy": CatalogClubOffer Offer = CatalogManager.GetClubOffer(ItemId); if (Offer == null || (Offer.Price > 0 && Session.CharacterInfo.CreditsBalance < Offer.Price) || (int)Offer.Level < (int)Session.SubscriptionManager.SubscriptionLevel) { return; } string BasicAchievement = "ACH_BasicClub"; string VipAchievement = "ACH_VipClub"; // Extend membership and take credits Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, -Offer.Price); Session.SubscriptionManager.AddOrExtend((int)Offer.Level, Offer.LengthSeconds); // Check if we need to manually award basic/vip badges bool NeedsBasicUnlock = !Session.BadgeCache.ContainsCodeWith(BasicAchievement); bool NeedsVipUnlock = !Session.BadgeCache.ContainsCodeWith(VipAchievement); // Reload the badge cache (reactivating any disabled subscription badges) Session.BadgeCache.ReloadCache(MySqlClient, Session.AchievementCache); // Calculate progress int Progress = (int)Math.Ceiling((double)(Offer.LengthDays / 31)); if (Progress <= 0) { Progress = 1; } // Progress VIP achievement if (Offer.Level >= ClubSubscriptionLevel.VipClub) { NeedsVipUnlock = !AchievementManager.ProgressUserAchievement(MySqlClient, Session, VipAchievement, Progress) && NeedsVipUnlock; } else { NeedsVipUnlock = false; } // Progress basic achievement NeedsBasicUnlock = !AchievementManager.ProgressUserAchievement(MySqlClient, Session, BasicAchievement, Progress) && NeedsBasicUnlock; // Virtually unlock the basic achievement without reward if needed if (NeedsBasicUnlock) { Achievement Achievement = AchievementManager.GetAchievement(BasicAchievement); if (Achievement != null) { UserAchievement UserAchievement = Session.AchievementCache.GetAchievementData( BasicAchievement); if (UserAchievement != null) { Session.SendData(AchievementUnlockedComposer.Compose(Achievement, UserAchievement.Level, 0, 0)); } } } // Virtually unlock the VIP achievement without reward if needed if (NeedsVipUnlock) { Achievement Achievement = AchievementManager.GetAchievement(VipAchievement); if (Achievement != null) { UserAchievement UserAchievement = Session.AchievementCache.GetAchievementData( VipAchievement); if (UserAchievement != null) { Session.SendData(AchievementUnlockedComposer.Compose(Achievement, UserAchievement.Level, 0, 0)); } } } // Disable any VIP badges if they still aren't valid if (Session.SubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.VipClub) { Session.BadgeCache.DisableSubscriptionBadge(VipAchievement); } // Synchronize equipped badges if the user has unlocked anything if (NeedsVipUnlock || NeedsBasicUnlock) { RoomInstance Instance = RoomManager.GetInstanceByRoomId(Session.CurrentRoomId); if (Instance != null) { Instance.BroadcastMessage(RoomUserBadgesComposer.Compose(Session.CharacterId, Session.BadgeCache.EquippedBadges)); } } // Clear catalog cache for user (in case of changes) CatalogManager.ClearCacheGroup(Session.CharacterId); // Send new data to client Session.SendData(CatalogPurchaseResultComposer.Compose(Offer)); Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance)); Session.SendData(FuseRightsListComposer.Compose(Session)); Session.SendData(SubscriptionStatusComposer.Compose(Session.SubscriptionManager, true)); //Session.SendData(ClubGiftReadyComposer.Compose(1)); break; } } }