[2008_11_09_01_mangos_command.sql] Create new command .senditems and remove from moderator level command .sendmail possibility send items.

This commit is contained in:
VladimirMangos 2008-11-09 11:01:41 +03:00
parent 397d855569
commit ad59efb6d9
7 changed files with 171 additions and 78 deletions

View file

@ -6125,6 +6125,155 @@ bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
return true;
}
//Send items by mail
bool ChatHandler::HandleSendItemsCommand(const char* args)
{
if(!*args)
return false;
// format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
char* pName = strtok((char*)args, " ");
if(!pName)
return false;
char* tail1 = strtok(NULL, "");
if(!tail1)
return false;
char* msgSubject;
if(*tail1=='"')
msgSubject = strtok(tail1+1, "\"");
else
{
char* space = strtok(tail1, "\"");
if(!space)
return false;
msgSubject = strtok(NULL, "\"");
}
if (!msgSubject)
return false;
char* tail2 = strtok(NULL, "");
if(!tail2)
return false;
char* msgText;
if(*tail2=='"')
msgText = strtok(tail2+1, "\"");
else
{
char* space = strtok(tail2, "\"");
if(!space)
return false;
msgText = strtok(NULL, "\"");
}
if (!msgText)
return false;
// pName, msgSubject, msgText isn't NUL after prev. check
std::string name = pName;
std::string subject = msgSubject;
std::string text = msgText;
// extract items
typedef std::pair<uint32,uint32> ItemPair;
typedef std::list< ItemPair > ItemPairs;
ItemPairs items;
// get all tail string
char* tail = strtok(NULL, "");
// get from tail next item str
while(char* itemStr = strtok(tail, " "))
{
// and get new tail
tail = strtok(NULL, "");
// parse item str
char* itemIdStr = strtok(itemStr, ":");
char* itemCountStr = strtok(NULL, " ");
uint32 item_id = atoi(itemIdStr);
if(!item_id)
return false;
ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
if(!item_proto)
{
PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
SetSentErrorMessage(true);
return false;
}
uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
if(item_count < 1 || item_proto->MaxCount && item_count > item_proto->MaxCount)
{
PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
SetSentErrorMessage(true);
return false;
}
while(item_count > item_proto->Stackable)
{
items.push_back(ItemPair(item_id,item_proto->Stackable));
item_count -= item_proto->Stackable;
}
items.push_back(ItemPair(item_id,item_count));
if(items.size() > MAX_MAIL_ITEMS)
{
PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
SetSentErrorMessage(true);
return false;
}
}
if(!normalizePlayerName(name))
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
if(!receiver_guid)
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
// from console show not existed sender
uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
uint32 messagetype = MAIL_NORMAL;
uint32 stationery = MAIL_STATIONERY_GM;
uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
Player *receiver = objmgr.GetPlayer(receiver_guid);
// fill mail
MailItemsInfo mi; // item list preparing
for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
{
if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
{
item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
}
}
WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
PSendSysMessage(LANG_MAIL_SENT, name.c_str());
return true;
}
/// Send a message to a player in game
bool ChatHandler::HandleSendMessageCommand(const char* args)
{