icculus quake2 doxygen  1.0 dev
sv_init.c File Reference
#include "server.h"

Go to the source code of this file.

Functions

int SV_FindIndex (char *name, int start, int max, qboolean create)
 
int SV_ModelIndex (char *name)
 
int SV_SoundIndex (char *name)
 
int SV_ImageIndex (char *name)
 
void SV_CreateBaseline (void)
 
void SV_CheckForSavegame (void)
 
void SV_SpawnServer (char *server, char *spawnpoint, server_state_t serverstate, qboolean attractloop, qboolean loadgame)
 
void SV_InitGame (void)
 
void SV_Map (qboolean attractloop, char *levelstring, qboolean loadgame)
 

Variables

server_static_t svs
 
server_t sv
 

Function Documentation

◆ SV_CheckForSavegame()

void SV_CheckForSavegame ( void  )

Definition at line 117 of file sv_init.c.

118 {
119  char name[MAX_OSPATH];
120  FILE *f;
121  int i;
122 
123  if (sv_noreload->value)
124  return;
125 
126  if (Cvar_VariableValue ("deathmatch"))
127  return;
128 
129  Com_sprintf (name, sizeof(name), "%s/save/current/%s.sav", FS_Gamedir(), sv.name);
130  f = fopen (name, "rb");
131  if (!f)
132  return; // no savegame
133 
134  fclose (f);
135 
136  SV_ClearWorld ();
137 
138  // get configstrings and areaportals
139  SV_ReadLevelFile ();
140 
141  if (!sv.loadgame)
142  { // coming back to a level after being in a different
143  // level, so run it for ten seconds
144 
145  // rlava2 was sending too many lightstyles, and overflowing the
146  // reliable data. temporarily changing the server state to loading
147  // prevents these from being passed down.
148  server_state_t previousState; // PGM
149 
150  previousState = sv.state; // PGM
151  sv.state = ss_loading; // PGM
152  for (i=0 ; i<100 ; i++)
153  ge->RunFrame ();
154 
155  sv.state = previousState; // PGM
156  }
157 }

Referenced by SV_SpawnServer().

◆ SV_CreateBaseline()

void SV_CreateBaseline ( void  )

Definition at line 89 of file sv_init.c.

90 {
91  edict_t *svent;
92  int entnum;
93 
94  for (entnum = 1; entnum < ge->num_edicts ; entnum++)
95  {
96  svent = EDICT_NUM(entnum);
97  if (!svent->inuse)
98  continue;
99  if (!svent->s.modelindex && !svent->s.sound && !svent->s.effects)
100  continue;
101  svent->s.number = entnum;
102 
103  //
104  // take current state as baseline
105  //
106  VectorCopy (svent->s.origin, svent->s.old_origin);
107  sv.baselines[entnum] = svent->s;
108  }
109 }

Referenced by SV_SpawnServer().

◆ SV_FindIndex()

int SV_FindIndex ( char *  name,
int  start,
int  max,
qboolean  create 
)

Definition at line 32 of file sv_init.c.

33 {
34  int i;
35 
36  if (!name || !name[0])
37  return 0;
38 
39  for (i=1 ; i<max && sv.configstrings[start+i][0] ; i++)
40  if (!strcmp(sv.configstrings[start+i], name))
41  return i;
42 
43  if (!create)
44  return 0;
45 
46  if (i == max)
47  Com_Error (ERR_DROP, "*Index: overflow");
48 
49  strncpy (sv.configstrings[start+i], name, sizeof(sv.configstrings[i]));
50 
51  if (sv.state != ss_loading)
52  { // send the update to everyone
55  MSG_WriteShort (&sv.multicast, start+i);
58  }
59 
60  return i;
61 }

Referenced by SV_ImageIndex(), SV_ModelIndex(), and SV_SoundIndex().

◆ SV_ImageIndex()

int SV_ImageIndex ( char *  name)

Definition at line 74 of file sv_init.c.

75 {
76  return SV_FindIndex (name, CS_IMAGES, MAX_IMAGES, true);
77 }

Referenced by SV_InitGameProgs().

◆ SV_InitGame()

void SV_InitGame ( void  )

Definition at line 289 of file sv_init.c.

290 {
291  int i;
292  edict_t *ent;
293  char idmaster[32];
294 
295  if (svs.initialized)
296  {
297  // cause any connected clients to reconnect
298  SV_Shutdown ("Server restarted\n", true);
299  }
300  else
301  {
302  // make sure the client is down
303  CL_Drop ();
305  }
306 
307  // get any latched variable changes (maxclients, etc)
309 
310  svs.initialized = true;
311 
312  if (Cvar_VariableValue ("coop") && Cvar_VariableValue ("deathmatch"))
313  {
314  Com_Printf("Deathmatch and Coop both set, disabling Coop\n");
315  Cvar_FullSet ("coop", "0", CVAR_SERVERINFO | CVAR_LATCH);
316  }
317 
318  // dedicated servers are can't be single player and are usually DM
319  // so unless they explicity set coop, force it to deathmatch
320  if (dedicated->value)
321  {
322  if (!Cvar_VariableValue ("coop"))
323  Cvar_FullSet ("deathmatch", "1", CVAR_SERVERINFO | CVAR_LATCH);
324  }
325 
326  // init clients
327  if (Cvar_VariableValue ("deathmatch"))
328  {
329  if (maxclients->value <= 1)
330  Cvar_FullSet ("maxclients", "8", CVAR_SERVERINFO | CVAR_LATCH);
331  else if (maxclients->value > MAX_CLIENTS)
332  Cvar_FullSet ("maxclients", va("%i", MAX_CLIENTS), CVAR_SERVERINFO | CVAR_LATCH);
333  }
334  else if (Cvar_VariableValue ("coop"))
335  {
336  if (maxclients->value <= 1 || maxclients->value > 4)
337  Cvar_FullSet ("maxclients", "4", CVAR_SERVERINFO | CVAR_LATCH);
338 #ifdef COPYPROTECT
339  if (!sv.attractloop && !dedicated->value)
340  Sys_CopyProtect ();
341 #endif
342  }
343  else // non-deathmatch, non-coop is one player
344  {
345  Cvar_FullSet ("maxclients", "1", CVAR_SERVERINFO | CVAR_LATCH);
346 #ifdef COPYPROTECT
347  if (!sv.attractloop)
348  Sys_CopyProtect ();
349 #endif
350  }
351 
352  svs.spawncount = rand();
356 
357  // init network stuff
358  NET_Config ( (maxclients->value > 1) );
359 
360  // heartbeats will always be sent to the id master
361  svs.last_heartbeat = -99999; // send immediately
362  Com_sprintf(idmaster, sizeof(idmaster), "192.246.40.37:%i", PORT_MASTER);
363  NET_StringToAdr (idmaster, &master_adr[0]);
364 
365  // init game
366  SV_InitGameProgs ();
367  for (i=0 ; i<maxclients->value ; i++)
368  {
369  ent = EDICT_NUM(i+1);
370  ent->s.number = i+1;
371  svs.clients[i].edict = ent;
372  memset (&svs.clients[i].lastcmd, 0, sizeof(svs.clients[i].lastcmd));
373  }
374 }

Referenced by SV_Map(), and SV_ReadServerFile().

◆ SV_Map()

void SV_Map ( qboolean  attractloop,
char *  levelstring,
qboolean  loadgame 
)

Definition at line 393 of file sv_init.c.

394 {
395  char level[MAX_QPATH];
396  char *ch;
397  int l;
398  char spawnpoint[MAX_QPATH];
399 
400  sv.loadgame = loadgame;
401  sv.attractloop = attractloop;
402 
403  if (sv.state == ss_dead && !sv.loadgame)
404  SV_InitGame (); // the game is just starting
405 
406  strcpy (level, levelstring);
407 
408  // if there is a + in the map, set nextserver to the remainder
409  ch = strstr(level, "+");
410  if (ch)
411  {
412  *ch = 0;
413  Cvar_Set ("nextserver", va("gamemap \"%s\"", ch+1));
414  }
415  else
416  Cvar_Set ("nextserver", "");
417 
418  //ZOID special hack for end game screen in coop mode
419  if (Cvar_VariableValue ("coop") && !Q_stricmp(level, "victory.pcx"))
420  Cvar_Set ("nextserver", "gamemap \"*base1\"");
421 
422  // if there is a $, use the remainder as a spawnpoint
423  ch = strstr(level, "$");
424  if (ch)
425  {
426  *ch = 0;
427  strcpy (spawnpoint, ch+1);
428  }
429  else
430  spawnpoint[0] = 0;
431 
432  // skip the end-of-unit flag if necessary
433  if (level[0] == '*')
434  strcpy (level, level+1);
435 
436  l = strlen(level);
437  if (l > 4 && !strcmp (level+l-4, ".cin") )
438  {
439  SCR_BeginLoadingPlaque (); // for local system
440  SV_BroadcastCommand ("changing\n");
441  SV_SpawnServer (level, spawnpoint, ss_cinematic, attractloop, loadgame);
442  }
443  else if (l > 4 && !strcmp (level+l-4, ".dm2") )
444  {
445  SCR_BeginLoadingPlaque (); // for local system
446  SV_BroadcastCommand ("changing\n");
447  SV_SpawnServer (level, spawnpoint, ss_demo, attractloop, loadgame);
448  }
449  else if (l > 4 && !strcmp (level+l-4, ".pcx") )
450  {
451  SCR_BeginLoadingPlaque (); // for local system
452  SV_BroadcastCommand ("changing\n");
453  SV_SpawnServer (level, spawnpoint, ss_pic, attractloop, loadgame);
454  }
455  else
456  {
457  SCR_BeginLoadingPlaque (); // for local system
458  SV_BroadcastCommand ("changing\n");
460  SV_SpawnServer (level, spawnpoint, ss_game, attractloop, loadgame);
461  Cbuf_CopyToDefer ();
462  }
463 
464  SV_BroadcastCommand ("reconnect\n");
465 }

Referenced by SV_DemoMap_f(), SV_GameMap_f(), and SV_Loadgame_f().

◆ SV_ModelIndex()

int SV_ModelIndex ( char *  name)

Definition at line 64 of file sv_init.c.

65 {
66  return SV_FindIndex (name, CS_MODELS, MAX_MODELS, true);
67 }

Referenced by PF_setmodel(), and SV_InitGameProgs().

◆ SV_SoundIndex()

int SV_SoundIndex ( char *  name)

Definition at line 69 of file sv_init.c.

70 {
71  return SV_FindIndex (name, CS_SOUNDS, MAX_SOUNDS, true);
72 }

Referenced by SV_InitGameProgs().

◆ SV_SpawnServer()

void SV_SpawnServer ( char *  server,
char *  spawnpoint,
server_state_t  serverstate,
qboolean  attractloop,
qboolean  loadgame 
)

Definition at line 169 of file sv_init.c.

170 {
171  int i;
172  unsigned checksum;
173 
174  if (attractloop)
175  Cvar_Set ("paused", "0");
176 
177  Com_Printf ("------- Server Initialization -------\n");
178 
179  Com_DPrintf ("SpawnServer: %s\n",server);
180  if (sv.demofile)
181  fclose (sv.demofile);
182 
183  svs.spawncount++; // any partially connected client will be
184  // restarted
185  sv.state = ss_dead;
187 
188  // wipe the entire per-level structure
189  memset (&sv, 0, sizeof(sv));
190  svs.realtime = 0;
191  sv.loadgame = loadgame;
192  sv.attractloop = attractloop;
193 
194  // save name for levels that don't set message
195  strcpy (sv.configstrings[CS_NAME], server);
196  if (Cvar_VariableValue ("deathmatch"))
197  {
200  }
201  else
202  {
203  strcpy(sv.configstrings[CS_AIRACCEL], "0");
204  pm_airaccelerate = 0;
205  }
206 
208 
209  strcpy (sv.name, server);
210 
211  // leave slots at start for clients only
212  for (i=0 ; i<maxclients->value ; i++)
213  {
214  // needs to reconnect
215  if (svs.clients[i].state > cs_connected)
217  svs.clients[i].lastframe = -1;
218  }
219 
220  sv.time = 1000;
221 
222  strcpy (sv.name, server);
223  strcpy (sv.configstrings[CS_NAME], server);
224 
225  if (serverstate != ss_game)
226  {
227  sv.models[1] = CM_LoadMap ("", false, &checksum); // no real map
228  }
229  else
230  {
232  "maps/%s.bsp", server);
233  sv.models[1] = CM_LoadMap (sv.configstrings[CS_MODELS+1], false, &checksum);
234  }
236  "%i", checksum);
237 
238  //
239  // clear physics interaction links
240  //
241  SV_ClearWorld ();
242 
243  for (i=1 ; i< CM_NumInlineModels() ; i++)
244  {
246  "*%i", i);
248  }
249 
250  //
251  // spawn the rest of the entities on the map
252  //
253 
254  // precache and static commands can be issued during
255  // map initialization
256  sv.state = ss_loading;
258 
259  // load and spawn all other entities
260  ge->SpawnEntities ( sv.name, CM_EntityString(), spawnpoint );
261 
262  // run two frames to allow everything to settle
263  ge->RunFrame ();
264  ge->RunFrame ();
265 
266  // all precaches are complete
267  sv.state = serverstate;
269 
270  // create a baseline for more efficient communications
272 
273  // check for a savegame
275 
276  // set serverinfo variable
278 
279  Com_Printf ("-------------------------------------\n");
280 }

Referenced by SV_Map().

Variable Documentation

◆ sv

◆ svs

client_s::lastframe
int lastframe
Definition: server.h:101
entity_state_s::old_origin
vec3_t old_origin
Definition: q_shared.h:1175
game_export_t::SpawnEntities
void(* SpawnEntities)(char *mapname, char *entstring, char *spawnpoint)
Definition: game.h:192
CL_Drop
void CL_Drop(void)
Definition: cl_main.c:412
MAX_CLIENTS
#define MAX_CLIENTS
Definition: q_shared.h:79
edict_s::s
entity_state_t s
Definition: g_local.h:964
dedicated
cvar_t * dedicated
Definition: common.c:47
Sys_CopyProtect
void Sys_CopyProtect(void)
Definition: sys_win.c:186
MAX_QPATH
#define MAX_QPATH
Definition: q_shared.h:73
MAX_MODELS
#define MAX_MODELS
Definition: q_shared.h:82
server_static_t::spawncount
int spawncount
Definition: server.h:165
CS_SOUNDS
#define CS_SOUNDS
Definition: q_shared.h:1137
CVAR_NOSET
#define CVAR_NOSET
Definition: q_shared.h:312
maxclients
cvar_t * maxclients
Definition: g_main.c:44
Com_SetServerState
void Com_SetServerState(int state)
Definition: common.c:285
server_t::multicast_buf
byte multicast_buf[MAX_MSGLEN]
Definition: server.h:62
entity_state_s
Definition: q_shared.h:1169
PORT_MASTER
#define PORT_MASTER
Definition: qcommon.h:184
SV_SpawnServer
void SV_SpawnServer(char *server, char *spawnpoint, server_state_t serverstate, qboolean attractloop, qboolean loadgame)
Definition: sv_init.c:169
SV_ReadLevelFile
void SV_ReadLevelFile(void)
Definition: sv_ccmds.c:306
entity_state_s::origin
vec3_t origin
Definition: q_shared.h:1173
UPDATE_BACKUP
#define UPDATE_BACKUP
Definition: qcommon.h:190
server_static_t::realtime
int realtime
Definition: server.h:161
CS_MODELS
#define CS_MODELS
Definition: q_shared.h:1136
edict_s::inuse
qboolean inuse
Definition: g_local.h:970
i
int i
Definition: q_shared.c:305
sv
server_t sv
Definition: sv_init.c:24
SV_ClearWorld
void SV_ClearWorld(void)
Definition: sv_world.c:135
server_t::multicast
sizebuf_t multicast
Definition: server.h:61
cs_connected
@ cs_connected
Definition: server.h:78
SZ_Init
void SZ_Init(sizebuf_t *buf, byte *data, int length)
Definition: common.c:904
client_s::state
client_state_t state
Definition: server.h:97
CS_NAME
#define CS_NAME
Definition: q_shared.h:1125
server_t::demofile
FILE * demofile
Definition: server.h:65
SCR_BeginLoadingPlaque
void SCR_BeginLoadingPlaque(void)
Definition: cl_scrn.c:571
SV_BroadcastCommand
void SV_BroadcastCommand(char *fmt,...)
Definition: sv_send.c:132
SV_CreateBaseline
void SV_CreateBaseline(void)
Definition: sv_init.c:89
SZ_Clear
void SZ_Clear(sizebuf_t *buf)
Definition: common.c:911
entity_state_s::effects
unsigned int effects
Definition: q_shared.h:1180
CVAR_SERVERINFO
#define CVAR_SERVERINFO
Definition: q_shared.h:311
server_state_t
server_state_t
Definition: server.h:32
entity_state_s::sound
int sound
Definition: q_shared.h:1185
NET_StringToAdr
qboolean NET_StringToAdr(char *s, netadr_t *a)
Definition: net_wins.c:257
va
char * va(char *format,...)
Definition: q_shared.c:1050
server_t::baselines
entity_state_t baselines[MAX_EDICTS]
Definition: server.h:57
server_static_t::client_entities
entity_state_t * client_entities
Definition: server.h:171
CS_IMAGES
#define CS_IMAGES
Definition: q_shared.h:1138
server_static_t::clients
client_t * clients
Definition: server.h:168
ss_cinematic
@ ss_cinematic
Definition: server.h:36
edict_s
Definition: g_local.h:962
SV_FindIndex
int SV_FindIndex(char *name, int start, int max, qboolean create)
Definition: sv_init.c:32
CS_MAPCHECKSUM
#define CS_MAPCHECKSUM
Definition: q_shared.h:1134
server_static_t::num_client_entities
int num_client_entities
Definition: server.h:169
Cvar_FullSet
cvar_t * Cvar_FullSet(char *var_name, char *value, int flags)
Definition: cvar.c:288
ge
game_export_t * ge
Definition: sv_game.c:24
svs
server_static_t svs
Definition: sv_init.c:23
ss_demo
@ ss_demo
Definition: server.h:37
SV_InitGameProgs
void SV_InitGameProgs(void)
Definition: sv_game.c:325
client_s::lastcmd
usercmd_t lastcmd
Definition: server.h:102
MULTICAST_ALL_R
@ MULTICAST_ALL_R
Definition: q_shared.h:112
cvar_s::value
float value
Definition: q_shared.h:324
SV_CheckForSavegame
void SV_CheckForSavegame(void)
Definition: sv_init.c:117
server_t::models
struct cmodel_s * models[MAX_MODELS]
Definition: server.h:54
MAX_OSPATH
#define MAX_OSPATH
Definition: q_shared.h:74
master_adr
netadr_t master_adr[MAX_MASTERS]
Definition: sv_main.c:23
MSG_WriteString
void MSG_WriteString(sizebuf_t *sb, char *s)
Definition: common.c:375
entity_state_s::number
int number
Definition: q_shared.h:1171
CVAR_LATCH
#define CVAR_LATCH
Definition: q_shared.h:314
MSG_WriteShort
void MSG_WriteShort(sizebuf_t *sb, int c)
Definition: common.c:335
server_t::attractloop
qboolean attractloop
Definition: server.h:47
Com_Error
void Com_Error(int code, char *fmt,...)
Definition: common.c:203
Z_Malloc
void * Z_Malloc(int size)
Definition: common.c:1223
server_t::loadgame
qboolean loadgame
Definition: server.h:48
ERR_DROP
#define ERR_DROP
Definition: qcommon.h:736
CM_InlineModel
cmodel_t * CM_InlineModel(char *name)
Definition: cmodel.c:639
Q_stricmp
int Q_stricmp(char *s1, char *s2)
Definition: q_shared.c:1192
MSG_WriteChar
void MSG_WriteChar(sizebuf_t *sb, int c)
Definition: common.c:309
SV_Multicast
void SV_Multicast(vec3_t origin, multicast_t to)
Definition: sv_send.c:161
name
cvar_t * name
Definition: cl_main.c:94
NET_Config
void NET_Config(qboolean multiplayer)
Definition: net_wins.c:690
SV_SendClientMessages
void SV_SendClientMessages(void)
Definition: sv_send.c:490
server_static_t::last_heartbeat
int last_heartbeat
Definition: server.h:173
SV_Shutdown
void SV_Shutdown(char *finalmsg, qboolean reconnect)
Definition: sv_main.c:1035
server_static_t::initialized
qboolean initialized
Definition: server.h:160
VectorCopy
#define VectorCopy(a, b)
Definition: q_shared.h:158
game_export_t::RunFrame
void(* RunFrame)(void)
Definition: game.h:213
CM_LoadMap
cmodel_t * CM_LoadMap(char *name, qboolean clientload, unsigned *checksum)
Definition: cmodel.c:548
CM_EntityString
char * CM_EntityString(void)
Definition: cmodel.c:662
vec3_origin
vec3_t vec3_origin
Definition: q_shared.c:24
server_t::time
unsigned time
Definition: server.h:50
Cbuf_CopyToDefer
void Cbuf_CopyToDefer(void)
Definition: cmd.c:147
level
GLint level
Definition: qgl_win.c:116
FS_Gamedir
char * FS_Gamedir(void)
Definition: files.c:590
svc_configstring
@ svc_configstring
Definition: qcommon.h:222
pm_airaccelerate
float pm_airaccelerate
Definition: pmove.c:57
MAX_SOUNDS
#define MAX_SOUNDS
Definition: q_shared.h:83
Cvar_GetLatchedVars
void Cvar_GetLatchedVars(void)
Definition: cvar.c:336
ss_game
@ ss_game
Definition: server.h:35
SV_InitGame
void SV_InitGame(void)
Definition: sv_init.c:289
entity_state_s::modelindex
int modelindex
Definition: q_shared.h:1176
server_t::state
server_state_t state
Definition: server.h:45
CM_NumInlineModels
int CM_NumInlineModels(void)
Definition: cmodel.c:657
Cvar_Set
cvar_t * Cvar_Set(char *var_name, char *value)
Definition: cvar.c:278
Com_DPrintf
void Com_DPrintf(char *fmt,...)
Definition: common.c:155
client_s
Definition: server.h:95
Com_Printf
void Com_Printf(char *fmt,...)
Definition: common.c:102
EDICT_NUM
#define EDICT_NUM(n)
Definition: server.h:69
sv_noreload
cvar_t * sv_noreload
Definition: sv_main.c:45
server_t::configstrings
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH]
Definition: server.h:56
ss_pic
@ ss_pic
Definition: server.h:38
CS_AIRACCEL
#define CS_AIRACCEL
Definition: q_shared.h:1132
ss_loading
@ ss_loading
Definition: server.h:34
MAX_IMAGES
#define MAX_IMAGES
Definition: q_shared.h:84
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1236
server_t::name
char name[MAX_QPATH]
Definition: server.h:53
ss_dead
@ ss_dead
Definition: server.h:33
sv_airaccelerate
cvar_t * sv_airaccelerate
Definition: sv_main.c:43
game_export_t::num_edicts
int num_edicts
Definition: game.h:231
client_s::edict
edict_t * edict
Definition: server.h:114
Cvar_VariableValue
float Cvar_VariableValue(char *var_name)
Definition: cvar.c:63