refactor(Core/Player): add helper method for PLAYER_FLAGS_DEVELOPER (#4395)

Co-Authored-By: ForesterDev <11771800+ForesterDev@users.noreply.github.com>
This commit is contained in:
Kitzunu
2021-02-08 22:55:04 +01:00
committed by GitHub
parent 736def2058
commit 05a8217270
4 changed files with 15 additions and 14 deletions

View File

@@ -2210,7 +2210,7 @@ uint8 Player::GetChatTag() const
tag |= CHAT_TAG_DND;
if (isAFK())
tag |= CHAT_TAG_AFK;
if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_DEVELOPER))
if (IsDeveloper())
tag |= CHAT_TAG_DEV;
return tag;

View File

@@ -1173,6 +1173,9 @@ public:
void CleanupAfterTaxiFlight();
void ContinueTaxiFlight();
// mount_id can be used in scripting calls
[[nodiscard]] bool IsDeveloper() const { return HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_DEVELOPER); }
void SetDeveloper(bool on) { ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_DEVELOPER, on); }
[[nodiscard]] bool isAcceptWhispers() const { return m_ExtraFlags & PLAYER_EXTRA_ACCEPT_WHISPERS; }
void SetAcceptWhispers(bool on) { if (on) m_ExtraFlags |= PLAYER_EXTRA_ACCEPT_WHISPERS; else m_ExtraFlags &= ~PLAYER_EXTRA_ACCEPT_WHISPERS; }
[[nodiscard]] bool IsGameMaster() const { return m_ExtraFlags & PLAYER_EXTRA_GM_ON; }

View File

@@ -331,29 +331,27 @@ public:
return true;
}
static bool HandleDevCommand(ChatHandler* handler, char const* args)
static bool HandleDevCommand(ChatHandler* handler, char const* enable)
{
if (!*args)
Player* player = handler->GetSession()->GetPlayer();
if (!*enable)
{
if (handler->GetSession()->GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_DEVELOPER))
handler->GetSession()->SendNotification(LANG_DEV_ON);
else
handler->GetSession()->SendNotification(LANG_DEV_OFF);
handler->GetSession()->SendNotification(player->IsDeveloper() ? LANG_DEV_ON : LANG_DEV_OFF);
return true;
}
std::string argstr = (char*)args;
std::string enablestr = (char*)enable;
if (argstr == "on")
if (enablestr == "on")
{
handler->GetSession()->GetPlayer()->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_DEVELOPER);
player->SetDeveloper(true);
handler->GetSession()->SendNotification(LANG_DEV_ON);
return true;
}
if (argstr == "off")
else if (enablestr == "off")
{
handler->GetSession()->GetPlayer()->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_DEVELOPER);
player->SetDeveloper(false);
handler->GetSession()->SendNotification(LANG_DEV_OFF);
return true;
}

View File

@@ -111,7 +111,7 @@ public:
if (handler->GetSession())
if (Player* p = handler->GetSession()->GetPlayer())
if (p->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_DEVELOPER))
if (p->IsDeveloper())
handler->PSendSysMessage("DEV wavg: %ums, nsmax: %ums, nsavg: %ums. LFG avg: %ums, max: %ums.", avgDiffTracker.getTimeWeightedAverage(), devDiffTracker.getMax(), devDiffTracker.getAverage(), lfgDiffTracker.getAverage(), lfgDiffTracker.getMax());
//! Can't use sWorld->ShutdownMsg here in case of console command