Skip to content

Commit 38ebd41

Browse files
authored
Enhance GM commands configuration with per-account overrides and default settings (#6)
TLDR: Introduce per-account configurations for GM commands, allowing custom GM levels and command lists, along with default settings for accounts without specific overrides. Setting a GM Level (at least 1) is important to make some features to work - such as the keeping the player extra flags permanent after the relog (e.g. gm on/visible flags) This pull request introduces a major refactor and extension of the GM commands configuration system. The changes provide more granular control over which accounts can use GM commands, their permission levels, and the commands available to them. The configuration file now supports per-account overrides, default levels, and command lists, while the codebase is updated to support these new features with a more robust and flexible structure. Configuration enhancements: * Added support for specifying a default GM level (`GmCommandsModule.DefaultLevel`) and a default allowed command list (`GmCommandsModule.DefaultCommands`) in `conf/mod_gm_commands.conf.dist`. These apply to all managed accounts unless overridden per account. Per-account overrides for both level and allowed commands are now supported. Codebase refactor and feature additions: * Replaced the old `LoadAccountIds` and `LoadAllowedCommands` methods with a single `Reload` method in `GMCommands`, reflecting the new configuration structure. * Introduced per-account configuration via the `AccountConfiguration` struct, supporting optional GM level and allowed command set for each account. * Added logic to normalize and validate command names and account levels, as well as improved error handling for invalid account IDs. * Enhanced command permission checking: `IsCommandAllowed` now considers both the account ID and the specific command, supporting per-account and default command lists. * Added methods to associate command metadata and handler information, enabling more detailed permission and command tracking.
1 parent 7514e2f commit 38ebd41

File tree

5 files changed

+550
-44
lines changed

5 files changed

+550
-44
lines changed

.github/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# GM Commands Module
2+
3+
This module lets you curate the set of chat commands that selected accounts can use without granting them the full GM security level. It hooks into the AzerothCore command system to hide or block commands that are not explicitly whitelisted, while still enforcing the regular command security for every other player.
4+
5+
## Capabilities
6+
- Manage a list of account IDs controlled by the module.
7+
- Assign a shared default GM level and default command list for those accounts.
8+
- Override the GM level or allowed commands per account.
9+
- Allow commands that normally require a higher security level when they are explicitly whitelisted.
10+
- Always allow commands that require security level `SEC_PLAYER` (0).
11+
12+
## Configuration Files
13+
The module looks for its configuration in both `modules/mod_gm_commands.conf.dist` and `modules/mod_gm_commands.conf` inside your server configuration directory (for example `env/dist/etc/modules/`).
14+
15+
When the server starts (or the config is reloaded), the module reads `.conf.dist` first and then `.conf`. Keys present in the non-`.dist` file override the defaults. This allows you to keep personal changes out of version control while still benefiting from distribution updates.
16+
17+
### Required Keys
18+
- `GmCommandsModule.Enable`: Set to `1` to activate the module.
19+
- `GmCommandsModule.AccountIds`: Comma-separated list of account IDs that the module manages. Only accounts in this list are affected.
20+
21+
### Optional Defaults
22+
- `GmCommandsModule.DefaultLevel`: GM level applied to managed accounts that do not define their own level. Clamped between `SEC_PLAYER (0)` and `SEC_ADMINISTRATOR (3)`.
23+
- `GmCommandsModule.DefaultCommands`: Comma-separated list of commands granted to managed accounts that do not define their own command list. Commands that require level 0 are still automatically available even if they are not listed.
24+
25+
### Per-Account Overrides
26+
Use the following keys to override defaults for a specific account, replacing `<AccountId>` with the numeric ID:
27+
- `GmCommandsModule.Account.<AccountId>.Level`
28+
- `GmCommandsModule.Account.<AccountId>.Commands`
29+
30+
Both files (`mod_gm_commands.conf.dist` and `mod_gm_commands.conf`) are scanned, so you may define an override in either place. Values found in the non-`.dist` file take precedence.
31+
32+
#### Command List Formatting
33+
Commands are stored in a normalized, lowercase form:
34+
- Trim spaces around each entry.
35+
- Collapse multiple inner spaces to a single space.
36+
- Use the full chat command path. For example, the command shown in chat as `.character level` must be written as `character level`; `levelup` can be listed as-is because it is a top-level command.
37+
38+
You can list multi-word commands exactly as they appear after the leading dot, separated by commas:
39+
```
40+
GmCommandsModule.Account.3.Commands = "character level, character rename, levelup, gm visible"
41+
```
42+
43+
## Runtime Behaviour
44+
- When a GM account uses a command, the module records the command name and its required security level.
45+
- If an account is in the managed list and the command requires more than `SEC_PLAYER`, the module checks the whitelist before the core performs its visibility/security check.
46+
- Whitelisted commands return early from the visibility hook, effectively bypassing the security-level requirement for that account. Non-whitelisted commands continue through the normal core checks and are blocked with “You are not allowed to use this command.”
47+
- The module logs the resolved default settings and per-account overrides at startup (log channel `modules.gmcommands`) to aid troubleshooting.
48+
49+
## Reloading Configuration
50+
After editing the configuration, either restart the worldserver or run `.reload config` from a GM account with adequate privileges. The module will re-read both configuration files and log the updated account summaries.
51+
52+
## Troubleshooting
53+
- Ensure the account ID is listed in `GmCommandsModule.AccountIds`; otherwise the account is ignored.
54+
- Use the full command name (including subcommand structure) in the whitelist. If a command still reports “does not exist,” verify the spelling and normalization.
55+
- Check the worldserver log for `modules.gmcommands` entries to confirm that the module picked up your overrides.
56+
- Commands that require only `SEC_PLAYER` never need to be listed; if users cannot run them, the issue lies elsewhere (permissions, syntax, etc.).
57+
58+
## Example
59+
```
60+
GmCommandsModule.Enable = 1
61+
GmCommandsModule.AccountIds = "3,4"
62+
GmCommandsModule.DefaultLevel = 0
63+
GmCommandsModule.DefaultCommands = "go"
64+
65+
GmCommandsModule.Account.3.Level = 1
66+
GmCommandsModule.Account.3.Commands = "character level, levelup, gm, gm visible"
67+
68+
GmCommandsModule.Account.4.Commands = "appeal, go, ticket"
69+
```
70+
71+
In this example account 3 keeps security level 1 but can run `character level` and `levelup`, while account 4 inherits the default security level (0) yet receives a custom command list.
72+
73+
## Development Notes
74+
The implementation lives in `src/GmCommands.cpp` and exposes a singleton (`sGMCommands`) responsible for:
75+
- Loading overrides from `sConfigMgr` and the module config files.
76+
- Normalizing command names and caching per-command required security.
77+
- Hooking `AllCommandScript` to hide or allow commands based on the configured whitelist.
78+
79+
Any changes to the command registry should keep the normalization logic in mind so that configuration values remain compatible.

conf/mod_gm_commands.conf.dist

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,41 @@ GmCommandsModule.Enable = 1
1818

1919
#
2020
# GmCommandsModule.AccountIds
21-
# Description: Allow the specified accounts to use commands. Separated by comma
22-
#
21+
# Description: Comma separated list of account identifiers that should be managed by this module.
22+
# Each listed account can optionally define a custom GM level or custom command list.
2323
#
2424

2525
GmCommandsModule.AccountIds = ""
2626

2727
#
28+
# GmCommandsModule.DefaultLevel
29+
# Description: Default GM level assigned to managed accounts that do not define their own level.
30+
# The value is clamped between SEC_PLAYER (0) and SEC_ADMINISTRATOR (3).
31+
# Default: 0 - SEC_PLAYER
2832
#
29-
# GmCommandsModule.AllowedCommands
30-
# Description: Allow the specified commands to be used. Separated by comma.
33+
34+
GmCommandsModule.DefaultLevel = 0
35+
3136
#
37+
# GmCommandsModule.DefaultCommands
38+
# Description: Default comma separated list of commands (case-insensitive) allowed to managed accounts
39+
# when a specific command list is not defined for the account. Commands that require
40+
# security level 0 are always allowed.
41+
# Default: ""
3242
#
3343

34-
GmCommandsModule.AllowedCommands = ""
44+
GmCommandsModule.DefaultCommands = ""
45+
46+
#
47+
# Per-account overrides
48+
#
49+
# GmCommandsModule.Account.<AccountId>.Level
50+
# Description: Override the GM level for the specified account id.
51+
# Omit this entry to use `GmCommandsModule.DefaultLevel`.
52+
# Example: GmCommandsModule.Account.42.Level = 2
53+
#
54+
# GmCommandsModule.Account.<AccountId>.Commands
55+
# Description: Override the allowed commands for the specified account id. Provide a comma
56+
# separated, case-insensitive list. Leave unset to inherit `GmCommandsModule.DefaultCommands`.
57+
# Example: GmCommandsModule.Account.42.Commands = "gm, gm visible, account"
58+
#

0 commit comments

Comments
 (0)