//used when player copies mail body to his inventory
void WorldSession::HandleMailCreateTextItem(WorldPackets::Mail::MailCreateTextItem& packet)
{
if (!CanOpenMailBox(packet.Mailbox))
return;
Player* player = _player;
Mail* m = player->GetMail(packet.MailID);
if (!m || (m->body.empty() && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(nullptr) || (m->checked & MAIL_CHECK_MASK_COPIED))
{
player->SendMailResult(packet.MailID, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
return;
}
Item* bodyItem = new Item; // This is not bag and then can be used new Item.
if (!bodyItem->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), MAIL_BODY_ITEM_TEMPLATE, player))
{
delete bodyItem;
return;
}
// in mail template case we need create new item text
if (m->mailTemplateId)
{
MailTemplateEntry const* mailTemplateEntry = sMailTemplateStore.LookupEntry(m->mailTemplateId);
if (!mailTemplateEntry)
{
player->SendMailResult(packet.MailID, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
return;
}
bodyItem->SetText(mailTemplateEntry->Body->Str[GetSessionDbcLocale()]);
}
else
bodyItem->SetText(m->body);
if (m->messageType == MAIL_NORMAL)
bodyItem->SetGuidValue(ITEM_FIELD_CREATOR, ObjectGuid::Create<HighGuid::Player>(m->sender));
bodyItem->SetFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_READABLE);
ItemPosCountVec dest;
uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, bodyItem, false);
if (msg == EQUIP_ERR_OK)
{
m->checked = m->checked | MAIL_CHECK_MASK_COPIED;
m->state = MAIL_STATE_CHANGED;
player->m_mailsUpdated = true;
player->StoreItem(dest, bodyItem, true);
player->SendMailResult(packet.MailID, MAIL_MADE_PERMANENT, MAIL_OK);
}
else
{
player->SendMailResult(packet.MailID, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg);
delete bodyItem;
}
}
bool ChatHandler::HandleLookupTitleCommand(const char* args)
{
if (!*args)
return false;
// can be NULL in console call
Player* target = getSelectedPlayer();
// title name have single string arg for player name
char const* targetName = target ? target->GetName() : "NAME";
std::string namepart = args;
std::wstring wnamepart;
if (!Utf8toWStr(namepart, wnamepart))
return false;
// converting string that we try to find to lower case
wstrToLower(wnamepart);
uint32 counter = 0; // Counter for figure out that we found smth.
uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
// Search in CharTitles.dbc
for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
{
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
if (titleInfo)
{
int loc = GetSessionDbcLocale();
std::string name = titleInfo->name[loc];
if (name.empty())
continue;
if (!Utf8FitTo(name, wnamepart))
{
loc = 0;
for (; loc < TOTAL_LOCALES; ++loc)
{
if (loc == GetSessionDbcLocale())
continue;
name = titleInfo->name[loc];
if (name.empty())
continue;
if (Utf8FitTo(name, wnamepart))
break;
}
}
if (loc < TOTAL_LOCALES)
{
if (maxResults && counter == maxResults)
{
PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults);
return true;
}
char const* knownStr = target && target->HasTitle(titleInfo) ? GetTrinityString(LANG_KNOWN) : "";
char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index
? GetTrinityString(LANG_ACTIVE)
: "";
char titleNameStr[80];
snprintf(titleNameStr, 80, name.c_str(), targetName);
// send title in "id (idx:idx) - [namedlink locale]" format
if (m_session)
PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[loc], knownStr, activeStr);
else
PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, titleNameStr, localeNames[loc], knownStr, activeStr);
++counter;
}
}
}
if (counter == 0) // if counter == 0 then we found nth
SendSysMessage(LANG_COMMAND_NOTITLEFOUND);
return true;
}
//.........这里部分代码省略.........
continue;
// check if target is globally visible for player
if (!pl->IsVisibleGloballyFor(_player))
continue;
// check if target's level is in level range
uint32 lvl = pl->getLevel();
if (lvl < level_min || lvl > level_max)
continue;
// check if class matches classmask
uint32 class_ = pl->getClass();
if (!(classmask & (1 << class_)))
continue;
// check if race matches racemask
uint32 race = pl->getRace();
if (!(racemask & (1 << race)))
continue;
uint32 pzoneid = pl->GetZoneId();
uint8 gender = pl->getGender();
bool z_show = true;
for (uint32 i = 0; i < zones_count; ++i)
{
if (zoneids[i] == pzoneid)
{
z_show = true;
break;
}
z_show = false;
}
if (!z_show)
continue;
std::string pname = pl->GetName();
std::wstring wpname;
if (!Utf8toWStr(pname, wpname))
continue;
wstrToLower(wpname);
if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
continue;
std::string gname = sGuildMgr.GetGuildNameById(pl->GetGuildId());
std::wstring wgname;
if (!Utf8toWStr(gname, wgname))
continue;
wstrToLower(wgname);
if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos))
continue;
std::string aname;
if (AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(pzoneid))
aname = areaEntry->area_name[GetSessionDbcLocale()];
bool s_show = true;
for (uint32 i = 0; i < str_count; ++i)
{
if (!str[i].empty())
{
if (wgname.find(str[i]) != std::wstring::npos ||
wpname.find(str[i]) != std::wstring::npos ||
Utf8FitTo(aname, str[i]))
{
s_show = true;
break;
}
s_show = false;
}
}
if (!s_show)
continue;
// 49 is maximum player count sent to client
++matchcount;
if (matchcount > 49)
continue;
++displaycount;
data << pname; // player name
data << gname; // guild name
data << uint32(lvl); // player level
data << uint32(class_); // player class
data << uint32(race); // player race
data << uint8(gender); // player gender
data << uint32(pzoneid); // player zone id
}
data.put(0, displaycount); // insert right count, count displayed
data.put(4, matchcount); // insert right count, count of matches
SendPacket(&data);
DEBUG_LOG("WORLD: Send SMSG_WHO Message");
}
/**
* Handles the packet sent by the client when he copies the body a mail to his inventory.
*
* When a player copies the body of a mail to his inventory this method is called. It will create
* a new item with the text of the mail and store it in the players inventory (if possible).
*
*/
void WorldSession::HandleMailCreateTextItem(WorldPacket& recv_data)
{
ObjectGuid mailboxGuid;
uint32 mailId;
recv_data >> mailboxGuid;
recv_data >> mailId;
if (!CheckMailBox(mailboxGuid))
return;
Player* pl = _player;
Mail* m = pl->GetMail(mailId);
if (!m || (m->body.empty() && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL))
{
pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
return;
}
Item* bodyItem = new Item; // This is not bag and then can be used new Item.
if (!bodyItem->Create(sObjectMgr.GenerateItemLowGuid(), MAIL_BODY_ITEM_TEMPLATE, pl))
{
delete bodyItem;
return;
}
// in mail template case we need create new item text
if (m->mailTemplateId)
{
MailTemplateEntry const* mailTemplateEntry = sMailTemplateStore.LookupEntry(m->mailTemplateId);
if (!mailTemplateEntry)
{
pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR);
return;
}
bodyItem->SetText(mailTemplateEntry->content[GetSessionDbcLocale()]);
}
else
bodyItem->SetText(m->body);
bodyItem->SetGuidValue(ITEM_FIELD_CREATOR, ObjectGuid(HIGHGUID_PLAYER, m->sender));
bodyItem->SetFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_READABLE | ITEM_DYNFLAG_UNK15 | ITEM_DYNFLAG_UNK16);
DETAIL_LOG("HandleMailCreateTextItem mailid=%u", mailId);
ItemPosCountVec dest;
InventoryResult msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, bodyItem, false);
if (msg == EQUIP_ERR_OK)
{
m->checked = m->checked | MAIL_CHECK_MASK_COPIED;
m->state = MAIL_STATE_CHANGED;
pl->m_mailsUpdated = true;
pl->StoreItem(dest, bodyItem, true);
pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_OK);
}
else
{
pl->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg);
delete bodyItem;
}
}
请发表评论