aboutsummaryrefslogtreecommitdiff
path: root/src/game/Level1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Level1.cpp')
-rw-r--r--src/game/Level1.cpp163
1 files changed, 151 insertions, 12 deletions
diff --git a/src/game/Level1.cpp b/src/game/Level1.cpp
index c1bca8b8b40..19dec5500bc 100644
--- a/src/game/Level1.cpp
+++ b/src/game/Level1.cpp
@@ -147,9 +147,11 @@ bool ChatHandler::HandleGMmodeCommand(const char* args)
{
if(!*args)
{
- SendSysMessage(LANG_USE_BOL);
- SetSentErrorMessage(true);
- return false;
+ if(m_session->GetPlayer()->isGameMaster())
+ m_session->SendNotification(LANG_GM_ON);
+ else
+ m_session->SendNotification(LANG_GM_OFF);
+ return true;
}
std::string argstr = (char*)args;
@@ -157,7 +159,7 @@ bool ChatHandler::HandleGMmodeCommand(const char* args)
if (argstr == "on")
{
m_session->GetPlayer()->SetGameMaster(true);
- m_session->SendNotification("GM mode is ON");
+ m_session->SendNotification(LANG_GM_ON);
#ifdef _DEBUG_VMAPS
VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
vMapManager->processCommand("stoplog");
@@ -168,7 +170,7 @@ bool ChatHandler::HandleGMmodeCommand(const char* args)
if (argstr == "off")
{
m_session->GetPlayer()->SetGameMaster(false);
- m_session->SendNotification("GM mode is OFF");
+ m_session->SendNotification(LANG_GM_OFF);
#ifdef _DEBUG_VMAPS
VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
vMapManager->processCommand("startlog");
@@ -181,6 +183,40 @@ bool ChatHandler::HandleGMmodeCommand(const char* args)
return false;
}
+// Enables or disables hiding of the staff badge
+bool ChatHandler::HandleGMChatCommand(const char* args)
+{
+ if(!*args)
+ {
+ if(m_session->GetPlayer()->isGMChat())
+ m_session->SendNotification(LANG_GM_CHAT_ON);
+ else
+ m_session->SendNotification(LANG_GM_CHAT_OFF);
+ return true;
+ }
+
+ std::string argstr = (char*)args;
+
+ if (argstr == "on")
+ {
+ m_session->GetPlayer()->SetGMChat(true);
+ m_session->SendNotification(LANG_GM_CHAT_ON);
+ return true;
+ }
+
+ if (argstr == "off")
+ {
+ m_session->GetPlayer()->SetGMChat(false);
+ m_session->SendNotification(LANG_GM_CHAT_OFF);
+ return true;
+ }
+
+ SendSysMessage(LANG_USE_BOL);
+ SetSentErrorMessage(true);
+ return false;
+}
+
+
//Enable\Dissable Invisible mode
bool ChatHandler::HandleVisibleCommand(const char* args)
{
@@ -195,13 +231,13 @@ bool ChatHandler::HandleVisibleCommand(const char* args)
if (argstr == "on")
{
m_session->GetPlayer()->SetGMVisible(true);
- m_session->SendNotification(GetMangosString(LANG_INVISIBLE_VISIBLE));
+ m_session->SendNotification(LANG_INVISIBLE_VISIBLE);
return true;
}
if (argstr == "off")
{
- m_session->SendNotification(GetMangosString(LANG_INVISIBLE_INVISIBLE));
+ m_session->SendNotification(LANG_INVISIBLE_INVISIBLE);
m_session->GetPlayer()->SetGMVisible(false);
return true;
}
@@ -1823,19 +1859,107 @@ bool ChatHandler::HandleSendMailCommand(const char* args)
if(!*args)
return false;
+ // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
+
char* pName = strtok((char*)args, " ");
- char* msgSubject = strtok(NULL, " ");
- char* msgText = strtok(NULL, "");
+ 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);
@@ -1844,9 +1968,12 @@ bool ChatHandler::HandleSendMailCommand(const char* args)
}
uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
-
if(!receiver_guid)
+ {
+ SendSysMessage(LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage(true);
return false;
+ }
uint32 mailId = objmgr.GenerateMailID();
uint32 sender_guidlo = m_session->GetPlayer()->GetGUIDLow();
@@ -1860,7 +1987,19 @@ bool ChatHandler::HandleSendMailCommand(const char* args)
Player *receiver = objmgr.GetPlayer(receiver_guid);
- WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE);
+ // 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->GetPlayer()))
+ {
+ 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;