diff --git a/data/sql/updates/pending_db_world/rev_1575409612123583009.sql b/data/sql/updates/pending_db_world/rev_1575409612123583009.sql new file mode 100644 index 000000000..84dac16dc --- /dev/null +++ b/data/sql/updates/pending_db_world/rev_1575409612123583009.sql @@ -0,0 +1,7 @@ +INSERT INTO `version_db_world` (`sql_rev`) VALUES ('1575409612123583009'); + +DELETE FROM `command` WHERE `name` IN ('player learn','player unlearn'); +INSERT INTO `command` (`name`, `security`, `help`) +VALUES +('player learn',2,'Syntax: .player learn #playername #spell [all].'), +('player unlearn',2,'Syntax: .player unlearn #playername #spell [all].'); diff --git a/src/server/scripts/Commands/CMakeLists.txt b/src/server/scripts/Commands/CMakeLists.txt index 07e8208e6..0007a4a1c 100644 --- a/src/server/scripts/Commands/CMakeLists.txt +++ b/src/server/scripts/Commands/CMakeLists.txt @@ -10,6 +10,7 @@ set(scripts_STAT_SRCS ${scripts_STAT_SRCS} + Commands/PlayerCommand.cpp Commands/cs_account.cpp Commands/cs_achievement.cpp Commands/cs_arena.cpp @@ -46,6 +47,7 @@ set(scripts_STAT_SRCS Commands/cs_titles.cpp Commands/cs_wp.cpp Commands/cs_spectator.cpp + Commands/cs_player.cpp # Commands/cs_pdump.cpp # Commands/cs_channel.cpp # Commands/cs_pet.cpp diff --git a/src/server/scripts/Commands/PlayerCommand.cpp b/src/server/scripts/Commands/PlayerCommand.cpp new file mode 100644 index 000000000..135fee773 --- /dev/null +++ b/src/server/scripts/Commands/PlayerCommand.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 +*/ + +#include "Chat.h" +#include "ScriptMgr.h" +#include "Language.h" +#include "Player.h" +#include "PlayerCommand.h" + +bool PlayerCommand::Learn(ChatHandler* handler, Player* targetPlayer, uint32 spell, char const* all) +{ + if (!spell) + return false; + + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell); + if (!spellInfo) + { + handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND); + handler->SetSentErrorMessage(true); + return false; + } + + if (!SpellMgr::IsSpellValid(spellInfo)) + { + handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell); + handler->SetSentErrorMessage(true); + return false; + } + + if (handler->GetSession()) + { + SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell); + uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell); + if (handler->GetSession() && handler->GetSession()->GetSecurity() < SEC_ADMINISTRATOR && (bounds.first != bounds.second || spellDifficultyId)) + { + handler->PSendSysMessage("Spell %u cannot be learnt using a command!", spell); + handler->SetSentErrorMessage(true); + return false; + } + } + + bool allRanks = all ? (strncmp(all, "all", 3) == 0) : false; + + if (!allRanks && targetPlayer->HasSpell(spell)) + { + if (targetPlayer == handler->GetSession()->GetPlayer()) + handler->SendSysMessage(LANG_YOU_KNOWN_SPELL); + else + handler->PSendSysMessage(LANG_TARGET_KNOWN_SPELL, handler->GetNameLink(targetPlayer).c_str()); + handler->SetSentErrorMessage(true); + return false; + } + + if (allRanks) + targetPlayer->learnSpellHighRank(spell); + else + targetPlayer->learnSpell(spell); + + uint32 firstSpell = sSpellMgr->GetFirstSpellInChain(spell); + if (GetTalentSpellCost(firstSpell)) + targetPlayer->SendTalentsInfoData(false); + + return true; +} + +bool PlayerCommand::UnLearn(ChatHandler* handler, Player* target, uint32 spellId, char const* allStr) +{ + if (!spellId) + return false; + + bool allRanks = allStr ? (strncmp(allStr, "all", 3) == 0) : false; + + if (allRanks) + spellId = sSpellMgr->GetFirstSpellInChain (spellId); + + if (target->HasSpell(spellId)) + target->removeSpell(spellId, SPEC_MASK_ALL, false); + else + handler->SendSysMessage(LANG_FORGET_SPELL); + + if (GetTalentSpellCost(spellId)) + target->SendTalentsInfoData(false); + + return true; +} diff --git a/src/server/scripts/Commands/PlayerCommand.h b/src/server/scripts/Commands/PlayerCommand.h new file mode 100644 index 000000000..6ee945f8b --- /dev/null +++ b/src/server/scripts/Commands/PlayerCommand.h @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 +*/ + +class PlayerCommand +{ +public: + static bool Learn(ChatHandler* handler, Player* targetPlayer, uint32 spell, char const* all); + static bool UnLearn(ChatHandler* handler, Player* targetPlayer, uint32 spell, char const* all); +}; diff --git a/src/server/scripts/Commands/cs_learn.cpp b/src/server/scripts/Commands/cs_learn.cpp index fd9575059..261d4a49f 100644 --- a/src/server/scripts/Commands/cs_learn.cpp +++ b/src/server/scripts/Commands/cs_learn.cpp @@ -19,8 +19,9 @@ EndScriptData */ #include "SpellInfo.h" #include "Player.h" #include "Pet.h" +#include "PlayerCommand.h" -class learn_commandscript : public CommandScript +class learn_commandscript : public CommandScript, public PlayerCommand { public: learn_commandscript() : CommandScript("learn_commandscript") { } @@ -37,7 +38,7 @@ public: static std::vector learnAllCommandTable = { - { "my", SEC_GAMEMASTER, false, nullptr, "", learnAllMyCommandTable }, + { "my", SEC_GAMEMASTER, false, nullptr, "", learnAllMyCommandTable }, { "gm", SEC_GAMEMASTER, false, &HandleLearnAllGMCommand, "" }, { "crafts", SEC_GAMEMASTER, false, &HandleLearnAllCraftsCommand, "" }, { "default", SEC_GAMEMASTER, false, &HandleLearnAllDefaultCommand, "" }, @@ -47,13 +48,13 @@ public: static std::vector learnCommandTable = { - { "all", SEC_GAMEMASTER, false, nullptr, "", learnAllCommandTable }, + { "all", SEC_GAMEMASTER, false, nullptr, "", learnAllCommandTable }, { "", SEC_GAMEMASTER, false, &HandleLearnCommand, "" } }; static std::vector commandTable = { - { "learn", SEC_GAMEMASTER, false, nullptr, "", learnCommandTable }, + { "learn", SEC_GAMEMASTER, false, nullptr, "", learnCommandTable }, { "unlearn", SEC_GAMEMASTER, false, &HandleUnLearnCommand, "" } }; return commandTable; @@ -61,6 +62,9 @@ public: static bool HandleLearnCommand(ChatHandler* handler, char const* args) { + if (!*args) + return false; + Player* targetPlayer = handler->getSelectedPlayer(); if (!targetPlayer) @@ -72,56 +76,8 @@ public: // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spell = handler->extractSpellIdFromLink((char*)args); - if (!spell) - return false; - - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell); - if (!spellInfo) - { - handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND); - handler->SetSentErrorMessage(true); - return false; - } - - if (!SpellMgr::IsSpellValid(spellInfo)) - { - handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell); - handler->SetSentErrorMessage(true); - return false; - } - - SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell); - uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell); - if (handler->GetSession()->GetSecurity() < SEC_ADMINISTRATOR && (bounds.first != bounds.second || spellDifficultyId)) - { - handler->PSendSysMessage("Spell %u cannot be learnt using a command!", spell); - handler->SetSentErrorMessage(true); - return false; - } - char const* all = strtok(nullptr, " "); - bool allRanks = all ? (strncmp(all, "all", strlen(all)) == 0) : false; - - if (!allRanks && targetPlayer->HasSpell(spell)) - { - if (targetPlayer == handler->GetSession()->GetPlayer()) - handler->SendSysMessage(LANG_YOU_KNOWN_SPELL); - else - handler->PSendSysMessage(LANG_TARGET_KNOWN_SPELL, handler->GetNameLink(targetPlayer).c_str()); - handler->SetSentErrorMessage(true); - return false; - } - - if (allRanks) - targetPlayer->learnSpellHighRank(spell); - else - targetPlayer->learnSpell(spell); - - uint32 firstSpell = sSpellMgr->GetFirstSpellInChain(spell); - if (GetTalentSpellCost(firstSpell)) - targetPlayer->SendTalentsInfoData(false); - - return true; + return Learn(handler, targetPlayer, spell, all); } static bool HandleLearnAllGMCommand(ChatHandler* handler, char const* /*args*/) @@ -476,14 +432,6 @@ public: if (!*args) return false; - // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r - uint32 spellId = handler->extractSpellIdFromLink((char*)args); - if (!spellId) - return false; - - char const* allStr = strtok(nullptr, " "); - bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false; - Player* target = handler->getSelectedPlayer(); if (!target) { @@ -492,18 +440,10 @@ public: return false; } - if (allRanks) - spellId = sSpellMgr->GetFirstSpellInChain (spellId); - - if (target->HasSpell(spellId)) - target->removeSpell(spellId, SPEC_MASK_ALL, false); - else - handler->SendSysMessage(LANG_FORGET_SPELL); - - if (GetTalentSpellCost(spellId)) - target->SendTalentsInfoData(false); - - return true; + // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r + uint32 spellId = handler->extractSpellIdFromLink((char*)args); + char const* allStr = strtok(nullptr, " "); + return UnLearn(handler, target, spellId, allStr); } }; diff --git a/src/server/scripts/Commands/cs_player.cpp b/src/server/scripts/Commands/cs_player.cpp new file mode 100644 index 000000000..9e455e159 --- /dev/null +++ b/src/server/scripts/Commands/cs_player.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 +*/ + +#include "Chat.h" +#include "ScriptMgr.h" +#include "Language.h" +#include "Player.h" +#include "PlayerCommand.h" + +class player_commandscript : public CommandScript, public PlayerCommand +{ +public: + player_commandscript() : CommandScript("player_commandscript") { } + + std::vector GetCommands() const override + { + static std::vector playerCommandTable = + { + { "learn", SEC_GAMEMASTER, true, &HandlePlayerLearnCommand, "" }, + { "unlearn", SEC_GAMEMASTER, true, &HandlePlayerUnLearnCommand, "" } + }; + + static std::vector commandTable = + { + { "player", SEC_GAMEMASTER, true, nullptr, "", playerCommandTable } + }; + return commandTable; + } + + static bool HandlePlayerLearnCommand(ChatHandler* handler, char const* args) + { + if (!*args) + return false; + + char* playerName = strtok((char*)args, " "); + char* spellid = strtok(nullptr, " "); + char const* all = strtok(nullptr, " "); + Player* targetPlayer = FindPlayer(handler, playerName); + if (!spellid || !targetPlayer) + return false; + + uint32 spell = handler->extractSpellIdFromLink(spellid); + if (!spell) + return false; + + return Learn(handler, targetPlayer, spell, all); + } + + static bool HandlePlayerUnLearnCommand(ChatHandler* handler, char const* args) + { + if (!*args) + return false; + + char* playerName = strtok((char*)args, " "); + char* spellid = strtok(nullptr, " "); + char const* all = strtok(nullptr, " "); + Player* targetPlayer = FindPlayer(handler, playerName); + if (!spellid || !targetPlayer) + return false; + + uint32 spell = handler->extractSpellIdFromLink(spellid); + if (!spell) + return false; + + return UnLearn(handler, targetPlayer, spell, all); + } + +private: + static Player* FindPlayer(ChatHandler* handler, char* playerName) + { + if (!playerName) + return nullptr; + + Player* targetPlayer; + if (!handler->extractPlayerTarget(playerName, &targetPlayer)) + return nullptr; + + if (!targetPlayer) + { + handler->SendSysMessage(LANG_PLAYER_NOT_FOUND); + handler->SetSentErrorMessage(true); + return nullptr; + } + + return targetPlayer; + } +}; + +void AddSC_player_commandscript() +{ + new player_commandscript(); +} diff --git a/src/server/scripts/ScriptLoader.cpp b/src/server/scripts/ScriptLoader.cpp index 3e9862d59..3fb43d1fe 100644 --- a/src/server/scripts/ScriptLoader.cpp +++ b/src/server/scripts/ScriptLoader.cpp @@ -62,6 +62,7 @@ void AddSC_tele_commandscript(); void AddSC_ticket_commandscript(); void AddSC_titles_commandscript(); void AddSC_wp_commandscript(); +void AddSC_player_commandscript(); #ifdef SCRIPTS //world @@ -613,7 +614,7 @@ void AddCommandScripts() AddSC_character_commandscript(); AddSC_cheat_commandscript(); AddSC_debug_commandscript(); - AddSC_deserter_commandscript(); + AddSC_deserter_commandscript(); AddSC_disable_commandscript(); AddSC_event_commandscript(); AddSC_gm_commandscript(); @@ -639,6 +640,7 @@ void AddCommandScripts() AddSC_ticket_commandscript(); AddSC_titles_commandscript(); AddSC_wp_commandscript(); + AddSC_player_commandscript(); } void AddWorldScripts()