aboutsummaryrefslogtreecommitdiff
path: root/src/game/Level3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Level3.cpp')
-rw-r--r--src/game/Level3.cpp1435
1 files changed, 1029 insertions, 406 deletions
diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp
index 71ee2fbab62..c2c8645a27d 100644
--- a/src/game/Level3.cpp
+++ b/src/game/Level3.cpp
@@ -52,6 +52,7 @@
#include "BattleGroundMgr.h"
#include "InstanceSaveMgr.h"
#include "InstanceData.h"
+#include "AccountMgr.h"
//reload commands
bool ChatHandler::HandleReloadCommand(const char* arg)
@@ -681,56 +682,47 @@ bool ChatHandler::HandleLoadScriptsCommand(const char* args)
return true;
}
-bool ChatHandler::HandleSecurityCommand(const char* args)
+bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
{
char* arg1 = strtok((char*)args, " ");
if( !arg1 )
return false;
- char* arg2 = 0;
+ char* arg2 = strtok(NULL, " ");
- std::string targetName;
+ std::string targetAccountName;
uint32 targetAccountId = 0;
uint32 targetSecurity = 0;
+ /// only target player different from self allowed (if targetPlayer!=NULL then not console)
Player* targetPlayer = getSelectedPlayer();
- if(targetPlayer)
+ if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
{
- targetName = targetPlayer->GetName();
+ /// wrong command syntax or unexpected targeting
+ if(arg2)
+ return false;
+
targetAccountId = targetPlayer->GetSession()->GetAccountId();
targetSecurity = targetPlayer->GetSession()->GetSecurity();
- arg2 = arg1;
+ if(!accmgr.GetName(targetAccountId,targetAccountName))
+ {
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
+ SetSentErrorMessage(true);
+ return false;
+ }
}
else
{
- targetName = arg1;
- if(!normalizePlayerName(targetName))
+ targetAccountName = arg1;
+ if(!AccountMgr::normilizeString(targetAccountName))
{
- SendSysMessage(LANG_PLAYER_NOT_FOUND);
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
SetSentErrorMessage(true);
return false;
}
- targetPlayer = ObjectAccessor::Instance().FindPlayerByName(targetName.c_str());
- if(targetPlayer)
- {
- targetAccountId = targetPlayer->GetSession()->GetAccountId();
- targetSecurity = targetPlayer->GetSession()->GetSecurity();
- }
- else
- {
- uint64 targetGUID = objmgr.GetPlayerGUIDByName(targetName.c_str());
- if(!targetGUID)
- {
- SendSysMessage(LANG_PLAYER_NOT_FOUND);
- SetSentErrorMessage(true);
- return false;
- }
- targetAccountId = objmgr.GetPlayerAccountIdByGUID(targetGUID);
- targetSecurity = accmgr.GetSecurity(targetAccountId);
- }
-
- arg2 = strtok(NULL, " ");
+ targetAccountId = accmgr.GetId(targetAccountName);
+ targetSecurity = accmgr.GetSecurity(targetAccountId);
}
int32 gm = (int32)atoi(arg2);
@@ -741,8 +733,12 @@ bool ChatHandler::HandleSecurityCommand(const char* args)
return false;
}
- // can set security level only for target with less security and to less security that we have
- if(targetSecurity >= m_session->GetSecurity() || uint32(gm) >= m_session->GetSecurity() )
+ /// m_session==NULL only for console
+ uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
+
+ /// can set security level only for target with less security and to less security that we have
+ /// This is also reject self apply in fact
+ if(targetSecurity >= plSecurity || uint32(gm) >= plSecurity )
{
SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
SetSentErrorMessage(true);
@@ -751,18 +747,91 @@ bool ChatHandler::HandleSecurityCommand(const char* args)
if(targetPlayer)
{
- if( targetPlayer != m_session->GetPlayer() )
- ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,m_session->GetPlayer()->GetName(), gm);
-
+ ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,m_session->GetPlayer()->GetName(), gm);
targetPlayer->GetSession()->SetSecurity(gm);
}
- PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetName.c_str(), gm);
+ PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
return true;
}
+/// Set password for account
+bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
+{
+ if(!*args)
+ return false;
+
+ ///- Get the command line arguments
+ char *szAccount = strtok ((char*)args," ");
+ char *szPassword1 = strtok (NULL," ");
+ char *szPassword2 = strtok (NULL," ");
+
+ if (!szAccount||!szPassword1 || !szPassword2)
+ return false;
+
+ std::string account_name = szAccount;
+ if(!AccountMgr::normilizeString(account_name))
+ {
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ uint32 targetAccountId = accmgr.GetId(account_name);
+ if (!targetAccountId)
+ {
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ uint32 targetSecurity = accmgr.GetSecurity(targetAccountId);
+
+ /// m_session==NULL only for console
+ uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
+
+ /// can set password only for target with less security
+ /// This is also reject self apply in fact
+ if (targetSecurity >= plSecurity)
+ {
+ SendSysMessage (LANG_YOURS_SECURITY_IS_LOW);
+ SetSentErrorMessage (true);
+ return false;
+ }
+
+ if (strcmp(szPassword1,szPassword2))
+ {
+ SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
+ SetSentErrorMessage (true);
+ return false;
+ }
+
+ AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
+
+ switch(result)
+ {
+ case AOR_OK:
+ SendSysMessage(LANG_COMMAND_PASSWORD);
+ break;
+ case AOR_NAME_NOT_EXIST:
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
+ SetSentErrorMessage(true);
+ return false;
+ case AOR_PASS_TOO_LONG:
+ SendSysMessage(LANG_PASSWORD_TOO_LONG);
+ SetSentErrorMessage(true);
+ return false;
+ default:
+ SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ return true;
+}
+
bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
{
if(sWorld.getAllowMovement())
@@ -1976,10 +2045,16 @@ bool ChatHandler::HandleListItemCommand(const char* args)
char* cId = extractKeyFromLink((char*)args,"Hitem");
if(!cId)
return false;
- uint32 item_id = atol(cId);
-
- ItemPrototype const* itemProto = item_id ? itemProto = objmgr.GetItemPrototype(item_id) : NULL;
+ uint32 item_id = atol(cId);
+ if(!item_id)
+ {
+ PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
if(!itemProto)
{
PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
@@ -2135,14 +2210,53 @@ bool ChatHandler::HandleListItemCommand(const char* args)
delete result;
}
- if(inv_count+mail_count+auc_count == 0)
+ // guild bank case
+ uint32 guild_count = 0;
+ result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
+ if(result)
+ {
+ guild_count = (*result)[0].GetUInt32();
+ delete result;
+ }
+
+ result=CharacterDatabase.PQuery(
+ // 0 1 2
+ "SELECT gi.item_guid, gi.guildid, guild.name "
+ "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
+ item_id,uint32(count));
+
+ if(result)
+ {
+ do
+ {
+ Field *fields = result->Fetch();
+ uint32 item_guid = fields[0].GetUInt32();
+ uint32 guild_guid = fields[1].GetUInt32();
+ std::string guild_name = fields[2].GetCppString();
+
+ char const* item_pos = "[in guild bank]";
+
+ PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
+ } while (result->NextRow());
+
+ int64 res_count = result->GetRowCount();
+
+ delete result;
+
+ if(count > res_count)
+ count-=res_count;
+ else if(count)
+ count = 0;
+ }
+
+ if(inv_count+mail_count+auc_count+guild_count == 0)
{
SendSysMessage(LANG_COMMAND_NOITEMFOUND);
SetSentErrorMessage(true);
return false;
}
- PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count,inv_count,mail_count,auc_count);
+ PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
return true;
}
@@ -2152,16 +2266,21 @@ bool ChatHandler::HandleListObjectCommand(const char* args)
if(!*args)
return false;
- // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
+ // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
if(!cId)
return false;
uint32 go_id = atol(cId);
+ if(!go_id)
+ {
+ PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
+ SetSentErrorMessage(true);
+ return false;
+ }
GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
-
- if(!go_id || !gInfo)
+ if(!gInfo)
{
PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
SetSentErrorMessage(true);
@@ -2174,7 +2293,6 @@ bool ChatHandler::HandleListObjectCommand(const char* args)
if(count < 0)
return false;
- Player* pl = m_session->GetPlayer();
QueryResult *result;
uint32 obj_count = 0;
@@ -2185,8 +2303,15 @@ bool ChatHandler::HandleListObjectCommand(const char* args)
delete result;
}
- result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
- pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
+ if(m_session)
+ {
+ Player* pl = m_session->GetPlayer();
+ result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
+ pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
+ }
+ else
+ result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
+ go_id,uint32(count));
if (result)
{
@@ -2199,7 +2324,10 @@ bool ChatHandler::HandleListObjectCommand(const char* args)
float z = fields[3].GetFloat();
int mapid = fields[4].GetUInt16();
- PSendSysMessage(LANG_GO_LIST, guid, guid, gInfo->name, x, y, z, mapid);
+ if (m_session)
+ PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
+ else
+ PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
} while (result->NextRow());
delete result;
@@ -2238,7 +2366,7 @@ bool ChatHandler::HandleNearObjectCommand(const char* args)
if(!gInfo)
continue;
- PSendSysMessage(LANG_GO_LIST, guid, guid, gInfo->name, x, y, z, mapid);
+ PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
++count;
} while (result->NextRow());
@@ -2293,16 +2421,21 @@ bool ChatHandler::HandleListCreatureCommand(const char* args)
if(!*args)
return false;
- // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
+ // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
if(!cId)
return false;
uint32 cr_id = atol(cId);
+ if(!cr_id)
+ {
+ PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
+ SetSentErrorMessage(true);
+ return false;
+ }
CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
-
- if(!cr_id || !cInfo)
+ if(!cInfo)
{
PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
SetSentErrorMessage(true);
@@ -2315,7 +2448,6 @@ bool ChatHandler::HandleListCreatureCommand(const char* args)
if(count < 0)
return false;
- Player* pl = m_session->GetPlayer();
QueryResult *result;
uint32 cr_count = 0;
@@ -2326,8 +2458,15 @@ bool ChatHandler::HandleListCreatureCommand(const char* args)
delete result;
}
- result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
- pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
+ if(m_session)
+ {
+ Player* pl = m_session->GetPlayer();
+ result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
+ pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
+ }
+ else
+ result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
+ cr_id,uint32(count));
if (result)
{
@@ -2340,7 +2479,10 @@ bool ChatHandler::HandleListCreatureCommand(const char* args)
float z = fields[3].GetFloat();
int mapid = fields[4].GetUInt16();
- PSendSysMessage(LANG_CREATURE_LIST, guid, guid, cInfo->Name, x, y, z, mapid);
+ if (m_session)
+ PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
+ else
+ PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
} while (result->NextRow());
delete result;
@@ -2373,7 +2515,7 @@ bool ChatHandler::HandleLookupItemCommand(const char* args)
if(!pProto)
continue;
- int loc_idx = m_session->GetSessionDbLocaleIndex();
+ int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
if ( loc_idx >= 0 )
{
ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
@@ -2385,7 +2527,10 @@ bool ChatHandler::HandleLookupItemCommand(const char* args)
if (Utf8FitTo(name, wnamepart))
{
- PSendSysMessage(LANG_ITEM_LIST, id, id, name.c_str());
+ if (m_session)
+ PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
+ else
+ PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
++counter;
continue;
}
@@ -2399,7 +2544,10 @@ bool ChatHandler::HandleLookupItemCommand(const char* args)
if (Utf8FitTo(name, wnamepart))
{
- PSendSysMessage(LANG_ITEM_LIST, id, id, name.c_str());
+ if (m_session)
+ PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
+ else
+ PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
++counter;
}
}
@@ -2432,8 +2580,8 @@ bool ChatHandler::HandleLookupItemSetCommand(const char* args)
ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
if(set)
{
- int loc = m_session->GetSessionDbcLocale();
- std::string name = set->name[m_session->GetSessionDbcLocale()];
+ int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
+ std::string name = set->name[loc];
if(name.empty())
continue;
@@ -2442,10 +2590,10 @@ bool ChatHandler::HandleLookupItemSetCommand(const char* args)
loc = 0;
for(; loc < MAX_LOCALE; ++loc)
{
- if(loc==m_session->GetSessionDbcLocale())
+ if(m_session && loc==m_session->GetSessionDbcLocale())
continue;
- name = set->name[m_session->GetSessionDbcLocale()];
+ name = set->name[loc];
if(name.empty())
continue;
@@ -2457,7 +2605,10 @@ bool ChatHandler::HandleLookupItemSetCommand(const char* args)
if(loc < MAX_LOCALE)
{
// send item set in "id - [namedlink locale]" format
- PSendSysMessage(LANG_ITEMSET_LIST,id,id,name.c_str(),localeNames[loc]);
+ if (m_session)
+ PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
+ else
+ PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
++counter;
}
}
@@ -2469,16 +2620,11 @@ bool ChatHandler::HandleLookupItemSetCommand(const char* args)
bool ChatHandler::HandleLookupSkillCommand(const char* args)
{
- Player* target = getSelectedPlayer();
- if(!target)
- {
- SendSysMessage(LANG_PLAYER_NOT_FOUND);
- SetSentErrorMessage(true);
+ if (!*args)
return false;
- }
- if(!*args)
- return false;
+ // can be NULL in console call
+ Player* target = getSelectedPlayer();
std::string namepart = args;
std::wstring wnamepart;
@@ -2497,7 +2643,7 @@ bool ChatHandler::HandleLookupSkillCommand(const char* args)
SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
if(skillInfo)
{
- int loc = m_session->GetSessionDbcLocale();
+ int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
std::string name = skillInfo->name[loc];
if(name.empty())
continue;
@@ -2507,7 +2653,7 @@ bool ChatHandler::HandleLookupSkillCommand(const char* args)
loc = 0;
for(; loc < MAX_LOCALE; ++loc)
{
- if(loc==m_session->GetSessionDbcLocale())
+ if(m_session && loc==m_session->GetSessionDbcLocale())
continue;
name = skillInfo->name[loc];
@@ -2521,8 +2667,15 @@ bool ChatHandler::HandleLookupSkillCommand(const char* args)
if(loc < MAX_LOCALE)
{
+ char const* knownStr = "";
+ if(target && target->HasSkill(id))
+ knownStr = GetTrinityString(LANG_KNOWN);
+
// send skill in "id - [namedlink locale]" format
- PSendSysMessage(LANG_SKILL_LIST,id,id,name.c_str(),localeNames[loc],(target->HasSkill(id) ? m_session->GetTrinityString(LANG_KNOWN) : ""));
+ if (m_session)
+ PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr);
+ else
+ PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr);
++counter;
}
@@ -2535,16 +2688,11 @@ bool ChatHandler::HandleLookupSkillCommand(const char* args)
bool ChatHandler::HandleLookupSpellCommand(const char* args)
{
- Player* target = getSelectedPlayer();
- if( !target )
- {
- SendSysMessage(LANG_PLAYER_NOT_FOUND);
- SetSentErrorMessage(true);
+ if (!*args)
return false;
- }
- if(!*args)
- return false;
+ // can be NULL at console call
+ Player* target = getSelectedPlayer();
std::string namepart = args;
std::wstring wnamepart;
@@ -2563,7 +2711,7 @@ bool ChatHandler::HandleLookupSpellCommand(const char* args)
SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
if(spellInfo)
{
- int loc = m_session->GetSessionDbcLocale();
+ int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
std::string name = spellInfo->SpellName[loc];
if(name.empty())
continue;
@@ -2573,7 +2721,7 @@ bool ChatHandler::HandleLookupSpellCommand(const char* args)
loc = 0;
for(; loc < MAX_LOCALE; ++loc)
{
- if(loc==m_session->GetSessionDbcLocale())
+ if(m_session && loc==m_session->GetSessionDbcLocale())
continue;
name = spellInfo->SpellName[loc];
@@ -2587,14 +2735,14 @@ bool ChatHandler::HandleLookupSpellCommand(const char* args)
if(loc < MAX_LOCALE)
{
- bool known = target->HasSpell(id);
+ bool known = target && target->HasSpell(id);
bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
uint32 telentCost = GetTalentSpellCost(id);
bool talent = (telentCost > 0);
bool passive = IsPassiveSpell(id);
- bool active = target->HasAura(id,0) || target->HasAura(id,1) || target->HasAura(id,2);
+ bool active = target && (target->HasAura(id,0) || target->HasAura(id,1) || target->HasAura(id,2));
// unit32 used to prevent interpreting uint8 as char at output
// find rank of learned spell for learning spell, or talent rank
@@ -2602,13 +2750,19 @@ bool ChatHandler::HandleLookupSpellCommand(const char* args)
// send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
std::ostringstream ss;
- ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
+ if (m_session)
+ ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
+ else
+ ss << id << " - " << name;
// include rank in link name
if(rank)
ss << GetTrinityString(LANG_SPELL_RANK) << rank;
- ss << " " << localeNames[loc] << "]|h|r";
+ if (m_session)
+ ss << " " << localeNames[loc] << "]|h|r";
+ else
+ ss << " " << localeNames[loc];
if(talent)
ss << GetTrinityString(LANG_TALENT);
@@ -2634,16 +2788,11 @@ bool ChatHandler::HandleLookupSpellCommand(const char* args)
bool ChatHandler::HandleLookupQuestCommand(const char* args)
{
- Player* target = getSelectedPlayer();
- if( !target )
- {
- SendSysMessage(LANG_PLAYER_NOT_FOUND);
- SetSentErrorMessage(true);
+ if (!*args)
return false;
- }
- if(!*args)
- return false;
+ // can be NULL at console call
+ Player* target = getSelectedPlayer();
std::string namepart = args;
std::wstring wnamepart;
@@ -2661,7 +2810,7 @@ bool ChatHandler::HandleLookupQuestCommand(const char* args)
{
Quest * qinfo = iter->second;
- int loc_idx = m_session->GetSessionDbLocaleIndex();
+ int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
if ( loc_idx >= 0 )
{
QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
@@ -2673,20 +2822,28 @@ bool ChatHandler::HandleLookupQuestCommand(const char* args)
if (Utf8FitTo(title, wnamepart))
{
- QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
-
char const* statusStr = "";
- if(status == QUEST_STATUS_COMPLETE)
+
+ if(target)
{
- if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
- statusStr = GetTrinityString(LANG_COMMAND_QUEST_REWARDED);
- else
- statusStr = GetTrinityString(LANG_COMMAND_QUEST_COMPLETE);
+ QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
+
+ if(status == QUEST_STATUS_COMPLETE)
+ {
+ if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
+ statusStr = GetTrinityString(LANG_COMMAND_QUEST_REWARDED);
+ else
+ statusStr = GetTrinityString(LANG_COMMAND_QUEST_COMPLETE);
+ }
+ else if(status == QUEST_STATUS_INCOMPLETE)
+ statusStr = GetTrinityString(LANG_COMMAND_QUEST_ACTIVE);
}
- else if(status == QUEST_STATUS_INCOMPLETE)
- statusStr = GetTrinityString(LANG_COMMAND_QUEST_ACTIVE);
+
+ if (m_session)
+ PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
+ else
+ PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
- PSendSysMessage(LANG_QUEST_LIST,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),(status == QUEST_STATUS_COMPLETE ? GetTrinityString(LANG_COMPLETE) : (status == QUEST_STATUS_INCOMPLETE ? GetTrinityString(LANG_ACTIVE) : "") ));
++counter;
continue;
}
@@ -2700,20 +2857,28 @@ bool ChatHandler::HandleLookupQuestCommand(const char* args)
if (Utf8FitTo(title, wnamepart))
{
- QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
-
char const* statusStr = "";
- if(status == QUEST_STATUS_COMPLETE)
+
+ if(target)
{
- if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
- statusStr = GetTrinityString(LANG_COMMAND_QUEST_REWARDED);
- else
- statusStr = GetTrinityString(LANG_COMMAND_QUEST_COMPLETE);
+ QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
+
+ if(status == QUEST_STATUS_COMPLETE)
+ {
+ if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
+ statusStr = GetTrinityString(LANG_COMMAND_QUEST_REWARDED);
+ else
+ statusStr = GetTrinityString(LANG_COMMAND_QUEST_COMPLETE);
+ }
+ else if(status == QUEST_STATUS_INCOMPLETE)
+ statusStr = GetTrinityString(LANG_COMMAND_QUEST_ACTIVE);
}
- else if(status == QUEST_STATUS_INCOMPLETE)
- statusStr = GetTrinityString(LANG_COMMAND_QUEST_ACTIVE);
+
+ if (m_session)
+ PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
+ else
+ PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
- PSendSysMessage(LANG_QUEST_LIST,qinfo->GetQuestId(),qinfo->GetQuestId(), title.c_str(),(status == QUEST_STATUS_COMPLETE ? GetTrinityString(LANG_COMPLETE) : (status == QUEST_STATUS_INCOMPLETE ? GetTrinityString(LANG_ACTIVE) : "") ));
++counter;
}
}
@@ -2726,39 +2891,43 @@ bool ChatHandler::HandleLookupQuestCommand(const char* args)
bool ChatHandler::HandleLookupCreatureCommand(const char* args)
{
- if(!*args)
+ if (!*args)
return false;
std::string namepart = args;
std::wstring wnamepart;
// converting string that we try to find to lower case
- if(!Utf8toWStr(namepart,wnamepart))
+ if (!Utf8toWStr (namepart,wnamepart))
return false;
- wstrToLower(wnamepart);
+ wstrToLower (wnamepart);
uint32 counter = 0;
- for (uint32 id = 0; id< sCreatureStorage.MaxEntry; id++ )
+ for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
{
- CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(id);
+ CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
if(!cInfo)
continue;
- int loc_idx = m_session->GetSessionDbLocaleIndex();
- if ( loc_idx >= 0 )
+ int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
+ if (loc_idx >= 0)
{
- CreatureLocale const *cl = objmgr.GetCreatureLocale(id);
+ CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
if (cl)
{
- if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty())
+ if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
{
std::string name = cl->Name[loc_idx];
- if (Utf8FitTo(name, wnamepart))
+ if (Utf8FitTo (name, wnamepart))
{
- PSendSysMessage(LANG_CREATURE_ENTRY_LIST, id, id, name.c_str());
+ if (m_session)
+ PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
+ else
+ PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
+
++counter;
continue;
}
@@ -2767,18 +2936,21 @@ bool ChatHandler::HandleLookupCreatureCommand(const char* args)
}
std::string name = cInfo->Name;
- if(name.empty())
+ if (name.empty ())
continue;
if (Utf8FitTo(name, wnamepart))
{
- PSendSysMessage(LANG_CREATURE_ENTRY_LIST,id,id,name.c_str());
+ if (m_session)
+ PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
+ else
+ PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
++counter;
}
}
if (counter==0)
- SendSysMessage(LANG_COMMAND_NOCREATUREFOUND);
+ SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
return true;
}
@@ -2805,7 +2977,7 @@ bool ChatHandler::HandleLookupObjectCommand(const char* args)
if(!gInfo)
continue;
- int loc_idx = m_session->GetSessionDbLocaleIndex();
+ int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
if ( loc_idx >= 0 )
{
GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
@@ -2817,7 +2989,10 @@ bool ChatHandler::HandleLookupObjectCommand(const char* args)
if (Utf8FitTo(name, wnamepart))
{
- PSendSysMessage(LANG_GO_ENTRY_LIST, id, id, name.c_str());
+ if (m_session)
+ PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
+ else
+ PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
++counter;
continue;
}
@@ -2831,7 +3006,10 @@ bool ChatHandler::HandleLookupObjectCommand(const char* args)
if(Utf8FitTo(name, wnamepart))
{
- PSendSysMessage(LANG_GO_ENTRY_LIST, id, id, name.c_str());
+ if (m_session)
+ PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
+ else
+ PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
++counter;
}
}
@@ -2856,86 +3034,82 @@ bool ChatHandler::HandleGuildCreateCommand(const char* args)
if (!*args)
return false;
- Guild *guild;
- Player * player;
- char *lname,*gname;
- std::string guildname;
-
- lname = strtok((char*)args, " ");
- gname = strtok(NULL, "");
+ char *lname = strtok ((char*)args, " ");
+ char *gname = strtok (NULL, "");
- if(!lname)
+ if (!lname)
return false;
- else if(!gname)
+
+ if (!gname)
{
- SendSysMessage(LANG_INSERT_GUILD_NAME);
- SetSentErrorMessage(true);
+ SendSysMessage (LANG_INSERT_GUILD_NAME);
+ SetSentErrorMessage (true);
return false;
}
- guildname = gname;
- player = ObjectAccessor::Instance().FindPlayerByName(lname);
+ std::string guildname = gname;
- if(!player)
+ Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
+ if (!player)
{
- SendSysMessage(LANG_PLAYER_NOT_FOUND);
- SetSentErrorMessage(true);
+ SendSysMessage (LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage (true);
return false;
}
- if(!player->GetGuildId())
+ if (player->GetGuildId())
{
- guild = new Guild;
- if(!guild->create(player->GetGUID(),guildname))
- {
- delete guild;
- SendSysMessage(LANG_GUILD_NOT_CREATED);
- SetSentErrorMessage(true);
- return false;
- }
+ SendSysMessage (LANG_PLAYER_IN_GUILD);
+ return true;
+ }
- objmgr.AddGuild(guild);
+ Guild *guild = new Guild;
+ if (!guild->create (player->GetGUID (),guildname))
+ {
+ delete guild;
+ SendSysMessage (LANG_GUILD_NOT_CREATED);
+ SetSentErrorMessage (true);
+ return false;
}
- else
- SendSysMessage(LANG_PLAYER_IN_GUILD);
-
+
+ objmgr.AddGuild (guild);
return true;
}
bool ChatHandler::HandleGuildInviteCommand(const char *args)
{
- if(!*args)
+ if (!*args)
return false;
- char* par1 = strtok((char*)args, " ");
+ char* par1 = strtok ((char*)args, " ");
char* par2 = strtok (NULL, "");
if(!par1 || !par2)
return false;
std::string glName = par2;
- Guild* targetGuild = objmgr.GetGuildByName(glName);
- if(!targetGuild)
+ Guild* targetGuild = objmgr.GetGuildByName (glName);
+ if (!targetGuild)
return false;
std::string plName = par1;
- if(!normalizePlayerName(plName))
+ if (!normalizePlayerName (plName))
{
- SendSysMessage(LANG_PLAYER_NOT_FOUND);
- SetSentErrorMessage(true);
+ SendSysMessage (LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage (true);
return false;
}
uint64 plGuid = 0;
- if(Player* targetPlayer = ObjectAccessor::Instance().FindPlayerByName(plName.c_str()))
- plGuid = targetPlayer->GetGUID();
+ if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
+ plGuid = targetPlayer->GetGUID ();
else
- plGuid = objmgr.GetPlayerGUIDByName(plName.c_str());
+ plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
- if(!plGuid)
+ if (!plGuid)
false;
// players's guild membership checked in AddMember before add
- if(!targetGuild->AddMember(plGuid,targetGuild->GetLowestRank()))
+ if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
return false;
return true;
@@ -2943,107 +3117,109 @@ bool ChatHandler::HandleGuildInviteCommand(const char *args)
bool ChatHandler::HandleGuildUninviteCommand(const char *args)
{
- if(!*args)
+ if (!*args)
return false;
- char* par1 = strtok((char*)args, " ");
+ char* par1 = strtok ((char*)args, " ");
if(!par1)
return false;
+
std::string plName = par1;
- if(!normalizePlayerName(plName))
+ if (!normalizePlayerName (plName))
{
- SendSysMessage(LANG_PLAYER_NOT_FOUND);
- SetSentErrorMessage(true);
+ SendSysMessage (LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage (true);
return false;
}
uint64 plGuid = 0;
uint32 glId = 0;
- if(Player* targetPlayer = ObjectAccessor::Instance().FindPlayerByName(plName.c_str()))
+ if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
{
- plGuid = targetPlayer->GetGUID();
- glId = targetPlayer->GetGuildId();
+ plGuid = targetPlayer->GetGUID ();
+ glId = targetPlayer->GetGuildId ();
}
else
{
- plGuid = objmgr.GetPlayerGUIDByName(plName.c_str());
- glId = Player::GetGuildIdFromDB(plGuid);
+ plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
+ glId = Player::GetGuildIdFromDB (plGuid);
}
- if(!plGuid || !glId)
+ if (!plGuid || !glId)
return false;
- Guild* targetGuild = objmgr.GetGuildById(glId);
- if(!targetGuild)
+ Guild* targetGuild = objmgr.GetGuildById (glId);
+ if (!targetGuild)
return false;
- targetGuild->DelMember(plGuid);
+ targetGuild->DelMember (plGuid);
return true;
}
bool ChatHandler::HandleGuildRankCommand(const char *args)
{
- if(!*args)
+ if (!*args)
return false;
- char* par1 = strtok((char*)args, " ");
- char* par2 = strtok(NULL, " ");
- if(!par1 || !par2)
+ char* par1 = strtok ((char*)args, " ");
+ char* par2 = strtok (NULL, " ");
+ if (!par1 || !par2)
return false;
+
std::string plName = par1;
- if(!normalizePlayerName(plName))
+ if (!normalizePlayerName (plName))
{
- SendSysMessage(LANG_PLAYER_NOT_FOUND);
- SetSentErrorMessage(true);
+ SendSysMessage (LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage (true);
return false;
}
uint64 plGuid = 0;
uint32 glId = 0;
- if(Player* targetPlayer = ObjectAccessor::Instance().FindPlayerByName(plName.c_str()))
+ if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
{
- plGuid = targetPlayer->GetGUID();
- glId = targetPlayer->GetGuildId();
+ plGuid = targetPlayer->GetGUID ();
+ glId = targetPlayer->GetGuildId ();
}
else
{
- plGuid = objmgr.GetPlayerGUIDByName(plName.c_str());
- glId = Player::GetGuildIdFromDB(plGuid);
+ plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
+ glId = Player::GetGuildIdFromDB (plGuid);
}
- if(!plGuid || !glId)
+ if (!plGuid || !glId)
return false;
- Guild* targetGuild = objmgr.GetGuildById(glId);
- if(!targetGuild)
+ Guild* targetGuild = objmgr.GetGuildById (glId);
+ if (!targetGuild)
return false;
- uint32 newrank = uint32(atoi(par2));
- if(newrank > targetGuild->GetLowestRank())
+ uint32 newrank = uint32 (atoi (par2));
+ if (newrank > targetGuild->GetLowestRank ())
return false;
- targetGuild->ChangeRank(plGuid,newrank);
+ targetGuild->ChangeRank (plGuid,newrank);
return true;
}
bool ChatHandler::HandleGuildDeleteCommand(const char* args)
{
- if(!*args)
+ if (!*args)
return false;
- char* par1 = strtok((char*)args, " ");
- if(!par1)
+ char* par1 = strtok ((char*)args, " ");
+ if (!par1)
return false;
std::string gld = par1;
- Guild* targetGuild = objmgr.GetGuildByName(gld);
- if(!targetGuild)
+ Guild* targetGuild = objmgr.GetGuildByName (gld);
+ if (!targetGuild)
return false;
- targetGuild->Disband();
+ targetGuild->Disband ();
return true;
}
@@ -3471,11 +3647,6 @@ bool ChatHandler::HandleNearGraveCommand(const char* args)
return true;
}
-bool ChatHandler::HandleSpawnTransportCommand(const char* /*args*/)
-{
- return true;
-}
-
//play npc emote
bool ChatHandler::HandlePlayEmoteCommand(const char* args)
{
@@ -4720,238 +4891,470 @@ bool ChatHandler::HandleCompleteQuest(const char* args)
return true;
}
-bool ChatHandler::HandleBanCommand(const char* args)
+bool ChatHandler::HandleBanAccountCommand(const char* args)
{
- if(!args)
- return false;
+ return HandleBanHelper(BAN_ACCOUNT,args);
+}
- char* type = strtok((char*)args, " ");
+bool ChatHandler::HandleBanCharacterCommand(const char* args)
+{
+ return HandleBanHelper(BAN_CHARACTER,args);
+}
- if(!type)
+bool ChatHandler::HandleBanIPCommand(const char* args)
+{
+ return HandleBanHelper(BAN_IP,args);
+}
+
+bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
+{
+ if(!args)
return false;
- char* nameOrIP = strtok(NULL, " ");
- if(!nameOrIP)
+ char* cnameOrIP = strtok ((char*)args, " ");
+ if (!cnameOrIP)
return false;
- char* duration = strtok(NULL," ");
+ std::string nameOrIP = cnameOrIP;
+
+ char* duration = strtok (NULL," ");
if(!duration || !atoi(duration))
return false;
- char* reason = strtok(NULL,"");
+ char* reason = strtok (NULL,"");
if(!reason)
return false;
- switch(sWorld.BanAccount(type, nameOrIP, duration, reason,m_session->GetPlayerName()))
+ switch(mode)
+ {
+ case BAN_ACCOUNT:
+ if(!AccountMgr::normilizeString(nameOrIP))
+ {
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
+ SetSentErrorMessage(true);
+ return false;
+ }
+ break;
+ case BAN_CHARACTER:
+ if(!normalizePlayerName(nameOrIP))
+ {
+ SendSysMessage(LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage(true);
+ return false;
+ }
+ break;
+ case BAN_IP:
+ if(!IsIPAddress(nameOrIP.c_str()))
+ return false;
+ break;
+ }
+
+ switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
{
case BAN_SUCCESS:
if(atoi(duration)>0)
- PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP,secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
+ PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
else
- PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP,reason);
+ PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
break;
case BAN_SYNTAX_ERROR:
return false;
case BAN_NOTFOUND:
- PSendSysMessage(LANG_BAN_NOTFOUND,type,nameOrIP);
- break;
+ switch(mode)
+ {
+ default:
+ PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
+ break;
+ case BAN_CHARACTER:
+ PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
+ break;
+ case BAN_IP:
+ PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
+ break;
+
+ }
+ SetSentErrorMessage(true);
+ return false;
}
return true;
}
-bool ChatHandler::HandleUnBanCommand(const char* args)
+bool ChatHandler::HandleUnBanAccountCommand(const char* args)
{
- if(!args)
- return false;
- char* type = strtok((char*)args, " ");
- if(!type)
- return false;
- char* nameOrIP = strtok(NULL, " ");
-
- if(!nameOrIP)
- return false;
+ return HandleUnBanHelper(BAN_ACCOUNT,args);
+}
- if(sWorld.RemoveBanAccount(type,nameOrIP))
- PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP);
- else
- PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP);
+bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
+{
+ return HandleUnBanHelper(BAN_CHARACTER,args);
+}
- return true;
+bool ChatHandler::HandleUnBanIPCommand(const char* args)
+{
+ return HandleUnBanHelper(BAN_IP,args);
}
-bool ChatHandler::HandleBanInfoCommand(const char* args)
+bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
{
if(!args)
return false;
- char* cType = strtok((char*)args, " ");
- char* cnameOrIP = strtok(NULL, "");
- if(!cType || !cnameOrIP)
+ char* cnameOrIP = strtok ((char*)args, " ");
+ if(!cnameOrIP)
return false;
std::string nameOrIP = cnameOrIP;
- std::string type = cType;
- if (!IsIPAddress(cnameOrIP) && type=="ip")
- return false;
-
- Field *fields;
- if(type != "ip")
+ switch(mode)
{
- //look the accountid up
- uint32 accountid;
- std::string accountname;
- if(type == "account")
- {
- loginDatabase.escape_string(nameOrIP);
- QueryResult *result = loginDatabase.PQuery("SELECT id, username FROM account WHERE username = '%s'",nameOrIP.c_str());
- if (!result)
+ case BAN_ACCOUNT:
+ if(!AccountMgr::normilizeString(nameOrIP))
{
- PSendSysMessage(LANG_BANINFO_NOACCOUNT);
- return true;
- }
- fields = result->Fetch();
- accountid = fields[0].GetUInt32();
- accountname = fields[1].GetCppString();
- delete result;
- }
- else if(type == "character")
- {
- if(!normalizePlayerName(nameOrIP))
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
+ SetSentErrorMessage(true);
+ return false;
+ }
+ break;
+ case BAN_CHARACTER:
+ if(!normalizePlayerName(nameOrIP))
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
+ break;
+ case BAN_IP:
+ if(!IsIPAddress(nameOrIP.c_str()))
+ return false;
+ break;
+ }
- accountid = objmgr.GetPlayerAccountIdByPlayerName (nameOrIP);
- if (!accountid)
- {
- PSendSysMessage(LANG_BANINFO_NOCHARACTER);
- return true;
- }
-
- if (!accmgr.GetName (accountid,accountname))
- {
- PSendSysMessage(LANG_BANINFO_NOCHARACTER);
- return true;
- }
- }
- else
- return false;
+ if(sWorld.RemoveBanAccount(mode,nameOrIP))
+ PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
+ else
+ PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
- QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
- if(!result)
- {
- PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname.c_str());
- return true;
- }
+ return true;
+}
- PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname.c_str());
- do
- {
- fields = result->Fetch();
-
- time_t unbandate = time_t(fields[3].GetUInt64());
- bool active = false;
- if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
- active = true;
- bool permanent = (fields[1].GetUInt64() == (uint64)0);
- std::string bantime = permanent?GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
- PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
- fields[0].GetString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES):GetTrinityString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
- }while (result->NextRow());
+bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
+{
+ if(!args)
+ return false;
- delete result;
+ char* cname = strtok((char*)args, "");
+ if(!cname)
+ return false;
+
+ std::string account_name = cname;
+ if(!AccountMgr::normilizeString(account_name))
+ {
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
+ SetSentErrorMessage(true);
+ return false;
}
- else
+
+ uint32 accountid = accmgr.GetId(account_name);
+ if(!accountid)
{
- loginDatabase.escape_string(nameOrIP);
- QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",nameOrIP.c_str());
- if(!result)
- {
- PSendSysMessage(LANG_BANINFO_NOIP);
- return true;
- }
- fields = result->Fetch();
- bool permanent = (fields[6].GetUInt64()==(uint64)0);
- PSendSysMessage(LANG_BANINFO_IPENTRY,
- fields[0].GetString(), fields[1].GetString(), permanent ? GetTrinityString(LANG_BANINFO_NEVER):fields[2].GetString(),
- permanent ? GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
- delete result;
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
+ return true;
}
- return true;
+
+ return HandleBanInfoHelper(accountid,account_name.c_str());
}
-bool ChatHandler::HandleBanListCommand(const char* args)
+bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
{
- loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
- if(!*args)
+ if(!args)
return false;
- char* cType = strtok((char*)args, " ");
- char* cFilter = strtok(NULL, "");
- if(!cType || !cFilter)
+
+ char* cname = strtok ((char*)args, "");
+ if(!cname)
return false;
- std::string Filter = cFilter;
- std::string Type = cType;
- loginDatabase.escape_string(Filter);
- QueryResult* result = NULL;
- Field *fields = NULL;
- if(Type == "ip")
- {
- result = loginDatabase.PQuery("SELECT ip FROM ip_banned WHERE ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),Filter.c_str());
- if(!result)
- {
- PSendSysMessage(LANG_BANLIST_NOIP);
- return true;
- }
- PSendSysMessage(LANG_BANLIST_MATCHINGIP);
- do
- {
- fields = result->Fetch();
- PSendSysMessage("%s",fields[0].GetString());
- } while (result->NextRow());
+ std::string name = cname;
+ if(!normalizePlayerName(name))
+ {
+ SendSysMessage(LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage(true);
+ return false;
+ }
- delete result;
+ uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
+ if(!accountid)
+ {
+ SendSysMessage(LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ std::string accountname;
+ if(!accmgr.GetName(accountid,accountname))
+ {
+ PSendSysMessage(LANG_BANINFO_NOCHARACTER);
return true;
}
- //lookup accountid
- if(Type == "account")
+
+ return HandleBanInfoHelper(accountid,accountname.c_str());
+}
+
+bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
+{
+ QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
+ if(!result)
{
- result = loginDatabase.PQuery("SELECT id FROM account WHERE username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),Filter.c_str());
- if (!result)
- {
- PSendSysMessage(LANG_BANLIST_NOACCOUNT);
- return true;
- }
- //do not delete result
+ PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
+ return true;
}
- else if(Type == "characters")
+
+ PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
+ do
{
- result = CharacterDatabase.PQuery("SELECT account FROM characters, WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),Filter.c_str());
- if (!result)
- {
- PSendSysMessage(LANG_BANLIST_NOCHARACTER);
- return true;
- }
+ Field* fields = result->Fetch();
+
+ time_t unbandate = time_t(fields[3].GetUInt64());
+ bool active = false;
+ if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
+ active = true;
+ bool permanent = (fields[1].GetUInt64() == (uint64)0);
+ std::string bantime = permanent?GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
+ PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
+ fields[0].GetString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES):GetTrinityString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
+ }while (result->NextRow());
+
+ delete result;
+ return true;
+}
+
+bool ChatHandler::HandleBanInfoIPCommand(const char* args)
+{
+ if(!args)
+ return false;
+
+ char* cIP = strtok ((char*)args, "");
+ if(!cIP)
+ return false;
+
+ if (!IsIPAddress(cIP))
+ return false;
+
+ std::string IP = cIP;
+
+ loginDatabase.escape_string(IP);
+ QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
+ if(!result)
+ {
+ PSendSysMessage(LANG_BANINFO_NOIP);
+ return true;
}
- else
+
+ Field *fields = result->Fetch();
+ bool permanent = !fields[6].GetUInt64();
+ PSendSysMessage(LANG_BANINFO_IPENTRY,
+ fields[0].GetString(), fields[1].GetString(), permanent ? GetTrinityString(LANG_BANINFO_NEVER):fields[2].GetString(),
+ permanent ? GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
+ delete result;
+ return true;
+}
+
+bool ChatHandler::HandleBanListCharacterCommand(const char* args)
+{
+ loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
+
+ char* cFilter = strtok ((char*)args, " ");
+ if(!cFilter)
return false;
+ std::string filter = cFilter;
+ loginDatabase.escape_string(filter);
+ QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
+ if (!result)
+ {
+ PSendSysMessage(LANG_BANLIST_NOCHARACTER);
+ return true;
+ }
+
+ return HandleBanListHelper(result);
+}
+
+bool ChatHandler::HandleBanListAccountCommand(const char* args)
+{
+ loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
+
+ char* cFilter = strtok((char*)args, " ");
+ std::string filter = cFilter ? cFilter : "";
+ loginDatabase.escape_string(filter);
+
+ QueryResult* result;
+
+ if(filter.empty())
+ {
+ result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
+ " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
+ }
+ else
+ {
+ result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
+ " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
+ filter.c_str());
+ }
+
+ if (!result)
+ {
+ PSendSysMessage(LANG_BANLIST_NOACCOUNT);
+ return true;
+ }
+
+ return HandleBanListHelper(result);
+}
+
+bool ChatHandler::HandleBanListHelper(QueryResult* result)
+{
PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
- do
+
+ // Chat short output
+ if(m_session)
{
- fields = result->Fetch();
- uint32 accountid = fields[0].GetUInt32();
- QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.active = '1' AND account_banned.id=account.id",accountid);
- if(banresult)
+ do
+ {
+ Field* fields = result->Fetch();
+ uint32 accountid = fields[0].GetUInt32();
+
+ QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
+ if(banresult)
+ {
+ Field* fields2 = banresult->Fetch();
+ PSendSysMessage("%s",fields2[0].GetString());
+ delete banresult;
+ }
+ } while (result->NextRow());
+ }
+ // Console wide output
+ else
+ {
+ SendSysMessage(LANG_BANLIST_ACCOUNTS);
+ SendSysMessage("===============================================================================");
+ SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
+ do
+ {
+ SendSysMessage("-------------------------------------------------------------------------------");
+ Field *fields = result->Fetch();
+ uint32 account_id = fields[0].GetUInt32 ();
+
+ std::string account_name;
+
+ // "account" case, name can be get in same quary
+ if(result->GetFieldCount() > 1)
+ account_name = fields[1].GetCppString();
+ // "character" case, name need extract from another DB
+ else
+ accmgr.GetName (account_id,account_name);
+
+ // No SQL injection. id is uint32.
+ QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
+ if (banInfo)
+ {
+ Field *fields2 = banInfo->Fetch();
+ do
+ {
+ time_t t_ban = fields2[0].GetUInt64();
+ tm* aTm_ban = localtime(&t_ban);
+
+ if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
+ {
+ PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
+ account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
+ fields2[2].GetString(),fields2[3].GetString());
+ }
+ else
+ {
+ time_t t_unban = fields2[1].GetUInt64();
+ tm* aTm_unban = localtime(&t_unban);
+ PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
+ account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
+ aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
+ fields2[2].GetString(),fields2[3].GetString());
+ }
+ }while ( banInfo->NextRow() );
+ delete banInfo;
+ }
+ }while( result->NextRow() );
+ SendSysMessage("===============================================================================");
+ }
+
+ delete result;
+ return true;
+}
+
+bool ChatHandler::HandleBanListIPCommand(const char* args)
+{
+ loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
+
+ char* cFilter = strtok((char*)args, " ");
+ std::string filter = cFilter ? cFilter : "";
+ loginDatabase.escape_string(filter);
+
+ QueryResult* result;
+
+ if(filter.empty())
+ {
+ result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
+ " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
+ " ORDER BY unbandate" );
+ }
+ else
+ {
+ result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
+ " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
+ " ORDER BY unbandate",filter.c_str() );
+ }
+
+ if(!result)
+ {
+ PSendSysMessage(LANG_BANLIST_NOIP);
+ return true;
+ }
+
+ PSendSysMessage(LANG_BANLIST_MATCHINGIP);
+ // Chat short output
+ if(m_session)
+ {
+ do
+ {
+ Field* fields = result->Fetch();
+ PSendSysMessage("%s",fields[0].GetString());
+ }while (result->NextRow());
+ }
+ // Console wide output
+ else
+ {
+ SendSysMessage(LANG_BANLIST_IPS);SendSysMessage("===============================================================================");
+ SendSysMessage(LANG_BANLIST_IPS_HEADER);
+ do
{
- Field* fields2 = banresult->Fetch();
- PSendSysMessage("%s",fields2[0].GetString());
- delete banresult;
- }
- } while (result->NextRow());
+ SendSysMessage("-------------------------------------------------------------------------------");
+ Field *fields = result->Fetch();
+ time_t t_ban = fields[1].GetUInt64();
+ tm* aTm_ban = localtime(&t_ban);
+ if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
+ {
+ PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
+ fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
+ fields[3].GetString(), fields[4].GetString());
+ }
+ else
+ {
+ time_t t_unban = fields[2].GetUInt64();
+ tm* aTm_unban = localtime(&t_unban);
+ PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
+ fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
+ aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
+ fields[3].GetString(), fields[4].GetString());
+ }
+ }while( result->NextRow() );
+ SendSysMessage("===============================================================================");
+ }
delete result;
return true;
@@ -5012,37 +5415,111 @@ bool ChatHandler::HandleFlyModeCommand(const char* args)
bool ChatHandler::HandleLoadPDumpCommand(const char *args)
{
- if(!args)
+ if (!args)
return false;
- char * file = strtok((char*)args, " "); if(!file) return false;
- char * acc = strtok(NULL, " "); if(!acc) return false;
- if(!file || !acc)
+ char * file = strtok((char*)args, " ");
+ if(!file)
+ return false;
+
+ char * account = strtok(NULL, " ");
+ if(!account)
+ return false;
+
+ std::string account_name = account;
+ if(!AccountMgr::normilizeString(account_name))
+ {
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
+ SetSentErrorMessage(true);
return false;
+ }
- uint32 account_id = accmgr.GetId(acc);
+ uint32 account_id = accmgr.GetId(account_name);
if(!account_id)
{
- account_id = atoi(acc);
- if(account_id)
+ account_id = atoi(account); // use original string
+ if(!account_id)
{
- std::string acc_name;
- if(!accmgr.GetName(account_id,acc_name))
- return false;
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
+ SetSentErrorMessage(true);
+ return false;
}
- else
+ }
+
+ if(!accmgr.GetName(account_id,account_name))
+ {
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ char* guid_str = NULL;
+ char* name_str = strtok(NULL, " ");
+
+ std::string name;
+ if(name_str)
+ {
+ name = name_str;
+ // normalize the name if specified and check if it exists
+ if(!normalizePlayerName(name))
+ {
+ PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ if(!ObjectMgr::IsValidName(name,true))
+ {
+ PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
+ SetSentErrorMessage(true);
return false;
- }
-
- char * name = strtok(NULL, " ");
- char * guid_str = name ? strtok(NULL, " ") : NULL;
-
- uint32 guid = guid_str ? atoi(guid_str) : 0;
-
- if(PlayerDumpReader().LoadDump(file, account_id, name ? name : "", guid))
- PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
- else
- PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
+ }
+
+ guid_str = strtok(NULL, " ");
+ }
+
+ uint32 guid = 0;
+
+ if(guid_str)
+ {
+ guid = atoi(guid_str);
+ if(!guid)
+ {
+ PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ if(objmgr.GetPlayerAccountIdByGUID(guid))
+ {
+ PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
+ SetSentErrorMessage(true);
+ return false;
+ }
+ }
+
+ switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
+ {
+ case DUMP_SUCCESS:
+ PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
+ break;
+ case DUMP_FILE_OPEN_ERROR:
+ PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
+ SetSentErrorMessage(true);
+ return false;
+ case DUMP_FILE_BROKEN:
+ PSendSysMessage(LANG_DUMP_BROKEN,file);
+ SetSentErrorMessage(true);
+ return false;
+ case DUMP_TOO_MANY_CHARS:
+ PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name,account_id);
+ SetSentErrorMessage(true);
+ return false;
+ default:
+ PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
+ SetSentErrorMessage(true);
+ return false;
+ }
return true;
}
@@ -5086,10 +5563,27 @@ bool ChatHandler::HandleWritePDumpCommand(const char *args)
if(!guid)
guid = atoi(p2);
- if (PlayerDumpWriter().WriteDump(file, guid))
- PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
- else
- PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
+ if(!objmgr.GetPlayerAccountIdByGUID(guid))
+ {
+ PSendSysMessage(LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ switch(PlayerDumpWriter().WriteDump(file, guid))
+ {
+ case DUMP_SUCCESS:
+ PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
+ break;
+ case DUMP_FILE_OPEN_ERROR:
+ PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
+ SetSentErrorMessage(true);
+ return false;
+ default:
+ PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
+ SetSentErrorMessage(true);
+ return false;
+ }
return true;
}
@@ -5573,6 +6067,135 @@ bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
return true;
}
+/// Display the list of GMs
+bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
+{
+ ///- Get the accounts with GM Level >0
+ QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
+ if(result)
+ {
+ SendSysMessage(LANG_GMLIST);
+ SendSysMessage("========================");
+ SendSysMessage(LANG_GMLIST_HEADER);
+ SendSysMessage("========================");
+
+ ///- Circle through them. Display username and GM level
+ do
+ {
+ Field *fields = result->Fetch();
+ PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
+ } while( result->NextRow() );
+
+ PSendSysMessage("========================");
+ delete result;
+ }
+ else
+ PSendSysMessage(LANG_GMLIST_EMPTY);
+ return true;
+}
+
+/// Define the 'Message of the day' for the realm
+bool ChatHandler::HandleServerSetMotdCommand(const char* args)
+{
+ sWorld.SetMotd(args);
+ PSendSysMessage(LANG_MOTD_NEW, args);
+ return true;
+}
+
+/// Set/Unset the expansion level for an account
+bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
+{
+ ///- Get the command line arguments
+ char *szAcc = strtok((char*)args," ");
+ char *szExp = strtok(NULL," ");
+
+ if(!szAcc)
+ return false;
+
+ std::string account_name;
+ uint32 account_id;
+
+ if(!szExp)
+ {
+ Player* player = getSelectedPlayer();
+ if(!player)
+ return false;
+
+ account_id = player->GetSession()->GetAccountId();
+ accmgr.GetName(account_id,account_name);
+ szExp = szAcc;
+ }
+ else
+ {
+ ///- Convert Account name to Upper Format
+ account_name = szAcc;
+ if(!AccountMgr::normilizeString(account_name))
+ {
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ account_id = accmgr.GetId(account_name);
+ if(!account_id)
+ {
+ PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
+ SetSentErrorMessage(true);
+ return false;
+ }
+ }
+
+ int lev=atoi(szExp); //get int anyway (0 if error)
+ if(lev < 0)
+ return false;
+
+ // No SQL injection
+ loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
+ PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
+ return true;
+}
+
+/// Send a message to a player in game
+bool ChatHandler::HandleSendMessageCommand(const char* args)
+{
+ ///- Get the command line arguments
+ char* name_str = strtok((char*)args, " ");
+ char* msg_str = strtok(NULL, "");
+
+ if(!name_str || !msg_str)
+ return false;
+
+ std::string name = name_str;
+
+ if(!normalizePlayerName(name))
+ return false;
+
+ ///- Find the player and check that he is not logging out.
+ Player *rPlayer = objmgr.GetPlayer(name.c_str());
+ if(!rPlayer)
+ {
+ SendSysMessage(LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ if(rPlayer->GetSession()->isLogingOut())
+ {
+ SendSysMessage(LANG_PLAYER_NOT_FOUND);
+ SetSentErrorMessage(true);
+ return false;
+ }
+
+ ///- Send the message
+ //Use SendAreaTriggerMessage for fastest delivery.
+ rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
+ rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
+
+ //Confirmation message
+ PSendSysMessage(LANG_SENDMESSAGE,name.c_str(),msg_str);
+ return true;
+}
+
bool ChatHandler::HandleFreezeCommand(const char *args)
{
std::string name;