2010-10-07 12:41:56 +02:00
|
|
|
/*
|
|
|
|
|
* 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/>.
|
2008-10-02 16:23:55 -05:00
|
|
|
*/
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "Common.h"
|
2010-06-08 15:50:23 -06:00
|
|
|
#include "DatabaseEnv.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "World.h"
|
|
|
|
|
#include "Player.h"
|
2010-06-08 15:50:23 -06:00
|
|
|
#include "Opcodes.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "Chat.h"
|
|
|
|
|
#include "ObjectAccessor.h"
|
2010-06-08 15:50:23 -06:00
|
|
|
#include "Language.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "AccountMgr.h"
|
2010-08-16 09:51:37 +02:00
|
|
|
#include "SystemConfig.h"
|
|
|
|
|
#include "revision.h"
|
2010-06-08 15:50:23 -06:00
|
|
|
#include "Util.h"
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
bool ChatHandler::HandleHelpCommand(const char* args)
|
|
|
|
|
{
|
2009-02-09 08:16:34 -05:00
|
|
|
char* cmd = strtok((char*)args, " ");
|
2010-04-07 19:14:10 +02:00
|
|
|
if (!cmd)
|
2009-02-09 08:16:34 -05:00
|
|
|
{
|
|
|
|
|
ShowHelpForCommand(getCommandTable(), "help");
|
|
|
|
|
ShowHelpForCommand(getCommandTable(), "");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-04-07 19:14:10 +02:00
|
|
|
if (!ShowHelpForCommand(getCommandTable(), cmd))
|
2009-02-09 08:16:34 -05:00
|
|
|
SendSysMessage(LANG_NO_HELP_CMD);
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-04-19 09:26:37 +02:00
|
|
|
bool ChatHandler::HandleCommandsCommand(const char* /*args*/)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
ShowHelpForCommand(getCommandTable(), "");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-26 13:32:42 -05:00
|
|
|
bool ChatHandler::HandleAccountCommand(const char* /*args*/)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2009-04-29 00:31:03 -05:00
|
|
|
AccountTypes gmlevel = m_session->GetSecurity();
|
|
|
|
|
PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmlevel));
|
2008-10-02 16:23:55 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
bool ChatHandler::HandleStartCommand(const char* /*args*/)
|
|
|
|
|
{
|
|
|
|
|
Player *chr = m_session->GetPlayer();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-04-07 19:14:10 +02:00
|
|
|
if (chr->isInFlight())
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
SendSysMessage(LANG_YOU_IN_FLIGHT);
|
|
|
|
|
SetSentErrorMessage(true);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-04-07 19:14:10 +02:00
|
|
|
if (chr->isInCombat())
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
SendSysMessage(LANG_YOU_IN_COMBAT);
|
|
|
|
|
SetSentErrorMessage(true);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-17 16:20:24 -07:00
|
|
|
|
2010-04-07 19:14:10 +02:00
|
|
|
if ((chr->isDead()) || (chr->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST)))
|
2009-10-13 14:24:58 +01:00
|
|
|
{
|
|
|
|
|
// if player is dead and stuck, send ghost to graveyard
|
|
|
|
|
chr->RepopAtGraveyard();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
// cast spell Stuck
|
2010-07-19 03:49:15 +02:00
|
|
|
chr->CastSpell(chr, 7355, false);
|
2008-10-02 16:23:55 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-11-02 16:53:46 -06:00
|
|
|
bool ChatHandler::HandleServerInfoCommand(const char* /*args*/)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2009-07-12 00:16:56 +02:00
|
|
|
uint32 PlayersNum = sWorld.GetPlayerCount();
|
|
|
|
|
uint32 MaxPlayersNum = sWorld.GetMaxPlayerCount();
|
2008-10-02 16:23:55 -05:00
|
|
|
uint32 activeClientsNum = sWorld.GetActiveSessionCount();
|
|
|
|
|
uint32 queuedClientsNum = sWorld.GetQueuedSessionCount();
|
|
|
|
|
uint32 maxActiveClientsNum = sWorld.GetMaxActiveSessionCount();
|
|
|
|
|
uint32 maxQueuedClientsNum = sWorld.GetMaxQueuedSessionCount();
|
2009-12-24 10:20:15 +01:00
|
|
|
std::string uptime = secsToTimeString(sWorld.GetUptime());
|
2008-12-30 18:03:26 -06:00
|
|
|
uint32 updateTime = sWorld.GetUpdateTime();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-01-17 09:23:03 -05:00
|
|
|
PSendSysMessage(_FULLVERSION);
|
2009-07-12 00:16:56 +02:00
|
|
|
PSendSysMessage(LANG_CONNECTED_PLAYERS, PlayersNum, MaxPlayersNum);
|
2008-10-02 16:23:55 -05:00
|
|
|
PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum);
|
2009-12-24 10:20:15 +01:00
|
|
|
PSendSysMessage(LANG_UPTIME, uptime.c_str());
|
2008-12-30 18:03:26 -06:00
|
|
|
PSendSysMessage("Update time diff: %u.", updateTime);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
bool ChatHandler::HandleDismountCommand(const char* /*args*/)
|
|
|
|
|
{
|
|
|
|
|
//If player is not mounted, so go out :)
|
2010-04-07 22:59:46 +02:00
|
|
|
if (!m_session->GetPlayer()->IsMounted())
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
SendSysMessage(LANG_CHAR_NON_MOUNTED);
|
|
|
|
|
SetSentErrorMessage(true);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-04-07 22:59:46 +02:00
|
|
|
if (m_session->GetPlayer()->isInFlight())
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
SendSysMessage(LANG_YOU_IN_FLIGHT);
|
|
|
|
|
SetSentErrorMessage(true);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
m_session->GetPlayer()->Unmount();
|
2009-04-06 13:31:14 +02:00
|
|
|
m_session->GetPlayer()->RemoveAurasByType(SPELL_AURA_MOUNTED);
|
2008-10-02 16:23:55 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
bool ChatHandler::HandleSaveCommand(const char* /*args*/)
|
|
|
|
|
{
|
2010-07-19 03:49:15 +02:00
|
|
|
Player *player = m_session->GetPlayer();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-07-19 03:49:15 +02:00
|
|
|
// save GM account without delay and output message
|
2010-04-07 19:14:10 +02:00
|
|
|
if (m_session->GetSecurity() > SEC_PLAYER)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
player->SaveToDB();
|
|
|
|
|
SendSysMessage(LANG_PLAYER_SAVED);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-07-19 03:49:15 +02:00
|
|
|
// save if the player has last been saved over 20 seconds ago
|
2010-08-23 19:56:47 -07:00
|
|
|
uint32 save_interval = sWorld.getIntConfig(CONFIG_INTERVAL_SAVE);
|
2010-08-23 07:51:19 +02:00
|
|
|
if (save_interval == 0 || (save_interval > 20*IN_MILLISECONDS && player->GetSaveTimer() <= save_interval - 20*IN_MILLISECONDS))
|
2008-10-02 16:23:55 -05:00
|
|
|
player->SaveToDB();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-26 13:32:42 -05:00
|
|
|
bool ChatHandler::HandleGMListIngameCommand(const char* /*args*/)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
bool first = true;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-06-25 00:18:01 +02:00
|
|
|
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, *HashMapHolder<Player>::GetLock(), true);
|
|
|
|
|
HashMapHolder<Player>::MapType &m = sObjectAccessor.GetPlayers();
|
2010-03-13 16:17:25 +01:00
|
|
|
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2009-07-20 11:55:44 +08:00
|
|
|
AccountTypes itr_sec = itr->second->GetSession()->GetSecurity();
|
2010-08-23 19:56:47 -07:00
|
|
|
if ((itr->second->isGameMaster() || (itr_sec > SEC_PLAYER && itr_sec <= AccountTypes(sWorld.getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
|
2009-07-20 11:51:20 +08:00
|
|
|
(!m_session || itr->second->IsVisibleGloballyFor(m_session->GetPlayer())))
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2010-04-07 19:14:10 +02:00
|
|
|
if (first)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
SendSysMessage(LANG_GMS_ON_SRV);
|
|
|
|
|
first = false;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-02-02 15:36:52 -06:00
|
|
|
SendSysMessage(GetNameLink(itr->second).c_str());
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-04-07 19:14:10 +02:00
|
|
|
if (first)
|
2008-10-02 16:23:55 -05:00
|
|
|
SendSysMessage(LANG_GMS_NOT_LOGGED);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-04-24 11:45:25 -05:00
|
|
|
bool ChatHandler::HandleAccountPasswordCommand(const char* args)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2010-04-07 19:14:10 +02:00
|
|
|
if (!*args)
|
2010-07-19 03:49:15 +02:00
|
|
|
{
|
|
|
|
|
SendSysMessage(LANG_CMD_SYNTAX);
|
|
|
|
|
SetSentErrorMessage(true);
|
2008-10-02 16:23:55 -05:00
|
|
|
return false;
|
2010-07-19 03:49:15 +02:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-07-19 03:49:15 +02:00
|
|
|
char *old_pass = strtok((char*)args, " ");
|
|
|
|
|
char *new_pass = strtok(NULL, " ");
|
|
|
|
|
char *new_pass_c = strtok(NULL, " ");
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-26 13:32:42 -05:00
|
|
|
if (!old_pass || !new_pass || !new_pass_c)
|
2010-07-19 03:49:15 +02:00
|
|
|
{
|
|
|
|
|
SendSysMessage(LANG_CMD_SYNTAX);
|
|
|
|
|
SetSentErrorMessage(true);
|
2008-10-02 16:23:55 -05:00
|
|
|
return false;
|
2010-07-19 03:49:15 +02:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
std::string password_old = old_pass;
|
|
|
|
|
std::string password_new = new_pass;
|
|
|
|
|
std::string password_new_c = new_pass_c;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-08-08 05:25:45 +02:00
|
|
|
if (!sAccountMgr.CheckPassword(m_session->GetAccountId(), password_old))
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2010-07-19 03:49:15 +02:00
|
|
|
SendSysMessage(LANG_COMMAND_WRONGOLDPASSWORD);
|
|
|
|
|
SetSentErrorMessage(true);
|
2009-02-09 08:16:34 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-07-19 03:49:15 +02:00
|
|
|
if (strcmp(new_pass, new_pass_c) != 0)
|
2009-02-09 08:16:34 -05:00
|
|
|
{
|
2010-07-19 03:49:15 +02:00
|
|
|
SendSysMessage(LANG_NEW_PASSWORDS_NOT_MATCH);
|
|
|
|
|
SetSentErrorMessage(true);
|
2008-10-02 16:23:55 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-08-08 05:25:45 +02:00
|
|
|
AccountOpResult result = sAccountMgr.ChangePassword(m_session->GetAccountId(), password_new);
|
2008-10-02 16:23:55 -05:00
|
|
|
switch(result)
|
|
|
|
|
{
|
|
|
|
|
case AOR_OK:
|
|
|
|
|
SendSysMessage(LANG_COMMAND_PASSWORD);
|
|
|
|
|
break;
|
2009-02-09 08:16:34 -05:00
|
|
|
case AOR_PASS_TOO_LONG:
|
|
|
|
|
SendSysMessage(LANG_PASSWORD_TOO_LONG);
|
|
|
|
|
SetSentErrorMessage(true);
|
|
|
|
|
return false;
|
2008-10-02 16:23:55 -05:00
|
|
|
default:
|
|
|
|
|
SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
|
|
|
|
|
SetSentErrorMessage(true);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-09-27 21:23:06 -07:00
|
|
|
bool ChatHandler::HandleAccountAddonCommand(const char* args)
|
|
|
|
|
{
|
2010-04-07 19:14:10 +02:00
|
|
|
if (!*args)
|
2010-07-19 03:49:15 +02:00
|
|
|
{
|
|
|
|
|
SendSysMessage(LANG_CMD_SYNTAX);
|
|
|
|
|
SetSentErrorMessage(true);
|
2009-09-27 21:23:06 -07:00
|
|
|
return false;
|
2010-07-19 03:49:15 +02:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-07-19 03:49:15 +02:00
|
|
|
char *szExp = strtok((char*)args, " ");
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-09-27 21:23:06 -07:00
|
|
|
uint32 account_id = m_session->GetAccountId();
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-07-19 03:49:15 +02:00
|
|
|
int expansion = atoi(szExp); //get int anyway (0 if error)
|
2010-08-23 19:56:47 -07:00
|
|
|
if (expansion < 0 || uint8(expansion) > sWorld.getIntConfig(CONFIG_EXPANSION))
|
2010-07-19 03:49:15 +02:00
|
|
|
{
|
|
|
|
|
SendSysMessage(LANG_IMPROPER_VALUE);
|
|
|
|
|
SetSentErrorMessage(true);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-09-27 21:23:06 -07:00
|
|
|
// No SQL injection
|
2010-05-08 05:03:32 +02:00
|
|
|
LoginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'", expansion, account_id);
|
2009-10-05 21:47:51 +02:00
|
|
|
PSendSysMessage(LANG_ACCOUNT_ADDON, expansion);
|
2009-09-27 21:23:06 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-04-24 11:45:25 -05:00
|
|
|
bool ChatHandler::HandleAccountLockCommand(const char* args)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
if (!*args)
|
|
|
|
|
{
|
|
|
|
|
SendSysMessage(LANG_USE_BOL);
|
2010-07-19 03:49:15 +02:00
|
|
|
SetSentErrorMessage(true);
|
|
|
|
|
return false;
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
std::string argstr = (char*)args;
|
|
|
|
|
if (argstr == "on")
|
|
|
|
|
{
|
2010-05-08 05:03:32 +02:00
|
|
|
LoginDatabase.PExecute("UPDATE account SET locked = '1' WHERE id = '%d'",m_session->GetAccountId());
|
2008-10-02 16:23:55 -05:00
|
|
|
PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
if (argstr == "off")
|
|
|
|
|
{
|
2010-05-08 05:03:32 +02:00
|
|
|
LoginDatabase.PExecute("UPDATE account SET locked = '0' WHERE id = '%d'",m_session->GetAccountId());
|
2008-10-02 16:23:55 -05:00
|
|
|
PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
SendSysMessage(LANG_USE_BOL);
|
2010-07-19 03:49:15 +02:00
|
|
|
SetSentErrorMessage(true);
|
|
|
|
|
return false;
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-26 13:32:42 -05:00
|
|
|
/// Display the 'Message of the day' for the realm
|
|
|
|
|
bool ChatHandler::HandleServerMotdCommand(const char* /*args*/)
|
|
|
|
|
{
|
2009-02-09 08:16:34 -05:00
|
|
|
PSendSysMessage(LANG_MOTD_CURRENT, sWorld.GetMotd());
|
|
|
|
|
return true;
|
2008-10-26 13:32:42 -05:00
|
|
|
}
|
2009-02-17 20:07:49 -06:00
|
|
|
|