refactor(Scripts/Commands): Convert commands to new system Part 1 (#8704)

This commit is contained in:
IntelligentQuantum
2021-10-29 22:28:59 +03:30
committed by GitHub
parent 67b3ac442a
commit fe682805ab
7 changed files with 338 additions and 397 deletions

View File

@@ -15,78 +15,90 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file cs_deserter.cpp
* @brief .deserter related commands
*
* This file contains the CommandScripts for all deserter sub-commands
*/
#include "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "SpellAuraEffects.h"
#include "SpellAuras.h"
using namespace Acore::ChatCommands;
enum Spells
{
LFG_SPELL_DUNGEON_DESERTER = 71041,
BG_SPELL_DESERTER = 26013
};
#if AC_COMPILER == AC_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
using namespace Acore::ChatCommands;
class deserter_commandscript : public CommandScript
{
public:
deserter_commandscript() : CommandScript("deserter_commandscript") { }
/**
* @brief Returns the command structure for the system.
*/
ChatCommandTable GetCommands() const override
{
static ChatCommandTable deserterinstanceCommandTable =
static ChatCommandTable deserterInstanceCommandTable =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleDeserterInstanceAdd, "" },
{ "remove", SEC_ADMINISTRATOR, false, &HandleDeserterInstanceRemove, "" }
{ "add", HandleDeserterInstanceAdd, SEC_ADMINISTRATOR, Console::No },
{ "remove", HandleDeserterInstanceRemove, SEC_ADMINISTRATOR, Console::No }
};
static ChatCommandTable deserterBGCommandTable =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleDeserterBGAdd, "" },
{ "remove", SEC_ADMINISTRATOR, false, &HandleDeserterBGRemove, "" }
{ "add", HandleDeserterBGAdd, SEC_ADMINISTRATOR, Console::No },
{ "remove", HandleDeserterBGRemove, SEC_ADMINISTRATOR, Console::No }
};
static ChatCommandTable deserterCommandTable =
{
{ "instance", SEC_ADMINISTRATOR, false, nullptr, "", deserterinstanceCommandTable },
{ "bg", SEC_ADMINISTRATOR, false, nullptr, "", deserterBGCommandTable }
{ "instance", deserterInstanceCommandTable },
{ "bg", deserterBGCommandTable }
};
static ChatCommandTable commandTable =
{
{ "deserter", SEC_ADMINISTRATOR, false, nullptr, "", deserterCommandTable }
{ "deserter", deserterCommandTable }
};
return commandTable;
}
static bool HandleDeserterAdd(ChatHandler* handler, char const* args, bool isInstance)
/**
* @brief Applies the Deserter Debuff to a player
*
* This function applies a Deserter Debuff of the given type (Instance or BG) to the
* selected player, with the provided duration in seconds.
*
* @param handler The ChatHandler, passed by the system.
* @param time The provided duration in seconds.
* @param isInstance provided by the relaying functions, so we don't have
* to write that much code :)
*
* @return true if everything was correct, false if an error occured.
*
* Example Usage:
* @code
* .deserter instance add 3600 (one hour)
* -or-
* .deserter bg add 3600 (one hour)
* @endcode
*/
static bool HandleDeserterAdd(ChatHandler* handler, uint32 time, bool isInstance)
{
if (!*args)
return false;
Player* targetPlayer = handler->getSelectedPlayer();
if (!targetPlayer)
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
char* timeStr = strtok((char*)args, " ");
if (!timeStr)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
uint32 time = atoi(timeStr);
if (!time)
{
@@ -95,7 +107,7 @@ public:
return false;
}
Aura* aura = targetPlayer->AddAura(isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER, targetPlayer);
Aura* aura = player->AddAura(isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER, player);
if (!aura)
{
@@ -108,39 +120,62 @@ public:
return true;
}
static bool HandleDeserterRemove(ChatHandler* handler, char const* /*args*/, bool isInstance)
/**
* @brief Removes the Deserter Debuff from a player
*
* This function removes a Deserter Debuff of the given type (Instance or BG) from the
* selected player.
*
* @param handler The ChatHandler, passed by the system.
* @param isInstance provided by the relaying functions, so we don't have
* to write that much code :)
*
* @return true if everything was correct, false if an error occured.
*
* Example Usage:
* @code
* .deserter instance remove
* -or-
* .deserter bg remove
* @endcode
*/
static bool HandleDeserterRemove(ChatHandler* handler, bool isInstance)
{
Player* targetPlayer = handler->getSelectedPlayer();
if (!targetPlayer)
Player* player = handler->getSelectedPlayer();
if (!player)
{
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
handler->SetSentErrorMessage(true);
return false;
}
targetPlayer->RemoveAura(isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER);
player->RemoveAura(isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER);
return true;
}
static bool HandleDeserterInstanceAdd(ChatHandler* handler, char const* args)
/// @sa HandleDeserterAdd()
static bool HandleDeserterInstanceAdd(ChatHandler* handler, uint32 time)
{
return HandleDeserterAdd(handler, args, true);
return HandleDeserterAdd(handler, time, true);
}
static bool HandleDeserterBGAdd(ChatHandler* handler, char const* args)
/// @sa HandleDeserterAdd()
static bool HandleDeserterBGAdd(ChatHandler* handler, uint32 time)
{
return HandleDeserterAdd(handler, args, false);
return HandleDeserterAdd(handler, time, false);
}
static bool HandleDeserterInstanceRemove(ChatHandler* handler, char const* args)
/// @sa HandleDeserterRemove()
static bool HandleDeserterInstanceRemove(ChatHandler* handler)
{
return HandleDeserterRemove(handler, args, true);
return HandleDeserterRemove(handler, true);
}
static bool HandleDeserterBGRemove(ChatHandler* handler, char const* args)
/// @sa HandleDeserterRemove()
static bool HandleDeserterBGRemove(ChatHandler* handler)
{
return HandleDeserterRemove(handler, args, false);
return HandleDeserterRemove(handler, false);
}
};

View File

@@ -22,19 +22,17 @@ Comment: All gm related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "AccountMgr.h"
#include "Chat.h"
#include "DatabaseEnv.h"
#include "Language.h"
#include "ObjectMgr.h"
#include "ObjectAccessor.h"
#include "Opcodes.h"
#include "Player.h"
#include "Realm.h"
#include "ScriptMgr.h"
#include "World.h"
#if AC_COMPILER == AC_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#include "WorldSession.h"
using namespace Acore::ChatCommands;
@@ -47,47 +45,47 @@ public:
{
static ChatCommandTable gmCommandTable =
{
{ "chat", SEC_GAMEMASTER, false, &HandleGMChatCommand, "" },
{ "fly", SEC_GAMEMASTER, false, &HandleGMFlyCommand, "" },
{ "ingame", SEC_PLAYER, true, &HandleGMListIngameCommand, "" },
{ "list", SEC_GAMEMASTER, true, &HandleGMListFullCommand, "" },
{ "visible", SEC_GAMEMASTER, false, &HandleGMVisibleCommand, "" },
{ "", SEC_MODERATOR, false, &HandleGMCommand, "" }
{ "chat", HandleGMChatCommand, SEC_GAMEMASTER, Console::No },
{ "fly", HandleGMFlyCommand, SEC_GAMEMASTER, Console::No },
{ "ingame", HandleGMListIngameCommand, SEC_PLAYER, Console::Yes },
{ "list", HandleGMListFullCommand, SEC_GAMEMASTER, Console::Yes },
{ "visible", HandleGMVisibleCommand, SEC_GAMEMASTER, Console::No },
{ "on", HandleGMOnCommand, SEC_GAMEMASTER, Console::No },
{ "off", HandleGMOffCommand, SEC_GAMEMASTER, Console::No }
};
static ChatCommandTable commandTable =
{
{ "gm", SEC_MODERATOR, false, nullptr, "", gmCommandTable }
{ "gm", gmCommandTable }
};
return commandTable;
}
// Enables or disables hiding of the staff badge
static bool HandleGMChatCommand(ChatHandler* handler, char const* args)
// Enables or disables the staff badge
static bool HandleGMChatCommand(ChatHandler* handler, Optional<bool> enableArg)
{
if (!*args)
if (WorldSession* session = handler->GetSession())
{
WorldSession* session = handler->GetSession();
if (!AccountMgr::IsPlayerAccount(session->GetSecurity()) && session->GetPlayer()->isGMChat())
if (!enableArg)
{
if (!AccountMgr::IsPlayerAccount(session->GetSecurity()) && session->GetPlayer()->isGMChat())
session->SendNotification(LANG_GM_CHAT_ON);
else
session->SendNotification(LANG_GM_CHAT_OFF);
return true;
}
if (*enableArg)
{
session->GetPlayer()->SetGMChat(true);
session->SendNotification(LANG_GM_CHAT_ON);
return true;
}
else
{
session->GetPlayer()->SetGMChat(false);
session->SendNotification(LANG_GM_CHAT_OFF);
return true;
}
std::string param = (char*)args;
if (param == "on")
{
handler->GetSession()->GetPlayer()->SetGMChat(true);
handler->GetSession()->SendNotification(LANG_GM_CHAT_ON);
return true;
}
if (param == "off")
{
handler->GetSession()->GetPlayer()->SetGMChat(false);
handler->GetSession()->SendNotification(LANG_GM_CHAT_OFF);
return true;
return true;
}
}
handler->SendSysMessage(LANG_USE_BOL);
@@ -95,51 +93,37 @@ public:
return false;
}
static bool HandleGMFlyCommand(ChatHandler* handler, char const* args)
static bool HandleGMFlyCommand(ChatHandler* handler, bool enable)
{
if (!*args)
return false;
Player* target = handler->getSelectedPlayer();
if (!target || AccountMgr::IsGMAccount(handler->GetSession()->GetSecurity()))
Player* target = handler->getSelectedPlayer();
if (!target)
target = handler->GetSession()->GetPlayer();
WorldPacket data(12);
if (strncmp(args, "on", 3) == 0)
{
if (enable)
data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
sScriptMgr->AnticheatSetCanFlybyServer(target, true);
}
else if (strncmp(args, "off", 4) == 0)
{
data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
sScriptMgr->AnticheatSetCanFlybyServer(target, false);
}
else
{
handler->SendSysMessage(LANG_USE_BOL);
return false;
}
data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
data << target->GetPackGUID();
data << uint32(0); // unknown
target->SendMessageToSet(&data, true);
handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), args);
handler->SetSentErrorMessage(true);
return false;
handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), enable ? "on" : "off");
return true;
}
static bool HandleGMListIngameCommand(ChatHandler* handler, char const* /*args*/)
static bool HandleGMListIngameCommand(ChatHandler* handler)
{
bool first = true;
bool footer = false;
std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
HashMapHolder<Player>::MapType const& m = ObjectAccessor::GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
for (auto const& [playerGuid, player] : ObjectAccessor::GetPlayers())
{
AccountTypes itrSec = itr->second->GetSession()->GetSecurity();
if ((itr->second->IsGameMaster() || (!AccountMgr::IsPlayerAccount(itrSec) && itrSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
(!handler->GetSession() || itr->second->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
AccountTypes playerSec = player->GetSession()->GetSecurity();
if ((player->IsGameMaster() ||
(!AccountMgr::IsPlayerAccount(playerSec) && playerSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
(!handler->GetSession() || player->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
{
if (first)
{
@@ -148,9 +132,9 @@ public:
handler->SendSysMessage(LANG_GMS_ON_SRV);
handler->SendSysMessage("========================");
}
std::string const& name = itr->second->GetName();
uint8 size = name.size();
uint8 security = itrSec;
std::string const& name = player->GetName();
uint8 size = uint8(name.size());
uint8 security = playerSec;
uint8 max = ((16 - size) / 2);
uint8 max2 = max;
if ((max + max2 + size) == 16)
@@ -169,7 +153,7 @@ public:
}
/// Display the list of GMs
static bool HandleGMListFullCommand(ChatHandler* handler, char const* /*args*/)
static bool HandleGMListFullCommand(ChatHandler* handler)
{
///- Get the accounts with GM Level >0
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_GM_ACCOUNTS);
@@ -204,77 +188,52 @@ public:
}
//Enable\Disable Invisible mode
static bool HandleGMVisibleCommand(ChatHandler* handler, char const* args)
static bool HandleGMVisibleCommand(ChatHandler* handler, Optional<bool> visibleArg)
{
Player* _player = handler->GetSession()->GetPlayer();
if (!*args)
if (!visibleArg)
{
handler->PSendSysMessage(LANG_YOU_ARE, _player->isGMVisible() ? handler->GetAcoreString(LANG_VISIBLE) : handler->GetAcoreString(LANG_INVISIBLE));
handler->SetSentErrorMessage(true);
return false;
return true;
}
std::string param = (char*)args;
const uint32 VISUAL_AURA = 37800;
if (param == "on")
if (*visibleArg)
{
if (_player->HasAura(VISUAL_AURA))
_player->RemoveAurasDueToSpell(VISUAL_AURA);
_player->SetGMVisible(true);
//_player->UpdateObjectVisibility();
_player->UpdateObjectVisibility();
handler->GetSession()->SendNotification(LANG_INVISIBLE_VISIBLE);
handler->SetSentErrorMessage(true);
return false;
}
if (param == "off")
else
{
_player->AddAura(VISUAL_AURA, _player);
_player->SetGMVisible(false);
//_player->UpdateObjectVisibility();
_player->UpdateObjectVisibility();
handler->GetSession()->SendNotification(LANG_INVISIBLE_INVISIBLE);
handler->SetSentErrorMessage(true);
return false;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
return true;
}
//Enable\Disable GM Mode
static bool HandleGMCommand(ChatHandler* handler, char const* args)
static bool HandleGMOnCommand(ChatHandler* handler)
{
Player* _player = handler->GetSession()->GetPlayer();
handler->GetPlayer()->SetGameMaster(true);
handler->GetPlayer()->UpdateTriggerVisibility();
handler->GetSession()->SendNotification(LANG_GM_ON);
return true;
}
if (!*args)
{
handler->GetSession()->SendNotification(_player->IsGameMaster() ? LANG_GM_ON : LANG_GM_OFF);
handler->SetSentErrorMessage(true);
return false;
}
std::string param = (char*)args;
if (param == "on")
{
_player->SetGameMaster(true);
handler->GetSession()->SendNotification(LANG_GM_ON);
_player->UpdateTriggerVisibility();
handler->SetSentErrorMessage(true);
return false;
}
if (param == "off")
{
_player->SetGameMaster(false);
handler->GetSession()->SendNotification(LANG_GM_OFF);
_player->UpdateTriggerVisibility();
handler->SetSentErrorMessage(true);
return false;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
static bool HandleGMOffCommand(ChatHandler* handler)
{
handler->GetPlayer()->SetGameMaster(false);
handler->GetPlayer()->UpdateTriggerVisibility();
handler->GetSession()->SendNotification(LANG_GM_OFF);
return true;
}
};

View File

@@ -22,15 +22,11 @@ Comment: All honor related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
#if AC_COMPILER == AC_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#include "WorldSession.h"
using namespace Acore::ChatCommands;
@@ -43,28 +39,25 @@ public:
{
static ChatCommandTable honorAddCommandTable =
{
{ "kill", SEC_GAMEMASTER, false, &HandleHonorAddKillCommand, "" },
{ "", SEC_GAMEMASTER, false, &HandleHonorAddCommand, "" }
{ "kill", HandleHonorAddKillCommand, SEC_GAMEMASTER, Console::No },
{ "", HandleHonorAddCommand, SEC_GAMEMASTER, Console::No }
};
static ChatCommandTable honorCommandTable =
{
{ "add", SEC_GAMEMASTER, false, nullptr, "", honorAddCommandTable },
{ "update", SEC_GAMEMASTER, false, &HandleHonorUpdateCommand, "" }
{ "add", honorAddCommandTable },
{ "update", HandleHonorUpdateCommand, SEC_GAMEMASTER, Console::No }
};
static ChatCommandTable commandTable =
{
{ "honor", SEC_GAMEMASTER, false, nullptr, "", honorCommandTable }
{ "honor", honorCommandTable }
};
return commandTable;
}
static bool HandleHonorAddCommand(ChatHandler* handler, char const* args)
static bool HandleHonorAddCommand(ChatHandler* handler, uint32 amount)
{
if (!*args)
return false;
Player* target = handler->getSelectedPlayer();
if (!target)
{
@@ -74,15 +67,14 @@ public:
}
// check online security
if (handler->HasLowerSecurity(target))
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
return false;
uint32 amount = (uint32)atoi(args);
target->RewardHonor(nullptr, 1, amount);
return true;
}
static bool HandleHonorAddKillCommand(ChatHandler* handler, char const* /*args*/)
static bool HandleHonorAddKillCommand(ChatHandler* handler)
{
Unit* target = handler->getSelectedUnit();
if (!target)
@@ -93,14 +85,15 @@ public:
}
// check online security
if (target->GetTypeId() == TYPEID_PLAYER && handler->HasLowerSecurity(target->ToPlayer()))
return false;
if (Player* player = target->ToPlayer())
if (handler->HasLowerSecurity(player, ObjectGuid::Empty))
return false;
handler->GetSession()->GetPlayer()->RewardHonor(target, 1);
return true;
}
static bool HandleHonorUpdateCommand(ChatHandler* handler, char const* /*args*/)
static bool HandleHonorUpdateCommand(ChatHandler* handler)
{
Player* target = handler->getSelectedPlayer();
if (!target)
@@ -111,7 +104,7 @@ public:
}
// check online security
if (handler->HasLowerSecurity(target))
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
return false;
target->UpdateHonorFields();

View File

@@ -22,15 +22,18 @@ Comment: All message related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "Channel.h"
#include "ChannelMgr.h"
#include "Chat.h"
#include "DatabaseEnv.h"
#include "DBCStores.h"
#include "Language.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
#if AC_COMPILER == AC_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#include "World.h"
#include "WorldSession.h"
using namespace Acore::ChatCommands;
@@ -43,70 +46,71 @@ public:
{
static ChatCommandTable commandTable =
{
{ "nameannounce", SEC_GAMEMASTER, true, &HandleNameAnnounceCommand, "" },
{ "gmnameannounce", SEC_GAMEMASTER, true, &HandleGMNameAnnounceCommand, "" },
{ "announce", SEC_GAMEMASTER, true, &HandleAnnounceCommand, "" },
{ "gmannounce", SEC_GAMEMASTER, true, &HandleGMAnnounceCommand, "" },
{ "notify", SEC_GAMEMASTER, true, &HandleNotifyCommand, "" },
{ "gmnotify", SEC_GAMEMASTER, true, &HandleGMNotifyCommand, "" },
{ "whispers", SEC_MODERATOR, false, &HandleWhispersCommand, "" }
{ "nameannounce", HandleNameAnnounceCommand, SEC_GAMEMASTER, Console::Yes },
{ "gmnameannounce", HandleGMNameAnnounceCommand, SEC_GAMEMASTER, Console::Yes },
{ "announce", HandleAnnounceCommand, SEC_GAMEMASTER, Console::Yes },
{ "gmannounce", HandleGMAnnounceCommand, SEC_GAMEMASTER, Console::Yes },
{ "notify", HandleNotifyCommand, SEC_GAMEMASTER, Console::Yes },
{ "gmnotify", HandleGMNotifyCommand, SEC_GAMEMASTER, Console::Yes },
{ "whispers", HandleWhispersCommand, SEC_MODERATOR, Console::No },
};
return commandTable;
}
static bool HandleNameAnnounceCommand(ChatHandler* handler, char const* args)
static bool HandleNameAnnounceCommand(ChatHandler* handler, Tail message)
{
if (!*args)
if (message.empty())
return false;
std::string name("Console");
if (WorldSession* session = handler->GetSession())
name = session->GetPlayer()->GetName();
sWorld->SendWorldText(LANG_ANNOUNCE_COLOR, name.c_str(), args);
sWorld->SendWorldText(LANG_ANNOUNCE_COLOR, name.c_str(), message.data());
return true;
}
static bool HandleGMNameAnnounceCommand(ChatHandler* handler, char const* args)
static bool HandleGMNameAnnounceCommand(ChatHandler* handler, Tail message)
{
if (!*args)
if (message.empty())
return false;
std::string name("Console");
if (WorldSession* session = handler->GetSession())
name = session->GetPlayer()->GetName();
sWorld->SendGMText(LANG_GM_ANNOUNCE_COLOR, name.c_str(), args);
sWorld->SendGMText(LANG_GM_ANNOUNCE_COLOR, name.c_str(), message.data());
return true;
}
// global announce
static bool HandleAnnounceCommand(ChatHandler* handler, char const* args)
static bool HandleAnnounceCommand(ChatHandler* handler, Tail message)
{
if (!*args)
if (message.empty())
return false;
char buff[2048];
sprintf(buff, handler->GetAcoreString(LANG_SYSTEMMESSAGE), args);
sWorld->SendServerMessage(SERVER_MSG_STRING, buff);
sWorld->SendServerMessage(SERVER_MSG_STRING, Acore::StringFormat(handler->GetAcoreString(LANG_SYSTEMMESSAGE), message.data()).c_str());
return true;
}
// announce to logged in GMs
static bool HandleGMAnnounceCommand(ChatHandler* /*handler*/, char const* args)
static bool HandleGMAnnounceCommand(ChatHandler* /*handler*/, Tail message)
{
if (!*args)
if (message.empty())
return false;
sWorld->SendGMText(LANG_GM_BROADCAST, args);
sWorld->SendGMText(LANG_GM_BROADCAST, message.data());
return true;
}
// notification player at the screen
static bool HandleNotifyCommand(ChatHandler* handler, char const* args)
// send on-screen notification to players
static bool HandleNotifyCommand(ChatHandler* handler, Tail message)
{
if (!*args)
if (message.empty())
return false;
std::string str = handler->GetAcoreString(LANG_GLOBAL_NOTIFY);
str += args;
str += message;
WorldPacket data(SMSG_NOTIFICATION, (str.size() + 1));
data << str;
@@ -114,14 +118,15 @@ public:
return true;
}
// notification GM at the screen
static bool HandleGMNotifyCommand(ChatHandler* handler, char const* args)
// send on-screen notification to GMs
static bool HandleGMNotifyCommand(ChatHandler* handler, Tail message)
{
if (!*args)
if (message.empty())
return false;
std::string str = handler->GetAcoreString(LANG_GM_NOTIFY);
str += args;
str += message;
WorldPacket data(SMSG_NOTIFICATION, (str.size() + 1));
data << str;
@@ -129,34 +134,55 @@ public:
return true;
}
// Enable\Dissable accept whispers (for GM)
static bool HandleWhispersCommand(ChatHandler* handler, char const* args)
// Enable/Disable accepting whispers (for GM)
static bool HandleWhispersCommand(ChatHandler* handler, Optional<Variant<bool, EXACT_SEQUENCE("remove")>> operationArg, Optional<std::string> playerNameArg)
{
if (!*args)
if (!operationArg)
{
handler->PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, handler->GetSession()->GetPlayer()->isAcceptWhispers() ? handler->GetAcoreString(LANG_ON) : handler->GetAcoreString(LANG_OFF));
return true;
}
std::string argStr = (char*)args;
// whisper on
if (argStr == "on")
if (operationArg->holds_alternative<bool>())
{
handler->GetSession()->GetPlayer()->SetAcceptWhispers(true);
handler->SendSysMessage(LANG_COMMAND_WHISPERON);
return true;
if (operationArg->get<bool>())
{
handler->GetSession()->GetPlayer()->SetAcceptWhispers(true);
handler->SendSysMessage(LANG_COMMAND_WHISPERON);
return true;
}
else
{
// Remove all players from the Gamemaster's whisper whitelist
handler->GetSession()->GetPlayer()->ClearWhisperWhiteList();
handler->GetSession()->GetPlayer()->SetAcceptWhispers(false);
handler->SendSysMessage(LANG_COMMAND_WHISPEROFF);
return true;
}
}
// whisper off
if (argStr == "off")
if (operationArg->holds_alternative<EXACT_SEQUENCE("remove")>())
{
// Remove all players from the Gamemaster's whisper whitelist
handler->GetSession()->GetPlayer()->ClearWhisperWhiteList();
handler->GetSession()->GetPlayer()->SetAcceptWhispers(false);
handler->SendSysMessage(LANG_COMMAND_WHISPEROFF);
return true;
}
if (!playerNameArg)
return false;
if (normalizePlayerName(*playerNameArg))
{
if (Player* player = ObjectAccessor::FindPlayerByName(*playerNameArg))
{
handler->GetSession()->GetPlayer()->RemoveFromWhisperWhiteList(player->GetGUID());
handler->PSendSysMessage(LANG_COMMAND_WHISPEROFFPLAYER, playerNameArg->c_str());
return true;
}
else
{
handler->PSendSysMessage(LANG_PLAYER_NOT_FOUND, playerNameArg->c_str());
handler->SetSentErrorMessage(true);
return false;
}
}
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;

View File

@@ -22,17 +22,13 @@ Comment: All tele related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "Chat.h"
#include "Group.h"
#include "Language.h"
#include "MapMgr.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
#if AC_COMPILER == AC_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
using namespace Acore::ChatCommands;
@@ -45,30 +41,25 @@ public:
{
static ChatCommandTable teleCommandTable =
{
{ "add", SEC_ADMINISTRATOR, false, &HandleTeleAddCommand, "" },
{ "del", SEC_ADMINISTRATOR, true, &HandleTeleDelCommand, "" },
{ "name", SEC_GAMEMASTER, true, &HandleTeleNameCommand, "" },
{ "group", SEC_GAMEMASTER, false, &HandleTeleGroupCommand, "" },
{ "", SEC_MODERATOR, false, &HandleTeleCommand, "" }
{ "add", HandleTeleAddCommand, SEC_ADMINISTRATOR, Console::No },
{ "del", HandleTeleDelCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "name", HandleTeleNameCommand, SEC_GAMEMASTER, Console::Yes },
{ "group", HandleTeleGroupCommand, SEC_GAMEMASTER, Console::No },
{ "", HandleTeleCommand, SEC_GAMEMASTER, Console::No }
};
static ChatCommandTable commandTable =
{
{ "teleport", SEC_MODERATOR, false, nullptr, "", teleCommandTable }
{ "teleport", teleCommandTable }
};
return commandTable;
}
static bool HandleTeleAddCommand(ChatHandler* handler, const char* 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->GetGameTele(name))
{
handler->SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
@@ -162,7 +153,7 @@ public:
handler->PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), handler->GetAcoreString(LANG_OFFLINE), locationName.c_str());
Player::SavePositionInDB({mapId, pos}, sMapMgr->GetZoneId(PHASEMASK_NORMAL, {mapId, pos}), player.GetGUID(), nullptr);
Player::SavePositionInDB({ mapId, pos }, sMapMgr->GetZoneId(PHASEMASK_NORMAL, { mapId, pos }), player.GetGUID(), nullptr);
}
return true;
@@ -173,7 +164,6 @@ public:
{
if (!player)
player = PlayerIdentifier::FromTargetOrSelf(handler);
if (!player)
return false;
@@ -224,7 +214,7 @@ public:
}
// check online security
if (handler->HasLowerSecurity(target))
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
return false;
MapEntry const* map = sMapStore.LookupEntry(tele->mapId);
@@ -253,7 +243,7 @@ public:
continue;
// check online security
if (handler->HasLowerSecurity(player))
if (handler->HasLowerSecurity(player, ObjectGuid::Empty))
return false;
std::string plNameLink = handler->GetNameLink(player);
@@ -266,17 +256,16 @@ public:
handler->PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(), "", tele->name.c_str());
if (handler->needReportToTarget(player))
(ChatHandler(player->GetSession())).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
ChatHandler(player->GetSession()).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
// stop flight if need
if (player->IsInFlight())
if (target->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
target->GetMotionMaster()->MovementExpired();
target->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
else // save only in non-flight case
target->SaveRecallPosition();
player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
}
@@ -293,16 +282,8 @@ public:
return false;
}
Player* me = handler->GetSession()->GetPlayer();
if (!tele)
{
handler->SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (me->IsInCombat())
Player* player = handler->GetSession()->GetPlayer();
if (player->IsInCombat())
{
handler->SendSysMessage(LANG_YOU_IN_COMBAT);
handler->SetSentErrorMessage(true);
@@ -310,7 +291,7 @@ public:
}
MapEntry const* map = sMapStore.LookupEntry(tele->mapId);
if (!map || map->IsBattlegroundOrArena())
if (!map || (map->IsBattlegroundOrArena() && (player->GetMapId() != tele->mapId || !player->IsGameMaster())))
{
handler->SendSysMessage(LANG_CANNOT_TELE_TO_BG);
handler->SetSentErrorMessage(true);
@@ -318,16 +299,15 @@ public:
}
// stop flight if need
if (me->IsInFlight())
if (player->IsInFlight())
{
me->GetMotionMaster()->MovementExpired();
me->CleanupAfterTaxiFlight();
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
me->SaveRecallPosition();
else // save only in non-flight case
player->SaveRecallPosition();
me->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
return true;
}
};

View File

@@ -22,15 +22,11 @@ Comment: All titles related commands
Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "Language.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
#if AC_COMPILER == AC_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#include "Chat.h"
#include "DBCStores.h"
#include "Language.h"
#include "Player.h"
using namespace Acore::ChatCommands;
@@ -43,37 +39,24 @@ public:
{
static ChatCommandTable titlesSetCommandTable =
{
{ "mask", SEC_GAMEMASTER, false, &HandleTitlesSetMaskCommand, "" }
{ "mask", HandleTitlesSetMaskCommand, SEC_GAMEMASTER, Console::No },
};
static ChatCommandTable titlesCommandTable =
{
{ "add", SEC_GAMEMASTER, false, &HandleTitlesAddCommand, "" },
{ "current", SEC_GAMEMASTER, false, &HandleTitlesCurrentCommand, "" },
{ "remove", SEC_GAMEMASTER, false, &HandleTitlesRemoveCommand, "" },
{ "set", SEC_GAMEMASTER, false, nullptr, "", titlesSetCommandTable }
{ "add", HandleTitlesAddCommand, SEC_GAMEMASTER, Console::No },
{ "current", HandleTitlesCurrentCommand, SEC_GAMEMASTER, Console::No },
{ "remove", HandleTitlesRemoveCommand, SEC_GAMEMASTER, Console::No },
{ "set", titlesSetCommandTable },
};
static ChatCommandTable commandTable =
{
{ "titles", SEC_GAMEMASTER, false, nullptr, "", titlesCommandTable }
{ "titles", titlesCommandTable },
};
return commandTable;
}
static bool HandleTitlesCurrentCommand(ChatHandler* handler, const char* args)
static bool HandleTitlesCurrentCommand(ChatHandler* handler, Variant<Hyperlink<title>, uint16> titleId)
{
// 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;
int32 id = atoi(id_p);
if (id <= 0)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
Player* target = handler->getSelectedPlayer();
if (!target)
{
@@ -83,88 +66,30 @@ public:
}
// check online security
if (handler->HasLowerSecurity(target))
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
if (!titleInfo)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, uint32(titleId));
handler->SetSentErrorMessage(true);
return false;
}
std::string tNameLink = handler->GetNameLink(target);
target->SetTitle(titleInfo); // to be sure that title now known
target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->bit_index);
handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, id, target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], tNameLink.c_str());
return true;
}
static bool HandleTitlesAddCommand(ChatHandler* handler, const char* 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;
int32 id = atoi(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))
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);
char titleNameStr[80];
snprintf(titleNameStr, 80, target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName().c_str());
std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
target->SetTitle(titleInfo);
handler->PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr, tNameLink.c_str());
target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->bit_index);
handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, uint32(titleId), titleNameStr, tNameLink);
return true;
}
static bool HandleTitlesRemoveCommand(ChatHandler* handler, char const* args)
static bool HandleTitlesAddCommand(ChatHandler* handler, Variant<Hyperlink<title>, uint16> titleId)
{
// 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;
int32 id = atoi(id_p);
if (id <= 0)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->SetSentErrorMessage(true);
return false;
}
Player* target = handler->getSelectedPlayer();
if (!target)
{
@@ -174,13 +99,44 @@ public:
}
// check online security
if (handler->HasLowerSecurity(target))
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
return false;
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(titleId);
if (!titleInfo)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, id);
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, uint32(titleId));
handler->SetSentErrorMessage(true);
return false;
}
std::string tNameLink = handler->GetNameLink(target);
std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
target->SetTitle(titleInfo);
handler->PSendSysMessage(LANG_TITLE_ADD_RES, uint32(titleId), titleNameStr, tNameLink);
return true;
}
static bool HandleTitlesRemoveCommand(ChatHandler* handler, Variant<Hyperlink<title>, uint16> titleId)
{
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(titleId);
if (!titleInfo)
{
handler->PSendSysMessage(LANG_INVALID_TITLE_ID, uint32(titleId));
handler->SetSentErrorMessage(true);
return false;
}
@@ -188,31 +144,22 @@ public:
target->SetTitle(titleInfo, true);
std::string tNameLink = handler->GetNameLink(target);
std::string titleNameStr = Acore::StringFormat(target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName());
char titleNameStr[80];
snprintf(titleNameStr, 80, target->getGender() == GENDER_MALE ? titleInfo->nameMale[handler->GetSessionDbcLocale()] : titleInfo->nameFemale[handler->GetSessionDbcLocale()], target->GetName().c_str());
handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr, tNameLink.c_str());
handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, uint32(titleId), titleNameStr, tNameLink);
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
{
target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink.c_str());
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink);
}
return true;
}
//Edit Player KnownTitles
static bool HandleTitlesSetMaskCommand(ChatHandler* handler, char const* args)
static bool HandleTitlesSetMaskCommand(ChatHandler* handler, uint64 mask)
{
if (!*args)
return false;
uint64 titles = 0;
sscanf((char*)args, UI64FMTD, &titles);
Player* target = handler->getSelectedPlayer();
if (!target)
{
@@ -222,24 +169,24 @@ public:
}
// check online security
if (handler->HasLowerSecurity(target))
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
return false;
uint64 titles2 = titles;
uint64 titles2 = mask;
for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
titles2 &= ~(uint64(1) << tEntry->bit_index);
titles &= ~titles2; // remove not existed titles
mask &= ~titles2; // remove non-existing titles
target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, mask);
handler->SendSysMessage(LANG_DONE);
if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
{
target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, handler->GetNameLink(target).c_str());
handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, handler->GetNameLink(target));
}
return true;