diff options
| author | Subv <s.v.h21@hotmail.com> | 2012-07-29 07:57:55 -0700 |
|---|---|---|
| committer | Subv <s.v.h21@hotmail.com> | 2012-07-29 07:57:55 -0700 |
| commit | caea2a16a637de78b2f10ffec8832ffe8700e17d (patch) | |
| tree | 117e545cdaafbd3fc9d3ffcd8c8d50069a65e086 /src/server/game/Chat | |
| parent | e40a088b1576e5c5be0b60e35d51c2f7db34bf85 (diff) | |
| parent | 4a3df36bd9a72bdc519e2a366672a3ef638c5c0e (diff) | |
Merge pull request #7218 from Vincent-Michael/commandMisc2
Core/Commands: Convert more misc commands in commandscript
Diffstat (limited to 'src/server/game/Chat')
| -rwxr-xr-x | src/server/game/Chat/Chat.cpp | 45 | ||||
| -rwxr-xr-x | src/server/game/Chat/Chat.h | 13 | ||||
| -rwxr-xr-x | src/server/game/Chat/Commands/Level3.cpp | 342 |
3 files changed, 4 insertions, 396 deletions
diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index 5211e4686ac..32a6273abd4 100755 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -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()); } } diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index 5a20f312ae1..269ebdd1d2f 100755 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -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 diff --git a/src/server/game/Chat/Commands/Level3.cpp b/src/server/game/Chat/Commands/Level3.cpp deleted file mode 100755 index 41c92f36997..00000000000 --- a/src/server/game/Chat/Commands/Level3.cpp +++ /dev/null @@ -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; -} |
