public static ServerMessage Compose(CatalogItem Item) { ServerMessage Message = new ServerMessage(OpcodesOut.CATALOG_PURCHASE_RESULT); Message.AppendUInt32(Item.Definition.Id); Message.AppendStringWithBreak(Item.DisplayName); Message.AppendInt32(Item.CostCredits); Message.AppendInt32(Item.CostActivityPoints); Message.AppendInt32(0); // No noticable effect Message.AppendInt32(1); // Amount of messages shown to end user Message.AppendStringWithBreak(Item.Definition.TypeLetter); Message.AppendUInt32(Item.Definition.SpriteId); Message.AppendStringWithBreak(Item.PresetFlags); Message.AppendInt32(1); // ?????????????????????? Message.AppendInt32(0); // ????????????? Message.AppendInt32(0); // ????????????????? return Message; }
public static ServerMessage Compose(CatalogItem Item, List<PetRaceData> RaceData, int PetType) { // L{a0 pet12RAPCHIHPCIIHPCJIHPCKIHPCPAIHPCQAIH ServerMessage Message = new ServerMessage(OpcodesOut.CATALOG_PET_DATA); Message.AppendStringWithBreak(Item.DisplayName); Message.AppendInt32(RaceData.Count); foreach (PetRaceData Race in RaceData) { Message.AppendInt32(PetType); // Pet type Message.AppendInt32(Race.Data1); // Color?? Message.AppendInt32(Race.Data2); Message.AppendInt32(Race.Data3); } return Message; }
public static void HandlePurchase(SqlDatabaseClient MySqlClient, Session Session, CatalogItem Item, string ItemFlags) { lock (mPurchaseSyncRoot) { int TotalCreditCost = Item.CostCredits; int TotalApCost = Item.CostActivityPoints; if (Session.CharacterInfo.CreditsBalance < TotalCreditCost || Session.CharacterInfo.ActivityPointsBalance < TotalApCost) { return; } string[] PetData = null; if (Item.PresetFlags.Length > 0) { ItemFlags = Item.PresetFlags; } else { switch (Item.Definition.Behavior) { case ItemBehavior.Pet: PetData = ItemFlags.Split('\n'); if (PetData.Length != 3) { return; } string Name = PetData[0]; string Color = PetData[2]; int Race = 0; int.TryParse(PetData[1], out Race); bool RaceOk = false; List<PetRaceData> Races = PetDataManager.GetRaceDataForType(Item.Definition.BehaviorData); foreach (PetRaceData RaceData in Races) { if (RaceData.Data1 == Race) { RaceOk = true; break; } } if (PetName.VerifyPetName(Name) != PetNameError.NameOk || Color.ToLower() != "ffffff" || !RaceOk) { return; } break; case ItemBehavior.PrizeTrophy: if (ItemFlags.Length > 255) { ItemFlags = ItemFlags.Substring(0, 255); } ItemFlags = Session.CharacterInfo.Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + Convert.ToChar(9) + UserInputFilter.FilterString(ItemFlags.Trim(), true); break; default: ItemFlags = string.Empty; break; } } if (TotalCreditCost > 0) { Session.CharacterInfo.UpdateCreditsBalance(MySqlClient, -TotalCreditCost); Session.SendData(CreditsBalanceComposer.Compose(Session.CharacterInfo.CreditsBalance)); } if (TotalApCost > 0) { Session.CharacterInfo.UpdateActivityPointsBalance(MySqlClient, -TotalApCost); Session.SendData(ActivityPointsBalanceComposer.Compose(Session.CharacterInfo.ActivityPointsBalance, -TotalApCost)); } Dictionary<int, List<uint>> NewItems = new Dictionary<int, List<uint>>(); for (int i = 0; i < Item.Amount; i++) { switch (Item.Definition.Type) { default: List<Item> GeneratedGenericItems = new List<Item>(); double ExpireTimestamp = 0; if (Item.Definition.Behavior == ItemBehavior.Rental) { ExpireTimestamp = UnixTimestamp.GetCurrent() + 3600; } GeneratedGenericItems.Add(ItemFactory.CreateItem(MySqlClient, Item.DefinitionId, Session.CharacterId, ItemFlags, ItemFlags, ExpireTimestamp)); switch (Item.Definition.Behavior) { case ItemBehavior.Teleporter: Item LinkedItem = ItemFactory.CreateItem(MySqlClient, Item.DefinitionId, Session.CharacterId, GeneratedGenericItems[0].Id.ToString(), string.Empty, ExpireTimestamp); GeneratedGenericItems[0].Flags = LinkedItem.Id.ToString(); GeneratedGenericItems[0].SynchronizeDatabase(MySqlClient, true); GeneratedGenericItems.Add(LinkedItem); break; } foreach (Item GeneratedItem in GeneratedGenericItems) { Session.InventoryCache.Add(GeneratedItem); int TabId = GeneratedItem.Definition.Type == ItemType.FloorItem ? 1 : 2; if (!NewItems.ContainsKey(TabId)) { NewItems.Add(TabId, new List<uint>()); } NewItems[TabId].Add(GeneratedItem.Id); } break; case ItemType.AvatarEffect: AvatarEffect Effect = null; if (Session.AvatarEffectCache.HasEffect((int)Item.Definition.SpriteId)) { Effect = Session.AvatarEffectCache.GetEffect((int)Item.Definition.SpriteId); if (Effect != null) { Effect.AddToQuantity(); } } else { Effect = AvatarEffectFactory.CreateEffect(MySqlClient, Session.CharacterId, (int)Item.Definition.SpriteId, 3600); Session.AvatarEffectCache.Add(Effect); } if (Effect != null) { Session.SendData(UserEffectAddedComposer.Compose(Effect)); } break; case ItemType.Pet: Pet Pet = PetFactory.CreatePet(MySqlClient, Session.CharacterId, Item.Definition.BehaviorData, PetData[0], int.Parse(PetData[1])); Session.PetInventoryCache.Add(Pet); Session.SendData(InventoryPetAddedComposer.Compose(Pet)); if (!NewItems.ContainsKey(3)) { NewItems.Add(3, new List<uint>()); } NewItems[3].Add(Pet.Id); break; } } Session.SendData(CatalogPurchaseResultComposer.Compose(Item)); Session.SendData(InventoryRefreshComposer.Compose()); foreach (KeyValuePair<int, List<uint>> NewItemData in NewItems) { foreach (uint NewItem in NewItemData.Value) { Session.NewItemsCache.MarkNewItem(MySqlClient, NewItemData.Key, NewItem); } } if (NewItems.Count > 0) { Session.SendData(InventoryNewItemsComposer.Compose(new Dictionary<int, List<uint>>(NewItems))); } } }
public static void RefreshCatalogData(SqlDatabaseClient MySqlClient, bool NotifyUsers = true) { int CountLoaded = 0; lock (mPages) { mCatalogItems.Clear(); mCatalogItemsIdIndex.Clear(); mCatalogItemsNameIndex.Clear(); mPages.Clear(); mClubOffers.Clear(); mPages.Add(-1, new CatalogPage(-1, 0, string.Empty, 0, 0, string.Empty, true, true, string.Empty, null, null, new List<CatalogItem>())); // root category MySqlClient.SetParameter("enabled", "1"); DataTable ItemTable = MySqlClient.ExecuteQueryTable("SELECT * FROM catalog_items WHERE enabled = @enabled ORDER BY base_id ASC"); foreach (DataRow Row in ItemTable.Rows) { int PageId = (int)Row["page_id"]; if (!mCatalogItems.ContainsKey(PageId)) { mCatalogItems[PageId] = new List<CatalogItem>(); } CatalogItem Item = new CatalogItem((uint)Row["id"], (uint)Row["base_id"], (string)Row["name"], (int)Row["cost_credits"], (int)Row["cost_pixels"], (int)Row["amount"], (string)Row["preset_flags"], (int)Row["club_restriction"]); if (Item.Definition == null) { Output.WriteLine("Warning: Catalog item " + (uint)Row["id"] + " has an invalid base_id reference.", OutputLevel.Warning); continue; } mCatalogItems[PageId].Add(Item); mCatalogItemsIdIndex[Item.Id] = Item; mCatalogItemsNameIndex[Item.DisplayName] = Item; } MySqlClient.SetParameter("enabled", "1"); DataTable Table = MySqlClient.ExecuteQueryTable("SELECT * FROM catalog WHERE enabled = @enabled ORDER BY order_num ASC"); foreach (DataRow Row in Table.Rows) { List<string> PageStrings1 = new List<string>(); List<string> PageStrings2 = new List<string>(); foreach (string String in Row["page_strings_1"].ToString().Split('|')) PageStrings1.Add(String); foreach (string String in Row["page_strings_2"].ToString().Split('|')) PageStrings2.Add(String); int Id = (int)Row["id"]; mPages.Add(Id, new CatalogPage((int)Row["id"], (int)Row["parent_id"], (string)Row["title"], (int)Row["icon"], (int)Row["color"], (string)Row["required_right"], (Row["visible"].ToString() == "1"), (Row["dummy_page"].ToString() == "1"), (string)Row["template"], PageStrings1, PageStrings2, mCatalogItems.ContainsKey(Id) ? mCatalogItems[Id] : new List<CatalogItem>())); CountLoaded++; } DataTable ClubTable = MySqlClient.ExecuteQueryTable("SELECT * FROM catalog_subscriptions"); foreach (DataRow Row in ClubTable.Rows) { CatalogClubOfferType OfferType = CatalogClubOfferType.Basic; switch ((string)Row["type"]) { case "vip": OfferType = CatalogClubOfferType.Vip; break; case "upgrade": OfferType = CatalogClubOfferType.VipUpgrade; break; } mClubOffers.Add((uint)Row["id"], new CatalogClubOffer((uint)Row["id"], (string)Row["name"], (int)Row["cost_credits"], (int)Row["length_days"], OfferType)); } } Output.WriteLine("Loaded " + CountLoaded + " catalog page(s).", OutputLevel.DebugInformation); if (NotifyUsers) { SessionManager.BroadcastPacket(CatalogUpdatedNotificationComposer.Compose()); } }