aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/scripts')
-rw-r--r--src/server/scripts/Commands/cs_list.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/server/scripts/Commands/cs_list.cpp b/src/server/scripts/Commands/cs_list.cpp
index fce1f77c2cf..81608ebd458 100644
--- a/src/server/scripts/Commands/cs_list.cpp
+++ b/src/server/scripts/Commands/cs_list.cpp
@@ -29,6 +29,7 @@ EndScriptData */
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Player.h"
+#include <iostream>
class list_commandscript : public CommandScript
{
@@ -43,6 +44,7 @@ public:
{ "item", SEC_ADMINISTRATOR, true, &HandleListItemCommand, "", NULL },
{ "object", SEC_ADMINISTRATOR, true, &HandleListObjectCommand, "", NULL },
{ "auras", SEC_ADMINISTRATOR, false, &HandleListAurasCommand, "", NULL },
+ { "mail", SEC_ADMINISTRATOR, true, &HandleListMailCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
@@ -463,6 +465,114 @@ public:
return true;
}
+ // handle list mail command
+ static bool HandleListMailCommand(ChatHandler* handler, char const* args)
+ {
+ Player* target;
+ uint64 targetGuid;
+ std::string targetName;
+
+ if (!*args)
+ return false;
+
+ uint32 parseGUID = MAKE_NEW_GUID(atol((char*)args), 0, HIGHGUID_PLAYER);
+
+ if (sObjectMgr->GetPlayerNameByGUID(parseGUID, targetName))
+ {
+ target = sObjectMgr->GetPlayerByLowGUID(parseGUID);
+ targetGuid = parseGUID;
+ }
+ else if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
+ return false;
+
+ PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_LIST_COUNT);
+ stmt->setUInt32(0, targetGuid);
+ PreparedQueryResult result = CharacterDatabase.Query(stmt);
+ if (result)
+ {
+ Field* fields = result->Fetch();
+ uint32 countMail = fields[0].GetUInt64();
+ std::string nameLink = handler->playerLink(targetName);
+ handler->PSendSysMessage(LANG_LIST_MAIL_HEADER, countMail, nameLink.c_str(), targetGuid);
+ handler->PSendSysMessage(LANG_ACCOUNT_LIST_BAR);
+ PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_LIST_INFO);
+ stmt->setUInt32(0, targetGuid);
+ PreparedQueryResult result = CharacterDatabase.Query(stmt);
+ if (result)
+ {
+ do
+ {
+ Field* fields = result->Fetch();
+ uint32 messageId = fields[0].GetUInt32();
+ uint32 senderId = fields[1].GetUInt32();
+ std::string sender = fields[2].GetString();
+ uint32 receiverId = fields[3].GetUInt32();
+ std::string receiver = fields[4].GetString();
+ std::string subject = fields[5].GetString();
+ uint64 deliverTime = fields[6].GetUInt32();
+ uint64 expireTime = fields[7].GetUInt32();
+ uint32 money = fields[8].GetUInt32();
+ int hasItem = fields[9].GetUInt8();
+ uint32 gold = money /GOLD;
+ uint32 silv = (money % GOLD) / SILVER;
+ uint32 copp = (money % GOLD) % SILVER;
+ std::string receiverStr = handler->playerLink(receiver);
+ std::string senderStr = handler->playerLink(sender);
+ handler->PSendSysMessage(LANG_LIST_MAIL_INFO_1 , messageId, subject.c_str(),gold, silv, copp);
+ handler->PSendSysMessage(LANG_LIST_MAIL_INFO_2, senderStr.c_str(), senderId, receiverStr.c_str(), receiverId);
+ handler->PSendSysMessage(LANG_LIST_MAIL_INFO_3, TimeToTimestampStr(deliverTime).c_str(), TimeToTimestampStr(expireTime).c_str());
+ if (hasItem == 1)
+ {
+ QueryResult result2;
+ result2 = CharacterDatabase.PQuery("SELECT item_guid FROM mail_items WHERE mail_id = '%u'", messageId);
+ if (result2)
+ {
+ do
+ {
+ uint32 item_guid = (*result2)[0].GetUInt32();
+ PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL_LIST_ITEMS);
+ stmt->setUInt32(0, item_guid);
+ PreparedQueryResult result3 = CharacterDatabase.Query(stmt);
+ if (result3)
+ {
+ do
+ {
+ Field* fields = result3->Fetch();
+ uint32 item_entry = fields[0].GetUInt32();
+ uint32 item_count = fields[1].GetUInt32();
+ QueryResult result4;
+ result4 = WorldDatabase.PQuery("SELECT name,quality FROM item_template WHERE entry = '%u'", item_entry);
+ Field* fields1 = result4->Fetch();
+ std::string item_name = fields1[0].GetString();
+ int item_quality = fields1[1].GetUInt8();
+ if (handler->GetSession())
+ {
+ uint32 color = ItemQualityColors[item_quality];
+ std::ostringstream itemStr;
+ itemStr << "|c" << std::hex << color << "|Hitem:" << item_entry << ":0:0:0:0:0:0:0:0:0|h[" << item_name << "]|h|r";
+ handler->PSendSysMessage(LANG_LIST_MAIL_INFO_ITEM, itemStr.str().c_str(), item_entry, item_guid, item_count);
+ }
+ else
+ handler->PSendSysMessage(LANG_LIST_MAIL_INFO_ITEM, item_name.c_str(), item_entry, item_guid, item_count);
+ }
+ while (result3->NextRow());
+ }
+ }
+ while (result2->NextRow());
+ }
+ }
+ handler->PSendSysMessage(LANG_ACCOUNT_LIST_BAR);
+ }
+ while (result->NextRow());
+ }
+ else
+ handler->PSendSysMessage(LANG_LIST_MAIL_NOT_FOUND);
+ return true;
+ }
+ else
+ handler->PSendSysMessage(LANG_LIST_MAIL_NOT_FOUND);
+ return true;
+ }
};
void AddSC_list_commandscript()