Skip to content

Commit 24451a8

Browse files
committed
feat: Implement presets for GM commands configuration with detailed precedence rules
1 parent 38ebd41 commit 24451a8

File tree

4 files changed

+284
-43
lines changed

4 files changed

+284
-43
lines changed

README.md

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ This module lets you curate the set of chat commands that selected accounts can
44

55
## Capabilities
66
- Manage a list of account IDs controlled by the module.
7-
- Assign a shared default GM level and default command list for those accounts.
7+
- Define reusable presets with specific GM levels and command lists.
8+
- Assign presets to accounts for consistent configuration management.
9+
- Assign a shared default GM level and default command list for accounts without presets.
810
- Override the GM level or allowed commands per account.
911
- Allow commands that normally require a higher security level when they are explicitly whitelisted.
1012
- Always allow commands that require security level `SEC_PLAYER` (0).
1113

14+
## Configuration Precedence
15+
The module follows a clear precedence hierarchy when resolving the effective configuration for each account:
16+
17+
1. **Default settings** (lowest priority): `GmCommandsModule.DefaultLevel` and `GmCommandsModule.DefaultCommands`
18+
2. **Preset settings**: If a preset is assigned to an account via `GmCommandsModule.Account.<AccountId>.Preset`, its level and commands override the defaults
19+
3. **Per-account overrides** (highest priority): `GmCommandsModule.Account.<AccountId>.Level` and `GmCommandsModule.Account.<AccountId>.Commands` override everything else
20+
1221
## Configuration Files
1322
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/`).
1423

@@ -22,12 +31,19 @@ When the server starts (or the config is reloaded), the module reads `.conf.dist
2231
- `GmCommandsModule.DefaultLevel`: GM level applied to managed accounts that do not define their own level. Clamped between `SEC_PLAYER (0)` and `SEC_ADMINISTRATOR (3)`.
2332
- `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.
2433

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`
34+
### Presets
35+
Presets allow you to define reusable configurations that can be assigned to multiple accounts:
36+
- `GmCommandsModule.Presets`: Comma-separated list of preset names.
37+
- `GmCommandsModule.Preset.<PresetName>.Level`: GM level for this preset.
38+
- `GmCommandsModule.Preset.<PresetName>.Commands`: Comma-separated list of commands for this preset.
2939

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.
40+
### Account Configuration
41+
Use the following keys to configure specific accounts, replacing `<AccountId>` with the numeric ID:
42+
- `GmCommandsModule.Account.<AccountId>.Preset`: Assign a preset to this account. Only one preset per account is allowed.
43+
- `GmCommandsModule.Account.<AccountId>.Level`: Override the preset or default level for this account (highest priority).
44+
- `GmCommandsModule.Account.<AccountId>.Commands`: Override the preset or default commands for this account (highest priority).
45+
46+
Both files (`mod_gm_commands.conf.dist` and `mod_gm_commands.conf`) are scanned, so you may define configuration in either place. Values found in the non-`.dist` file take precedence.
3147

3248
#### Command List Formatting
3349
Commands are stored in a normalized, lowercase form:
@@ -43,32 +59,57 @@ GmCommandsModule.Account.3.Commands = "character level, character rename, levelu
4359
## Runtime Behaviour
4460
- When a GM account uses a command, the module records the command name and its required security level.
4561
- 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.
62+
- 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."
63+
- The module logs the resolved configuration (defaults → preset → overrides) for each account at startup (log channel `modules.gmcommands`) to aid troubleshooting.
4864

4965
## Reloading Configuration
5066
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.
5167

5268
## Troubleshooting
5369
- 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.
70+
- Use the full command name (including subcommand structure) in the whitelist. If a command still reports "does not exist," verify the spelling and normalization.
71+
- Check the worldserver log for `modules.gmcommands` entries to confirm that the module picked up your presets, assignments, and overrides.
72+
- If a preset is assigned but the account is not configured as expected, verify that the preset name is listed in `GmCommandsModule.Presets` and that the preset definition exists.
5673
- Commands that require only `SEC_PLAYER` never need to be listed; if users cannot run them, the issue lies elsewhere (permissions, syntax, etc.).
5774

5875
## Example
5976
```
6077
GmCommandsModule.Enable = 1
61-
GmCommandsModule.AccountIds = "3,4"
78+
GmCommandsModule.AccountIds = "3,4,5"
6279
GmCommandsModule.DefaultLevel = 0
63-
GmCommandsModule.DefaultCommands = "go"
80+
GmCommandsModule.DefaultCommands = ""
81+
82+
# Define presets
83+
GmCommandsModule.Presets = "tv_account, gm_helper"
6484
65-
GmCommandsModule.Account.3.Level = 1
66-
GmCommandsModule.Account.3.Commands = "character level, levelup, gm, gm visible"
85+
GmCommandsModule.Preset.tv_account.Level = 1
86+
GmCommandsModule.Preset.tv_account.Commands = "gm, gm visible, appear, go, teleport, gm fly"
6787
68-
GmCommandsModule.Account.4.Commands = "appeal, go, ticket"
88+
GmCommandsModule.Preset.gm_helper.Level = 2
89+
GmCommandsModule.Preset.gm_helper.Commands = "ticket, summon, learn, gm on, gm off"
90+
91+
# Assign presets to accounts
92+
GmCommandsModule.Account.3.Preset = "tv_account"
93+
GmCommandsModule.Account.4.Preset = "gm_helper"
94+
GmCommandsModule.Account.5.Preset = "tv_account"
95+
96+
# Override commands for account 5 while keeping the preset level
97+
GmCommandsModule.Account.5.Commands = "gm, gm visible, appear, go, teleport, gm fly, gmannounce"
6998
```
7099

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.
100+
In this example:
101+
- Account 3 receives the `tv_account` preset (level 1 with limited commands)
102+
- Account 4 receives the `gm_helper` preset (level 2 with ticket/support commands)
103+
- Account 5 receives the `tv_account` preset level (1) but has an additional command (`gmannounce`) added to its command list
104+
105+
## Development Notes
106+
The implementation lives in `src/GmCommands.cpp` and exposes a singleton (`sGMCommands`) responsible for:
107+
- Loading presets and per-account configurations from `sConfigMgr` and the module config files.
108+
- Building effective configurations by applying precedence rules (defaults → presets → overrides).
109+
- Normalizing command names and caching per-command required security.
110+
- Hooking `AllCommandScript` to hide or allow commands based on the configured whitelist.
111+
112+
Any changes to the command registry should keep the normalization logic in mind so that configuration values remain compatible.
72113

73114
## Development Notes
74115
The implementation lives in `src/GmCommands.cpp` and exposes a singleton (`sGMCommands`) responsible for:

conf/mod_gm_commands.conf.dist

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,67 @@ GmCommandsModule.DefaultLevel = 0
4444
GmCommandsModule.DefaultCommands = ""
4545

4646
#
47-
# Per-account overrides
47+
# Presets
48+
#
49+
# GmCommandsModule.Presets
50+
# Description: Comma separated list of preset names. Each preset can define a level and command list
51+
# that can be assigned to one or more accounts.
52+
# Default: ""
53+
#
54+
55+
GmCommandsModule.Presets = ""
56+
57+
#
58+
# GmCommandsModule.Preset.<PresetName>.Level
59+
# Description: GM level for this preset. Value is clamped between SEC_PLAYER (0) and SEC_ADMINISTRATOR (3).
60+
# Example: GmCommandsModule.Preset.tv_account.Level = 1
61+
#
62+
# GmCommandsModule.Preset.<PresetName>.Commands
63+
# Description: Comma separated, case-insensitive list of commands allowed for this preset.
64+
# Example: GmCommandsModule.Preset.tv_account.Commands = "gm, gm visible, appear, go, teleport, gm fly"
65+
#
66+
67+
#
68+
# Account configuration
69+
#
70+
# Precedence: Defaults (lowest) < Preset < Per-account overrides (highest)
71+
#
72+
# GmCommandsModule.Account.<AccountId>.Preset
73+
# Description: Assign a preset to this account. The preset's level and commands will be applied.
74+
# Only one preset per account is allowed; multiple assignments will log a warning.
75+
# Example: GmCommandsModule.Account.42.Preset = "tv_account"
4876
#
4977
# GmCommandsModule.Account.<AccountId>.Level
50-
# Description: Override the GM level for the specified account id.
51-
# Omit this entry to use `GmCommandsModule.DefaultLevel`.
78+
# Description: Override the GM level for the specified account id. This takes precedence over
79+
# the preset level and the default level.
5280
# Example: GmCommandsModule.Account.42.Level = 2
5381
#
5482
# 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`.
83+
# Description: Override the allowed commands for the specified account id. This takes precedence
84+
# over the preset commands and the default commands. Provide a comma separated,
85+
# case-insensitive list.
5786
# Example: GmCommandsModule.Account.42.Commands = "gm, gm visible, account"
5887
#
88+
89+
#
90+
# Example configuration with presets:
91+
#
92+
# GmCommandsModule.Enable = 1
93+
# GmCommandsModule.AccountIds = "3,4,5"
94+
# GmCommandsModule.DefaultLevel = 0
95+
# GmCommandsModule.DefaultCommands = ""
96+
#
97+
# GmCommandsModule.Presets = "tv_account, gm_helper"
98+
#
99+
# GmCommandsModule.Preset.tv_account.Level = 1
100+
# GmCommandsModule.Preset.tv_account.Commands = "gm, gm visible, appear, go, teleport, gm fly"
101+
#
102+
# GmCommandsModule.Preset.gm_helper.Level = 2
103+
# GmCommandsModule.Preset.gm_helper.Commands = "ticket, summon, learn, gm on, gm off"
104+
#
105+
# GmCommandsModule.Account.3.Preset = "tv_account"
106+
# GmCommandsModule.Account.4.Preset = "gm_helper"
107+
# GmCommandsModule.Account.5.Preset = "tv_account"
108+
# GmCommandsModule.Account.5.Commands = "gm, gm visible, appear, go, teleport, gm fly, gmannounce"
109+
#
110+

0 commit comments

Comments
 (0)