コード例 #1
0
        public void LoadAuctions()
        {
            uint oldMSTime = Time.GetMSTime();

            PreparedStatement stmt   = DB.Characters.GetPreparedStatement(CharStatements.SEL_AUCTIONS);
            SQLResult         result = DB.Characters.Query(stmt);

            if (result.IsEmpty())
            {
                Log.outInfo(LogFilter.ServerLoading, "Loaded 0 auctions. DB table `auctionhouse` is empty.");
                return;
            }

            uint           count = 0;
            SQLTransaction trans = new SQLTransaction();

            do
            {
                AuctionEntry aItem = new AuctionEntry();
                if (!aItem.LoadFromDB(result.GetFields()))
                {
                    aItem.DeleteFromDB(trans);
                    continue;
                }

                GetAuctionsMap(aItem.factionTemplateId).AddAuction(aItem);
                ++count;
            } while (result.NextRow());

            DB.Characters.CommitTransaction(trans);

            Log.outInfo(LogFilter.ServerLoading, "Loaded {0} auctions in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
        }
コード例 #2
0
        void HandleAuctionRemoveItem(AuctionRemoveItem packet)
        {
            Creature creature = GetPlayer().GetNPCIfCanInteractWith(packet.Auctioneer, NPCFlags.Auctioneer, NPCFlags2.None);

            if (!creature)
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandleAuctionRemoveItem - {0} not found or you can't interact with him.", packet.Auctioneer.ToString());
                return;
            }

            // remove fake death
            if (GetPlayer().HasUnitState(UnitState.Died))
            {
                GetPlayer().RemoveAurasByType(AuraType.FeignDeath);
            }

            AuctionHouseObject auctionHouse = Global.AuctionMgr.GetAuctionsMap(creature.GetFaction());

            AuctionEntry auction = auctionHouse.GetAuction((uint)packet.AuctionItemID);
            Player       player  = GetPlayer();

            SQLTransaction trans = new SQLTransaction();

            if (auction != null && auction.owner == player.GetGUID().GetCounter())
            {
                Item pItem = Global.AuctionMgr.GetAItem(auction.itemGUIDLow);
                if (pItem)
                {
                    if (auction.bidder > 0)                        // If we have a bidder, we have to send him the money he paid
                    {
                        ulong auctionCut = auction.GetAuctionCut();
                        if (!player.HasEnoughMoney(auctionCut))          //player doesn't have enough money, maybe message needed
                        {
                            return;
                        }
                        Global.AuctionMgr.SendAuctionCancelledToBidderMail(auction, trans);
                        player.ModifyMoney(-(long)auctionCut);
                    }

                    // item will deleted or added to received mail list
                    new MailDraft(auction.BuildAuctionMailSubject(MailAuctionAnswers.Canceled), AuctionEntry.BuildAuctionMailBody(0, 0, auction.buyout, auction.deposit, 0))
                    .AddItem(pItem)
                    .SendMailTo(trans, new MailReceiver(player), new MailSender(auction), MailCheckMask.Copied);
                }
                else
                {
                    Log.outError(LogFilter.Network, "Auction id: {0} got non existing item (item guid : {1})!", auction.Id, auction.itemGUIDLow);
                    SendAuctionCommandResult(null, AuctionAction.Cancel, AuctionError.DatabaseError);
                    return;
                }
            }
            else
            {
                SendAuctionCommandResult(null, AuctionAction.Cancel, AuctionError.DatabaseError);
                //this code isn't possible ... maybe there should be assert
                Log.outError(LogFilter.Network, "CHEATER: {0} tried to cancel auction (id: {1}) of another player or auction is null", player.GetGUID().ToString(), packet.AuctionItemID);
                return;
            }

            //inform player, that auction is removed
            SendAuctionCommandResult(auction, AuctionAction.Cancel, AuctionError.Ok);

            // Now remove the auction
            player.SaveInventoryAndGoldToDB(trans);
            auction.DeleteFromDB(trans);
            DB.Characters.CommitTransaction(trans);

            Global.AuctionMgr.RemoveAItem(auction.itemGUIDLow);
            auctionHouse.RemoveAuction(auction);
        }
コード例 #3
0
        void HandleAuctionPlaceBid(AuctionPlaceBid packet)
        {
            if (packet.AuctionItemID == 0 || packet.BidAmount == 0)
            {
                return; // check for cheaters
            }
            Creature creature = GetPlayer().GetNPCIfCanInteractWith(packet.Auctioneer, NPCFlags.Auctioneer, NPCFlags2.None);

            if (!creature)
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandleAuctionPlaceBid - {0} not found or you can't interact with him.", packet.Auctioneer.ToString());
                return;
            }

            // remove fake death
            if (GetPlayer().HasUnitState(UnitState.Died))
            {
                GetPlayer().RemoveAurasByType(AuraType.FeignDeath);
            }

            AuctionHouseObject auctionHouse = Global.AuctionMgr.GetAuctionsMap(creature.GetFaction());

            AuctionEntry auction = auctionHouse.GetAuction(packet.AuctionItemID);
            Player       player  = GetPlayer();

            if (auction == null || auction.owner == player.GetGUID().GetCounter())
            {
                //you cannot bid your own auction:
                SendAuctionCommandResult(null, AuctionAction.PlaceBid, AuctionError.BidOwn);
                return;
            }

            // impossible have online own another character (use this for speedup check in case online owner)
            ObjectGuid ownerGuid     = ObjectGuid.Create(HighGuid.Player, auction.owner);
            Player     auction_owner = Global.ObjAccessor.FindPlayer(ownerGuid);

            if (!auction_owner && Global.CharacterCacheStorage.GetCharacterAccountIdByGuid(ownerGuid) == player.GetSession().GetAccountId())
            {
                //you cannot bid your another character auction:
                SendAuctionCommandResult(null, AuctionAction.PlaceBid, AuctionError.BidOwn);
                return;
            }

            // cheating
            if (packet.BidAmount <= auction.bid || packet.BidAmount < auction.startbid)
            {
                return;
            }

            // price too low for next bid if not buyout
            if ((packet.BidAmount < auction.buyout || auction.buyout == 0) && packet.BidAmount < auction.bid + auction.GetAuctionOutBid())
            {
                // client already test it but just in case ...
                SendAuctionCommandResult(auction, AuctionAction.PlaceBid, AuctionError.HigherBid);
                return;
            }

            if (!player.HasEnoughMoney(packet.BidAmount))
            {
                // client already test it but just in case ...
                SendAuctionCommandResult(auction, AuctionAction.PlaceBid, AuctionError.NotEnoughtMoney);
                return;
            }

            SQLTransaction trans = new SQLTransaction();

            if (packet.BidAmount < auction.buyout || auction.buyout == 0)
            {
                if (auction.bidder > 0)
                {
                    if (auction.bidder == player.GetGUID().GetCounter())
                    {
                        player.ModifyMoney(-(long)(packet.BidAmount - auction.bid));
                    }
                    else
                    {
                        // mail to last bidder and return money
                        Global.AuctionMgr.SendAuctionOutbiddedMail(auction, packet.BidAmount, GetPlayer(), trans);
                        player.ModifyMoney(-(long)packet.BidAmount);
                    }
                }
                else
                {
                    player.ModifyMoney(-(long)packet.BidAmount);
                }

                auction.bidder = player.GetGUID().GetCounter();
                auction.bid    = (uint)packet.BidAmount;
                GetPlayer().UpdateCriteria(CriteriaTypes.HighestAuctionBid, packet.BidAmount);

                PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_AUCTION_BID);
                stmt.AddValue(0, auction.bidder);
                stmt.AddValue(1, auction.bid);
                stmt.AddValue(2, auction.Id);
                trans.Append(stmt);

                SendAuctionCommandResult(auction, AuctionAction.PlaceBid, AuctionError.Ok);

                // Not sure if we must send this now.
                Player owner = Global.ObjAccessor.FindConnectedPlayer(ObjectGuid.Create(HighGuid.Player, auction.owner));
                Item   item  = Global.AuctionMgr.GetAItem(auction.itemGUIDLow);
                if (owner && item)
                {
                    owner.GetSession().SendAuctionOwnerBidNotification(auction, item);
                }
            }
            else
            {
                //buyout:
                if (player.GetGUID().GetCounter() == auction.bidder)
                {
                    player.ModifyMoney(-(long)(auction.buyout - auction.bid));
                }
                else
                {
                    player.ModifyMoney(-(long)auction.buyout);
                    if (auction.bidder != 0)                          //buyout for bidded auction ..
                    {
                        Global.AuctionMgr.SendAuctionOutbiddedMail(auction, auction.buyout, GetPlayer(), trans);
                    }
                }
                auction.bidder = player.GetGUID().GetCounter();
                auction.bid    = auction.buyout;
                GetPlayer().UpdateCriteria(CriteriaTypes.HighestAuctionBid, auction.buyout);

                SendAuctionCommandResult(auction, AuctionAction.PlaceBid, AuctionError.Ok);

                //- Mails must be under transaction control too to prevent data loss
                Global.AuctionMgr.SendAuctionSalePendingMail(auction, trans);
                Global.AuctionMgr.SendAuctionSuccessfulMail(auction, trans);
                Global.AuctionMgr.SendAuctionWonMail(auction, trans);

                auction.DeleteFromDB(trans);

                Global.AuctionMgr.RemoveAItem(auction.itemGUIDLow);
                auctionHouse.RemoveAuction(auction);
            }

            player.SaveInventoryAndGoldToDB(trans);
            DB.Characters.CommitTransaction(trans);
        }