Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

g_svcmds.c File Reference

#include "g_local.h"

Include dependency graph for g_svcmds.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  ipFilter_s

Defines

#define MAX_IPFILTERS   1024

Typedefs

typedef ipFilter_s ipFilter_t

Functions

void AddIP (char *str)
gclient_tClientForString (const char *s)
char * ConcatArgs (int start)
qboolean ConsoleCommand (void)
qboolean G_FilterPacket (char *from)
void G_ProcessIPBans (void)
qboolean StringToFilter (char *s, ipFilter_t *f)
void Svcmd_AddIP_f (void)
void Svcmd_EntityList_f (void)
void Svcmd_ForceTeam_f (void)
void Svcmd_RemoveIP_f (void)
void UpdateIPBans (void)

Variables

ipFilter_t ipFilters [MAX_IPFILTERS]
int numIPFilters


Define Documentation

#define MAX_IPFILTERS   1024
 

Definition at line 68 of file g_svcmds.c.


Typedef Documentation

typedef struct ipFilter_s ipFilter_t
 

Referenced by StringToFilter(), and Svcmd_RemoveIP_f().


Function Documentation

void AddIP char *  str  )  [static]
 

Definition at line 211 of file g_svcmds.c.

References ipFilter_s::compare, G_Printf(), i, ipFilters, numIPFilters, StringToFilter(), and UpdateIPBans().

Referenced by G_ProcessIPBans(), and Svcmd_AddIP_f().

00212 {
00213     int     i;
00214 
00215     for (i = 0 ; i < numIPFilters ; i++)
00216         if (ipFilters[i].compare == 0xffffffff)
00217             break;      // free spot
00218     if (i == numIPFilters)
00219     {
00220         if (numIPFilters == MAX_IPFILTERS)
00221         {
00222             G_Printf ("IP filter list is full\n");
00223             return;
00224         }
00225         numIPFilters++;
00226     }
00227     
00228     if (!StringToFilter (str, &ipFilters[i]))
00229         ipFilters[i].compare = 0xffffffffu;
00230 
00231     UpdateIPBans();
00232 }

Here is the call graph for this function:

gclient_t* ClientForString const char *  s  ) 
 

Definition at line 378 of file g_svcmds.c.

References atoi, cl, level_locals_t::clients, Com_Printf(), G_Printf(), gclient_t, i, level, level_locals_t::maxclients, Q_stricmp(), and s.

Referenced by Svcmd_ForceTeam_f().

00378                                               {
00379     gclient_t   *cl;
00380     int         i;
00381     int         idnum;
00382 
00383     // numeric values are just slot numbers
00384     if ( s[0] >= '0' && s[0] <= '9' ) {
00385         idnum = atoi( s );
00386         if ( idnum < 0 || idnum >= level.maxclients ) {
00387             Com_Printf( "Bad client slot: %i\n", idnum );
00388             return NULL;
00389         }
00390 
00391         cl = &level.clients[idnum];
00392         if ( cl->pers.connected == CON_DISCONNECTED ) {
00393             G_Printf( "Client %i is not connected\n", idnum );
00394             return NULL;
00395         }
00396         return cl;
00397     }
00398 
00399     // check for a name match
00400     for ( i=0 ; i < level.maxclients ; i++ ) {
00401         cl = &level.clients[i];
00402         if ( cl->pers.connected == CON_DISCONNECTED ) {
00403             continue;
00404         }
00405         if ( !Q_stricmp( cl->pers.netname, s ) ) {
00406             return cl;
00407         }
00408     }
00409 
00410     G_Printf( "User %s is not on the server\n", s );
00411 
00412     return NULL;
00413 }

Here is the call graph for this function:

char* ConcatArgs int  start  ) 
 

Definition at line 127 of file g_cmds.c.

References c, i, line, MAX_STRING_CHARS, memcpy(), strlen(), trap_Argc(), and trap_Argv().

Referenced by Cmd_Give_f(), Cmd_Say_f(), Cmd_Tell_f(), Cmd_Voice_f(), Cmd_VoiceTell_f(), and ConsoleCommand().

00127                                  {
00128     int     i, c, tlen;
00129     static char line[MAX_STRING_CHARS];
00130     int     len;
00131     char    arg[MAX_STRING_CHARS];
00132 
00133     len = 0;
00134     c = trap_Argc();
00135     for ( i = start ; i < c ; i++ ) {
00136         trap_Argv( i, arg, sizeof( arg ) );
00137         tlen = strlen( arg );
00138         if ( len + tlen >= MAX_STRING_CHARS - 1 ) {
00139             break;
00140         }
00141         memcpy( line + len, arg, tlen );
00142         len += tlen;
00143         if ( i != c - 1 ) {
00144             line[len] = ' ';
00145             len++;
00146         }
00147     }
00148 
00149     line[len] = 0;
00150 
00151     return line;
00152 }

Here is the call graph for this function:

qboolean ConsoleCommand void   ) 
 

Definition at line 446 of file g_svcmds.c.

References ConcatArgs(), EXEC_NOW, g_dedicated, vmCvar_t::integer, Q_stricmp(), qboolean, Svcmd_AbortPodium_f(), Svcmd_AddBot_f(), Svcmd_AddIP_f(), Svcmd_BotList_f(), Svcmd_EntityList_f(), Svcmd_ForceTeam_f(), Svcmd_GameMem_f(), Svcmd_RemoveIP_f(), trap_Argv(), trap_SendConsoleCommand(), trap_SendServerCommand(), and va().

Referenced by vmMain().

00446                                    {
00447     char    cmd[MAX_TOKEN_CHARS];
00448 
00449     trap_Argv( 0, cmd, sizeof( cmd ) );
00450 
00451     if ( Q_stricmp (cmd, "entitylist") == 0 ) {
00452         Svcmd_EntityList_f();
00453         return qtrue;
00454     }
00455 
00456     if ( Q_stricmp (cmd, "forceteam") == 0 ) {
00457         Svcmd_ForceTeam_f();
00458         return qtrue;
00459     }
00460 
00461     if (Q_stricmp (cmd, "game_memory") == 0) {
00462         Svcmd_GameMem_f();
00463         return qtrue;
00464     }
00465 
00466     if (Q_stricmp (cmd, "addbot") == 0) {
00467         Svcmd_AddBot_f();
00468         return qtrue;
00469     }
00470 
00471     if (Q_stricmp (cmd, "botlist") == 0) {
00472         Svcmd_BotList_f();
00473         return qtrue;
00474     }
00475 
00476     if (Q_stricmp (cmd, "abort_podium") == 0) {
00477         Svcmd_AbortPodium_f();
00478         return qtrue;
00479     }
00480 
00481     if (Q_stricmp (cmd, "addip") == 0) {
00482         Svcmd_AddIP_f();
00483         return qtrue;
00484     }
00485 
00486     if (Q_stricmp (cmd, "removeip") == 0) {
00487         Svcmd_RemoveIP_f();
00488         return qtrue;
00489     }
00490 
00491     if (Q_stricmp (cmd, "listip") == 0) {
00492         trap_SendConsoleCommand( EXEC_NOW, "g_banIPs\n" );
00493         return qtrue;
00494     }
00495 
00496     if (g_dedicated.integer) {
00497         if (Q_stricmp (cmd, "say") == 0) {
00498             trap_SendServerCommand( -1, va("print \"server: %s\"", ConcatArgs(1) ) );
00499             return qtrue;
00500         }
00501         // everything else will also be printed as a say command
00502         trap_SendServerCommand( -1, va("print \"server: %s\"", ConcatArgs(0) ) );
00503         return qtrue;
00504     }
00505 
00506     return qfalse;
00507 }

Here is the call graph for this function:

qboolean G_FilterPacket char *  from  ) 
 

Definition at line 177 of file g_svcmds.c.

References byte, ipFilter_s::compare, g_filterBan, i, in, vmCvar_t::integer, ipFilters, m, ipFilter_s::mask, p, and qboolean.

Referenced by ClientConnect().

00178 {
00179     int     i;
00180     unsigned    in;
00181     byte m[4];
00182     char *p;
00183 
00184     i = 0;
00185     p = from;
00186     while (*p && i < 4) {
00187         m[i] = 0;
00188         while (*p >= '0' && *p <= '9') {
00189             m[i] = m[i]*10 + (*p - '0');
00190             p++;
00191         }
00192         if (!*p || *p == ':')
00193             break;
00194         i++, p++;
00195     }
00196     
00197     in = *(unsigned *)m;
00198 
00199     for (i=0 ; i<numIPFilters ; i++)
00200         if ( (in & ipFilters[i].mask) == ipFilters[i].compare)
00201             return g_filterBan.integer != 0;
00202 
00203     return g_filterBan.integer == 0;
00204 }

void G_ProcessIPBans void   ) 
 

Definition at line 239 of file g_svcmds.c.

References AddIP(), g_banIPs, Q_strncpyz(), s, strchr(), vmCvar_t::string, and t.

Referenced by G_InitGame().

00240 {
00241     char *s, *t;
00242     char        str[MAX_CVAR_VALUE_STRING];
00243 
00244     Q_strncpyz( str, g_banIPs.string, sizeof(str) );
00245 
00246     for (t = s = g_banIPs.string; *t; /* */ ) {
00247         s = strchr(s, ' ');
00248         if (!s)
00249             break;
00250         while (*s == ' ')
00251             *s++ = 0;
00252         if (*t)
00253             AddIP( t );
00254         t = s;
00255     }
00256 }

Here is the call graph for this function:

qboolean StringToFilter char *  s,
ipFilter_t f
[static]
 

Definition at line 78 of file g_svcmds.c.

References atoi, b, byte, ipFilter_s::compare, f, G_Printf(), i, ipFilter_t, j, m, ipFilter_s::mask, qboolean, and s.

Referenced by AddIP(), and Svcmd_RemoveIP_f().

00079 {
00080     char    num[128];
00081     int     i, j;
00082     byte    b[4];
00083     byte    m[4];
00084     
00085     for (i=0 ; i<4 ; i++)
00086     {
00087         b[i] = 0;
00088         m[i] = 0;
00089     }
00090     
00091     for (i=0 ; i<4 ; i++)
00092     {
00093         if (*s < '0' || *s > '9')
00094         {
00095             if (*s == '*') // 'match any'
00096             {
00097                 // b[i] and m[i] to 0
00098                 s++;
00099                 if (!*s)
00100                     break;
00101                 s++;
00102                 continue;
00103             }
00104             G_Printf( "Bad filter address: %s\n", s );
00105             return qfalse;
00106         }
00107         
00108         j = 0;
00109         while (*s >= '0' && *s <= '9')
00110         {
00111             num[j++] = *s++;
00112         }
00113         num[j] = 0;
00114         b[i] = atoi(num);
00115         m[i] = 255;
00116 
00117         if (!*s)
00118             break;
00119         s++;
00120     }
00121     
00122     f->mask = *(unsigned *)m;
00123     f->compare = *(unsigned *)b;
00124     
00125     return qtrue;
00126 }

Here is the call graph for this function:

void Svcmd_AddIP_f void   ) 
 

Definition at line 264 of file g_svcmds.c.

References AddIP(), G_Printf(), trap_Argc(), and trap_Argv().

Referenced by ConsoleCommand().

00265 {
00266     char        str[MAX_TOKEN_CHARS];
00267 
00268     if ( trap_Argc() < 2 ) {
00269         G_Printf("Usage:  addip <ip-mask>\n");
00270         return;
00271     }
00272 
00273     trap_Argv( 1, str, sizeof( str ) );
00274 
00275     AddIP( str );
00276 
00277 }

Here is the call graph for this function:

void Svcmd_EntityList_f void   ) 
 

Definition at line 319 of file g_svcmds.c.

References check(), gentity_s::classname, e, ET_BEAM, ET_GENERAL, ET_GRAPPLE, ET_INVISIBLE, ET_ITEM, ET_MISSILE, ET_MOVER, ET_PLAYER, ET_PORTAL, ET_PUSH_TRIGGER, ET_SPEAKER, ET_TELEPORT_TRIGGER, entityState_s::eType, g_entities, G_Printf(), gentity_t, gentity_s::inuse, level, level_locals_t::num_entities, and gentity_s::s.

Referenced by ConsoleCommand().

00319                                   {
00320     int         e;
00321     gentity_t       *check;
00322 
00323     check = g_entities+1;
00324     for (e = 1; e < level.num_entities ; e++, check++) {
00325         if ( !check->inuse ) {
00326             continue;
00327         }
00328         G_Printf("%3i:", e);
00329         switch ( check->s.eType ) {
00330         case ET_GENERAL:
00331             G_Printf("ET_GENERAL          ");
00332             break;
00333         case ET_PLAYER:
00334             G_Printf("ET_PLAYER           ");
00335             break;
00336         case ET_ITEM:
00337             G_Printf("ET_ITEM             ");
00338             break;
00339         case ET_MISSILE:
00340             G_Printf("ET_MISSILE          ");
00341             break;
00342         case ET_MOVER:
00343             G_Printf("ET_MOVER            ");
00344             break;
00345         case ET_BEAM:
00346             G_Printf("ET_BEAM             ");
00347             break;
00348         case ET_PORTAL:
00349             G_Printf("ET_PORTAL           ");
00350             break;
00351         case ET_SPEAKER:
00352             G_Printf("ET_SPEAKER          ");
00353             break;
00354         case ET_PUSH_TRIGGER:
00355             G_Printf("ET_PUSH_TRIGGER     ");
00356             break;
00357         case ET_TELEPORT_TRIGGER:
00358             G_Printf("ET_TELEPORT_TRIGGER ");
00359             break;
00360         case ET_INVISIBLE:
00361             G_Printf("ET_INVISIBLE        ");
00362             break;
00363         case ET_GRAPPLE:
00364             G_Printf("ET_GRAPPLE          ");
00365             break;
00366         default:
00367             G_Printf("%3i                 ", check->s.eType);
00368             break;
00369         }
00370 
00371         if ( check->classname ) {
00372             G_Printf("%s", check->classname);
00373         }
00374         G_Printf("\n");
00375     }
00376 }

Here is the call graph for this function:

void Svcmd_ForceTeam_f void   ) 
 

Definition at line 422 of file g_svcmds.c.

References cl, ClientForString(), level_locals_t::clients, g_entities, gclient_t, level, SetTeam(), and trap_Argv().

Referenced by ConsoleCommand().

00422                                   {
00423     gclient_t   *cl;
00424     char        str[MAX_TOKEN_CHARS];
00425 
00426     // find the player
00427     trap_Argv( 1, str, sizeof( str ) );
00428     cl = ClientForString( str );
00429     if ( !cl ) {
00430         return;
00431     }
00432 
00433     // set the team
00434     trap_Argv( 2, str, sizeof( str ) );
00435     SetTeam( &g_entities[cl - level.clients], str );
00436 }

Here is the call graph for this function:

void Svcmd_RemoveIP_f void   ) 
 

Definition at line 284 of file g_svcmds.c.

References ipFilter_s::compare, f, G_Printf(), i, ipFilter_t, ipFilters, ipFilter_s::mask, StringToFilter(), trap_Argc(), trap_Argv(), and UpdateIPBans().

Referenced by ConsoleCommand().

00285 {
00286     ipFilter_t  f;
00287     int         i;
00288     char        str[MAX_TOKEN_CHARS];
00289 
00290     if ( trap_Argc() < 2 ) {
00291         G_Printf("Usage:  sv removeip <ip-mask>\n");
00292         return;
00293     }
00294 
00295     trap_Argv( 1, str, sizeof( str ) );
00296 
00297     if (!StringToFilter (str, &f))
00298         return;
00299 
00300     for (i=0 ; i<numIPFilters ; i++) {
00301         if (ipFilters[i].mask == f.mask &&
00302             ipFilters[i].compare == f.compare) {
00303             ipFilters[i].compare = 0xffffffffu;
00304             G_Printf ("Removed.\n");
00305 
00306             UpdateIPBans();
00307             return;
00308         }
00309     }
00310 
00311     G_Printf ( "Didn't find %s.\n", str );
00312 }

Here is the call graph for this function:

void UpdateIPBans void   )  [static]
 

Definition at line 133 of file g_svcmds.c.

References b, byte, Com_Printf(), ipFilter_s::compare, i, ipFilters, j, m, ipFilter_s::mask, Q_strcat(), strlen(), trap_Cvar_Set(), and va().

Referenced by AddIP(), and Svcmd_RemoveIP_f().

00134 {
00135     byte    b[4];
00136     byte    m[4];
00137     int     i,j;
00138     char    iplist_final[MAX_CVAR_VALUE_STRING];
00139     char    ip[64];
00140 
00141     *iplist_final = 0;
00142     for (i = 0 ; i < numIPFilters ; i++)
00143     {
00144         if (ipFilters[i].compare == 0xffffffff)
00145             continue;
00146 
00147         *(unsigned *)b = ipFilters[i].compare;
00148         *(unsigned *)m = ipFilters[i].mask;
00149         *ip = 0;
00150         for (j = 0 ; j < 4 ; j++)
00151         {
00152             if (m[j]!=255)
00153                 Q_strcat(ip, sizeof(ip), "*");
00154             else
00155                 Q_strcat(ip, sizeof(ip), va("%i", b[j]));
00156             Q_strcat(ip, sizeof(ip), (j<3) ? "." : " ");
00157         }       
00158         if (strlen(iplist_final)+strlen(ip) < MAX_CVAR_VALUE_STRING)
00159         {
00160             Q_strcat( iplist_final, sizeof(iplist_final), ip);
00161         }
00162         else
00163         {
00164             Com_Printf("g_banIPs overflowed at MAX_CVAR_VALUE_STRING\n");
00165             break;
00166         }
00167     }
00168 
00169     trap_Cvar_Set( "g_banIPs", iplist_final );
00170 }

Here is the call graph for this function:


Variable Documentation

ipFilter_t ipFilters[MAX_IPFILTERS] [static]
 

Definition at line 70 of file g_svcmds.c.

Referenced by AddIP(), G_FilterPacket(), Svcmd_RemoveIP_f(), and UpdateIPBans().

int numIPFilters [static]
 

Definition at line 71 of file g_svcmds.c.

Referenced by AddIP().


Generated on Thu Aug 25 13:57:29 2005 for Quake III Arena by  doxygen 1.3.9.1