summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game/g_admin.c93
-rw-r--r--src/game/g_admin.h14
-rw-r--r--src/game/g_client.c15
-rw-r--r--src/game/g_cmds.c2
-rw-r--r--src/game/g_local.h20
-rw-r--r--src/game/g_namelog.c6
-rw-r--r--src/game/g_utils.c38
7 files changed, 80 insertions, 108 deletions
diff --git a/src/game/g_admin.c b/src/game/g_admin.c
index 806d2d76..e0f65d94 100644
--- a/src/game/g_admin.c
+++ b/src/game/g_admin.c
@@ -517,7 +517,7 @@ static void admin_writeconfig( void )
trap_FS_Write( "guid = ", 10, f );
admin_writeconfig_string( b->guid, f );
trap_FS_Write( "ip = ", 10, f );
- admin_writeconfig_string( b->ip, f );
+ admin_writeconfig_string( b->ip.str, f );
trap_FS_Write( "reason = ", 10, f );
admin_writeconfig_string( b->reason, f );
trap_FS_Write( "made = ", 10, f );
@@ -811,13 +811,10 @@ qboolean G_admin_ban_check( gentity_t *ent, char *reason, int rlen )
{
int i;
int t;
- addr_t ip, test;
- int mask = -1;
g_admin_ban_t *ban;
t = trap_RealTime( NULL );
- // this happens when ip = localhost
- if( !G_AddressParse( ent->client->pers.ip, &ip, NULL ) )
+ if( ent->client->pers.localClient )
return qfalse;
for( ban = g_admin_bans, i = 0; ban; ban = ban->next, i++ )
{
@@ -827,8 +824,7 @@ qboolean G_admin_ban_check( gentity_t *ent, char *reason, int rlen )
if( !Q_stricmp( ban->guid, ent->client->pers.guid ) ||
( !G_admin_permission( ent, ADMF_IMMUNITY ) &&
- G_AddressParse( ban->ip, &test, &mask ) &&
- G_AddressCompare( &ip, &test, mask ) ) )
+ G_AddressCompare( &ban->ip, &ent->client->pers.ip ) ) )
{
char duration[ 13 ];
G_admin_duration( ban->expires - t,
@@ -846,7 +842,7 @@ qboolean G_admin_ban_check( gentity_t *ent, char *reason, int rlen )
" at %s is banned (ban #%d)\n",
ent->client->pers.netname[ 0 ] ? ent->client->pers.netname :
ban->name,
- ent->client->pers.ip,
+ ent->client->pers.ip.str,
i + 1 );
return qtrue;
}
@@ -914,6 +910,7 @@ qboolean G_admin_readconfig( gentity_t *ent )
char *t;
qboolean level_open, admin_open, ban_open, command_open;
int i;
+ char ip[ 44 ];
G_admin_cleanup();
@@ -1047,7 +1044,8 @@ qboolean G_admin_readconfig( gentity_t *ent )
}
else if( !Q_stricmp( t, "ip" ) )
{
- admin_readconfig_string( &cnf, b->ip, sizeof( b->ip ) );
+ admin_readconfig_string( &cnf, ip, sizeof( ip ) );
+ G_AddressParse( ip, &b->ip );
}
else if( !Q_stricmp( t, "reason" ) )
{
@@ -1282,7 +1280,7 @@ qboolean G_admin_setlevel( gentity_t *ent )
static qboolean admin_create_ban( gentity_t *ent,
char *netname,
char *guid,
- char *ip,
+ addr_t *ip,
int seconds,
char *reason )
{
@@ -1313,7 +1311,7 @@ static qboolean admin_create_ban( gentity_t *ent,
Q_strncpyz( b->name, netname, sizeof( b->name ) );
Q_strncpyz( b->guid, guid, sizeof( b->guid ) );
- Q_strncpyz( b->ip, ip, sizeof( b->ip ) );
+ memcpy( &b->ip, &ip, sizeof( b->ip ) );
Com_sprintf( b->made, sizeof( b->made ), "%02i/%02i/%02i %02i:%02i:%02i",
qt.tm_mon + 1, qt.tm_mday, qt.tm_year % 100,
@@ -1421,7 +1419,7 @@ qboolean G_admin_kick( gentity_t *ent )
admin_create_ban( ent,
vic->client->pers.netname,
vic->client->pers.guid,
- vic->client->pers.ip,
+ &vic->client->pers.ip,
MAX( 1, G_admin_parse_time( g_adminTempBan.string ) ),
( *reason ) ? reason : "kicked by admin" );
admin_writeconfig();
@@ -1442,7 +1440,7 @@ qboolean G_admin_ban( gentity_t *ent )
char n2[ MAX_NAME_LENGTH ];
char s2[ MAX_NAME_LENGTH ];
int netmask = -1;
- addr_t ip, cmp;
+ addr_t ip;
qboolean ipmatch = qfalse;
namelog_t *namelog, *match = NULL;
@@ -1493,11 +1491,11 @@ qboolean G_admin_ban( gentity_t *ent )
for( match = level.namelogs; match->slot != i; match = match->next );
}
}
- else if( G_AddressParse( search, &ip, &netmask ) )
+ else if( G_AddressParse( search, &ip ) )
{
int max = ip.type == IPv4 ? 32 : 128;
int min = ent ? max / 2 : 1;
- if( netmask < min || netmask > max )
+ if( ip.mask < min || ip.mask > max )
{
ADMP( va( "^3ban: ^7invalid netmask (%d is not one of %d-%d)\n",
netmask, min, max ) );
@@ -1514,14 +1512,13 @@ qboolean G_admin_ban( gentity_t *ent )
if( ipmatch )
{
- for( i = 0; i < MAX_NAMELOG_ADDRS && namelog->ip[ i ][ 0 ]; i++ )
+ for( i = 0; i < MAX_NAMELOG_ADDRS && namelog->ip[ i ].str[ 0 ]; i++ )
{
- if( G_AddressParse( namelog->ip[ i ], &cmp, NULL ) &&
- G_AddressCompare( &ip, &cmp, netmask ) )
+ if( G_AddressCompare( &ip, &namelog->ip[ i ] ) )
{
match = namelog;
- if( ( ip.type == IPv4 && netmask == 32 ) ||
- ( ip.type == IPv6 && netmask == 128 ) )
+ if( ( ip.type == IPv4 && ip.mask == 32 ) ||
+ ( ip.type == IPv6 && ip.mask == 128 ) )
{
exactmatch = qtrue;
break;
@@ -1571,8 +1568,8 @@ qboolean G_admin_ban( gentity_t *ent )
va( S_COLOR_YELLOW "%-2d" S_COLOR_WHITE, namelog->slot ) : "- " );
for( i = 0; i < MAX_NAMELOG_NAMES && namelog->name[ i ][ 0 ]; i++ )
ADMBP( va( " %s" S_COLOR_WHITE, namelog->name[ i ] ) );
- for( i = 0; i < MAX_NAMELOG_ADDRS && namelog->ip[ i ][ 0 ]; i++ )
- ADMBP( va( " %s", namelog->ip[ i ] ) );
+ for( i = 0; i < MAX_NAMELOG_ADDRS && namelog->ip[ i ].str[ 0 ]; i++ )
+ ADMBP( va( " %s", namelog->ip[ i ].str ) );
ADMBP( "\n" );
}
}
@@ -1587,7 +1584,7 @@ qboolean G_admin_ban( gentity_t *ent )
" level than you\n" );
return qfalse;
}
- if( !strcmp( match->ip[ 0 ], "localhost" ) )
+ if( !strcmp( match->ip[ 0 ].str, "localhost" ) )
{
ADMP( "^3ban: ^7disconnecting the host would end the game\n" );
return qfalse;
@@ -1603,20 +1600,20 @@ qboolean G_admin_ban( gentity_t *ent )
match->name[ match->nameChanges % MAX_NAMELOG_NAMES ] :
level.clients[ match->slot ].pers.netname,
match->guid,
- search,
+ &ip,
seconds, reason );
}
else
{
// ban all IP addresses used by this player
- for( i = 0; i < MAX_NAMELOG_ADDRS && match->ip[ i ][ 0 ]; i++ )
+ for( i = 0; i < MAX_NAMELOG_ADDRS && match->ip[ i ].str[ 0 ]; i++ )
{
admin_create_ban( ent,
match->slot == -1 ?
match->name[ match->nameChanges % MAX_NAMELOG_NAMES ] :
level.clients[ match->slot ].pers.netname,
match->guid,
- match->ip[ i ],
+ &match->ip[ i ],
seconds, reason );
}
}
@@ -1713,7 +1710,7 @@ qboolean G_admin_adjustban( gentity_t *ent )
trap_Argv( 2, secs, sizeof( secs ) );
if( secs[ 0 ] == '/' )
{
- int max = strchr( ban->ip, ':' ) ? 128 : 32;
+ int max = ban->ip.type == IPv6 ? 128 : 32;
int min = ent ? max / 2 : 1;
mask = atoi( secs + 1 );
if( mask < min || mask > max )
@@ -1765,10 +1762,11 @@ qboolean G_admin_adjustban( gentity_t *ent )
}
if( mask )
{
- char *p = strchr( ban->ip, '/' );
+ char *p = strchr( ban->ip.str, '/' );
if( !p )
- p = ban->ip + strlen( ban->ip );
- Com_sprintf( p, sizeof( ban->ip ) - ( p - ban->ip ), "/%d", mask );
+ p = ban->ip.str + strlen( ban->ip.str );
+ Com_sprintf( p, sizeof( ban->ip.str ) - ( p - ban->ip.str ), "/%d", mask );
+ ban->ip.mask = mask;
}
reason = ConcatArgs( 3 + skiparg );
if( *reason )
@@ -2208,8 +2206,7 @@ qboolean G_admin_showbans( gentity_t *ent )
char *made;
char n1[ MAX_NAME_LENGTH ] = {""};
qboolean ipmatch = qfalse;
- addr_t ipa, ipb;
- int neta, netb;
+ addr_t ip;
char name_match[ MAX_NAME_LENGTH ] = {""};
g_admin_ban_t *ban, *p = NULL;
@@ -2256,7 +2253,7 @@ qboolean G_admin_showbans( gentity_t *ent )
start = 0;
}
else
- ipmatch = G_AddressParse( filter, &ipa, &neta );
+ ipmatch = G_AddressParse( filter, &ip );
}
if( start > found )
@@ -2273,10 +2270,8 @@ qboolean G_admin_showbans( gentity_t *ent )
if( ipmatch )
{
- if( !G_AddressParse( ban->ip, &ipb, &netb ) )
- continue;
- if( !G_AddressCompare( &ipa, &ipb, neta ) &&
- !G_AddressCompare( &ipa, &ipb, netb ) )
+ if( !G_AddressCompare( &ip, &ban->ip ) &&
+ !G_AddressCompare( &ban->ip, &ip ) )
continue;
}
else if( name_match[ 0 ] )
@@ -2306,10 +2301,8 @@ qboolean G_admin_showbans( gentity_t *ent )
if( ipmatch )
{
- if( !G_AddressParse( ban->ip, &ipb, &netb ) )
- continue;
- if( !G_AddressCompare( &ipa, &ipb, neta ) &&
- !G_AddressCompare( &ipa, &ipb, netb ) )
+ if( !G_AddressCompare( &ip, &ban->ip ) &&
+ !G_AddressCompare( &ban->ip, &ip ) )
continue;
}
else if( name_match[ 0 ] )
@@ -2349,7 +2342,7 @@ qboolean G_admin_showbans( gentity_t *ent )
( count + start ),
max_name + colorlen1,
ban->name,
- ban->ip,
+ ban->ip.str,
date,
max_banner + colorlen2,
ban->banner,
@@ -2722,15 +2715,14 @@ qboolean G_admin_namelog( gentity_t *ent )
char s2[ MAX_NAME_LENGTH ] = {""};
char n2[ MAX_NAME_LENGTH ] = {""};
int printed = 0;
- addr_t a, b;
- int mask = -1;
+ addr_t ip;
qboolean ipmatch = qfalse;
namelog_t *n;
if( trap_Argc() > 1 )
{
trap_Argv( 1, search, sizeof( search ) );
- ipmatch = G_AddressParse( search, &a, &mask );
+ ipmatch = G_AddressParse( search, &ip );
if( !ipmatch )
G_SanitiseString( search, s2, sizeof( s2 ) );
}
@@ -2739,13 +2731,12 @@ qboolean G_admin_namelog( gentity_t *ent )
{
if( ipmatch )
{
- for( i = 0; i < MAX_NAMELOG_ADDRS && n->ip[ i ][ 0 ]; i++ )
+ for( i = 0; i < MAX_NAMELOG_ADDRS && n->ip[ i ].str[ 0 ]; i++ )
{
- if( G_AddressParse( n->ip[ i ], &b, NULL ) &&
- G_AddressCompare( &a, &b, mask ) )
+ if( G_AddressCompare( &ip, &n->ip[ i ] ) )
break;
}
- if( i == MAX_NAMELOG_ADDRS || !n->ip[ i ][ 0 ] )
+ if( i == MAX_NAMELOG_ADDRS || !n->ip[ i ].str[ 0 ] )
continue;
}
else if( search[ 0 ] )
@@ -2761,8 +2752,8 @@ qboolean G_admin_namelog( gentity_t *ent )
}
printed++;
ADMBP( ( n->slot > -1 ) ? va( "^3%-2d", n->slot ) : "- " );
- for( i = 0; i < MAX_NAMELOG_ADDRS && n->ip[ i ][ 0 ]; i++ )
- ADMBP( va( " %s", n->ip[ i ] ) );
+ for( i = 0; i < MAX_NAMELOG_ADDRS && n->ip[ i ].str[ 0 ]; i++ )
+ ADMBP( va( " %s", n->ip[ i ].str ) );
for( i = 0; i < MAX_NAMELOG_NAMES && n->name[ i ][ 0 ]; i++ )
ADMBP( va( " '%s^7'", n->name[ i ] ) );
ADMBP( "\n" );
diff --git a/src/game/g_admin.h b/src/game/g_admin.h
index 126e33de..0137ec19 100644
--- a/src/game/g_admin.h
+++ b/src/game/g_admin.h
@@ -99,12 +99,24 @@ typedef struct g_admin_admin
}
g_admin_admin_t;
+#define ADDRLEN 16
+typedef struct
+{
+ enum
+ {
+ IPv4,
+ IPv6
+ } type;
+ byte addr[ ADDRLEN ];
+ int mask;
+ char str[ 44 ];
+} addr_t;
typedef struct g_admin_ban
{
struct g_admin_ban *next;
char name[ MAX_NAME_LENGTH ];
char guid[ 33 ];
- char ip[ 44 ]; // big enough for IPv6 CIDR notation (without brackets)
+ addr_t ip;
char reason[ MAX_ADMIN_BAN_REASON ];
char made[ 18 ]; // big enough for strftime() %c
int expires;
diff --git a/src/game/g_client.c b/src/game/g_client.c
index 9820fa31..8d0e212c 100644
--- a/src/game/g_client.c
+++ b/src/game/g_client.c
@@ -1063,7 +1063,7 @@ void ClientUserinfoChanged( int clientNum )
trap_SendServerCommand( -1, va( "print \"%s" S_COLOR_WHITE
" renamed to %s\n\"", oldname, client->pers.netname ) );
G_LogPrintf( "ClientRename: %i [%s] (%s) \"%s^7\" -> \"%s^7\" \"%c%s%c^7\"\n",
- clientNum, client->pers.ip, client->pers.guid,
+ clientNum, client->pers.ip.str, client->pers.guid,
oldname, client->pers.netname,
DECOLOR_OFF, client->pers.netname, DECOLOR_ON );
}
@@ -1217,7 +1217,10 @@ char *ClientConnect( int clientNum, qboolean firstTime )
Q_strncpyz( client->pers.guid, value, sizeof( client->pers.guid ) );
value = Info_ValueForKey( userinfo, "ip" );
- Q_strncpyz( client->pers.ip, value, sizeof( client->pers.ip ) );
+ // check for local client
+ if( !strcmp( value, "localhost" ) )
+ client->pers.localClient = qtrue;
+ G_AddressParse( value, &client->pers.ip );
client->pers.admin = G_admin_admin( client->pers.guid );
@@ -1257,10 +1260,6 @@ char *ClientConnect( int clientNum, qboolean firstTime )
}
}
- // check for local client
- if( !strcmp( client->pers.ip, "localhost" ) )
- client->pers.localClient = qtrue;
-
client->pers.connected = CON_CONNECTING;
// read or initialize the session data
@@ -1273,7 +1272,7 @@ char *ClientConnect( int clientNum, qboolean firstTime )
G_namelog_connect( client );
ClientUserinfoChanged( clientNum );
G_LogPrintf( "ClientConnect: %i [%s] (%s) \"%s^7\" \"%c%s%c^7\"\n",
- clientNum, client->pers.ip, client->pers.guid,
+ clientNum, client->pers.ip.str, client->pers.guid,
client->pers.netname,
DECOLOR_OFF, client->pers.netname, DECOLOR_ON );
@@ -1717,7 +1716,7 @@ void ClientDisconnect( int clientNum )
}
G_LogPrintf( "ClientDisconnect: %i [%s] (%s) \"%s^7\"\n", clientNum,
- ent->client->pers.ip, ent->client->pers.guid, ent->client->pers.netname );
+ ent->client->pers.ip.str, ent->client->pers.guid, ent->client->pers.netname );
trap_UnlinkEntity( ent );
ent->s.modelindex = 0;
diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c
index b1a26e6b..431434c2 100644
--- a/src/game/g_cmds.c
+++ b/src/game/g_cmds.c
@@ -1066,7 +1066,7 @@ void Cmd_CallVote_f( gentity_t *ent )
}
Com_sprintf( level.voteString[ team ], sizeof( level.voteString[ team ] ),
- "ban %s \"1s%s\" vote kick", level.clients[ clientNum ].pers.ip,
+ "ban %s \"1s%s\" vote kick", level.clients[ clientNum ].pers.ip.str,
g_adminTempBan.string );
Com_sprintf( level.voteDisplayString[ team ],
sizeof( level.voteDisplayString[ team ] ),
diff --git a/src/game/g_local.h b/src/game/g_local.h
index 6ace8093..600ea8a0 100644
--- a/src/game/g_local.h
+++ b/src/game/g_local.h
@@ -279,7 +279,7 @@ typedef struct namelog_s
{
struct namelog_s *next;
char name[ MAX_NAMELOG_NAMES ][ MAX_NAME_LENGTH ];
- char ip[ MAX_NAMELOG_ADDRS ][ 40 ];
+ addr_t ip[ MAX_NAMELOG_ADDRS ];
char guid[ 33 ];
int slot;
qboolean banned;
@@ -339,7 +339,7 @@ typedef struct
vec3_t lastDeathLocation;
char guid[ 33 ];
- char ip[ 40 ];
+ addr_t ip;
char voice[ MAX_VOICE_NAME_LEN ];
qboolean useUnlagged;
// keep track of other players' info for tinfo
@@ -768,19 +768,9 @@ qboolean G_InPowerZone( gentity_t *self );
//
// g_utils.c
//
-#define ADDRLEN 16
-typedef struct
-{
- enum
- {
- IPv4,
- IPv6
- } type;
- byte addr[ ADDRLEN ];
-} addr_t;
-qboolean G_AddressParse( const char *str, addr_t *addr, int *netmask );
-qboolean G_AddressCompare( const addr_t *a, const addr_t *b, int netmask );
-qboolean G_AdrCmpStr( const char *a, const char *b );
+//addr_t in g_admin.h for g_admin_ban_t
+qboolean G_AddressParse( const char *str, addr_t *addr );
+qboolean G_AddressCompare( const addr_t *a, const addr_t *b );
int G_ParticleSystemIndex( char *name );
int G_ShaderIndex( char *name );
diff --git a/src/game/g_namelog.c b/src/game/g_namelog.c
index 2da09cf7..53a3f5de 100644
--- a/src/game/g_namelog.c
+++ b/src/game/g_namelog.c
@@ -60,12 +60,12 @@ void G_namelog_connect( gclient_t *client )
G_namelog_update_name( client );
- for( i = 0; i < MAX_NAMELOG_ADDRS && n->ip[ i ][ 0 ]; i++ )
- if( !strcmp( n->ip[ i ], client->pers.ip ) )
+ for( i = 0; i < MAX_NAMELOG_ADDRS && n->ip[ i ].str[ 0 ]; i++ )
+ if( !strcmp( n->ip[ i ].str, client->pers.ip.str ) )
return;
if( i == MAX_NAMELOG_ADDRS )
i--;
- strcpy( n->ip[ i ], client->pers.ip );
+ memcpy( &n->ip[ i ], &client->pers.ip, sizeof( n->ip[ i ] ) );
}
void G_namelog_disconnect( gclient_t *client )
diff --git a/src/game/g_utils.c b/src/game/g_utils.c
index 9de86337..1204a984 100644
--- a/src/game/g_utils.c
+++ b/src/game/g_utils.c
@@ -941,7 +941,7 @@ static const char *addr6parse( const char *str, addr_t *addr )
return str + i;
}
-qboolean G_AddressParse( const char *str, addr_t *addr, int *netmask )
+qboolean G_AddressParse( const char *str, addr_t *addr )
{
const char *p;
int max;
@@ -955,23 +955,20 @@ qboolean G_AddressParse( const char *str, addr_t *addr, int *netmask )
p = addr4parse( str, addr );
max = 32;
}
+ Q_strncpyz( addr->str, str, sizeof( addr->str ) );
if( !p )
return qfalse;
if( *p == '/' )
{
- if( netmask )
- {
- *netmask = atoi( p + 1 );
- if( *netmask < 1 || *netmask > max )
- *netmask = max;
- }
+ addr->mask = atoi( p + 1 );
+ if( addr->mask < 1 || addr->mask > max )
+ addr->mask = max;
}
else
{
if( *p )
return qfalse;
- if( netmask )
- *netmask = max;
+ addr->mask = max;
}
return qtrue;
}
@@ -983,11 +980,12 @@ G_AddressCompare
Based largely on NET_CompareBaseAdrMask from ioq3 revision 1557
===============
*/
-qboolean G_AddressCompare( const addr_t *a, const addr_t *b, int netmask )
+qboolean G_AddressCompare( const addr_t *a, const addr_t *b )
{
- int i;
+ int i, netmask;
if( a->type != b->type )
return qfalse;
+ netmask = a->mask;
if( a->type == IPv4 )
{
if( netmask < 1 || netmask > 32 )
@@ -1008,21 +1006,3 @@ qboolean G_AddressCompare( const addr_t *a, const addr_t *b, int netmask )
}
return qtrue;
}
-
-/*
-===============
-G_AdrCmpStr
-
-The first argument may be in CIDR notation
-===============
-*/
-qboolean G_AdrCmpStr( const char *a, const char *b )
-{
- int netmask = -1;
- addr_t cmpa, cmpb;
- if( !G_AddressParse( a, &cmpa, &netmask ) )
- return qfalse;
- if( !G_AddressParse( b, &cmpb, NULL ) )
- return qfalse;
- return G_AddressCompare( &cmpa, &cmpb, netmask );
-}