Skip to content

Commit

Permalink
Scripts/Commands: Add .list mail $char/$guid command
Browse files Browse the repository at this point in the history
Prints a list of mails received by the characters

Closs #9421
  • Loading branch information
Bezo authored and DDuarte committed Mar 17, 2013
1 parent f598bf8 commit 228d980
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
12 changes: 12 additions & 0 deletions sql/updates/world/2013_03_17_03_world_misc.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DELETE FROM `trinity_string` WHERE `entry` IN (1151, 1152, 1153, 1154, 1155, 1156);
INSERT INTO `trinity_string` (`entry`,`content_default`) VALUES
(1151, 'Mail List Info: # of mails: %u, Player: %s(%u)'),
(1152, 'Mail Id: %u Title: \"%s\" Money: %ug%us%uc'),
(1153, 'Sender: %s(%u), Receiver: %s(%u)'),
(1154, 'Time deliver: %s, Time expire: %s'),
(1155, 'Item: %s[Entry:%u Guid:%u Count:%u]'),
(1156, 'Mail List Info: No mail found for this character.');

DELETE FROM `command` WHERE `name` = 'list mail';
INSERT INTO `command` (`name`,`security`,`help`) VALUES
('list mail', 3, 'Syntax: .list mail $character\nList of mails the character received.');
8 changes: 7 additions & 1 deletion src/server/game/Miscellaneous/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,13 @@ enum TrinityStrings
LANG_GROUP_FULL = 1148,
LANG_GROUP_TYPE = 1149,
LANG_GROUP_PLAYER_NAME_GUID = 1150,
// Room for more level 3 1151-1199 not used
LANG_LIST_MAIL_HEADER = 1151,
LANG_LIST_MAIL_INFO_1 = 1152,
LANG_LIST_MAIL_INFO_2 = 1153,
LANG_LIST_MAIL_INFO_3 = 1154,
LANG_LIST_MAIL_INFO_ITEM = 1155,
LANG_LIST_MAIL_NOT_FOUND = 1156,
// Room for more level 3 1157-1199 not used

// Debug commands
LANG_CINEMATIC_NOT_EXIST = 1200,
Expand Down
110 changes: 110 additions & 0 deletions src/server/scripts/Commands/cs_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ EndScriptData */
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Player.h"
#include <iostream>

class list_commandscript : public CommandScript
{
Expand All @@ -43,6 +44,7 @@ class list_commandscript : public CommandScript
{ "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[] =
Expand Down Expand Up @@ -463,6 +465,114 @@ class list_commandscript : public CommandScript

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ void CharacterDatabaseConnection::DoPrepareStatements()
PrepareStatement(CHAR_SEL_GUID_BY_NAME_FILTER, "SELECT guid, name FROM characters WHERE name LIKE CONCAT('%%', ?, '%%')", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_BANINFO_LIST, "SELECT bandate, unbandate, bannedby, banreason FROM character_banned WHERE guid = ? ORDER BY unbandate", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_BANNED_NAME, "SELECT characters.name FROM characters, character_banned WHERE character_banned.guid = ? AND character_banned.guid = characters.guid", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_MAIL_LIST_COUNT, "SELECT COUNT(id) FROM mail WHERE receiver = ? ", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_MAIL_LIST_INFO, "SELECT id, sender, (SELECT name FROM characters WHERE guid = sender) AS sendername, receiver, (SELECT name FROM characters WHERE guid = receiver) AS receivername,"
"SUBJECT, deliver_time, expire_time, money, has_items FROM mail WHERE receiver = ? ", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_MAIL_LIST_ITEMS, "SELECT itemEntry,count FROM item_instance WHERE guid = ?", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_ENUM, "SELECT c.guid, c.name, c.race, c.class, c.gender, c.playerBytes, c.playerBytes2, c.level, c.zone, c.map, c.position_x, c.position_y, c.position_z, "
"gm.guildid, c.playerFlags, c.at_login, cp.entry, cp.modelid, cp.level, c.equipmentCache, cb.guid "
"FROM characters AS c LEFT JOIN character_pet AS cp ON c.guid = cp.owner AND cp.slot = ? LEFT JOIN guild_member AS gm ON c.guid = gm.guid "
Expand Down
3 changes: 3 additions & 0 deletions src/server/shared/Database/Implementation/CharacterDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ enum CharacterDatabaseStatements
CHAR_SEL_GUID_BY_NAME_FILTER,
CHAR_SEL_BANINFO_LIST,
CHAR_SEL_BANNED_NAME,
CHAR_SEL_MAIL_LIST_COUNT,
CHAR_SEL_MAIL_LIST_INFO,
CHAR_SEL_MAIL_LIST_ITEMS,
CHAR_SEL_ENUM,
CHAR_SEL_ENUM_DECLINED_NAME,
CHAR_SEL_FREE_NAME,
Expand Down

0 comments on commit 228d980

Please sign in to comment.