Skip to content

Commit 84375a7

Browse files
committed
feat: Implement account name/command as config
1 parent 3d012a4 commit 84375a7

File tree

4 files changed

+131
-13
lines changed

4 files changed

+131
-13
lines changed

conf/conf.sh.dist

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
## CUSTOM SQL - Important file used by the db_assembler.sh
4+
## Keep only the required variables (base sql files or updates, depending on the DB)
5+
6+
## BASE SQL
7+
8+
DB_AUTH_CUSTOM_PATHS+=(
9+
"$MOD_SKELETON_ROOT/sql/auth/base/"
10+
)
11+
12+
DB_CHARACTERS_CUSTOM_PATHS+=(
13+
"$MOD_SKELETON_ROOT/sql/characters/base/"
14+
)
15+
16+
DB_WORLD_CUSTOM_PATHS+=(
17+
"$MOD_SKELETON_ROOT/sql/world/base/"
18+
)
19+
20+
## UPDATES
21+
22+
DB_AUTH_UPDATES_PATHS+=(
23+
"$MOD_SKELETON_ROOT/sql/auth/updates/"
24+
)
25+
26+
DB_CHARACTERS_UPDATES_PATHS+=(
27+
"$MOD_SKELETON_ROOT/sql/characters/updates/"
28+
)
29+
30+
DB_WORLD_UPDATES_PATHS+=(
31+
"$MOD_SKELETON_ROOT/sql/world/updates/"
32+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,20 @@
1515
#
1616

1717
GmCommandsModule.Enable = 1
18+
19+
#
20+
# GmCommandsModule.AccountIds
21+
# Description: Allow the specified accounts to use commands. Separated by comma
22+
#
23+
#
24+
25+
GmCommandsModule.AccountIds = ""
26+
27+
#
28+
#
29+
# GmCommandsModule.AllowedCommands
30+
# Description: Allow the specified commands to be used. Separated by comma.
31+
#
32+
#
33+
34+
GmCommandsModule.AllowedCommands = ""

src/GmCommands.cpp

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,48 @@
33
#include "Chat.h"
44
#include "ChatCommand.h"
55
#include "Config.h"
6+
#include "GmCommands.h"
7+
#include "Tokenize.h"
8+
9+
GMCommands* GMCommands::instance()
10+
{
11+
static GMCommands instance;
12+
return &instance;
13+
}
14+
15+
void GMCommands::LoadAccountIds()
16+
{
17+
std::string accountIds = sConfigMgr->GetOption<std::string>("GmCommandsModule.AccountIds", "");
18+
for (auto& itr : Acore::Tokenize(accountIds, ',', false))
19+
{
20+
uint32 accountId = Acore::StringTo<uint32>(itr).value();
21+
accountIDs.push_back(accountId);
22+
}
23+
}
24+
25+
void GMCommands::LoadAllowedCommands()
26+
{
27+
std::string allowedCommandsList = sConfigMgr->GetOption<std::string>("GmCommandsModule.AllowedCommands", "");
28+
for (auto& itr : Acore::Tokenize(allowedCommandsList, ',', false))
29+
{
30+
std::string command(itr);
31+
allowedCommands.push_back(command);
32+
}
33+
}
34+
35+
bool GMCommands::IsAccountAllowed(uint32 accountId) const
36+
{
37+
for (auto& itr : accountIDs)
38+
{
39+
LOG_ERROR("sql.sql", "AccountId {}", itr);
40+
}
41+
return std::find(accountIDs.begin(), accountIDs.end(), accountId) != accountIDs.end();
42+
}
43+
44+
bool GMCommands::IsCommandAllowed(std::string command) const
45+
{
46+
return std::find(allowedCommands.begin(), allowedCommands.end(), command) != allowedCommands.end();
47+
}
648

749
class GmCommands : public AllCommandScript
850
{
@@ -21,28 +63,30 @@ class GmCommands : public AllCommandScript
2163

2264
uint32 accountID = player->GetSession()->GetAccountId();
2365

24-
if (!std::count(eligibleAccounts.begin(), eligibleAccounts.end(), accountID))
25-
return true; // Account is not eligible
66+
if (!sGMCommands->IsAccountAllowed(accountID))
67+
return true;
2668

27-
if (std::count(eligibleCommands.begin(), eligibleCommands.end(), name))
28-
return false; // Command is eligible
69+
if (!sGMCommands->IsCommandAllowed(name))
70+
return true;
2971

30-
return true; // Command is not eligible
72+
return false;
3173
}
74+
};
3275

33-
private:
34-
std::vector<uint32> eligibleAccounts =
35-
{
36-
94143, // HEYITSGMCH
37-
};
76+
class mod_gm_commands_worldscript : public WorldScript
77+
{
78+
public:
79+
mod_gm_commands_worldscript() : WorldScript("mod_gm_commands_worldscript") {}
3880

39-
std::vector<std::string> eligibleCommands =
81+
void OnAfterConfigLoad(bool /*reload*/) override
4082
{
41-
"gm fly",
42-
};
83+
sGMCommands->LoadAccountIds();
84+
sGMCommands->LoadAllowedCommands();
85+
}
4386
};
4487

4588
void AddGmCommandScripts()
4689
{
4790
new GmCommands();
91+
new mod_gm_commands_worldscript();
4892
}

src/GmCommands.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef DEF_GMCOMMANDS_H
2+
#define DEF_GMCOMMANDS_H
3+
4+
#include "Player.h"
5+
#include "Config.h"
6+
7+
class GMCommands
8+
{
9+
public:
10+
static GMCommands* instance();
11+
12+
void LoadAccountIds();
13+
void LoadAllowedCommands();
14+
15+
[[nodiscard]] bool IsAccountAllowed(uint32 accountId) const;
16+
[[nodiscard]] bool IsCommandAllowed(std::string command) const;
17+
18+
private:
19+
std::vector<uint32> accountIDs;
20+
std::vector<std::string> allowedCommands;
21+
};
22+
23+
#define sGMCommands GMCommands::instance()
24+
25+
#endif

0 commit comments

Comments
 (0)