343 lines
8.7 KiB
C++
Executable File
343 lines
8.7 KiB
C++
Executable File
/*
|
|
* Copyright (C) 2008-2012 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/>.
|
|
*/
|
|
|
|
#include "Common.h"
|
|
#include "DatabaseEnv.h"
|
|
#include "WorldPacket.h"
|
|
#include "WorldSession.h"
|
|
#include "World.h"
|
|
#include "ObjectMgr.h"
|
|
#include "ArenaTeamMgr.h"
|
|
#include "GuildMgr.h"
|
|
#include "AuctionHouseMgr.h"
|
|
#include "AccountMgr.h"
|
|
#include "PlayerDump.h"
|
|
#include "SpellMgr.h"
|
|
#include "Player.h"
|
|
#include "Opcodes.h"
|
|
#include "GameObject.h"
|
|
#include "Chat.h"
|
|
#include "Log.h"
|
|
#include "Guild.h"
|
|
#include "ObjectAccessor.h"
|
|
#include "MapManager.h"
|
|
#include "Language.h"
|
|
#include "GridNotifiersImpl.h"
|
|
#include "CellImpl.h"
|
|
#include "Weather.h"
|
|
#include "PointMovementGenerator.h"
|
|
#include "TargetedMovementGenerator.h"
|
|
#include "SkillDiscovery.h"
|
|
#include "SkillExtraItems.h"
|
|
#include "SystemConfig.h"
|
|
#include "Config.h"
|
|
#include "Util.h"
|
|
#include "ItemEnchantmentMgr.h"
|
|
#include "BattlegroundMgr.h"
|
|
#include "InstanceSaveMgr.h"
|
|
#include "InstanceScript.h"
|
|
#include "CreatureEventAIMgr.h"
|
|
#include "SpellAuraEffects.h"
|
|
#include "DBCEnums.h"
|
|
#include "ConditionMgr.h"
|
|
#include "DisableMgr.h"
|
|
#include "Transport.h"
|
|
#include "WeatherMgr.h"
|
|
#include "ScriptMgr.h"
|
|
#include "CreatureTextMgr.h"
|
|
#include "SmartAI.h"
|
|
#include "Group.h"
|
|
#include "ChannelMgr.h"
|
|
|
|
bool ChatHandler::HandlePDumpLoadCommand(const char *args)
|
|
{
|
|
if (!*args)
|
|
return false;
|
|
|
|
char * file = strtok((char*)args, " ");
|
|
if (!file)
|
|
return false;
|
|
|
|
char * account = strtok(NULL, " ");
|
|
if (!account)
|
|
return false;
|
|
|
|
std::string account_name = account;
|
|
if (!AccountMgr::normalizeString(account_name))
|
|
{
|
|
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, account_name.c_str());
|
|
SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
uint32 account_id = AccountMgr::GetId(account_name);
|
|
if (!account_id)
|
|
{
|
|
account_id = atoi(account); // use original string
|
|
if (!account_id)
|
|
{
|
|
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, account_name.c_str());
|
|
SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (!AccountMgr::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::CheckPlayerName(name, true) != CHAR_NAME_SUCCESS)
|
|
{
|
|
PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
|
|
SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
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 (sObjectMgr->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.c_str(), account_id);
|
|
SetSentErrorMessage(true);
|
|
return false;
|
|
default:
|
|
PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
|
|
SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ChatHandler::HandlePDumpWriteCommand(const char *args)
|
|
{
|
|
if (!*args)
|
|
return false;
|
|
|
|
char* file = strtok((char*)args, " ");
|
|
char* p2 = strtok(NULL, " ");
|
|
|
|
if (!file || !p2)
|
|
return false;
|
|
|
|
uint64 guid;
|
|
// character name can't start from number
|
|
if (isNumeric(p2))
|
|
guid = MAKE_NEW_GUID(atoi(p2), 0, HIGHGUID_PLAYER);
|
|
else
|
|
{
|
|
std::string name = extractPlayerNameFromLink(p2);
|
|
if (name.empty())
|
|
{
|
|
SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
|
SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
guid = sObjectMgr->GetPlayerGUIDByName(name);
|
|
}
|
|
|
|
if (!sObjectMgr->GetPlayerAccountIdByGUID(guid))
|
|
{
|
|
PSendSysMessage(LANG_PLAYER_NOT_FOUND);
|
|
SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
switch (PlayerDumpWriter().WriteDump(file, uint32(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;
|
|
case DUMP_CHARACTER_DELETED:
|
|
PSendSysMessage(LANG_COMMAND_EXPORT_DELETED_CHAR);
|
|
SetSentErrorMessage(true);
|
|
return false;
|
|
default:
|
|
PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
|
|
SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ChatHandler::HandlePlayAllCommand(const char *args)
|
|
{
|
|
if (!*args)
|
|
return false;
|
|
|
|
uint32 soundId = atoi((char*)args);
|
|
|
|
if (!sSoundEntriesStore.LookupEntry(soundId))
|
|
{
|
|
PSendSysMessage(LANG_SOUND_NOT_EXIST, soundId);
|
|
SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
WorldPacket data(SMSG_PLAY_SOUND, 4);
|
|
data << uint32(soundId) << m_session->GetPlayer()->GetGUID();
|
|
sWorld->SendGlobalMessage(&data);
|
|
|
|
PSendSysMessage(LANG_COMMAND_PLAYED_TO_ALL, soundId);
|
|
return true;
|
|
}
|
|
|
|
bool ChatHandler::HandleGroupLeaderCommand(const char *args)
|
|
{
|
|
Player* player = NULL;
|
|
Group* group = NULL;
|
|
uint64 guid = 0;
|
|
char* cname = strtok((char*)args, " ");
|
|
|
|
if (GetPlayerGroupAndGUIDByName(cname, player, group, guid))
|
|
if (group && group->GetLeaderGUID() != guid)
|
|
{
|
|
group->ChangeLeader(guid);
|
|
group->SendUpdate();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ChatHandler::HandleGroupDisbandCommand(const char *args)
|
|
{
|
|
Player* player = NULL;
|
|
Group* group = NULL;
|
|
uint64 guid = 0;
|
|
char* cname = strtok((char*)args, " ");
|
|
|
|
if (GetPlayerGroupAndGUIDByName(cname, player, group, guid))
|
|
if (group)
|
|
group->Disband();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ChatHandler::HandleGroupRemoveCommand(const char *args)
|
|
{
|
|
Player* player = NULL;
|
|
Group* group = NULL;
|
|
uint64 guid = 0;
|
|
char* cname = strtok((char*)args, " ");
|
|
|
|
if (GetPlayerGroupAndGUIDByName(cname, player, group, guid, true))
|
|
if (group)
|
|
group->RemoveMember(guid);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ChatHandler::HandlePossessCommand(const char * /*args*/)
|
|
{
|
|
Unit* unit = getSelectedUnit();
|
|
if (!unit)
|
|
return false;
|
|
|
|
m_session->GetPlayer()->CastSpell(unit, 530, true);
|
|
return true;
|
|
}
|
|
|
|
bool ChatHandler::HandleUnPossessCommand(const char * /*args*/)
|
|
{
|
|
Unit* unit = getSelectedUnit();
|
|
if (!unit)
|
|
unit = m_session->GetPlayer();
|
|
|
|
unit->RemoveCharmAuras();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ChatHandler::HandleBindSightCommand(const char * /*args*/)
|
|
{
|
|
Unit* unit = getSelectedUnit();
|
|
if (!unit)
|
|
return false;
|
|
|
|
m_session->GetPlayer()->CastSpell(unit, 6277, true);
|
|
return true;
|
|
}
|
|
|
|
bool ChatHandler::HandleUnbindSightCommand(const char * /*args*/)
|
|
{
|
|
Player* player = m_session->GetPlayer();
|
|
|
|
if (player->isPossessing())
|
|
return false;
|
|
|
|
player->StopCastingBindSight();
|
|
return true;
|
|
}
|