sourcemod icon indicating copy to clipboard operation
sourcemod copied to clipboard

Add OnCommandRegistered() forward

Open dragokas opened this issue 3 years ago • 6 comments

Use case: !COMMAND eater.

When some plugin gets dynamically loaded/unloaded we have no way to identify what commands are added other than making a full commands enumeration with a significant CPU cycle loss. We don't even know when to do such enumeration, because no OnPluginLoaded() forward exists at all (second problem).

So, I suggest to add:

forward OnCommandRegistered(char[] name)

forward OnCommandUnregistered(char[] name)

making life much easy.

Thank you.

dragokas avatar Apr 19 '21 09:04 dragokas

Hi! What's your use case for this proposed feature?

Headline avatar Apr 19 '21 12:04 Headline

Adding command name to a global cache for further checking in real time - is particular command exists. CommandExist() doesn't do its job: https://github.com/alliedmodders/sourcemod/issues/1480

dragokas avatar Apr 19 '21 12:04 dragokas

GetCommandIterator is the proper way to do this.

KyleSanderson avatar May 24 '21 22:05 KyleSanderson

There is no way to use GetCommandIterator() to retrieve an updated list of commands just for 1 single and simple check, because it gives like ~0.5-1 second lag to iterate the whole convars and commands list.

dragokas avatar May 24 '21 23:05 dragokas

A global callback for when commands are registered or unregistered sounds acceptable. But it could be very spammy, so I think it would need to be an opt-in thing (eg, so you can do an initial scan on plugin load, and then activate the callback after). Eg, this kind of signature:

// status == true, adding command
// status == false, removing command - bonus points for this being an enum
typedef CommandRegistrationCallback = function void (Handle plugin, const char[] name, bool status);

void AddCommandRegistrationListener(CommandRegistrationCallback callback);

I'd be happy to review a PR for this.

dvander avatar May 24 '21 23:05 dvander

Thanks for the suggestion. I'm writing in C++ very rarely. I'll give a chance to somebody more skilled.

dragokas avatar May 26 '21 20:05 dragokas