registerCmd
(since 1.0)
Register a new server command.
Description
string
registerCmd
(
string name, boolean require_sessid, function fn )
Used to register a new command on the server, this command can then be used by clients.
Parameters
name
The command name
require_sessid
Does this command requires a connected user (is sessid required) ?
fn
This function will be called when an user uses the created command.
- params - (object) The list of parameters sent by the client.
- info - (object) Contains information about the client:
Examples
Ape.registerCmd("foocmd", true, function(params, info) {
Ape.log("The user ip : ("+info.ip+"), foo : " + params.foo);
});
/*
* You can return error in two ways:
* By returning 0 to return a "BAD_PARAMS"
* By returning an array [code, error] for custom errors.
*/
Ape.registerCmd("foocmd", true, function(params, info) {
if (!$defined(params.john)) return 0; // send a "BAD_PARAMS" RAW to the user
if (params.john != "doe") return ["209", "NOT_A_JOHN_DOE"];
return 1;
});
//Return an object to send a raw as response.
Ape.registerCmd( "gettime", true, function(params, info) ) {
return {
name: "TIME",//The raw's name
data: { time: new Date().getTime() }//The raw's data (must be an object)
}
}
User notes
# No comment
Post a note
CollaborAPE to our wiki !
Find the information you need on the APE Official Wiki : Install, Server, JSF, Help...
