diff options
| author | Treeston <treeston.mmoc@gmail.com> | 2018-09-07 20:31:04 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2021-10-25 00:03:23 +0200 |
| commit | 0c681b6509d4b517dc2e65a152753224df745605 (patch) | |
| tree | 61c77765713f13d5d7006ef90e6c0a392ee6328a /src/server/scripts/Commands | |
| parent | 42f366648f6b65753b3719f66b406e110ec9a871 (diff) | |
Scripts/Commands: New argument parsing methodology (PR #22363)
- Detect the arguments accepted by the command handler
- Tokenize out those arguments automatically and feed them to the handler
- Unmatched rest of the string can be accepted by trailing char const* or CommandArgs*
(cherry picked from commit 66a87c4642d25f27ca24254cfeb0a0c4b21036b1)
Diffstat (limited to 'src/server/scripts/Commands')
| -rw-r--r-- | src/server/scripts/Commands/cs_go.cpp | 455 | ||||
| -rw-r--r-- | src/server/scripts/Commands/cs_tele.cpp | 43 |
2 files changed, 146 insertions, 352 deletions
diff --git a/src/server/scripts/Commands/cs_go.cpp b/src/server/scripts/Commands/cs_go.cpp index 75c8822e171..ffd3181d205 100644 --- a/src/server/scripts/Commands/cs_go.cpp +++ b/src/server/scripts/Commands/cs_go.cpp @@ -34,9 +34,11 @@ EndScriptData */ #include "RBAC.h" #include "SupportMgr.h" #include "Transport.h" +#include "Util.h" #include "WorldSession.h" #include <sstream> +using namespace Trinity::ChatCommands; class go_commandscript : public CommandScript { public: @@ -44,15 +46,27 @@ public: std::vector<ChatCommand> GetCommands() const override { + static std::vector<ChatCommand> goCreatureCommandTable = + { + { "id", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoCreatureCIdCommand, "" }, + { "", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoCreatureSpawnIdCommand, "" } + }; + + static std::vector<ChatCommand> goGameObjectCommandTable = + { + { "id", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoGameObjectGOIdCommand, "" }, + { "", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoGameObjectSpawnIdCommand, "" } + }; + static std::vector<ChatCommand> goCommandTable = { - { "creature", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoCreatureCommand, "" }, + { "creature", rbac::RBAC_PERM_COMMAND_GO, false, nullptr, "", goCreatureCommandTable }, + { "gameobject", rbac::RBAC_PERM_COMMAND_GO, false, nullptr, "", goGameObjectCommandTable }, { "graveyard", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoGraveyardCommand, "" }, { "grid", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoGridCommand, "" }, - { "object", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoObjectCommand, "" }, { "quest", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoQuestCommand, "" }, { "taxinode", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoTaxinodeCommand, "" }, - { "trigger", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoTriggerCommand, "" }, + { "areatrigger", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoAreaTriggerCommand, "" }, { "zonexy", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoZoneXYCommand, "" }, { "xyz", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoXYZCommand, "" }, { "bugticket", rbac::RBAC_PERM_COMMAND_GO, false, &HandleGoTicketCommand<BugTicket>, "" }, @@ -69,118 +83,113 @@ public: return commandTable; } - /** \brief Teleport the GM to the specified creature - * - * .gocreature <GUID> --> TP using creature.guid - * .gocreature azuregos --> TP player to the mob with this name - * Warning: If there is more than one mob with this name - * you will be teleported to the first one that is found. - * .gocreature id 6109 --> TP player to the mob, that has this creature_template.entry - * Warning: If there is more than one mob with this "id" - * you will be teleported to the first one that is found. - */ - //teleport to creature - static bool HandleGoCreatureCommand(ChatHandler* handler, char const* args) + static bool DoTeleport(ChatHandler* handler, WorldLocation loc) { - if (!*args) - return false; - Player* player = handler->GetSession()->GetPlayer(); - // "id" or number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r - char* param1 = handler->extractKeyFromLink((char*)args, "Hcreature"); - if (!param1) + if (!MapManager::IsValidMapCoord(loc) || sObjectMgr->IsTransportMap(loc.GetMapId())) + { + handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ()); + handler->SetSentErrorMessage(true); return false; + } + + // stop flight if need + if (player->IsInFlight()) + player->FinishTaxiFlight(); + else + player->SaveRecallPosition(); // save only in non-flight case - std::ostringstream whereClause; + player->TeleportTo(loc); + return true; + } - // User wants to teleport to the NPC's template entry - if (strcmp(param1, "id") == 0) + static bool HandleGoCreatureSpawnIdCommand(ChatHandler* handler, Variant<Hyperlink<creature>, ObjectGuid::LowType> spawnId) + { + CreatureData const* spawnpoint = sObjectMgr->GetCreatureData(spawnId); + if (!spawnpoint) { - // Get the "creature_template.entry" - // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r - char* tail = strtok(nullptr, ""); - if (!tail) - return false; - char* id = handler->extractKeyFromLink(tail, "Hcreature_entry"); - if (!id) - return false; + handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND); + handler->SetSentErrorMessage(true); + return false; + } - uint32 entry = atoul(id); - if (!entry) - return false; + return DoTeleport(handler, spawnpoint->spawnPoint); + } - whereClause << "WHERE id = '" << entry << '\''; - } - else + static bool HandleGoCreatureCIdCommand(ChatHandler* handler, Variant<Hyperlink<creature_entry>, uint32> cId) + { + CreatureData const* spawnpoint = nullptr; + for (auto const& pair : sObjectMgr->GetAllCreatureData()) { - ObjectGuid::LowType guidLow = atoull(param1); + if (pair.second.id != *cId) + continue; - // Number is invalid - maybe the user specified the mob's name - if (!guidLow) + if (!spawnpoint) + spawnpoint = &pair.second; + else { - std::string name = param1; - WorldDatabase.EscapeString(name); - whereClause << ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name LIKE '" << name << '\''; + handler->SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE); + break; } - else - whereClause << "WHERE guid = '" << guidLow << '\''; } - QueryResult result = WorldDatabase.PQuery("SELECT position_x, position_y, position_z, orientation, map FROM creature %s", whereClause.str().c_str()); - if (!result) + if (!spawnpoint) { handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND); handler->SetSentErrorMessage(true); return false; } - if (result->GetRowCount() > 1) - handler->SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE); - Field* fields = result->Fetch(); - float x = fields[0].GetFloat(); - float y = fields[1].GetFloat(); - float z = fields[2].GetFloat(); - float o = fields[3].GetFloat(); - uint32 mapId = fields[4].GetUInt16(); + return DoTeleport(handler, spawnpoint->spawnPoint); + } - if (!MapManager::IsValidMapCoord(mapId, x, y, z, o) || sObjectMgr->IsTransportMap(mapId)) + static bool HandleGoGameObjectSpawnIdCommand(ChatHandler* handler, uint32 spawnId) + { + GameObjectData const* spawnpoint = sObjectMgr->GetGameObjectData(spawnId); + if (!spawnpoint) { - handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId); + handler->SendSysMessage(LANG_COMMAND_GOOBJNOTFOUND); handler->SetSentErrorMessage(true); return false; } - // stop flight if need - if (player->IsInFlight()) - player->FinishTaxiFlight(); - else - player->SaveRecallPosition(); // save only in non-flight case - - player->TeleportTo(mapId, x, y, z, o); - return true; + return DoTeleport(handler, spawnpoint->spawnPoint); } - static bool HandleGoGraveyardCommand(ChatHandler* handler, char const* args) + static bool HandleGoGameObjectGOIdCommand(ChatHandler* handler, uint32 goId) { - Player* player = handler->GetSession()->GetPlayer(); + GameObjectData const* spawnpoint = nullptr; + for (auto const& pair : sObjectMgr->GetAllGameObjectData()) + { + if (pair.second.id != goId) + continue; - if (!*args) - return false; + if (!spawnpoint) + spawnpoint = &pair.second; + else + { + handler->SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE); + break; + } + } - char* gyId = strtok((char*)args, " "); - if (!gyId) + if (!spawnpoint) + { + handler->SendSysMessage(LANG_COMMAND_GOOBJNOTFOUND); + handler->SetSentErrorMessage(true); return false; + } - uint32 graveyardId = atoul(gyId); - - if (!graveyardId) - return false; + return DoTeleport(handler, spawnpoint->spawnPoint); + } - WorldSafeLocsEntry const* gy = sObjectMgr->GetWorldSafeLoc(graveyardId); + static bool HandleGoGraveyardCommand(ChatHandler* handler, uint32 gyId) + { + WorldSafeLocsEntry const* gy = sObjectMgr->GetWorldSafeLoc(gyId); if (!gy) { - handler->PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, graveyardId); + handler->PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, gyId); handler->SetSentErrorMessage(true); return false; } @@ -192,6 +201,7 @@ public: return false; } + Player* player = handler->GetSession()->GetPlayer(); // stop flight if need if (player->IsInFlight()) player->FinishTaxiFlight(); @@ -203,25 +213,14 @@ public: } //teleport to grid - static bool HandleGoGridCommand(ChatHandler* handler, char const* args) + static bool HandleGoGridCommand(ChatHandler* handler, float gridX, float gridY, Optional<uint32> oMapId) { - if (!*args) - return false; - Player* player = handler->GetSession()->GetPlayer(); - - char* gridX = strtok((char*)args, " "); - char* gridY = strtok(nullptr, " "); - char* id = strtok(nullptr, " "); - - if (!gridX || !gridY) - return false; - - uint32 mapId = id ? atoul(id) : player->GetMapId(); + uint32 mapId = oMapId.get_value_or(player->GetMapId()); // center of grid - float x = ((float)atof(gridX) - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS; - float y = ((float)atof(gridY) - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS; + float x = (gridX - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS; + float y = (gridY - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS; if (!MapManager::IsValidMapCoord(mapId, x, y)) { @@ -243,49 +242,6 @@ public: return true; } - //teleport to gameobject - static bool HandleGoObjectCommand(ChatHandler* handler, char const* args) - { - if (!*args) - return false; - - Player* player = handler->GetSession()->GetPlayer(); - - // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r - char* id = handler->extractKeyFromLink((char*)args, "Hgameobject"); - if (!id) - return false; - - ObjectGuid::LowType guidLow = atoull(id); - if (!guidLow) - return false; - - // by DB guid - GameObjectData const* goData = sObjectMgr->GetGameObjectData(guidLow); - if (!goData) - { - handler->SendSysMessage(LANG_COMMAND_GOOBJNOTFOUND); - handler->SetSentErrorMessage(true); - return false; - } - - if (!MapManager::IsValidMapCoord(goData->spawnPoint) || sObjectMgr->IsTransportMap(goData->spawnPoint.GetMapId())) - { - handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, goData->spawnPoint.GetPositionX(), goData->spawnPoint.GetPositionY(), goData->spawnPoint.GetMapId()); - handler->SetSentErrorMessage(true); - return false; - } - - // stop flight if need - if (player->IsInFlight()) - player->FinishTaxiFlight(); - else - player->SaveRecallPosition(); // save only in non-flight case - - player->TeleportTo(goData->spawnPoint); - return true; - } - static bool HandleGoQuestCommand(ChatHandler* handler, char const* args) { if (!*args) @@ -348,21 +304,8 @@ public: return true; } - static bool HandleGoTaxinodeCommand(ChatHandler* handler, char const* args) + static bool HandleGoTaxinodeCommand(ChatHandler* handler, Variant<Hyperlink<taxinode>, uint32> nodeId) { - Player* player = handler->GetSession()->GetPlayer(); - - if (!*args) - return false; - - char* id = handler->extractKeyFromLink((char*)args, "Htaxinode"); - if (!id) - return false; - - uint32 nodeId = atoul(id); - if (!nodeId) - return false; - TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(nodeId); if (!node) { @@ -370,41 +313,11 @@ public: handler->SetSentErrorMessage(true); return false; } - - if ((node->Pos.X == 0.0f && node->Pos.Y == 0.0f && node->Pos.Z == 0.0f) || - !MapManager::IsValidMapCoord(node->ContinentID, node->Pos.X, node->Pos.Y, node->Pos.Z)) - { - handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, node->Pos.X, node->Pos.Y, uint32(node->ContinentID)); - handler->SetSentErrorMessage(true); - return false; - } - - // stop flight if need - if (player->IsInFlight()) - player->FinishTaxiFlight(); - else - player->SaveRecallPosition(); // save only in non-flight case - - player->TeleportTo(node->ContinentID, node->Pos.X, node->Pos.Y, node->Pos.Z, player->GetOrientation()); - return true; + return DoTeleport(handler, { node->ContinentID, { node->Pos.X, node->Pos.Y, node->Pos.Z } }); } - static bool HandleGoTriggerCommand(ChatHandler* handler, char const* args) + static bool HandleGoAreaTriggerCommand(ChatHandler* handler, Variant<Hyperlink<areatrigger>, uint32> areaTriggerId) { - Player* player = handler->GetSession()->GetPlayer(); - - if (!*args) - return false; - - char* id = strtok((char*)args, " "); - if (!id) - return false; - - uint32 areaTriggerId = atoul(id); - - if (!areaTriggerId) - return false; - AreaTriggerEntry const* at = sAreaTriggerStore.LookupEntry(areaTriggerId); if (!at) { @@ -412,22 +325,7 @@ public: handler->SetSentErrorMessage(true); return false; } - - if (!MapManager::IsValidMapCoord(at->ContinentID, at->Pos.X, at->Pos.Y, at->Pos.Z)) - { - handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, at->Pos.X, at->Pos.Y, uint32(at->ContinentID)); - handler->SetSentErrorMessage(true); - return false; - } - - // stop flight if need - if (player->IsInFlight()) - player->FinishTaxiFlight(); - else - player->SaveRecallPosition(); // save only in non-flight case - - player->TeleportTo(at->ContinentID, at->Pos.X, at->Pos.Y, at->Pos.Z, player->GetOrientation()); - return true; + return DoTeleport(handler, { uint32(at->ContinentID), { at->Pos.X, at->Pos.Y, at->Pos.Z } }); } //teleport at coordinates @@ -503,32 +401,13 @@ public: } //teleport at coordinates, including Z and orientation - static bool HandleGoXYZCommand(ChatHandler* handler, char const* args) + static bool HandleGoXYZCommand(ChatHandler* handler, float x, float y, Optional<float> z, Optional<uint32> id, Optional<float> o) { - if (!*args) - return false; - Player* player = handler->GetSession()->GetPlayer(); - - char* goX = strtok((char*)args, " "); - char* goY = strtok(nullptr, " "); - char* goZ = strtok(nullptr, " "); - char* id = strtok(nullptr, " "); - char* port = strtok(nullptr, " "); - - if (!goX || !goY) - return false; - - float x = (float)atof(goX); - float y = (float)atof(goY); - float z; - float ort = port ? (float)atof(port) : player->GetOrientation(); - uint32 mapId = id ? atoul(id) : player->GetMapId(); - - if (goZ) + uint32 mapId = id.get_value_or(player->GetMapId()); + if (z) { - z = (float)atof(goZ); - if (!MapManager::IsValidMapCoord(mapId, x, y, z)) + if (!MapManager::IsValidMapCoord(mapId, x, y, *z)) { handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId); handler->SetSentErrorMessage(true); @@ -547,30 +426,12 @@ public: z = std::max(map->GetStaticHeight(PhasingHandler::GetEmptyPhaseShift(), x, y, MAX_HEIGHT), map->GetWaterLevel(PhasingHandler::GetEmptyPhaseShift(), x, y)); } - // stop flight if need - if (player->IsInFlight()) - player->FinishTaxiFlight(); - else - player->SaveRecallPosition(); // save only in non-flight case - - player->TeleportTo(mapId, x, y, z, ort); - return true; + return DoTeleport(handler, { mapId, { x, y, *z, o.get_value_or(0.0f) } }); } template<typename T> - static bool HandleGoTicketCommand(ChatHandler* handler, char const* args) + static bool HandleGoTicketCommand(ChatHandler* handler, uint32 ticketId) { - if (!*args) - return false; - - char* id = strtok((char*)args, " "); - if (!id) - return false; - - uint32 ticketId = atoul(id); - if (!ticketId) - return false; - T* ticket = sSupportMgr->GetTicket<T>(ticketId); if (!ticket) { @@ -590,95 +451,47 @@ public: return true; } - static bool HandleGoOffsetCommand(ChatHandler* handler, char const* args) + static bool HandleGoOffsetCommand(ChatHandler* handler, float dX, Optional<float> dY, Optional<float> dZ, Optional<float> dO) { - if (!*args) - return false; - - Player* player = handler->GetSession()->GetPlayer(); + WorldLocation loc = handler->GetSession()->GetPlayer()->GetWorldLocation(); + loc.RelocateOffset({ dX, dY.get_value_or(0.0f), dZ.get_value_or(0.0f), dO.get_value_or(0.0f) }); - char* goX = strtok((char*)args, " "); - char* goY = strtok(nullptr, " "); - char* goZ = strtok(nullptr, " "); - char* port = strtok(nullptr, " "); - - float x, y, z, o; - player->GetPosition(x, y, z, o); - if (goX) - x += atof(goX); - if (goY) - y += atof(goY); - if (goZ) - z += atof(goZ); - if (port) - o += atof(port); - - if (!Trinity::IsValidMapCoord(x, y, z, o)) - { - handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, player->GetMapId()); - handler->SetSentErrorMessage(true); - return false; - } - - // stop flight if need - if (player->IsInFlight()) - player->FinishTaxiFlight(); - else - player->SaveRecallPosition(); // save only in non-flight case - - player->TeleportTo(player->GetMapId(), x, y, z, o); - return true; + return DoTeleport(handler, loc); } - static bool HandleGoInstanceCommand(ChatHandler* handler, char const* args) + static bool HandleGoInstanceCommand(ChatHandler* handler, std::vector<std::string> const& labels) { - if (!*args) - return false; - - char* pos = const_cast<char*>(args); - do *pos = tolower(*pos); - while (*(++pos)); - - Tokenizer labels(args, ' '); uint32 mapid = 0; - if (labels.size() == 1) + + std::multimap<uint32, std::pair<uint32, std::string>> matches; + for (auto const& pair : sObjectMgr->GetInstanceTemplates()) { - try { mapid = std::stoi(labels[0]); } - catch (...) {} + uint32 count = 0; + std::string const& scriptName = sObjectMgr->GetScriptName(pair.second.ScriptId); + for (auto const& label : labels) + if (StringContainsStringI(scriptName, label)) + ++count; + + if (count) + matches.emplace(count, decltype(matches)::mapped_type({ pair.first, scriptName })); } - - if (!mapid) + if (matches.empty()) { - std::multimap<uint32, std::pair<uint32, std::string>> matches; - for (auto const& pair : sObjectMgr->GetInstanceTemplates()) - { - uint32 count = 0; - std::string const& scriptName = sObjectMgr->GetScriptName(pair.second.ScriptId); - for (char const* label : labels) - if (scriptName.find(label) != std::string::npos) - ++count; - - if (count) - matches.emplace(count, decltype(matches)::mapped_type({ pair.first, scriptName })); - } - if (matches.empty()) - { - handler->SendSysMessage(LANG_COMMAND_NO_INSTANCES_MATCH); - return false; - } - auto it = matches.rbegin(); - uint32 maxCount = it->first; - mapid = it->second.first; - if (++it != matches.rend() && it->first == maxCount) - { - handler->SendSysMessage(LANG_COMMAND_MULTIPLE_INSTANCES_MATCH); - --it; - do - handler->PSendSysMessage(LANG_COMMAND_MULTIPLE_INSTANCES_ENTRY, it->second.first, it->second.second.c_str()); - while (++it != matches.rend() && it->first == maxCount); - handler->SetSentErrorMessage(true); - return false; - } + handler->SendSysMessage(LANG_COMMAND_NO_INSTANCES_MATCH); + return false; + } + auto it = matches.rbegin(); + uint32 maxCount = it->first; + mapid = it->second.first; + if (++it != matches.rend() && it->first == maxCount) + { + handler->SendSysMessage(LANG_COMMAND_MULTIPLE_INSTANCES_MATCH); + --it; + do + handler->PSendSysMessage(LANG_COMMAND_MULTIPLE_INSTANCES_ENTRY, it->second.first, it->second.second); + while (++it != matches.rend() && it->first == maxCount); + handler->SetSentErrorMessage(true); + return false; } ASSERT(mapid); diff --git a/src/server/scripts/Commands/cs_tele.cpp b/src/server/scripts/Commands/cs_tele.cpp index 75a5aa88d68..16e08b52ed3 100644 --- a/src/server/scripts/Commands/cs_tele.cpp +++ b/src/server/scripts/Commands/cs_tele.cpp @@ -35,6 +35,8 @@ EndScriptData */ #include "RBAC.h" #include "WorldSession.h" +using namespace Trinity::ChatCommands; + class tele_commandscript : public CommandScript { public: @@ -57,17 +59,12 @@ public: return commandTable; } - static bool HandleTeleAddCommand(ChatHandler* handler, char const* args) + static bool HandleTeleAddCommand(ChatHandler* handler, std::string const& name) { - if (!*args) - return false; - Player* player = handler->GetSession()->GetPlayer(); if (!player) return false; - std::string name = args; - if (sObjectMgr->GetGameTeleExactName(name)) { handler->SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST); @@ -97,13 +94,8 @@ public: return true; } - static bool HandleTeleDelCommand(ChatHandler* handler, char const* args) + static bool HandleTeleDelCommand(ChatHandler* handler, GameTele const* tele) { - if (!*args) - return false; - - // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r - GameTele const* tele = handler->extractGameTeleFromLink((char*)args); if (!tele) { handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND); @@ -210,10 +202,14 @@ public: } //Teleport group to given game_tele.entry - static bool HandleTeleGroupCommand(ChatHandler* handler, char const* args) + static bool HandleTeleGroupCommand(ChatHandler* handler, GameTele const* tele) { - if (!*args) + if (!tele) + { + handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND); + handler->SetSentErrorMessage(true); return false; + } Player* target = handler->getSelectedPlayer(); if (!target) @@ -227,15 +223,6 @@ public: if (handler->HasLowerSecurity(target, ObjectGuid::Empty)) return false; - // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r - GameTele const* tele = handler->extractGameTeleFromLink((char*)args); - if (!tele) - { - handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND); - handler->SetSentErrorMessage(true); - return false; - } - MapEntry const* map = sMapStore.LookupEntry(tele->mapId); if (!map || map->IsBattlegroundOrArena()) { @@ -289,15 +276,8 @@ public: return true; } - static bool HandleTeleCommand(ChatHandler* handler, char const* args) + static bool HandleTeleCommand(ChatHandler* handler, GameTele const* tele) { - if (!*args) - return false; - - Player* player = handler->GetSession()->GetPlayer(); - - // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r - GameTele const* tele = handler->extractGameTeleFromLink((char*)args); if (!tele) { handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND); @@ -305,6 +285,7 @@ public: return false; } + Player* player = handler->GetSession()->GetPlayer(); if (player->IsInCombat() && !handler->GetSession()->HasPermission(rbac::RBAC_PERM_COMMAND_TELE_NAME)) { handler->SendSysMessage(LANG_YOU_IN_COMBAT); |
