Debian Codegraph @

code/server/sv_init.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23 #include "server.h"
24
25
26 /*
27 ===============
28 SV_SendConfigstring
29
30 Creates and sends the server command necessary to update the CS index for the
31 given client
32 ===============
33 */
34 static void SV_SendConfigstring(client_t *client, int index)
35 {
36 int maxChunkSize = MAX_STRING_CHARS - 24;
37 int len;
38
39 len = strlen(sv.configstrings[index]);
40
41 if( len >= maxChunkSize ) {
42 int sent = 0;
43 int remaining = len;
44 char *cmd;
45 char buf[MAX_STRING_CHARS];
46
47 while (remaining > 0 ) {
48 if ( sent == 0 ) {
49 cmd = "bcs0";
50 }
51 else if( remaining < maxChunkSize ) {
52 cmd = "bcs2";
53 }
54 else {
55 cmd = "bcs1";
56 }
57 Q_strncpyz( buf, &sv.configstrings[index][sent],
58 maxChunkSize );
59
60 SV_SendServerCommand( client, "%s %i \"%s\"\n", cmd,
61 index, buf );
62
63 sent += (maxChunkSize - 1);
64 remaining -= (maxChunkSize - 1);
65 }
66 } else {
67 // standard cs, just send it
68 SV_SendServerCommand( client, "cs %i \"%s\"\n", index,
69 sv.configstrings[index] );
70 }
71 }
72
73 /*
74 ===============
75 SV_UpdateConfigstrings
76
77 Called when a client goes from CS_PRIMED to CS_ACTIVE. Updates all
78 Configstring indexes that have changed while the client was in CS_PRIMED
79 ===============
80 */
81 void SV_UpdateConfigstrings(client_t *client)
82 {
83 int index;
84
85 for( index = 0; index < MAX_CONFIGSTRINGS; index++ ) {
86 // if the CS hasn't changed since we went to CS_PRIMED, ignore
87 if(!client->csUpdated[index])
88 continue;
89
90 // do not always send server info to all clients
91 if ( index == CS_SERVERINFO && client->gentity &&
92 (client->gentity->r.svFlags & SVF_NOSERVERINFO) ) {
93 continue;
94 }
95 SV_SendConfigstring(client, index);
96 client->csUpdated[index] = qfalse;
97 }
98 }
99
100 /*
101 ===============
102 SV_SetConfigstring
103
104 ===============
105 */
106 void SV_SetConfigstring (int index, const char *val) {
107 int i;
108 client_t *client;
109
110 if ( index < 0 || index >= MAX_CONFIGSTRINGS ) {
111 Com_Error (ERR_DROP, "SV_SetConfigstring: bad index %i", index);
112 }
113
114 if ( !val ) {
115 val = "";
116 }
117
118 // don't bother broadcasting an update if no change
119 if ( !strcmp( val, sv.configstrings[ index ] ) ) {
120 return;
121 }
122
123 // change the string in sv
124 Z_Free( sv.configstrings[index] );
125 sv.configstrings[index] = CopyString( val );
126
127 // send it to all the clients if we aren't
128 // spawning a new server
129 if ( sv.state == SS_GAME || sv.restarting ) {
130
131 // send the data to all relevant clients
132 for (i = 0, client = svs.clients; i < sv_maxclients->integer ; i++, client++) {
133 if ( client->state < CS_ACTIVE ) {
134 if ( client->state == CS_PRIMED )
135 client->csUpdated[ index ] = qtrue;
136 continue;
137 }
138 // do not always send server info to all clients
139 if ( index == CS_SERVERINFO && client->gentity && (client->gentity->r.svFlags & SVF_NOSERVERINFO) ) {
140 continue;
141 }
142
143 SV_SendConfigstring(client, index);
144 }
145 }
146 }
147
148 /*
149 ===============
150 SV_GetConfigstring
151
152 ===============
153 */
154 void SV_GetConfigstring( int index, char *buffer, int bufferSize ) {
155 if ( bufferSize < 1 ) {
156 Com_Error( ERR_DROP, "SV_GetConfigstring: bufferSize == %i", bufferSize );
157 }
158 if ( index < 0 || index >= MAX_CONFIGSTRINGS ) {
159 Com_Error (ERR_DROP, "SV_GetConfigstring: bad index %i", index);
160 }
161 if ( !sv.configstrings[index] ) {
162 buffer[0] = 0;
163 return;
164 }
165
166 Q_strncpyz( buffer, sv.configstrings[index], bufferSize );
167 }
168
169
170 /*
171 ===============
172 SV_SetUserinfo
173
174 ===============
175 */
176 void SV_SetUserinfo( int index, const char *val ) {
177 if ( index < 0 || index >= sv_maxclients->integer ) {
178 Com_Error (ERR_DROP, "SV_SetUserinfo: bad index %i", index);
179 }
180
181 if ( !val ) {
182 val = "";
183 }
184
185 Q_strncpyz( svs.clients[index].userinfo, val, sizeof( svs.clients[ index ].userinfo ) );
186 Q_strncpyz( svs.clients[index].name, Info_ValueForKey( val, "name" ), sizeof(svs.clients[index].name) );
187 }
188
189
190
191 /*
192 ===============
193 SV_GetUserinfo
194
195 ===============
196 */
197 void SV_GetUserinfo( int index, char *buffer, int bufferSize ) {
198 if ( bufferSize < 1 ) {
199 Com_Error( ERR_DROP, "SV_GetUserinfo: bufferSize == %i", bufferSize );
200 }
201 if ( index < 0 || index >= sv_maxclients->integer ) {
202 Com_Error (ERR_DROP, "SV_GetUserinfo: bad index %i", index);
203 }
204 Q_strncpyz( buffer, svs.clients[ index ].userinfo, bufferSize );
205 }
206
207
208 /*
209 ================
210 SV_CreateBaseline
211
212 Entity baselines are used to compress non-delta messages
213 to the clients -- only the fields that differ from the
214 baseline will be transmitted
215 ================
216 */
217 static void SV_CreateBaseline( void ) {
218 sharedEntity_t *svent;
219 int entnum;
220
221 for ( entnum = 1; entnum < sv.num_entities ; entnum++ ) {
222 svent = SV_GentityNum(entnum);
223 if (!svent->r.linked) {
224 continue;
225 }
226 svent->s.number = entnum;
227
228 //
229 // take current state as baseline
230 //
231 sv.svEntities[entnum].baseline = svent->s;
232 }
233 }
234
235
236 /*
237 ===============
238 SV_BoundMaxClients
239
240 ===============
241 */
242 static void SV_BoundMaxClients( int minimum ) {
243 // get the current maxclients value
244 Cvar_Get( "sv_maxclients", "8", 0 );
245
246 sv_maxclients->modified = qfalse;
247
248 if ( sv_maxclients->integer < minimum ) {
249 Cvar_Set( "sv_maxclients", va("%i", minimum) );
250 } else if ( sv_maxclients->integer > MAX_CLIENTS ) {
251 Cvar_Set( "sv_maxclients", va("%i", MAX_CLIENTS) );
252 }
253 }
254
255
256 /*
257 ===============
258 SV_Startup
259
260 Called when a host starts a map when it wasn't running
261 one before. Successive map or map_restart commands will
262 NOT cause this to be called, unless the game is exited to
263 the menu system first.
264 ===============
265 */
266 static void SV_Startup( void ) {
267 if ( svs.initialized ) {
268 Com_Error( ERR_FATAL, "SV_Startup: svs.initialized" );
269 }
270 SV_BoundMaxClients( 1 );
271
272 svs.clients = Z_Malloc (sizeof(client_t) * sv_maxclients->integer );
273 if ( com_dedicated->integer ) {
274 svs.numSnapshotEntities = sv_maxclients->integer * PACKET_BACKUP * MAX_SNAPSHOT_ENTITIES;
275 } else {
276 // we don't need nearly as many when playing locally
277 svs.numSnapshotEntities = sv_maxclients->integer * 4 * MAX_SNAPSHOT_ENTITIES;
278 }
279 svs.initialized = qtrue;
280
281 // Don't respect sv_killserver unless a server is actually running
282 if ( sv_killserver->integer ) {
283 Cvar_Set( "sv_killserver", "0" );
284 }
285
286 Cvar_Set( "sv_running", "1" );
287
288 // Join the ipv6 multicast group now that a map is running so clients can scan for us on the local network.
289 NET_JoinMulticast6();
290 }
291
292
293 /*
294 ==================
295 SV_ChangeMaxClients
296 ==================
297 */
298 void SV_ChangeMaxClients( void ) {
299 int oldMaxClients;
300 int i;
301 client_t *oldClients;
302 int count;
303
304 // get the highest client number in use
305 count = 0;
306 for ( i = 0 ; i < sv_maxclients->integer ; i++ ) {
307 if ( svs.clients[i].state >= CS_CONNECTED ) {
308 if (i > count)
309 count = i;
310 }
311 }
312 count++;
313
314 oldMaxClients = sv_maxclients->integer;
315 // never go below the highest client number in use
316 SV_BoundMaxClients( count );
317 // if still the same
318 if ( sv_maxclients->integer == oldMaxClients ) {
319 return;
320 }
321
322 oldClients = Hunk_AllocateTempMemory( count * sizeof(client_t) );
323 // copy the clients to hunk memory
324 for ( i = 0 ; i < count ; i++ ) {
325 if ( svs.clients[i].state >= CS_CONNECTED ) {
326 oldClients[i] = svs.clients[i];
327 }
328 else {
329 Com_Memset(&oldClients[i], 0, sizeof(client_t));
330 }
331 }
332
333 // free old clients arrays
334 Z_Free( svs.clients );
335
336 // allocate new clients
337 svs.clients = Z_Malloc ( sv_maxclients->integer * sizeof(client_t) );
338 Com_Memset( svs.clients, 0, sv_maxclients->integer * sizeof(client_t) );
339
340 // copy the clients over
341 for ( i = 0 ; i < count ; i++ ) {
342 if ( oldClients[i].state >= CS_CONNECTED ) {
343 svs.clients[i] = oldClients[i];
344 }
345 }
346
347 // free the old clients on the hunk
348 Hunk_FreeTempMemory( oldClients );
349
350 // allocate new snapshot entities
351 if ( com_dedicated->integer ) {
352 svs.numSnapshotEntities = sv_maxclients->integer * PACKET_BACKUP * MAX_SNAPSHOT_ENTITIES;
353 } else {
354 // we don't need nearly as many when playing locally
355 svs.numSnapshotEntities = sv_maxclients->integer * 4 * MAX_SNAPSHOT_ENTITIES;
356 }
357 }
358
359 /*
360 ================
361 SV_ClearServer
362 ================
363 */
364 static void SV_ClearServer(void) {
365 int i;
366
367 for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) {
368 if ( sv.configstrings[i] ) {
369 Z_Free( sv.configstrings[i] );
370 }
371 }
372 Com_Memset (&sv, 0, sizeof(sv));
373 }
374
375 /*
376 ================
377 SV_TouchFile
378 ================
379 */
380 static void SV_TouchFile( const char *filename ) {
381 fileHandle_t f;
382
383 FS_FOpenFileRead( filename, &f, qfalse );
384 if ( f ) {
385 FS_FCloseFile( f );
386 }
387 }
388
389 /*
390 ================
391 SV_SpawnServer
392
393 Change the server to a new map, taking all connected
394 clients along with it.
395 This is NOT called for map_restart
396 ================
397 */
398 void SV_SpawnServer( char *server, qboolean killBots ) {
399 int i;
400 int checksum;
401 qboolean isBot;
402 char systemInfo[16384];
403 const char *p;
404
405 // shut down the existing game if it is running
406 SV_ShutdownGameProgs();
407
408 Com_Printf ("------ Server Initialization ------\n");
409 Com_Printf ("Server: %s\n",server);
410
411 // if not running a dedicated server CL_MapLoading will connect the client to the server
412 // also print some status stuff
413 CL_MapLoading();
414
415 // make sure all the client stuff is unloaded
416 CL_ShutdownAll(qfalse);
417
418 // clear the whole hunk because we're (re)loading the server
419 Hunk_Clear();
420
421 // clear collision map data
422 CM_ClearMap();
423
424 // init client structures and svs.numSnapshotEntities
425 if ( !Cvar_VariableValue("sv_running") ) {
426 SV_Startup();
427 } else {
428 // check for maxclients change
429 if ( sv_maxclients->modified ) {
430 SV_ChangeMaxClients();
431 }
432 }
433
434 // clear pak references
435 FS_ClearPakReferences(0);
436
437 // allocate the snapshot entities on the hunk
438 svs.snapshotEntities = Hunk_Alloc( sizeof(entityState_t)*svs.numSnapshotEntities, h_high );
439 svs.nextSnapshotEntities = 0;
440
441 // toggle the server bit so clients can detect that a
442 // server has changed
443 svs.snapFlagServerBit ^= SNAPFLAG_SERVERCOUNT;
444
445 // set nextmap to the same map, but it may be overriden
446 // by the game startup or another console command
447 Cvar_Set( "nextmap", "map_restart 0");
448 // Cvar_Set( "nextmap", va("map %s", server) );
449
450 for (i=0 ; i<sv_maxclients->integer ; i++) {
451 // save when the server started for each client already connected
452 if (svs.clients[i].state >= CS_CONNECTED) {
453 svs.clients[i].oldServerTime = sv.time;
454 }
455 }
456
457 // wipe the entire per-level structure
458 SV_ClearServer();
459 for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) {
460 sv.configstrings[i] = CopyString("");
461 }
462
463 // make sure we are not paused
464 Cvar_Set("cl_paused", "0");
465
466 // get a new checksum feed and restart the file system
467 sv.checksumFeed = ( ((unsigned int)rand() << 16) ^ (unsigned int)rand() ) ^ Com_Milliseconds();
468 FS_Restart( sv.checksumFeed );
469
470 CM_LoadMap( va("maps/%s.bsp", server), qfalse, &checksum );
471
472 // set serverinfo visible name
473 Cvar_Set( "mapname", server );
474
475 Cvar_Set( "sv_mapChecksum", va("%i",checksum) );
476
477 // serverid should be different each time
478 sv.serverId = com_frameTime;
479 sv.restartedServerId = sv.serverId; // I suppose the init here is just to be safe
480 sv.checksumFeedServerId = sv.serverId;
481 Cvar_Set( "sv_serverid", va("%i", sv.serverId ) );
482
483 // clear physics interaction links
484 SV_ClearWorld ();
485
486 // media configstring setting should be done during
487 // the loading stage, so connected clients don't have
488 // to load during actual gameplay
489 sv.state = SS_LOADING;
490
491 // load and spawn all other entities
492 SV_InitGameProgs();
493
494 // don't allow a map_restart if game is modified
495 sv_gametype->modified = qfalse;
496
497 // run a few frames to allow everything to settle
498 for (i = 0;i < 3; i++)
499 {
500 VM_Call (gvm, GAME_RUN_FRAME, sv.time);
501 SV_BotFrame (sv.time);
502 sv.time += 100;
503 svs.time += 100;
504 }
505
506 // create a baseline for more efficient communications
507 SV_CreateBaseline ();
508
509 for (i=0 ; i<sv_maxclients->integer ; i++) {
510 // send the new gamestate to all connected clients
511 if (svs.clients[i].state >= CS_CONNECTED) {
512 char *denied;
513
514 if ( svs.clients[i].netchan.remoteAddress.type == NA_BOT ) {
515 if ( killBots ) {
516 SV_DropClient( &svs.clients[i], "" );
517 continue;
518 }
519 isBot = qtrue;
520 }
521 else {
522 isBot = qfalse;
523 }
524
525 // connect the client again
526 denied = VM_ExplicitArgPtr( gvm, VM_Call( gvm, GAME_CLIENT_CONNECT, i, qfalse, isBot ) ); // firstTime = qfalse
527 if ( denied ) {
528 // this generally shouldn't happen, because the client
529 // was connected before the level change
530 SV_DropClient( &svs.clients[i], denied );
531 } else {
532 if( !isBot ) {
533 // when we get the next packet from a connected client,
534 // the new gamestate will be sent
535 svs.clients[i].state = CS_CONNECTED;
536 }
537 else {
538 client_t *client;
539 sharedEntity_t *ent;
540
541 client = &svs.clients[i];
542 client->state = CS_ACTIVE;
543 ent = SV_GentityNum( i );
544 ent->s.number = i;
545 client->gentity = ent;
546
547 client->deltaMessage = -1;
548 client->lastSnapshotTime = 0; // generate a snapshot immediately
549
550 VM_Call( gvm, GAME_CLIENT_BEGIN, i );
551 }
552 }
553 }
554 }
555
556 // run another frame to allow things to look at all the players
557 VM_Call (gvm, GAME_RUN_FRAME, sv.time);
558 SV_BotFrame (sv.time);
559 sv.time += 100;
560 svs.time += 100;
561
562 if ( sv_pure->integer ) {
563 // the server sends these to the clients so they will only
564 // load pk3s also loaded at the server
565 p = FS_LoadedPakChecksums();
566 Cvar_Set( "sv_paks", p );
567 if (strlen(p) == 0) {
568 Com_Printf( "WARNING: sv_pure set but no PK3 files loaded\n" );
569 }
570 p = FS_LoadedPakNames();
571 Cvar_Set( "sv_pakNames", p );
572
573 // we need to touch the cgame and ui qvm because they could be in
574 // separate pk3 files and the client will need to download the pk3
575 // files with the latest cgame and ui qvm to pass the pure check
576 SV_TouchFile( "vm/cgame.qvm" );
577 SV_TouchFile( "vm/ui.qvm" );
578 }
579 else {
580 Cvar_Set( "sv_paks", "" );
581 Cvar_Set( "sv_pakNames", "" );
582 }
583 // the server sends these to the clients so they can figure
584 // out which pk3s should be auto-downloaded
585 p = FS_ReferencedPakChecksums();
586 Cvar_Set( "sv_referencedPaks", p );
587 p = FS_ReferencedPakNames();
588 Cvar_Set( "sv_referencedPakNames", p );
589
590 // save systeminfo and serverinfo strings
591 Q_strncpyz( systemInfo, Cvar_InfoString_Big( CVAR_SYSTEMINFO ), sizeof( systemInfo ) );
592 cvar_modifiedFlags &= ~CVAR_SYSTEMINFO;
593 SV_SetConfigstring( CS_SYSTEMINFO, systemInfo );
594
595 SV_SetConfigstring( CS_SERVERINFO, Cvar_InfoString( CVAR_SERVERINFO ) );
596 cvar_modifiedFlags &= ~CVAR_SERVERINFO;
597
598 // any media configstring setting now should issue a warning
599 // and any configstring changes should be reliably transmitted
600 // to all clients
601 sv.state = SS_GAME;
602
603 // send a heartbeat now so the master will get up to date info
604 SV_Heartbeat_f();
605
606 Hunk_SetMark();
607
608 #ifndef DEDICATED
609 if ( com_dedicated->integer ) {
610 // restart renderer in order to show console for dedicated servers
611 // launched through the regular binary
612 CL_StartHunkUsers( qtrue );
613 }
614 #endif
615
616 Com_Printf ("-----------------------------------\n");
617 }
618
619 /*
620 ===============
621 SV_Init
622
623 Only called at main exe startup, not for each game
624 ===============
625 */
626 void SV_Init (void)
627 {
628 int index;
629
630 SV_AddOperatorCommands ();
631
632 // serverinfo vars
633 Cvar_Get ("dmflags", "0", CVAR_SERVERINFO);
634 Cvar_Get ("fraglimit", "20", CVAR_SERVERINFO);
635 Cvar_Get ("timelimit", "0", CVAR_SERVERINFO);
636 sv_gametype = Cvar_Get ("g_gametype", "0", CVAR_SERVERINFO | CVAR_LATCH );
637 Cvar_Get ("sv_keywords", "", CVAR_SERVERINFO);
638 sv_mapname = Cvar_Get ("mapname", "nomap", CVAR_SERVERINFO | CVAR_ROM);
639 sv_privateClients = Cvar_Get ("sv_privateClients", "0", CVAR_SERVERINFO);
640 sv_hostname = Cvar_Get ("sv_hostname", "noname", CVAR_SERVERINFO | CVAR_ARCHIVE );
641 sv_maxclients = Cvar_Get ("sv_maxclients", "8", CVAR_SERVERINFO | CVAR_LATCH);
642
643 sv_minRate = Cvar_Get ("sv_minRate", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
644 sv_maxRate = Cvar_Get ("sv_maxRate", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
645 sv_dlRate = Cvar_Get("sv_dlRate", "100", CVAR_ARCHIVE | CVAR_SERVERINFO);
646 sv_minPing = Cvar_Get ("sv_minPing", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
647 sv_maxPing = Cvar_Get ("sv_maxPing", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
648 sv_floodProtect = Cvar_Get ("sv_floodProtect", "1", CVAR_ARCHIVE | CVAR_SERVERINFO );
649
650 // systeminfo
651 Cvar_Get ("sv_cheats", "1", CVAR_SYSTEMINFO | CVAR_ROM );
652 sv_serverid = Cvar_Get ("sv_serverid", "0", CVAR_SYSTEMINFO | CVAR_ROM );
653 sv_pure = Cvar_Get ("sv_pure", "1", CVAR_SYSTEMINFO );
654 #ifdef USE_VOIP
655 sv_voip = Cvar_Get("sv_voip", "1", CVAR_LATCH);
656 Cvar_CheckRange(sv_voip, 0, 1, qtrue);
657 sv_voipProtocol = Cvar_Get("sv_voipProtocol", sv_voip->integer ? "opus" : "", CVAR_SYSTEMINFO | CVAR_ROM );
658 #endif
659 Cvar_Get ("sv_paks", "", CVAR_SYSTEMINFO | CVAR_ROM );
660 Cvar_Get ("sv_pakNames", "", CVAR_SYSTEMINFO | CVAR_ROM );
661 Cvar_Get ("sv_referencedPaks", "", CVAR_SYSTEMINFO | CVAR_ROM );
662 Cvar_Get ("sv_referencedPakNames", "", CVAR_SYSTEMINFO | CVAR_ROM );
663
664 // server vars
665 sv_rconPassword = Cvar_Get ("rconPassword", "", CVAR_TEMP );
666 sv_privatePassword = Cvar_Get ("sv_privatePassword", "", CVAR_TEMP );
667 sv_fps = Cvar_Get ("sv_fps", "20", CVAR_TEMP );
668 sv_timeout = Cvar_Get ("sv_timeout", "200", CVAR_TEMP );
669 sv_zombietime = Cvar_Get ("sv_zombietime", "2", CVAR_TEMP );
670 Cvar_Get ("nextmap", "", CVAR_TEMP );
671
672 sv_allowDownload = Cvar_Get ("sv_allowDownload", "0", CVAR_SERVERINFO);
673 Cvar_Get ("sv_dlURL", "", CVAR_SERVERINFO | CVAR_ARCHIVE);
674
675 sv_master[0] = Cvar_Get("sv_master1", MASTER_SERVER_NAME, 0);
676 sv_master[1] = Cvar_Get("sv_master2", "directory.ioquake3.org", 0);
677 for(index = 2; index < MAX_MASTER_SERVERS; index++)
678 sv_master[index] = Cvar_Get(va("sv_master%d", index + 1), "", CVAR_ARCHIVE);
679
680 sv_reconnectlimit = Cvar_Get ("sv_reconnectlimit", "3", 0);
681 sv_showloss = Cvar_Get ("sv_showloss", "0", 0);
682 sv_padPackets = Cvar_Get ("sv_padPackets", "0", 0);
683 sv_killserver = Cvar_Get ("sv_killserver", "0", 0);
684 sv_mapChecksum = Cvar_Get ("sv_mapChecksum", "", CVAR_ROM);
685 sv_lanForceRate = Cvar_Get ("sv_lanForceRate", "1", CVAR_ARCHIVE );
686 #ifndef STANDALONE
687 sv_strictAuth = Cvar_Get ("sv_strictAuth", "1", CVAR_ARCHIVE );
688 #endif
689 sv_banFile = Cvar_Get("sv_banFile", "serverbans.dat", CVAR_ARCHIVE);
690
691 // initialize bot cvars so they are listed and can be set before loading the botlib
692 SV_BotInitCvars();
693
694 // init the botlib here because we need the pre-compiler in the UI
695 SV_BotInitBotLib();
696
697 // Load saved bans
698 Cbuf_AddText("rehashbans\n");
699 }
700
701
702 /*
703 ==================
704 SV_FinalMessage
705
706 Used by SV_Shutdown to send a final message to all
707 connected clients before the server goes down. The messages are sent immediately,
708 not just stuck on the outgoing message list, because the server is going
709 to totally exit after returning from this function.
710 ==================
711 */
712 void SV_FinalMessage( char *message ) {
713 int i, j;
714 client_t *cl;
715
716 // send it twice, ignoring rate
717 for ( j = 0 ; j < 2 ; j++ ) {
718 for (i=0, cl = svs.clients ; i < sv_maxclients->integer ; i++, cl++) {
719 if (cl->state >= CS_CONNECTED) {
720 // don't send a disconnect to a local client
721 if ( cl->netchan.remoteAddress.type != NA_LOOPBACK ) {
722 SV_SendServerCommand( cl, "print \"%s\n\"\n", message );
723 SV_SendServerCommand( cl, "disconnect \"%s\"", message );
724 }
725 // force a snapshot to be sent
726 cl->lastSnapshotTime = 0;
727 SV_SendClientSnapshot( cl );
728 }
729 }
730 }
731 }
732
733
734 /*
735 ================
736 SV_Shutdown
737
738 Called when each game quits,
739 before Sys_Quit or Sys_Error
740 ================
741 */
742 void SV_Shutdown( char *finalmsg ) {
743 if ( !com_sv_running || !com_sv_running->integer ) {
744 return;
745 }
746
747 Com_Printf( "----- Server Shutdown (%s) -----\n", finalmsg );
748
749 NET_LeaveMulticast6();
750
751 if ( svs.clients && !com_errorEntered ) {
752 SV_FinalMessage( finalmsg );
753 }
754
755 SV_RemoveOperatorCommands();
756 SV_MasterShutdown();
757 SV_ShutdownGameProgs();
758
759 // free current level
760 SV_ClearServer();
761
762 // free server static data
763 if(svs.clients)
764 {
765 int index;
766
767 for(index = 0; index < sv_maxclients->integer; index++)
768 SV_FreeClient(&svs.clients[index]);
769
770 Z_Free(svs.clients);
771 }
772 Com_Memset( &svs, 0, sizeof( svs ) );
773
774 Cvar_Set( "sv_running", "0" );
775 Cvar_Set("ui_singlePlayerActive", "0");
776
777 Com_Printf( "---------------------------\n" );
778
779 // disconnect any local clients
780 if( sv_killserver->integer != 2 )
781 CL_Disconnect( qfalse );
782 }
783