예제 #1
0
        public void LoadMarketplaceOffers(DatabaseClient dbClient)
        {
            Logging.Write("Loading marketplace offers... ");
            this.Offers.Clear();
            this.Sold.Clear();

            DataTable offers = dbClient.ReadDataTable("SELECT * FROM catalog_marketplace_offers");

            if (offers != null && offers.Rows.Count > 0)
            {
                foreach (DataRow dataRow in offers.Rows)
                {
                    uint             id    = (uint)dataRow["id"];
                    MarketplaceOffer offer = new MarketplaceOffer(id, (uint)dataRow["user_id"], (uint)dataRow["item_id"], (int)dataRow["price"], (double)dataRow["timestamp"], TextUtilies.StringToBool((string)dataRow["sold"]), (double)dataRow["sold_timestamp"], TextUtilies.StringToBool((string)dataRow["redeem"]), (uint)dataRow["furni_id"], (string)dataRow["furni_extra_data"]);

                    if (!offer.Sold)        //not sold
                    {
                        if (!offer.Expired) //not expired
                        {
                            this.Offers.Add(id, offer);
                        }
                        else //expired
                        {
                            this.Expired.Add(id, offer);
                        }
                    }
                    else //sold
                    {
                        this.Sold.Add(id, offer);
                    }
                }
            }
            Logging.WriteLine("completed!", ConsoleColor.Green);
        }
예제 #2
0
        public void CancelOffer(GameClient session, uint id)
        {
            MarketplaceOffer offer = this.TryGetOffer(id);

            if (offer != null)
            {
                if (!offer.Sold && !offer.Redeem) //for sure both
                {
                    offer.Cancalled = true;

                    Item item = Skylight.GetGame().GetItemManager().TryGetItem(offer.ItemID);
                    if (item != null)
                    {
                        this.Offers.Remove(offer.ID);
                        this.Sold.Remove(offer.ID); //for sure :D
                        this.Expired.Remove(offer.ID);
                        session.GetHabbo().GetInventoryManager().AddItem(offer.FurniID, item.ID, offer.FurniExtraData, true);

                        using (DatabaseClient dbClient = Skylight.GetDatabaseManager().GetClient())
                        {
                            dbClient.AddParamWithValue("offerId", offer.ID);
                            dbClient.ExecuteQuery("DELETE FROM catalog_marketplace_offers WHERE id = @offerId LIMIT 1"); //useless data so we can delete it
                        }

                        ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108);
                        message.Init(r63aOutgoing.CancelOfferResult);
                        message.AppendUInt(offer.ID);
                        message.AppendInt32(1); //result, 0 = failed, 1 = success
                        session.SendMessage(message);
                    }
                    else
                    {
                        ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108);
                        message.Init(r63aOutgoing.CancelOfferResult);
                        message.AppendUInt(offer.ID);
                        message.AppendInt32(0); //result, 0 = failed, 1 = success
                        session.SendMessage(message);
                    }
                }
                else
                {
                    ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108);
                    message.Init(r63aOutgoing.CancelOfferResult);
                    message.AppendUInt(offer.ID);
                    message.AppendInt32(0); //result, 0 = failed, 1 = success
                    session.SendMessage(message);
                }
            }
            else
            {
                ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108);
                message.Init(r63aOutgoing.CancelOfferResult);
                message.AppendUInt(id);
                message.AppendInt32(0); //result, 0 = failed, 1 = success
                session.SendMessage(message);
            }
        }
예제 #3
0
        public void BuyOffer(GameClient session, uint id)
        {
            MarketplaceOffer offer = this.TryGetOffer(id);

            if (offer != null)
            {
                if (!offer.Expired)
                {
                    if (!offer.Sold && !offer.Cancalled)
                    {
                        offer.Sold          = true;
                        offer.SoldTimestamp = TimeUtilies.GetUnixTimestamp();

                        this.Offers.Remove(id);   //remove it, not anymore active
                        this.Sold.Add(id, offer); //add it to solds :)

                        Item item = Skylight.GetGame().GetItemManager().TryGetItem(offer.ItemID);
                        if (item != null)
                        {
                            int totalPrice = this.CalcCompremission(offer.Price) + offer.Price;
                            if (session.GetHabbo().Credits < totalPrice)
                            {
                                ServerMessage result = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108);
                                result.Init(r63aOutgoing.MarketplaceBuyOfferResult);
                                result.AppendInt32(4); //result, 1 = success, 2 = all sold out, 3 = update item and show confirmation, 4 = no credits
                                result.AppendInt32(0);
                                result.AppendInt32(0);
                                result.AppendInt32(0);
                                session.SendMessage(result);
                            }
                            else
                            {
                                session.GetHabbo().Credits -= totalPrice;
                                session.GetHabbo().UpdateCredits(true);
                                session.GetHabbo().GetInventoryManager().AddItem(offer.FurniID, item.ID, offer.FurniExtraData, true);

                                using (DatabaseClient dbClient = Skylight.GetDatabaseManager().GetClient())
                                {
                                    dbClient.AddParamWithValue("offerId", offer.ID);
                                    dbClient.AddParamWithValue("timestamp", offer.SoldTimestamp);

                                    dbClient.ExecuteQuery("UPDATE catalog_marketplace_offers SET sold = '1', sold_timestamp = @timestamp WHERE id = @offerId LIMIT 1");
                                }

                                ServerMessage message = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108);
                                message.Init(r63aOutgoing.BuyInfo);
                                message.AppendUInt(item.ID);
                                message.AppendString(item.PublicName);
                                message.AppendInt32(totalPrice);
                                message.AppendInt32(0);
                                message.AppendInt32(0);
                                message.AppendInt32(1);
                                message.AppendString(item.Type.ToString());
                                message.AppendInt32(item.SpriteID);
                                message.AppendString("");
                                message.AppendInt32(1);
                                message.AppendInt32(-1);
                                message.AppendString("");
                                session.SendMessage(message);

                                ServerMessage result_ = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108);
                                result_.Init(r63aOutgoing.MarketplaceBuyOfferResult);
                                result_.AppendInt32(1); //result, 1 = success, 2 = all sold out, 3 = update item and show confirmation, 4 = no credits
                                result_.AppendInt32(0);
                                result_.AppendInt32(0);
                                result_.AppendInt32(0);
                                session.SendMessage(result_);
                            }
                        }
                        else
                        {
                            session.SendNotif("Unable to find item base item!");
                        }
                    }
                    else
                    {
                        MarketplaceOffer newOffer = this.TryGetMarketplaceOfferByItemID(offer.ItemID);
                        if (newOffer != null)
                        {
                            if (newOffer.Price != offer.Price)
                            {
                                ServerMessage result = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108);
                                result.Init(r63aOutgoing.MarketplaceBuyOfferResult);
                                result.AppendInt32(3);                                                       //result, 1 = success, 2 = all sold out, 3 = update item and show confirmation, 4 = no credits
                                result.AppendUInt(newOffer.ID);                                              //new id
                                result.AppendInt32(this.CalcCompremission(newOffer.Price) + newOffer.Price); //new price
                                result.AppendUInt(offer.ID);                                                 //old id
                                session.SendMessage(result);
                            }
                            else
                            {
                                this.BuyOffer(session, newOffer.ID);
                            }
                        }
                        else
                        {
                            ServerMessage result = BasicUtilies.GetRevisionServerMessage(Revision.RELEASE63_35255_34886_201108111108);
                            result.Init(r63aOutgoing.MarketplaceBuyOfferResult);
                            result.AppendInt32(2); //result, 1 = success, 2 = all sold out, 3 = update item and show confirmation, 4 = no credits
                            result.AppendUInt(0);  //new id
                            result.AppendInt32(0); //price
                            result.AppendUInt(0);  //old id
                            session.SendMessage(result);
                        }
                    }
                }
                else
                {
                    session.SendNotif("Offer have expired! Sorry! :(");
                }
            }
            else
            {
                session.SendNotif("Unable to find offer! Sorry! :(");
            }
        }