Just a few renames.
[AHbot.git] / src / game / AuctionHouseHandler.cpp
blobd37b1b7319d148d817b4bf71d3b30a422c3a7f76
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "WorldPacket.h"
20 #include "WorldSession.h"
21 #include "Opcodes.h"
22 #include "Log.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "Player.h"
26 #include "UpdateMask.h"
27 #include "AuctionHouseMgr.h"
28 #include "Util.h"
30 //please DO NOT use iterator++, because it is slower than ++iterator!!!
31 //post-incrementation is always slower than pre-incrementation !
33 //void called when player click on auctioneer npc
34 void WorldSession::HandleAuctionHelloOpcode( WorldPacket & recv_data )
36 CHECK_PACKET_SIZE(recv_data,8);
38 uint64 guid; //NPC guid
39 recv_data >> guid;
41 Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
42 if (!unit)
44 sLog.outDebug( "WORLD: HandleAuctionHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
45 return;
48 // remove fake death
49 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
50 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
52 SendAuctionHello(guid, unit);
55 //this void causes that auction window is opened
56 void WorldSession::SendAuctionHello( uint64 guid, Creature* unit )
58 AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->getFaction());
59 if(!ahEntry)
60 return;
62 WorldPacket data( MSG_AUCTION_HELLO, 12 );
63 data << (uint64) guid;
64 data << (uint32) ahEntry->houseId;
65 SendPacket( &data );
68 //call this method when player bids, creates, or deletes auction
69 void WorldSession::SendAuctionCommandResult(uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError )
71 WorldPacket data( SMSG_AUCTION_COMMAND_RESULT, 16 );
72 data << auctionId;
73 data << Action;
74 data << ErrorCode;
75 if ( !ErrorCode && Action )
76 data << bidError; //when bid, then send 0, once...
77 SendPacket(&data);
80 //this function sends notification, if bidder is online
81 void WorldSession::SendAuctionBidderNotification( uint32 location, uint32 auctionId, uint64 bidder, uint32 bidSum, uint32 diff, uint32 item_template)
83 WorldPacket data(SMSG_AUCTION_BIDDER_NOTIFICATION, (8*4));
84 data << uint32(location);
85 data << uint32(auctionId);
86 data << uint64(bidder);
87 data << uint32(bidSum);
88 data << uint32(diff);
89 data << uint32(item_template);
90 data << uint32(0);
91 SendPacket(&data);
94 //this void causes on client to display: "Your auction sold"
95 void WorldSession::SendAuctionOwnerNotification( AuctionEntry* auction)
97 WorldPacket data(SMSG_AUCTION_OWNER_NOTIFICATION, (7*4));
98 data << auction->Id;
99 data << auction->bid;
100 data << (uint32) 0; //unk
101 data << (uint32) 0; //unk
102 data << (uint32) 0; //unk
103 data << auction->item_template;
104 data << (uint32) 0; //unk
105 SendPacket(&data);
108 //this function sends mail to old bidder
109 void WorldSession::SendAuctionOutbiddedMail(AuctionEntry *auction, uint32 newPrice)
111 uint64 oldBidder_guid = MAKE_NEW_GUID(auction->bidder,0, HIGHGUID_PLAYER);
112 Player *oldBidder = objmgr.GetPlayer(oldBidder_guid);
114 uint32 oldBidder_accId = 0;
115 if(!oldBidder)
116 oldBidder_accId = objmgr.GetPlayerAccountIdByGUID(oldBidder_guid);
118 // old bidder exist
119 if(oldBidder || oldBidder_accId)
121 std::ostringstream msgAuctionOutbiddedSubject;
122 msgAuctionOutbiddedSubject << auction->item_template << ":0:" << AUCTION_OUTBIDDED;
124 if (oldBidder)
125 oldBidder->GetSession()->SendAuctionBidderNotification( auction->GetHouseId(), auction->Id, _player->GetGUID(), newPrice, auction->GetAuctionOutBid(), auction->item_template);
127 WorldSession::SendMailTo(oldBidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->bidder, msgAuctionOutbiddedSubject.str(), 0, NULL, auction->bid, 0, MAIL_CHECK_MASK_NONE);
131 //this function sends mail, when auction is cancelled to old bidder
132 void WorldSession::SendAuctionCancelledToBidderMail( AuctionEntry* auction )
134 uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
135 Player *bidder = objmgr.GetPlayer(bidder_guid);
137 uint32 bidder_accId = 0;
138 if(!bidder)
139 bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid);
141 // bidder exist
142 if(bidder || bidder_accId)
144 std::ostringstream msgAuctionCancelledSubject;
145 msgAuctionCancelledSubject << auction->item_template << ":0:" << AUCTION_CANCELLED_TO_BIDDER;
147 WorldSession::SendMailTo(bidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->bidder, msgAuctionCancelledSubject.str(), 0, NULL, auction->bid, 0, MAIL_CHECK_MASK_NONE);
151 //this void creates new auction and adds auction to some auctionhouse
152 void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
154 CHECK_PACKET_SIZE(recv_data,8+8+4+4+4);
156 uint64 auctioneer, item;
157 uint32 etime, bid, buyout;
158 recv_data >> auctioneer >> item;
159 recv_data >> bid >> buyout >> etime;
160 Player *pl = GetPlayer();
162 if (!item || !bid || !etime)
163 return; //check for cheaters
165 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
166 if (!pCreature)
168 sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) );
169 return;
172 AuctionHouseEntry const* auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(pCreature->getFaction());
173 if(!auctionHouseEntry)
175 sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) has wrong faction.", uint32(GUID_LOPART(auctioneer)) );
176 return;
180 // client send time in minutes, convert to common used sec time
181 etime *= MINUTE;
183 // client understand only 3 auction time
184 switch(etime)
186 case 1*MIN_AUCTION_TIME:
187 case 2*MIN_AUCTION_TIME:
188 case 4*MIN_AUCTION_TIME:
189 break;
190 default:
191 return;
194 // remove fake death
195 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
196 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
198 Item *it = pl->GetItemByGuid( item );
199 //do not allow to sell already auctioned items
200 if(auctionmgr.GetAItem(GUID_LOPART(item)))
202 sLog.outError("AuctionError, player %s is sending item id: %u, but item is already in another auction", pl->GetName(), GUID_LOPART(item));
203 SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
204 return;
206 // prevent sending bag with items (cheat: can be placed in bag after adding equiped empty bag to auction)
207 if(!it)
209 SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_ITEM_NOT_FOUND);
210 return;
213 if(!it->CanBeTraded())
215 SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
216 return;
219 if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_CONJURED) || it->GetUInt32Value(ITEM_FIELD_DURATION))
221 SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
222 return;
225 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() );
227 //we have to take deposit :
228 uint32 deposit = auctionmgr.GetAuctionDeposit( auctionHouseEntry, etime, it );
229 if ( pl->GetMoney() < deposit )
231 SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_NOT_ENOUGHT_MONEY);
232 return;
235 if( GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
237 sLog.outCommand(GetAccountId(),"GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)",
238 GetPlayerName(),GetAccountId(),it->GetProto()->Name1,it->GetEntry(),it->GetCount());
241 pl->ModifyMoney( -int32(deposit) );
243 uint32 auction_time = uint32(etime * sWorld.getRate(RATE_AUCTION_TIME));
245 AuctionEntry *AH = new AuctionEntry;
246 AH->Id = objmgr.GenerateAuctionID();
247 AH->auctioneer = GUID_LOPART(auctioneer);
248 AH->item_guidlow = GUID_LOPART(item);
249 AH->item_template = it->GetEntry();
250 AH->owner = pl->GetGUIDLow();
251 AH->startbid = bid;
252 AH->bidder = 0;
253 AH->bid = 0;
254 AH->buyout = buyout;
255 AH->expire_time = time(NULL) + auction_time;
256 AH->deposit = deposit;
257 AH->auctionHouseEntry = auctionHouseEntry;
259 sLog.outDetail("selling item %u to auctioneer %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", GUID_LOPART(item), GUID_LOPART(auctioneer), bid, buyout, auction_time, AH->GetHouseId());
260 auctionHouse->AddAuction(AH);
262 auctionmgr.AddAItem(it);
263 pl->MoveItemFromInventory( it->GetBagSlot(), it->GetSlot(), true);
265 CharacterDatabase.BeginTransaction();
266 it->DeleteFromInventoryDB();
267 it->SaveToDB(); // recursive and not have transaction guard into self, not in inventiory and can be save standalone
268 AH->SaveToDB();
269 pl->SaveInventoryAndGoldToDB();
270 CharacterDatabase.CommitTransaction();
272 SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, AUCTION_OK);
275 //this function is called when client bids or buys out auction
276 void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
278 CHECK_PACKET_SIZE(recv_data,8+4+4);
280 uint64 auctioneer;
281 uint32 auctionId;
282 uint32 price;
283 recv_data >> auctioneer;
284 recv_data >> auctionId >> price;
286 if (!auctionId || !price)
287 return; //check for cheaters
289 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
290 if (!pCreature)
292 sLog.outDebug( "WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) );
293 return;
296 // remove fake death
297 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
298 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
300 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() );
302 AuctionEntry *auction = auctionHouse->GetAuction(auctionId);
303 Player *pl = GetPlayer();
305 if( !auction || auction->owner == pl->GetGUIDLow() )
307 //you cannot bid your own auction:
308 SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR );
309 return;
312 // impossible have online own another character (use this for speedup check in case online owner)
313 Player* auction_owner = objmgr.GetPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER));
314 if( !auction_owner && objmgr.GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == pl->GetSession()->GetAccountId())
316 //you cannot bid your another character auction:
317 SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR );
318 return;
321 // cheating
322 if(price <= auction->bid)
323 return;
325 // price too low for next bid if not buyout
326 if ((price < auction->buyout || auction->buyout == 0) &&
327 price < auction->bid + auction->GetAuctionOutBid())
329 //auction has already higher bid, client tests it!
330 return;
333 if (price > pl->GetMoney())
335 //you don't have enought money!, client tests!
336 //SendAuctionCommandResult(auction->auctionId, AUCTION_PLACE_BID, ???);
337 return;
340 if ((price < auction->buyout) || (auction->buyout == 0))
342 if (auction->bidder > 0)
344 if ( auction->bidder == pl->GetGUIDLow() )
346 pl->ModifyMoney( -int32(price - auction->bid));
348 else
350 // mail to last bidder and return money
351 SendAuctionOutbiddedMail( auction , price );
352 pl->ModifyMoney( -int32(price) );
355 else
357 pl->ModifyMoney( -int32(price) );
359 auction->bidder = pl->GetGUIDLow();
360 auction->bid = price;
361 GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, price);
363 // after this update we should save player's money ...
364 CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id);
366 SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK, 0 );
368 else
370 //buyout:
371 if (pl->GetGUIDLow() == auction->bidder )
373 pl->ModifyMoney(-int32(auction->buyout - auction->bid));
375 else
377 pl->ModifyMoney(-int32(auction->buyout));
378 if ( auction->bidder ) //buyout for bidded auction ..
380 SendAuctionOutbiddedMail( auction, auction->buyout );
383 auction->bidder = pl->GetGUIDLow();
384 auction->bid = auction->buyout;
385 GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, auction->buyout);
387 auctionmgr.SendAuctionSalePendingMail( auction );
388 auctionmgr.SendAuctionSuccessfulMail( auction );
389 auctionmgr.SendAuctionWonMail( auction );
391 SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK);
393 auctionmgr.RemoveAItem(auction->item_guidlow);
394 auctionHouse->RemoveAuction(auction->Id);
395 auction->DeleteFromDB();
397 delete auction;
399 CharacterDatabase.BeginTransaction();
400 pl->SaveInventoryAndGoldToDB();
401 CharacterDatabase.CommitTransaction();
404 //this void is called when auction_owner cancels his auction
405 void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data )
407 CHECK_PACKET_SIZE(recv_data,8+4);
409 uint64 auctioneer;
410 uint32 auctionId;
411 recv_data >> auctioneer;
412 recv_data >> auctionId;
413 //sLog.outDebug( "Cancel AUCTION AuctionID: %u", auctionId);
415 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
416 if (!pCreature)
418 sLog.outDebug( "WORLD: HandleAuctionRemoveItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) );
419 return;
422 // remove fake death
423 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
424 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
426 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() );
428 AuctionEntry *auction = auctionHouse->GetAuction(auctionId);
429 Player *pl = GetPlayer();
431 if (auction && auction->owner == pl->GetGUIDLow())
433 Item *pItem = auctionmgr.GetAItem(auction->item_guidlow);
434 if (pItem)
436 if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid
438 uint32 auctionCut = auction->GetAuctionCut();
439 if ( pl->GetMoney() < auctionCut ) //player doesn't have enough money, maybe message needed
440 return;
441 //some auctionBidderNotification would be needed, but don't know that parts..
442 SendAuctionCancelledToBidderMail( auction );
443 pl->ModifyMoney( -int32(auctionCut) );
445 // Return the item by mail
446 std::ostringstream msgAuctionCanceledOwner;
447 msgAuctionCanceledOwner << auction->item_template << ":0:" << AUCTION_CANCELED;
449 MailItemsInfo mi;
450 mi.AddItem(auction->item_guidlow, auction->item_template, pItem);
452 // item will deleted or added to received mail list
453 WorldSession::SendMailTo(pl, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), pl->GetGUIDLow(), msgAuctionCanceledOwner.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
455 else
457 sLog.outError("Auction id: %u has non-existed item (item guid : %u)!!!", auction->Id, auction->item_guidlow);
458 SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR );
459 return;
462 else
464 SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR );
465 //this code isn't possible ... maybe there should be assert
466 sLog.outError("CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", pl->GetGUIDLow(), auctionId );
467 return;
470 //inform player, that auction is removed
471 SendAuctionCommandResult( auction->Id, AUCTION_CANCEL, AUCTION_OK );
472 // Now remove the auction
473 CharacterDatabase.BeginTransaction();
474 auction->DeleteFromDB();
475 pl->SaveInventoryAndGoldToDB();
476 CharacterDatabase.CommitTransaction();
477 auctionmgr.RemoveAItem( auction->item_guidlow );
478 auctionHouse->RemoveAuction( auction->Id );
479 delete auction;
482 //called when player lists his bids
483 void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data )
485 CHECK_PACKET_SIZE(recv_data,8+4+4);
487 uint64 guid; //NPC guid
488 uint32 listfrom; //page of auctions
489 uint32 outbiddedCount; //count of outbidded auctions
491 recv_data >> guid;
492 recv_data >> listfrom; // not used in fact (this list not have page control in client)
493 recv_data >> outbiddedCount;
494 if (recv_data.size() != (16 + outbiddedCount * 4 ))
496 sLog.outError("Client sent bad opcode!!! with count: %u and size : %lu (must be: %u)", outbiddedCount, (unsigned long)recv_data.size(),(16 + outbiddedCount * 4 ));
497 outbiddedCount = 0;
500 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
501 if (!pCreature)
503 sLog.outDebug( "WORLD: HandleAuctionListBidderItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
504 return;
507 // remove fake death
508 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
509 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
511 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() );
513 WorldPacket data( SMSG_AUCTION_BIDDER_LIST_RESULT, (4+4+4) );
514 Player *pl = GetPlayer();
515 data << (uint32) 0; //add 0 as count
516 uint32 count = 0;
517 uint32 totalcount = 0;
518 while ( outbiddedCount > 0) //add all data, which client requires
520 --outbiddedCount;
521 uint32 outbiddedAuctionId;
522 recv_data >> outbiddedAuctionId;
523 AuctionEntry * auction = auctionHouse->GetAuction( outbiddedAuctionId );
524 if ( auction && auction->BuildAuctionInfo(data))
526 ++totalcount;
527 ++count;
531 auctionHouse->BuildListBidderItems(data,pl,count,totalcount);
532 data.put<uint32>( 0, count ); // add count to placeholder
533 data << totalcount;
534 data << (uint32)300; //unk 2.3.0
535 SendPacket(&data);
538 //this void sends player info about his auctions
539 void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data )
541 CHECK_PACKET_SIZE(recv_data,8+4);
543 uint32 listfrom;
544 uint64 guid;
546 recv_data >> guid;
547 recv_data >> listfrom; // not used in fact (this list not have page control in client)
549 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
550 if (!pCreature)
552 sLog.outDebug( "WORLD: HandleAuctionListOwnerItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
553 return;
556 // remove fake death
557 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
558 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
560 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() );
562 WorldPacket data( SMSG_AUCTION_OWNER_LIST_RESULT, (4+4+4) );
563 data << (uint32) 0; // amount place holder
565 uint32 count = 0;
566 uint32 totalcount = 0;
568 auctionHouse->BuildListOwnerItems(data,_player,count,totalcount);
569 data.put<uint32>(0, count);
570 data << (uint32) totalcount;
571 data << (uint32) 0;
572 SendPacket(&data);
575 //this void is called when player clicks on search button
576 void WorldSession::HandleAuctionListItems( WorldPacket & recv_data )
578 CHECK_PACKET_SIZE(recv_data,8+4+1+1+1+4+4+4+4+1);
580 std::string searchedname;
581 uint8 levelmin, levelmax, usable;
582 uint32 listfrom, auctionSlotID, auctionMainCategory, auctionSubCategory, quality;
583 uint64 guid;
585 recv_data >> guid;
586 recv_data >> listfrom; // start, used for page control listing by 50 elements
587 recv_data >> searchedname;
589 // recheck with known string size
590 CHECK_PACKET_SIZE(recv_data,8+4+(searchedname.size()+1)+1+1+4+4+4+4+1);
592 recv_data >> levelmin >> levelmax;
593 recv_data >> auctionSlotID >> auctionMainCategory >> auctionSubCategory;
594 recv_data >> quality >> usable;
596 Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
597 if (!pCreature)
599 sLog.outDebug( "WORLD: HandleAuctionListItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
600 return;
603 // remove fake death
604 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
605 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
607 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() );
609 //sLog.outDebug("Auctionhouse search guid: " I64FMTD ", list from: %u, searchedname: %s, levelmin: %u, levelmax: %u, auctionSlotID: %u, auctionMainCategory: %u, auctionSubCategory: %u, quality: %u, usable: %u", guid, listfrom, searchedname.c_str(), levelmin, levelmax, auctionSlotID, auctionMainCategory, auctionSubCategory, quality, usable);
611 WorldPacket data( SMSG_AUCTION_LIST_RESULT, (4+4+4) );
612 uint32 count = 0;
613 uint32 totalcount = 0;
614 data << (uint32) 0;
616 // converting string that we try to find to lower case
617 std::wstring wsearchedname;
618 if(!Utf8toWStr(searchedname,wsearchedname))
619 return;
621 wstrToLower(wsearchedname);
623 auctionHouse->BuildListAuctionItems(data,_player,
624 wsearchedname, listfrom, levelmin, levelmax, usable,
625 auctionSlotID, auctionMainCategory, auctionSubCategory, quality,
626 count,totalcount);
628 data.put<uint32>(0, count);
629 data << (uint32) totalcount;
630 data << (uint32) 300; // unk 2.3.0 const?
631 SendPacket(&data);
634 void WorldSession::HandleAuctionListPendingSales( WorldPacket & recv_data )
636 sLog.outDebug("CMSG_AUCTION_LIST_PENDING_SALES");
637 recv_data.hexlike();
639 uint32 count = 0;
641 WorldPacket data(SMSG_AUCTION_LIST_PENDING_SALES, 4);
642 data << uint32(count); // count
643 /*for(uint32 i = 0; i < count; ++i)
645 data << ""; // string
646 data << ""; // string
647 data << uint32(0);
648 data << uint32(0);
649 data << float(0);
651 SendPacket(&data);