Dev:Command API

Registering a new command
Syntax: Command *CommandAdd(Module *module, const char *cmd, CmdFunc func, unsigned char params, int flags); flags available:
 * module - The module this command is associated with
 * cmd - The text of the command
 * func - A function pointer to be called when this function is executed (will explained later)
 * params - The number of parameters this command accepts, use MAXPARA to accept up to maximum.
 * flags - The flags for this new command decide who may execute the command. Multiple flags are OR'ed together.

Example: CMD_FUNC(mymod_test); /* Forward declaration */

MOD_INIT(mymod) {   CommandAdd(modinfo->handle, "TEST", mymod_test, MAXPARA, CMD_USER|CMD_SERVER); }

You should always add all your commands in MOD_INIT and never in MOD_LOAD.

The actual command function
Example: CMD_FUNC(mymod_test) {   sendnotice(client, "Thanks for testing"); }

The CMD_FUNC macro of UnrealIRCd will provide the following parameters:

Client information
For more information on the contents of client, see Common structures in the doxygen documentation. In particular, the Client struct documentation which shows you the meaning of all fields.

Parameter checking
Safe operation on parc and parv is important and may be slightly confusing if you're new. Here's an example: if you execute  then parc will be 2 and parv[1] will contain the string lalala.

Most code in UnrealIRCd checks such things as follows: CMD_FUNC(mymod_test) {   if ((parc < 3) || BadPtr(parv[2])) {       sendnotice(client, "Error: Two parameter required"); return; }   sendnotice(client, "Thanks for testing with the following two parameter: '%s' and '%s'", parv[1], parv[2]); }