[11701] Command .auction item and support auction without owner.

* New command allow place auction from chat/console and create auction without owner.
* Same code can be used in other place when server code want create generated auction
  without need have associated player. Auction code update for support this case.
* MailDraft::SendMailTo now allow "send" mails to non-players. It correcly drop items in like case.
This commit is contained in:
VladimirMangos 2011-06-29 23:24:51 +04:00
parent 78991c1131
commit 67f9c26d51
12 changed files with 210 additions and 86 deletions

View file

@ -24,7 +24,7 @@ CREATE TABLE `db_version` (
`version` varchar(120) default NULL,
`creature_ai_version` varchar(120) default NULL,
`cache_id` int(10) default '0',
`required_11690_01_mangos_spell_proc_event` bit(1) default NULL
`required_11701_01_mangos_command` bit(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes';
--
@ -509,6 +509,7 @@ INSERT INTO `command` VALUES
('auction alliance',3,'Syntax: .auction alliance\r\n\r\nShow alliance auction store independent from your team.'),
('auction goblin',3,'Syntax: .auction goblin\r\n\r\nShow goblin auction store common for all teams.'),
('auction horde',3,'Syntax: .auction horde\r\n\r\nShow horde auction store independent from your team.'),
('auction item',3,'Syntax: .auction item (alliance|horde|goblin) #itemid[:#itemcount] [[[#minbid] #buyout] [short|long|verylong]\r\n\r\nAdd new item (in many stackes if amount grater stack size) to specific auction house at short|long|verylogn perios similar same settings in auction in game dialog. Created auction not have owner.'),
('aura',3,'Syntax: .aura #spellid\r\n\r\nAdd the aura from spell #spellid to the selected Unit.'),
('ban account',3,'Syntax: .ban account $Name $bantime $reason\r\nBan account kick player.\r\n$bantime: negative value leads to permban, otherwise use a timestring like \"4d20h3s\".'),
('ban character',3,'Syntax: .ban character $Name $bantime $reason\r\nBan account and kick player.\r\n$bantime: negative value leads to permban, otherwise use a timestring like \"4d20h3s\".'),

View file

@ -0,0 +1,6 @@
ALTER TABLE db_version CHANGE COLUMN required_11690_01_mangos_spell_proc_event required_11701_01_mangos_command bit;
DELETE FROM command WHERE name = 'auction item';
INSERT INTO command (name, security, help) VALUES
('auction item',3,'Syntax: .auction item (alliance|horde|goblin) #itemid[:#itemcount] [[[#minbid] #buyout] [short|long|verylong]\r\n\r\nAdd new item (in many stackes if amount grater stack size) to specific auction house at short|long|verylogn perios similar same settings in auction in game dialog. Created auction not have owner.');

View file

@ -371,36 +371,10 @@ void WorldSession::HandleAuctionSellItem(WorldPacket & recv_data)
pl->ModifyMoney(-int32(deposit));
uint32 auction_time = uint32(etime * sWorld.getConfig(CONFIG_FLOAT_RATE_AUCTION_TIME));
AuctionEntry *AH = new AuctionEntry;
AH->Id = sObjectMgr.GenerateAuctionID();
AH->itemGuidLow = newItem->GetObjectGuid().GetCounter();
AH->itemTemplate = newItem->GetEntry();
AH->owner = pl->GetGUIDLow();
Utf8toWStr(pl->GetName(), AH->ownerName);
AH->startbid = bid;
AH->bidder = 0;
AH->bid = 0;
AH->buyout = buyout;
AH->expireTime = time(NULL) + auction_time;
AH->moneyDeliveryTime = 0;
AH->deposit = deposit;
AH->auctionHouseEntry = auctionHouseEntry;
AuctionEntry* AH = auctionHouse->AddAuction(auctionHouseEntry, newItem, etime, bid, buyout, deposit, pl);
DETAIL_LOG("selling %s to auctioneer %s with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u",
itemGuid.GetString().c_str(), auctioneerGuid.GetString().c_str(), bid, buyout, auction_time, AH->GetHouseId());
auctionHouse->AddAuction(AH);
sAuctionMgr.AddAItem(newItem);
CharacterDatabase.BeginTransaction();
newItem->SaveToDB();
AH->SaveToDB();
pl->SaveInventoryAndGoldToDB();
CharacterDatabase.CommitTransaction();
itemGuid.GetString().c_str(), auctioneerGuid.GetString().c_str(), bid, buyout, etime, auctionHouseEntry->houseId);
SendAuctionCommandResult(AH, AUCTION_STARTED, AUCTION_OK);
@ -447,7 +421,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket & recv_data)
// impossible have online own another character (use this for speedup check in case online owner)
Player* auction_owner = sObjectMgr.GetPlayer(ownerGuid);
if (!auction_owner && sObjectMgr.GetPlayerAccountIdByGUID(ownerGuid) == pl->GetSession()->GetAccountId())
if (!auction_owner && ownerGuid && sObjectMgr.GetPlayerAccountIdByGUID(ownerGuid) == pl->GetSession()->GetAccountId())
{
// you cannot bid your another character auction:
SendAuctionCommandResult(NULL, AUCTION_BID_PLACED, AUCTION_ERR_BID_OWN);
@ -564,11 +538,21 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket & recv_data)
AuctionEntry *auction = auctionHouse->GetAuction(auctionId);
Player *pl = GetPlayer();
if (auction && auction->owner == pl->GetGUIDLow())
if (!auction || auction->owner != pl->GetGUIDLow())
{
SendAuctionCommandResult(NULL, AUCTION_REMOVED, AUCTION_ERR_DATABASE);
sLog.outError("CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", pl->GetGUIDLow(), auctionId);
return;
}
Item *pItem = sAuctionMgr.GetAItem(auction->itemGuidLow);
if (pItem)
if (!pItem)
{
sLog.outError("Auction id: %u has nonexistent item (item guid : %u)!!!", auction->Id, auction->itemGuidLow);
SendAuctionCommandResult(NULL, AUCTION_REMOVED, AUCTION_ERR_INVENTORY, EQUIP_ERR_ITEM_NOT_FOUND);
return;
}
if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid
{
uint32 auctionCut = auction->GetAuctionCut();
@ -586,21 +570,6 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket & recv_data)
MailDraft(msgAuctionCanceledOwner.str(), "") // TODO: fix body
.AddItem(pItem)
.SendMailTo(pl, auction, MAIL_CHECK_MASK_COPIED);
}
else
{
sLog.outError("Auction id: %u has nonexistent item (item guid : %u)!!!", auction->Id, auction->itemGuidLow);
SendAuctionCommandResult(NULL, AUCTION_REMOVED, AUCTION_ERR_INVENTORY, EQUIP_ERR_ITEM_NOT_FOUND);
return;
}
}
else
{
SendAuctionCommandResult(NULL, AUCTION_REMOVED, AUCTION_ERR_DATABASE);
// this code isn't possible ... maybe there should be ASSERT
sLog.outError("CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", pl->GetGUIDLow(), auctionId);
return;
}
// inform player, that auction is removed
SendAuctionCommandResult(auction, AUCTION_REMOVED, AUCTION_OK);

View file

@ -88,6 +88,9 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry *auction)
uint32 bidder_accId = 0;
ObjectGuid ownerGuid = ObjectGuid(HIGHGUID_PLAYER, auction->owner);
Player* auction_owner = sObjectMgr.GetPlayer(ownerGuid);
// data for gm.log
if (sWorld.getConfig(CONFIG_BOOL_GM_LOG_TRADE))
{
@ -113,12 +116,13 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry *auction)
if (bidder_security > SEC_PLAYER)
{
ObjectGuid owner_guid = ObjectGuid(HIGHGUID_PLAYER, auction->owner);
std::string owner_name;
if (!sObjectMgr.GetPlayerNameByGUID(owner_guid, owner_name))
if (auction_owner)
owner_name = auction_owner->GetName();
else if (ownerGuid && !sObjectMgr.GetPlayerNameByGUID(ownerGuid, owner_name))
owner_name = sObjectMgr.GetMangosStringForDBCLocale(LANG_UNKNOWN);
uint32 owner_accid = sObjectMgr.GetPlayerAccountIdByGUID(owner_guid);
uint32 owner_accid = ownerGuid ? sObjectMgr.GetPlayerAccountIdByGUID(ownerGuid) : 0;
sLog.outCommand(bidder_accId,"GM %s (Account: %u) won item in auction: %s (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)",
bidder_name.c_str(), bidder_accId, pItem->GetProto()->Name1, pItem->GetEntry(), pItem->GetCount(), auction->bid, owner_name.c_str(), owner_accid);
@ -127,8 +131,6 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry *auction)
else if (!bidder)
bidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(bidder_guid);
ObjectGuid ownerGuid = ObjectGuid(HIGHGUID_PLAYER, auction->owner);
Player* auction_owner = sObjectMgr.GetPlayer(ownerGuid);
if (auction_owner)
auction_owner->GetSession()->SendAuctionOwnerNotification(auction);
@ -178,7 +180,7 @@ void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry * auction)
Player *owner = sObjectMgr.GetPlayer(owner_guid);
// owner exist (online or offline)
if (owner || sObjectMgr.GetPlayerAccountIdByGUID(owner_guid))
if (owner || owner_guid && sObjectMgr.GetPlayerAccountIdByGUID(owner_guid))
{
std::ostringstream msgAuctionSalePendingSubject;
msgAuctionSalePendingSubject << auction->itemTemplate << ":0:" << AUCTION_SALE_PENDING;
@ -208,7 +210,7 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail(AuctionEntry * auction)
Player *owner = sObjectMgr.GetPlayer(owner_guid);
uint32 owner_accId = 0;
if (!owner)
if (!owner && owner_guid)
owner_accId = sObjectMgr.GetPlayerAccountIdByGUID(owner_guid);
// owner exist
@ -389,6 +391,9 @@ void AuctionHouseMgr::LoadAuctions()
auction->itemGuidLow = fields[2].GetUInt32();
auction->itemTemplate = fields[3].GetUInt32();
auction->owner = fields[4].GetUInt32();
if (auction->owner)
{
std::wstring& plWName = playerNames[auction->owner];
if (plWName.empty())
{
@ -400,6 +405,7 @@ void AuctionHouseMgr::LoadAuctions()
}
auction->ownerName = plWName;
}
auction->buyout = fields[5].GetUInt32();
auction->expireTime = fields[6].GetUInt32();
@ -909,6 +915,43 @@ void AuctionHouseObject::BuildListPendingSales(WorldPacket& data, Player* player
}
}
AuctionEntry* AuctionHouseObject::AddAuction(AuctionHouseEntry const* auctionHouseEntry, Item* newItem, uint32 etime, uint32 bid, uint32 buyout, uint32 deposit, Player * pl /*= NULL*/)
{
uint32 auction_time = uint32(etime * sWorld.getConfig(CONFIG_FLOAT_RATE_AUCTION_TIME));
AuctionEntry *AH = new AuctionEntry;
AH->Id = sObjectMgr.GenerateAuctionID();
AH->itemGuidLow = newItem->GetObjectGuid().GetCounter();
AH->itemTemplate = newItem->GetEntry();
AH->owner = pl ? pl->GetGUIDLow() : 0;
if (pl)
Utf8toWStr(pl->GetName(), AH->ownerName);
AH->startbid = bid;
AH->bidder = 0;
AH->bid = 0;
AH->buyout = buyout;
AH->expireTime = time(NULL) + auction_time;
AH->moneyDeliveryTime = 0;
AH->deposit = deposit;
AH->auctionHouseEntry = auctionHouseEntry;
AddAuction(AH);
sAuctionMgr.AddAItem(newItem);
CharacterDatabase.BeginTransaction();
newItem->SaveToDB();
AH->SaveToDB();
if (pl)
pl->SaveInventoryAndGoldToDB();
CharacterDatabase.CommitTransaction();
return AH;
}
// this function inserts to WorldPacket auction's data
bool AuctionEntry::BuildAuctionInfo(WorldPacket & data) const
{

View file

@ -58,7 +58,7 @@ struct AuctionEntry
uint32 Id;
uint32 itemGuidLow;
uint32 itemTemplate;
uint32 owner;
uint32 owner; // player low guid, can be 0 for server generated auction
std::wstring ownerName; // cache name for sorting
uint32 startbid; // maybe useless
uint32 bid;
@ -122,6 +122,7 @@ class AuctionHouseObject
void BuildListOwnerItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
void BuildListPendingSales(WorldPacket& data, Player* player, uint32& count);
AuctionEntry* AddAuction(AuctionHouseEntry const* auctionHouseEntry, Item* newItem, uint32 etime, uint32 bid, uint32 buyout = 0, uint32 deposit = 0, Player * pl = NULL);
private:
AuctionEntryMap AuctionsMap;
};

View file

@ -109,6 +109,7 @@ ChatCommand * ChatHandler::getCommandTable()
{ "alliance", SEC_ADMINISTRATOR, false, &ChatHandler::HandleAuctionAllianceCommand, "", NULL },
{ "goblin", SEC_ADMINISTRATOR, false, &ChatHandler::HandleAuctionGoblinCommand, "", NULL },
{ "horde", SEC_ADMINISTRATOR, false, &ChatHandler::HandleAuctionHordeCommand, "", NULL },
{ "item", SEC_ADMINISTRATOR, true, &ChatHandler::HandleAuctionItemCommand, "", NULL },
{ "", SEC_ADMINISTRATOR, false, &ChatHandler::HandleAuctionCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};

View file

@ -145,6 +145,7 @@ class MANGOS_DLL_SPEC ChatHandler
bool HandleAuctionAllianceCommand(char* args);
bool HandleAuctionGoblinCommand(char* args);
bool HandleAuctionHordeCommand(char* args);
bool HandleAuctionItemCommand(char* args);
bool HandleAuctionCommand(char* args);
bool HandleAchievementCommand(char* args);

View file

@ -4495,6 +4495,97 @@ bool ChatHandler::HandleAuctionCommand(char* /*args*/)
return true;
}
bool ChatHandler::HandleAuctionItemCommand(char* args)
{
// format: (alliance|horde|goblin) item[:count] price [buyout] [short|long|verylong]
char* typeStr = ExtractLiteralArg(&args);
if (!typeStr)
return false;
uint32 houseid;
if (strncmp(typeStr, "alliance", strlen(typeStr)) == 0)
houseid = 1;
else if (strncmp(typeStr, "horde", strlen(typeStr)) == 0)
houseid = 6;
else if (strncmp(typeStr, "goblin", strlen(typeStr)) == 0)
houseid = 7;
else
return false;
// parse item str
char* itemStr = ExtractArg(&args);
if (!itemStr)
return false;
uint32 item_id = 0;
uint32 item_count = 1;
if (sscanf(itemStr, "%u:%u", &item_id, &item_count) != 2)
if (sscanf(itemStr, "%u", &item_id) != 1)
return false;
uint32 price;
if (!ExtractUInt32(&args, price))
return false;
uint32 buyout;
if (!ExtractOptUInt32(&args, buyout, 0))
return false;
uint32 etime = 4*MIN_AUCTION_TIME;
if (char* timeStr = ExtractLiteralArg(&args))
{
if (strncmp(timeStr, "short", strlen(timeStr)) == 0)
etime = 1*MIN_AUCTION_TIME;
else if (strncmp(timeStr, "long", strlen(timeStr)) == 0)
etime = 2*MIN_AUCTION_TIME;
else if (strncmp(timeStr, "verylong", strlen(timeStr)) == 0)
etime = 4*MIN_AUCTION_TIME;
else
return false;
}
AuctionHouseEntry const* auctionHouseEntry = sAuctionHouseStore.LookupEntry(houseid);
AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap(auctionHouseEntry);
if (!item_id)
{
PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
SetSentErrorMessage(true);
return false;
}
ItemPrototype const* item_proto = ObjectMgr::GetItemPrototype(item_id);
if (!item_proto)
{
PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
SetSentErrorMessage(true);
return false;
}
if (item_count < 1 || (item_proto->MaxCount > 0 && item_count > uint32(item_proto->MaxCount)))
{
PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count, item_id);
SetSentErrorMessage(true);
return false;
}
Player* pl = m_session ? m_session->GetPlayer() : NULL;
do
{
uint32 item_stack = item_count > item_proto->GetMaxStackSize() ? item_proto->GetMaxStackSize() : item_count;
item_count -= item_stack;
Item* newItem = Item::CreateItem(item_id, item_stack);
MANGOS_ASSERT(newItem);
auctionHouse->AddAuction(auctionHouseEntry, newItem, etime, price, buyout);
} while (item_count);
return true;
}
bool ChatHandler::HandleBankCommand(char* /*args*/)
{
m_session->SendShowBank(m_session->GetPlayer()->GetObjectGuid());

View file

@ -241,6 +241,16 @@ void MailDraft::SendMailTo(MailReceiver const& receiver, MailSender const& sende
{
Player* pReceiver = receiver.GetPlayer(); // can be NULL
uint32 pReceiverAccount = 0;
if (!pReceiver)
pReceiverAccount = sObjectMgr.GetPlayerAccountIdByGUID(receiver.GetPlayerGuid());
if (!pReceiver && !pReceiverAccount) // receiver not exist
{
deleteIncludedItems(true);
return;
}
bool has_items = !m_items.empty();
// generate mail template items for online player, for offline player items will generated at open

View file

@ -610,6 +610,7 @@ class MANGOS_DLL_SPEC WorldSession
void HandleAuctionListItems( WorldPacket & recv_data );
void HandleAuctionListBidderItems( WorldPacket & recv_data );
void HandleAuctionSellItem( WorldPacket & recv_data );
void HandleAuctionRemoveItem( WorldPacket & recv_data );
void HandleAuctionListOwnerItems( WorldPacket & recv_data );
void HandleAuctionPlaceBid( WorldPacket & recv_data );

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11700"
#define REVISION_NR "11701"
#endif // __REVISION_NR_H__

View file

@ -1,6 +1,6 @@
#ifndef __REVISION_SQL_H__
#define __REVISION_SQL_H__
#define REVISION_DB_CHARACTERS "required_11620_01_characters_character_equipmentsets"
#define REVISION_DB_MANGOS "required_11690_01_mangos_spell_proc_event"
#define REVISION_DB_MANGOS "required_11701_01_mangos_command"
#define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version"
#endif // __REVISION_SQL_H__