[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / AuctionHouseHandler.cpp
blobac9ef713142501b35a3982f405660e019c41cccd
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 = ObjectAccessor::GetNPCIfCanInteractWith(*_player, 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 = ObjectAccessor::GetNPCIfCanInteractWith(*_player, 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 = ObjectAccessor::GetNPCIfCanInteractWith(*_player, 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;
362 // after this update we should save player's money ...
363 CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id);
365 SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK, 0 );
367 else
369 //buyout:
370 if (pl->GetGUIDLow() == auction->bidder )
372 pl->ModifyMoney(-int32(auction->buyout - auction->bid));
374 else
376 pl->ModifyMoney(-int32(auction->buyout));
377 if ( auction->bidder ) //buyout for bidded auction ..
379 SendAuctionOutbiddedMail( auction, auction->buyout );
382 auction->bidder = pl->GetGUIDLow();
383 auction->bid = auction->buyout;
385 auctionmgr.SendAuctionSalePendingMail( auction );
386 auctionmgr.SendAuctionSuccessfulMail( auction );
387 auctionmgr.SendAuctionWonMail( auction );
389 SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK);
391 auctionmgr.RemoveAItem(auction->item_guidlow);
392 auctionHouse->RemoveAuction(auction->Id);
393 auction->DeleteFromDB();
395 delete auction;
397 CharacterDatabase.BeginTransaction();
398 pl->SaveInventoryAndGoldToDB();
399 CharacterDatabase.CommitTransaction();
402 //this void is called when auction_owner cancels his auction
403 void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data )
405 CHECK_PACKET_SIZE(recv_data,8+4);
407 uint64 auctioneer;
408 uint32 auctionId;
409 recv_data >> auctioneer;
410 recv_data >> auctionId;
411 //sLog.outDebug( "Cancel AUCTION AuctionID: %u", auctionId);
413 Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
414 if (!pCreature)
416 sLog.outDebug( "WORLD: HandleAuctionRemoveItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) );
417 return;
420 // remove fake death
421 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
422 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
424 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() );
426 AuctionEntry *auction = auctionHouse->GetAuction(auctionId);
427 Player *pl = GetPlayer();
429 if (auction && auction->owner == pl->GetGUIDLow())
431 Item *pItem = auctionmgr.GetAItem(auction->item_guidlow);
432 if (pItem)
434 if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid
436 uint32 auctionCut = auction->GetAuctionCut();
437 if ( pl->GetMoney() < auctionCut ) //player doesn't have enough money, maybe message needed
438 return;
439 //some auctionBidderNotification would be needed, but don't know that parts..
440 SendAuctionCancelledToBidderMail( auction );
441 pl->ModifyMoney( -int32(auctionCut) );
443 // Return the item by mail
444 std::ostringstream msgAuctionCanceledOwner;
445 msgAuctionCanceledOwner << auction->item_template << ":0:" << AUCTION_CANCELED;
447 MailItemsInfo mi;
448 mi.AddItem(auction->item_guidlow, auction->item_template, pItem);
450 // item will deleted or added to received mail list
451 WorldSession::SendMailTo(pl, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), pl->GetGUIDLow(), msgAuctionCanceledOwner.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
453 else
455 sLog.outError("Auction id: %u has non-existed item (item guid : %u)!!!", auction->Id, auction->item_guidlow);
456 SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR );
457 return;
460 else
462 SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR );
463 //this code isn't possible ... maybe there should be assert
464 sLog.outError("CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", pl->GetGUIDLow(), auctionId );
465 return;
468 //inform player, that auction is removed
469 SendAuctionCommandResult( auction->Id, AUCTION_CANCEL, AUCTION_OK );
470 // Now remove the auction
471 CharacterDatabase.BeginTransaction();
472 auction->DeleteFromDB();
473 pl->SaveInventoryAndGoldToDB();
474 CharacterDatabase.CommitTransaction();
475 auctionmgr.RemoveAItem( auction->item_guidlow );
476 auctionHouse->RemoveAuction( auction->Id );
477 delete auction;
480 //called when player lists his bids
481 void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data )
483 CHECK_PACKET_SIZE(recv_data,8+4+4);
485 uint64 guid; //NPC guid
486 uint32 listfrom; //page of auctions
487 uint32 outbiddedCount; //count of outbidded auctions
489 recv_data >> guid;
490 recv_data >> listfrom; // not used in fact (this list not have page control in client)
491 recv_data >> outbiddedCount;
492 if (recv_data.size() != (16 + outbiddedCount * 4 ))
494 sLog.outError("Client sent bad opcode!!! with count: %u and size : %d (mustbe: %d", outbiddedCount, recv_data.size(),(16 + outbiddedCount * 4 ));
495 outbiddedCount = 0;
498 Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER);
499 if (!pCreature)
501 sLog.outDebug( "WORLD: HandleAuctionListBidderItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
502 return;
505 // remove fake death
506 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
507 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
509 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() );
511 WorldPacket data( SMSG_AUCTION_BIDDER_LIST_RESULT, (4+4+4) );
512 Player *pl = GetPlayer();
513 data << (uint32) 0; //add 0 as count
514 uint32 count = 0;
515 uint32 totalcount = 0;
516 while ( outbiddedCount > 0) //add all data, which client requires
518 --outbiddedCount;
519 uint32 outbiddedAuctionId;
520 recv_data >> outbiddedAuctionId;
521 AuctionEntry * auction = auctionHouse->GetAuction( outbiddedAuctionId );
522 if ( auction && auction->BuildAuctionInfo(data))
524 ++totalcount;
525 ++count;
529 auctionHouse->BuildListBidderItems(data,pl,count,totalcount);
530 data.put<uint32>( 0, count ); // add count to placeholder
531 data << totalcount;
532 data << (uint32)300; //unk 2.3.0
533 SendPacket(&data);
536 //this void sends player info about his auctions
537 void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data )
539 CHECK_PACKET_SIZE(recv_data,8+4);
541 uint32 listfrom;
542 uint64 guid;
544 recv_data >> guid;
545 recv_data >> listfrom; // not used in fact (this list not have page control in client)
547 Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER);
548 if (!pCreature)
550 sLog.outDebug( "WORLD: HandleAuctionListOwnerItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
551 return;
554 // remove fake death
555 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
556 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
558 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() );
560 WorldPacket data( SMSG_AUCTION_OWNER_LIST_RESULT, (4+4+4) );
561 data << (uint32) 0; // amount place holder
563 uint32 count = 0;
564 uint32 totalcount = 0;
566 auctionHouse->BuildListOwnerItems(data,_player,count,totalcount);
567 data.put<uint32>(0, count);
568 data << (uint32) totalcount;
569 data << (uint32) 0;
570 SendPacket(&data);
573 //this void is called when player clicks on search button
574 void WorldSession::HandleAuctionListItems( WorldPacket & recv_data )
576 CHECK_PACKET_SIZE(recv_data,8+4+1+1+1+4+4+4+4+1);
578 std::string searchedname;
579 uint8 levelmin, levelmax, usable;
580 uint32 listfrom, auctionSlotID, auctionMainCategory, auctionSubCategory, quality;
581 uint64 guid;
583 recv_data >> guid;
584 recv_data >> listfrom; // start, used for page control listing by 50 elements
585 recv_data >> searchedname;
587 // recheck with known string size
588 CHECK_PACKET_SIZE(recv_data,8+4+(searchedname.size()+1)+1+1+4+4+4+4+1);
590 recv_data >> levelmin >> levelmax;
591 recv_data >> auctionSlotID >> auctionMainCategory >> auctionSubCategory;
592 recv_data >> quality >> usable;
594 Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER);
595 if (!pCreature)
597 sLog.outDebug( "WORLD: HandleAuctionListItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
598 return;
601 // remove fake death
602 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
603 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
605 AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() );
607 //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);
609 WorldPacket data( SMSG_AUCTION_LIST_RESULT, (4+4+4) );
610 uint32 count = 0;
611 uint32 totalcount = 0;
612 data << (uint32) 0;
614 // converting string that we try to find to lower case
615 std::wstring wsearchedname;
616 if(!Utf8toWStr(searchedname,wsearchedname))
617 return;
619 wstrToLower(wsearchedname);
621 auctionHouse->BuildListAuctionItems(data,_player,
622 wsearchedname, listfrom, levelmin, levelmax, usable,
623 auctionSlotID, auctionMainCategory, auctionSubCategory, quality,
624 count,totalcount);
626 data.put<uint32>(0, count);
627 data << (uint32) totalcount;
628 data << (uint32) 300; // unk 2.3.0 const?
629 SendPacket(&data);
632 void WorldSession::HandleAuctionListPendingSales( WorldPacket & recv_data )
634 sLog.outDebug("CMSG_AUCTION_LIST_PENDING_SALES");
635 recv_data.hexlike();
637 uint32 count = 0;
639 WorldPacket data(SMSG_AUCTION_LIST_PENDING_SALES, 4);
640 data << uint32(count); // count
641 /*for(uint32 i = 0; i < count; ++i)
643 data << ""; // string
644 data << ""; // string
645 data << uint32(0);
646 data << uint32(0);
647 data << float(0);
649 SendPacket(&data);