Tip of the day: The Security article gives hands-on tips on how to deal with drone attacks, flooding, spammers, (D)DoS and more. |
Dev:Command Overrides
Command overrides allow you to "override" a core command (or a command from other modules). Your code will then execute either before or after the actual command is executed. Or, you can choose not to execute the real command at all.
Generally people prefer the Dev:Hook API as it's more fine-grained and requires less work on your hand. People generally revert to Command Override's if Hooks do not provide (all) the functionality they are looking for.
About the variables available via CMD_OVERRIDE_FUNC
For command overrides we will use the CMD_OVERRIDE_FUNC()
macro. These are the variables that you will receive in your override handler in your module:
Variable | Type | Description |
---|---|---|
ovr | CommandOverride * | The override information, usually not touched, except for passing to CallCommandOverride() |
client | Client * | Client pointer of user executing the command. |
recv_mtags | MessageTag * | Message tags associated with the command. If you don't know what this is then just ignore it for now. |
parc | int | Command + parameter count |
parv | char *[] | Parameters |
Registering your command override
Registering your override is easy. Example:
CMD_OVERRIDE_FUNC(mymod_nickoverride); /* Forward declaration */ MOD_LOAD(mymod) { CmdoverrideAdd(modinfo->handle, "NICK", mymod_nickoverride); }
The command override function
Generally you want your code to execute before the real (core?) function is called:
CMD_OVERRIDE_FUNC(mymod_nickoverride) { sendnotice(client, "We are about to call the real function. We could do something useful here."); return CallCommandOverride(ovr, client, recv_mtags, parc, parv); // call the real function and return it's return value }
If you want to execute your function after this is also possible, it just takes some extra care:
CMD_OVERRIDE_FUNC(mymod_nickoverride) { CallCommandOverride(ovr, client, recv_mtags, parc, parv); // call the real function if (IsDead(client)) return; /* killed or client exited, we MUST return */ sendnotice(client, "The command was executed. We could do something useful here afterwards."); }
More information
For more information on parc and parv[], see Dev:Command_API#Parameter_checking
You can also look at the source of other modules or UnrealIRCd itself. Overrides are used in the hideserver module, restrict-commands and in the antimixedutf8 module.