sv_init.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. // leave this as first line for PCH reasons...
  2. //
  3. #include "../server/exe_headers.h"
  4. #include "../client/snd_music.h" // didn't want to put this in snd_local because of rebuild times etc.
  5. #include "server.h"
  6. #include "../win32/xbox_texture_man.h"
  7. #include <xgraphics.h>
  8. /*
  9. Ghoul2 Insert Start
  10. */
  11. #if !defined(TR_LOCAL_H)
  12. #include "../renderer/tr_local.h"
  13. #endif
  14. #if !defined (MINIHEAP_H_INC)
  15. #include "../qcommon/miniheap.h"
  16. #endif
  17. void CM_CleanLeafCache(void);
  18. extern void SV_FreeClient(client_t*);
  19. CMiniHeap *G2VertSpaceServer = NULL;
  20. /*
  21. Ghoul2 Insert End
  22. */
  23. /*
  24. ===============
  25. SV_SetConfigstring
  26. ===============
  27. */
  28. void SV_SetConfigstring (int index, const char *val) {
  29. if ( index < 0 || index >= MAX_CONFIGSTRINGS ) {
  30. Com_Error (ERR_DROP, "SV_SetConfigstring: bad index %i\n", index);
  31. }
  32. if ( !val ) {
  33. val = "";
  34. }
  35. // don't bother broadcasting an update if no change
  36. if ( !strcmp( val, sv.configstrings[ index ] ) ) {
  37. return;
  38. }
  39. // change the string in sv
  40. Z_Free( sv.configstrings[index] );
  41. sv.configstrings[index] = CopyString( val );
  42. // send it to all the clients if we aren't
  43. // spawning a new server
  44. if ( sv.state == SS_GAME ) {
  45. SV_SendServerCommand( NULL, "cs %i \"%s\"\n", index, val );
  46. }
  47. }
  48. /*
  49. ===============
  50. SV_GetConfigstring
  51. ===============
  52. */
  53. void SV_GetConfigstring( int index, char *buffer, int bufferSize ) {
  54. if ( bufferSize < 1 ) {
  55. Com_Error( ERR_DROP, "SV_GetConfigstring: bufferSize == %i", bufferSize );
  56. }
  57. if ( index < 0 || index >= MAX_CONFIGSTRINGS ) {
  58. Com_Error (ERR_DROP, "SV_GetConfigstring: bad index %i\n", index);
  59. }
  60. if ( !sv.configstrings[index] ) {
  61. buffer[0] = 0;
  62. return;
  63. }
  64. Q_strncpyz( buffer, sv.configstrings[index], bufferSize );
  65. }
  66. /*
  67. ===============
  68. SV_SetUserinfo
  69. ===============
  70. */
  71. void SV_SetUserinfo( int index, const char *val ) {
  72. if ( index < 0 || index >= 1 ) {
  73. Com_Error (ERR_DROP, "SV_SetUserinfo: bad index %i\n", index);
  74. }
  75. if ( !val ) {
  76. val = "";
  77. }
  78. Q_strncpyz( svs.clients[ index ].userinfo, val, sizeof( svs.clients[ index ].userinfo ) );
  79. }
  80. /*
  81. ===============
  82. SV_GetUserinfo
  83. ===============
  84. */
  85. void SV_GetUserinfo( int index, char *buffer, int bufferSize ) {
  86. if ( bufferSize < 1 ) {
  87. Com_Error( ERR_DROP, "SV_GetUserinfo: bufferSize == %i", bufferSize );
  88. }
  89. if ( index < 0 || index >= 1 ) {
  90. Com_Error (ERR_DROP, "SV_GetUserinfo: bad index %i\n", index);
  91. }
  92. Q_strncpyz( buffer, svs.clients[ index ].userinfo, bufferSize );
  93. }
  94. /*
  95. ================
  96. SV_CreateBaseline
  97. Entity baselines are used to compress non-delta messages
  98. to the clients -- only the fields that differ from the
  99. baseline will be transmitted
  100. ================
  101. */
  102. void SV_CreateBaseline( void ) {
  103. gentity_t *svent;
  104. int entnum;
  105. for ( entnum = 0; entnum < ge->num_entities ; entnum++ ) {
  106. svent = SV_GentityNum(entnum);
  107. if (!svent->inuse) {
  108. continue;
  109. }
  110. if (!svent->linked) {
  111. continue;
  112. }
  113. svent->s.number = entnum;
  114. //
  115. // take current state as baseline
  116. //
  117. sv.svEntities[entnum].baseline = svent->s;
  118. }
  119. }
  120. /*
  121. ===============
  122. SV_Startup
  123. Called when a game is about to begin
  124. ===============
  125. */
  126. void SV_Startup( void ) {
  127. if ( svs.initialized ) {
  128. Com_Error( ERR_FATAL, "SV_Startup: svs.initialized" );
  129. }
  130. svs.clients = (struct client_s *) Z_Malloc ( sizeof(client_t) * 1, TAG_CLIENTS, qtrue );
  131. svs.numSnapshotEntities = 2 * 4 * 64;
  132. svs.initialized = qtrue;
  133. Cvar_Set( "sv_running", "1" );
  134. }
  135. #ifdef _XBOX
  136. //Xbox-only memory freeing.
  137. extern void R_ModelFree(void);
  138. extern void Sys_IORequestQueueClear(void);
  139. extern void Music_Free(void);
  140. extern void AS_FreePartial(void);
  141. extern void G_ASPreCacheFree(void);
  142. extern void Ghoul2InfoArray_Free(void);
  143. extern void Ghoul2InfoArray_Reset(void);
  144. extern void Menu_Reset(void);
  145. extern void G2_FreeRag(void);
  146. extern void ClearAllNavStructures(void);
  147. extern void ClearModelsAlreadyDone(void);
  148. extern void CL_FreeServerCommands(void);
  149. extern void CL_FreeReliableCommands(void);
  150. extern void CM_Free(void);
  151. extern void ShaderEntryPtrs_Clear(void);
  152. extern void G_FreeRoffs(void);
  153. extern void BG_ClearVehicles(void);
  154. extern void ClearHStringPool(void);
  155. extern void ClearTheBonePool(void);
  156. extern char cinematicSkipScript[64];
  157. extern HANDLE s_BCThread;
  158. extern void IN_HotSwap1Off(void);
  159. extern void IN_HotSwap2Off(void);
  160. extern void IN_HotSwap3Off(void);
  161. extern int cg_saberOnSoundTime[MAX_GENTITIES];
  162. extern char current_speeders;
  163. extern int zfFaceShaders[3];
  164. extern int tfTorsoShader;
  165. extern bool dontPillarPush;
  166. void SV_ClearLastLevel(void)
  167. {
  168. Menu_Reset();
  169. Z_TagFree(TAG_G_ALLOC);
  170. Z_TagFree(TAG_UI_ALLOC);
  171. G_FreeRoffs();
  172. R_ModelFree();
  173. Music_Free();
  174. Sys_IORequestQueueClear();
  175. AS_FreePartial();
  176. G_ASPreCacheFree();
  177. Ghoul2InfoArray_Free();
  178. G2_FreeRag();
  179. ClearAllNavStructures();
  180. ClearModelsAlreadyDone();
  181. CL_FreeServerCommands();
  182. CL_FreeReliableCommands();
  183. CM_Free();
  184. ShaderEntryPtrs_Clear();
  185. ClearTheBonePool();
  186. BG_ClearVehicles();
  187. cinematicSkipScript[0] = 0;
  188. if (svs.clients)
  189. {
  190. SV_FreeClient( svs.clients );
  191. }
  192. ClearHStringPool();
  193. // The bink copier thread is so trivial as to not have any communication
  194. // Rather than polling constantly to clean it up, we just check here.
  195. // This code should only happen ONCE:
  196. if (s_BCThread != INVALID_HANDLE_VALUE)
  197. {
  198. DWORD status;
  199. if (GetExitCodeThread( s_BCThread, &status ) && (status != STILL_ACTIVE))
  200. {
  201. // Thread is done. Clean up after ourselves:
  202. CloseHandle( s_BCThread );
  203. s_BCThread = INVALID_HANDLE_VALUE;
  204. }
  205. }
  206. IN_HotSwap1Off();
  207. IN_HotSwap2Off();
  208. IN_HotSwap3Off();
  209. memset(&cg_saberOnSoundTime, 0, MAX_GENTITIES);
  210. memset(zfFaceShaders, -1, sizeof(zfFaceShaders));
  211. tfTorsoShader = -1;
  212. current_speeders = 0;
  213. dontPillarPush = false;
  214. }
  215. #endif
  216. qboolean CM_SameMap(char *server);
  217. qboolean CM_HasTerrain(void);
  218. void Cvar_Defrag(void);
  219. // Load-time animation hackery:
  220. struct OVERLAYINFO
  221. {
  222. D3DTexture *texture;
  223. D3DSurface *surface;
  224. };
  225. OVERLAYINFO Image;
  226. static int loadingX = 290;
  227. void InitLoadingAnimation( void )
  228. {
  229. /*
  230. // Make our two textures:
  231. Image.texture = new IDirect3DTexture9;
  232. // Fill in the texture headers:
  233. DWORD pixelSize =
  234. XGSetTextureHeader( 4,
  235. 4,
  236. 1,
  237. 0,
  238. D3DFMT_YUY2,
  239. 0,
  240. Image.texture,
  241. 0,
  242. 0 );
  243. // Get pixel data, texNum is unused:
  244. byte *pixels = (byte *)gTextures.Allocate( pixelSize, 0 );
  245. // texNum is unused:
  246. Image.texture->Register( pixels );
  247. // Turn on overlays:
  248. glw_state->device->EnableOverlay( TRUE );
  249. // Get surface pointers:
  250. Image.texture->GetSurfaceLevel( 0, &Image.surface );
  251. D3DLOCKED_RECT lock;
  252. Image.surface->LockRect( &lock, NULL, D3DLOCK_TILED );
  253. // Grey?
  254. memset( lock.pBits, 0x7f7f7f7f, lock.Pitch * 4 );
  255. Image.surface->UnlockRect();
  256. // Just to be safe:
  257. // loadingIndex = 0;
  258. */
  259. }
  260. void UpdateLoadingAnimation( void )
  261. {
  262. /*
  263. // Draw the image tiny, in the bottom of the screen:
  264. RECT dst_rect = { loadingX, 390, loadingX + 8, 398 };
  265. RECT src_rect = { 0, 0, 4, 4 };
  266. // Update this bugger.
  267. glw_state->device->UpdateOverlay( Image.surface, &src_rect, &dst_rect, FALSE, 0 );
  268. loadingX += 4;
  269. if (loadingX > 342 )
  270. loadingX = 290;
  271. */
  272. }
  273. void StopLoadingAnimation( void )
  274. {
  275. /*
  276. // Release surfaces:
  277. Image.surface->Release();
  278. Image.surface = NULL;
  279. // Clean up the textures we made for the overlay stuff:
  280. Image.texture->BlockUntilNotBusy();
  281. delete Image.texture;
  282. Image.texture = NULL;
  283. // Turn overlays back off:
  284. glw_state->device->EnableOverlay( FALSE );
  285. */
  286. }
  287. /*
  288. ================
  289. SV_SpawnServer
  290. Change the server to a new map, taking all connected
  291. clients along with it.
  292. ================
  293. */
  294. void SV_SpawnServer( char *iServer, ForceReload_e eForceReload, qboolean bAllowScreenDissolve )
  295. {
  296. int i;
  297. int checksum;
  298. char server[64];
  299. Q_strncpyz( server, iServer, sizeof(server), qtrue );
  300. #ifdef XBOX_DEMO
  301. // Pause the timer if "someone is playing"
  302. extern void Demo_TimerPause( bool bPaused );
  303. Demo_TimerPause( true );
  304. #endif
  305. // The following fixes for potential issues only work on Xbox
  306. #ifdef _XBOX
  307. extern qboolean stop_icarus;
  308. stop_icarus = qfalse;
  309. //Broken scripts may leave the player locked. I think that's always bad.
  310. extern qboolean player_locked;
  311. player_locked = qfalse;
  312. //If you quit while in Matrix Mode, this never gets cleared!
  313. extern qboolean MatrixMode;
  314. MatrixMode = qfalse;
  315. // Failsafe to ensure that we don't have rumbling during level load
  316. extern void IN_KillRumbleScripts( void );
  317. IN_KillRumbleScripts();
  318. #endif
  319. RE_RegisterMedia_LevelLoadBegin( server, eForceReload, bAllowScreenDissolve );
  320. Cvar_SetValue( "cl_paused", 0 );
  321. Cvar_Set( "timescale", "1" );//jic we were skipping
  322. // shut down the existing game if it is running
  323. SV_ShutdownGameProgs(qtrue);
  324. Com_Printf ("------ Server Initialization ------\n%s\n", com_version->string);
  325. Com_Printf ("Server: %s\n",server);
  326. Cvar_Set( "ui_mapname", server );
  327. #ifndef FINAL_BUILD
  328. // extern unsigned long texturePointMax;
  329. // Com_Printf ("Texture pool highwater mark: %u\n", texturePointMax);
  330. #endif
  331. #ifdef _XBOX
  332. // disable vsync during load for speed
  333. qglDisable(GL_VSYNC);
  334. #endif
  335. // Hope this is correct - InitGame gets called later, which does this,
  336. // but UI_DrawConnect (in CL_MapLoading) needs it now, to properly
  337. // mimic CG_DrawInformation:
  338. extern SavedGameJustLoaded_e g_eSavedGameJustLoaded;
  339. g_eSavedGameJustLoaded = eSavedGameJustLoaded;
  340. // don't let sound stutter and dump all stuff on the hunk
  341. CL_MapLoading();
  342. if (!CM_SameMap(server))
  343. { //rww - only clear if not loading the same map
  344. CM_ClearMap();
  345. }
  346. #ifndef _XBOX
  347. else if (CM_HasTerrain())
  348. { //always clear when going between maps with terrain
  349. CM_ClearMap();
  350. }
  351. #endif
  352. // Miniheap never changes sizes, so I just put it really early in mem.
  353. G2VertSpaceServer->ResetHeap();
  354. #ifdef _XBOX
  355. // Deletes all textures
  356. R_DeleteTextures();
  357. #endif
  358. Hunk_Clear();
  359. // Moved up from below to help reduce fragmentation
  360. if (svs.snapshotEntities)
  361. {
  362. Z_Free(svs.snapshotEntities);
  363. svs.snapshotEntities = NULL;
  364. }
  365. // wipe the entire per-level structure
  366. // Also moved up, trying to do all freeing before new allocs
  367. for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) {
  368. if ( sv.configstrings[i] ) {
  369. Z_Free( sv.configstrings[i] );
  370. sv.configstrings[i] = NULL;
  371. }
  372. }
  373. #ifdef _XBOX
  374. SV_ClearLastLevel();
  375. #endif
  376. // Collect all the small allocations done by the cvar system
  377. // This frees, then allocates. Make it the last thing before other
  378. // allocations begin!
  379. Cvar_Defrag();
  380. /*
  381. This is useful for debugging memory fragmentation. Please don't
  382. remove it.
  383. */
  384. #ifdef _XBOX
  385. // We've over-freed the info array above, this puts it back into a working state
  386. Ghoul2InfoArray_Reset();
  387. extern void Z_DumpMemMap_f(void);
  388. extern void Z_Details_f(void);
  389. extern void Z_TagPointers(memtag_t);
  390. Z_DumpMemMap_f();
  391. // Z_TagPointers(TAG_ALL);
  392. Z_Details_f();
  393. #endif
  394. InitLoadingAnimation();
  395. UpdateLoadingAnimation();
  396. // init client structures and svs.numSnapshotEntities
  397. // This is moved down quite a bit, but should be safe. And keeps
  398. // svs.clients right at the beginning of memory
  399. if ( !Cvar_VariableIntegerValue("sv_running") ) {
  400. SV_Startup();
  401. }
  402. // clear out those shaders, images and Models
  403. // R_InitImages();
  404. // R_InitShaders();
  405. // R_ModelInit();
  406. // allocate the snapshot entities
  407. svs.snapshotEntities = (entityState_t *) Z_Malloc (sizeof(entityState_t)*svs.numSnapshotEntities, TAG_CLIENTS, qtrue );
  408. Music_SetLevelName(server);
  409. // toggle the server bit so clients can detect that a
  410. // server has changed
  411. //!@ svs.snapFlagServerBit ^= SNAPFLAG_SERVERCOUNT;
  412. // set nextmap to the same map, but it may be overriden
  413. // by the game startup or another console command
  414. Cvar_Set( "nextmap", va("map %s", server) );
  415. memset (&sv, 0, sizeof(sv));
  416. for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) {
  417. sv.configstrings[i] = CopyString("");
  418. }
  419. sv.time = 1000;
  420. G2API_SetTime(sv.time,G2T_SV_TIME);
  421. #ifdef _XBOX
  422. UpdateLoadingAnimation();
  423. CL_StartHunkUsers();
  424. UpdateLoadingAnimation();
  425. CM_LoadMap( va("maps/%s.bsp", server), qfalse, &checksum );
  426. UpdateLoadingAnimation();
  427. RE_LoadWorldMap(va("maps/%s.bsp", server));
  428. UpdateLoadingAnimation();
  429. #else
  430. CM_LoadMap( va("maps/%s.bsp", server), qfalse, &checksum, qfalse );
  431. #endif
  432. // set serverinfo visible name
  433. Cvar_Set( "mapname", server );
  434. Cvar_Set( "sv_mapChecksum", va("%i",checksum) );
  435. // serverid should be different each time
  436. sv.serverId = com_frameTime;
  437. Cvar_Set( "sv_serverid", va("%i", sv.serverId ) );
  438. // clear physics interaction links
  439. SV_ClearWorld ();
  440. // media configstring setting should be done during
  441. // the loading stage, so connected clients don't have
  442. // to load during actual gameplay
  443. sv.state = SS_LOADING;
  444. // load and spawn all other entities
  445. SV_InitGameProgs();
  446. // run a few frames to allow everything to settle
  447. for ( i = 0 ;i < 3 ; i++ ) {
  448. ge->RunFrame( sv.time );
  449. sv.time += 100;
  450. G2API_SetTime(sv.time,G2T_SV_TIME);
  451. }
  452. ge->ConnectNavs(sv_mapname->string, sv_mapChecksum->integer);
  453. // create a baseline for more efficient communications
  454. SV_CreateBaseline ();
  455. for (i=0 ; i<1 ; i++) {
  456. // clear all time counters, because we have reset sv.time
  457. svs.clients[i].lastPacketTime = 0;
  458. svs.clients[i].lastConnectTime = 0;
  459. svs.clients[i].nextSnapshotTime = 0;
  460. // send the new gamestate to all connected clients
  461. if (svs.clients[i].state >= CS_CONNECTED) {
  462. char *denied;
  463. // connect the client again
  464. denied = ge->ClientConnect( i, qfalse, eNO/*qfalse*/ ); // firstTime = qfalse, qbFromSavedGame
  465. if ( denied ) {
  466. // this generally shouldn't happen, because the client
  467. // was connected before the level change
  468. SV_DropClient( &svs.clients[i], denied );
  469. } else {
  470. svs.clients[i].state = CS_CONNECTED;
  471. // when we get the next packet from a connected client,
  472. // the new gamestate will be sent
  473. }
  474. }
  475. }
  476. // run another frame to allow things to look at all connected clients
  477. ge->RunFrame( sv.time );
  478. sv.time += 100;
  479. G2API_SetTime(sv.time,G2T_SV_TIME);
  480. // save systeminfo and serverinfo strings
  481. SV_SetConfigstring( CS_SYSTEMINFO, Cvar_InfoString( CVAR_SYSTEMINFO ) );
  482. cvar_modifiedFlags &= ~CVAR_SYSTEMINFO;
  483. SV_SetConfigstring( CS_SERVERINFO, Cvar_InfoString( CVAR_SERVERINFO ) );
  484. cvar_modifiedFlags &= ~CVAR_SERVERINFO;
  485. // any media configstring setting now should issue a warning
  486. // and any configstring changes should be reliably transmitted
  487. // to all clients
  488. sv.state = SS_GAME;
  489. // send a heartbeat now so the master will get up to date info
  490. svs.nextHeartbeatTime = -9999999;
  491. Hunk_SetMark();
  492. #ifndef _XBOX
  493. Z_Validate();
  494. Z_Validate();
  495. Z_Validate();
  496. #endif
  497. StopLoadingAnimation();
  498. Com_Printf ("-----------------------------------\n");
  499. }
  500. /*
  501. ===============
  502. SV_Init
  503. Only called at main exe startup, not for each game
  504. ===============
  505. */
  506. void SV_Init (void) {
  507. SV_AddOperatorCommands ();
  508. // serverinfo vars
  509. Cvar_Get ("protocol", va("%i", PROTOCOL_VERSION), CVAR_SERVERINFO | CVAR_ROM);
  510. sv_mapname = Cvar_Get ("mapname", "nomap", CVAR_SERVERINFO | CVAR_ROM);
  511. // systeminfo
  512. Cvar_Get ("helpUsObi", "0", CVAR_SYSTEMINFO );
  513. sv_serverid = Cvar_Get ("sv_serverid", "0", CVAR_SYSTEMINFO | CVAR_ROM );
  514. // server vars
  515. sv_fps = Cvar_Get ("sv_fps", "20", CVAR_TEMP );
  516. sv_timeout = Cvar_Get ("sv_timeout", "120", CVAR_TEMP );
  517. sv_zombietime = Cvar_Get ("sv_zombietime", "2", CVAR_TEMP );
  518. Cvar_Get ("nextmap", "", CVAR_TEMP );
  519. sv_spawntarget = Cvar_Get ("spawntarget", "", 0 );
  520. sv_reconnectlimit = Cvar_Get ("sv_reconnectlimit", "3", 0);
  521. sv_showloss = Cvar_Get ("sv_showloss", "0", 0);
  522. sv_killserver = Cvar_Get ("sv_killserver", "0", 0);
  523. sv_mapChecksum = Cvar_Get ("sv_mapChecksum", "", CVAR_ROM);
  524. sv_testsave = Cvar_Get ("sv_testsave", "0", 0);
  525. sv_compress_saved_games = Cvar_Get ("sv_compress_saved_games", "1", 0);
  526. // Only allocated once, no point in moving it around and fragmenting
  527. // create a heap for Ghoul2 to use for game side model vertex transforms used in collision detection
  528. {
  529. static CMiniHeap singleton(132096);
  530. G2VertSpaceServer = &singleton;
  531. }
  532. }
  533. /*
  534. ==================
  535. SV_FinalMessage
  536. Used by SV_Shutdown to send a final message to all
  537. connected clients before the server goes down. The messages are sent immediately,
  538. not just stuck on the outgoing message list, because the server is going
  539. to totally exit after returning from this function.
  540. ==================
  541. */
  542. void SV_FinalMessage( char *message ) {
  543. int i, j;
  544. client_t *cl;
  545. SV_SendServerCommand( NULL, "print \"%s\"", message );
  546. SV_SendServerCommand( NULL, "disconnect" );
  547. // send it twice, ignoring rate
  548. for ( j = 0 ; j < 2 ; j++ ) {
  549. for (i=0, cl = svs.clients ; i < 1 ; i++, cl++) {
  550. if (cl->state >= CS_CONNECTED) {
  551. // force a snapshot to be sent
  552. cl->nextSnapshotTime = -1;
  553. SV_SendClientSnapshot( cl );
  554. }
  555. }
  556. }
  557. }
  558. /*
  559. ================
  560. SV_Shutdown
  561. Called when each game quits,
  562. before Sys_Quit or Sys_Error
  563. ================
  564. */
  565. void SV_Shutdown( char *finalmsg ) {
  566. int i;
  567. if ( !com_sv_running || !com_sv_running->integer ) {
  568. return;
  569. }
  570. //Com_Printf( "----- Server Shutdown -----\n" );
  571. if ( svs.clients && !com_errorEntered ) {
  572. SV_FinalMessage( finalmsg );
  573. }
  574. SV_RemoveOperatorCommands();
  575. SV_ShutdownGameProgs(qfalse);
  576. if (svs.snapshotEntities)
  577. {
  578. Z_Free(svs.snapshotEntities);
  579. svs.snapshotEntities = NULL;
  580. }
  581. for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) {
  582. if ( sv.configstrings[i] ) {
  583. Z_Free( sv.configstrings[i] );
  584. }
  585. }
  586. // free current level
  587. memset( &sv, 0, sizeof( sv ) );
  588. // free server static data
  589. if ( svs.clients ) {
  590. SV_FreeClient(svs.clients);
  591. Z_Free( svs.clients );
  592. }
  593. memset( &svs, 0, sizeof( svs ) );
  594. // Ensure we free any memory used by the leaf cache.
  595. CM_CleanLeafCache();
  596. Cvar_Set( "sv_running", "0" );
  597. //Com_Printf( "---------------------------\n" );
  598. }