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

Referenced by SV_Map(), and SV_ReadServerFile().

◆ SV_Map()

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

Definition at line 394 of file sv_init.c.

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

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:1151
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:399
MAX_CLIENTS
#define MAX_CLIENTS
Definition: q_shared.h:86
edict_s::s
entity_state_t s
Definition: g_local.h:970
dedicated
cvar_t * dedicated
Definition: common.c:47
Sys_CopyProtect
void Sys_CopyProtect(void)
Definition: sys_win.c:191
MAX_QPATH
#define MAX_QPATH
Definition: q_shared.h:80
MAX_MODELS
#define MAX_MODELS
Definition: q_shared.h:89
server_static_t::spawncount
int spawncount
Definition: server.h:165
CS_SOUNDS
#define CS_SOUNDS
Definition: q_shared.h:1113
int
CONST PIXELFORMATDESCRIPTOR int
Definition: qgl_win.c:35
CVAR_NOSET
#define CVAR_NOSET
Definition: q_shared.h:319
maxclients
cvar_t * maxclients
Definition: g_main.c:44
Com_SetServerState
void Com_SetServerState(int state)
Definition: common.c:266
server_t::multicast_buf
byte multicast_buf[MAX_MSGLEN]
Definition: server.h:62
entity_state_s
Definition: q_shared.h:1145
PORT_MASTER
#define PORT_MASTER
Definition: qcommon.h:201
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:1149
UPDATE_BACKUP
#define UPDATE_BACKUP
Definition: qcommon.h:207
server_static_t::realtime
int realtime
Definition: server.h:161
CS_MODELS
#define CS_MODELS
Definition: q_shared.h:1112
edict_s::inuse
qboolean inuse
Definition: g_local.h:976
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:136
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:885
client_s::state
client_state_t state
Definition: server.h:97
CS_NAME
#define CS_NAME
Definition: q_shared.h:1101
server_t::demofile
FILE * demofile
Definition: server.h:65
SCR_BeginLoadingPlaque
void SCR_BeginLoadingPlaque(void)
Definition: cl_scrn.c:562
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:892
entity_state_s::effects
unsigned int effects
Definition: q_shared.h:1156
CVAR_SERVERINFO
#define CVAR_SERVERINFO
Definition: q_shared.h:318
server_state_t
server_state_t
Definition: server.h:32
entity_state_s::sound
int sound
Definition: q_shared.h:1161
NET_StringToAdr
qboolean NET_StringToAdr(char *s, netadr_t *a)
Definition: net_wins.c:262
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:1114
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:968
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:1110
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:323
client_s::lastcmd
usercmd_t lastcmd
Definition: server.h:102
MULTICAST_ALL_R
@ MULTICAST_ALL_R
Definition: q_shared.h:119
cvar_s::value
float value
Definition: q_shared.h:331
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:81
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:356
entity_state_s::number
int number
Definition: q_shared.h:1147
CVAR_LATCH
#define CVAR_LATCH
Definition: q_shared.h:321
MSG_WriteShort
void MSG_WriteShort(sizebuf_t *sb, int c)
Definition: common.c:316
server_t::attractloop
qboolean attractloop
Definition: server.h:47
Com_Error
void Com_Error(int code, char *fmt,...)
Definition: common.c:181
Z_Malloc
void * Z_Malloc(int size)
Definition: common.c:1200
server_t::loadgame
qboolean loadgame
Definition: server.h:48
ERR_DROP
#define ERR_DROP
Definition: qcommon.h:744
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:1180
MSG_WriteChar
void MSG_WriteChar(sizebuf_t *sb, int c)
Definition: common.c:290
SV_Multicast
void SV_Multicast(vec3_t origin, multicast_t to)
Definition: sv_send.c:161
name
cvar_t * name
Definition: cl_main.c:79
NET_Config
void NET_Config(qboolean multiplayer)
Definition: net_wins.c:695
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:165
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:559
svc_configstring
@ svc_configstring
Definition: qcommon.h:239
pm_airaccelerate
float pm_airaccelerate
Definition: pmove.c:57
MAX_SOUNDS
#define MAX_SOUNDS
Definition: q_shared.h:90
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:1152
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:157
client_s
Definition: server.h:95
Com_Printf
void Com_Printf(char *fmt,...)
Definition: common.c:104
EDICT_NUM
#define EDICT_NUM(n)
Definition: server.h:69
SV_ShutdownGameProgs
void SV_ShutdownGameProgs(void)
Definition: sv_game.c:305
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:1108
ss_loading
@ ss_loading
Definition: server.h:34
MAX_IMAGES
#define MAX_IMAGES
Definition: q_shared.h:91
max
#define max(a, b)
Definition: vk_local.h:75
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1223
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