From 861f114d5d9c69aa470ac4a5e5b14482ac204242 Mon Sep 17 00:00:00 2001 From: Aokromes Date: Sun, 2 Sep 2018 21:45:47 +0200 Subject: [PATCH] Scripts/Commands: New command ".go instance". Goes to an instance. --- sql/base/auth_database.sql | 4 +- sql/updates/auth/3.3.5/2018_08_30_00_auth.sql | 9 ++ .../world/3.3.5/2018_08_30_02_world.sql | 6 + src/server/game/Accounts/RBAC.h | 2 + src/server/game/Globals/ObjectMgr.h | 1 + src/server/scripts/Commands/cs_go.cpp | 117 ++++++++++++++++++ 6 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 sql/updates/auth/3.3.5/2018_08_30_00_auth.sql create mode 100644 sql/updates/world/3.3.5/2018_08_30_02_world.sql diff --git a/sql/base/auth_database.sql b/sql/base/auth_database.sql index 0b6235f8205..602e149417d 100644 --- a/sql/base/auth_database.sql +++ b/sql/base/auth_database.sql @@ -1036,6 +1036,7 @@ INSERT INTO `rbac_linked_permissions` VALUES (198,317), (198,318), (198,855), +(198,874), (198,367), (198,368), (198,369), @@ -1831,7 +1832,8 @@ INSERT INTO `rbac_permissions` VALUES (865,'Command: npc showloot'), (866,'Command: list spawnpoints'), (867,'Command: reload quest_greeting_locale'), -(872,'Command: server debug'); +(872,'Command: server debug'), +(874,'Command: go instance'); /*!40000 ALTER TABLE `rbac_permissions` ENABLE KEYS */; UNLOCK TABLES; diff --git a/sql/updates/auth/3.3.5/2018_08_30_00_auth.sql b/sql/updates/auth/3.3.5/2018_08_30_00_auth.sql new file mode 100644 index 00000000000..d5f59238bb1 --- /dev/null +++ b/sql/updates/auth/3.3.5/2018_08_30_00_auth.sql @@ -0,0 +1,9 @@ +-- +DELETE FROM `rbac_permissions` WHERE `id`=874; +INSERT INTO `rbac_permissions` (`id`,`name`) VALUES +(874, "Command: go instance"); + + SET @parent := (SELECT `id` FROM `rbac_linked_permissions` WHERE `linkedId`=852); +DELETE FROM `rbac_linked_permissions` WHERE `linkedId`=874; +INSERT INTO `rbac_linked_permissions` (`id`,`linkedId`) VALUES +(@parent, 874); diff --git a/sql/updates/world/3.3.5/2018_08_30_02_world.sql b/sql/updates/world/3.3.5/2018_08_30_02_world.sql new file mode 100644 index 00000000000..d8b3b9c4b10 --- /dev/null +++ b/sql/updates/world/3.3.5/2018_08_30_02_world.sql @@ -0,0 +1,6 @@ +-- +DELETE FROM `command` WHERE `name`="go instance"; +INSERT INTO `command` (`name`,`permission`,`help`) VALUES +('go instance', 874, 'Syntax: .go instance [mapid | name] + +Teleports you to entrance of instance with script name matching input (or given mapid)'); diff --git a/src/server/game/Accounts/RBAC.h b/src/server/game/Accounts/RBAC.h index 12f86edd6d8..01066b92dbd 100644 --- a/src/server/game/Accounts/RBAC.h +++ b/src/server/game/Accounts/RBAC.h @@ -771,6 +771,8 @@ enum RBACPermissions RBAC_PERM_COMMAND_DEBUG_THREATINFO = 870, RBAC_PERM_COMMAND_DEBUG_INSTANCESPAWN = 871, RBAC_PERM_COMMAND_SERVER_DEBUG = 872, + RBAC_PERM_COMMAND_RELOAD_CREATURE_MOVEMENT_OVERRIDE = 873, + RBAC_PERM_COMMAND_GO_INSTANCE = 874, // // IF YOU ADD NEW PERMISSIONS, ADD THEM IN MASTER BRANCH AS WELL! // diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 82b6b7bc4b0..fa85d98ed6d 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -943,6 +943,7 @@ class TC_GAME_API ObjectMgr ItemTemplate const* GetItemTemplate(uint32 entry) const; ItemTemplateContainer const* GetItemTemplateStore() const { return &_itemTemplateStore; } + InstanceTemplateContainer const& GetInstanceTemplates() const { return _instanceTemplateStore; } InstanceTemplate const* GetInstanceTemplate(uint32 mapId) const; PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint8 level) const; diff --git a/src/server/scripts/Commands/cs_go.cpp b/src/server/scripts/Commands/cs_go.cpp index cae3e1a5fac..557ddfb3452 100644 --- a/src/server/scripts/Commands/cs_go.cpp +++ b/src/server/scripts/Commands/cs_go.cpp @@ -55,6 +55,7 @@ public: { "xyz", rbac::RBAC_PERM_COMMAND_GO_XYZ, false, &HandleGoXYZCommand, "" }, { "ticket", rbac::RBAC_PERM_COMMAND_GO_TICKET, false, &HandleGoTicketCommand, "" }, { "offset", rbac::RBAC_PERM_COMMAND_GO_OFFSET, false, &HandleGoOffsetCommand, "" }, + { "instance", rbac::RBAC_PERM_COMMAND_GO_INSTANCE, false, &HandleGoInstanceCommand, "" } }; static std::vector commandTable = @@ -596,6 +597,122 @@ public: player->TeleportTo(player->GetMapId(), x, y, z, o); return true; } + + static bool HandleGoInstanceCommand(ChatHandler* handler, char const* args) + { + if (!*args) + return false; + + std::vector labels; + + // tokenize and convert to lowercase + char* pos = const_cast(args); + char* last = nullptr; + do + { + if (*pos == ' ') + { + if (last) + { + *pos = '\0'; + labels.emplace_back(last); + last = nullptr; + } + } + else + { + if (!last) + last = pos; + *pos = tolower(*pos); + } + } while (*++pos); + if (last) + labels.emplace_back(last); + // tokenizing done + + uint32 mapid = 0; + if (labels.size() == 1) + { + try { mapid = std::stoi(labels[0]); } + catch (...) {} + } + + if (!mapid) + { + std::multimap> matches; + for (auto const& pair : sObjectMgr->GetInstanceTemplates()) + { + uint32 count = 0; + std::string const& scriptName = sObjectMgr->GetScriptName(pair.second.ScriptId); + for (std::string 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("No matches found for your input"); + return false; + } + auto it = matches.rbegin(); + uint32 maxCount = it->first; + mapid = it->second.first; + if (++it != matches.rend() && it->first == maxCount) + { + handler->SendSysMessage("Multiple matches found for your input - please specify:"); + --it; + do + handler->PSendSysMessage("* Map %03u: '%s'", it->second.first, it->second.second); + while (++it != matches.rend() && it->first == maxCount); + handler->SetSentErrorMessage(true); + return false; + } + } + + ASSERT(mapid); + + InstanceTemplate const* temp = sObjectMgr->GetInstanceTemplate(mapid); + if (!temp) + { + handler->PSendSysMessage("Map %u is not instanced", mapid); + handler->SetSentErrorMessage(true); + return false; + } + std::string const& scriptname = sObjectMgr->GetScriptName(temp->ScriptId); + + AreaTrigger const* entrance = sObjectMgr->GetMapEntranceTrigger(mapid); + if (!entrance) + { + handler->PSendSysMessage("Could not find entrance for instance %u (%s)", mapid, scriptname); + handler->SetSentErrorMessage(true); + return false; + } + + Player* player = handler->GetSession()->GetPlayer(); + if (player->IsInFlight()) + player->FinishTaxiFlight(); + else + player->SaveRecallPosition(); + + if (player->TeleportTo(entrance->target_mapId, entrance->target_X, entrance->target_Y, entrance->target_Z, entrance->target_Orientation)) + handler->PSendSysMessage("Teleported you to entrance of mapid %u (%s)", mapid, scriptname); + else + { + AreaTrigger const* exit = sObjectMgr->GetGoBackTrigger(mapid); + if (player->TeleportTo(exit->target_mapId, exit->target_X, exit->target_Y, exit->target_Z, exit->target_Orientation + M_PI)) + handler->PSendSysMessage("Teleported you in front of entrance to mapid %u (%s)", mapid, scriptname); + else + { + handler->PSendSysMessage("Failed to teleport you to entrance of mapid %u (%s) - missing attunement/expansion for parent map?", mapid, scriptname); + handler->SetSentErrorMessage(true); + return false; + } + } + + return true; + } }; void AddSC_go_commandscript()