ClientCommand: Difference between revisions
Jump to navigation
Jump to search
Biohazard 90 (talk | contribs) mNo edit summary |
(Gender neutral pronouns) |
||
Line 1: | Line 1: | ||
The [[function]] ClientCommand() can be found in the [[CBasePlayer|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 | The [[function]] ClientCommand() can be found in the [[CBasePlayer|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. | ||
Revision as of 00:20, 2 February 2023
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;
}
[...]
}