Beispiel #1
0
        internal static void SellItem(GameClient Session, uint ItemId, int SellingPrice)
        {
            UserItem Item = Session.GetHabbo().GetInventoryComponent().GetItem(ItemId);

            if (Item == null || SellingPrice > 10000 || !CanSellItem(Item))
            {
                Session.GetMessageHandler().GetResponse().Init(610);
                Session.GetMessageHandler().GetResponse().AppendBoolean(false);
                Session.GetMessageHandler().GetResponse();
                Session.GetMessageHandler().SendResponse();
                return;
            }

            int Comission = CalculateComissionPrice(SellingPrice);
            int TotalPrice = SellingPrice + Comission;
            int ItemType = 1;

            if (Item.GetBaseItem().Type == 'i')
                ItemType++;

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {
                dbClient.setQuery("INSERT INTO catalog_marketplace_offers (item_id,user_id,asking_price,total_price,public_name,sprite_id,item_type,timestamp,extra_data) VALUES (" + Item.BaseItem + "," + Session.GetHabbo().Id + "," + SellingPrice + "," + TotalPrice + ",@public_name," + Item.GetBaseItem().SpriteId + "," + ItemType + "," + FirewindEnvironment.GetUnixTimestamp() + ",@extra_data)");
                dbClient.addParameter("public_name", "NEEDS REPLACMENT HERE");
                dbClient.addParameter("extra_data", Item.Data);
                dbClient.runQuery();
            }

            Session.GetHabbo().GetInventoryComponent().RemoveItem(ItemId, false);
            Session.GetHabbo().GetInventoryComponent().RunDBUpdate();

            Session.GetMessageHandler().GetResponse().Init(610);
            Session.GetMessageHandler().GetResponse().AppendBoolean(true);
            Session.GetMessageHandler().SendResponse();
        }
Beispiel #2
0
        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;
            }

            uint 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.ToUInt32(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.UpdateInventary);
                //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());
                    }

                }
            }
        }
Beispiel #3
0
        internal override bool OnTrigger(GameClient Session, RoomItem Item, int Request, bool UserHasRights)
        {
            Room Room = Session.GetHabbo().CurrentRoom;
            RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            MapStuffData data = (MapStuffData)Item.data;

            string figure = data.Data["FIGURE"];
            string gender = data.Data["GENDER"];

            // We gotta keep our skin and headgear!
            string filteredLook = "";
            string[] sp = Session.GetHabbo().Look.Split('.');
            foreach (string s in sp)
            {
                if ((s.StartsWith("hd") || s.StartsWith("ha") || s.StartsWith("he") || s.StartsWith("fa") || s.StartsWith("ea") || s.StartsWith("hr")))
                {
                    filteredLook += s + ".";
                }
            }
            filteredLook += figure;

            using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
            {

                dbClient.setQuery("UPDATE users SET gender = @gender, look = @look WHERE id = @id");
                dbClient.addParameter("id", Session.GetHabbo().Id);
                dbClient.addParameter("gender", gender);
                dbClient.addParameter("look", filteredLook);
                dbClient.runQuery();
            }

            Session.GetHabbo().Look = filteredLook;
            Session.GetHabbo().Gender = gender;

            Session.GetMessageHandler().GetResponse().Init(Outgoing.UpdateUserInformation);
            Session.GetMessageHandler().GetResponse().AppendInt32(-1);
            Session.GetMessageHandler().GetResponse().AppendStringWithBreak(Session.GetHabbo().Look);
            Session.GetMessageHandler().GetResponse().AppendStringWithBreak(Session.GetHabbo().Gender.ToLower());
            Session.GetMessageHandler().GetResponse().AppendStringWithBreak(Session.GetHabbo().Motto);
            Session.GetMessageHandler().GetResponse().AppendInt32(Session.GetHabbo().AchievementPoints);
            Session.GetMessageHandler().SendResponse();

            ServerMessage RoomUpdate = new ServerMessage(Outgoing.UpdateUserInformation);
            RoomUpdate.AppendInt32(User.VirtualId);
            RoomUpdate.AppendStringWithBreak(Session.GetHabbo().Look);
            RoomUpdate.AppendStringWithBreak(Session.GetHabbo().Gender.ToLower());
            RoomUpdate.AppendStringWithBreak(Session.GetHabbo().Motto);
            RoomUpdate.AppendInt32(Session.GetHabbo().AchievementPoints);
            Room.SendMessage(RoomUpdate);

            return true;
        }
Beispiel #4
0
        internal void RemoveUserFromRoom(GameClient Session, Boolean NotifyClient, Boolean NotifyKick)
        {
            try
            {
                if (Session == null)
                    return;

                if (Session.GetHabbo() == null)
                    return;

                Session.GetHabbo().GetAvatarEffectsInventoryComponent().OnRoomExit();

                if (NotifyClient)
                {
                    if (NotifyKick)
                    {
                        Session.GetMessageHandler().GetResponse().Init(Outgoing.GenericError);
                        Session.GetMessageHandler().GetResponse().AppendInt32(4008);
                        Session.GetMessageHandler().SendResponse();
                    }

                    Session.GetMessageHandler().GetResponse().Init(Outgoing.OutOfRoom);
                    Session.GetMessageHandler().SendResponse();
                }

                RoomUser User = GetRoomUserByHabbo(Session.GetHabbo().Id);

                if (User != null)
                {
                    if (User.team != Team.none)
                    {
                        room.GetTeamManagerForBanzai().OnUserLeave(User);
                        room.GetTeamManagerForFreeze().OnUserLeave(User);
                    }
                    if (User.isMounted == true)
                    {
                        User.isMounted = false;
                        RoomUser usuarioVinculado = GetRoomUserByVirtualId((int)User.mountID);
                        if (usuarioVinculado != null)
                        {
                            usuarioVinculado.isMounted = false;
                            usuarioVinculado.mountID = 0;

                        }
                    }

                    if (User.sentadoBol == true || User.acostadoBol == true)
                    {
                        User.sentadoBol = false;
                        User.acostadoBol = false;
                    }

                    RemoveRoomUser(User);

                    if (Session.GetHabbo() != null)
                    {
                        if (!User.IsSpectator)
                        {
                            if (User.CurrentItemEffect != ItemEffectType.None)
                            {
                                User.GetClient().GetHabbo().GetAvatarEffectsInventoryComponent().CurrentEffect = -1;
                            }
                            //UserMatrix[User.X, User.Y] = false;

                            if (Session.GetHabbo() != null)
                            {
                                if (room.HasActiveTrade(Session.GetHabbo().Id))
                                    room.TryStopTrade(Session.GetHabbo().Id);

                                if (Session.GetHabbo().Username == room.Owner)
                                {
                                    if (room.HasOngoingEvent)
                                    {
                                        ServerMessage Message = new ServerMessage(Outgoing.RoomEvent);
                                        Message.AppendStringWithBreak("-1");
                                        room.SendMessage(Message);

                                        FirewindEnvironment.GetGame().GetRoomManager().GetEventManager().QueueRemoveEvent(room.RoomData, room.Event.Category);
                                        room.Event = null;
                                    }
                                }
                                Session.GetHabbo().CurrentRoomId = 0;

                                try
                                {
                                    if (Session.GetHabbo().GetMessenger() != null)
                                        Session.GetHabbo().GetMessenger().OnStatusChanged(true);
                                }
                                catch { }
                            }

                            //DateTime Start = DateTime.Now;
                            //using (IQueryAdapter dbClient = FirewindEnvironment.GetDatabaseManager().getQueryreactor())
                            //{
                            //    //TimeSpan TimeUsed1 = DateTime.Now - Start;
                            //    //Logging.LogThreadException("Time used on sys part 2: " + TimeUsed1.Seconds + "s, " + TimeUsed1.Milliseconds + "ms", "");

                            //    //if (Session.GetHabbo() != null)
                            //    //    dbClient.runFastQuery("UPDATE user_roomvisits SET exit_timestamp = '" + FirewindEnvironment.GetUnixTimestamp() + "' WHERE room_id = '" + this.Id + "' AND user_id = '" + Id + "' ORDER BY exit_timestamp DESC LIMIT 1");
                            //    //dbClient.runFastQuery("UPDATE rooms SET users_now = " + UsersNow + " WHERE id = " + Id);
                            //    //dbClient.runFastQuery("REPLACE INTO room_active VALUES (" + RoomId + ", " + UsersNow + ")");
                            //    dbClient.runFastQuery("UPDATE room_active SET active_users = " + UsersNow);
                            //}
                        }
                    }

                    usersByUserID.Remove(User.userID);
                    if (Session.GetHabbo() != null)
                        usersByUsername.Remove(Session.GetHabbo().Username.ToLower());

                    User.Dispose();
                }

            }
            catch (Exception e)
            {
                Logging.LogCriticalException("Error during removing user from room:" + e.ToString());
            }
        }