aboutsummaryrefslogtreecommitdiff
path: root/src/game/Level3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Level3.cpp')
-rw-r--r--src/game/Level3.cpp239
1 files changed, 239 insertions, 0 deletions
diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp
index 9b2e8fb8800..8b368e737b5 100644
--- a/src/game/Level3.cpp
+++ b/src/game/Level3.cpp
@@ -6201,6 +6201,245 @@ 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 money by mail
+bool ChatHandler::HandleSendMoneyCommand(const char* args)
+{
+ if (!*args)
+ return false;
+
+ /// format: name "subject text" "mail text" money
+
+ 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;
+
+ char* money_str = strtok(NULL, "");
+ int32 money = money_str ? atoi(money_str) : 0;
+ if (money <= 0)
+ return false;
+
+ // pName, msgSubject, msgText isn't NUL after prev. check
+ std::string name = pName;
+ std::string subject = msgSubject;
+ std::string text = msgText;
+
+ 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;
+ }
+
+ uint32 mailId = objmgr.GenerateMailID();
+
+ // 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);
+
+ WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 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)
{