TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AuctionHouseMgr Class Reference

#include <AuctionHouseMgr.h>

Public Types

typedef std::unordered_map
< ObjectGuid::LowType, Item * > 
ItemMap
 
typedef std::vector
< AuctionEntry * > 
PlayerAuctions
 
typedef std::pair
< PlayerAuctions *, uint32
AuctionPair
 

Public Member Functions

AuctionHouseObjectGetAuctionsMap (uint32 factionTemplateId)
 
AuctionHouseObjectGetBidsMap (uint32 factionTemplateId)
 
ItemGetAItem (ObjectGuid::LowType id)
 
void SendAuctionWonMail (AuctionEntry *auction, SQLTransaction &trans)
 
void SendAuctionSalePendingMail (AuctionEntry *auction, SQLTransaction &trans)
 
void SendAuctionSuccessfulMail (AuctionEntry *auction, SQLTransaction &trans)
 
void SendAuctionExpiredMail (AuctionEntry *auction, SQLTransaction &trans)
 
void SendAuctionOutbiddedMail (AuctionEntry *auction, uint32 newPrice, Player *newBidder, SQLTransaction &trans)
 
void SendAuctionCancelledToBidderMail (AuctionEntry *auction, SQLTransaction &trans)
 
void LoadAuctionItems ()
 
void LoadAuctions ()
 
void AddAItem (Item *it)
 
bool RemoveAItem (ObjectGuid::LowType id, bool deleteItem=false)
 
void PendingAuctionAdd (Player *player, AuctionEntry *aEntry)
 
uint32 PendingAuctionCount (const Player *player) const
 
void PendingAuctionProcess (Player *player)
 
void UpdatePendingAuctions ()
 
void Update ()
 

Static Public Member Functions

static AuctionHouseMgrinstance ()
 
static uint32 GetAuctionDeposit (AuctionHouseEntry const *entry, uint32 time, Item *pItem, uint32 count)
 
static AuctionHouseEntry constGetAuctionHouseEntry (uint32 factionTemplateId)
 

Private Member Functions

 AuctionHouseMgr ()
 
 ~AuctionHouseMgr ()
 

Private Attributes

AuctionHouseObject mHordeAuctions
 
AuctionHouseObject mAllianceAuctions
 
AuctionHouseObject mNeutralAuctions
 
std::map< ObjectGuid, AuctionPairpendingAuctionMap
 
ItemMap mAitems
 

Member Typedef Documentation

typedef std::unordered_map<ObjectGuid::LowType, Item*> AuctionHouseMgr::ItemMap

Constructor & Destructor Documentation

AuctionHouseMgr::AuctionHouseMgr ( )
private
40 { }
AuctionHouseMgr::~AuctionHouseMgr ( )
private
43 {
44  for (ItemMap::iterator itr = mAitems.begin(); itr != mAitems.end(); ++itr)
45  delete itr->second;
46 }
ItemMap mAitems
Definition: AuctionHouseMgr.h:196

Member Function Documentation

void AuctionHouseMgr::AddAItem ( Item it)
376 {
377  ASSERT(it);
378  ASSERT(mAitems.count(it->GetGUID().GetCounter()) == 0);
379  mAitems[it->GetGUID().GetCounter()] = it;
380 }
ItemMap mAitems
Definition: AuctionHouseMgr.h:196
ObjectGuid const & GetGUID() const
Definition: Object.h:105
#define ASSERT
Definition: Errors.h:55
LowType GetCounter() const
Definition: ObjectGuid.h:221

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Item* AuctionHouseMgr::GetAItem ( ObjectGuid::LowType  id)
inline
155  {
156  ItemMap::const_iterator itr = mAitems.find(id);
157  if (itr != mAitems.end())
158  return itr->second;
159 
160  return NULL;
161  }
ItemMap mAitems
Definition: AuctionHouseMgr.h:196
arena_t NULL
Definition: jemalloc_internal.h:624

+ Here is the caller graph for this function:

uint32 AuctionHouseMgr::GetAuctionDeposit ( AuctionHouseEntry const entry,
uint32  time,
Item pItem,
uint32  count 
)
static
72 {
73  uint32 MSV = pItem->GetTemplate()->GetSellPrice();
74 
75  if (MSV <= 0)
77 
78  float multiplier = CalculatePct(float(entry->DepositRate), 3);
79  uint32 timeHr = (((time / 60) / 60) / 12);
80  uint32 deposit = uint32(MSV * multiplier * sWorld->getRate(RATE_AUCTION_DEPOSIT));
81  float remainderbase = float(MSV * multiplier * sWorld->getRate(RATE_AUCTION_DEPOSIT)) - deposit;
82 
83  deposit *= timeHr * count;
84 
85  int i = count;
86  while (i > 0 && (remainderbase * i) != uint32(remainderbase * i))
87  i--;
88 
89  if (i)
90  deposit += remainderbase * i * timeHr;
91 
92  TC_LOG_DEBUG("auctionHouse", "MSV: %u", MSV);
93  TC_LOG_DEBUG("auctionHouse", "Items: %u", count);
94  TC_LOG_DEBUG("auctionHouse", "Multiplier: %f", multiplier);
95  TC_LOG_DEBUG("auctionHouse", "Deposit: %u", deposit);
96  TC_LOG_DEBUG("auctionHouse", "Deposit rm: %f", remainderbase * count);
97 
98  if (deposit < AH_MINIMUM_DEPOSIT * sWorld->getRate(RATE_AUCTION_DEPOSIT))
100  else
101  return deposit;
102 }
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
#define sWorld
Definition: World.h:887
Definition: AuctionHouseMgr.cpp:37
uint32 GetSellPrice() const
Definition: ItemTemplate.h:663
uint32_t uint32
Definition: Define.h:150
Definition: World.h:433
T CalculatePct(T base, U pct)
Definition: Util.h:92
uint32_t uint32
Definition: g3dmath.h:168
ItemTemplate const * GetTemplate() const
Definition: Item.cpp:547

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AuctionHouseEntry const * AuctionHouseMgr::GetAuctionHouseEntry ( uint32  factionTemplateId)
static
517 {
518  uint32 houseid = 7; // goblin auction house
519 
521  {
522  // FIXME: found way for proper auctionhouse selection by another way
523  // AuctionHouse.dbc have faction field with _player_ factions associated with auction house races.
524  // but no easy way convert creature faction to player race faction for specific city
525  switch (factionTemplateId)
526  {
527  case 12: houseid = 1; break; // human
528  case 29: houseid = 6; break; // orc, and generic for horde
529  case 55: houseid = 2; break; // dwarf, and generic for alliance
530  case 68: houseid = 4; break; // undead
531  case 80: houseid = 3; break; // n-elf
532  case 104: houseid = 5; break; // trolls
533  case 120: houseid = 7; break; // booty bay, neutral
534  case 474: houseid = 7; break; // gadgetzan, neutral
535  case 855: houseid = 7; break; // everlook, neutral
536  case 1604: houseid = 6; break; // b-elfs,
537  default: // for unknown case
538  {
539  FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId);
540  if (!u_entry)
541  houseid = 7; // goblin auction house
542  else if (u_entry->Mask & FACTION_MASK_ALLIANCE)
543  houseid = 1; // human auction house
544  else if (u_entry->Mask & FACTION_MASK_HORDE)
545  houseid = 6; // orc auction house
546  else
547  houseid = 7; // goblin auction house
548  break;
549  }
550  }
551  }
552 
553  return sAuctionHouseStore.LookupEntry(houseid);
554 }
Definition: DBCEnums.h:470
DB2Storage< AuctionHouseEntry > sAuctionHouseStore("AuctionHouse.db2", AuctionHouseFormat, HOTFIX_SEL_AUCTION_HOUSE)
#define sWorld
Definition: World.h:887
uint32_t uint32
Definition: Define.h:150
Definition: DBCStructure.h:433
uint32 Mask
Definition: DBCStructure.h:438
DBCStorage< FactionTemplateEntry > sFactionTemplateStore(FactionTemplatefmt)
Definition: DBCEnums.h:471

+ Here is the caller graph for this function:

AuctionHouseObject * AuctionHouseMgr::GetAuctionsMap ( uint32  factionTemplateId)
55 {
57  return &mNeutralAuctions;
58 
59  // teams have linked auction houses
60  FactionTemplateEntry const* uEntry = sFactionTemplateStore.LookupEntry(factionTemplateId);
61  if (!uEntry)
62  return &mNeutralAuctions;
63  else if (uEntry->Mask & FACTION_MASK_ALLIANCE)
64  return &mAllianceAuctions;
65  else if (uEntry->Mask & FACTION_MASK_HORDE)
66  return &mHordeAuctions;
67  else
68  return &mNeutralAuctions;
69 }
Definition: DBCEnums.h:470
AuctionHouseObject mNeutralAuctions
Definition: AuctionHouseMgr.h:192
#define sWorld
Definition: World.h:887
AuctionHouseObject mAllianceAuctions
Definition: AuctionHouseMgr.h:191
Definition: DBCStructure.h:433
uint32 Mask
Definition: DBCStructure.h:438
DBCStorage< FactionTemplateEntry > sFactionTemplateStore(FactionTemplatefmt)
AuctionHouseObject mHordeAuctions
Definition: AuctionHouseMgr.h:190
Definition: DBCEnums.h:471

+ Here is the caller graph for this function:

AuctionHouseObject* AuctionHouseMgr::GetBidsMap ( uint32  factionTemplateId)
AuctionHouseMgr * AuctionHouseMgr::instance ( )
static
49 {
51  return &instance;
52 }
static AuctionHouseMgr * instance()
Definition: AuctionHouseMgr.cpp:48
Definition: AuctionHouseMgr.h:138
void AuctionHouseMgr::LoadAuctionItems ( )
284 {
285  uint32 oldMSTime = getMSTime();
286 
287  // need to clear in case we are reloading
288  if (!mAitems.empty())
289  {
290  for (ItemMap::iterator itr = mAitems.begin(); itr != mAitems.end(); ++itr)
291  delete itr->second;
292 
293  mAitems.clear();
294  }
295 
296  // data needs to be at first place for Item::LoadFromDB
299 
300  if (!result)
301  {
302  TC_LOG_INFO("server.loading", ">> Loaded 0 auction items. DB table `auctionhouse` or `item_instance` is empty!");
303  return;
304  }
305 
306  uint32 count = 0;
307 
308  do
309  {
310  Field* fields = result->Fetch();
311 
312  ObjectGuid::LowType itemGuid = fields[0].GetUInt64();
313  uint32 itemEntry = fields[1].GetUInt32();
314 
315  ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemEntry);
316  if (!proto)
317  {
318  TC_LOG_ERROR("misc", "AuctionHouseMgr::LoadAuctionItems: Unknown item (GUID: " UI64FMTD " item entry: #%u) in auction, skipped.", itemGuid, itemEntry);
319  continue;
320  }
321 
322  Item* item = NewItemOrBag(proto);
323  if (!item->LoadFromDB(itemGuid, ObjectGuid::Empty, fields, itemEntry))
324  {
325  delete item;
326  continue;
327  }
328  AddAItem(item);
329 
330  ++count;
331  }
332  while (result->NextRow());
333 
334  TC_LOG_INFO("server.loading", ">> Loaded %u auction items in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
335 }
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
uint64 GetUInt64() const
Definition: Field.h:184
ItemMap mAitems
Definition: AuctionHouseMgr.h:196
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 getMSTime()
Definition: Timer.h:24
virtual bool LoadFromDB(ObjectGuid::LowType guid, ObjectGuid ownerGuid, Field *fields, uint32 entry)
Definition: Item.cpp:411
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: PreparedStatement.h:74
Item * NewItemOrBag(ItemTemplate const *proto)
Definition: Bag.h:69
void AddAItem(Item *it)
Definition: AuctionHouseMgr.cpp:375
Definition: Item.h:259
#define UI64FMTD
Definition: Define.h:137
uint32_t uint32
Definition: Define.h:150
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
Definition: ItemTemplate.h:647
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: CharacterDatabase.h:121

+ Here is the call graph for this function:

void AuctionHouseMgr::LoadAuctions ( )
338 {
339  uint32 oldMSTime = getMSTime();
340 
343 
344  if (!result)
345  {
346  TC_LOG_INFO("server.loading", ">> Loaded 0 auctions. DB table `auctionhouse` is empty.");
347  return;
348  }
349 
350  uint32 count = 0;
351 
353  do
354  {
355  Field* fields = result->Fetch();
356 
357  AuctionEntry* aItem = new AuctionEntry();
358  if (!aItem->LoadFromDB(fields))
359  {
360  aItem->DeleteFromDB(trans);
361  delete aItem;
362  continue;
363  }
364 
366  ++count;
367  } while (result->NextRow());
368 
370 
371  TC_LOG_INFO("server.loading", ">> Loaded %u auctions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
372 
373 }
Definition: CharacterDatabase.h:125
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Class used to access individual fields of database query result.
Definition: Field.h:56
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
uint32 getMSTime()
Definition: Timer.h:24
Definition: AuctionHouseMgr.h:67
void DeleteFromDB(SQLTransaction &trans) const
Definition: AuctionHouseMgr.cpp:800
Definition: PreparedStatement.h:74
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
AuctionHouseObject * GetAuctionsMap(uint32 factionTemplateId)
Definition: AuctionHouseMgr.cpp:54
uint32_t uint32
Definition: Define.h:150
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 factionTemplateId
Definition: AuctionHouseMgr.h:83
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
void AddAuction(AuctionEntry *auction)
Definition: AuctionHouseMgr.cpp:556
bool LoadFromDB(Field *fields)
Definition: AuctionHouseMgr.cpp:823
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

void AuctionHouseMgr::PendingAuctionAdd ( Player player,
AuctionEntry aEntry 
)
400 {
401  PlayerAuctions* thisAH;
402  auto itr = pendingAuctionMap.find(player->GetGUID());
403  if (itr != pendingAuctionMap.end())
404  thisAH = itr->second.first;
405  else
406  {
407  thisAH = new PlayerAuctions;
408  pendingAuctionMap[player->GetGUID()] = AuctionPair(thisAH, 0);
409  }
410  thisAH->push_back(aEntry);
411 }
std::pair< PlayerAuctions *, uint32 > AuctionPair
Definition: AuctionHouseMgr.h:149
std::map< ObjectGuid, AuctionPair > pendingAuctionMap
Definition: AuctionHouseMgr.h:194
std::vector< AuctionEntry * > PlayerAuctions
Definition: AuctionHouseMgr.h:148
uint32 AuctionHouseMgr::PendingAuctionCount ( const Player player) const
414 {
415  auto const itr = pendingAuctionMap.find(player->GetGUID());
416  if (itr != pendingAuctionMap.end())
417  return itr->second.first->size();
418 
419  return 0;
420 }
std::map< ObjectGuid, AuctionPair > pendingAuctionMap
Definition: AuctionHouseMgr.h:194

+ Here is the caller graph for this function:

void AuctionHouseMgr::PendingAuctionProcess ( Player player)
423 {
424  auto iterMap = pendingAuctionMap.find(player->GetGUID());
425  if (iterMap == pendingAuctionMap.end())
426  return;
427 
428  PlayerAuctions* thisAH = iterMap->second.first;
429 
431 
432  uint32 totalItems = 0;
433  for (auto itrAH = thisAH->begin(); itrAH != thisAH->end(); ++itrAH)
434  {
435  AuctionEntry* AH = (*itrAH);
436  totalItems += AH->itemCount;
437  }
438 
439  uint32 totaldeposit = 0;
440  auto itr = (*thisAH->begin());
441 
442  if (Item* item = GetAItem(itr->itemGUIDLow))
443  totaldeposit = GetAuctionDeposit(itr->auctionHouseEntry, itr->etime, item, totalItems);
444 
445  uint32 depositremain = totaldeposit;
446  for (auto itr = thisAH->begin(); itr != thisAH->end(); ++itr)
447  {
448  AuctionEntry* AH = (*itr);
449 
450  if (next(itr) == thisAH->end())
451  AH->deposit = depositremain;
452  else
453  {
454  AH->deposit = totaldeposit / thisAH->size();
455  depositremain -= AH->deposit;
456  }
457 
458  AH->DeleteFromDB(trans);
459  AH->SaveToDB(trans);
460  }
461 
463  pendingAuctionMap.erase(player->GetGUID());
464  delete thisAH;
465  player->ModifyMoney(-int32(totaldeposit));
466 }
void SaveToDB(SQLTransaction &trans) const
Definition: AuctionHouseMgr.cpp:807
uint32 itemCount
Definition: AuctionHouseMgr.h:73
int next(int i, int n)
Definition: RecastContour.cpp:469
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
Definition: AuctionHouseMgr.h:67
void DeleteFromDB(SQLTransaction &trans) const
Definition: AuctionHouseMgr.cpp:800
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
Definition: Item.h:259
uint32_t uint32
Definition: Define.h:150
Item * GetAItem(ObjectGuid::LowType id)
Definition: AuctionHouseMgr.h:154
std::map< ObjectGuid, AuctionPair > pendingAuctionMap
Definition: AuctionHouseMgr.h:194
int32_t int32
Definition: g3dmath.h:167
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
std::vector< AuctionEntry * > PlayerAuctions
Definition: AuctionHouseMgr.h:148
uint32 deposit
Definition: AuctionHouseMgr.h:80
static uint32 GetAuctionDeposit(AuctionHouseEntry const *entry, uint32 time, Item *pItem, uint32 count)
Definition: AuctionHouseMgr.cpp:71
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool AuctionHouseMgr::RemoveAItem ( ObjectGuid::LowType  id,
bool  deleteItem = false 
)
383 {
384  ItemMap::iterator i = mAitems.find(id);
385  if (i == mAitems.end())
386  return false;
387 
388  if (deleteItem)
389  {
390  SQLTransaction trans = SQLTransaction(nullptr);
391  i->second->FSetState(ITEM_REMOVED);
392  i->second->SaveToDB(trans);
393  }
394 
395  mAitems.erase(i);
396  return true;
397 }
ItemMap mAitems
Definition: AuctionHouseMgr.h:196
Definition: Item.h:219
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58
void AuctionHouseMgr::SendAuctionCancelledToBidderMail ( AuctionEntry auction,
SQLTransaction trans 
)
267 {
268  ObjectGuid bidder_guid = ObjectGuid::Create<HighGuid::Player>(auction->bidder);
269  Player* bidder = ObjectAccessor::FindConnectedPlayer(bidder_guid);
270 
271  uint32 bidder_accId = 0;
272 
273  if (!bidder)
274  bidder_accId = ObjectMgr::GetPlayerAccountIdByGUID(bidder_guid);
275 
276  // bidder exist
277  if (bidder || bidder_accId)
279  .AddMoney(auction->bid)
280  .SendMailTo(trans, MailReceiver(bidder, auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
281 }
static std::string BuildAuctionMailBody(uint64 lowGuid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut)
Definition: AuctionHouseMgr.cpp:877
This mail was returned. Do not allow returning mail back again.
Definition: Mail.h:50
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition: Mail.cpp:173
Definition: Mail.h:118
std::string BuildAuctionMailSubject(MailAuctionAnswers response) const
Definition: AuctionHouseMgr.cpp:870
ObjectGuid::LowType owner
Definition: AuctionHouseMgr.h:74
Definition: AuctionHouseMgr.h:62
uint32_t uint32
Definition: Define.h:150
uint32 bid
Definition: AuctionHouseMgr.h:76
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
uint32 buyout
Definition: AuctionHouseMgr.h:77
static uint32 GetPlayerAccountIdByGUID(ObjectGuid const &guid)
Definition: ObjectMgr.cpp:2302
Definition: ObjectGuid.h:189
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
Definition: Mail.h:104
uint32 deposit
Definition: AuctionHouseMgr.h:80

+ Here is the call graph for this function:

void AuctionHouseMgr::SendAuctionExpiredMail ( AuctionEntry auction,
SQLTransaction trans 
)
215 {
216  //return an item in auction to its owner by mail
217  Item* item = GetAItem(auction->itemGUIDLow);
218  if (!item)
219  return;
220 
221  ObjectGuid owner_guid = ObjectGuid::Create<HighGuid::Player>(auction->owner);
222  Player* owner = ObjectAccessor::FindConnectedPlayer(owner_guid);
223  uint32 owner_accId = ObjectMgr::GetPlayerAccountIdByGUID(owner_guid);
224  // owner exist
225  if (owner || owner_accId)
226  {
227  if (owner)
228  owner->GetSession()->SendAuctionClosedNotification(auction, 0.0f, false, item);
229 
231  .AddItem(item)
232  .SendMailTo(trans, MailReceiver(owner, auction->owner), auction, MAIL_CHECK_MASK_COPIED, 0);
233  }
234  else
235  {
236  // owner doesn't exist, delete the item
237  sAuctionMgr->RemoveAItem(auction->itemGUIDLow, true);
238  }
239 }
Definition: AuctionHouseMgr.h:61
ObjectGuid::LowType itemGUIDLow
Definition: AuctionHouseMgr.h:71
static std::string BuildAuctionMailBody(uint64 lowGuid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut)
Definition: AuctionHouseMgr.cpp:877
This mail was returned. Do not allow returning mail back again.
Definition: Mail.h:50
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition: Mail.cpp:173
Definition: Mail.h:118
std::string BuildAuctionMailSubject(MailAuctionAnswers response) const
Definition: AuctionHouseMgr.cpp:870
ObjectGuid::LowType owner
Definition: AuctionHouseMgr.h:74
Definition: Item.h:259
uint32_t uint32
Definition: Define.h:150
Item * GetAItem(ObjectGuid::LowType id)
Definition: AuctionHouseMgr.h:154
uint32 buyout
Definition: AuctionHouseMgr.h:77
#define sAuctionMgr
Definition: AuctionHouseMgr.h:199
static uint32 GetPlayerAccountIdByGUID(ObjectGuid const &guid)
Definition: ObjectMgr.cpp:2302
Definition: ObjectGuid.h:189
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
Definition: Mail.h:104
uint32 deposit
Definition: AuctionHouseMgr.h:80

+ Here is the call graph for this function:

void AuctionHouseMgr::SendAuctionOutbiddedMail ( AuctionEntry auction,
uint32  newPrice,
Player newBidder,
SQLTransaction trans 
)
243 {
244  ObjectGuid oldBidder_guid = ObjectGuid::Create<HighGuid::Player>(auction->bidder);
245  Player* oldBidder = ObjectAccessor::FindConnectedPlayer(oldBidder_guid);
246 
247  uint32 oldBidder_accId = 0;
248  if (!oldBidder)
249  oldBidder_accId = ObjectMgr::GetPlayerAccountIdByGUID(oldBidder_guid);
250 
251  Item* item = GetAItem(auction->itemGUIDLow);
252 
253  // old bidder exist
254  if (oldBidder || oldBidder_accId)
255  {
256  if (oldBidder && item)
257  oldBidder->GetSession()->SendAuctionOutBidNotification(auction, item);
258 
259  MailDraft(auction->BuildAuctionMailSubject(AUCTION_OUTBIDDED), AuctionEntry::BuildAuctionMailBody(auction->owner, auction->bid, auction->buyout, auction->deposit, auction->GetAuctionCut()))
260  .AddMoney(auction->bid)
261  .SendMailTo(trans, MailReceiver(oldBidder, auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
262  }
263 }
Definition: AuctionHouseMgr.h:58
ObjectGuid::LowType itemGUIDLow
Definition: AuctionHouseMgr.h:71
static std::string BuildAuctionMailBody(uint64 lowGuid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut)
Definition: AuctionHouseMgr.cpp:877
This mail was returned. Do not allow returning mail back again.
Definition: Mail.h:50
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition: Mail.cpp:173
Definition: Mail.h:118
std::string BuildAuctionMailSubject(MailAuctionAnswers response) const
Definition: AuctionHouseMgr.cpp:870
ObjectGuid::LowType owner
Definition: AuctionHouseMgr.h:74
Definition: Item.h:259
uint32_t uint32
Definition: Define.h:150
uint32 bid
Definition: AuctionHouseMgr.h:76
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
Item * GetAItem(ObjectGuid::LowType id)
Definition: AuctionHouseMgr.h:154
uint32 GetAuctionCut() const
Definition: AuctionHouseMgr.cpp:787
uint32 buyout
Definition: AuctionHouseMgr.h:77
MailDraft & AddMoney(uint64 money)
Definition: Mail.h:137
static uint32 GetPlayerAccountIdByGUID(ObjectGuid const &guid)
Definition: ObjectMgr.cpp:2302
Definition: ObjectGuid.h:189
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
Definition: Mail.h:104
uint32 deposit
Definition: AuctionHouseMgr.h:80

+ Here is the call graph for this function:

void AuctionHouseMgr::SendAuctionSalePendingMail ( AuctionEntry auction,
SQLTransaction trans 
)
175 {
176  ObjectGuid owner_guid = ObjectGuid::Create<HighGuid::Player>(auction->owner);
177  Player* owner = ObjectAccessor::FindConnectedPlayer(owner_guid);
178  uint32 owner_accId = ObjectMgr::GetPlayerAccountIdByGUID(owner_guid);
179  // owner exist (online or offline)
180  if (owner || owner_accId)
182  .SendMailTo(trans, MailReceiver(owner, auction->owner), auction, MAIL_CHECK_MASK_COPIED);
183 }
static std::string BuildAuctionMailBody(uint64 lowGuid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut)
Definition: AuctionHouseMgr.cpp:877
This mail was returned. Do not allow returning mail back again.
Definition: Mail.h:50
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition: Mail.cpp:173
Definition: Mail.h:118
std::string BuildAuctionMailSubject(MailAuctionAnswers response) const
Definition: AuctionHouseMgr.cpp:870
ObjectGuid::LowType owner
Definition: AuctionHouseMgr.h:74
uint32_t uint32
Definition: Define.h:150
uint32 bid
Definition: AuctionHouseMgr.h:76
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
uint32 GetAuctionCut() const
Definition: AuctionHouseMgr.cpp:787
uint32 buyout
Definition: AuctionHouseMgr.h:77
static uint32 GetPlayerAccountIdByGUID(ObjectGuid const &guid)
Definition: ObjectMgr.cpp:2302
Definition: ObjectGuid.h:189
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
Definition: Mail.h:104
uint32 deposit
Definition: AuctionHouseMgr.h:80
Definition: AuctionHouseMgr.h:64

+ Here is the call graph for this function:

void AuctionHouseMgr::SendAuctionSuccessfulMail ( AuctionEntry auction,
SQLTransaction trans 
)
187 {
188  ObjectGuid owner_guid = ObjectGuid::Create<HighGuid::Player>(auction->owner);
189  Player* owner = ObjectAccessor::FindConnectedPlayer(owner_guid);
190  uint32 owner_accId = ObjectMgr::GetPlayerAccountIdByGUID(owner_guid);
191  Item* item = GetAItem(auction->itemGUIDLow);
192 
193  // owner exist
194  if (owner || owner_accId)
195  {
196  uint32 profit = auction->bid + auction->deposit - auction->GetAuctionCut();
197 
198  //FIXME: what do if owner offline
199  if (owner && item)
200  {
201  owner->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GOLD_EARNED_BY_AUCTIONS, profit);
202  owner->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_SOLD, auction->bid);
203  //send auction owner notification, bidder must be current!
204  owner->GetSession()->SendAuctionClosedNotification(auction, (float)sWorld->getIntConfig(CONFIG_MAIL_DELIVERY_DELAY), true, item);
205  }
206 
208  .AddMoney(profit)
209  .SendMailTo(trans, MailReceiver(owner, auction->owner), auction, MAIL_CHECK_MASK_COPIED, sWorld->getIntConfig(CONFIG_MAIL_DELIVERY_DELAY));
210  }
211 }
ObjectGuid::LowType itemGUIDLow
Definition: AuctionHouseMgr.h:71
#define sWorld
Definition: World.h:887
static std::string BuildAuctionMailBody(uint64 lowGuid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut)
Definition: AuctionHouseMgr.cpp:877
This mail was returned. Do not allow returning mail back again.
Definition: Mail.h:50
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition: Mail.cpp:173
Definition: Mail.h:118
std::string BuildAuctionMailSubject(MailAuctionAnswers response) const
Definition: AuctionHouseMgr.cpp:870
ObjectGuid::LowType owner
Definition: AuctionHouseMgr.h:74
Definition: Item.h:259
uint32_t uint32
Definition: Define.h:150
uint32 bid
Definition: AuctionHouseMgr.h:76
Definition: World.h:267
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
Item * GetAItem(ObjectGuid::LowType id)
Definition: AuctionHouseMgr.h:154
uint32 GetAuctionCut() const
Definition: AuctionHouseMgr.cpp:787
uint32 buyout
Definition: AuctionHouseMgr.h:77
MailDraft & AddMoney(uint64 money)
Definition: Mail.h:137
static uint32 GetPlayerAccountIdByGUID(ObjectGuid const &guid)
Definition: ObjectMgr.cpp:2302
Definition: ObjectGuid.h:189
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
Definition: Mail.h:104
uint32 deposit
Definition: AuctionHouseMgr.h:80
Definition: AuctionHouseMgr.h:60

+ Here is the call graph for this function:

void AuctionHouseMgr::SendAuctionWonMail ( AuctionEntry auction,
SQLTransaction trans 
)
106 {
107  Item* item = GetAItem(auction->itemGUIDLow);
108  if (!item)
109  return;
110 
111  uint32 bidderAccId = 0;
112  ObjectGuid bidderGuid = ObjectGuid::Create<HighGuid::Player>(auction->bidder);
113  Player* bidder = ObjectAccessor::FindConnectedPlayer(bidderGuid);
114  // data for gm.log
115  std::string bidderName;
116  bool logGmTrade = false;
117 
118  if (bidder)
119  {
120  bidderAccId = bidder->GetSession()->GetAccountId();
121  bidderName = bidder->GetName();
122  logGmTrade = bidder->GetSession()->HasPermission(rbac::RBAC_PERM_LOG_GM_TRADE);
123  }
124  else
125  {
126  bidderAccId = ObjectMgr::GetPlayerAccountIdByGUID(bidderGuid);
128 
129  if (logGmTrade && !ObjectMgr::GetPlayerNameByGUID(bidderGuid, bidderName))
130  bidderName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
131  }
132 
133  if (logGmTrade)
134  {
135  ObjectGuid ownerGuid = ObjectGuid::Create<HighGuid::Player>(auction->owner);
136  std::string ownerName;
137  if (!ObjectMgr::GetPlayerNameByGUID(ownerGuid, ownerName))
138  ownerName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
139 
140  uint32 ownerAccId = ObjectMgr::GetPlayerAccountIdByGUID(ownerGuid);
141 
142  sLog->outCommand(bidderAccId, "GM %s (Account: %u) won item in auction: %s (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)",
143  bidderName.c_str(), bidderAccId, item->GetTemplate()->GetDefaultLocaleName(), item->GetEntry(), item->GetCount(), auction->bid, ownerName.c_str(), ownerAccId);
144  }
145 
146  // receiver exist
147  if (bidder || bidderAccId)
148  {
149  // set owner to bidder (to prevent delete item with sender char deleting)
150  // owner in `data` will set at mail receive and item extracting
152  stmt->setUInt64(0, auction->bidder);
153  stmt->setUInt64(1, item->GetGUID().GetCounter());
154  trans->Append(stmt);
155 
156  if (bidder)
157  {
158  bidder->GetSession()->SendAuctionWonNotification(auction, item);
159  // FIXME: for offline player need also
160  bidder->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS, 1);
161  }
162 
163  MailDraft(auction->BuildAuctionMailSubject(AUCTION_WON), AuctionEntry::BuildAuctionMailBody(auction->owner, auction->bid, auction->buyout, 0, 0))
164  .AddItem(item)
165  .SendMailTo(trans, MailReceiver(bidder, auction->bidder), auction, MAIL_CHECK_MASK_COPIED);
166  }
167  else
168  {
169  // bidder doesn't exist, delete the item
170  sAuctionMgr->RemoveAItem(auction->itemGUIDLow, true);
171  }
172 }
uint32 GetCount() const
Definition: Item.h:322
uint32 Realm
Definition: Realm.h:53
static bool HasPermission(uint32 accountId, uint32 permission, uint32 realmId)
Definition: AccountMgr.cpp:533
Realm realm
Definition: World.cpp:3485
ObjectGuid::LowType itemGUIDLow
Definition: AuctionHouseMgr.h:71
Definition: DBCEnums.h:271
#define sLog
Definition: Log.h:154
#define sObjectMgr
Definition: ObjectMgr.h:1567
static std::string BuildAuctionMailBody(uint64 lowGuid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut)
Definition: AuctionHouseMgr.cpp:877
This mail was returned. Do not allow returning mail back again.
Definition: Mail.h:50
Definition: PreparedStatement.h:74
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition: Mail.cpp:173
Definition: Mail.h:118
std::string BuildAuctionMailSubject(MailAuctionAnswers response) const
Definition: AuctionHouseMgr.cpp:870
ObjectGuid::LowType owner
Definition: AuctionHouseMgr.h:74
Definition: AuctionHouseMgr.h:59
Battlenet::RealmHandle Id
Definition: Realm.h:86
Definition: Item.h:259
uint32_t uint32
Definition: Define.h:150
uint32 bid
Definition: AuctionHouseMgr.h:76
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
Item * GetAItem(ObjectGuid::LowType id)
Definition: AuctionHouseMgr.h:154
uint32 buyout
Definition: AuctionHouseMgr.h:77
ObjectGuid const & GetGUID() const
Definition: Object.h:105
static bool GetPlayerNameByGUID(ObjectGuid const &guid, std::string &name)
Definition: ObjectMgr.cpp:2258
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
Definition: RBAC.h:63
#define sAuctionMgr
Definition: AuctionHouseMgr.h:199
static uint32 GetPlayerAccountIdByGUID(ObjectGuid const &guid)
Definition: ObjectMgr.cpp:2302
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
uint32 GetEntry() const
Definition: Object.h:107
Definition: ObjectGuid.h:189
Definition: Language.h:78
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
Definition: Mail.h:104
LowType GetCounter() const
Definition: ObjectGuid.h:221
Definition: CharacterDatabase.h:136
ItemTemplate const * GetTemplate() const
Definition: Item.cpp:547
char const * GetDefaultLocaleName() const
Definition: ItemTemplate.cpp:33

+ Here is the call graph for this function:

void AuctionHouseMgr::Update ( )
510 {
514 }
AuctionHouseObject mNeutralAuctions
Definition: AuctionHouseMgr.h:192
void Update()
Definition: AuctionHouseMgr.cpp:575
AuctionHouseObject mAllianceAuctions
Definition: AuctionHouseMgr.h:191
AuctionHouseObject mHordeAuctions
Definition: AuctionHouseMgr.h:190

+ Here is the call graph for this function:

void AuctionHouseMgr::UpdatePendingAuctions ( )
469 {
470  for (auto itr = pendingAuctionMap.begin(); itr != pendingAuctionMap.end();)
471  {
472  ObjectGuid playerGUID = itr->first;
473  if (Player* player = ObjectAccessor::FindConnectedPlayer(playerGUID))
474  {
475  // Check if there were auctions since last update process if not
476  if (PendingAuctionCount(player) == itr->second.second)
477  {
478  ++itr;
479  PendingAuctionProcess(player);
480  }
481  else
482  {
483  ++itr;
484  pendingAuctionMap[playerGUID].second = PendingAuctionCount(player);
485  }
486  }
487  else
488  {
489  // Expire any auctions that we couldn't get a deposit for
490  TC_LOG_WARN("auctionHouse", "Player %s was offline, unable to retrieve deposit!", playerGUID.ToString().c_str());
491  PlayerAuctions* thisAH = itr->second.first;
492  ++itr;
494  for (auto AHitr = thisAH->begin(); AHitr != thisAH->end();)
495  {
496  AuctionEntry* AH = (*AHitr);
497  ++AHitr;
498  AH->expire_time = time(NULL);
499  AH->DeleteFromDB(trans);
500  AH->SaveToDB(trans);
501  }
503  pendingAuctionMap.erase(playerGUID);
504  delete thisAH;
505  }
506  }
507 }
void SaveToDB(SQLTransaction &trans) const
Definition: AuctionHouseMgr.cpp:807
void PendingAuctionProcess(Player *player)
Definition: AuctionHouseMgr.cpp:422
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
Definition: AuctionHouseMgr.h:67
void DeleteFromDB(SQLTransaction &trans) const
Definition: AuctionHouseMgr.cpp:800
arena_t NULL
Definition: jemalloc_internal.h:624
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
time_t expire_time
Definition: AuctionHouseMgr.h:78
std::map< ObjectGuid, AuctionPair > pendingAuctionMap
Definition: AuctionHouseMgr.h:194
#define TC_LOG_WARN(filterType__,...)
Definition: Log.h:204
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Definition: ObjectGuid.h:189
uint32 PendingAuctionCount(const Player *player) const
Definition: AuctionHouseMgr.cpp:413
std::vector< AuctionEntry * > PlayerAuctions
Definition: AuctionHouseMgr.h:148
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215
std::string ToString() const
Definition: ObjectGuid.cpp:99
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

Member Data Documentation

ItemMap AuctionHouseMgr::mAitems
private
AuctionHouseObject AuctionHouseMgr::mAllianceAuctions
private
AuctionHouseObject AuctionHouseMgr::mHordeAuctions
private
AuctionHouseObject AuctionHouseMgr::mNeutralAuctions
private
std::map<ObjectGuid, AuctionPair> AuctionHouseMgr::pendingAuctionMap
private

The documentation for this class was generated from the following files: