I built a general purpose server/client command registration and dispatch system for the mean bot/admin mod, there's a few hundred lines of code which is too much to post in here, but here's some bits which show how I get agruments for custom server and client commands. Each command that is executed, is passed an array of strings "vtxArgList" (in my case using the standard C++ string class, not the C style strings). The nice part about this system is ALL my custom commands use the exact same argument header and dispatch function. In otherwords, I only register one standard dispatch function associated with each command name. When a server command is executed, it calls the dispatch function, the dispatch function then looks up the command in an array of registered commands (which include security settings and other nice things). When a match is found, it gets the arguments and passes it to the custom command function as a standard array of strings. From there, the custom command function simply does whatever it is supposed to do using as its arguments the array of strings. It's VERY simple to use, but was a bit complicated to figure out at first. I've been using it for so long now I've almost forgottem how it works!
Anyway here's the code that gets the arguments, hope you can read the non standard naming convention I've been using
Code:
int finGetCmdLineArgCount( void )
{ // returns number of command line arguments including the command itself;
return CMD_ARGC();
}
string ftxGetCmdLineArgValue( int pinIdx )
{
return CMD_ARGV( pinIdx );
}
string ftxGetCmdLineString( void )
{ // returns the command line argument list;
// does *not* include the command portion;
return CMD_ARGS( );
}
void tclCommand::fvoGetArgs( void )
{
vinNumArgs = finGetCmdLineArgCount( );
if ( vinNumArgs > cinMaxArgs )
// ensure our buffer does not overflow
vinNumArgs = cinMaxArgs;
else
if ( vinNumArgs < cinMinArgs )
// ensure our buffer does not overflow
vinNumArgs = cinMinArgs;
int vinIdx;
for ( vinIdx = 0; vinIdx < vinNumArgs; vinIdx++ )
{
vtxArgList[ vinIdx ] = ftxGetCmdLineArgValue( vinIdx );
fvoToLower( vtxArgList[ vinIdx ] );
}
for (; vinIdx <= cinMaxArg_Idx; vinIdx++ )
{
vtxArgList[ vinIdx ] = "";
}
if ( vinNumArgs > 1 )
{
vtxArgString = ftxGetCmdLineString( );
}
else
{
vtxArgString.erase( );
}
} // tclCommand::fvoGetArgs