ClientCommand
Jump to navigation
Jump to search
This article is an orphan, meaning that few or no articles link to it.
You can help by adding links to this article from other relevant articles.
January 2024
You can help by adding links to this article from other relevant articles.
January 2024
The function ClientCommand() can be found in the player classes of the server project and is executed when it is not possible to resolve an incoming command string from a client in any other way (for example through a ConCommand). Returning the value 'false' will cause the server to tell the respective client that their command was supposedly invalid.
The client uses the function engine->ServerCmd() to trigger ClientCommand() on the server and can even optionally pass information along in the string:
void SelectClass( int iClassIndex ) // a function on the client
{
engine->ServerCmd( VarArgs( "selectclass %i", iClassIndex ) ); // sent to the server
}
The following snippet of code shows how the command selectclass is handled by the server:
bool CSDKPlayer::ClientCommand( const CCommand &args )
{
if ( FStrEq( pcmd, "selectclass" ) ) // this is our command name
{
if ( args.ArgC() < 2 ) // make sure that an argument was passed along
{
Warning( "bad selectclass cmd\n" );
return true;
}
int iIndex = atoi( args[1] ); // convert our argument back to an integer
HandleClassSelection( iIndex );
return true;
}
[...]
}