mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-07 23:38:00 +00:00
feat(Script/Commands): Add account flag commands (#26301)
This commit is contained in:
@@ -30,6 +30,42 @@ char const* localeNames[TOTAL_LOCALES] =
|
||||
"ruRU"
|
||||
};
|
||||
|
||||
AccountFlagName const accountFlagNames[MAX_ACCOUNT_FLAG] =
|
||||
{
|
||||
{ "ACCOUNT_FLAG_GM", "GM" },
|
||||
{ "ACCOUNT_FLAG_NOKICK", "NOKICK" },
|
||||
{ "ACCOUNT_FLAG_COLLECTOR", "COLLECTOR" },
|
||||
{ "ACCOUNT_FLAG_TRIAL", "TRIAL" },
|
||||
{ "ACCOUNT_FLAG_CANCELLED", "CANCELLED" },
|
||||
{ "ACCOUNT_FLAG_IGR", "IGR" },
|
||||
{ "ACCOUNT_FLAG_WHOLESALER", "WHOLESALER" },
|
||||
{ "ACCOUNT_FLAG_PRIVILEGED", "PRIVILEGED" },
|
||||
{ "ACCOUNT_FLAG_EU_FORBID_ELV", "EU_FORBID_ELV" },
|
||||
{ "ACCOUNT_FLAG_EU_FORBID_BILLING", "EU_FORBID_BILLING" },
|
||||
{ "ACCOUNT_FLAG_RESTRICTED", "RESTRICTED" },
|
||||
{ "ACCOUNT_FLAG_REFERRAL", "REFERRAL" },
|
||||
{ "ACCOUNT_FLAG_BLIZZARD", "BLIZZARD" },
|
||||
{ "ACCOUNT_FLAG_RECURRING_BILLING", "RECURRING_BILLING" },
|
||||
{ "ACCOUNT_FLAG_NOELECTUP", "NOELECTUP" },
|
||||
{ "ACCOUNT_FLAG_KR_CERTIFICATE", "KR_CERTIFICATE" },
|
||||
{ "ACCOUNT_FLAG_EXPANSION_COLLECTOR", "EXPANSION_COLLECTOR" },
|
||||
{ "ACCOUNT_FLAG_DISABLE_VOICE", "DISABLE_VOICE" },
|
||||
{ "ACCOUNT_FLAG_DISABLE_VOICE_SPEAK", "DISABLE_VOICE_SPEAK" },
|
||||
{ "ACCOUNT_FLAG_REFERRAL_RESURRECT", "REFERRAL_RESURRECT" },
|
||||
{ "ACCOUNT_FLAG_EU_FORBID_CC", "EU_FORBID_CC" },
|
||||
{ "ACCOUNT_FLAG_OPENBETA_DELL", "OPENBETA_DELL" },
|
||||
{ "ACCOUNT_FLAG_PROPASS", "PROPASS" },
|
||||
{ "ACCOUNT_FLAG_PROPASS_LOCK", "PROPASS_LOCK" },
|
||||
{ "ACCOUNT_FLAG_PENDING_UPGRADE", "PENDING_UPGRADE" },
|
||||
{ "ACCOUNT_FLAG_RETAIL_FROM_TRIAL", "RETAIL_FROM_TRIAL" },
|
||||
{ "ACCOUNT_FLAG_EXPANSION2_COLLECTOR", "EXPANSION2_COLLECTOR" },
|
||||
{ "ACCOUNT_FLAG_OVERMIND_LINKED", "OVERMIND_LINKED" },
|
||||
{ "ACCOUNT_FLAG_DEMOS", "DEMOS" },
|
||||
{ "ACCOUNT_FLAG_DEATH_KNIGHT_OK", "DEATH_KNIGHT_OK" },
|
||||
{ "ACCOUNT_FLAG_S2_REQUIRE_IGR", "S2_REQUIRE_IGR" },
|
||||
{ "ACCOUNT_FLAG_S2_TRIAL", "S2_TRIAL" }
|
||||
};
|
||||
|
||||
bool IsLocaleValid(std::string const& locale)
|
||||
{
|
||||
for (int i = 0; i < TOTAL_LOCALES; ++i)
|
||||
|
||||
@@ -113,6 +113,14 @@ constexpr uint32 ACCOUNT_FLAGS_ALL =
|
||||
ACCOUNT_FLAG_OVERMIND_LINKED | ACCOUNT_FLAG_DEMOS | ACCOUNT_FLAG_DEATH_KNIGHT_OK |
|
||||
ACCOUNT_FLAG_S2_REQUIRE_IGR | ACCOUNT_FLAG_S2_TRIAL;
|
||||
|
||||
struct AccountFlagName
|
||||
{
|
||||
char const* full;
|
||||
char const* shortName;
|
||||
};
|
||||
|
||||
AC_COMMON_API extern AccountFlagName const accountFlagNames[MAX_ACCOUNT_FLAG];
|
||||
|
||||
enum LocaleConstant
|
||||
{
|
||||
LOCALE_enUS = 0,
|
||||
|
||||
@@ -702,6 +702,10 @@ enum RBACPermissions
|
||||
RBAC_PERM_COMMAND_SPELLINFO_ALL = 938,
|
||||
RBAC_PERM_COMMAND_SERVER_SET_SECURITY = 939,
|
||||
RBAC_PERM_COMMAND_GROUP_INVITES = 940,
|
||||
RBAC_PERM_COMMAND_ACCOUNT_FLAG = 941,
|
||||
RBAC_PERM_COMMAND_ACCOUNT_FLAG_LIST = 942,
|
||||
RBAC_PERM_COMMAND_ACCOUNT_FLAG_ADD = 943,
|
||||
RBAC_PERM_COMMAND_ACCOUNT_FLAG_REMOVE = 944,
|
||||
// custom permissions 1000+
|
||||
RBAC_PERM_MAX
|
||||
};
|
||||
|
||||
@@ -1537,7 +1537,14 @@ enum AcoreStrings
|
||||
// Group invites toggle command
|
||||
LANG_COMMAND_GROUP_INVITES_ACCEPTING = 35462,
|
||||
LANG_COMMAND_GROUP_INVITES_ON = 35463,
|
||||
LANG_COMMAND_GROUP_INVITES_OFF = 35464
|
||||
LANG_COMMAND_GROUP_INVITES_OFF = 35464,
|
||||
|
||||
// Account flag command
|
||||
LANG_ACCOUNT_FLAG_LIST_HEADER = 35465,
|
||||
LANG_ACCOUNT_FLAG_LIST_EMPTY = 35466,
|
||||
LANG_ACCOUNT_FLAG_INVALID = 35467,
|
||||
LANG_ACCOUNT_FLAG_RESERVED = 35468,
|
||||
LANG_ACCOUNT_FLAG_ADDED = 35469,
|
||||
LANG_ACCOUNT_FLAG_REMOVED = 35470
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -20,8 +20,10 @@
|
||||
#include "Base32.h"
|
||||
#include "Chat.h"
|
||||
#include "CommandScript.h"
|
||||
#include "Common.h"
|
||||
#include "CryptoGenerics.h"
|
||||
#include "IPLocation.h"
|
||||
#include "Language.h"
|
||||
#include "Player.h"
|
||||
#include "RBAC.h"
|
||||
#include "Realm.h"
|
||||
@@ -29,6 +31,9 @@
|
||||
#include "SecretMgr.h"
|
||||
#include "StringConvert.h"
|
||||
#include "TOTP.h"
|
||||
#include "Util.h"
|
||||
#include "WorldSession.h"
|
||||
#include "WorldSessionMgr.h"
|
||||
#include <unordered_map>
|
||||
|
||||
#if AC_COMPILER == AC_COMPILER_GNU
|
||||
@@ -70,12 +75,20 @@ public:
|
||||
{ "country", HandleAccountRemoveLockCountryCommand, rbac::RBAC_PERM_COMMAND_ACCOUNT_LOCK_COUNTRY, Console::Yes },
|
||||
};
|
||||
|
||||
static ChatCommandTable accountFlagCommandTable
|
||||
{
|
||||
{ "list", HandleAccountFlagListCommand, rbac::RBAC_PERM_COMMAND_ACCOUNT_FLAG_LIST, Console::Yes },
|
||||
{ "add", HandleAccountFlagAddCommand, rbac::RBAC_PERM_COMMAND_ACCOUNT_FLAG_ADD, Console::Yes },
|
||||
{ "remove", HandleAccountFlagRemoveCommand, rbac::RBAC_PERM_COMMAND_ACCOUNT_FLAG_REMOVE, Console::Yes }
|
||||
};
|
||||
|
||||
static ChatCommandTable accountCommandTable =
|
||||
{
|
||||
{ "2fa", account2faCommandTable },
|
||||
{ "addon", HandleAccountAddonCommand, rbac::RBAC_PERM_COMMAND_ACCOUNT_ADDON, Console::No },
|
||||
{ "create", HandleAccountCreateCommand, rbac::RBAC_PERM_COMMAND_ACCOUNT_CREATE, Console::Yes },
|
||||
{ "delete", HandleAccountDeleteCommand, rbac::RBAC_PERM_COMMAND_ACCOUNT_DELETE, Console::Yes },
|
||||
{ "flag", accountFlagCommandTable },
|
||||
{ "onlinelist", HandleAccountOnlineListCommand, rbac::RBAC_PERM_COMMAND_ACCOUNT_ONLINE_LIST, Console::Yes },
|
||||
{ "lock", accountLockCommandTable },
|
||||
{ "set", accountSetCommandTable },
|
||||
@@ -911,6 +924,111 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static Optional<uint8> ParseAccountFlagBit(std::string_view input)
|
||||
{
|
||||
for (uint8 i = 0; i < MAX_ACCOUNT_FLAG; ++i)
|
||||
if (StringEqualI(input, accountFlagNames[i].full) || StringEqualI(input, accountFlagNames[i].shortName))
|
||||
return i;
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static bool HandleAccountFlagListCommand(ChatHandler* handler, Optional<AccountIdentifier> account)
|
||||
{
|
||||
uint32 accountId;
|
||||
std::string accountName;
|
||||
|
||||
if (account)
|
||||
{
|
||||
accountId = account->GetID();
|
||||
accountName = account->GetName();
|
||||
}
|
||||
else if (WorldSession* session = handler->GetSession())
|
||||
{
|
||||
accountId = session->GetAccountId();
|
||||
AccountMgr::GetName(accountId, accountName);
|
||||
}
|
||||
else
|
||||
{
|
||||
handler->SendErrorMessage(LANG_CMD_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (handler->HasLowerSecurityAccount(nullptr, accountId, true))
|
||||
return false;
|
||||
|
||||
uint32 flags;
|
||||
if (WorldSession* targetSession = sWorldSessionMgr->FindSession(accountId))
|
||||
flags = targetSession->GetAccountFlags();
|
||||
else
|
||||
{
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_FLAG);
|
||||
stmt->SetData(0, accountId);
|
||||
PreparedQueryResult result = LoginDatabase.Query(stmt);
|
||||
if (!result)
|
||||
{
|
||||
handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
|
||||
return false;
|
||||
}
|
||||
|
||||
flags = (*result)[0].Get<uint32>();
|
||||
}
|
||||
|
||||
if (!flags)
|
||||
{
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_FLAG_LIST_EMPTY, accountName, accountId);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_FLAG_LIST_HEADER, accountName, accountId);
|
||||
for (uint8 i = 0; i < MAX_ACCOUNT_FLAG; ++i)
|
||||
if (flags & (uint32(1) << i))
|
||||
handler->PSendSysMessage(LANG_SUBCMDS_LIST_ENTRY, accountFlagNames[i].full);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ChangeAccountFlag(ChatHandler* handler, AccountIdentifier const& account, std::string_view flagArg, bool add)
|
||||
{
|
||||
if (handler->HasLowerSecurityAccount(nullptr, account.GetID(), true))
|
||||
return false;
|
||||
|
||||
Optional<uint8> bit = ParseAccountFlagBit(flagArg);
|
||||
if (!bit)
|
||||
{
|
||||
handler->SendErrorMessage(LANG_ACCOUNT_FLAG_INVALID, flagArg);
|
||||
return false;
|
||||
}
|
||||
|
||||
// ACCOUNT_FLAG_GM is handled by GMLevel and should not be allowed to set manually
|
||||
uint32 const flag = uint32(1) << *bit;
|
||||
if (flag & ACCOUNT_FLAG_GM)
|
||||
{
|
||||
handler->SendErrorMessage(LANG_ACCOUNT_FLAG_RESERVED);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (WorldSession* session = sWorldSessionMgr->FindSession(account.GetID()))
|
||||
session->UpdateAccountFlag(flag, !add);
|
||||
else
|
||||
LoginDatabase.Execute("UPDATE account SET Flags = Flags {} {} WHERE id = {}",
|
||||
add ? "|" : "& ~", flag, account.GetID());
|
||||
|
||||
handler->PSendSysMessage(add ? LANG_ACCOUNT_FLAG_ADDED : LANG_ACCOUNT_FLAG_REMOVED,
|
||||
accountFlagNames[*bit].full, account.GetName(), account.GetID());
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleAccountFlagAddCommand(ChatHandler* handler, AccountIdentifier account, std::string_view flagArg)
|
||||
{
|
||||
return ChangeAccountFlag(handler, account, flagArg, true);
|
||||
}
|
||||
|
||||
static bool HandleAccountFlagRemoveCommand(ChatHandler* handler, AccountIdentifier account, std::string_view flagArg)
|
||||
{
|
||||
return ChangeAccountFlag(handler, account, flagArg, false);
|
||||
}
|
||||
|
||||
/// Set email for account
|
||||
static bool HandleAccountSetEmailCommand(ChatHandler* handler, AccountIdentifier account, std::string email, std::string emailConfirmation)
|
||||
|
||||
|
||||
@@ -61,49 +61,6 @@
|
||||
constexpr auto SPELL_STUCK = 7355;
|
||||
constexpr auto SPELL_FREEZE = 9454;
|
||||
|
||||
struct AccountFlagText
|
||||
{
|
||||
AccountFlag flag;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
AccountFlagText const accountFlagText[MAX_ACCOUNT_FLAG] =
|
||||
{
|
||||
{ ACCOUNT_FLAG_GM, "ACCOUNT_FLAG_GM" },
|
||||
{ ACCOUNT_FLAG_NOKICK, "ACCOUNT_FLAG_NOKICK" },
|
||||
{ ACCOUNT_FLAG_COLLECTOR, "ACCOUNT_FLAG_COLLECTOR" },
|
||||
{ ACCOUNT_FLAG_TRIAL, "ACCOUNT_FLAG_TRIAL" },
|
||||
{ ACCOUNT_FLAG_CANCELLED, "ACCOUNT_FLAG_CANCELLED" },
|
||||
{ ACCOUNT_FLAG_IGR, "ACCOUNT_FLAG_IGR" },
|
||||
{ ACCOUNT_FLAG_WHOLESALER, "ACCOUNT_FLAG_WHOLESALER" },
|
||||
{ ACCOUNT_FLAG_PRIVILEGED, "ACCOUNT_FLAG_PRIVILEGED" },
|
||||
{ ACCOUNT_FLAG_EU_FORBID_ELV, "ACCOUNT_FLAG_EU_FORBID_ELV" },
|
||||
{ ACCOUNT_FLAG_EU_FORBID_BILLING, "ACCOUNT_FLAG_EU_FORBID_BILLING" },
|
||||
{ ACCOUNT_FLAG_RESTRICTED, "ACCOUNT_FLAG_RESTRICTED" },
|
||||
{ ACCOUNT_FLAG_REFERRAL, "ACCOUNT_FLAG_REFERRAL" },
|
||||
{ ACCOUNT_FLAG_BLIZZARD, "ACCOUNT_FLAG_BLIZZARD" },
|
||||
{ ACCOUNT_FLAG_RECURRING_BILLING, "ACCOUNT_FLAG_RECURRING_BILLING" },
|
||||
{ ACCOUNT_FLAG_NOELECTUP, "ACCOUNT_FLAG_NOELECTUP" },
|
||||
{ ACCOUNT_FLAG_KR_CERTIFICATE, "ACCOUNT_FLAG_KR_CERTIFICATE" },
|
||||
{ ACCOUNT_FLAG_EXPANSION_COLLECTOR, "ACCOUNT_FLAG_EXPANSION_COLLECTOR" },
|
||||
{ ACCOUNT_FLAG_DISABLE_VOICE, "ACCOUNT_FLAG_DISABLE_VOICE" },
|
||||
{ ACCOUNT_FLAG_DISABLE_VOICE_SPEAK, "ACCOUNT_FLAG_DISABLE_VOICE_SPEAK" },
|
||||
{ ACCOUNT_FLAG_REFERRAL_RESURRECT, "ACCOUNT_FLAG_REFERRAL_RESURRECT" },
|
||||
{ ACCOUNT_FLAG_EU_FORBID_CC, "ACCOUNT_FLAG_EU_FORBID_CC" },
|
||||
{ ACCOUNT_FLAG_OPENBETA_DELL, "ACCOUNT_FLAG_OPENBETA_DELL" },
|
||||
{ ACCOUNT_FLAG_PROPASS, "ACCOUNT_FLAG_PROPASS" },
|
||||
{ ACCOUNT_FLAG_PROPASS_LOCK, "ACCOUNT_FLAG_PROPASS_LOCK" },
|
||||
{ ACCOUNT_FLAG_PENDING_UPGRADE, "ACCOUNT_FLAG_PENDING_UPGRADE" },
|
||||
{ ACCOUNT_FLAG_RETAIL_FROM_TRIAL, "ACCOUNT_FLAG_RETAIL_FROM_TRIAL" },
|
||||
{ ACCOUNT_FLAG_EXPANSION2_COLLECTOR, "ACCOUNT_FLAG_EXPANSION2_COLLECTOR" },
|
||||
{ ACCOUNT_FLAG_OVERMIND_LINKED, "ACCOUNT_FLAG_OVERMIND_LINKED" },
|
||||
{ ACCOUNT_FLAG_DEMOS, "ACCOUNT_FLAG_DEMOS" },
|
||||
{ ACCOUNT_FLAG_DEATH_KNIGHT_OK, "ACCOUNT_FLAG_DEATH_KNIGHT_OK" },
|
||||
{ ACCOUNT_FLAG_S2_REQUIRE_IGR, "ACCOUNT_FLAG_S2_REQUIRE_IGR" },
|
||||
{ ACCOUNT_FLAG_S2_TRIAL, "ACCOUNT_FLAG_S2_TRIAL" },
|
||||
// { ACCOUNT_FLAG_S2_RESTRICTED, "ACCOUNT_FLAG_S2_RESTRICTED" }
|
||||
};
|
||||
|
||||
std::string const GetLocalizeCreatureName(Creature* creature, LocaleConstant locale)
|
||||
{
|
||||
auto creatureTemplate = sObjectMgr->GetCreatureTemplate(creature->GetEntry());
|
||||
@@ -2280,8 +2237,8 @@ public:
|
||||
uint32 accountFlags = playerTarget->GetSession()->GetAccountFlags();
|
||||
handler->PSendSysMessage(LANG_ACCOUNT_FLAGS_PINFO);
|
||||
for (uint8 i = 0; i < MAX_ACCOUNT_FLAG; i++)
|
||||
if (accountFlags & static_cast<uint32>(accountFlagText[i].flag))
|
||||
handler->PSendSysMessage(LANG_SUBCMDS_LIST_ENTRY, accountFlagText[i].text);
|
||||
if (accountFlags & (uint32(1) << i))
|
||||
handler->PSendSysMessage(LANG_SUBCMDS_LIST_ENTRY, accountFlagNames[i].full);
|
||||
}
|
||||
|
||||
// Output VI. LANG_PINFO_ACC_LASTLOGIN
|
||||
|
||||
Reference in New Issue
Block a user