mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Merge pull request #7218 from Vincent-Michael/commandMisc2
Core/Commands: Convert more misc commands in commandscript
This commit is contained in:
@@ -38,13 +38,6 @@
|
||||
|
||||
bool ChatHandler::load_command_table = true;
|
||||
|
||||
// wrapper for old-style handlers
|
||||
template<bool (ChatHandler::*F)(const char*)>
|
||||
bool OldHandler(ChatHandler* chatHandler, const char* args)
|
||||
{
|
||||
return (chatHandler->*F)(args);
|
||||
}
|
||||
|
||||
// get number of commands in table
|
||||
static size_t getCommandTableSize(const ChatCommand* commands)
|
||||
{
|
||||
@@ -67,35 +60,6 @@ static size_t appendCommandTable(ChatCommand* target, const ChatCommand* source)
|
||||
|
||||
ChatCommand* ChatHandler::getCommandTable()
|
||||
{
|
||||
|
||||
static ChatCommand groupCommandTable[] =
|
||||
{
|
||||
{ "leader", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleGroupLeaderCommand>, "", NULL },
|
||||
{ "disband", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleGroupDisbandCommand>, "", NULL },
|
||||
{ "remove", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleGroupRemoveCommand>, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand pdumpCommandTable[] =
|
||||
{
|
||||
{ "load", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandlePDumpLoadCommand>, "", NULL },
|
||||
{ "write", SEC_ADMINISTRATOR, true, OldHandler<&ChatHandler::HandlePDumpWriteCommand>, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "pdump", SEC_ADMINISTRATOR, true, NULL, "", pdumpCommandTable },
|
||||
{ "group", SEC_ADMINISTRATOR, false, NULL, "", groupCommandTable },
|
||||
|
||||
{ "possess", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandlePossessCommand>, "", NULL },
|
||||
{ "unpossess", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleUnPossessCommand>, "", NULL },
|
||||
{ "bindsight", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleBindSightCommand>, "", NULL },
|
||||
{ "unbindsight", SEC_ADMINISTRATOR, false, OldHandler<&ChatHandler::HandleUnbindSightCommand>, "", NULL },
|
||||
{ "playall", SEC_GAMEMASTER, false, OldHandler<&ChatHandler::HandlePlayAllCommand>, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
|
||||
// cache for commands, needed because some commands are loaded dynamically through ScriptMgr
|
||||
// cache is never freed and will show as a memory leak in diagnostic tools
|
||||
// can't use vector as vector storage is implementation-dependent, eg, there can be alignment gaps between elements
|
||||
@@ -107,25 +71,23 @@ ChatCommand* ChatHandler::getCommandTable()
|
||||
|
||||
{
|
||||
// count total number of top-level commands
|
||||
size_t total = getCommandTableSize(commandTable);
|
||||
size_t total = 0;
|
||||
std::vector<ChatCommand*> const& dynamic = sScriptMgr->GetChatCommands();
|
||||
for (std::vector<ChatCommand*>::const_iterator it = dynamic.begin(); it != dynamic.end(); ++it)
|
||||
total += getCommandTableSize(*it);
|
||||
total += 1; // ending zero
|
||||
|
||||
// cache top-level commands
|
||||
size_t added = 0;
|
||||
commandTableCache = (ChatCommand*)malloc(sizeof(ChatCommand) * total);
|
||||
memset(commandTableCache, 0, sizeof(ChatCommand) * total);
|
||||
ACE_ASSERT(commandTableCache);
|
||||
size_t added = appendCommandTable(commandTableCache, commandTable);
|
||||
for (std::vector<ChatCommand*>::const_iterator it = dynamic.begin(); it != dynamic.end(); ++it)
|
||||
added += appendCommandTable(commandTableCache + added, *it);
|
||||
}
|
||||
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_COMMANDS);
|
||||
|
||||
PreparedQueryResult result = WorldDatabase.Query(stmt);
|
||||
|
||||
if (result)
|
||||
{
|
||||
do
|
||||
@@ -135,7 +97,8 @@ ChatCommand* ChatHandler::getCommandTable()
|
||||
|
||||
SetDataForCommandInTable(commandTableCache, name.c_str(), fields[1].GetUInt8(), fields[2].GetString(), name);
|
||||
|
||||
} while (result->NextRow());
|
||||
}
|
||||
while (result->NextRow());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,19 +131,6 @@ class ChatHandler
|
||||
bool ExecuteCommandInTable(ChatCommand* table, const char* text, const std::string& fullcmd);
|
||||
bool ShowHelpForSubCommands(ChatCommand* table, char const* cmd, char const* subcmd);
|
||||
|
||||
bool HandlePossessCommand(const char* args);
|
||||
bool HandleUnPossessCommand(const char* args);
|
||||
bool HandleBindSightCommand(const char* args);
|
||||
bool HandleUnbindSightCommand(const char* args);
|
||||
|
||||
bool HandlePDumpLoadCommand(const char *args);
|
||||
bool HandlePDumpWriteCommand(const char *args);
|
||||
|
||||
bool HandleGroupLeaderCommand(const char* args);
|
||||
bool HandleGroupDisbandCommand(const char* args);
|
||||
bool HandleGroupRemoveCommand(const char* args);
|
||||
|
||||
bool HandlePlayAllCommand(const char* args);
|
||||
private:
|
||||
WorldSession* m_session; // != NULL for chat command call and NULL for CLI command
|
||||
|
||||
|
||||
@@ -1,342 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@@ -26,6 +26,7 @@ EndScriptData */
|
||||
#include "Chat.h"
|
||||
#include "AccountMgr.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "PlayerDump.h"
|
||||
|
||||
class character_commandscript : public CommandScript
|
||||
{
|
||||
@@ -34,6 +35,12 @@ public:
|
||||
|
||||
ChatCommand* GetCommands() const
|
||||
{
|
||||
static ChatCommand pdumpCommandTable[] =
|
||||
{
|
||||
{ "load", SEC_ADMINISTRATOR, true, &HandlePDumpLoadCommand, "", NULL },
|
||||
{ "write", SEC_ADMINISTRATOR, true, &HandlePDumpWriteCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand characterDeletedCommandTable[] =
|
||||
{
|
||||
{ "delete", SEC_CONSOLE, true, &HandleCharacterDeletedDeleteCommand, "", NULL },
|
||||
@@ -48,7 +55,7 @@ public:
|
||||
{ "customize", SEC_GAMEMASTER, true, &HandleCharacterCustomizeCommand, "", NULL },
|
||||
{ "changefaction", SEC_GAMEMASTER, true, &HandleCharacterChangeFactionCommand, "", NULL },
|
||||
{ "changerace", SEC_GAMEMASTER, true, &HandleCharacterChangeRaceCommand, "", NULL },
|
||||
{ "deleted", SEC_GAMEMASTER, true, NULL, "", characterDeletedCommandTable},
|
||||
{ "deleted", SEC_GAMEMASTER, true, NULL, "", characterDeletedCommandTable },
|
||||
{ "erase", SEC_CONSOLE, true, &HandleCharacterEraseCommand, "", NULL },
|
||||
{ "level", SEC_ADMINISTRATOR, true, &HandleCharacterLevelCommand, "", NULL },
|
||||
{ "rename", SEC_GAMEMASTER, true, &HandleCharacterRenameCommand, "", NULL },
|
||||
@@ -59,8 +66,9 @@ public:
|
||||
|
||||
static ChatCommand commandTable[] =
|
||||
{
|
||||
{ "character", SEC_GAMEMASTER, true, NULL, "", characterCommandTable},
|
||||
{ "character", SEC_GAMEMASTER, true, NULL, "", characterCommandTable },
|
||||
{ "levelup", SEC_ADMINISTRATOR, false, &HandleLevelUpCommand, "", NULL },
|
||||
{ "pdump", SEC_ADMINISTRATOR, true, NULL, "", pdumpCommandTable },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
return commandTable;
|
||||
@@ -740,6 +748,174 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandlePDumpLoadCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* fileStr = strtok((char*)args, " ");
|
||||
if (!fileStr)
|
||||
return false;
|
||||
|
||||
char* accountStr = strtok(NULL, " ");
|
||||
if (!accountStr)
|
||||
return false;
|
||||
|
||||
std::string accountName = accountStr;
|
||||
if (!AccountMgr::normalizeString(accountName))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 accountId = AccountMgr::GetId(accountName);
|
||||
if (!accountId)
|
||||
{
|
||||
accountId = atoi(accountStr); // use original string
|
||||
if (!accountId)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!AccountMgr::GetName(accountId, accountName))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
char* guidStr = NULL;
|
||||
char* nameStr = strtok(NULL, " ");
|
||||
|
||||
std::string name;
|
||||
if (nameStr)
|
||||
{
|
||||
name = nameStr;
|
||||
// normalize the name if specified and check if it exists
|
||||
if (!normalizePlayerName(name))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ObjectMgr::CheckPlayerName(name, true) != CHAR_NAME_SUCCESS)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
guidStr = strtok(NULL, " ");
|
||||
}
|
||||
|
||||
uint32 guid = 0;
|
||||
|
||||
if (guidStr)
|
||||
{
|
||||
guid = uint32(atoi(guidStr));
|
||||
if (!guid)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sObjectMgr->GetPlayerAccountIdByGUID(guid))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_CHARACTER_GUID_IN_USE, guid);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (PlayerDumpReader().LoadDump(fileStr, accountId, name, guid))
|
||||
{
|
||||
case DUMP_SUCCESS:
|
||||
handler->PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
|
||||
break;
|
||||
case DUMP_FILE_OPEN_ERROR:
|
||||
handler->PSendSysMessage(LANG_FILE_OPEN_FAIL, fileStr);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case DUMP_FILE_BROKEN:
|
||||
handler->PSendSysMessage(LANG_DUMP_BROKEN, fileStr);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case DUMP_TOO_MANY_CHARS:
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL, accountName.c_str(), accountId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
default:
|
||||
handler->PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandlePDumpWriteCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* fileStr = strtok((char*)args, " ");
|
||||
char* playerStr = strtok(NULL, " ");
|
||||
|
||||
if (!fileStr || !playerStr)
|
||||
return false;
|
||||
|
||||
uint64 guid;
|
||||
// character name can't start from number
|
||||
if (isNumeric(playerStr))
|
||||
guid = MAKE_NEW_GUID(atoi(playerStr), 0, HIGHGUID_PLAYER);
|
||||
else
|
||||
{
|
||||
std::string name = handler->extractPlayerNameFromLink(playerStr);
|
||||
if (name.empty())
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
guid = sObjectMgr->GetPlayerGUIDByName(name);
|
||||
}
|
||||
|
||||
if (!sObjectMgr->GetPlayerAccountIdByGUID(guid))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (PlayerDumpWriter().WriteDump(fileStr, uint32(guid)))
|
||||
{
|
||||
case DUMP_SUCCESS:
|
||||
handler->PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
|
||||
break;
|
||||
case DUMP_FILE_OPEN_ERROR:
|
||||
handler->PSendSysMessage(LANG_FILE_OPEN_FAIL, fileStr);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
case DUMP_CHARACTER_DELETED:
|
||||
handler->PSendSysMessage(LANG_COMMAND_EXPORT_DELETED_CHAR);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
default:
|
||||
handler->PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_character_commandscript()
|
||||
|
||||
@@ -1156,7 +1156,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleLookupMapCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleLookupMapCommand(ChatHandler* /*handler*/, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
@@ -37,11 +37,18 @@ public:
|
||||
|
||||
ChatCommand* GetCommands() const
|
||||
{
|
||||
static ChatCommand groupCommandTable[] =
|
||||
{
|
||||
{ "leader", SEC_ADMINISTRATOR, false, &HandleGroupLeaderCommand, "", NULL },
|
||||
{ "disband", SEC_ADMINISTRATOR, false, &HandleGroupDisbandCommand, "", NULL },
|
||||
{ "remove", SEC_ADMINISTRATOR, false, &HandleGroupRemoveCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand petCommandTable[] =
|
||||
{
|
||||
{ "create", SEC_GAMEMASTER, false, &HandleCreatePetCommand, "", NULL },
|
||||
{ "learn", SEC_GAMEMASTER, false, &HandlePetLearnCommand, "", NULL },
|
||||
{ "unlearn", SEC_GAMEMASTER, false, &HandlePetUnlearnCommand, "", NULL },
|
||||
{ "create", SEC_GAMEMASTER, false, &HandleCreatePetCommand, "", NULL },
|
||||
{ "learn", SEC_GAMEMASTER, false, &HandlePetLearnCommand, "", NULL },
|
||||
{ "unlearn", SEC_GAMEMASTER, false, &HandlePetUnlearnCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
static ChatCommand sendCommandTable[] =
|
||||
@@ -103,6 +110,12 @@ public:
|
||||
{ "freeze", SEC_MODERATOR, false, &HandleFreezeCommand, "", NULL },
|
||||
{ "unfreeze", SEC_MODERATOR, false, &HandleUnFreezeCommand, "", NULL },
|
||||
{ "listfreeze", SEC_MODERATOR, false, &HandleListFreezeCommand, "", NULL },
|
||||
{ "group", SEC_ADMINISTRATOR, false, NULL, "", groupCommandTable },
|
||||
{ "possess", SEC_ADMINISTRATOR, false, HandlePossessCommand, "", NULL },
|
||||
{ "unpossess", SEC_ADMINISTRATOR, false, HandleUnPossessCommand, "", NULL },
|
||||
{ "bindsight", SEC_ADMINISTRATOR, false, HandleBindSightCommand, "", NULL },
|
||||
{ "unbindsight", SEC_ADMINISTRATOR, false, HandleUnbindSightCommand, "", NULL },
|
||||
{ "playall", SEC_GAMEMASTER, false, HandlePlayAllCommand, "", NULL },
|
||||
{ NULL, 0, false, NULL, "", NULL }
|
||||
};
|
||||
return commandTable;
|
||||
@@ -2749,6 +2762,115 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGroupLeaderCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
Player* player = NULL;
|
||||
Group* group = NULL;
|
||||
uint64 guid = 0;
|
||||
char* nameStr = strtok((char*)args, " ");
|
||||
|
||||
if (handler->GetPlayerGroupAndGUIDByName(nameStr, player, group, guid))
|
||||
if (group && group->GetLeaderGUID() != guid)
|
||||
{
|
||||
group->ChangeLeader(guid);
|
||||
group->SendUpdate();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGroupDisbandCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
Player* player = NULL;
|
||||
Group* group = NULL;
|
||||
uint64 guid = 0;
|
||||
char* nameStr = strtok((char*)args, " ");
|
||||
|
||||
if (handler->GetPlayerGroupAndGUIDByName(nameStr, player, group, guid))
|
||||
if (group)
|
||||
group->Disband();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleGroupRemoveCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
Player* player = NULL;
|
||||
Group* group = NULL;
|
||||
uint64 guid = 0;
|
||||
char* nameStr = strtok((char*)args, " ");
|
||||
|
||||
if (handler->GetPlayerGroupAndGUIDByName(nameStr, player, group, guid, true))
|
||||
if (group)
|
||||
group->RemoveMember(guid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandlePlayAllCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
uint32 soundId = atoi((char*)args);
|
||||
|
||||
if (!sSoundEntriesStore.LookupEntry(soundId))
|
||||
{
|
||||
handler->PSendSysMessage(LANG_SOUND_NOT_EXIST, soundId);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
WorldPacket data(SMSG_PLAY_SOUND, 4);
|
||||
data << uint32(soundId) << handler->GetSession()->GetPlayer()->GetGUID();
|
||||
sWorld->SendGlobalMessage(&data);
|
||||
|
||||
handler->PSendSysMessage(LANG_COMMAND_PLAYED_TO_ALL, soundId);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandlePossessCommand(ChatHandler* handler, char const* /*args*/)
|
||||
{
|
||||
Unit* unit = handler->getSelectedUnit();
|
||||
if (!unit)
|
||||
return false;
|
||||
|
||||
handler->GetSession()->GetPlayer()->CastSpell(unit, 530, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleUnPossessCommand(ChatHandler* handler, char const* /*args*/)
|
||||
{
|
||||
Unit* unit = handler->getSelectedUnit();
|
||||
if (!unit)
|
||||
unit = handler->GetSession()->GetPlayer();
|
||||
|
||||
unit->RemoveCharmAuras();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleBindSightCommand(ChatHandler* handler, char const* /*args*/)
|
||||
{
|
||||
Unit* unit = handler->getSelectedUnit();
|
||||
if (!unit)
|
||||
return false;
|
||||
|
||||
handler->GetSession()->GetPlayer()->CastSpell(unit, 6277, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleUnbindSightCommand(ChatHandler* handler, char const* /*args*/)
|
||||
{
|
||||
Player* player = handler->GetSession()->GetPlayer();
|
||||
|
||||
if (player->isPossessing())
|
||||
return false;
|
||||
|
||||
player->StopCastingBindSight();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_misc_commandscript()
|
||||
|
||||
Reference in New Issue
Block a user