internal void SendNewTicket(GameClient Session, int Category, uint ReportedUser, String Message) { if (Session.GetHabbo().CurrentRoomId <= 0) { return; } RoomData Data = FirewindEnvironment.GetGame().GetRoomManager().GenerateNullableRoomData(Session.GetHabbo().CurrentRoomId); uint TicketId = 0; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO moderation_tickets (score,type,status,sender_id,reported_id,moderator_id,message,room_id,room_name,timestamp) VALUES (1,'" + Category + "','open','" + Session.GetHabbo().Id + "','" + ReportedUser + "','0',@message,'" + Data.Id + "',@name,'" + FirewindEnvironment.GetUnixTimestamp() + "')"); dbClient.addParameter("message", Message); dbClient.addParameter("name", Data.Name); TicketId = (uint)dbClient.insertQuery(); dbClient.runFastQuery("UPDATE user_info SET cfhs = cfhs + 1 WHERE user_id = " + Session.GetHabbo().Id + ""); //dbClient.setQuery("SELECT id FROM moderation_tickets WHERE sender_id = " + Session.GetHabbo().Id + " ORDER BY id DESC LIMIT 1"); //TicketId = (uint)dbClient.getRow()[0]; } SupportTicket Ticket = new SupportTicket(TicketId, 1, Category, Session.GetHabbo().Id, ReportedUser, Message, Data.Id, Data.Name, FirewindEnvironment.GetUnixTimestamp()); Tickets.Add(Ticket); SendTicketToModerators(Ticket); }
internal RoomData CreateRoom(GameClient Session, string Name, string Desc, string Model, int Category, int MaxVisitors, int TradeState) { if (!this.roomModels.Contains(Model)) { Session.SendNotif("I can't create your room with that model!"); return(null); } uint RoomId = 0; using (IQueryAdapter dbClient = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { dbClient.setQuery("INSERT INTO rooms (roomtype,caption,description,owner,model_name,category,users_max,trade_state) VALUES ('private',@caption,@desc,@username,@model,@cat,@usmax,@tstate)"); dbClient.addParameter("caption", Name); dbClient.addParameter("desc", Desc); dbClient.addParameter("username", Session.GetHabbo().Username); dbClient.addParameter("model", Model); dbClient.addParameter("cat", Category); dbClient.addParameter("usmax", MaxVisitors); dbClient.addParameter("tstate", TradeState.ToString()); RoomId = (uint)dbClient.insertQuery(); } RoomData Data = this.GenerateRoomData(RoomId); Session.GetHabbo().UsersRooms.Add(Data); return(Data); }
internal void RecycleItem() { if (!Session.GetHabbo().InRoom) { return; } int ItemsCount = Request.PopWiredInt32(); // 5 for (int i = 0; i < ItemsCount; i++) { uint ItemId = Request.PopWiredUInt(); if (!Session.GetHabbo().GetInventoryComponent().ContainsItem(ItemId)) { return; } Session.GetHabbo().GetInventoryComponent().RemoveItem(ItemId, true); } uint newItemId; EcotronReward Reward = OtanixEnvironment.GetGame().GetCatalog().GetRandomEcotronReward(); if (Reward == null) { return; } using (IQueryAdapter dbClient = OtanixEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO items (base_id) VALUES (" + EmuSettings.FURNIMATIC_BOX_ITEMID + ")"); newItemId = (uint)dbClient.insertQuery(); dbClient.runFastQuery("INSERT INTO items_users VALUES (" + newItemId + "," + Session.GetHabbo().Id + ")"); dbClient.setQuery("INSERT INTO items_extradata VALUES (" + newItemId + ",@data)"); dbClient.addParameter("data", DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day); dbClient.runQuery(); dbClient.runFastQuery("INSERT INTO user_presents (item_id,base_id,amount,extra_data) VALUES (" + newItemId + "," + Reward.BaseId + ",1,'')"); } UserItem u = Session.GetHabbo().GetInventoryComponent().AddNewItem(newItemId, (uint)EmuSettings.FURNIMATIC_BOX_ITEMID, DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day, false, false, false, Reward.GetBaseItem().Name, Session.GetHabbo().Id, 0); Session.GetMessageHandler().GetResponse().Init(Outgoing.SendPurchaseAlert); Session.GetMessageHandler().GetResponse().AppendInt32(1); // items Session.GetMessageHandler().GetResponse().AppendInt32(1); // type (gift) == s Session.GetMessageHandler().GetResponse().AppendInt32(1); Session.GetMessageHandler().GetResponse().AppendUInt(u.Id); Session.GetMessageHandler().SendResponse(); Session.GetHabbo().GetInventoryComponent().UpdateItems(false); Response.Init(Outgoing.FurniMaticReceiveItem); Response.AppendInt32(1); Response.AppendUInt(newItemId); SendResponse(); }
internal void SendNewTicket(GameClient Session, int Category, uint ReportedUser, string Message, int type, List <string> Messages) { UInt32 Id = 0; if (Session.GetHabbo().CurrentRoomId <= 0) { using (IQueryAdapter DBClient = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { DBClient.setQuery(string.Concat(new object[] { "INSERT INTO moderation_tickets (score,type,status,sender_id,reported_id,moderator_id,message,room_id,room_name,timestamp) VALUES (1,'", Category, "','open','", Session.GetHabbo().Id, "','", ReportedUser, "','0',@message,'0','','", CyberEnvironment.GetUnixTimestamp(), "')" })); DBClient.addParameter("message", Message); Id = (uint)DBClient.insertQuery(); DBClient.runFastQuery("UPDATE user_info SET cfhs = cfhs + 1 WHERE user_id = " + Session.GetHabbo().Id); } SupportTicket Ticket = new SupportTicket(Id, 1, type, Session.GetHabbo().Id, ReportedUser, Message, 0u, "", (double)CyberEnvironment.GetUnixTimestamp(), Messages); this.Tickets.Add(Ticket); ModerationTool.SendTicketToModerators(Ticket); return; } RoomData Data = CyberEnvironment.GetGame().GetRoomManager().GenerateNullableRoomData(Session.GetHabbo().CurrentRoomId); using (IQueryAdapter DBClient = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { DBClient.setQuery(string.Concat(new object[] { "INSERT INTO moderation_tickets (score,type,status,sender_id,reported_id,moderator_id,message,room_id,room_name,timestamp) VALUES (1,'", Category, "','open','", Session.GetHabbo().Id, "','", ReportedUser, "','0',@message,'", Data.Id, "',@name,'", CyberEnvironment.GetUnixTimestamp(), "')" })); DBClient.addParameter("message", Message); DBClient.addParameter("name", Data.Name); Id = (uint)DBClient.insertQuery(); DBClient.runFastQuery("UPDATE user_info SET cfhs = cfhs + 1 WHERE user_id = " + Session.GetHabbo().Id); } SupportTicket Ticket2 = new SupportTicket(Id, 1, type, Session.GetHabbo().Id, ReportedUser, Message, 0u, "", (double)CyberEnvironment.GetUnixTimestamp(), Messages); this.Tickets.Add(Ticket2); ModerationTool.SendTicketToModerators(Ticket2); }
internal void CreateGroup(string Name, string Desc, uint RoomId, string Badge, GameClient Session, int Colour1, int Colour2, out Guild Group) { using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor.setQuery(string.Concat(new object[] { "INSERT INTO groups (`name`, `desc`,`badge`,`owner_id`,`created`,`room_id`,`colour1`,`colour2`) VALUES(@name, @desc, @badge, ", Session.GetHabbo().Id, ", UNIX_TIMESTAMP(), ", RoomId, ",'", Colour1, "','", Colour2, "')" })); queryreactor.addParameter("name", Name); queryreactor.addParameter("desc", Desc); queryreactor.addParameter("badge", Badge); uint num = checked ((uint)queryreactor.insertQuery()); queryreactor.runFastQuery(string.Concat(new object[] { "UPDATE rooms SET group_id=", num, " WHERE id=", RoomId, " LIMIT 1" })); Dictionary <uint, GroupUser> dictionary = new Dictionary <uint, GroupUser>(); dictionary.Add(Session.GetHabbo().Id, new GroupUser(Session.GetHabbo().Id, num, 2)); this.Groups.Add(num, new Guild(num, Name, Desc, RoomId, Badge, CyberEnvironment.GetUnixTimestamp(), Session.GetHabbo().Id, Colour1, Colour2, dictionary, new List <uint>(), new Dictionary <uint, GroupUser>(), 0u, 1u, false, Name, Desc, 0, 0.0, 0, "", 0)); queryreactor.runFastQuery(string.Concat(new object[] { "INSERT INTO group_memberships (group_id, user_id, rank) VALUES (", num, ", ", Session.GetHabbo().Id, ", '2')" })); Group = this.GetGroup(num); GroupUser User = new GroupUser(Session.GetHabbo().Id, num, 2); Session.GetHabbo().UserGroups.Add(User); Group.Admins.Add(Session.GetHabbo().Id, User); queryreactor.runFastQuery(string.Concat(new object[] { "UPDATE user_stats SET favourite_group=", num, " WHERE id= ", Session.GetHabbo().Id, " LIMIT 1" })); queryreactor.runFastQuery("DELETE FROM room_rights WHERE room_id=" + RoomId); } }
internal RoomData CreateRoom(GameClient Session, string Name, string Model) { Name = PiciEnvironment.FilterInjectionChars(Name); if (!roomModels.ContainsKey(Model)) { Session.SendNotif(LanguageLocale.GetValue("room.modelmissing")); return(null); } Console.WriteLine("ClubOnly: " + ((RoomModel)roomModels[Model]).ClubOnly + ""); if (((RoomModel)roomModels[Model]).ClubOnly == 1 && !Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_vip")) { Session.SendNotif(LanguageLocale.GetValue("room.missingclub")); return(null); } if (Name.Length < 3) { Session.SendNotif(LanguageLocale.GetValue("room.namelengthshort")); return(null); } UInt32 RoomId = 0; using (IQueryAdapter dbClient = PiciEnvironment.GetDatabaseManager().getQueryreactor()) { if (dbClient.dbType == DatabaseType.MSSQL)//description,public_ccts,tags,password { dbClient.setQuery("INSERT INTO rooms (roomtype,caption,owner,model_name,description,public_ccts,tags,password) OUTPUT INSERTED.* VALUES ('private',@caption,@username,@model,'','','','')"); } else { dbClient.setQuery("INSERT INTO rooms (roomtype,caption,owner,model_name) VALUES ('private',@caption,@username,@model)"); } dbClient.addParameter("caption", Name); dbClient.addParameter("model", Model); dbClient.addParameter("username", Session.GetHabbo().Username); RoomId = (UInt32)dbClient.insertQuery(); } RoomData newRoomData = GenerateRoomData(RoomId); Session.GetHabbo().UsersRooms.Add(newRoomData); return(newRoomData); }
public Group CreateGroup(GameClient creator, string name, string description, int roomID, int color1, int color2, List <Tuple <int, int, int> > badgeData) { // We call this method after doing all checks. int groupID; //string badgeCode = Group.GenerateBadgeImage(badgeData); string createTime = DateTime.Now.ToString("d-M-yyyy"); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { // Insert the group dbClient.setQuery("INSERT INTO groups(name,description,badge_data,users_id,rooms_id,color1,color2,date_created) VALUES(@name,@desc,@badge,@ownerid,@roomid,@color1,@color2,@date)"); dbClient.addParameter("name", name); dbClient.addParameter("desc", description); dbClient.addParameter("ownerid", creator.GetHabbo().Id); dbClient.addParameter("roomid", roomID); dbClient.addParameter("color1", color1); dbClient.addParameter("color2", color2); dbClient.addParameter("badge", Group.ConvertBadgeForDatabase(badgeData)); dbClient.addParameter("date", createTime); groupID = (int)dbClient.insertQuery(); // Create membership for owner dbClient.setQuery("INSERT INTO group_memberships VALUES(@id,@groupid,3,1)"); dbClient.addParameter("id", creator.GetHabbo().Id); dbClient.addParameter("groupid", groupID); dbClient.runQuery(); // Update room dbClient.runFastQuery("UPDATE rooms SET groups_id = " + groupID + " WHERE id = " + roomID); } Group group = new Group() { ID = groupID, Name = name, Description = description, RoomID = roomID, ColorID1 = color1, ColorID2 = color2, BadgeData = badgeData, DateCreated = createTime }; group.Members.Add(creator.GetHabbo().Id); string s = group.BadgeCode; return(group); }
internal static Pet CreatePet(int UserId, string Name, int Type, string Race, string Color) { Pet pet = new Pet(404, UserId, 0, Name, (uint)Type, Race, Color, 0, 100, 100, 0, FirewindEnvironment.GetUnixTimestamp(), 0, 0, 0.0, false); pet.DBState = DatabaseUpdateState.NeedsUpdate; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO user_pets (user_id,name,type,race,color,expirience,energy,createstamp) VALUES (" + pet.OwnerId + ",@" + pet.PetId + "name," + pet.Type + ",@" + pet.PetId + "race,@" + pet.PetId + "color,0,100,'" + pet.CreationStamp + "')"); dbClient.addParameter(pet.PetId + "name", pet.Name); dbClient.addParameter(pet.PetId + "race", pet.Race); dbClient.addParameter(pet.PetId + "color", pet.Color); pet.PetId = (uint)dbClient.insertQuery(); } return(pet); }
internal RoomData CreateRoom(GameClient Session, string Name, string Model) { Name = FirewindEnvironment.FilterInjectionChars(Name); if (!roomModels.ContainsKey(Model)) { Session.SendNotif(LanguageLocale.GetValue("room.modelmissing")); return(null); } if (((RoomModel)roomModels[Model]).ClubOnly && !Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_vip")) { Session.SendNotif(LanguageLocale.GetValue("room.missingclub")); return(null); } if (Name.Length < 3) { Session.SendNotif(LanguageLocale.GetValue("room.namelengthshort")); return(null); } UInt32 RoomId = 0; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("INSERT INTO rooms (caption,owner,model_name) VALUES (@caption,@username,@model)"); dbClient.addParameter("caption", Name); dbClient.addParameter("model", Model); dbClient.addParameter("username", Session.GetHabbo().Username); RoomId = (UInt32)dbClient.insertQuery(); } RoomData newRoomData = GenerateRoomData(RoomId); Session.GetHabbo().UsersRooms.Add(newRoomData); return(newRoomData); }
internal static Pet CreatePet(uint UserId, string Name, int Type, string Race, string Color) { Pet pet = new Pet(404, UserId, 0, Name, (uint)Type, Race, Color, 0, 100, 100, 0, ButterflyEnvironment.GetUnixTimestamp(), 0, 0, 0.0); pet.DBState = DatabaseUpdateState.NeedsUpdate; using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { if (dbClient.dbType == Database_Manager.Database.DatabaseType.MSSQL) { dbClient.setQuery("INSERT INTO user_pets (user_id,name,type,race,color,expirience,energy,createstamp,nutrition,respect,x,y,z) OUTPUT INSERTED.* VALUES (" + pet.OwnerId + ",@" + pet.PetId + "name," + pet.Type + ",@" + pet.PetId + "race,@" + pet.PetId + "color,0,100,'" + pet.CreationStamp + "',0,0,0,0,0)"); } else { dbClient.setQuery("INSERT INTO user_pets (user_id,name,type,race,color,expirience,energy,createstamp) VALUES (" + pet.OwnerId + ",@" + pet.PetId + "name," + pet.Type + ",@" + pet.PetId + "race,@" + pet.PetId + "color,0,100,'" + pet.CreationStamp + "')"); } dbClient.addParameter(pet.PetId + "name", pet.Name); dbClient.addParameter(pet.PetId + "race", pet.Race); dbClient.addParameter(pet.PetId + "color", pet.Color); pet.PetId = (uint)dbClient.insertQuery(); } return(pet); }
public Group CreateGroup(GameClient creator, string name, string description, int roomID, int color1, int color2, List <Tuple <int, int, int> > badgeData) { // We call this method after doing all checks. int groupID; string badgeCode = Group.GenerateBadgeImage(badgeData); string createTime = DateTime.Now.ToString("d-M-yyyy"); using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { // Insert the group dbClient.setQuery("INSERT INTO guild(name,description,badge,users_id,rooms_id,color1,color2,date_created) VALUES(@name,@desc,@badge,@ownerid,@roomid,@color1,@color2,@date)"); dbClient.addParameter("name", name); dbClient.addParameter("desc", description); dbClient.addParameter("ownerid", creator.GetHabbo().Id); dbClient.addParameter("roomid", roomID); dbClient.addParameter("color1", color1); dbClient.addParameter("color2", color2); dbClient.addParameter("badge", badgeCode); dbClient.addParameter("date", createTime); groupID = (int)dbClient.insertQuery(); } Group group = new Group() { ID = groupID, Name = name, Description = description, RoomID = roomID, ColorID1 = color1, ColorID2 = color2, BadgeCode = badgeCode, DateCreated = createTime, }; return(group); }
internal void HandlePurchase(GameClient Session, int PageId, uint ItemId, string extraParameter, int buyAmount, Boolean IsGift, string GiftUser, string GiftMessage, int GiftSpriteId, int GiftLazo, int GiftColor, bool giftShowIdentity) { int finalAmount = buyAmount; if (buyAmount > 5) // Possible discount! { // Nearest number that increases the amount of free items int nearestDiscount = ((int)Math.Floor(buyAmount / 6.0) * 6); // How many free ones we get int freeItemsCount = (nearestDiscount - 3) / 3; // Add 1 free if more than 42 if (buyAmount >= 42) { freeItemsCount++; } // Doesn't follow rules as it isn't dividable by 6, but still increases free items if (buyAmount >= 99) { freeItemsCount = 33; } // This is how many we pay for in the end finalAmount = buyAmount - freeItemsCount; } //Logging.WriteLine("Amount: " + priceAmount + "; withOffer= " + finalAmount); CatalogPage Page; if (!Pages.TryGetValue(PageId, out Page)) { return; } if (Page == null || !Page.Enabled || !Page.Visible || Session == null || Session.GetHabbo() == null) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } if (Page.ClubOnly && !Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_club") && !Session.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_vip")) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } if (Page.MinRank > Session.GetHabbo().Rank) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } CatalogItem Item = Page.GetItem(ItemId); if (Item == null) // TODO: Check item minimum club rank { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } if (!Item.HaveOffer && buyAmount > 1) // Check if somebody is bulk-buying when not allowed { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } if (Item.IsLimited && Item.LimitedStack <= Item.LimitedSelled) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } int GiftUserId = 0; //int giftWrappingCost = 0; if (IsGift) { if (!Item.AllowGift) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } if (Item.Items.Count > 1 || Item.Amount > 1) // Gifts can only have 1 item? { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } DataRow dRow; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT id FROM users WHERE username = @gift_user"); dbClient.addParameter("gift_user", GiftUser); dRow = dbClient.getRow(); } if (dRow == null) { Session.GetMessageHandler().GetResponse().Init(Outgoing.GiftError); Session.GetMessageHandler().GetResponse().AppendString(GiftUser); Session.GetMessageHandler().SendResponse(); return; } GiftUserId = Convert.ToInt32(dRow[0]); if (GiftUserId == 0) { Session.GetMessageHandler().GetResponse().Init(Outgoing.GiftError); Session.GetMessageHandler().GetResponse().AppendString(GiftUser); Session.GetMessageHandler().SendResponse(); return; } } Boolean CreditsError = false; Boolean PixelError = false; Boolean CrystalError = false; if (Session.GetHabbo().Credits < (Item.CreditsCost * finalAmount)) { CreditsError = true; } if (Session.GetHabbo().VipPoints < (Item.CrystalCost * finalAmount)) { CrystalError = true; } if (Session.GetHabbo().ActivityPoints < (Item.PixelsCost * finalAmount)) { PixelError = true; } if (CreditsError || PixelError) { ServerMessage message = new ServerMessage(Outgoing.NotEnoughBalance); message.AppendBoolean(CreditsError); message.AppendBoolean(PixelError); Session.SendMessage(message); return; } if (Item.CrystalCost > 0) { int cost = Item.CrystalCost * finalAmount; if (Session.GetHabbo().VipPoints < cost) { Session.SendNotif("You can't afford that item!"); Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } Session.GetHabbo().VipPoints -= cost; Session.GetHabbo().UpdateActivityPointsBalance(true); using (IQueryAdapter adapter = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { adapter.runFastQuery("UPDATE users SET vip_points = " + Session.GetHabbo().VipPoints + " WHERE id = " + Session.GetHabbo().Id); } } if (Item.CreditsCost > 0 && !IsGift) { Session.GetHabbo().Credits -= (Item.CreditsCost * finalAmount); Session.GetHabbo().UpdateCreditsBalance(); } if (Item.PixelsCost > 0 && !IsGift) { Session.GetHabbo().ActivityPoints -= (Item.PixelsCost * finalAmount); Session.GetHabbo().UpdateActivityPointsBalance(true); } // Item is purchased, now do post-proccessing if (Item.IsLimited) { Item.LimitedSelled++; using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE catalog_items SET limited_sells = " + Item.LimitedSelled + " WHERE id = " + Item.Id); } Page.InitMsg(); // update page! // send update Session.SendMessage(Page.GetMessage); } foreach (uint i in Item.Items) { //Logging.WriteLine(Item.GetBaseItem().ItemId); //Logging.WriteLine(Item.GetBaseItem().InteractionType.ToLower()); // Extra Data is _NOT_ filtered at this point and MUST BE VERIFIED BELOW: if (Item.GetBaseItem(i).Type == 'h') // Subscription { int Months = 0; int Days = 0; if (Item.Name.Contains("HABBO_CLUB_VIP_")) { if (Item.Name.Contains("_DAY")) { Days = int.Parse(Item.Name.Split('_')[3]); } else if (Item.Name.Contains("_MONTH")) { Months = int.Parse(Item.Name.Split('_')[3]); Days = 31 * Months; } } else if (Item.Name.Equals("deal_vip_1_year_and_badge")) { Months = 12; Days = 31 * Months; } else if (Item.Name.Equals("HABBO_CLUB_VIP_5_YEAR")) { Months = 5 * 12; Days = 31 * Months; } else if (Item.Name.StartsWith("DEAL_HC_")) { Months = int.Parse(Item.Name.Split('_')[2]); Days = 31 * Months; Session.GetHabbo().GetSubscriptionManager().AddOrExtendSubscription("habbo_club", Days * 24 * 3600); Session.GetHabbo().SerializeClub(); return; } Session.GetHabbo().GetSubscriptionManager().AddOrExtendSubscription("habbo_vip", Days * 24 * 3600); Session.GetHabbo().SerializeClub(); return; } if (IsGift && Item.GetBaseItem(i).Type == 'e') { Session.SendNotif(LanguageLocale.GetValue("catalog.gift.send.error")); return; } IRoomItemData itemData = new StringData(extraParameter); switch (Item.GetBaseItem(i).InteractionType) { case InteractionType.none: //itemData = new StringData(extraParameter); break; case InteractionType.musicdisc: itemData = new StringData(Item.songID.ToString()); break; #region Pet handling case InteractionType.pet: try { string[] Bits = extraParameter.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)) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } //if (Race.Length != 1) // return; if (Color.Length != 6) { Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } } catch (Exception e) { Logging.WriteLine(e.ToString()); Logging.HandleException(e, "Catalog.HandlePurchase"); Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } break; #endregion case InteractionType.roomeffect: Double Number = 0; try { if (string.IsNullOrEmpty(extraParameter)) { Number = 0; } else { Number = Double.Parse(extraParameter, FirewindEnvironment.cultureInfo); } } catch (Exception e) { Logging.HandleException(e, "Catalog.HandlePurchase: " + extraParameter); } itemData = new StringData(Number.ToString().Replace(',', '.')); break; // maintain extra data // todo: validate case InteractionType.postit: itemData = new StringData("FFFF33"); break; case InteractionType.dimmer: itemData = new StringData("1,1,1,#000000,255"); break; case InteractionType.trophy: itemData = new StringData(String.Format("{0}\t{1}\t{2}", Session.GetHabbo().Username, DateTime.Now.ToString("d-M-yyy"), extraParameter)); break; //case InteractionType.mannequin: // MapStuffData data = new MapStuffData(); // data.Data.Add("OUTFIT_NAME", ""); // data.Data.Add("FIGURE", ""); // data.Data.Add("GENDER", ""); // itemData = data; // break; default: //itemData = new StringData(extraParameter); break; } //Session.GetMessageHandler().GetResponse().Init(Outgoing.UpdateInventory); //Session.GetMessageHandler().SendResponse(); Session.GetMessageHandler().GetResponse().Init(Outgoing.PurchaseOK); // PurchaseOKMessageEvent Item.Serialize(Session.GetMessageHandler().GetResponse()); Session.GetMessageHandler().SendResponse(); if (IsGift) { uint itemID; //uint GenId = GenerateItemId(); Item Present = FirewindEnvironment.GetGame().GetItemManager().GetItemBySpriteID(GiftSpriteId); if (Present == null) { Logging.LogDebug(string.Format("Somebody tried to purchase a present with invalid sprite ID: {0}", GiftSpriteId)); Session.SendMessage(new ServerMessage(Outgoing.PurchaseError)); return; } MapStuffData giftData = new MapStuffData(); if (giftShowIdentity) { giftData.Data.Add("PURCHASER_NAME", Session.GetHabbo().Username); giftData.Data.Add("PURCHASER_FIGURE", Session.GetHabbo().Look); } giftData.Data.Add("MESSAGE", GiftMessage); giftData.Data.Add("PRODUCT_CODE", "10"); giftData.Data.Add("EXTRA_PARAM", "test"); giftData.Data.Add("state", "1"); using (IQueryAdapter dbClient = FirewindEnvironment.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 + ")"); if (!string.IsNullOrEmpty(GiftMessage)) { dbClient.setQuery("INSERT INTO items_extradata VALUES (" + itemID + ",@datatype,@data,@extra)"); dbClient.addParameter("datatype", giftData.GetTypeID()); dbClient.addParameter("data", giftData.ToString()); dbClient.addParameter("extra", GiftColor * 1000 + GiftLazo); dbClient.runQuery(); } dbClient.setQuery("INSERT INTO user_presents (item_id,base_id,amount,extra_data) VALUES (" + itemID + "," + Item.GetBaseItem(i).ItemId + "," + Item.Amount + ",@extra_data)"); dbClient.addParameter("extra_data", itemData.ToString()); dbClient.runQuery(); } GameClient Receiver = FirewindEnvironment.GetGame().GetClientManager().GetClientByUserID(GiftUserId); if (Receiver != null) { Receiver.SendNotif(LanguageLocale.GetValue("catalog.gift.received") + Session.GetHabbo().Username); UserItem u = Receiver.GetHabbo().GetInventoryComponent().AddNewItem(itemID, Present.ItemId, giftData, GiftColor * 1000 + GiftLazo, false, false, 0); Receiver.GetHabbo().GetInventoryComponent().SendFloorInventoryUpdate(); Receiver.GetMessageHandler().GetResponse().Init(Outgoing.UnseenItems); Receiver.GetMessageHandler().GetResponse().AppendInt32(1); // items Receiver.GetMessageHandler().GetResponse().AppendInt32(1); // type (gift) == s Receiver.GetMessageHandler().GetResponse().AppendInt32(1); Receiver.GetMessageHandler().GetResponse().AppendUInt(u.Id); Receiver.GetMessageHandler().SendResponse(); InventoryComponent targetInventory = Receiver.GetHabbo().GetInventoryComponent(); if (targetInventory != null) { targetInventory.RunDBUpdate(); } } Session.SendNotif(LanguageLocale.GetValue("catalog.gift.sent")); } else { List <UserItem> items = DeliverItems(Session, Item.GetBaseItem(i), (buyAmount * Item.Amount), itemData.ToString(), Item.songID); int Type = 2; if (Item.GetBaseItem(i).Type.ToString().ToLower().Equals("s")) { if (Item.GetBaseItem(i).InteractionType == InteractionType.pet) { Type = 3; } else { Type = 1; } } Session.GetMessageHandler().GetResponse().Init(Outgoing.UnseenItems); Session.GetMessageHandler().GetResponse().AppendInt32(1); // items Session.GetMessageHandler().GetResponse().AppendInt32(Type); Session.GetMessageHandler().GetResponse().AppendInt32(items.Count); foreach (UserItem u in items) { Session.GetMessageHandler().GetResponse().AppendUInt(u.Id); } Session.GetMessageHandler().SendResponse(); //Logging.WriteLine("Purchased " + items.Count); Session.GetHabbo().GetInventoryComponent().UpdateItems(false); if (Item.GetBaseItem(i).InteractionType == InteractionType.pet) { Session.SendMessage(Session.GetHabbo().GetInventoryComponent().SerializePetInventory()); } } } }
internal void HandlePurchase(GameClient Session, int PageId, uint ItemId, string ExtraData, Boolean IsGift, string GiftUser, string GiftMessage) { 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.GetHabbo().GetSubscriptionManager().HasSubscription("habbo_club")) { return; } if (Session.GetHabbo().Rank != Page.MinRank) // Workaround { if (Session.GetHabbo().Rank < Page.MinRank) { return; } } CatalogItem Item = Page.GetItem(ItemId); if (Item == null) { return; } uint GiftUserId = 0; 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", GiftUser); dRow = dbClient.getRow(); } if (dRow == null) { Session.GetMessageHandler().GetResponse().Init(76); Session.GetMessageHandler().GetResponse().AppendBoolean(true); Session.GetMessageHandler().GetResponse().AppendStringWithBreak(GiftUser); Session.GetMessageHandler().SendResponse(); return; } GiftUserId = Convert.ToUInt32(dRow[0]); if (GiftUserId == 0) { Session.GetMessageHandler().GetResponse().Init(76); Session.GetMessageHandler().GetResponse().AppendBoolean(true); Session.GetMessageHandler().GetResponse().AppendStringWithBreak(GiftUser); Session.GetMessageHandler().SendResponse(); return; } } Boolean CreditsError = false; Boolean PixelError = false; if (Session.GetHabbo().Credits < Item.CreditsCost) { CreditsError = true; } if (Session.GetHabbo().ActivityPoints < Item.PixelsCost) { PixelError = true; } if (CreditsError || PixelError) { Session.GetMessageHandler().GetResponse().Init(68); Session.GetMessageHandler().GetResponse().AppendBoolean(CreditsError); Session.GetMessageHandler().GetResponse().AppendBoolean(PixelError); Session.GetMessageHandler().SendResponse(); return; } if (IsGift && Item.GetBaseItem().Type == 'e') { Session.SendNotif(LanguageLocale.GetValue("catalog.gift.send.error")); return; } if (Item.CrystalCost > 0) { int userCrystals = 0; using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT crystals FROM users WHERE id = " + Session.GetHabbo().Id); userCrystals = dbClient.getInteger(); } if (Item.CrystalCost > userCrystals) { Session.SendNotif(LanguageLocale.GetValue("catalog.crystalerror") + Item.CrystalCost); return; } userCrystals = userCrystals - Item.CrystalCost; using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE users SET crystals = " + userCrystals + " WHERE id = " + Session.GetHabbo().Id); } Session.SendNotif(LanguageLocale.GetValue("catalog.crystalsbought") + userCrystals); } if (Item.OudeCredits > 0) { int oudeCredits = 0; using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("SELECT belcredits FROM users WHERE id = " + Session.GetHabbo().Id); oudeCredits = dbClient.getInteger(); } if (Item.OudeCredits > oudeCredits) { Session.SendNotif(LanguageLocale.GetValue("catalog.oudebelcreditserror") + Item.OudeCredits); return; } oudeCredits = oudeCredits - Item.OudeCredits; using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("UPDATE users SET belcredits = " + oudeCredits + " WHERE id = " + Session.GetHabbo().Id); } Session.SendNotif(LanguageLocale.GetValue("catalog.oudebelcreditsok") + oudeCredits); } //Console.WriteLine(Item.GetBaseItem().ItemId); //Console.WriteLine(Item.GetBaseItem().InteractionType.ToLower()); // Extra Data is _NOT_ filtered at this point and MUST BE VERIFIED BELOW: switch (Item.GetBaseItem().InteractionType) { case InteractionType.none: 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: 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) { return; } if (Color.Length != 6) { return; } } 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; // maintain extra data // todo: validate 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; default: ExtraData = ""; break; } if (Item.CreditsCost > 0) { Session.GetHabbo().Credits -= Item.CreditsCost; Session.GetHabbo().UpdateCreditsBalance(); } if (Item.PixelsCost > 0) { Session.GetHabbo().ActivityPoints -= Item.PixelsCost; Session.GetHabbo().UpdateActivityPointsBalance(true); } Session.GetMessageHandler().GetResponse().Init(101); Session.GetMessageHandler().SendResponse(); Session.GetMessageHandler().GetResponse().Init(67); Session.GetMessageHandler().GetResponse().AppendUInt(Item.GetBaseItem().ItemId); Session.GetMessageHandler().GetResponse().AppendStringWithBreak(Item.GetBaseItem().Name); Session.GetMessageHandler().GetResponse().AppendInt32(Item.CreditsCost); Session.GetMessageHandler().GetResponse().AppendInt32(Item.PixelsCost); Session.GetMessageHandler().GetResponse().AppendInt32(0); Session.GetMessageHandler().GetResponse().AppendInt32(1); Session.GetMessageHandler().GetResponse().AppendStringWithBreak(Item.GetBaseItem().Type.ToString().ToLower()); Session.GetMessageHandler().GetResponse().AppendInt32(Item.GetBaseItem().SpriteId); Session.GetMessageHandler().GetResponse().AppendStringWithBreak(""); Session.GetMessageHandler().GetResponse().AppendInt32(1); Session.GetMessageHandler().GetResponse().AppendInt32(0); Session.GetMessageHandler().SendResponse(); if (IsGift) { uint itemID; //uint GenId = GenerateItemId(); Item Present = GeneratePresent(); using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { if (dbClient.dbType == Database_Manager.Database.DatabaseType.MSSQL) { dbClient.setQuery("INSERT INTO items (base_id) OUTPUT INSERTED.* VALUES (" + Present.ItemId + ")"); } else { dbClient.setQuery("INSERT INTO items (base_id) VALUES (" + Present.ItemId + ")"); } itemID = (uint)dbClient.insertQuery(); dbClient.runFastQuery("INSERT INTO items_users VALUES (" + itemID + "," + GiftUserId + ")"); if (!string.IsNullOrEmpty(GiftMessage)) { dbClient.setQuery("INSERT INTO items_extradata VALUES (" + itemID + ",@data)"); dbClient.addParameter("data", GiftMessage); dbClient.runQuery(); } dbClient.setQuery("INSERT INTO user_presents (item_id,base_id,amount,extra_data) VALUES (" + itemID + "," + Item.GetBaseItem().ItemId + "," + Item.Amount + ",@extra_data)"); dbClient.addParameter("gift_message", "!" + GiftMessage); dbClient.addParameter("extra_data", ExtraData); dbClient.runQuery(); } GameClient Receiver = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUserID(GiftUserId); if (Receiver != null) { Receiver.SendNotif(LanguageLocale.GetValue("catalog.gift.received") + Session.GetHabbo().Username); Receiver.GetHabbo().GetInventoryComponent().AddNewItem(itemID, Present.ItemId, ExtraData, false, false, 0); Receiver.GetHabbo().GetInventoryComponent().SendFloorInventoryUpdate(); InventoryComponent targetInventory = Receiver.GetHabbo().GetInventoryComponent(); if (targetInventory != null) { targetInventory.RunDBUpdate(); } } Session.SendNotif(LanguageLocale.GetValue("catalog.gift.sent")); } else { DeliverItems(Session, Item.GetBaseItem(), Item.Amount, ExtraData, Item.songID); } }
internal UserItem AddNewItem(UInt32 Id, UInt32 BaseItem, string ExtraData, bool insert, bool fromRoom, UInt32 songID = 0) { isUpdated = false; if (insert) { if (fromRoom) { using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { if (dbClient.dbType == Database_Manager.Database.DatabaseType.MSSQL) { dbClient.setQuery("DELETE FROM items_users WHERE item_id = " + Id); dbClient.setQuery("INSERT INTO items_users VALUES (" + Id + "," + UserId + ")"); } else { dbClient.runFastQuery("REPLACE INTO items_users VALUES (" + Id + "," + UserId + ")"); } //dbClient.setQuery("REPLACE INTO user_items (id, user_id,base_item,extra_data) VALUES ('" + Id + "','" + UserId + "','" + BaseItem + "',@extra_data)"); //dbClient.addParameter("extra_data", ExtraData); //dbClient.runQuery(); } Item baseItem = ButterflyEnvironment.GetGame().GetItemManager().GetItem(BaseItem); if (baseItem != null && baseItem.InteractionType == InteractionType.musicdisc) { using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.runFastQuery("DELETE FROM room_items_songs WHERE item_id = " + Id); //dbClient.runFastQuery("REPLACE INTO user_items_songs (item_id,user_id,song_id) VALUES (" + Id + "," + UserId + "," + songID + ")"); } } } else { using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor()) { if (dbClient.dbType == Database_Manager.Database.DatabaseType.MSSQL) { dbClient.setQuery("INSERT INTO items (base_id) OUTPUT INSERTED.* VALUES (" + BaseItem + ")"); } else { dbClient.setQuery("INSERT INTO items (base_id) VALUES (" + BaseItem + ")"); } Id = (uint)dbClient.insertQuery(); if (!string.IsNullOrEmpty(ExtraData)) { dbClient.setQuery("INSERT INTO items_extradata VALUES (" + Id + ",@extradata)"); dbClient.addParameter("extradata", ExtraData); dbClient.runQuery(); } dbClient.runFastQuery("INSERT INTO items_users VALUES (" + Id + "," + UserId + ")"); //dbClient.setQuery("INSERT INTO user_items (user_id,base_item,extra_data) VALUES ('" + UserId + "','" + BaseItem + "',@extra_data)"); //dbClient.addParameter("extra_data", ExtraData); //Id = (uint)dbClient.insertQuery(); } } } UserItem ItemToAdd = new UserItem(Id, BaseItem, ExtraData); if (UserHoldsItem(Id)) { RemoveItem(Id, false); } if (ItemToAdd.GetBaseItem().InteractionType == InteractionType.musicdisc) { discs.Add(ItemToAdd.Id, ItemToAdd); } if (ItemToAdd.isWallItem) { wallItems.Add(ItemToAdd.Id, ItemToAdd); } else { floorItems.Add(ItemToAdd.Id, ItemToAdd); } if (mRemovedItems.Contains(Id)) { mRemovedItems.Remove(Id); } if (!mAddedItems.ContainsKey(Id)) { mAddedItems.Add(Id, ItemToAdd); } return(ItemToAdd); //Console.WriteLine("Item added: " + BaseItem); }
internal UserItem AddNewItem(uint Id, uint BaseItem, string ExtraData, uint Group, bool insert, bool fromRoom, int limno, int limtot, string SongCode = "") { this.isUpdated = false; if (insert) { if (fromRoom) { using (IQueryAdapter queryreactor = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor.runFastQuery("UPDATE items SET room_id='0' WHERE id=" + Id + " LIMIT 1"); goto IL_1C9; } } using (IQueryAdapter queryreactor2 = CyberEnvironment.GetDatabaseManager().getQueryReactor()) { queryreactor2.setQuery(string.Concat(new object[] { "INSERT INTO items (base_item, user_id, group_id) VALUES (", BaseItem, ", ", this.UserId, ", ", Group, ")" })); Id = checked ((uint)queryreactor2.insertQuery()); this.SendNewItems(Id); if (!string.IsNullOrEmpty(ExtraData)) { queryreactor2.setQuery("UPDATE items SET extra_data=@extradata WHERE id=" + Id + " LIMIT 1"); queryreactor2.addParameter("extradata", ExtraData); queryreactor2.runQuery(); } if (limno > 0) { queryreactor2.runFastQuery(string.Concat(new object[] { "INSERT INTO items_limited VALUES (", Id, ", ", limno, ", ", limtot, ")" })); } if (!string.IsNullOrEmpty(SongCode)) { queryreactor2.setQuery("UPDATE items SET songcode=@song_code WHERE id=" + Id + " LIMIT 1"); queryreactor2.addParameter("song_code", SongCode); queryreactor2.runQuery(); } } } IL_1C9: UserItem userItem = new UserItem(Id, BaseItem, ExtraData, Group, SongCode); if (this.UserHoldsItem(Id)) { this.RemoveItem(Id, false); } if (userItem.GetBaseItem().InteractionType == InteractionType.musicdisc) { this.discs.Add(userItem.Id, userItem); } if (userItem.isWallItem) { this.wallItems.Add(userItem.Id, userItem); } else { this.floorItems.Add(userItem.Id, userItem); } if (this.mRemovedItems.Contains(Id)) { this.mRemovedItems.Remove(Id); } if (!this.mAddedItems.Contains(Id)) { this.mAddedItems.Add(Id, userItem); } return(userItem); }