internal void PurchaseGift() { GiftData data = new GiftData(); int PageId = Request.ReadInt(); uint ItemId = Request.ReadUInt(); Request.ReadString(); data.sendingUser = ButterflyEnvironment.FilterInjectionChars(Request.ReadString()); data.message = ButterflyEnvironment.FilterInjectionChars(Request.ReadString()); data.spriteID = Request.ReadInt(); data.wrappingPaper = Request.ReadInt(); data.decorationType = Request.ReadInt(); data.showUsername = Request.ReadBool(); ButterflyEnvironment.GetGame().GetCatalog().HandlePurchase(Session, PageId, ItemId, string.Empty, 1, data); }
private void LoadGift() { if (GetBaseItem().IsGift && extraData.Length >= 12) { GiftData giftData = new GiftData(extraData); if (giftData.wrappingPaper < 20 && giftData.decorationType < 20) this.giftData = giftData; } }
internal void HandlePurchase(GameClient Session, int PageId, uint ItemId, string ExtraData, int amount, GiftData giftData) { bool IsGift = giftData != null; int discountCount = 0; if (amount >= 6) discountCount += 1; if (amount >= 12) discountCount += 2; if (amount >= 18) discountCount += 2; if (amount >= 24) discountCount += 2; if (amount >= 30) discountCount += 2; if (amount >= 36) discountCount += 2; if (amount >= 42) discountCount += 2; if (amount >= 48) discountCount += 2; if (amount >= 54) discountCount += 2; if (amount >= 60) discountCount += 2; if (amount >= 66) discountCount += 2; if (amount >= 72) discountCount += 2; if (amount >= 78) discountCount += 2; if (amount >= 84) discountCount += 2; if (amount >= 90) discountCount += 2; if (amount >= 96) discountCount += 2; if (amount >= 99) discountCount += 2; CatalogPage Page; if (!Pages.TryGetValue(PageId, out Page)) return; if (Page == null || Page.ComingSoon || !Page.Enabled || !Page.Visible || Session == null || Session.GetHabbo() == null) { return; } if (Page.ClubOnly && !Session.GetHabboDataContainer().GetSubscriptionManager().HasSubscription(SubscriptionManager.SUBSCRIPTION_TYPE_VIP)) { return; } if (Page.MinRank > Session.GetHabbo().Rank) { return; } CatalogItem Item = Page.GetItem(ItemId); if (Item == null) { return; } uint GiftUserId = 0; if (Item.isLimited) { amount = 1; discountCount = 0; if (Item.limitedInStock <= Item.limitedSold++) return; using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE catalog_items SET sold_amount = " + Item.limitedSold + " WHERE id = " + Item.ID); } Page.InitMsg(); } Session.GetHabboDataContainer().SynchronizeDiamondBalance(); int total_cost_credits = Item.creditCost * (amount - discountCount); int total_cost_pixels = Item.pixelCost * (amount - discountCount); int total_cost_diamonds = Item.diamondCost * (amount - discountCount); if (total_cost_diamonds > 0) { Session.GetHabbo().SynchronizeDiamondBalance(); } if (IsGift) { if (!Item.GetBaseItem().AllowGift) { return; } DataRow dRow; using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id FROM users WHERE username = @gift_user"); dbClient.addParameter("gift_user", giftData.sendingUser); dRow = dbClient.getRow(); } if (dRow == null) { ServerMessage response = PacketHandelingManager.GetRecycledItem(OutputCode.GiftReceiverNotFoundEvent); response.AddBoolean(true); response.AddString(giftData.sendingUser); Session.SendMessage(response); return; } GiftUserId = Convert.ToUInt32(dRow[0]); if (GiftUserId == 0) { ServerMessage response = PacketHandelingManager.GetRecycledItem(OutputCode.GiftReceiverNotFoundEvent); response.AddBoolean(true); response.AddString(giftData.sendingUser); Session.SendMessage(response); return; } } if (Session.GetHabbo().ActivityPoints < total_cost_pixels || Session.GetHabbo().Credits < total_cost_credits || Session.GetHabbo().Diamonds < total_cost_diamonds) return; if (IsGift && Item.GetBaseItem().Type == 'e') { Session.SendNotif("Oeps! Er is iets mis gegaan, probeer het opnieuw!\r\r<b>Beschrijving:</b>\rJe kunt dit item niet versturen als cadeau."); return; } if (Item.catalogName.Contains("HABBO_CLUB_VIP") || Item.catalogName.Equals("deal_vip_1_year_and_badge") || Item.catalogName.ToUpper().Contains("DEAL_HC")) { if (Item.creditCost > Session.GetHabbo().Credits) return; int Days = 0; //DEAL_HC_3 if (Item.catalogName.ToUpper().Contains("DEAL_HC_")) { int k = int.Parse(Item.catalogName.Split('_')[2]); switch (k) { case 1: Days = 1 * 31; break; case 2: Days = 3 * 31; break; case 3: Days = 6 * 31; break; } } else if (Item.catalogName.Contains("HABBO_CLUB_VIP_")) { if (Item.catalogName.Contains("_DAY")) { Days = int.Parse(Item.catalogName.Split('_')[3]); } else if (Item.catalogName.Contains("_MONTH")) { Days = 31 * int.Parse(Item.catalogName.Split('_')[3]); } } else if (Item.catalogName.Equals("deal_vip_1_year_and_badge")) { Days = 31 * 12; } else if (Item.catalogName.Equals("HABBO_CLUB_VIP_5_YEAR")) { Days = 31 * 5 * 12; } if (Item.creditCost > 0) { Session.GetHabbo().Credits -= total_cost_credits; Session.GetHabboDataContainer().UpdateCreditsBalance(); } if (Item.pixelCost > 0 || Item.diamondCost > 0) { Session.GetHabbo().Diamonds -= total_cost_diamonds; Session.GetHabbo().ActivityPoints -= total_cost_pixels; Session.GetHabboDataContainer().UpdateActivityPointsBalance(); Session.GetHabboDataContainer().StoreDiamondsNow(); } Session.GetHabboDataContainer().GetSubscriptionManager().AddOrExtendSubscription(Days * 24 * 3600, SubscriptionManager.SUBSCRIPTION_TYPE_VIP); //Session.GetHabboDataContainer().SerializeClub(); Session.GetMessageHandler().GetSubscriptionData(); ServerMessage ok = PacketHandelingManager.GetRecycledItem(OutputCode.PurchaseOKMessageEvent); ok.AddInt32((int)Item.GetBaseItem().ItemId); ok.AddString(Item.GetBaseItem().Name); ok.AddBoolean(false); ok.AddInt32(total_cost_credits); ok.AddInt32(Item.pixelCost); ok.AddInt32(0); ok.AddBoolean(true); ok.AddInt32(1); ok.AddString(Item.GetBaseItem().Type.ToString().ToLower()); ok.AddInt32(Item.GetBaseItem().SpriteId); ok.AddString(string.Empty); ok.AddInt32(1); ok.AddInt32(0); ok.AddString(string.Empty); ok.AddInt32(1); Session.SendMessage(ok); Session.GetHabboDataContainer().SerializeClub(); return; } switch (Item.GetBaseItem().InteractionType) { case InteractionType.groupClickable: case InteractionType.groupGate: case InteractionType.none: if (Item.GetBaseItem().IsGroupItem) { uint groupID = TextHandling.ParseUInt32(ExtraData); GroupData group = ButterflyEnvironment.GetGame().GetGroupManager().GetGroup(groupID); if (group == null || !group.IsMember(Session.GetHabbo().Id)) ExtraData = string.Empty; } else { ExtraData = ""; } break; case InteractionType.musicdisc: ExtraData = Item.songID.ToString(); break; #region Pet handling case InteractionType.pet0: case InteractionType.pet1: case InteractionType.pet2: case InteractionType.pet3: case InteractionType.pet4: case InteractionType.pet5: case InteractionType.pet6: case InteractionType.pet7: case InteractionType.pet8: case InteractionType.pet9: case InteractionType.pet10: case InteractionType.pet11: case InteractionType.pet12: case InteractionType.pet14: case InteractionType.pet15: case InteractionType.pet16: case InteractionType.pet17: case InteractionType.pet18: case InteractionType.pet19: case InteractionType.pet20: case InteractionType.pet21: case InteractionType.pet22: try { //uint count = 0; //using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) //{ // dbClient.setQuery("SELECT COUNT(*) FROM user_pets WHERE user_id = " + Session.GetHabbo().Id); // count = uint.Parse(dbClient.getString()); //} //if (count > 5) //{ // Session.SendNotif(LanguageLocale.GetValue("catalog.pets.maxpets")); // return; //} string[] Bits = ExtraData.Split('\n'); string PetName = Bits[0]; string Race = Bits[1]; string Color = Bits[2]; int.Parse(Race); // to trigger any possible errors if (!CheckPetName(PetName)) return; if (Race.Length != 1 && Race.Length != 2) return; if (Color.Length != 6) return; ButterflyEnvironment.GetGame().GetAchievementManager().ProgressUserAchievement(Session, "ACH_PetLover", 1); } catch (Exception e) { //Logging.WriteLine(e.ToString()); Logging.HandleException(e, "Catalog.HandlePurchase"); return; } break; #endregion case InteractionType.roomeffect: Double Number = 0; try { if (string.IsNullOrEmpty(ExtraData)) Number = 0; else Number = Double.Parse(ExtraData, ButterflyEnvironment.cultureInfo); } catch (Exception e) { Logging.HandleException(e, "Catalog.HandlePurchase: " + ExtraData); } ExtraData = Number.ToString().Replace(',', '.'); break; case InteractionType.postit: ExtraData = "FFFF33"; break; case InteractionType.dimmer: ExtraData = "1,1,1,#000000,255"; break; case InteractionType.trophy: ExtraData = Session.GetHabbo().Username + Convert.ToChar(9) + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + Convert.ToChar(9) + ButterflyEnvironment.FilterInjectionChars(ExtraData, true); break; case InteractionType.bot: ExtraData = Item.specialText; break; case InteractionType.badge_display: ExtraData = ExtraData + (char)9 + Session.GetHabbo().Username + (char)9 + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year; break; case InteractionType.mannequin: ExtraData = "m" + Convert.ToChar(5) + "" + Convert.ToChar(5) + "Leet Hotel"; break; default: ExtraData = ""; break; } if (Item.creditCost > 0) { Session.GetHabbo().Credits -= total_cost_credits; Session.GetHabboDataContainer().UpdateCreditsBalance(); } if (Item.pixelCost > 0 || Item.diamondCost > 0) { Session.GetHabbo().Diamonds -= total_cost_diamonds; Session.GetHabbo().ActivityPoints -= total_cost_pixels; Session.GetHabboDataContainer().UpdateActivityPointsBalance(); Session.GetHabboDataContainer().StoreDiamondsNow(); } ServerMessage resp = PacketHandelingManager.GetRecycledItem(OutputCode.FurniListUpdateEvent); Session.SendMessage(resp); resp = PacketHandelingManager.GetRecycledItem(OutputCode.PurchaseOKMessageEvent); resp.AddInt32((int)Item.GetBaseItem().ItemId); resp.AddString(Item.GetBaseItem().Name); resp.AddBoolean(false); resp.AddInt32(total_cost_credits); resp.AddInt32(total_cost_pixels); resp.AddInt32(0); resp.AddBoolean(true); resp.AddInt32(1); resp.AddString(Item.GetBaseItem().Type.ToString().ToLower()); resp.AddInt32(Item.GetBaseItem().SpriteId); resp.AddString(""); resp.AddInt32(1); resp.AddInt32(0); resp.AddString(""); resp.AddInt32(1); Session.SendMessage(resp); if (IsGift) { uint itemID; Item Present = GetPresent(giftData.spriteID); if (Present == null) return; ExtraData = giftData.SerializeExtraData(Session.GetHabbo().Id); using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO items (base_id) VALUES (" + Present.ItemId + ")"); itemID = (uint)dbClient.insertQuery(); dbClient.runFastQuery("INSERT INTO items_users VALUES (" + itemID + "," + GiftUserId + ")"); dbClient.setQuery("INSERT INTO items_extradata (item_id, data) VALUES (@id,@data)"); dbClient.addParameter("id", itemID); dbClient.addParameter("data", ExtraData); dbClient.runQuery(); dbClient.setQuery("INSERT INTO user_presents (item_id,base_id,amount) VALUES " + "(" + itemID + "," + Item.GetBaseItem().ItemId + "," + Item.amount + ")"); dbClient.runQuery(); } GameClient Receiver = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUserID(GiftUserId); if (Receiver != null) { Receiver.GetHabboDataContainer().GetInventoryComponent().AddNewItem(itemID, Present.ItemId, ExtraData, false, false, 0); Receiver.GetHabboDataContainer().GetInventoryComponent().SendFloorInventoryUpdate(); InventoryComponent targetInventory = Receiver.GetHabboDataContainer().GetInventoryComponent(); if (targetInventory != null) targetInventory.RunDBUpdate(); } } else { DeliverItems(Session, Item.GetBaseItem(), Item.amount * amount, ExtraData, Item.songID); } }