/* * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information * * 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 . */ /* ScriptData Name: titles_commandscript %Complete: 100 Comment: All titles related commands Category: commandscripts EndScriptData */ #include "ScriptMgr.h" #include "Chat.h" #include "ChatCommand.h" #include "DB2Stores.h" #include "Language.h" #include "Player.h" #include "RBAC.h" #if TRINITY_COMPILER == TRINITY_COMPILER_GNU #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif class titles_commandscript : public CommandScript { public: titles_commandscript() : CommandScript("titles_commandscript") { } std::vector GetCommands() const override { static std::vector titlesSetCommandTable = { { "mask", rbac::RBAC_PERM_COMMAND_TITLES_SET_MASK, false, &HandleTitlesSetMaskCommand, "" }, }; static std::vector titlesCommandTable = { { "add", rbac::RBAC_PERM_COMMAND_TITLES_ADD, false, &HandleTitlesAddCommand, "" }, { "current", rbac::RBAC_PERM_COMMAND_TITLES_CURRENT, false, &HandleTitlesCurrentCommand, "" }, { "remove", rbac::RBAC_PERM_COMMAND_TITLES_REMOVE, false, &HandleTitlesRemoveCommand, "" }, { "set", rbac::RBAC_PERM_COMMAND_TITLES_SET, false, nullptr, "", titlesSetCommandTable }, }; static std::vector commandTable = { { "titles", rbac::RBAC_PERM_COMMAND_TITLES, false, nullptr, "", titlesCommandTable }, }; return commandTable; } static bool HandleTitlesCurrentCommand(ChatHandler* handler, char const* args) { // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r char* id_p = handler->extractKeyFromLink((char*)args, "Htitle"); if (!id_p) return false; uint32 id = atoul(id_p); if (id == 0) { handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id); handler->SetSentErrorMessage(true); return false; } Player* target = handler->getSelectedPlayer(); if (!target) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } // check online security if (handler->HasLowerSecurity(target, ObjectGuid::Empty)) return false; CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id); if (!titleInfo) { handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id); handler->SetSentErrorMessage(true); return false; } std::string tNameLink = handler->GetNameLink(target); target->SetTitle(titleInfo); // to be sure that title now known target->SetChosenTitle(titleInfo->MaskID); handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, id, (target->GetNativeGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[handler->GetSessionDbcLocale()], tNameLink.c_str()); return true; } static bool HandleTitlesAddCommand(ChatHandler* handler, char const* args) { // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r char* id_p = handler->extractKeyFromLink((char*)args, "Htitle"); if (!id_p) return false; uint32 id = atoul(id_p); if (id == 0) { handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id); handler->SetSentErrorMessage(true); return false; } Player* target = handler->getSelectedPlayer(); if (!target) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } // check online security if (handler->HasLowerSecurity(target, ObjectGuid::Empty)) return false; CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id); if (!titleInfo) { handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id); handler->SetSentErrorMessage(true); return false; } std::string tNameLink = handler->GetNameLink(target); std::string titleNameStr = Trinity::StringFormat( (target->GetNativeGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[handler->GetSessionDbcLocale()], target->GetName().c_str() ); target->SetTitle(titleInfo); handler->PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr.c_str(), tNameLink.c_str()); return true; } static bool HandleTitlesRemoveCommand(ChatHandler* handler, char const* args) { // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r char* id_p = handler->extractKeyFromLink((char*)args, "Htitle"); if (!id_p) return false; uint32 id = atoul(id_p); if (id == 0) { handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id); handler->SetSentErrorMessage(true); return false; } Player* target = handler->getSelectedPlayer(); if (!target) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } // check online security if (handler->HasLowerSecurity(target, ObjectGuid::Empty)) return false; CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id); if (!titleInfo) { handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id); handler->SetSentErrorMessage(true); return false; } target->SetTitle(titleInfo, true); std::string tNameLink = handler->GetNameLink(target); std::string titleNameStr = Trinity::StringFormat( (target->GetNativeGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[handler->GetSessionDbcLocale()], target->GetName().c_str() ); handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr.c_str(), tNameLink.c_str()); if (!target->HasTitle(target->m_playerData->PlayerTitle)) { target->SetChosenTitle(0); handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink.c_str()); } return true; } //Edit Player KnownTitles static bool HandleTitlesSetMaskCommand(ChatHandler* handler, char const* args) { if (!*args) return false; uint64 titles = 0; sscanf((char*)args, UI64FMTD, &titles); Player* target = handler->getSelectedPlayer(); if (!target) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } // check online security if (handler->HasLowerSecurity(target, ObjectGuid::Empty)) return false; uint64 titles2 = titles; for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i) if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i)) titles2 &= ~(uint64(1) << tEntry->MaskID); titles &= ~titles2; // remove non-existing titles target->SetKnownTitles(0, titles); handler->SendSysMessage(LANG_DONE); if (!target->HasTitle(target->m_playerData->PlayerTitle)) { target->SetChosenTitle(0); handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, handler->GetNameLink(target).c_str()); } return true; } }; void AddSC_titles_commandscript() { new titles_commandscript(); }