Skip to content

Fixes #3655 - prevent duplicate command registration #4313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

MohabCodeX
Copy link
Contributor

Fixes #3655
This PR makes addCommandHandler reject any duplicate command names whether they're in the same resource or across different ones. So if a command like "test" is already registered in one resource, trying to register it again (even in the same resource) will fail with a warning in debugscript 3. For example, if Resource A registers "kick", Resource B (or even A again) won’t be able to override it. It's a solid security improvement that ensures predictable command behavior and prevents hijacking or conflicts with minimal changes.
⚠️ Heads up: any existing resources with duplicate commands will now fail to register them so devs may need to audit and rename conflicting ones.
image

@ffsPLASMA
Copy link
Contributor

I am against this PR, there are valid reasons to bind multiple functions to a single command.

@MegadreamsBE
Copy link
Member

I am against this PR, there are valid reasons to bind multiple functions to a single command.

Should be configurable at the very least

@MohabCodeX
Copy link
Contributor Author

I agree that sometimes multiple functions may need to be bound to the same command, but this can be handled better by combining them inside a single handler instead of registering several handlers for the same command which is bad practice in most cases.

Making this configurable per server is a good idea, and I can adjust the PR to support that.
Also, something like this should at least have a warning when duplicate handlers are added I know it's a breaking change if it refused the duplicated commands, but the warning would be important for catching accidental duplications.

Thanks for the feedback, I’ll make improvements.

@Fernando-A-Rocha
Copy link
Contributor

Please make it configurable as this is trying to solve a problem that doesn't exist, imo.

I used to have a chatbox resource that, if I remember correctly, made use of multiple command handlers per command. Also there are cases in which you want the same command to be handled clientside and also serverside (idk if this PR considers this).

@Fernando-A-Rocha
Copy link
Contributor

A warning on duplicate command handlers could be useful, I agree.
The config could be:
<allow_multi_command_handlers>
Values: 0, 1, 2
Where 0 is disallow, 1 is allow but with warning, and 2 is allow but no warnings.

@MohabCodeX MohabCodeX force-pushed the commandhandler-controlling branch from 82b5f22 to 2bd4d7e Compare July 28, 2025 22:33
@MohabCodeX
Copy link
Contributor Author

Thank you for all the feedback


Final Outcome: Configurable Duplicate Command Handler Behavior

A new server configuration option has been added:

<allow_multi_command_handlers>1</allow_multi_command_handlers>

This option controls how the system handles multiple addCommandHandler registrations for the same command.

Available Levels:

Value Behavior Debug Output
0 Disallow duplicate command handlers addCommandHandler: Duplicate command registration blocked for '%s' (multiple handlers disabled)
1 (default) ⚠️ Allow with warning addCommandHandler: Attempt to register duplicate command '%s'
2 Allow silently (No debug output)

Default Behavior:

  • The default value is 1, which allows duplicates but emits a warning, helping developers identify unexpected duplicate registrations.

Any other feedback would be appreciated.

@Fernando-A-Rocha
Copy link
Contributor

Nice
When blocking duplicate command handlers I think it should throw a Lua error instead of a warning

MohabCodeX and others added 10 commits July 30, 2025 14:15
• Removed Hungarian notation
• Switched to enum class
• Marked funcs noexcept, moved to header
• Used nullptr instead of NULL
• Added BitStream.Can check
• Minor cleanup: braces, naming
• Updated config templates
• throwing error when blocking duplicate command handlers instead of a warning
• Removed Hungarian notation
• Switched to enum class
• Marked funcs noexcept, moved to header
• Used nullptr instead of NULL
• Added BitStream.Can check
• Minor cleanup: braces, naming
• Updated config templates
• throwing error when blocking duplicate command handlers instead of a warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

addCommandHandler should disallow to create commands with duplicated names
5 participants