root/trunk/src/game/AuctionHouse.cpp @ 42

Revision 39, 29.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Various small changes here and there.
* Implementing MangChat? IRC system.
* Added new config option, MAX_WHO, can be used to set the limit of characters being sent in a /who request from client.

Original author: XTZGZoReX
Date: 2008-10-12 14:03:38-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
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 "AuctionHouseObject.h"
28#include "Util.h"
29#include "IRCClient.h"
30
31//please DO NOT use iterator++, because it is slower than ++iterator!!!
32//post-incrementation is always slower than pre-incrementation !
33
34//void called when player click on auctioneer npc
35void WorldSession::HandleAuctionHelloOpcode( WorldPacket & recv_data )
36{
37    CHECK_PACKET_SIZE(recv_data,8);
38
39    uint64 guid;                                            //NPC guid
40    recv_data >> guid;
41
42    Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER);
43    if (!unit)
44    {
45        sLog.outDebug( "WORLD: HandleAuctionHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
46        return;
47    }
48
49    // remove fake death
50    if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
51        GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
52
53    SendAuctionHello(guid, unit);
54}
55
56static uint8 AuctioneerFactionToLocation(uint32 faction)
57{
58    if(sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
59        return 7;                                           // neutral
60
61    FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(faction);
62    if(!u_entry)
63        return 7;                                           // neutral
64
65    if(u_entry->ourMask & FACTION_MASK_ALLIANCE)
66        return 2;
67    else if(u_entry->ourMask & FACTION_MASK_HORDE)
68        return 6;
69    else
70        return 7;
71}
72
73//this void causes that auction window is opened
74void WorldSession::SendAuctionHello( uint64 guid, Creature* unit )
75{
76    WorldPacket data( MSG_AUCTION_HELLO, 12 );
77    data << (uint64) guid;
78    data << (uint32) AuctioneerFactionToLocation(unit->getFaction());
79    SendPacket( &data );
80}
81
82//this function inserts to WorldPacket auction's data
83bool WorldSession::SendAuctionInfo(WorldPacket & data, AuctionEntry* auction)
84{
85    Item *pItem = objmgr.GetAItem(auction->item_guidlow);
86    if (!pItem)
87    {
88        sLog.outError("auction to item, that doesn't exist !!!!");
89        return false;
90    }
91    data << auction->Id;
92    data << pItem->GetUInt32Value(OBJECT_FIELD_ENTRY);
93
94    for (uint8 i = 0; i < MAX_INSPECTED_ENCHANTMENT_SLOT; i++)
95    {
96        data << (uint32) pItem->GetEnchantmentId(EnchantmentSlot(i));
97        data << (uint32) pItem->GetEnchantmentDuration(EnchantmentSlot(i));
98        data << (uint32) pItem->GetEnchantmentCharges(EnchantmentSlot(i));
99    }
100
101    data << (uint32) pItem->GetItemRandomPropertyId();      //random item property id
102    data << (uint32) pItem->GetItemSuffixFactor();          //SuffixFactor
103    data << (uint32) pItem->GetCount();                     //item->count
104    data << (uint32) pItem->GetSpellCharges();              //item->charge FFFFFFF
105    data << (uint32) 0;                                     //Unknown
106    data << (uint64) auction->owner;                        //Auction->owner
107    data << (uint32) auction->startbid;                     //Auction->startbid (not sure if useful)
108    data << (uint32) ((auction->bid)? objmgr.GetAuctionOutBid(auction->bid) : 0);
109                                                            //minimal outbid
110    data << (uint32) auction->buyout;                       //auction->buyout
111    data << (uint32) (auction->time - time(NULL)) * 1000;   //time left
112    data << (uint64) auction->bidder;                       //auction->bidder current
113    data << (uint32) auction->bid;                          //current bid
114    return true;
115}
116
117//call this method when player bids, creates, or deletes auction
118void WorldSession::SendAuctionCommandResult(uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError )
119{
120    WorldPacket data( SMSG_AUCTION_COMMAND_RESULT, 16 );
121    data << auctionId;
122    data << Action;
123    data << ErrorCode;
124    if ( !ErrorCode && Action )
125        data << bidError;                                   //when bid, then send 0, once...
126    SendPacket(&data);
127}
128
129//this function sends notification, if bidder is online
130void WorldSession::SendAuctionBidderNotification( uint32 location, uint32 auctionId, uint64 bidder, uint32 bidSum, uint32 diff, uint32 item_template)
131{
132    WorldPacket data(SMSG_AUCTION_BIDDER_NOTIFICATION, (8*4));
133    data << location;
134    data << auctionId;
135    data << (uint64) bidder;
136    data << bidSum;
137    data << (uint32) diff;
138    data << item_template;
139    data << (uint32) 0;
140    SendPacket(&data);
141}
142
143//this void causes on client to display: "Your auction sold"
144void WorldSession::SendAuctionOwnerNotification( AuctionEntry* auction)
145{
146    WorldPacket data(SMSG_AUCTION_OWNER_NOTIFICATION, (7*4));
147    data << auction->Id;
148    data << auction->bid;
149    data << (uint32) 0;                                     //unk
150    data << (uint32) 0;                                     //unk
151    data << (uint32) 0;                                     //unk
152    data << auction->item_template;
153    data << (uint32) 0;                                     //unk
154    SendPacket(&data);
155}
156
157//this function sends mail to old bidder
158void WorldSession::SendAuctionOutbiddedMail(AuctionEntry *auction, uint32 newPrice)
159{
160    uint64 oldBidder_guid = MAKE_NEW_GUID(auction->bidder,0, HIGHGUID_PLAYER);
161    Player *oldBidder = objmgr.GetPlayer(oldBidder_guid);
162
163    uint32 oldBidder_accId = 0;
164    if(!oldBidder)
165        oldBidder_accId = objmgr.GetPlayerAccountIdByGUID(oldBidder_guid);
166
167    // old bidder exist
168    if(oldBidder || oldBidder_accId)
169    {
170        std::ostringstream msgAuctionOutbiddedSubject;
171        msgAuctionOutbiddedSubject << auction->item_template << ":0:" << AUCTION_OUTBIDDED;
172
173        if (oldBidder)
174            oldBidder->GetSession()->SendAuctionBidderNotification( auction->location, auction->Id, _player->GetGUID(), newPrice, objmgr.GetAuctionOutBid(auction->bid), auction->item_template);
175
176        WorldSession::SendMailTo(oldBidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->bidder, msgAuctionOutbiddedSubject.str(), 0, NULL, auction->bid, 0, MAIL_CHECK_MASK_NONE);
177    }
178}
179
180//this function sends mail, when auction is cancelled to old bidder
181void WorldSession::SendAuctionCancelledToBidderMail( AuctionEntry* auction )
182{
183    uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
184    Player *bidder = objmgr.GetPlayer(bidder_guid);
185
186    uint32 bidder_accId = 0;
187    if(!bidder)
188        bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid);
189
190    // bidder exist
191    if(bidder || bidder_accId)
192    {
193        std::ostringstream msgAuctionCancelledSubject;
194        msgAuctionCancelledSubject << auction->item_template << ":0:" << AUCTION_CANCELLED_TO_BIDDER;
195
196        WorldSession::SendMailTo(bidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->bidder, msgAuctionCancelledSubject.str(), 0, NULL, auction->bid, 0, MAIL_CHECK_MASK_NONE);
197    }
198}
199
200//this void creates new auction and adds auction to some auctionhouse
201void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
202{
203    CHECK_PACKET_SIZE(recv_data,8+8+4+4+4);
204
205    uint64 auctioneer, item;
206    uint32 etime, bid, buyout;
207    recv_data >> auctioneer >> item;
208    recv_data >> bid >> buyout >> etime;
209    Player *pl = GetPlayer();
210
211    if (!item || !bid || !etime)
212        return;                                             //check for cheaters
213
214    Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
215    if (!pCreature)
216    {
217        sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) );
218        return;
219    }
220
221    // client send time in minutes, convert to common used sec time
222    etime *= MINUTE;
223
224    // client understand only 3 auction time
225    switch(etime)
226    {
227        case 1*MIN_AUCTION_TIME:
228        case 2*MIN_AUCTION_TIME:
229        case 4*MIN_AUCTION_TIME:
230            break;
231        default:
232            return;
233    }
234
235    // remove fake death
236    if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
237        GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
238
239    Item *it = pl->GetItemByGuid( item );
240    //do not allow to sell already auctioned items
241    if(objmgr.GetAItem(GUID_LOPART(item)))
242    {
243        sLog.outError("AuctionError, player %s is sending item id: %u, but item is already in another auction", pl->GetName(), GUID_LOPART(item));
244        SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
245        return;
246    }
247    // prevent sending bag with items (cheat: can be placed in bag after adding equiped empty bag to auction)
248    if(!it)
249    {
250        SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_ITEM_NOT_FOUND);
251        return;
252    }
253
254    if(!it->CanBeTraded())
255    {
256        SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
257        return;
258    }
259
260    if (it->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_CONJURED) || it->GetUInt32Value(ITEM_FIELD_DURATION))
261    {
262        SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
263        return;
264    }
265
266    uint32 location = AuctioneerFactionToLocation(pCreature->getFaction());
267    AuctionHouseObject * mAuctions;
268    mAuctions = objmgr.GetAuctionsMap( location );
269
270    //we have to take deposit :
271    uint32 deposit = objmgr.GetAuctionDeposit( location, etime, it );
272    if ( pl->GetMoney() < deposit )
273    {
274        SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_NOT_ENOUGHT_MONEY);
275        return;
276    }
277
278    if( GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
279    {
280        sLog.outCommand("GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)",
281            GetPlayerName(),GetAccountId(),it->GetProto()->Name1,it->GetEntry(),it->GetCount());
282    }
283
284    pl->ModifyMoney( -int32(deposit) );
285
286    uint32 auction_time = uint32(etime * sWorld.getRate(RATE_AUCTION_TIME));
287
288    AuctionEntry *AH = new AuctionEntry;
289    AH->Id = objmgr.GenerateAuctionID();
290    AH->auctioneer = GUID_LOPART(auctioneer);
291    AH->item_guidlow = GUID_LOPART(item);
292    AH->item_template = it->GetEntry();
293    AH->owner = pl->GetGUIDLow();
294    AH->startbid = bid;
295    AH->bidder = 0;
296    AH->bid = 0;
297    AH->buyout = buyout;
298    AH->time = time(NULL) + auction_time;
299    AH->deposit = deposit;
300    AH->location = location;
301
302    sLog.outDetail("selling item %u to auctioneer %u with initial bid %u with buyout %u and with time %u (in sec) in location: %u", GUID_LOPART(item), GUID_LOPART(auctioneer), bid, buyout, auction_time, location);
303    mAuctions->AddAuction(AH);
304
305    objmgr.AddAItem(it);
306    pl->MoveItemFromInventory( it->GetBagSlot(), it->GetSlot(), true);
307
308    CharacterDatabase.BeginTransaction();
309    it->DeleteFromInventoryDB();
310    it->SaveToDB();                                         // recursive and not have transaction guard into self, not in inventiory and can be save standalone
311    CharacterDatabase.PExecute("INSERT INTO auctionhouse (id,auctioneerguid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit,location) "
312        "VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '" I64FMTD "', '%u', '%u', '%u', '%u', '%u')",
313        AH->Id, AH->auctioneer, AH->item_guidlow, AH->item_template, AH->owner, AH->buyout, (uint64)AH->time, AH->bidder, AH->bid, AH->startbid, AH->deposit, AH->location);
314    pl->SaveInventoryAndGoldToDB();
315    CharacterDatabase.CommitTransaction();
316
317    if((sIRC.BOTMASK & 1024) != 0) 
318        sIRC.AHFunc(it->GetEntry(), it->GetProto()->Name1, pl->GetName(), location);
319
320    SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, AUCTION_OK);
321}
322
323//this function is called when client bids or buys out auction
324void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
325{
326    CHECK_PACKET_SIZE(recv_data,8+4+4);
327
328    uint64 auctioneer;
329    uint32 auctionId;
330    uint32 price;
331    recv_data >> auctioneer;
332    recv_data >> auctionId >> price;
333
334    if (!auctionId || !price)
335        return;                                             //check for cheaters
336
337    Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
338    if (!pCreature)
339    {
340        sLog.outDebug( "WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) );
341        return;
342    }
343
344    // remove fake death
345    if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
346        GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
347
348    uint32 location = AuctioneerFactionToLocation(pCreature->getFaction());
349
350    AuctionHouseObject * mAuctions;
351    mAuctions = objmgr.GetAuctionsMap( location );
352
353    AuctionEntry *auction = mAuctions->GetAuction(auctionId);
354    Player *pl = GetPlayer();
355
356    if( !auction || auction->owner == pl->GetGUIDLow() )
357    {
358        //you cannot bid your own auction:
359        SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR );
360        return;
361    }
362
363    // impossible have online own another character (use this for speedup check in case online owner)
364    Player* auction_owner = objmgr.GetPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER));
365    if( !auction_owner && objmgr.GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == pl->GetSession()->GetAccountId())
366    {
367        //you cannot bid your another character auction:
368        SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR );
369        return;
370    }
371
372    if (price < (auction->bid + objmgr.GetAuctionOutBid(auction->bid)))
373    {
374        //auction has already higher bid, client tests it!
375        //SendAuctionCommandResult(auction->auctionId, AUCTION_PLACE_BID, ???);
376        return;
377    }
378
379    if (price > pl->GetMoney())
380    {
381        //you don't have enought money!, client tests!
382        //SendAuctionCommandResult(auction->auctionId, AUCTION_PLACE_BID, ???);
383        return;
384    }
385
386    if ((price < auction->buyout) || (auction->buyout == 0))
387    {
388        if (auction->bidder > 0)
389        {
390            if ( auction->bidder == pl->GetGUIDLow() )
391            {
392                pl->ModifyMoney( -int32(price - auction->bid));
393            }
394            else
395            {
396                // mail to last bidder and return money
397                SendAuctionOutbiddedMail( auction , price );
398                pl->ModifyMoney( -int32(price) );
399            }
400        }
401        else
402        {
403            pl->ModifyMoney( -int32(price) );
404        }
405        auction->bidder = pl->GetGUIDLow();
406        auction->bid = price;
407
408        // after this update we should save player's money ...
409        CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id);
410
411        SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK, 0 );
412    }
413    else
414    {
415        //buyout:
416        if (pl->GetGUIDLow() == auction->bidder )
417        {
418            pl->ModifyMoney(-int32(auction->buyout - auction->bid));
419        }
420        else
421        {
422            pl->ModifyMoney(-int32(auction->buyout));
423            if ( auction->bidder )                          //buyout for bidded auction ..
424            {
425                SendAuctionOutbiddedMail( auction, auction->buyout );
426            }
427        }
428        auction->bidder = pl->GetGUIDLow();
429        auction->bid = auction->buyout;
430
431        objmgr.SendAuctionSalePendingMail( auction );
432        objmgr.SendAuctionSuccessfulMail( auction );
433        objmgr.SendAuctionWonMail( auction );
434
435        SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK);
436
437        objmgr.RemoveAItem(auction->item_guidlow);
438        mAuctions->RemoveAuction(auction->Id);
439        CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE id = '%u'",auction->Id);
440
441        delete auction;
442    }
443    CharacterDatabase.BeginTransaction();
444    pl->SaveInventoryAndGoldToDB();
445    CharacterDatabase.CommitTransaction();
446}
447
448//this void is called when auction_owner cancels his auction
449void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data )
450{
451    CHECK_PACKET_SIZE(recv_data,8+4);
452
453    uint64 auctioneer;
454    uint32 auctionId;
455    recv_data >> auctioneer;
456    recv_data >> auctionId;
457    //sLog.outDebug( "Cancel AUCTION AuctionID: %u", auctionId);
458
459    Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
460    if (!pCreature)
461    {
462        sLog.outDebug( "WORLD: HandleAuctionRemoveItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) );
463        return;
464    }
465
466    // remove fake death
467    if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
468        GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
469
470    uint32 location = AuctioneerFactionToLocation(pCreature->getFaction());
471
472    AuctionHouseObject * mAuctions;
473    mAuctions = objmgr.GetAuctionsMap( location );
474
475    AuctionEntry *auction = mAuctions->GetAuction(auctionId);
476    Player *pl = GetPlayer();
477
478    if (auction && auction->owner == pl->GetGUIDLow())
479    {
480        Item *pItem = objmgr.GetAItem(auction->item_guidlow);
481        if (pItem)
482        {
483            if (auction->bidder > 0)                        // If we have a bidder, we have to send him the money he paid
484            {
485                uint32 auctionCut = objmgr.GetAuctionCut( auction->location, auction->bid);
486                if ( pl->GetMoney() < auctionCut )          //player doesn't have enough money, maybe message needed
487                    return;
488                //some auctionBidderNotification would be needed, but don't know that parts..
489                SendAuctionCancelledToBidderMail( auction );
490                pl->ModifyMoney( -int32(auctionCut) );
491            }
492            // Return the item by mail
493            std::ostringstream msgAuctionCanceledOwner;
494            msgAuctionCanceledOwner << auction->item_template << ":0:" << AUCTION_CANCELED;
495
496            MailItemsInfo mi;
497            mi.AddItem(auction->item_guidlow, auction->item_template, pItem);
498
499            // item will deleted or added to received mail list
500            WorldSession::SendMailTo(pl, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, pl->GetGUIDLow(), msgAuctionCanceledOwner.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
501        }
502        else
503        {
504            sLog.outError("Auction id: %u has non-existed item (item guid : %u)!!!", auction->Id, auction->item_guidlow);
505            SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR );
506            return;
507        }
508    }
509    else
510    {
511        SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR );
512        //this code isn't possible ... maybe there should be assert
513        sLog.outError("CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", pl->GetGUIDLow(), auctionId );
514        return;
515    }
516
517    //inform player, that auction is removed
518    SendAuctionCommandResult( auction->Id, AUCTION_CANCEL, AUCTION_OK );
519    // Now remove the auction
520    CharacterDatabase.BeginTransaction();
521    CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE id = '%u'",auction->Id);
522    pl->SaveInventoryAndGoldToDB();
523    CharacterDatabase.CommitTransaction();
524    objmgr.RemoveAItem( auction->item_guidlow );
525    mAuctions->RemoveAuction( auction->Id );
526    delete auction;
527}
528
529//called when player lists his bids
530void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data )
531{
532    CHECK_PACKET_SIZE(recv_data,8+4+4);
533
534    uint64 guid;                                            //NPC guid
535    uint32 listfrom;                                        //page of auctions
536    uint32 outbiddedCount;                                  //count of outbidded auctions
537
538    recv_data >> guid;
539    recv_data >> listfrom;                                  // not used in fact (this list not have page control in client)
540    recv_data >> outbiddedCount;
541    if (recv_data.size() != (16 + outbiddedCount * 4 ))
542    {
543        sLog.outError("Client sent bad opcode!!! with count: %u and size : %d (mustbe: %d", outbiddedCount, recv_data.size(),(16 + outbiddedCount * 4 ));
544        outbiddedCount = 0;
545    }
546
547    Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER);
548    if (!pCreature)
549    {
550        sLog.outDebug( "WORLD: HandleAuctionListBidderItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
551        return;
552    }
553
554    // remove fake death
555    if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
556        GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
557
558    uint32 location = AuctioneerFactionToLocation(pCreature->getFaction());
559    AuctionHouseObject* mAuctions = objmgr.GetAuctionsMap( location );
560
561    WorldPacket data( SMSG_AUCTION_BIDDER_LIST_RESULT, (4+4+4) );
562    Player *pl = GetPlayer();
563    data << (uint32) 0;                                     //add 0 as count
564    uint32 count = 0;
565    uint32 totalcount = 0;
566    while ( outbiddedCount > 0)                             //add all data, which client requires
567    {
568        --outbiddedCount;
569        uint32 outbiddedAuctionId;
570        recv_data >> outbiddedAuctionId;
571        AuctionEntry * auction = mAuctions->GetAuction( outbiddedAuctionId );
572        if ( auction && SendAuctionInfo(data, auction))
573        {
574            ++totalcount;
575            ++count;
576        }
577    }
578    for (AuctionHouseObject::AuctionEntryMap::iterator itr = mAuctions->GetAuctionsBegin();itr != mAuctions->GetAuctionsEnd();++itr)
579    {
580        AuctionEntry *Aentry = itr->second;
581        if( Aentry && Aentry->bidder == pl->GetGUIDLow() )
582        {
583            if (SendAuctionInfo(data, itr->second))
584                ++count;
585            ++totalcount;
586        }
587    }
588    data.put<uint32>( 0, count );                           // add count to placeholder
589    data << totalcount;
590    data << (uint32)300;                                    //unk 2.3.0
591    SendPacket(&data);
592}
593
594//this void sends player info about his auctions
595void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data )
596{
597    CHECK_PACKET_SIZE(recv_data,8+4);
598
599    uint32 listfrom;
600    uint64 guid;
601
602    recv_data >> guid;
603    recv_data >> listfrom;                                  // not used in fact (this list not have page control in client)
604
605    Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER);
606    if (!pCreature)
607    {
608        sLog.outDebug( "WORLD: HandleAuctionListOwnerItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
609        return;
610    }
611
612    // remove fake death
613    if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
614        GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
615
616    uint32 location = AuctioneerFactionToLocation(pCreature->getFaction());
617
618    AuctionHouseObject* mAuctions = objmgr.GetAuctionsMap( location );
619
620    WorldPacket data( SMSG_AUCTION_OWNER_LIST_RESULT, (4+4+4) );
621    data << (uint32) 0;                                     // amount place holder
622
623    uint32 count = 0;
624    uint32 totalcount = 0;
625    for (AuctionHouseObject::AuctionEntryMap::iterator itr = mAuctions->GetAuctionsBegin();itr != mAuctions->GetAuctionsEnd();++itr)
626    {
627        AuctionEntry *Aentry = itr->second;
628        if( Aentry && Aentry->owner == _player->GetGUIDLow() )
629        {
630            if(SendAuctionInfo(data, itr->second))
631                ++count;
632            ++totalcount;
633        }
634    }
635    data.put<uint32>(0, count);
636    data << (uint32) totalcount;
637    data << (uint32) 0;
638    SendPacket(&data);
639}
640
641//this void is called when player clicks on search button
642void WorldSession::HandleAuctionListItems( WorldPacket & recv_data )
643{
644    CHECK_PACKET_SIZE(recv_data,8+4+1+1+1+4+4+4+4+1);
645
646    std::string searchedname, name;
647    uint8 levelmin, levelmax, usable, location;
648    uint32 count, totalcount, listfrom, auctionSlotID, auctionMainCategory, auctionSubCategory, quality;
649    uint64 guid;
650
651    recv_data >> guid;
652    recv_data >> listfrom;                                  // start, used for page control listing by 50 elements
653    recv_data >> searchedname;
654
655    // recheck with known string size
656    CHECK_PACKET_SIZE(recv_data,8+4+(searchedname.size()+1)+1+1+4+4+4+4+1);
657
658    recv_data >> levelmin >> levelmax;
659    recv_data >> auctionSlotID >> auctionMainCategory >> auctionSubCategory;
660    recv_data >> quality >> usable;
661
662    Creature *pCreature = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_AUCTIONEER);
663    if (!pCreature)
664    {
665        sLog.outDebug( "WORLD: HandleAuctionListItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
666        return;
667    }
668
669    // remove fake death
670    if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
671        GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
672
673    location = AuctioneerFactionToLocation(pCreature->getFaction());
674    AuctionHouseObject * mAuctions;
675    mAuctions = objmgr.GetAuctionsMap( location );
676
677    //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);
678
679    WorldPacket data( SMSG_AUCTION_LIST_RESULT, (4+4+4) );
680    count = 0;
681    totalcount = 0;
682    data << (uint32) 0;
683
684    // converting string that we try to find to lower case
685    std::wstring wsearchedname;
686    if(!Utf8toWStr(searchedname,wsearchedname))
687        return;
688
689    wstrToLower(wsearchedname);
690
691    for (AuctionHouseObject::AuctionEntryMap::iterator itr = mAuctions->GetAuctionsBegin();itr != mAuctions->GetAuctionsEnd();++itr)
692    {
693        AuctionEntry *Aentry = itr->second;
694        Item *item = objmgr.GetAItem(Aentry->item_guidlow);
695        if( item )
696        {
697            ItemPrototype const *proto = item->GetProto();
698            if( proto )
699            {
700                if( auctionMainCategory == (0xffffffff) || proto->Class == auctionMainCategory )
701                {
702                    if( auctionSubCategory == (0xffffffff) || proto->SubClass == auctionSubCategory )
703                    {
704                        if( auctionSlotID == (0xffffffff) || proto->InventoryType == auctionSlotID )
705                        {
706                            if( quality == (0xffffffff) || proto->Quality == quality )
707                            {
708                                if( usable == (0x00) || _player->CanUseItem( item ) == EQUIP_ERR_OK )
709                                {
710                                    if( ( levelmin == (0x00) || proto->RequiredLevel >= levelmin ) && ( levelmax == (0x00) || proto->RequiredLevel <= levelmax ) )
711                                    {
712                                        name = proto->Name1;
713
714                                        // local name
715                                        int loc_idx = GetSessionDbLocaleIndex();
716                                        if ( loc_idx >= 0 )
717                                        {
718                                            ItemLocale const *il = objmgr.GetItemLocale(proto->ItemId);
719                                            if (il)
720                                            {
721                                                if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
722                                                    name = il->Name[loc_idx];
723                                            }
724                                        }
725
726                                        if(name.empty())
727                                            continue;
728
729                                        if( wsearchedname.empty() || Utf8FitTo(name, wsearchedname) )
730                                        {
731                                            if ((count < 50) && (totalcount >= listfrom))
732                                            {
733                                                ++count;
734                                                SendAuctionInfo( data, Aentry);
735                                            }
736                                            ++totalcount;
737                                        }
738                                    }
739                                }
740                            }
741                        }
742                    }
743                }
744            }
745        }
746    }
747    data.put<uint32>(0, count);
748    data << (uint32) totalcount;
749    data << (uint32) 300;                                   // unk 2.3.0 const?
750    SendPacket(&data);
751}
Note: See TracBrowser for help on using the browser.