summaryrefslogtreecommitdiff
path: root/src/game/g_svcmds.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2002-09-09 23:32:27 +0000
committerTim Angus <tim@ngus.net>2002-09-09 23:32:27 +0000
commitc0e95997d9e9fcaa220704c8c67b50d6761d1b66 (patch)
tree307242d290de1715df0f4f28dd7e08ccb7006f5c /src/game/g_svcmds.c
parent9af7c524043a8f296ea5f45ec7f73c16e29921b5 (diff)
* General tidy up and beautification of code
* Removal of most of the legacy Q3A stuff * Cursor no longer displayed on load screen * (Biggest commit EVAR?)
Diffstat (limited to 'src/game/g_svcmds.c')
-rw-r--r--src/game/g_svcmds.c364
1 files changed, 202 insertions, 162 deletions
diff --git a/src/game/g_svcmds.c b/src/game/g_svcmds.c
index 3fb05cf8..7386d90b 100644
--- a/src/game/g_svcmds.c
+++ b/src/game/g_svcmds.c
@@ -59,47 +59,48 @@ typedef struct ipFilter_s
#define MAX_IPFILTERS 1024
-static ipFilter_t ipFilters[MAX_IPFILTERS];
-static int numIPFilters;
+static ipFilter_t ipFilters[ MAX_IPFILTERS ];
+static int numIPFilters;
/*
=================
StringToFilter
=================
*/
-static qboolean StringToFilter (char *s, ipFilter_t *f)
+static qboolean StringToFilter( char *s, ipFilter_t *f )
{
- char num[128];
+ char num[ 128 ];
int i, j;
- byte b[4];
- byte m[4];
+ byte b[ 4 ];
+ byte m[ 4 ];
- for (i=0 ; i<4 ; i++)
+ for( i = 0; i < 4; i++ )
{
- b[i] = 0;
- m[i] = 0;
+ b[ i ] = 0;
+ m[ i ] = 0;
}
- for (i=0 ; i<4 ; i++)
+ for( i = 0; i < 4; i++ )
{
- if (*s < '0' || *s > '9')
+ if( *s < '0' || *s > '9' )
{
G_Printf( "Bad filter address: %s\n", s );
return qfalse;
}
j = 0;
- while (*s >= '0' && *s <= '9')
- {
- num[j++] = *s++;
- }
- num[j] = 0;
- b[i] = atoi(num);
- if (b[i] != 0)
- m[i] = 255;
-
- if (!*s)
+ while( *s >= '0' && *s <= '9' )
+ num[ j++ ] = *s++;
+
+ num[ j ] = 0;
+ b[ i ] = atoi( num );
+
+ if( b[ i ] != 0 )
+ m[ i ] = 255;
+
+ if( !*s )
break;
+
s++;
}
@@ -114,21 +115,22 @@ static qboolean StringToFilter (char *s, ipFilter_t *f)
UpdateIPBans
=================
*/
-static void UpdateIPBans (void)
+static void UpdateIPBans( void )
{
- byte b[4];
+ byte b[ 4 ];
int i;
- char iplist[MAX_INFO_STRING];
+ char iplist[ MAX_INFO_STRING ];
*iplist = 0;
- for (i = 0 ; i < numIPFilters ; i++)
+
+ for( i = 0 ; i < numIPFilters ; i++ )
{
- if (ipFilters[i].compare == 0xffffffff)
+ if( ipFilters[ i ].compare == 0xffffffff )
continue;
- *(unsigned *)b = ipFilters[i].compare;
- Com_sprintf( iplist + strlen(iplist), sizeof(iplist) - strlen(iplist),
- "%i.%i.%i.%i ", b[0], b[1], b[2], b[3]);
+ *(unsigned *)b = ipFilters[ i ].compare;
+ Com_sprintf( iplist + strlen( iplist ), sizeof( iplist ) - strlen( iplist ),
+ "%i.%i.%i.%i ", b[ 0 ], b[ 1 ], b[ 2 ], b[ 3 ] );
}
trap_Cvar_Set( "g_banIPs", iplist );
@@ -139,30 +141,34 @@ static void UpdateIPBans (void)
G_FilterPacket
=================
*/
-qboolean G_FilterPacket (char *from)
+qboolean G_FilterPacket( char *from )
{
- int i;
+ int i;
unsigned in;
- byte m[4];
- char *p;
+ byte m[ 4 ];
+ char *p;
i = 0;
p = from;
- while (*p && i < 4) {
- m[i] = 0;
- while (*p >= '0' && *p <= '9') {
- m[i] = m[i]*10 + (*p - '0');
+ while( *p && i < 4 )
+ {
+ m[ i ] = 0;
+ while( *p >= '0' && *p <= '9' )
+ {
+ m[ i ] = m[ i ] * 10 + ( *p - '0' );
p++;
}
- if (!*p || *p == ':')
+
+ if( !*p || *p == ':' )
break;
+
i++, p++;
}
in = *(unsigned *)m;
- for (i=0 ; i<numIPFilters ; i++)
- if ( (in & ipFilters[i].mask) == ipFilters[i].compare)
+ for( i = 0; i < numIPFilters; i++ )
+ if( ( in & ipFilters[ i ].mask ) == ipFilters[ i ].compare )
return g_filterBan.integer != 0;
return g_filterBan.integer == 0;
@@ -177,23 +183,25 @@ static void AddIP( char *str )
{
int i;
- for (i = 0 ; i < numIPFilters ; i++)
- if (ipFilters[i].compare == 0xffffffff)
+ for( i = 0 ; i < numIPFilters ; i++ )
+ if( ipFilters[ i ].compare == 0xffffffff )
break; // free spot
- if (i == numIPFilters)
+
+ if( i == numIPFilters )
{
- if (numIPFilters == MAX_IPFILTERS)
+ if( numIPFilters == MAX_IPFILTERS )
{
- G_Printf ("IP filter list is full\n");
+ G_Printf( "IP filter list is full\n" );
return;
}
+
numIPFilters++;
}
- if (!StringToFilter (str, &ipFilters[i]))
- ipFilters[i].compare = 0xffffffffu;
+ if( !StringToFilter( str, &ipFilters[ i ] ) )
+ ipFilters[ i ].compare = 0xffffffffu;
- UpdateIPBans();
+ UpdateIPBans( );
}
/*
@@ -201,21 +209,26 @@ static void AddIP( char *str )
G_ProcessIPBans
=================
*/
-void G_ProcessIPBans(void)
+void G_ProcessIPBans( void )
{
char *s, *t;
- char str[MAX_TOKEN_CHARS];
+ char str[ MAX_TOKEN_CHARS ];
- Q_strncpyz( str, g_banIPs.string, sizeof(str) );
+ Q_strncpyz( str, g_banIPs.string, sizeof( str ) );
- for (t = s = g_banIPs.string; *t; /* */ ) {
- s = strchr(s, ' ');
- if (!s)
+ for( t = s = g_banIPs.string; *t; /* */ )
+ {
+ s = strchr( s, ' ' );
+
+ if( !s )
break;
- while (*s == ' ')
+
+ while( *s == ' ' )
*s++ = 0;
- if (*t)
+
+ if( *t )
AddIP( t );
+
t = s;
}
}
@@ -226,19 +239,19 @@ void G_ProcessIPBans(void)
Svcmd_AddIP_f
=================
*/
-void Svcmd_AddIP_f (void)
+void Svcmd_AddIP_f( void )
{
- char str[MAX_TOKEN_CHARS];
+ char str[ MAX_TOKEN_CHARS ];
- if ( trap_Argc() < 2 ) {
- G_Printf("Usage: addip <ip-mask>\n");
+ if( trap_Argc( ) < 2 )
+ {
+ G_Printf( "Usage: addip <ip-mask>\n" );
return;
}
trap_Argv( 1, str, sizeof( str ) );
AddIP( str );
-
}
/*
@@ -246,29 +259,32 @@ void Svcmd_AddIP_f (void)
Svcmd_RemoveIP_f
=================
*/
-void Svcmd_RemoveIP_f (void)
+void Svcmd_RemoveIP_f( void )
{
ipFilter_t f;
- int i;
- char str[MAX_TOKEN_CHARS];
+ int i;
+ char str[ MAX_TOKEN_CHARS ];
- if ( trap_Argc() < 2 ) {
- G_Printf("Usage: sv removeip <ip-mask>\n");
+ if( trap_Argc( ) < 2 )
+ {
+ G_Printf( "Usage: sv removeip <ip-mask>\n" );
return;
}
trap_Argv( 1, str, sizeof( str ) );
- if (!StringToFilter (str, &f))
+ if( !StringToFilter( str, &f ) )
return;
- for (i=0 ; i<numIPFilters ; i++) {
- if (ipFilters[i].mask == f.mask &&
- ipFilters[i].compare == f.compare) {
- ipFilters[i].compare = 0xffffffffu;
- G_Printf ("Removed.\n");
+ for( i = 0; i < numIPFilters; i++ )
+ {
+ if( ipFilters[ i ].mask == f.mask &&
+ ipFilters[ i ].compare == f.compare)
+ {
+ ipFilters[ i ].compare = 0xffffffffu;
+ G_Printf ( "Removed.\n" );
- UpdateIPBans();
+ UpdateIPBans( );
return;
}
}
@@ -281,98 +297,110 @@ void Svcmd_RemoveIP_f (void)
Svcmd_EntityList_f
===================
*/
-void Svcmd_EntityList_f (void) {
- int e;
- gentity_t *check;
+void Svcmd_EntityList_f( void )
+{
+ int e;
+ gentity_t *check;
- check = g_entities+1;
- for (e = 1; e < level.num_entities ; e++, check++) {
- if ( !check->inuse ) {
+ check = g_entities + 1;
+
+ for( e = 1; e < level.num_entities; e++, check++ )
+ {
+ if( !check->inuse )
continue;
- }
- G_Printf("%3i:", e);
- switch ( check->s.eType ) {
- case ET_GENERAL:
- G_Printf("ET_GENERAL ");
- break;
- case ET_PLAYER:
- G_Printf("ET_PLAYER ");
- break;
- case ET_ITEM:
- G_Printf("ET_ITEM ");
- break;
- case ET_BUILDABLE:
- G_Printf("ET_BUILDABLE ");
- break;
- case ET_MISSILE:
- G_Printf("ET_MISSILE ");
- break;
- case ET_MOVER:
- G_Printf("ET_MOVER ");
- break;
- case ET_BEAM:
- G_Printf("ET_BEAM ");
- break;
- case ET_PORTAL:
- G_Printf("ET_PORTAL ");
- break;
- case ET_SPEAKER:
- G_Printf("ET_SPEAKER ");
- break;
- case ET_PUSH_TRIGGER:
- G_Printf("ET_PUSH_TRIGGER ");
- break;
- case ET_TELEPORT_TRIGGER:
- G_Printf("ET_TELEPORT_TRIGGER ");
- break;
- case ET_INVISIBLE:
- G_Printf("ET_INVISIBLE ");
- break;
- case ET_GRAPPLE:
- G_Printf("ET_GRAPPLE ");
- break;
- default:
- G_Printf("%3i ", check->s.eType);
- break;
- }
- if ( check->classname ) {
- G_Printf("%s", check->classname);
+ G_Printf( "%3i:", e );
+
+ switch( check->s.eType )
+ {
+ case ET_GENERAL:
+ G_Printf( "ET_GENERAL " );
+ break;
+ case ET_PLAYER:
+ G_Printf( "ET_PLAYER " );
+ break;
+ case ET_ITEM:
+ G_Printf( "ET_ITEM " );
+ break;
+ case ET_BUILDABLE:
+ G_Printf( "ET_BUILDABLE " );
+ break;
+ case ET_MISSILE:
+ G_Printf( "ET_MISSILE " );
+ break;
+ case ET_MOVER:
+ G_Printf( "ET_MOVER " );
+ break;
+ case ET_BEAM:
+ G_Printf( "ET_BEAM " );
+ break;
+ case ET_PORTAL:
+ G_Printf( "ET_PORTAL " );
+ break;
+ case ET_SPEAKER:
+ G_Printf( "ET_SPEAKER " );
+ break;
+ case ET_PUSH_TRIGGER:
+ G_Printf( "ET_PUSH_TRIGGER " );
+ break;
+ case ET_TELEPORT_TRIGGER:
+ G_Printf( "ET_TELEPORT_TRIGGER " );
+ break;
+ case ET_INVISIBLE:
+ G_Printf( "ET_INVISIBLE " );
+ break;
+ case ET_GRAPPLE:
+ G_Printf( "ET_GRAPPLE " );
+ break;
+ default:
+ G_Printf( "%3i ", check->s.eType );
+ break;
}
- G_Printf("\n");
+
+ if( check->classname )
+ G_Printf( "%s", check->classname );
+
+ G_Printf( "\n" );
}
}
-gclient_t *ClientForString( const char *s ) {
+gclient_t *ClientForString( const char *s )
+{
gclient_t *cl;
- int i;
- int idnum;
+ int i;
+ int idnum;
// numeric values are just slot numbers
- if ( s[0] >= '0' && s[0] <= '9' ) {
+ if( s[ 0 ] >= '0' && s[ 0 ] <= '9' )
+ {
idnum = atoi( s );
- if ( idnum < 0 || idnum >= level.maxclients ) {
+
+ if( idnum < 0 || idnum >= level.maxclients )
+ {
Com_Printf( "Bad client slot: %i\n", idnum );
return NULL;
}
- cl = &level.clients[idnum];
- if ( cl->pers.connected == CON_DISCONNECTED ) {
+ cl = &level.clients[ idnum ];
+
+ if( cl->pers.connected == CON_DISCONNECTED )
+ {
G_Printf( "Client %i is not connected\n", idnum );
return NULL;
}
+
return cl;
}
// check for a name match
- for ( i=0 ; i < level.maxclients ; i++ ) {
- cl = &level.clients[i];
- if ( cl->pers.connected == CON_DISCONNECTED ) {
+ for( i = 0; i < level.maxclients; i++ )
+ {
+ cl = &level.clients[ i ];
+ if( cl->pers.connected == CON_DISCONNECTED )
continue;
- }
- if ( !Q_stricmp( cl->pers.netname, s ) ) {
+
+ if( !Q_stricmp( cl->pers.netname, s ) )
return cl;
- }
}
G_Printf( "User %s is not on the server\n", s );
@@ -387,20 +415,22 @@ Svcmd_ForceTeam_f
forceteam <player> <team>
===================
*/
-void Svcmd_ForceTeam_f( void ) {
+void Svcmd_ForceTeam_f( void )
+{
gclient_t *cl;
- char str[MAX_TOKEN_CHARS];
+ char str[ MAX_TOKEN_CHARS ];
// find the player
trap_Argv( 1, str, sizeof( str ) );
cl = ClientForString( str );
- if ( !cl ) {
+
+ if( !cl )
return;
- }
// set the team
trap_Argv( 2, str, sizeof( str ) );
/*SetTeam( &g_entities[cl - level.clients], str );*/
+ //FIXME: tremulise this
}
char *ConcatArgs( int start );
@@ -411,48 +441,58 @@ ConsoleCommand
=================
*/
-qboolean ConsoleCommand( void ) {
- char cmd[MAX_TOKEN_CHARS];
+qboolean ConsoleCommand( void )
+{
+ char cmd[ MAX_TOKEN_CHARS ];
trap_Argv( 0, cmd, sizeof( cmd ) );
- if ( Q_stricmp (cmd, "entitylist") == 0 ) {
- Svcmd_EntityList_f();
+ if( Q_stricmp( cmd, "entitylist" ) == 0 )
+ {
+ Svcmd_EntityList_f( );
return qtrue;
}
- if ( Q_stricmp (cmd, "forceteam") == 0 ) {
- Svcmd_ForceTeam_f();
+ if( Q_stricmp( cmd, "forceteam" ) == 0 )
+ {
+ Svcmd_ForceTeam_f( );
return qtrue;
}
- if (Q_stricmp (cmd, "game_memory") == 0) {
- Svcmd_GameMem_f();
+ if( Q_stricmp( cmd, "game_memory" ) == 0 )
+ {
+ Svcmd_GameMem_f( );
return qtrue;
}
- if (Q_stricmp (cmd, "addip") == 0) {
- Svcmd_AddIP_f();
+ if( Q_stricmp( cmd, "addip" ) == 0 )
+ {
+ Svcmd_AddIP_f( );
return qtrue;
}
- if (Q_stricmp (cmd, "removeip") == 0) {
- Svcmd_RemoveIP_f();
+ if( Q_stricmp( cmd, "removeip" ) == 0 )
+ {
+ Svcmd_RemoveIP_f( );
return qtrue;
}
- if (Q_stricmp (cmd, "listip") == 0) {
+ if( Q_stricmp( cmd, "listip" ) == 0 )
+ {
trap_SendConsoleCommand( EXEC_NOW, "g_banIPs\n" );
return qtrue;
}
- if (g_dedicated.integer) {
- if (Q_stricmp (cmd, "say") == 0) {
- trap_SendServerCommand( -1, va("print \"server: %s\"", ConcatArgs(1) ) );
+ if( g_dedicated.integer )
+ {
+ if( Q_stricmp( cmd, "say" ) == 0 )
+ {
+ trap_SendServerCommand( -1, va( "print \"server: %s\"", ConcatArgs( 1 ) ) );
return qtrue;
}
+
// everything else will also be printed as a say command
- trap_SendServerCommand( -1, va("print \"server: %s\"", ConcatArgs(0) ) );
+ trap_SendServerCommand( -1, va( "print \"server: %s\"", ConcatArgs( 0 ) ) );
return qtrue;
}