Browse Source

Port restricted cmds and cvars from old engine. TODO: implement better stufftext filter

pull/2/head
Alibek Omarov 7 years ago
parent
commit
5a449a56ea
  1. 160
      engine/common/cmd.c
  2. 2
      engine/common/crtlib.h
  3. 1
      engine/common/cvar.h

160
engine/common/cmd.c

@ -603,32 +603,40 @@ void Cmd_TokenizeString( char *text ) @@ -603,32 +603,40 @@ void Cmd_TokenizeString( char *text )
/*
============
Cmd_AddCommand
Cmd_AddCommandEx
============
*/
void Cmd_AddCommand( const char *cmd_name, xcommand_t function, const char *cmd_desc )
static int Cmd_AddCommandEx( const char *funcname, const char *cmd_name, xcommand_t function,
const char *cmd_desc, int iFlags )
{
cmd_t *cmd, *cur, *prev;
if( !cmd_name || !*cmd_name )
{
MsgDev( D_ERROR, "Cmd_AddServerCommand: NULL name\n" );
return 0;
}
// fail if the command is a variable name
if( Cvar_FindVar( cmd_name ))
{
Con_Printf( S_ERROR "Cmd_AddCommand: %s already defined as a var\n", cmd_name );
return;
MsgDev( D_ERROR, "Cmd_AddServerCommand: %s already defined as a var\n", cmd_name );
return 0;
}
// fail if the command already exists
if( Cmd_Exists( cmd_name ))
{
Con_Printf( S_ERROR "Cmd_AddCommand: %s already defined\n", cmd_name );
return;
MsgDev( D_ERROR, "Cmd_AddServerCommand: %s already defined\n", cmd_name );
return 0;
}
// use a small malloc to avoid zone fragmentation
cmd = Z_Malloc( sizeof( cmd_t ));
cmd = Z_Malloc( sizeof( cmd_t ) );
cmd->name = copystring( cmd_name );
cmd->desc = copystring( cmd_desc );
cmd->function = function;
cmd->flags = iFlags;
// insert it at the right alphanumeric position
for( prev = NULL, cur = cmd_functions; cur && Q_strcmp( cur->name, cmd_name ) < 0; prev = cur, cur = cur->next );
@ -636,50 +644,42 @@ void Cmd_AddCommand( const char *cmd_name, xcommand_t function, const char *cmd_ @@ -636,50 +644,42 @@ void Cmd_AddCommand( const char *cmd_name, xcommand_t function, const char *cmd_
if( prev ) prev->next = cmd;
else cmd_functions = cmd;
cmd->next = cur;
#if defined(XASH_HASHED_VARS)
BaseCmd_Insert( HM_CMD, cmd, cmd->name );
#endif
return 1;
}
/*
============
Cmd_AddServerCommand
Cmd_AddCommand
============
*/
void Cmd_AddServerCommand( const char *cmd_name, xcommand_t function )
void Cmd_AddCommand( const char *cmd_name, xcommand_t function, const char *cmd_desc )
{
cmd_t *cmd, *cur, *prev;
if( !cmd_name || !*cmd_name )
{
MsgDev( D_ERROR, "Cmd_AddServerCommand: NULL name\n" );
return;
}
// fail if the command is a variable name
if( Cvar_FindVar( cmd_name ))
{
MsgDev( D_ERROR, "Cmd_AddServerCommand: %s already defined as a var\n", cmd_name );
return;
}
// fail if the command already exists
if( Cmd_Exists( cmd_name ))
{
MsgDev( D_ERROR, "Cmd_AddServerCommand: %s already defined\n", cmd_name );
return;
}
// use a small malloc to avoid zone fragmentation
cmd = Z_Malloc( sizeof( cmd_t ));
cmd->name = copystring( cmd_name );
cmd->desc = copystring( "server command" );
cmd->function = function;
cmd->flags = CMD_SERVERDLL;
Cmd_AddCommandEx( __FUNCTION__, cmd_name, function, cmd_desc, 0 );
}
// insert it at the right alphanumeric position
for( prev = NULL, cur = cmd_functions; cur && Q_strcmp( cur->name, cmd_name ) < 0; prev = cur, cur = cur->next );
/*
============
Cmd_AddRestrictedCommand
============
*/
void Cmd_AddRestrictedCommand( const char *cmd_name, xcommand_t function, const char *cmd_desc )
{
Cmd_AddCommandEx( __FUNCTION__, cmd_name, function, cmd_desc, CMD_LOCALONLY );
}
if( prev ) prev->next = cmd;
else cmd_functions = cmd;
cmd->next = cur;
/*
============
Cmd_AddServerCommand
============
*/
void Cmd_AddServerCommand( const char *cmd_name, xcommand_t function )
{
Cmd_AddCommandEx( __FUNCTION__, cmd_name, function, "server command", CMD_SERVERDLL );
}
/*
@ -689,43 +689,7 @@ Cmd_AddClientCommand @@ -689,43 +689,7 @@ Cmd_AddClientCommand
*/
int Cmd_AddClientCommand( const char *cmd_name, xcommand_t function )
{
cmd_t *cmd, *cur, *prev;
if( !cmd_name || !*cmd_name )
{
MsgDev( D_ERROR, "Cmd_AddClientCommand: NULL name\n" );
return 0;
}
// fail if the command is a variable name
if( Cvar_FindVar( cmd_name ))
{
MsgDev( D_ERROR, "Cmd_AddClientCommand: %s already defined as a var\n", cmd_name );
return 0;
}
// fail if the command already exists
if( Cmd_Exists( cmd_name ))
{
MsgDev( D_ERROR, "Cmd_AddClientCommand: %s already defined\n", cmd_name );
return 0;
}
// use a small malloc to avoid zone fragmentation
cmd = Z_Malloc( sizeof( cmd_t ));
cmd->name = copystring( cmd_name );
cmd->desc = copystring( "client command" );
cmd->function = function;
cmd->flags = CMD_CLIENTDLL;
// insert it at the right alphanumeric position
for( prev = NULL, cur = cmd_functions; cur && Q_strcmp( cur->name, cmd_name ) < 0; prev = cur, cur = cur->next );
if( prev ) prev->next = cmd;
else cmd_functions = cmd;
cmd->next = cur;
return 1;
return Cmd_AddCommandEx( __FUNCTION__, cmd_name, function, "server command", CMD_CLIENTDLL );
}
/*
@ -735,43 +699,7 @@ Cmd_AddGameUICommand @@ -735,43 +699,7 @@ Cmd_AddGameUICommand
*/
int Cmd_AddGameUICommand( const char *cmd_name, xcommand_t function )
{
cmd_t *cmd, *cur, *prev;
if( !cmd_name || !*cmd_name )
{
MsgDev( D_ERROR, "Cmd_AddGameUICommand: NULL name\n" );
return 0;
}
// fail if the command is a variable name
if( Cvar_FindVar( cmd_name ))
{
MsgDev( D_ERROR, "Cmd_AddGameUICommand: %s already defined as a var\n", cmd_name );
return 0;
}
// fail if the command already exists
if( Cmd_Exists( cmd_name ))
{
MsgDev( D_ERROR, "Cmd_AddGameUICommand: %s already defined\n", cmd_name );
return 0;
}
// use a small malloc to avoid zone fragmentation
cmd = Z_Malloc( sizeof( cmd_t ));
cmd->name = copystring( cmd_name );
cmd->desc = copystring( "GameUI command" );
cmd->function = function;
cmd->flags = CMD_GAMEUIDLL;
// insert it at the right alphanumeric position
for( prev = NULL, cur = cmd_functions; cur && Q_strcmp( cur->name, cmd_name ) < 0; prev = cur, cur = cur->next );
if( prev ) prev->next = cmd;
else cmd_functions = cmd;
cmd->next = cur;
return 1;
return Cmd_AddCommandEx( __FUNCTION__, cmd_name, function, "server command", CMD_GAMEUIDLL );
}
/*

2
engine/common/crtlib.h

@ -36,6 +36,7 @@ enum @@ -36,6 +36,7 @@ enum
#define CMD_SERVERDLL BIT( 0 ) // added by server.dll
#define CMD_CLIENTDLL BIT( 1 ) // added by client.dll
#define CMD_GAMEUIDLL BIT( 2 ) // added by GameUI.dll
#define CMD_LOCALONLY BIT( 3 ) // restricted from server commands
typedef void (*xcommand_t)( void );
@ -54,6 +55,7 @@ const char *Cmd_Argv( int arg ); @@ -54,6 +55,7 @@ const char *Cmd_Argv( int arg );
void Cmd_Init( void );
void Cmd_Unlink( int group );
void Cmd_AddCommand( const char *cmd_name, xcommand_t function, const char *cmd_desc );
void Cmd_AddRestrictedCommand( const char *cmd_name, xcommand_t function, const char *cmd_desc );
void Cmd_AddServerCommand( const char *cmd_name, xcommand_t function );
int Cmd_AddClientCommand( const char *cmd_name, xcommand_t function );
int Cmd_AddGameUICommand( const char *cmd_name, xcommand_t function );

1
engine/common/cvar.h

@ -43,6 +43,7 @@ typedef struct convar_s @@ -43,6 +43,7 @@ typedef struct convar_s
#define FCVAR_ALLOCATED (1<<19) // this convar_t is fully dynamic allocated (include description)
#define FCVAR_VIDRESTART (1<<20) // recreate the window is cvar with this flag was changed
#define FCVAR_TEMPORARY (1<<21) // these cvars holds their values and can be unlink in any time
#define FCVAR_LOCALONLY (1<<22) // can be set only from local buffers
#define CVAR_DEFINE( cv, cvname, cvstr, cvflags, cvdesc ) convar_t cv = { cvname, cvstr, cvflags, 0.0f, (void *)CVAR_SENTINEL, cvdesc }
#define CVAR_DEFINE_AUTO( cv, cvstr, cvflags, cvdesc ) convar_t cv = { #cv, cvstr, cvflags, 0.0f, (void *)CVAR_SENTINEL, cvdesc }

Loading…
Cancel
Save