icculus quake2 doxygen  1.0 dev
g_svcmds.c File Reference
#include "g_local.h"

Go to the source code of this file.

Classes

struct  ipfilter_t
 

Macros

#define MAX_IPFILTERS   1024
 

Functions

void Svcmd_Test_f (void)
 
static qboolean StringToFilter (char *s, ipfilter_t *f)
 
qboolean SV_FilterPacket (char *from)
 
void SVCmd_AddIP_f (void)
 
void SVCmd_RemoveIP_f (void)
 
void SVCmd_ListIP_f (void)
 
void SVCmd_WriteIP_f (void)
 
void ServerCommand (void)
 

Variables

ipfilter_t ipfilters [MAX_IPFILTERS]
 
int numipfilters
 

Macro Definition Documentation

◆ MAX_IPFILTERS

#define MAX_IPFILTERS   1024

Definition at line 66 of file g_svcmds.c.

Function Documentation

◆ ServerCommand()

void ServerCommand ( void  )

Definition at line 282 of file g_svcmds.c.

283 {
284  char *cmd;
285 
286  cmd = gi.argv(1);
287  if (Q_stricmp (cmd, "test") == 0)
288  Svcmd_Test_f ();
289  else if (Q_stricmp (cmd, "addip") == 0)
290  SVCmd_AddIP_f ();
291  else if (Q_stricmp (cmd, "removeip") == 0)
292  SVCmd_RemoveIP_f ();
293  else if (Q_stricmp (cmd, "listip") == 0)
294  SVCmd_ListIP_f ();
295  else if (Q_stricmp (cmd, "writeip") == 0)
296  SVCmd_WriteIP_f ();
297  else
298  gi.cprintf (NULL, PRINT_HIGH, "Unknown server command \"%s\"\n", cmd);
299 }

Referenced by GetGameAPI().

◆ StringToFilter()

static qboolean StringToFilter ( char *  s,
ipfilter_t f 
)
static

Definition at line 76 of file g_svcmds.c.

77 {
78  char num[128];
79  int i, j;
80  byte b[4];
81  byte m[4];
82 
83  for (i=0 ; i<4 ; i++)
84  {
85  b[i] = 0;
86  m[i] = 0;
87  }
88 
89  for (i=0 ; i<4 ; i++)
90  {
91  if (*s < '0' || *s > '9')
92  {
93  gi.cprintf(NULL, PRINT_HIGH, "Bad filter address: %s\n", s);
94  return false;
95  }
96 
97  j = 0;
98  while (*s >= '0' && *s <= '9')
99  {
100  num[j++] = *s++;
101  }
102  num[j] = 0;
103  b[i] = atoi(num);
104  if (b[i] != 0)
105  m[i] = 255;
106 
107  if (!*s)
108  break;
109  s++;
110  }
111 
112  f->mask = *(unsigned *)m;
113  f->compare = *(unsigned *)b;
114 
115  return true;
116 }

Referenced by SVCmd_AddIP_f(), and SVCmd_RemoveIP_f().

◆ SV_FilterPacket()

qboolean SV_FilterPacket ( char *  from)

Definition at line 123 of file g_svcmds.c.

124 {
125  int i;
126  unsigned in;
127  byte m[4];
128  char *p;
129 
130  i = 0;
131  p = from;
132  while (*p && i < 4) {
133  m[i] = 0;
134  while (*p >= '0' && *p <= '9') {
135  m[i] = m[i]*10 + (*p - '0');
136  p++;
137  }
138  if (!*p || *p == ':')
139  break;
140  i++, p++;
141  }
142 
143  in = *(unsigned *)m;
144 
145  for (i=0 ; i<numipfilters ; i++)
146  if ( (in & ipfilters[i].mask) == ipfilters[i].compare)
147  return (int)filterban->value;
148 
149  return (int)!filterban->value;
150 }

Referenced by ClientConnect().

◆ SVCmd_AddIP_f()

void SVCmd_AddIP_f ( void  )

Definition at line 158 of file g_svcmds.c.

159 {
160  int i;
161 
162  if (gi.argc() < 3) {
163  gi.cprintf(NULL, PRINT_HIGH, "Usage: addip <ip-mask>\n");
164  return;
165  }
166 
167  for (i=0 ; i<numipfilters ; i++)
168  if (ipfilters[i].compare == 0xffffffff)
169  break; // free spot
170  if (i == numipfilters)
171  {
173  {
174  gi.cprintf (NULL, PRINT_HIGH, "IP filter list is full\n");
175  return;
176  }
177  numipfilters++;
178  }
179 
180  if (!StringToFilter (gi.argv(2), &ipfilters[i]))
181  ipfilters[i].compare = 0xffffffff;
182 }

Referenced by ServerCommand().

◆ SVCmd_ListIP_f()

void SVCmd_ListIP_f ( void  )

Definition at line 220 of file g_svcmds.c.

221 {
222  int i;
223  byte b[4];
224 
225  gi.cprintf (NULL, PRINT_HIGH, "Filter list:\n");
226  for (i=0 ; i<numipfilters ; i++)
227  {
228  *(unsigned *)b = ipfilters[i].compare;
229  gi.cprintf (NULL, PRINT_HIGH, "%3i.%3i.%3i.%3i\n", b[0], b[1], b[2], b[3]);
230  }
231 }

Referenced by ServerCommand().

◆ SVCmd_RemoveIP_f()

void SVCmd_RemoveIP_f ( void  )

Definition at line 189 of file g_svcmds.c.

190 {
191  ipfilter_t f;
192  int i, j;
193 
194  if (gi.argc() < 3) {
195  gi.cprintf(NULL, PRINT_HIGH, "Usage: sv removeip <ip-mask>\n");
196  return;
197  }
198 
199  if (!StringToFilter (gi.argv(2), &f))
200  return;
201 
202  for (i=0 ; i<numipfilters ; i++)
203  if (ipfilters[i].mask == f.mask
204  && ipfilters[i].compare == f.compare)
205  {
206  for (j=i+1 ; j<numipfilters ; j++)
207  ipfilters[j-1] = ipfilters[j];
208  numipfilters--;
209  gi.cprintf (NULL, PRINT_HIGH, "Removed.\n");
210  return;
211  }
212  gi.cprintf (NULL, PRINT_HIGH, "Didn't find %s.\n", gi.argv(2));
213 }

Referenced by ServerCommand().

◆ Svcmd_Test_f()

void Svcmd_Test_f ( void  )

Definition at line 24 of file g_svcmds.c.

25 {
26  gi.cprintf (NULL, PRINT_HIGH, "Svcmd_Test_f()\n");
27 }

Referenced by ServerCommand().

◆ SVCmd_WriteIP_f()

void SVCmd_WriteIP_f ( void  )

Definition at line 238 of file g_svcmds.c.

239 {
240  FILE *f;
241  char name[MAX_OSPATH];
242  byte b[4];
243  int i;
244  cvar_t *game;
245 
246  game = gi.cvar("game", "", 0);
247 
248  if (!*game->string)
249  sprintf (name, "%s/listip.cfg", GAMEVERSION);
250  else
251  sprintf (name, "%s/listip.cfg", game->string);
252 
253  gi.cprintf (NULL, PRINT_HIGH, "Writing %s.\n", name);
254 
255  f = fopen (name, "wb");
256  if (!f)
257  {
258  gi.cprintf (NULL, PRINT_HIGH, "Couldn't open %s\n", name);
259  return;
260  }
261 
262  fprintf(f, "set filterban %d\n", (int)filterban->value);
263 
264  for (i=0 ; i<numipfilters ; i++)
265  {
266  *(unsigned *)b = ipfilters[i].compare;
267  fprintf (f, "sv addip %i.%i.%i.%i\n", b[0], b[1], b[2], b[3]);
268  }
269 
270  fclose (f);
271 }

Referenced by ServerCommand().

Variable Documentation

◆ ipfilters

◆ numipfilters

int numipfilters
gi
game_import_t gi
Definition: g_main.c:25
game_import_t::cvar
cvar_t *(* cvar)(char *var_name, char *value, int flags)
Definition: game.h:162
ipfilter_t::mask
unsigned mask
Definition: g_svcmds.c:62
ipfilter_t::compare
unsigned compare
Definition: g_svcmds.c:63
i
int i
Definition: q_shared.c:305
MAX_IPFILTERS
#define MAX_IPFILTERS
Definition: g_svcmds.c:66
cvar_s
Definition: q_shared.h:317
j
GLint j
Definition: qgl_win.c:150
SVCmd_ListIP_f
void SVCmd_ListIP_f(void)
Definition: g_svcmds.c:220
game_import_t::argc
int(* argc)(void)
Definition: game.h:167
ipfilter_t
Definition: g_svcmds.c:60
Svcmd_Test_f
void Svcmd_Test_f(void)
Definition: g_svcmds.c:24
cvar_s::value
float value
Definition: q_shared.h:324
game
game_locals_t game
Definition: g_main.c:23
MAX_OSPATH
#define MAX_OSPATH
Definition: q_shared.h:74
StringToFilter
static qboolean StringToFilter(char *s, ipfilter_t *f)
Definition: g_svcmds.c:76
PRINT_HIGH
#define PRINT_HIGH
Definition: q_shared.h:92
NULL
#define NULL
Definition: q_shared.h:60
filterban
cvar_t * filterban
Definition: g_main.c:50
GAMEVERSION
#define GAMEVERSION
Definition: g_local.h:31
Q_stricmp
int Q_stricmp(char *s1, char *s2)
Definition: q_shared.c:1192
SVCmd_AddIP_f
void SVCmd_AddIP_f(void)
Definition: g_svcmds.c:158
name
cvar_t * name
Definition: cl_main.c:94
game_import_t::cprintf
void(* cprintf)(edict_t *ent, int printlevel, char *fmt,...)
Definition: game.h:107
SVCmd_RemoveIP_f
void SVCmd_RemoveIP_f(void)
Definition: g_svcmds.c:189
ipfilters
ipfilter_t ipfilters[MAX_IPFILTERS]
Definition: g_svcmds.c:68
numipfilters
int numipfilters
Definition: g_svcmds.c:69
mask
GLint GLuint mask
Definition: qgl_win.c:317
SVCmd_WriteIP_f
void SVCmd_WriteIP_f(void)
Definition: g_svcmds.c:238
game_import_t::argv
char *(* argv)(int n)
Definition: game.h:168