diff options
Diffstat (limited to 'src/server/game/Handlers/AuctionHouseHandler.cpp')
-rw-r--r-- | src/server/game/Handlers/AuctionHouseHandler.cpp | 174 |
1 files changed, 100 insertions, 74 deletions
diff --git a/src/server/game/Handlers/AuctionHouseHandler.cpp b/src/server/game/Handlers/AuctionHouseHandler.cpp index 47ad7ffa568..33316338c9e 100644 --- a/src/server/game/Handlers/AuctionHouseHandler.cpp +++ b/src/server/game/Handlers/AuctionHouseHandler.cpp @@ -74,14 +74,29 @@ void WorldSession::SendAuctionHello(uint64 guid, Creature* unit) } //call this method when player bids, creates, or deletes auction -void WorldSession::SendAuctionCommandResult(uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError) +void WorldSession::SendAuctionCommandResult(AuctionEntry* auction, uint32 action, uint32 errorCode, uint32 bidError) { - WorldPacket data(SMSG_AUCTION_COMMAND_RESULT, 16); - data << auctionId; - data << Action; - data << ErrorCode; - if (!ErrorCode && Action) - data << bidError; //when bid, then send 0, once... + WorldPacket data(SMSG_AUCTION_COMMAND_RESULT); + data << uint32(auction ? auction->Id : 0); + data << uint32(action); + data << uint32(errorCode); + + switch (errorCode) + { + case ERR_AUCTION_OK: + if (action == AUCTION_PLACE_BID) + data << uint64(auction->bid ? auction->GetAuctionOutBid() : 0); + break; + case ERR_AUCTION_INVENTORY: + data << uint32(bidError); + break; + case ERR_AUCTION_HIGHER_BID: + data << uint64(auction->bidder); + data << uint64(auction->bid); + data << uint64(auction->bid ? auction->GetAuctionOutBid() : 0); + break; + } + SendPacket(&data); } @@ -92,32 +107,41 @@ void WorldSession::SendAuctionBidderNotification(uint32 location, uint32 auction data << uint32(location); data << uint32(auctionId); data << uint64(bidder); - data << uint32(bidSum); - data << uint32(diff); + data << uint64(bidSum); + data << uint64(diff); data << uint32(itemEntry); data << uint32(0); SendPacket(&data); } -//this void causes on client to display: "Your auction sold" +// this void causes on client to display: "Your auction sold" void WorldSession::SendAuctionOwnerNotification(AuctionEntry* auction) { - WorldPacket data(SMSG_AUCTION_OWNER_NOTIFICATION, (8*4)); + WorldPacket data(SMSG_AUCTION_OWNER_NOTIFICATION, 40); data << uint32(auction->Id); - data << uint32(auction->bid); - data << uint32(0); //unk - data << uint64(0); //unk (bidder guid?) + data << uint64(auction->bid); + data << uint64(0); //unk + data << uint64(0); //unk data << uint32(auction->itemEntry); - data << uint32(0); //unk - data << float(0); //unk (time?) + data << uint32(0); //unk + data << float(0); //unk + SendPacket(&data); +} + +void WorldSession::SendAuctionRemovedNotification(uint32 auctionId, uint32 itemEntry, int32 randomPropertyId) +{ + WorldPacket data(SMSG_AUCTION_REMOVED_NOTIFICATION, (4+4+4)); + data << uint32(auctionId); + data << uint32(itemEntry); + data << uint32(randomPropertyId); SendPacket(&data); } //this void creates new auction and adds auction to some auctionhouse void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) { - uint64 auctioneer; - uint32 itemsCount, etime, bid, buyout; + uint64 auctioneer, bid, buyout; + uint32 itemsCount, etime; recvData >> auctioneer; recvData >> itemsCount; @@ -126,7 +150,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) if (itemsCount > MAX_AUCTION_ITEMS) { - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR); + SendAuctionCommandResult(NULL, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR); return; } @@ -185,7 +209,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) if (!item) { - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, ERR_AUCTION_ITEM_NOT_FOUND); + SendAuctionCommandResult(NULL, AUCTION_SELL_ITEM, ERR_AUCTION_ITEM_NOT_FOUND); return; } @@ -193,7 +217,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) item->GetTemplate()->Flags & ITEM_PROTO_FLAG_CONJURED || item->GetUInt32Value(ITEM_FIELD_DURATION) || item->GetCount() < count[i]) { - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR); + SendAuctionCommandResult(NULL, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR); return; } @@ -203,7 +227,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) if (!finalCount) { - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR); + SendAuctionCommandResult(NULL, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR); return; } @@ -213,7 +237,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) if (item->GetMaxStackCount() < finalCount) { - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR); + SendAuctionCommandResult(NULL, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR); return; } } @@ -226,9 +250,9 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(creature->getFaction()); uint32 deposit = sAuctionMgr->GetAuctionDeposit(auctionHouseEntry, etime, item, finalCount); - if (!_player->HasEnoughMoney(deposit)) + if (!_player->HasEnoughMoney((uint64)deposit)) { - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, ERR_AUCTION_NOT_ENOUGHT_MONEY); + SendAuctionCommandResult(NULL, AUCTION_SELL_ITEM, ERR_AUCTION_NOT_ENOUGHT_MONEY); return; } @@ -263,7 +287,10 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) AH->deposit = deposit; AH->auctionHouseEntry = auctionHouseEntry; - sLog->outInfo(LOG_FILTER_NETWORKIO, "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) to auctioneer %u with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", _player->GetName().c_str(), _player->GetGUIDLow(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetGUIDLow(), AH->auctioneer, item->GetCount(), bid, buyout, auctionTime, AH->GetHouseId()); + sLog->outInfo(LOG_FILTER_NETWORKIO, "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) " + "to auctioneer %u with count %u with initial bid " UI64FMTD " with buyout " UI64FMTD " and with time %u (in sec) in auctionhouse %u", + _player->GetName().c_str(), _player->GetGUIDLow(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetGUIDLow(), + AH->auctioneer, item->GetCount(), bid, buyout, auctionTime, AH->GetHouseId()); sAuctionMgr->AddAItem(item); auctionHouse->AddAuction(AH); @@ -276,7 +303,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) _player->SaveInventoryAndGoldToDB(trans); CharacterDatabase.CommitTransaction(trans); - SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, ERR_AUCTION_OK); + SendAuctionCommandResult(AH, AUCTION_SELL_ITEM, ERR_AUCTION_OK); GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CREATE_AUCTION, 1); return; @@ -287,7 +314,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) if (!newItem) { sLog->outError(LOG_FILTER_NETWORKIO, "CMSG_AUCTION_SELL_ITEM: Could not create clone of item %u", item->GetEntry()); - SendAuctionCommandResult(0, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR); + SendAuctionCommandResult(NULL, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR); return; } @@ -309,7 +336,10 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) AH->deposit = deposit; AH->auctionHouseEntry = auctionHouseEntry; - sLog->outInfo(LOG_FILTER_NETWORKIO, "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) to auctioneer %u with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", _player->GetName().c_str(), _player->GetGUIDLow(), newItem->GetTemplate()->Name1.c_str(), newItem->GetEntry(), newItem->GetGUIDLow(), AH->auctioneer, newItem->GetCount(), bid, buyout, auctionTime, AH->GetHouseId()); + sLog->outInfo(LOG_FILTER_NETWORKIO, "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) to " + "auctioneer %u with count %u with initial bid " UI64FMTD " with buyout " UI64FMTD " and with time %u (in sec) in auctionhouse %u", + _player->GetName().c_str(), _player->GetGUIDLow(), newItem->GetTemplate()->Name1.c_str(), newItem->GetEntry(), + newItem->GetGUIDLow(), AH->auctioneer, newItem->GetCount(), bid, buyout, auctionTime, AH->GetHouseId()); sAuctionMgr->AddAItem(newItem); auctionHouse->AddAuction(AH); @@ -346,7 +376,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) _player->SaveInventoryAndGoldToDB(trans); CharacterDatabase.CommitTransaction(trans); - SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, ERR_AUCTION_OK); + SendAuctionCommandResult(AH, AUCTION_SELL_ITEM, ERR_AUCTION_OK); GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CREATE_AUCTION, 1); return; @@ -354,19 +384,20 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) } } -//this function is called when client bids or buys out auction +// this function is called when client bids or buys out auction void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_AUCTION_PLACE_BID"); uint64 auctioneer; uint32 auctionId; - uint32 price; + uint64 price; recvData >> auctioneer; - recvData >> auctionId >> price; + recvData >> auctionId; + recvData >> price; if (!auctionId || !price) - return; //check for cheaters + return; // check for cheaters Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer, UNIT_NPC_FLAG_AUCTIONEER); if (!creature) @@ -387,18 +418,18 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData) if (!auction || auction->owner == player->GetGUIDLow()) { //you cannot bid your own auction: - SendAuctionCommandResult(0, AUCTION_PLACE_BID, ERR_AUCTION_BID_OWN); + SendAuctionCommandResult(NULL, AUCTION_PLACE_BID, ERR_AUCTION_BID_OWN); return; } // impossible have online own another character (use this for speedup check in case online owner) - Player* auction_owner = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)); + /*Player* auction_owner = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)); if (!auction_owner && sObjectMgr->GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == player->GetSession()->GetAccountId()) { //you cannot bid your another character auction: - SendAuctionCommandResult(0, AUCTION_PLACE_BID, ERR_AUCTION_BID_OWN); + SendAuctionCommandResult(NULL, AUCTION_PLACE_BID, ERR_AUCTION_BID_OWN); return; - } + }*/ // cheating if (price <= auction->bid || price < auction->startbid) @@ -408,14 +439,15 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData) if ((price < auction->buyout || auction->buyout == 0) && price < auction->bid + auction->GetAuctionOutBid()) { - //auction has already higher bid, client tests it! + // client already test it but just in case ... + SendAuctionCommandResult(auction, AUCTION_PLACE_BID, ERR_AUCTION_HIGHER_BID); return; } if (!player->HasEnoughMoney(price)) { - //you don't have enought money!, client tests! - //SendAuctionCommandResult(auction->auctionId, AUCTION_PLACE_BID, ???); + // client already test it but just in case ... + SendAuctionCommandResult(auction, AUCTION_PLACE_BID, ERR_AUCTION_NOT_ENOUGHT_MONEY); return; } @@ -426,16 +458,16 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData) if (auction->bidder > 0) { if (auction->bidder == player->GetGUIDLow()) - player->ModifyMoney(-int32(price - auction->bid)); + player->ModifyMoney(-int64(price - auction->bid)); else { // mail to last bidder and return money sAuctionMgr->SendAuctionOutbiddedMail(auction, price, GetPlayer(), trans); - player->ModifyMoney(-int32(price)); + player->ModifyMoney(-int64(price)); } } else - player->ModifyMoney(-int32(price)); + player->ModifyMoney(-int64(price)); auction->bidder = player->GetGUIDLow(); auction->bid = price; @@ -447,16 +479,16 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData) stmt->setUInt32(2, auction->Id); trans->Append(stmt); - SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, ERR_AUCTION_OK, 0); + SendAuctionCommandResult(auction, AUCTION_PLACE_BID, ERR_AUCTION_OK); } else { //buyout: if (player->GetGUIDLow() == auction->bidder) - player->ModifyMoney(-int32(auction->buyout - auction->bid)); + player->ModifyMoney(-int64(auction->buyout - auction->bid)); else { - player->ModifyMoney(-int32(auction->buyout)); + player->ModifyMoney(-int64(auction->buyout)); if (auction->bidder) //buyout for bidded auction .. sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, GetPlayer(), trans); } @@ -469,7 +501,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData) sAuctionMgr->SendAuctionSuccessfulMail(auction, trans); sAuctionMgr->SendAuctionWonMail(auction, trans); - SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, ERR_AUCTION_OK); + SendAuctionCommandResult(auction, AUCTION_PLACE_BID, ERR_AUCTION_OK); auction->DeleteFromDB(trans); @@ -490,7 +522,6 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recvData) uint32 auctionId; recvData >> auctioneer; recvData >> auctionId; - //sLog->outDebug("Cancel AUCTION AuctionID: %u", auctionId); Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer, UNIT_NPC_FLAG_AUCTIONEER); if (!creature) @@ -517,11 +548,10 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recvData) if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid { uint32 auctionCut = auction->GetAuctionCut(); - if (!player->HasEnoughMoney(auctionCut)) //player doesn't have enough money, maybe message needed + if (!player->HasEnoughMoney((uint64)auctionCut)) //player doesn't have enough money, maybe message needed return; - //some auctionBidderNotification would be needed, but don't know that parts.. - sAuctionMgr->SendAuctionCancelledToBidderMail(auction, trans); - player->ModifyMoney(-int32(auctionCut)); + sAuctionMgr->SendAuctionCancelledToBidderMail(auction, trans, pItem); + player->ModifyMoney(-int64(auctionCut)); } // item will deleted or added to received mail list @@ -531,21 +561,21 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recvData) } else { - sLog->outError(LOG_FILTER_NETWORKIO, "Auction id: %u has non-existed item (item guid : %u)!!!", auction->Id, auction->itemGUIDLow); - SendAuctionCommandResult(0, AUCTION_CANCEL, ERR_AUCTION_DATABASE_ERROR); + sLog->outError(LOG_FILTER_NETWORKIO, "Auction id: %u got non existing item (item guid : %u)!", auction->Id, auction->itemGUIDLow); + SendAuctionCommandResult(NULL, AUCTION_CANCEL, ERR_AUCTION_DATABASE_ERROR); return; } } else { - SendAuctionCommandResult(0, AUCTION_CANCEL, ERR_AUCTION_DATABASE_ERROR); + SendAuctionCommandResult(NULL, AUCTION_CANCEL, ERR_AUCTION_DATABASE_ERROR); //this code isn't possible ... maybe there should be assert - sLog->outError(LOG_FILTER_NETWORKIO, "CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", player->GetGUIDLow(), auctionId); + sLog->outError(LOG_FILTER_NETWORKIO, "CHEATER: %u tried to cancel auction (id: %u) of another player or auction is NULL", player->GetGUIDLow(), auctionId); return; } //inform player, that auction is removed - SendAuctionCommandResult(auction->Id, AUCTION_CANCEL, ERR_AUCTION_OK); + SendAuctionCommandResult(auction, AUCTION_CANCEL, ERR_AUCTION_OK); // Now remove the auction @@ -592,7 +622,7 @@ void WorldSession::HandleAuctionListBidderItems(WorldPacket& recvData) WorldPacket data(SMSG_AUCTION_BIDDER_LIST_RESULT, (4+4+4)); Player* player = GetPlayer(); - data << (uint32) 0; //add 0 as count + data << uint32(0); //add 0 as count uint32 count = 0; uint32 totalcount = 0; while (outbiddedCount > 0) //add all data, which client requires @@ -611,7 +641,7 @@ void WorldSession::HandleAuctionListBidderItems(WorldPacket& recvData) auctionHouse->BuildListBidderItems(data, player, count, totalcount); data.put<uint32>(0, count); // add count to placeholder data << totalcount; - data << (uint32)300; //unk 2.3.0 + data << uint32(300); //unk 2.3.0 SendPacket(&data); } @@ -640,15 +670,15 @@ void WorldSession::HandleAuctionListOwnerItems(WorldPacket& recvData) AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(creature->getFaction()); WorldPacket data(SMSG_AUCTION_OWNER_LIST_RESULT, (4+4+4)); - data << (uint32) 0; // amount place holder + data << uint32(0); // amount place holder uint32 count = 0; uint32 totalcount = 0; auctionHouse->BuildListOwnerItems(data, _player, count, totalcount); data.put<uint32>(0, count); - data << (uint32) totalcount; - data << (uint32) 0; + data << uint32(totalcount); + data << uint32(0); SendPacket(&data); } @@ -671,15 +701,11 @@ void WorldSession::HandleAuctionListItems(WorldPacket& recvData) recvData >> quality >> usable; recvData.read_skip<uint8>(); // unk + recvData.read_skip<uint8>(); // unk // this block looks like it uses some lame byte packing or similar... - uint8 unkCnt; - recvData >> unkCnt; - for (uint8 i = 0; i < unkCnt; i++) - { - recvData.read_skip<uint8>(); + for (uint8 i = 0; i < 15; i++) recvData.read_skip<uint8>(); - } Creature* creature = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_AUCTIONEER); if (!creature) @@ -694,13 +720,13 @@ void WorldSession::HandleAuctionListItems(WorldPacket& recvData) AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(creature->getFaction()); - //sLog->outDebug("Auctionhouse search (GUID: %u TypeId: %u)",, list from: %u, searchedname: %s, levelmin: %u, levelmax: %u, auctionSlotID: %u, auctionMainCategory: %u, auctionSubCategory: %u, quality: %u, usable: %u", + //sLog->outDebug(LOG_FILTER_GENERAL, "Auctionhouse search (GUID: %u TypeId: %u)",, list from: %u, searchedname: %s, levelmin: %u, levelmax: %u, auctionSlotID: %u, auctionMainCategory: %u, auctionSubCategory: %u, quality: %u, usable: %u", // GUID_LOPART(guid), GuidHigh2TypeId(GUID_HIPART(guid)), listfrom, searchedname.c_str(), levelmin, levelmax, auctionSlotID, auctionMainCategory, auctionSubCategory, quality, usable); WorldPacket data(SMSG_AUCTION_LIST_RESULT, (4+4+4)); uint32 count = 0; uint32 totalcount = 0; - data << (uint32) 0; + data << uint32(0); // converting string that we try to find to lower case std::wstring wsearchedname; @@ -715,8 +741,8 @@ void WorldSession::HandleAuctionListItems(WorldPacket& recvData) count, totalcount); data.put<uint32>(0, count); - data << (uint32) totalcount; - data << (uint32) 300; // unk 2.3.0 const? + data << uint32(totalcount); + data << uint32(300); //unk 2.3.0 SendPacket(&data); } @@ -734,7 +760,7 @@ void WorldSession::HandleAuctionListPendingSales(WorldPacket& recvData) { data << ""; // string data << ""; // string - data << uint32(0); + data << uint64(0); data << uint32(0); data << float(0); }*/ |