Files
TCPlayerbotCore/src/server/game/Chat/Commands/Level2.cpp
T

1130 lines
34 KiB
C++
Raw Normal View History

/*
* Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2009-10-17 15:51:44 -07:00
#include "Common.h"
2010-06-08 15:50:23 -06:00
#include "DatabaseEnv.h"
#include "DBCStores.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "Item.h"
#include "GameObject.h"
2010-06-08 15:50:23 -06:00
#include "Opcodes.h"
#include "Chat.h"
#include "MapManager.h"
2010-06-08 15:50:23 -06:00
#include "Language.h"
#include "World.h"
#include "GameEventMgr.h"
#include "SpellMgr.h"
#include "PoolMgr.h"
#include "AccountMgr.h"
2010-06-08 15:50:23 -06:00
#include "WaypointManager.h"
#include "Util.h"
#include <cctype>
#include <iostream>
#include <fstream>
#include <map>
#include "OutdoorPvPMgr.h"
#include "Transport.h"
#include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
2009-04-06 20:33:52 -05:00
#include "CreatureGroups.h"
2009-10-17 15:51:44 -07:00
//mute player for some times
bool ChatHandler::HandleMuteCommand(const char* args)
{
char* nameStr;
char* delayStr;
extractOptFirstArg((char*)args,&nameStr,&delayStr);
2010-04-07 19:14:10 +02:00
if (!delayStr)
return false;
2009-10-17 15:51:44 -07:00
2009-06-29 15:03:07 +02:00
char *mutereason = strtok(NULL, "\r");
std::string mutereasonstr = "No reason";
2010-04-07 19:14:10 +02:00
if (mutereason != NULL)
2009-06-29 15:03:07 +02:00
mutereasonstr = mutereason;
2009-10-17 16:20:24 -07:00
Player* target;
uint64 target_guid;
std::string target_name;
2010-04-07 19:14:10 +02:00
if (!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
return false;
2009-10-17 15:51:44 -07:00
2010-08-08 05:25:45 +02:00
uint32 account_id = target ? target->GetSession()->GetAccountId() : sObjectMgr.GetPlayerAccountIdByGUID(target_guid);
2009-10-17 15:51:44 -07:00
// find only player from same account if any
2010-04-07 19:14:10 +02:00
if (!target)
if (WorldSession* session = sWorld.FindSession(account_id))
target = session->GetPlayer();
2009-10-17 15:51:44 -07:00
uint32 notspeaktime = (uint32) atoi(delayStr);
2009-10-17 15:51:44 -07:00
// must have strong lesser security level
2010-04-07 19:14:10 +02:00
if (HasLowerSecurity (target,target_guid,true))
return false;
2009-10-17 15:51:44 -07:00
time_t mutetime = time(NULL) + notspeaktime*60;
2009-10-17 15:51:44 -07:00
if (target)
target->GetSession()->m_muteTime = mutetime;
2009-10-17 15:51:44 -07:00
LoginDatabase.PExecute("UPDATE account SET mutetime = " UI64FMTD " WHERE id = '%u'",uint64(mutetime), account_id);
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (target)
ChatHandler(target).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, notspeaktime, mutereasonstr.c_str());
2009-10-17 15:51:44 -07:00
std::string nameLink = playerLink(target_name);
2009-10-17 15:51:44 -07:00
2009-06-29 15:03:07 +02:00
PSendSysMessage(LANG_YOU_DISABLE_CHAT, nameLink.c_str(), notspeaktime, mutereasonstr.c_str());
2009-10-17 15:51:44 -07:00
return true;
}
2009-10-17 15:51:44 -07:00
//unmute player
bool ChatHandler::HandleUnmuteCommand(const char* args)
{
Player* target;
uint64 target_guid;
std::string target_name;
2010-04-07 19:14:10 +02:00
if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
return false;
2009-10-17 15:51:44 -07:00
2010-08-08 05:25:45 +02:00
uint32 account_id = target ? target->GetSession()->GetAccountId() : sObjectMgr.GetPlayerAccountIdByGUID(target_guid);
2009-10-17 15:51:44 -07:00
// find only player from same account if any
2010-04-07 19:14:10 +02:00
if (!target)
if (WorldSession* session = sWorld.FindSession(account_id))
target = session->GetPlayer();
2009-10-17 15:51:44 -07:00
// must have strong lesser security level
2010-04-07 19:14:10 +02:00
if (HasLowerSecurity (target,target_guid,true))
return false;
2009-10-17 15:51:44 -07:00
if (target)
{
2010-04-07 19:14:10 +02:00
if (target->CanSpeak())
{
SendSysMessage(LANG_CHAT_ALREADY_ENABLED);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
target->GetSession()->m_muteTime = 0;
}
2009-10-17 15:51:44 -07:00
LoginDatabase.PExecute("UPDATE account SET mutetime = '0' WHERE id = '%u'", account_id);
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (target)
ChatHandler(target).PSendSysMessage(LANG_YOUR_CHAT_ENABLED);
2009-10-17 15:51:44 -07:00
std::string nameLink = playerLink(target_name);
2009-10-17 15:51:44 -07:00
2009-02-02 09:50:13 -06:00
PSendSysMessage(LANG_YOU_ENABLE_CHAT, nameLink.c_str());
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandleGUIDCommand(const char* /*args*/)
{
uint64 guid = m_session->GetPlayer()->GetSelection();
2009-10-17 15:51:44 -07:00
if (guid == 0)
{
SendSysMessage(LANG_NO_SELECTION);
SetSentErrorMessage(true);
return false;
}
PSendSysMessage(LANG_OBJECT_GUID, GUID_LOPART(guid), GUID_HIPART(guid));
return true;
}
2009-10-17 15:51:44 -07:00
//move item to other slot
bool ChatHandler::HandleItemMoveCommand(const char* args)
{
2010-04-07 19:14:10 +02:00
if (!*args)
return false;
uint8 srcslot, dstslot;
2009-10-17 15:51:44 -07:00
char* pParam1 = strtok((char*)args, " ");
if (!pParam1)
return false;
2009-10-17 15:51:44 -07:00
char* pParam2 = strtok(NULL, " ");
if (!pParam2)
return false;
2009-10-17 15:51:44 -07:00
srcslot = (uint8)atoi(pParam1);
dstslot = (uint8)atoi(pParam2);
2009-10-17 15:51:44 -07:00
2010-04-07 23:25:02 +02:00
if (srcslot == dstslot)
return true;
2009-10-17 15:51:44 -07:00
if (!m_session->GetPlayer()->IsValidPos(INVENTORY_SLOT_BAG_0, srcslot, true))
return false;
2009-10-17 15:51:44 -07:00
if (!m_session->GetPlayer()->IsValidPos(INVENTORY_SLOT_BAG_0, dstslot, false))
return false;
2009-10-17 15:51:44 -07:00
uint16 src = ((INVENTORY_SLOT_BAG_0 << 8) | srcslot);
uint16 dst = ((INVENTORY_SLOT_BAG_0 << 8) | dstslot);
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
m_session->GetPlayer()->SwapItem(src, dst);
2009-10-17 15:51:44 -07:00
return true;
}
2009-10-17 15:51:44 -07:00
//demorph player or unit
bool ChatHandler::HandleDeMorphCommand(const char* /*args*/)
{
Unit *target = getSelectedUnit();
2010-04-07 19:14:10 +02:00
if (!target)
target = m_session->GetPlayer();
2008-12-29 17:27:50 -06:00
// check online security
else if (target->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player*)target, 0))
return false;
2009-10-17 15:51:44 -07:00
target->DeMorph();
2009-10-17 15:51:44 -07:00
return true;
}
2009-10-17 15:51:44 -07:00
//kick player
bool ChatHandler::HandleKickPlayerCommand(const char *args)
{
const char* kickName = strtok((char*)args, " ");
2009-02-09 08:16:34 -05:00
char* kickReason = strtok(NULL, "\n");
std::string reason = "No reason given";
std::string kicker = "CONSOLE";
2010-04-07 19:14:10 +02:00
if (kickReason)
2009-02-09 08:16:34 -05:00
reason = kickReason;
2010-04-07 19:14:10 +02:00
if (m_session)
2009-02-09 08:16:34 -05:00
kicker = m_session->GetPlayer()->GetName();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!kickName)
2009-02-12 17:09:15 -06:00
{
2009-02-09 08:16:34 -05:00
Player* player = getSelectedPlayer();
2010-04-07 19:14:10 +02:00
if (!player)
2009-02-09 08:16:34 -05:00
{
SendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2010-04-07 23:25:02 +02:00
if (player == m_session->GetPlayer())
2008-12-28 22:58:52 +01:00
{
SendSysMessage(LANG_COMMAND_KICKSELF);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2008-12-29 17:27:50 -06:00
// check online security
if (HasLowerSecurity(player, 0))
return false;
2009-10-17 15:51:44 -07:00
if (sWorld.getBoolConfig(CONFIG_SHOW_KICK_IN_WORLD) == 1)
2009-02-09 08:16:34 -05:00
{
sWorld.SendWorldText(LANG_COMMAND_KICKMESSAGE, player->GetName(), kicker.c_str(), reason.c_str());
}
else
{
PSendSysMessage(LANG_COMMAND_KICKMESSAGE, player->GetName(), kicker.c_str(), reason.c_str());
}
2009-10-17 15:51:44 -07:00
2008-12-28 22:58:52 +01:00
player->GetSession()->KickPlayer();
}
2009-02-09 08:16:34 -05:00
else
{
2009-02-02 09:50:13 -06:00
std::string name = extractPlayerNameFromLink((char*)kickName);
2010-04-07 19:14:10 +02:00
if (name.empty())
2009-02-09 08:16:34 -05:00
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2010-04-07 23:25:02 +02:00
if (m_session && name == m_session->GetPlayer()->GetName())
2009-02-09 08:16:34 -05:00
{
SendSysMessage(LANG_COMMAND_KICKSELF);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2010-08-08 05:25:45 +02:00
Player* player = sObjectMgr.GetPlayer(kickName);
2010-04-07 19:14:10 +02:00
if (!player)
2009-02-09 08:16:34 -05:00
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (HasLowerSecurity(player, 0))
2009-02-09 08:16:34 -05:00
{
SendSysMessage(LANG_YOURS_SECURITY_IS_LOW); //maybe replacement string for this later on
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-02-02 09:50:13 -06:00
std::string nameLink = playerLink(name);
2009-10-17 16:20:24 -07:00
2010-04-07 19:14:10 +02:00
if (sWorld.KickPlayer(name))
2009-02-09 08:16:34 -05:00
{
if (sWorld.getBoolConfig(CONFIG_SHOW_KICK_IN_WORLD) == 1)
2009-02-09 08:16:34 -05:00
{
sWorld.SendWorldText(LANG_COMMAND_KICKMESSAGE, nameLink.c_str(), kicker.c_str(), reason.c_str());
2009-02-09 08:16:34 -05:00
}
else
{
PSendSysMessage(LANG_COMMAND_KICKMESSAGE,nameLink.c_str());
2009-02-09 08:16:34 -05:00
}
}
else
{
PSendSysMessage(LANG_COMMAND_KICKNOTFOUNDPLAYER,nameLink.c_str());
2009-02-09 08:16:34 -05:00
return false;
}
}
Player* target;
2010-04-07 19:14:10 +02:00
if (!extractPlayerTarget((char*)args,&target))
return false;
2009-10-17 15:51:44 -07:00
2010-04-07 23:25:02 +02:00
if (m_session && target == m_session->GetPlayer())
{
SendSysMessage(LANG_COMMAND_KICKSELF);
SetSentErrorMessage(true);
return false;
2009-02-09 08:16:34 -05:00
}
2009-10-17 15:51:44 -07:00
// check online security
if (HasLowerSecurity(target, 0))
return false;
2009-10-17 15:51:44 -07:00
// send before target pointer invalidate
PSendSysMessage(LANG_COMMAND_KICKMESSAGE,GetNameLink(target).c_str());
target->GetSession()->KickPlayer();
2009-02-09 08:16:34 -05:00
return true;
}
2009-10-17 15:51:44 -07:00
//show info of player
bool ChatHandler::HandlePInfoCommand(const char* args)
{
Player* target;
uint64 target_guid;
std::string target_name;
2010-04-07 19:14:10 +02:00
if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
return false;
2009-10-17 15:51:44 -07:00
uint32 accId = 0;
uint32 money = 0;
uint32 total_player_time = 0;
uint8 level = 0;
uint32 latency = 0;
uint8 race;
uint8 Class;
2009-10-17 15:51:44 -07:00
// get additional information from Player object
2010-04-07 19:14:10 +02:00
if (target)
{
2008-12-29 17:27:50 -06:00
// check online security
if (HasLowerSecurity(target, 0))
return false;
2009-10-17 15:51:44 -07:00
accId = target->GetSession()->GetAccountId();
money = target->GetMoney();
total_player_time = target->GetTotalPlayedTime();
level = target->getLevel();
latency = target->GetSession()->GetLatency();
race = target->getRace();
Class = target->getClass();
}
// get additional information from DB
else
{
2008-12-29 17:27:50 -06:00
// check offline security
if (HasLowerSecurity(NULL, target_guid))
2008-12-29 17:27:50 -06:00
return false;
2009-10-17 15:51:44 -07:00
// 0 1 2 3 4 5
2010-09-11 21:10:54 +02:00
QueryResult result = CharacterDatabase.PQuery("SELECT totaltime, level, money, account, race, class FROM characters WHERE guid = '%u'", GUID_LOPART(target_guid));
if (!result)
return false;
2009-10-17 15:51:44 -07:00
Field *fields = result->Fetch();
total_player_time = fields[0].GetUInt32();
2009-06-27 17:39:51 -05:00
level = fields[1].GetUInt32();
money = fields[2].GetUInt32();
accId = fields[3].GetUInt32();
race = fields[4].GetUInt8();
Class = fields[5].GetUInt8();
}
2009-10-17 15:51:44 -07:00
2008-10-14 11:57:03 -05:00
std::string username = GetTrinityString(LANG_ERROR);
std::string email = GetTrinityString(LANG_ERROR);
2008-10-14 11:57:03 -05:00
std::string last_ip = GetTrinityString(LANG_ERROR);
uint32 security = 0;
2008-10-14 11:57:03 -05:00
std::string last_login = GetTrinityString(LANG_ERROR);
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
QueryResult result = LoginDatabase.PQuery("SELECT a.username,aa.gmlevel,a.email,a.last_ip,a.last_login "
"FROM account a "
"LEFT JOIN account_access aa "
"ON (a.id = aa.id) "
"WHERE a.id = '%u'",accId);
2010-04-07 19:14:10 +02:00
if (result)
{
Field* fields = result->Fetch();
2010-09-24 22:16:21 +02:00
username = fields[0].GetString();
security = fields[1].GetUInt32();
2010-09-24 22:16:21 +02:00
email = fields[2].GetString();
2009-10-17 15:51:44 -07:00
if (email.empty())
email = "-";
2009-10-17 15:51:44 -07:00
if (!m_session || m_session->GetSecurity() >= AccountTypes(security))
{
last_ip = fields[3].GetString();
last_login = fields[4].GetString();
}
else
{
last_ip = "-";
last_login = "-";
}
}
2009-10-17 15:51:44 -07:00
std::string nameLink = playerLink(target_name);
2009-10-17 15:51:44 -07:00
PSendSysMessage(LANG_PINFO_ACCOUNT, (target?"":GetTrinityString(LANG_OFFLINE)), nameLink.c_str(), GUID_LOPART(target_guid), username.c_str(), accId, email.c_str(), security, last_ip.c_str(), last_login.c_str(), latency);
std::string race_s, Class_s;
switch(race)
{
case RACE_HUMAN: race_s = "Human"; break;
case RACE_ORC: race_s = "Orc"; break;
case RACE_DWARF: race_s = "Dwarf"; break;
case RACE_NIGHTELF: race_s = "Night Elf"; break;
case RACE_UNDEAD_PLAYER: race_s = "Undead"; break;
case RACE_TAUREN: race_s = "Tauren"; break;
case RACE_GNOME: race_s = "Gnome"; break;
case RACE_TROLL: race_s = "Troll"; break;
case RACE_BLOODELF: race_s = "Blood Elf"; break;
case RACE_DRAENEI: race_s = "Draenei"; break;
}
switch(Class)
{
case CLASS_WARRIOR: Class_s = "Warrior"; break;
case CLASS_PALADIN: Class_s = "Paladin"; break;
case CLASS_HUNTER: Class_s = "Hunter"; break;
case CLASS_ROGUE: Class_s = "Rogue"; break;
case CLASS_PRIEST: Class_s = "Priest"; break;
case CLASS_DEATH_KNIGHT: Class_s = "Death Knight"; break;
case CLASS_SHAMAN: Class_s = "Shaman"; break;
case CLASS_MAGE: Class_s = "Mage"; break;
case CLASS_WARLOCK: Class_s = "Warlock"; break;
case CLASS_DRUID: Class_s = "Druid"; break;
}
2009-10-17 15:51:44 -07:00
std::string timeStr = secsToTimeString(total_player_time,true,true);
uint32 gold = money /GOLD;
uint32 silv = (money % GOLD) / SILVER;
uint32 copp = (money % GOLD) % SILVER;
PSendSysMessage(LANG_PINFO_LEVEL, race_s.c_str(), Class_s.c_str(), timeStr.c_str(), level, gold, silv, copp);
return true;
}
2009-10-17 15:51:44 -07:00
//rename characters
bool ChatHandler::HandleCharacterRenameCommand(const char* args)
{
Player* target;
uint64 target_guid;
std::string target_name;
2010-04-07 19:14:10 +02:00
if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
return false;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (target)
{
2008-12-29 17:27:50 -06:00
// check online security
if (HasLowerSecurity(target, 0))
return false;
2009-10-17 15:51:44 -07:00
PSendSysMessage(LANG_RENAME_PLAYER, GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_RENAME);
}
else
{
2008-12-29 17:27:50 -06:00
// check offline security
if (HasLowerSecurity(NULL, target_guid))
2008-12-29 17:27:50 -06:00
return false;
2009-10-17 15:51:44 -07:00
std::string oldNameLink = playerLink(target_name);
2009-10-17 15:51:44 -07:00
PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(target_guid));
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'", GUID_LOPART(target_guid));
}
2009-10-17 15:51:44 -07:00
return true;
}
2009-10-17 15:51:44 -07:00
// customize characters
bool ChatHandler::HandleCharacterCustomizeCommand(const char* args)
{
Player* target;
uint64 target_guid;
std::string target_name;
2010-04-07 19:14:10 +02:00
if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
return false;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (target)
{
PSendSysMessage(LANG_CUSTOMIZE_PLAYER, GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_CUSTOMIZE);
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'", target->GetGUIDLow());
}
else
{
std::string oldNameLink = playerLink(target_name);
2009-10-17 15:51:44 -07:00
PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(target_guid));
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'", GUID_LOPART(target_guid));
}
2009-10-17 15:51:44 -07:00
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandleCharacterChangeFactionCommand(const char * args)
{
Player* target;
uint64 target_guid;
std::string target_name;
if(!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
return false;
if(target)
{
// TODO : add text into database
PSendSysMessage(LANG_CUSTOMIZE_PLAYER, GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_CHANGE_FACTION);
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '64' WHERE guid = %u", target->GetGUIDLow());
}
else
{
std::string oldNameLink = playerLink(target_name);
// TODO : add text into database
PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(target_guid));
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '64' WHERE guid = %u", GUID_LOPART(target_guid));
}
return true;
}
bool ChatHandler::HandleCharacterChangeRaceCommand(const char * args)
{
Player* target;
uint64 target_guid;
std::string target_name;
if(!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
return false;
if(target)
{
// TODO : add text into database
PSendSysMessage(LANG_CUSTOMIZE_PLAYER, GetNameLink(target).c_str());
target->SetAtLoginFlag(AT_LOGIN_CHANGE_RACE);
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '128' WHERE guid = %u", target->GetGUIDLow());
}
else
{
std::string oldNameLink = playerLink(target_name);
// TODO : add text into database
PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, oldNameLink.c_str(), GUID_LOPART(target_guid));
CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '128' WHERE guid = %u", GUID_LOPART(target_guid));
}
return true;
}
bool ChatHandler::HandleCharacterReputationCommand(const char* args)
{
Player* target;
2010-04-07 19:14:10 +02:00
if (!extractPlayerTarget((char*)args,&target))
return false;
2009-10-17 15:51:44 -07:00
LocaleConstant loc = GetSessionDbcLocale();
2009-10-17 15:51:44 -07:00
FactionStateList const& targetFSL = target->GetReputationMgr().GetStateList();
2009-10-17 16:20:24 -07:00
for (FactionStateList::const_iterator itr = targetFSL.begin(); itr != targetFSL.end(); ++itr)
{
FactionEntry const *factionEntry = sFactionStore.LookupEntry(itr->second.ID);
char const* factionName = factionEntry ? factionEntry->name[loc] : "#Not found#";
ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
2009-12-20 15:20:04 +01:00
std::string rankName = GetTrinityString(ReputationRankStrIndex[rank]);
std::ostringstream ss;
if (m_session)
ss << itr->second.ID << " - |cffffffff|Hfaction:" << itr->second.ID << "|h[" << factionName << " " << localeNames[loc] << "]|h|r";
else
ss << itr->second.ID << " - " << factionName << " " << localeNames[loc];
2009-10-17 15:51:44 -07:00
ss << " " << rankName << " (" << target->GetReputationMgr().GetReputation(factionEntry) << ")";
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (itr->second.Flags & FACTION_FLAG_VISIBLE)
2009-12-20 15:20:04 +01:00
ss << GetTrinityString(LANG_FACTION_VISIBLE);
2010-04-07 19:14:10 +02:00
if (itr->second.Flags & FACTION_FLAG_AT_WAR)
2009-12-20 15:20:04 +01:00
ss << GetTrinityString(LANG_FACTION_ATWAR);
2010-04-07 19:14:10 +02:00
if (itr->second.Flags & FACTION_FLAG_PEACE_FORCED)
2009-12-20 15:20:04 +01:00
ss << GetTrinityString(LANG_FACTION_PEACE_FORCED);
2010-04-07 19:14:10 +02:00
if (itr->second.Flags & FACTION_FLAG_HIDDEN)
2009-12-20 15:20:04 +01:00
ss << GetTrinityString(LANG_FACTION_HIDDEN);
2010-04-07 19:14:10 +02:00
if (itr->second.Flags & FACTION_FLAG_INVISIBLE_FORCED)
2009-12-20 15:20:04 +01:00
ss << GetTrinityString(LANG_FACTION_INVISIBLE_FORCED);
2010-04-07 19:14:10 +02:00
if (itr->second.Flags & FACTION_FLAG_INACTIVE)
2009-12-20 15:20:04 +01:00
ss << GetTrinityString(LANG_FACTION_INACTIVE);
2009-10-17 15:51:44 -07:00
SendSysMessage(ss.str().c_str());
}
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandleLookupEventCommand(const char* args)
{
2010-04-07 19:14:10 +02:00
if (!*args)
return false;
2009-10-17 15:51:44 -07:00
std::string namepart = args;
std::wstring wnamepart;
2009-10-17 15:51:44 -07:00
// converting string that we try to find to lower case
2010-04-07 19:14:10 +02:00
if (!Utf8toWStr(namepart,wnamepart))
return false;
2009-10-17 15:51:44 -07:00
wstrToLower(wnamepart);
2009-10-17 15:51:44 -07:00
bool found = false;
uint32 count = 0;
uint32 maxResults = sWorld.getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
2009-10-17 15:51:44 -07:00
2010-08-08 05:25:45 +02:00
GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
for (uint32 id = 0; id < events.size(); ++id)
{
GameEventData const& eventData = events[id];
2009-10-17 15:51:44 -07:00
std::string descr = eventData.description;
2010-04-07 19:14:10 +02:00
if (descr.empty())
continue;
2009-10-17 15:51:44 -07:00
if (Utf8FitTo(descr, wnamepart))
{
if (maxResults && count++ == maxResults)
{
PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults);
return true;
}
2008-12-30 16:12:56 -06:00
char const* active = activeEvents.find(id) != activeEvents.end() ? GetTrinityString(LANG_ACTIVE) : "";
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (m_session)
2010-04-07 22:59:46 +02:00
PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT,id,id,eventData.description.c_str(),active);
2008-12-29 17:27:50 -06:00
else
2010-04-07 22:59:46 +02:00
PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE,id,eventData.description.c_str(),active);
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!found)
found = true;
}
}
2009-10-17 15:51:44 -07:00
if (!found)
SendSysMessage(LANG_NOEVENTFOUND);
2009-10-17 15:51:44 -07:00
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandleCombatStopCommand(const char* args)
{
Player* target;
2010-04-07 19:14:10 +02:00
if (!extractPlayerTarget((char*)args,&target))
return false;
2009-10-17 15:51:44 -07:00
2008-12-29 17:27:50 -06:00
// check online security
if (HasLowerSecurity(target, 0))
2008-12-29 17:27:50 -06:00
return false;
2009-10-17 15:51:44 -07:00
target->CombatStop();
2010-03-09 11:11:10 +01:00
target->getHostileRefManager().deleteReferences();
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandleLookupPlayerIpCommand(const char* args)
{
2009-10-17 15:51:44 -07:00
if (!*args)
return false;
2009-10-17 15:51:44 -07:00
std::string ip = strtok ((char*)args, " ");
2008-12-29 17:27:50 -06:00
char* limit_str = strtok (NULL, " ");
int32 limit = limit_str ? atoi (limit_str) : -1;
2009-10-17 15:51:44 -07:00
LoginDatabase.escape_string (ip);
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
QueryResult result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip.c_str ());
2009-10-17 15:51:44 -07:00
return LookupPlayerSearchCommand (result,limit);
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandleLookupPlayerAccountCommand(const char* args)
{
if (!*args)
return false;
2009-10-17 15:51:44 -07:00
std::string account = strtok ((char*)args, " ");
2008-12-29 17:27:50 -06:00
char* limit_str = strtok (NULL, " ");
int32 limit = limit_str ? atoi (limit_str) : -1;
2009-10-17 15:51:44 -07:00
2009-05-21 19:46:56 +02:00
if (!AccountMgr::normalizeString (account))
return false;
2009-10-17 15:51:44 -07:00
LoginDatabase.escape_string (account);
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
QueryResult result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account.c_str ());
2009-10-17 15:51:44 -07:00
return LookupPlayerSearchCommand (result,limit);
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandleLookupPlayerEmailCommand(const char* args)
{
2009-10-17 15:51:44 -07:00
if (!*args)
return false;
2009-10-17 15:51:44 -07:00
std::string email = strtok ((char*)args, " ");
2008-12-29 17:27:50 -06:00
char* limit_str = strtok (NULL, " ");
int32 limit = limit_str ? atoi (limit_str) : -1;
2009-10-17 15:51:44 -07:00
LoginDatabase.escape_string (email);
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
QueryResult result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email.c_str ());
2009-10-17 15:51:44 -07:00
return LookupPlayerSearchCommand (result,limit);
}
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
bool ChatHandler::LookupPlayerSearchCommand(QueryResult result, int32 limit)
{
2010-04-07 19:14:10 +02:00
if (!result)
{
PSendSysMessage(LANG_NO_PLAYERS_FOUND);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2010-08-06 00:15:29 +06:00
int i = 0;
uint32 count = 0;
uint32 maxResults = sWorld.getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
do
{
if (maxResults && count++ == maxResults)
{
PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults);
return true;
}
Field* fields = result->Fetch();
uint32 acc_id = fields[0].GetUInt32();
2010-09-24 22:16:21 +02:00
std::string acc_name = fields[1].GetString();
2009-10-17 15:51:44 -07:00
2010-09-11 21:10:54 +02:00
QueryResult chars = CharacterDatabase.PQuery("SELECT guid,name FROM characters WHERE account = '%u'", acc_id);
2010-04-07 19:14:10 +02:00
if (chars)
{
PSendSysMessage(LANG_LOOKUP_PLAYER_ACCOUNT,acc_name.c_str(),acc_id);
2009-10-17 15:51:44 -07:00
uint64 guid = 0;
std::string name;
2009-10-17 15:51:44 -07:00
do
{
Field* charfields = chars->Fetch();
guid = charfields[0].GetUInt64();
2010-09-24 22:16:21 +02:00
name = charfields[1].GetString();
2009-10-17 15:51:44 -07:00
PSendSysMessage(LANG_LOOKUP_PLAYER_CHARACTER,name.c_str(),guid);
++i;
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
} while (chars->NextRow() && (limit == -1 || i < limit));
}
2010-04-07 19:13:19 +02:00
} while (result->NextRow());
2009-10-17 15:51:44 -07:00
2010-04-07 23:25:02 +02:00
if (i == 0) // empty accounts only
{
PSendSysMessage(LANG_NO_PLAYERS_FOUND);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
return true;
}
2009-10-17 15:51:44 -07:00
/// Triggering corpses expire check in world
bool ChatHandler::HandleServerCorpsesCommand(const char* /*args*/)
{
2010-08-06 00:15:29 +06:00
sObjectAccessor.RemoveOldCorpses();
2008-12-29 17:27:50 -06:00
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandleRepairitemsCommand(const char* args)
{
Player* target;
2010-04-07 19:14:10 +02:00
if (!extractPlayerTarget((char*)args,&target))
return false;
2009-10-17 15:51:44 -07:00
2008-12-29 17:27:50 -06:00
// check online security
if (HasLowerSecurity(target, 0))
return false;
2009-10-17 15:51:44 -07:00
// Repair items
target->DurabilityRepairAll(false, 0, false);
2009-10-17 15:51:44 -07:00
PSendSysMessage(LANG_YOU_REPAIR_ITEMS, GetNameLink(target).c_str());
2010-04-07 19:14:10 +02:00
if (needReportToTarget(target))
ChatHandler(target).PSendSysMessage(LANG_YOUR_ITEMS_REPAIRED, GetNameLink().c_str());
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandleWaterwalkCommand(const char* args)
{
2010-04-07 19:14:10 +02:00
if (!*args)
return false;
2009-10-17 15:51:44 -07:00
Player *player = getSelectedPlayer();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!player)
{
PSendSysMessage(LANG_NO_CHAR_SELECTED);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2008-12-29 17:27:50 -06:00
// check online security
if (HasLowerSecurity(player, 0))
return false;
2009-10-17 15:51:44 -07:00
if (strncmp(args, "on", 3) == 0)
player->SetMovement(MOVE_WATER_WALK); // ON
else if (strncmp(args, "off", 4) == 0)
player->SetMovement(MOVE_LAND_WALK); // OFF
else
{
SendSysMessage(LANG_USE_BOL);
return false;
}
2009-10-17 15:51:44 -07:00
PSendSysMessage(LANG_YOU_SET_WATERWALK, args, GetNameLink(player).c_str());
2010-04-07 19:14:10 +02:00
if (needReportToTarget(player))
ChatHandler(player).PSendSysMessage(LANG_YOUR_WATERWALK_SET, args, GetNameLink().c_str());
return true;
}
2009-10-17 15:51:44 -07:00
2010-04-19 09:26:37 +02:00
bool ChatHandler::HandleCreatePetCommand(const char* /*args*/)
{
2009-02-09 08:16:34 -05:00
Player *player = m_session->GetPlayer();
Creature *creatureTarget = getSelectedCreature();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!creatureTarget || creatureTarget->isPet() || creatureTarget->GetTypeId() == TYPEID_PLAYER)
2009-02-09 08:16:34 -05:00
{
PSendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2010-08-08 05:25:45 +02:00
CreatureInfo const* cInfo = sObjectMgr.GetCreatureTemplate(creatureTarget->GetEntry());
2009-02-09 08:16:34 -05:00
// Creatures with family 0 crashes the server
2010-04-07 19:14:10 +02:00
if (cInfo->family == 0)
2009-02-09 08:16:34 -05:00
{
PSendSysMessage("This creature cannot be tamed. (family id: 0).");
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (player->GetPetGUID())
2009-02-09 08:16:34 -05:00
{
PSendSysMessage("You already have a pet");
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
// Everything looks OK, create new pet
2009-03-25 21:32:34 -06:00
Pet* pet = new Pet(player, HUNTER_PET);
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!pet)
return false;
2009-10-17 16:20:24 -07:00
2010-04-07 19:14:10 +02:00
if (!pet->CreateBaseAtCreature(creatureTarget))
2009-02-09 08:16:34 -05:00
{
delete pet;
PSendSysMessage("Error 1");
return false;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
creatureTarget->setDeathState(JUST_DIED);
creatureTarget->RemoveCorpse();
creatureTarget->SetHealth(0); // just for nice GM-mode view
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, player->GetGUID());
pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, player->getFaction());
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!pet->InitStatsForLevel(creatureTarget->getLevel()))
2009-02-09 08:16:34 -05:00
{
sLog.outError("InitStatsForLevel() in EffectTameCreature failed! Pet deleted.");
2009-02-09 08:16:34 -05:00
PSendSysMessage("Error 2");
delete pet;
2009-02-09 08:16:34 -05:00
return false;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
// prepare visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()-1);
2009-10-17 15:51:44 -07:00
2010-08-26 01:20:57 +06:00
pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
// this enables pet details window (Shift+P)
pet->InitPetCreateSpells();
pet->SetFullHealth();
2009-10-17 15:51:44 -07:00
2010-08-26 01:20:57 +06:00
pet->GetMap()->Add(pet->ToCreature());
2009-10-17 15:51:44 -07:00
2010-08-26 01:20:57 +06:00
// visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel());
2009-10-17 15:51:44 -07:00
2010-08-26 01:20:57 +06:00
player->SetMinion(pet, true);
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
player->PetSpellInitialize();
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandlePetLearnCommand(const char* args)
{
2010-04-07 19:14:10 +02:00
if (!*args)
2009-02-09 08:16:34 -05:00
return false;
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
Player *plr = m_session->GetPlayer();
Pet *pet = plr->GetPet();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!pet)
2009-02-09 08:16:34 -05:00
{
PSendSysMessage("You have no pet");
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
uint32 spellId = extractSpellIdFromLink((char*)args);
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!spellId || !sSpellStore.LookupEntry(spellId))
return false;
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
// Check if pet already has it
2010-04-07 19:14:10 +02:00
if (pet->HasSpell(spellId))
2009-02-09 08:16:34 -05:00
{
PSendSysMessage("Pet already has spell: %u", spellId);
SetSentErrorMessage(true);
return false;
2009-02-09 08:16:34 -05:00
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
// Check if spell is valid
SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId);
2010-04-07 19:14:10 +02:00
if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
{
PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spellId);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
pet->learnSpell(spellId);
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
PSendSysMessage("Pet has learned spell %u", spellId);
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandlePetUnlearnCommand(const char *args)
{
2010-04-07 19:14:10 +02:00
if (!*args)
2009-02-09 08:16:34 -05:00
return false;
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
Player *plr = m_session->GetPlayer();
Pet *pet = plr->GetPet();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!pet)
2009-02-09 08:16:34 -05:00
{
PSendSysMessage("You have no pet");
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
uint32 spellId = extractSpellIdFromLink((char*)args);
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (pet->HasSpell(spellId))
pet->removeSpell(spellId, false);
2009-02-09 08:16:34 -05:00
else
PSendSysMessage("Pet doesn't have that spell");
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandlePetTpCommand(const char *args)
{
2010-04-07 19:14:10 +02:00
if (!*args)
2009-02-09 08:16:34 -05:00
return false;
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
Player *plr = m_session->GetPlayer();
Pet *pet = plr->GetPet();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!pet)
2009-02-09 08:16:34 -05:00
{
PSendSysMessage("You have no pet");
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
uint32 tp = atol(args);
2009-10-17 15:51:44 -07:00
//pet->SetTP(tp);
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
PSendSysMessage("Pet's tp changed to %u", tp);
return true;
}
2009-10-17 15:51:44 -07:00
bool ChatHandler::HandleLookupTitleCommand(const char* args)
{
2010-04-07 19:14:10 +02:00
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;
2010-04-07 19:14:10 +02:00
if (!Utf8toWStr(namepart,wnamepart))
return false;
// converting string that we try to find to lower case
2010-04-07 22:59:46 +02:00
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);
2010-04-07 19:14:10 +02:00
if (titleInfo)
{
int loc = GetSessionDbcLocale();
std::string name = titleInfo->name[loc];
2010-04-07 19:14:10 +02:00
if (name.empty())
continue;
if (!Utf8FitTo(name, wnamepart))
{
loc = 0;
2010-09-28 08:21:51 +03:00
for (; loc < TOTAL_LOCALES; ++loc)
{
2010-04-07 23:25:02 +02:00
if (loc == GetSessionDbcLocale())
continue;
name = titleInfo->name[loc];
2010-04-07 19:14:10 +02:00
if (name.empty())
continue;
if (Utf8FitTo(name, wnamepart))
break;
}
}
2010-09-28 08:21:51 +03:00
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) : "";
2010-04-07 23:25:02 +02:00
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;
}
bool ChatHandler::HandleCharacterTitlesCommand(const char* args)
{
if (!*args)
return false;
Player* target;
2010-04-07 19:14:10 +02:00
if (!extractPlayerTarget((char*)args,&target))
return false;
LocaleConstant loc = GetSessionDbcLocale();
char const* targetName = target->GetName();
char const* knownStr = GetTrinityString(LANG_KNOWN);
// Search in CharTitles.dbc
for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
{
CharTitlesEntry const *titleInfo = sCharTitlesStore.LookupEntry(id);
if (titleInfo && target->HasTitle(titleInfo))
{
std::string name = titleInfo->name[loc];
2010-04-07 19:14:10 +02:00
if (name.empty())
continue;
2010-04-07 23:25:02 +02:00
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,name.c_str(),localeNames[loc],knownStr,activeStr);
}
}
return true;
}