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

343 lines
8.7 KiB
C++
Raw Normal View History

/*
2012-01-01 00:32:13 +01:00
* 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/>.
*/
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
#include "Common.h"
2010-06-08 15:50:23 -06:00
#include "DatabaseEnv.h"
#include "WorldPacket.h"
#include "WorldSession.h"
2009-04-07 00:23:37 +02:00
#include "World.h"
#include "ObjectMgr.h"
#include "ArenaTeamMgr.h"
#include "GuildMgr.h"
2009-04-07 00:23:37 +02:00
#include "AuctionHouseMgr.h"
#include "AccountMgr.h"
#include "PlayerDump.h"
#include "SpellMgr.h"
#include "Player.h"
2010-06-08 15:50:23 -06:00
#include "Opcodes.h"
2009-04-07 00:23:37 +02:00
#include "GameObject.h"
#include "Chat.h"
2010-06-08 15:50:23 -06:00
#include "Log.h"
2009-04-07 00:23:37 +02:00
#include "Guild.h"
#include "ObjectAccessor.h"
#include "MapManager.h"
2010-06-08 15:50:23 -06:00
#include "Language.h"
#include "GridNotifiersImpl.h"
#include "CellImpl.h"
2009-04-07 00:23:37 +02:00
#include "Weather.h"
#include "PointMovementGenerator.h"
#include "TargetedMovementGenerator.h"
#include "SkillDiscovery.h"
#include "SkillExtraItems.h"
#include "SystemConfig.h"
#include "Config.h"
2010-06-08 15:50:23 -06:00
#include "Util.h"
2009-04-07 00:23:37 +02:00
#include "ItemEnchantmentMgr.h"
2010-08-08 04:37:24 +02:00
#include "BattlegroundMgr.h"
2009-04-07 00:23:37 +02:00
#include "InstanceSaveMgr.h"
2010-08-08 22:54:58 +06:00
#include "InstanceScript.h"
#include "CreatureEventAIMgr.h"
2010-01-10 01:23:15 +01:00
#include "SpellAuraEffects.h"
2009-12-17 11:30:18 +01:00
#include "DBCEnums.h"
2010-06-04 23:24:48 +02:00
#include "ConditionMgr.h"
#include "DisableMgr.h"
#include "Transport.h"
#include "WeatherMgr.h"
#include "ScriptMgr.h"
2010-09-26 20:48:25 +02:00
#include "CreatureTextMgr.h"
#include "SmartAI.h"
#include "Group.h"
#include "ChannelMgr.h"
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
bool ChatHandler::HandlePDumpLoadCommand(const char *args)
{
if (!*args)
return false;
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
char * file = strtok((char*)args, " ");
2010-04-07 19:14:10 +02:00
if (!file)
2009-04-07 00:23:37 +02:00
return false;
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
char * account = strtok(NULL, " ");
2010-04-07 19:14:10 +02:00
if (!account)
2009-04-07 00:23:37 +02:00
return false;
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
std::string account_name = account;
2010-04-07 19:14:10 +02:00
if (!AccountMgr::normalizeString(account_name))
2009-04-07 00:23:37 +02:00
{
2011-04-29 20:47:02 +02:00
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, account_name.c_str());
2009-04-07 00:23:37 +02:00
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
uint32 account_id = AccountMgr::GetId(account_name);
2010-04-07 19:14:10 +02:00
if (!account_id)
2009-04-07 00:23:37 +02:00
{
account_id = atoi(account); // use original string
2010-04-07 19:14:10 +02:00
if (!account_id)
2009-04-07 00:23:37 +02:00
{
2011-04-29 20:47:02 +02:00
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, account_name.c_str());
2009-04-07 00:23:37 +02:00
SetSentErrorMessage(true);
return false;
}
}
2009-10-17 15:51:44 -07:00
if (!AccountMgr::GetName(account_id, account_name))
2009-04-07 00:23:37 +02:00
{
2011-04-29 20:47:02 +02:00
PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, account_name.c_str());
2009-04-07 00:23:37 +02:00
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
char* guid_str = NULL;
char* name_str = strtok(NULL, " ");
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
std::string name;
if (name_str)
2009-04-07 00:23:37 +02:00
{
name = name_str;
// normalize the name if specified and check if it exists
if (!normalizePlayerName(name))
2009-04-07 00:23:37 +02:00
{
PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
if (ObjectMgr::CheckPlayerName(name, true) != CHAR_NAME_SUCCESS)
2009-04-07 00:23:37 +02:00
{
PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
guid_str = strtok(NULL, " ");
}
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
uint32 guid = 0;
2009-10-17 15:51:44 -07:00
if (guid_str)
2009-04-07 00:23:37 +02:00
{
guid = atoi(guid_str);
if (!guid)
2009-04-07 00:23:37 +02:00
{
PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
if (sObjectMgr->GetPlayerAccountIdByGUID(guid))
2009-04-07 00:23:37 +02:00
{
2011-04-29 20:47:02 +02:00
PSendSysMessage(LANG_CHARACTER_GUID_IN_USE, guid);
2009-04-07 00:23:37 +02:00
SetSentErrorMessage(true);
return false;
}
}
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
switch (PlayerDumpReader().LoadDump(file, account_id, name, guid))
2009-04-07 00:23:37 +02:00
{
case DUMP_SUCCESS:
PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
break;
case DUMP_FILE_OPEN_ERROR:
2011-04-29 20:47:02 +02:00
PSendSysMessage(LANG_FILE_OPEN_FAIL, file);
2009-04-07 00:23:37 +02:00
SetSentErrorMessage(true);
return false;
case DUMP_FILE_BROKEN:
2011-04-29 20:47:02 +02:00
PSendSysMessage(LANG_DUMP_BROKEN, file);
2009-04-07 00:23:37 +02:00
SetSentErrorMessage(true);
return false;
case DUMP_TOO_MANY_CHARS:
2011-04-29 20:47:02 +02:00
PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL, account_name.c_str(), account_id);
2009-04-07 00:23:37 +02:00
SetSentErrorMessage(true);
return false;
default:
PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
return true;
}
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
bool ChatHandler::HandlePDumpWriteCommand(const char *args)
{
if (!*args)
return false;
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
char* file = strtok((char*)args, " ");
char* p2 = strtok(NULL, " ");
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!file || !p2)
2009-04-07 00:23:37 +02:00
return false;
2009-10-17 15:51:44 -07:00
2010-08-30 23:07:14 +02:00
uint64 guid;
2009-04-07 00:23:37 +02:00
// character name can't start from number
if (isNumeric(p2))
2010-08-30 23:07:14 +02:00
guid = MAKE_NEW_GUID(atoi(p2), 0, HIGHGUID_PLAYER);
2009-04-07 00:23:37 +02:00
else
{
std::string name = extractPlayerNameFromLink(p2);
2010-04-07 19:14:10 +02:00
if (name.empty())
2009-04-07 00:23:37 +02:00
{
SendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
guid = sObjectMgr->GetPlayerGUIDByName(name);
2009-04-07 00:23:37 +02:00
}
2009-10-17 15:51:44 -07:00
if (!sObjectMgr->GetPlayerAccountIdByGUID(guid))
2009-04-07 00:23:37 +02:00
{
PSendSysMessage(LANG_PLAYER_NOT_FOUND);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
switch (PlayerDumpWriter().WriteDump(file, uint32(guid)))
2009-04-07 00:23:37 +02:00
{
case DUMP_SUCCESS:
PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
break;
case DUMP_FILE_OPEN_ERROR:
2011-04-29 20:47:02 +02:00
PSendSysMessage(LANG_FILE_OPEN_FAIL, file);
2009-04-07 00:23:37 +02:00
SetSentErrorMessage(true);
return false;
2010-08-02 15:14:47 +02:00
case DUMP_CHARACTER_DELETED:
PSendSysMessage(LANG_COMMAND_EXPORT_DELETED_CHAR);
SetSentErrorMessage(true);
return false;
2009-04-07 00:23:37 +02:00
default:
PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
return true;
}
2009-10-17 15:51:44 -07:00
2009-11-19 03:53:49 -08:00
bool ChatHandler::HandlePlayAllCommand(const char *args)
2009-04-07 00:23:37 +02:00
{
2009-11-19 03:53:49 -08:00
if (!*args)
2009-04-07 00:23:37 +02:00
return false;
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
uint32 soundId = atoi((char*)args);
2009-10-17 15:51:44 -07:00
2009-11-19 03:53:49 -08:00
if (!sSoundEntriesStore.LookupEntry(soundId))
2009-04-07 00:23:37 +02:00
{
PSendSysMessage(LANG_SOUND_NOT_EXIST, soundId);
SetSentErrorMessage(true);
return false;
}
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
WorldPacket data(SMSG_PLAY_SOUND, 4);
data << uint32(soundId) << m_session->GetPlayer()->GetGUID();
sWorld->SendGlobalMessage(&data);
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
PSendSysMessage(LANG_COMMAND_PLAYED_TO_ALL, soundId);
return true;
}
2009-10-17 15:51:44 -07:00
2009-11-19 03:53:49 -08:00
bool ChatHandler::HandleGroupLeaderCommand(const char *args)
2009-04-07 00:23:37 +02:00
{
2011-11-07 11:06:39 -06:00
Player* player = NULL;
2009-04-07 00:23:37 +02:00
Group* group = NULL;
uint64 guid = 0;
char* cname = strtok((char*)args, " ");
2009-10-17 15:51:44 -07:00
2011-11-07 11:06:39 -06:00
if (GetPlayerGroupAndGUIDByName(cname, player, group, guid))
2009-11-19 03:53:49 -08:00
if (group && group->GetLeaderGUID() != guid)
2011-02-18 18:35:52 +01:00
{
2009-04-07 00:23:37 +02:00
group->ChangeLeader(guid);
2011-02-18 18:35:52 +01:00
group->SendUpdate();
}
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
return true;
}
2009-10-17 15:51:44 -07:00
2009-11-19 03:53:49 -08:00
bool ChatHandler::HandleGroupDisbandCommand(const char *args)
2009-04-07 00:23:37 +02:00
{
2011-11-07 11:06:39 -06:00
Player* player = NULL;
2009-04-07 00:23:37 +02:00
Group* group = NULL;
uint64 guid = 0;
char* cname = strtok((char*)args, " ");
2009-10-17 15:51:44 -07:00
2011-11-07 11:06:39 -06:00
if (GetPlayerGroupAndGUIDByName(cname, player, group, guid))
2009-11-19 03:53:49 -08:00
if (group)
2009-04-07 00:23:37 +02:00
group->Disband();
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
return true;
}
2009-10-17 15:51:44 -07:00
2009-11-19 03:53:49 -08:00
bool ChatHandler::HandleGroupRemoveCommand(const char *args)
2009-04-07 00:23:37 +02:00
{
2011-11-07 11:06:39 -06:00
Player* player = NULL;
2009-04-07 00:23:37 +02:00
Group* group = NULL;
uint64 guid = 0;
char* cname = strtok((char*)args, " ");
2009-10-17 15:51:44 -07:00
2011-11-07 11:06:39 -06:00
if (GetPlayerGroupAndGUIDByName(cname, player, group, guid, true))
2009-11-19 03:53:49 -08:00
if (group)
group->RemoveMember(guid);
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
return true;
}
2009-10-17 15:51:44 -07:00
2010-04-19 09:26:37 +02:00
bool ChatHandler::HandlePossessCommand(const char * /*args*/)
2009-04-07 00:23:37 +02:00
{
2011-10-07 10:48:56 -05:00
Unit* unit = getSelectedUnit();
if (!unit)
2009-04-07 00:23:37 +02:00
return false;
2009-10-17 15:51:44 -07:00
2011-10-07 10:48:56 -05:00
m_session->GetPlayer()->CastSpell(unit, 530, true);
2009-04-07 00:23:37 +02:00
return true;
}
2009-10-17 15:51:44 -07:00
2010-04-19 09:26:37 +02:00
bool ChatHandler::HandleUnPossessCommand(const char * /*args*/)
2009-04-07 00:23:37 +02:00
{
2011-10-07 10:48:56 -05:00
Unit* unit = getSelectedUnit();
if (!unit)
unit = m_session->GetPlayer();
2009-10-17 15:51:44 -07:00
2011-10-07 10:48:56 -05:00
unit->RemoveCharmAuras();
2009-10-17 15:51:44 -07:00
2009-04-07 00:23:37 +02:00
return true;
}
2009-10-17 15:51:44 -07:00
2010-04-19 09:26:37 +02:00
bool ChatHandler::HandleBindSightCommand(const char * /*args*/)
2009-04-07 00:23:37 +02:00
{
2011-10-07 10:48:56 -05:00
Unit* unit = getSelectedUnit();
if (!unit)
2009-04-07 00:23:37 +02:00
return false;
2009-10-17 15:51:44 -07:00
2011-10-07 10:48:56 -05:00
m_session->GetPlayer()->CastSpell(unit, 6277, true);
2009-04-07 00:23:37 +02:00
return true;
}
2009-10-17 15:51:44 -07:00
2010-04-19 09:26:37 +02:00
bool ChatHandler::HandleUnbindSightCommand(const char * /*args*/)
2009-04-07 00:23:37 +02:00
{
2012-03-28 19:11:50 +08:00
Player* player = m_session->GetPlayer();
if (player->isPossessing())
2009-04-07 00:23:37 +02:00
return false;
2009-10-17 15:51:44 -07:00
2012-03-28 19:11:50 +08:00
player->StopCastingBindSight();
2009-04-07 00:23:37 +02:00
return true;
}