Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

sv_init.c File Reference

#include "server.h"

Include dependency graph for sv_init.c:

Include dependency graph

Go to the source code of this file.

Functions

void SV_BotInitBotLib (void)
void SV_BoundMaxClients (int minimum)
void SV_ChangeMaxClients (void)
void SV_ClearServer (void)
void SV_CreateBaseline (void)
void SV_FinalMessage (char *message)
void SV_GetConfigstring (int index, char *buffer, int bufferSize)
void SV_GetUserinfo (int index, char *buffer, int bufferSize)
void SV_Init (void)
void SV_SetConfigstring (int index, const char *val)
void SV_SetUserinfo (int index, const char *val)
void SV_Shutdown (char *finalmsg)
void SV_SpawnServer (char *server, qboolean killBots)
void SV_Startup (void)
void SV_TouchCGame (void)


Function Documentation

void SV_BotInitBotLib void   ) 
 

Definition at line 518 of file sv_bot.c.

References assert, botlib_import_s::AvailableMemory, bot_debugpoly_t, bot_maxdebugpolys, botlib_import_s::BotClientCommand, BOTLIB_API_VERSION, botlib_export, botlib_export_t, botlib_import_t, botlib_import_s::BSPEntityData, botlib_import_s::BSPModelMinsMaxsOrigin, Com_Error(), Cvar_VariableIntegerValue(), Cvar_VariableValue(), botlib_import_s::DebugLineCreate, botlib_import_s::DebugLineDelete, botlib_import_s::DebugLineShow, botlib_import_s::DebugPolygonCreate, botlib_import_s::DebugPolygonDelete, debugpolygons, botlib_import_s::EntityTrace, ERR_NEED_CD, botlib_import_s::FreeMemory, botlib_import_s::FS_FCloseFile, botlib_import_s::FS_FOpenFile, botlib_import_s::FS_Read, botlib_import_s::FS_Seek, botlib_import_s::FS_Write, GetBotLibAPI(), botlib_import_s::GetMemory, botlib_import_s::HunkAlloc, botlib_import_s::inPVS, botlib_import_s::PointContents, Sys_CheckCD(), botlib_import_s::Trace, Z_Free(), and Z_Malloc().

Referenced by SV_Init().

00518                             {
00519     botlib_import_t botlib_import;
00520 
00521     if ( !Cvar_VariableValue("fs_restrict") && !Sys_CheckCD() ) {
00522         Com_Error( ERR_NEED_CD, "Game CD not in drive" );
00523     }
00524 
00525     if (debugpolygons) Z_Free(debugpolygons);
00526     bot_maxdebugpolys = Cvar_VariableIntegerValue("bot_maxdebugpolys");
00527     debugpolygons = Z_Malloc(sizeof(bot_debugpoly_t) * bot_maxdebugpolys);
00528 
00529     botlib_import.Print = BotImport_Print;
00530     botlib_import.Trace = BotImport_Trace;
00531     botlib_import.EntityTrace = BotImport_EntityTrace;
00532     botlib_import.PointContents = BotImport_PointContents;
00533     botlib_import.inPVS = BotImport_inPVS;
00534     botlib_import.BSPEntityData = BotImport_BSPEntityData;
00535     botlib_import.BSPModelMinsMaxsOrigin = BotImport_BSPModelMinsMaxsOrigin;
00536     botlib_import.BotClientCommand = BotClientCommand;
00537 
00538     //memory management
00539     botlib_import.GetMemory = BotImport_GetMemory;
00540     botlib_import.FreeMemory = BotImport_FreeMemory;
00541     botlib_import.AvailableMemory = Z_AvailableMemory;
00542     botlib_import.HunkAlloc = BotImport_HunkAlloc;
00543 
00544     // file system access
00545     botlib_import.FS_FOpenFile = FS_FOpenFileByMode;
00546     botlib_import.FS_Read = FS_Read2;
00547     botlib_import.FS_Write = FS_Write;
00548     botlib_import.FS_FCloseFile = FS_FCloseFile;
00549     botlib_import.FS_Seek = FS_Seek;
00550 
00551     //debug lines
00552     botlib_import.DebugLineCreate = BotImport_DebugLineCreate;
00553     botlib_import.DebugLineDelete = BotImport_DebugLineDelete;
00554     botlib_import.DebugLineShow = BotImport_DebugLineShow;
00555 
00556     //debug polygons
00557     botlib_import.DebugPolygonCreate = BotImport_DebugPolygonCreate;
00558     botlib_import.DebugPolygonDelete = BotImport_DebugPolygonDelete;
00559 
00560     botlib_export = (botlib_export_t *)GetBotLibAPI( BOTLIB_API_VERSION, &botlib_import );
00561     assert(botlib_export);  // bk001129 - somehow we end up with a zero import.
00562 }

Here is the call graph for this function:

void SV_BoundMaxClients int  minimum  ) 
 

Definition at line 195 of file sv_init.c.

References Cvar_Get(), Cvar_Set(), cvar_s::integer, MAX_CLIENTS, cvar_s::modified, sv_maxclients, and va().

Referenced by SV_ChangeMaxClients(), and SV_Startup().

00195                                        {
00196     // get the current maxclients value
00197     Cvar_Get( "sv_maxclients", "8", 0 );
00198 
00199     sv_maxclients->modified = qfalse;
00200 
00201     if ( sv_maxclients->integer < minimum ) {
00202         Cvar_Set( "sv_maxclients", va("%i", minimum) );
00203     } else if ( sv_maxclients->integer > MAX_CLIENTS ) {
00204         Cvar_Set( "sv_maxclients", va("%i", MAX_CLIENTS) );
00205     }
00206 }

Here is the call graph for this function:

void SV_ChangeMaxClients void   ) 
 

Definition at line 243 of file sv_init.c.

References client_t, serverStatic_t::clients, com_dedicated, Com_Memset(), count, Hunk_AllocateTempMemory(), Hunk_FreeTempMemory(), i, cvar_s::integer, serverStatic_t::numSnapshotEntities, PACKET_BACKUP, client_s::state, SV_BoundMaxClients(), sv_maxclients, svs, Z_Free(), and Z_Malloc().

Referenced by SV_SpawnServer().

00243                                  {
00244     int     oldMaxClients;
00245     int     i;
00246     client_t    *oldClients;
00247     int     count;
00248 
00249     // get the highest client number in use
00250     count = 0;
00251     for ( i = 0 ; i < sv_maxclients->integer ; i++ ) {
00252         if ( svs.clients[i].state >= CS_CONNECTED ) {
00253             if (i > count)
00254                 count = i;
00255         }
00256     }
00257     count++;
00258 
00259     oldMaxClients = sv_maxclients->integer;
00260     // never go below the highest client number in use
00261     SV_BoundMaxClients( count );
00262     // if still the same
00263     if ( sv_maxclients->integer == oldMaxClients ) {
00264         return;
00265     }
00266 
00267     oldClients = Hunk_AllocateTempMemory( count * sizeof(client_t) );
00268     // copy the clients to hunk memory
00269     for ( i = 0 ; i < count ; i++ ) {
00270         if ( svs.clients[i].state >= CS_CONNECTED ) {
00271             oldClients[i] = svs.clients[i];
00272         }
00273         else {
00274             Com_Memset(&oldClients[i], 0, sizeof(client_t));
00275         }
00276     }
00277 
00278     // free old clients arrays
00279     Z_Free( svs.clients );
00280 
00281     // allocate new clients
00282     svs.clients = Z_Malloc ( sv_maxclients->integer * sizeof(client_t) );
00283     Com_Memset( svs.clients, 0, sv_maxclients->integer * sizeof(client_t) );
00284 
00285     // copy the clients over
00286     for ( i = 0 ; i < count ; i++ ) {
00287         if ( oldClients[i].state >= CS_CONNECTED ) {
00288             svs.clients[i] = oldClients[i];
00289         }
00290     }
00291 
00292     // free the old clients on the hunk
00293     Hunk_FreeTempMemory( oldClients );
00294     
00295     // allocate new snapshot entities
00296     if ( com_dedicated->integer ) {
00297         svs.numSnapshotEntities = sv_maxclients->integer * PACKET_BACKUP * 64;
00298     } else {
00299         // we don't need nearly as many when playing locally
00300         svs.numSnapshotEntities = sv_maxclients->integer * 4 * 64;
00301     }
00302 }

Here is the call graph for this function:

void SV_ClearServer void   ) 
 

Definition at line 309 of file sv_init.c.

References Com_Memset(), server_t::configstrings, i, sv, and Z_Free().

Referenced by SV_Shutdown(), and SV_SpawnServer().

00309                           {
00310     int i;
00311 
00312     for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) {
00313         if ( sv.configstrings[i] ) {
00314             Z_Free( sv.configstrings[i] );
00315         }
00316     }
00317     Com_Memset (&sv, 0, sizeof(sv));
00318 }

Here is the call graph for this function:

void SV_CreateBaseline void   ) 
 

Definition at line 170 of file sv_init.c.

References svEntity_s::baseline, entityShared_t::linked, server_t::num_entities, entityState_s::number, sharedEntity_t::r, sharedEntity_t::s, sv, SV_GentityNum(), and server_t::svEntities.

Referenced by SV_SpawnServer().

00170                                {
00171     sharedEntity_t *svent;
00172     int             entnum; 
00173 
00174     for ( entnum = 1; entnum < sv.num_entities ; entnum++ ) {
00175         svent = SV_GentityNum(entnum);
00176         if (!svent->r.linked) {
00177             continue;
00178         }
00179         svent->s.number = entnum;
00180 
00181         //
00182         // take current state as baseline
00183         //
00184         sv.svEntities[entnum].baseline = svent->s;
00185     }
00186 }

Here is the call graph for this function:

void SV_FinalMessage char *  message  ) 
 

Definition at line 633 of file sv_init.c.

References cl, client_t, serverStatic_t::clients, i, cvar_s::integer, j, sv_maxclients, SV_SendClientSnapshot(), SV_SendServerCommand(), and svs.

Referenced by SV_Shutdown().

00633                                       {
00634     int         i, j;
00635     client_t    *cl;
00636     
00637     // send it twice, ignoring rate
00638     for ( j = 0 ; j < 2 ; j++ ) {
00639         for (i=0, cl = svs.clients ; i < sv_maxclients->integer ; i++, cl++) {
00640             if (cl->state >= CS_CONNECTED) {
00641                 // don't send a disconnect to a local client
00642                 if ( cl->netchan.remoteAddress.type != NA_LOOPBACK ) {
00643                     SV_SendServerCommand( cl, "print \"%s\"", message );
00644                     SV_SendServerCommand( cl, "disconnect" );
00645                 }
00646                 // force a snapshot to be sent
00647                 cl->nextSnapshotTime = -1;
00648                 SV_SendClientSnapshot( cl );
00649             }
00650         }
00651     }
00652 }

Here is the call graph for this function:

void SV_GetConfigstring int  index,
char *  buffer,
int  bufferSize
 

Definition at line 107 of file sv_init.c.

References buffer, Com_Error(), server_t::configstrings, ERR_DROP, Q_strncpyz(), and sv.

Referenced by SV_GameSystemCalls().

00107                                                                    {
00108     if ( bufferSize < 1 ) {
00109         Com_Error( ERR_DROP, "SV_GetConfigstring: bufferSize == %i", bufferSize );
00110     }
00111     if ( index < 0 || index >= MAX_CONFIGSTRINGS ) {
00112         Com_Error (ERR_DROP, "SV_GetConfigstring: bad index %i\n", index);
00113     }
00114     if ( !sv.configstrings[index] ) {
00115         buffer[0] = 0;
00116         return;
00117     }
00118 
00119     Q_strncpyz( buffer, sv.configstrings[index], bufferSize );
00120 }

Here is the call graph for this function:

void SV_GetUserinfo int  index,
char *  buffer,
int  bufferSize
 

Definition at line 150 of file sv_init.c.

References buffer, serverStatic_t::clients, Com_Error(), ERR_DROP, cvar_s::integer, Q_strncpyz(), sv_maxclients, svs, and client_s::userinfo.

Referenced by SV_GameSystemCalls().

00150                                                                {
00151     if ( bufferSize < 1 ) {
00152         Com_Error( ERR_DROP, "SV_GetUserinfo: bufferSize == %i", bufferSize );
00153     }
00154     if ( index < 0 || index >= sv_maxclients->integer ) {
00155         Com_Error (ERR_DROP, "SV_GetUserinfo: bad index %i\n", index);
00156     }
00157     Q_strncpyz( buffer, svs.clients[ index ].userinfo, bufferSize );
00158 }

Here is the call graph for this function:

void SV_Init void   ) 
 

Definition at line 560 of file sv_init.c.

References CVAR_ARCHIVE, Cvar_Get(), CVAR_INIT, CVAR_LATCH, CVAR_ROM, CVAR_SERVERINFO, CVAR_SYSTEMINFO, CVAR_TEMP, MASTER_SERVER_NAME, PROTOCOL_VERSION, SV_AddOperatorCommands(), sv_allowDownload, SV_BotInitBotLib(), SV_BotInitCvars(), sv_floodProtect, sv_fps, sv_gametype, sv_hostname, sv_killserver, sv_lanForceRate, sv_mapChecksum, sv_mapname, sv_master, sv_maxclients, sv_maxPing, sv_maxRate, sv_minPing, sv_padPackets, sv_privateClients, sv_privatePassword, sv_pure, sv_rconPassword, sv_reconnectlimit, sv_serverid, sv_showloss, sv_strictAuth, sv_timeout, sv_zombietime, and va().

Referenced by Com_Init().

00560                     {
00561     SV_AddOperatorCommands ();
00562 
00563     // serverinfo vars
00564     Cvar_Get ("dmflags", "0", CVAR_SERVERINFO);
00565     Cvar_Get ("fraglimit", "20", CVAR_SERVERINFO);
00566     Cvar_Get ("timelimit", "0", CVAR_SERVERINFO);
00567     sv_gametype = Cvar_Get ("g_gametype", "0", CVAR_SERVERINFO | CVAR_LATCH );
00568     Cvar_Get ("sv_keywords", "", CVAR_SERVERINFO);
00569     Cvar_Get ("protocol", va("%i", PROTOCOL_VERSION), CVAR_SERVERINFO | CVAR_ROM);
00570     sv_mapname = Cvar_Get ("mapname", "nomap", CVAR_SERVERINFO | CVAR_ROM);
00571     sv_privateClients = Cvar_Get ("sv_privateClients", "0", CVAR_SERVERINFO);
00572     sv_hostname = Cvar_Get ("sv_hostname", "noname", CVAR_SERVERINFO | CVAR_ARCHIVE );
00573     sv_maxclients = Cvar_Get ("sv_maxclients", "8", CVAR_SERVERINFO | CVAR_LATCH);
00574 
00575     sv_maxRate = Cvar_Get ("sv_maxRate", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
00576     sv_minPing = Cvar_Get ("sv_minPing", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
00577     sv_maxPing = Cvar_Get ("sv_maxPing", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
00578     sv_floodProtect = Cvar_Get ("sv_floodProtect", "1", CVAR_ARCHIVE | CVAR_SERVERINFO );
00579 
00580     // systeminfo
00581     Cvar_Get ("sv_cheats", "1", CVAR_SYSTEMINFO | CVAR_ROM );
00582     sv_serverid = Cvar_Get ("sv_serverid", "0", CVAR_SYSTEMINFO | CVAR_ROM );
00583 #ifndef DLL_ONLY // bk010216 - for DLL-only servers
00584     sv_pure = Cvar_Get ("sv_pure", "1", CVAR_SYSTEMINFO );
00585 #else
00586     sv_pure = Cvar_Get ("sv_pure", "0", CVAR_SYSTEMINFO | CVAR_INIT | CVAR_ROM );
00587 #endif
00588     Cvar_Get ("sv_paks", "", CVAR_SYSTEMINFO | CVAR_ROM );
00589     Cvar_Get ("sv_pakNames", "", CVAR_SYSTEMINFO | CVAR_ROM );
00590     Cvar_Get ("sv_referencedPaks", "", CVAR_SYSTEMINFO | CVAR_ROM );
00591     Cvar_Get ("sv_referencedPakNames", "", CVAR_SYSTEMINFO | CVAR_ROM );
00592 
00593     // server vars
00594     sv_rconPassword = Cvar_Get ("rconPassword", "", CVAR_TEMP );
00595     sv_privatePassword = Cvar_Get ("sv_privatePassword", "", CVAR_TEMP );
00596     sv_fps = Cvar_Get ("sv_fps", "20", CVAR_TEMP );
00597     sv_timeout = Cvar_Get ("sv_timeout", "200", CVAR_TEMP );
00598     sv_zombietime = Cvar_Get ("sv_zombietime", "2", CVAR_TEMP );
00599     Cvar_Get ("nextmap", "", CVAR_TEMP );
00600 
00601     sv_allowDownload = Cvar_Get ("sv_allowDownload", "0", CVAR_SERVERINFO);
00602     sv_master[0] = Cvar_Get ("sv_master1", MASTER_SERVER_NAME, 0 );
00603     sv_master[1] = Cvar_Get ("sv_master2", "", CVAR_ARCHIVE );
00604     sv_master[2] = Cvar_Get ("sv_master3", "", CVAR_ARCHIVE );
00605     sv_master[3] = Cvar_Get ("sv_master4", "", CVAR_ARCHIVE );
00606     sv_master[4] = Cvar_Get ("sv_master5", "", CVAR_ARCHIVE );
00607     sv_reconnectlimit = Cvar_Get ("sv_reconnectlimit", "3", 0);
00608     sv_showloss = Cvar_Get ("sv_showloss", "0", 0);
00609     sv_padPackets = Cvar_Get ("sv_padPackets", "0", 0);
00610     sv_killserver = Cvar_Get ("sv_killserver", "0", 0);
00611     sv_mapChecksum = Cvar_Get ("sv_mapChecksum", "", CVAR_ROM);
00612     sv_lanForceRate = Cvar_Get ("sv_lanForceRate", "1", CVAR_ARCHIVE );
00613     sv_strictAuth = Cvar_Get ("sv_strictAuth", "1", CVAR_ARCHIVE );
00614 
00615     // initialize bot cvars so they are listed and can be set before loading the botlib
00616     SV_BotInitCvars();
00617 
00618     // init the botlib here because we need the pre-compiler in the UI
00619     SV_BotInitBotLib();
00620 }

Here is the call graph for this function:

void SV_SetConfigstring int  index,
const char *  val
 

Definition at line 31 of file sv_init.c.

References client_t, serverStatic_t::clients, Com_Error(), server_t::configstrings, CopyString(), CS_SERVERINFO, ERR_DROP, client_s::gentity, i, cvar_s::integer, MAX_STRING_CHARS, Q_strncpyz(), sharedEntity_t::r, server_t::restarting, SS_GAME, client_s::state, server_t::state, strcmp(), strlen(), sv, sv_maxclients, SV_SendServerCommand(), entityShared_t::svFlags, svs, and Z_Free().

Referenced by SV_Frame(), SV_GameSystemCalls(), SV_MapRestart_f(), SV_RankNewGameCBF(), and SV_SpawnServer().

00031                                                      {
00032     int     len, i;
00033     int     maxChunkSize = MAX_STRING_CHARS - 24;
00034     client_t    *client;
00035 
00036     if ( index < 0 || index >= MAX_CONFIGSTRINGS ) {
00037         Com_Error (ERR_DROP, "SV_SetConfigstring: bad index %i\n", index);
00038     }
00039 
00040     if ( !val ) {
00041         val = "";
00042     }
00043 
00044     // don't bother broadcasting an update if no change
00045     if ( !strcmp( val, sv.configstrings[ index ] ) ) {
00046         return;
00047     }
00048 
00049     // change the string in sv
00050     Z_Free( sv.configstrings[index] );
00051     sv.configstrings[index] = CopyString( val );
00052 
00053     // send it to all the clients if we aren't
00054     // spawning a new server
00055     if ( sv.state == SS_GAME || sv.restarting ) {
00056 
00057         // send the data to all relevent clients
00058         for (i = 0, client = svs.clients; i < sv_maxclients->integer ; i++, client++) {
00059             if ( client->state < CS_PRIMED ) {
00060                 continue;
00061             }
00062             // do not always send server info to all clients
00063             if ( index == CS_SERVERINFO && client->gentity && (client->gentity->r.svFlags & SVF_NOSERVERINFO) ) {
00064                 continue;
00065             }
00066 
00067             len = strlen( val );
00068             if( len >= maxChunkSize ) {
00069                 int     sent = 0;
00070                 int     remaining = len;
00071                 char    *cmd;
00072                 char    buf[MAX_STRING_CHARS];
00073 
00074                 while (remaining > 0 ) {
00075                     if ( sent == 0 ) {
00076                         cmd = "bcs0";
00077                     }
00078                     else if( remaining < maxChunkSize ) {
00079                         cmd = "bcs2";
00080                     }
00081                     else {
00082                         cmd = "bcs1";
00083                     }
00084                     Q_strncpyz( buf, &val[sent], maxChunkSize );
00085 
00086                     SV_SendServerCommand( client, "%s %i \"%s\"\n", cmd, index, buf );
00087 
00088                     sent += (maxChunkSize - 1);
00089                     remaining -= (maxChunkSize - 1);
00090                 }
00091             } else {
00092                 // standard cs, just send it
00093                 SV_SendServerCommand( client, "cs %i \"%s\"\n", index, val );
00094             }
00095         }
00096     }
00097 }

Here is the call graph for this function:

void SV_SetUserinfo int  index,
const char *  val
 

Definition at line 129 of file sv_init.c.

References serverStatic_t::clients, Com_Error(), ERR_DROP, Info_ValueForKey(), cvar_s::integer, client_s::name, Q_strncpyz(), sv_maxclients, svs, and client_s::userinfo.

Referenced by SV_DropClient(), and SV_GameSystemCalls().

00129                                                   {
00130     if ( index < 0 || index >= sv_maxclients->integer ) {
00131         Com_Error (ERR_DROP, "SV_SetUserinfo: bad index %i\n", index);
00132     }
00133 
00134     if ( !val ) {
00135         val = "";
00136     }
00137 
00138     Q_strncpyz( svs.clients[index].userinfo, val, sizeof( svs.clients[ index ].userinfo ) );
00139     Q_strncpyz( svs.clients[index].name, Info_ValueForKey( val, "name" ), sizeof(svs.clients[index].name) );
00140 }

Here is the call graph for this function:

void SV_Shutdown char *  finalmsg  ) 
 

Definition at line 663 of file sv_init.c.

References CL_Disconnect(), serverStatic_t::clients, Com_Memset(), Com_Printf(), com_sv_running, Cvar_Set(), cvar_s::integer, qfalse, SV_ClearServer(), SV_FinalMessage(), SV_MasterShutdown(), SV_RemoveOperatorCommands(), SV_ShutdownGameProgs(), svs, and Z_Free().

Referenced by CL_Connect_f(), Com_Error(), Com_Quit_f(), SV_Frame(), and SV_KillServer_f().

00663                                    {
00664     if ( !com_sv_running || !com_sv_running->integer ) {
00665         return;
00666     }
00667 
00668     Com_Printf( "----- Server Shutdown -----\n" );
00669 
00670     if ( svs.clients && !com_errorEntered ) {
00671         SV_FinalMessage( finalmsg );
00672     }
00673 
00674     SV_RemoveOperatorCommands();
00675     SV_MasterShutdown();
00676     SV_ShutdownGameProgs();
00677 
00678     // free current level
00679     SV_ClearServer();
00680 
00681     // free server static data
00682     if ( svs.clients ) {
00683         Z_Free( svs.clients );
00684     }
00685     Com_Memset( &svs, 0, sizeof( svs ) );
00686 
00687     Cvar_Set( "sv_running", "0" );
00688     Cvar_Set("ui_singlePlayerActive", "0");
00689 
00690     Com_Printf( "---------------------------\n" );
00691 
00692     // disconnect any local clients
00693     CL_Disconnect( qfalse );
00694 }

Here is the call graph for this function:

void SV_SpawnServer char *  server,
qboolean  killBots
 

Definition at line 347 of file sv_init.c.

References server_t::checksumFeed, server_t::checksumFeedServerId, CL_MapLoading(), CL_ShutdownAll(), client_t, serverStatic_t::clients, CM_ClearMap(), CM_LoadMap(), com_dedicated, Com_Milliseconds(), Com_Printf(), server_t::configstrings, CopyString(), CS_SERVERINFO, CS_SYSTEMINFO, Cvar_InfoString(), Cvar_InfoString_Big(), cvar_modifiedFlags, CVAR_SERVERINFO, Cvar_Set(), CVAR_SYSTEMINFO, Cvar_VariableValue(), client_s::deltaMessage, entityState_t, FS_ClearPakReferences(), FS_LoadedPakChecksums(), FS_LoadedPakNames(), FS_ReferencedPakChecksums(), FS_ReferencedPakNames(), FS_Restart(), GAME_CLIENT_BEGIN, GAME_CLIENT_CONNECT, GAME_RUN_FRAME, client_s::gentity, gvm, h_high, Hunk_Alloc(), Hunk_Clear(), Hunk_SetMark(), i, cvar_s::integer, cvar_s::modified, client_s::netchan, serverStatic_t::nextSnapshotEntities, client_s::nextSnapshotTime, entityState_s::number, serverStatic_t::numSnapshotEntities, p, Q_strncpyz(), qboolean, qfalse, rand(), netchan_t::remoteAddress, server_t::restartedServerId, sharedEntity_t::s, server_t::serverId, serverStatic_t::snapFlagServerBit, serverStatic_t::snapshotEntities, srand(), client_s::state, server_t::state, strlen(), sv, SV_BotFrame(), SV_ChangeMaxClients(), SV_ClearServer(), SV_ClearWorld(), SV_CreateBaseline(), SV_DropClient(), sv_gametype, SV_GentityNum(), SV_Heartbeat_f(), SV_InitGameProgs(), sv_maxclients, sv_pure, SV_SetConfigstring(), SV_ShutdownGameProgs(), SV_Startup(), SV_TouchCGame(), svs, serverStatic_t::time, netadr_t::type, va(), VM_Call(), and VM_ExplicitArgPtr().

Referenced by SV_Map_f(), and SV_MapRestart_f().

00347                                                        {
00348     int         i;
00349     int         checksum;
00350     qboolean    isBot;
00351     char        systemInfo[16384];
00352     const char  *p;
00353 
00354     // shut down the existing game if it is running
00355     SV_ShutdownGameProgs();
00356 
00357     Com_Printf ("------ Server Initialization ------\n");
00358     Com_Printf ("Server: %s\n",server);
00359 
00360     // if not running a dedicated server CL_MapLoading will connect the client to the server
00361     // also print some status stuff
00362     CL_MapLoading();
00363 
00364     // make sure all the client stuff is unloaded
00365     CL_ShutdownAll();
00366 
00367     // clear the whole hunk because we're (re)loading the server
00368     Hunk_Clear();
00369 
00370     // clear collision map data
00371     CM_ClearMap();
00372 
00373     // init client structures and svs.numSnapshotEntities 
00374     if ( !Cvar_VariableValue("sv_running") ) {
00375         SV_Startup();
00376     } else {
00377         // check for maxclients change
00378         if ( sv_maxclients->modified ) {
00379             SV_ChangeMaxClients();
00380         }
00381     }
00382 
00383     // clear pak references
00384     FS_ClearPakReferences(0);
00385 
00386     // allocate the snapshot entities on the hunk
00387     svs.snapshotEntities = Hunk_Alloc( sizeof(entityState_t)*svs.numSnapshotEntities, h_high );
00388     svs.nextSnapshotEntities = 0;
00389 
00390     // toggle the server bit so clients can detect that a
00391     // server has changed
00392     svs.snapFlagServerBit ^= SNAPFLAG_SERVERCOUNT;
00393 
00394     // set nextmap to the same map, but it may be overriden
00395     // by the game startup or another console command
00396     Cvar_Set( "nextmap", "map_restart 0");
00397 //  Cvar_Set( "nextmap", va("map %s", server) );
00398 
00399     // wipe the entire per-level structure
00400     SV_ClearServer();
00401     for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) {
00402         sv.configstrings[i] = CopyString("");
00403     }
00404 
00405     // make sure we are not paused
00406     Cvar_Set("cl_paused", "0");
00407 
00408     // get a new checksum feed and restart the file system
00409     srand(Com_Milliseconds());
00410     sv.checksumFeed = ( ((int) rand() << 16) ^ rand() ) ^ Com_Milliseconds();
00411     FS_Restart( sv.checksumFeed );
00412 
00413     CM_LoadMap( va("maps/%s.bsp", server), qfalse, &checksum );
00414 
00415     // set serverinfo visible name
00416     Cvar_Set( "mapname", server );
00417 
00418     Cvar_Set( "sv_mapChecksum", va("%i",checksum) );
00419 
00420     // serverid should be different each time
00421     sv.serverId = com_frameTime;
00422     sv.restartedServerId = sv.serverId; // I suppose the init here is just to be safe
00423     sv.checksumFeedServerId = sv.serverId;
00424     Cvar_Set( "sv_serverid", va("%i", sv.serverId ) );
00425 
00426     // clear physics interaction links
00427     SV_ClearWorld ();
00428     
00429     // media configstring setting should be done during
00430     // the loading stage, so connected clients don't have
00431     // to load during actual gameplay
00432     sv.state = SS_LOADING;
00433 
00434     // load and spawn all other entities
00435     SV_InitGameProgs();
00436 
00437     // don't allow a map_restart if game is modified
00438     sv_gametype->modified = qfalse;
00439 
00440     // run a few frames to allow everything to settle
00441     for ( i = 0 ;i < 3 ; i++ ) {
00442         VM_Call( gvm, GAME_RUN_FRAME, svs.time );
00443         SV_BotFrame( svs.time );
00444         svs.time += 100;
00445     }
00446 
00447     // create a baseline for more efficient communications
00448     SV_CreateBaseline ();
00449 
00450     for (i=0 ; i<sv_maxclients->integer ; i++) {
00451         // send the new gamestate to all connected clients
00452         if (svs.clients[i].state >= CS_CONNECTED) {
00453             char    *denied;
00454 
00455             if ( svs.clients[i].netchan.remoteAddress.type == NA_BOT ) {
00456                 if ( killBots ) {
00457                     SV_DropClient( &svs.clients[i], "" );
00458                     continue;
00459                 }
00460                 isBot = qtrue;
00461             }
00462             else {
00463                 isBot = qfalse;
00464             }
00465 
00466             // connect the client again
00467             denied = VM_ExplicitArgPtr( gvm, VM_Call( gvm, GAME_CLIENT_CONNECT, i, qfalse, isBot ) );   // firstTime = qfalse
00468             if ( denied ) {
00469                 // this generally shouldn't happen, because the client
00470                 // was connected before the level change
00471                 SV_DropClient( &svs.clients[i], denied );
00472             } else {
00473                 if( !isBot ) {
00474                     // when we get the next packet from a connected client,
00475                     // the new gamestate will be sent
00476                     svs.clients[i].state = CS_CONNECTED;
00477                 }
00478                 else {
00479                     client_t        *client;
00480                     sharedEntity_t  *ent;
00481 
00482                     client = &svs.clients[i];
00483                     client->state = CS_ACTIVE;
00484                     ent = SV_GentityNum( i );
00485                     ent->s.number = i;
00486                     client->gentity = ent;
00487 
00488                     client->deltaMessage = -1;
00489                     client->nextSnapshotTime = svs.time;    // generate a snapshot immediately
00490 
00491                     VM_Call( gvm, GAME_CLIENT_BEGIN, i );
00492                 }
00493             }
00494         }
00495     }   
00496 
00497     // run another frame to allow things to look at all the players
00498     VM_Call( gvm, GAME_RUN_FRAME, svs.time );
00499     SV_BotFrame( svs.time );
00500     svs.time += 100;
00501 
00502     if ( sv_pure->integer ) {
00503         // the server sends these to the clients so they will only
00504         // load pk3s also loaded at the server
00505         p = FS_LoadedPakChecksums();
00506         Cvar_Set( "sv_paks", p );
00507         if (strlen(p) == 0) {
00508             Com_Printf( "WARNING: sv_pure set but no PK3 files loaded\n" );
00509         }
00510         p = FS_LoadedPakNames();
00511         Cvar_Set( "sv_pakNames", p );
00512 
00513         // if a dedicated pure server we need to touch the cgame because it could be in a
00514         // seperate pk3 file and the client will need to load the latest cgame.qvm
00515         if ( com_dedicated->integer ) {
00516             SV_TouchCGame();
00517         }
00518     }
00519     else {
00520         Cvar_Set( "sv_paks", "" );
00521         Cvar_Set( "sv_pakNames", "" );
00522     }
00523     // the server sends these to the clients so they can figure
00524     // out which pk3s should be auto-downloaded
00525     p = FS_ReferencedPakChecksums();
00526     Cvar_Set( "sv_referencedPaks", p );
00527     p = FS_ReferencedPakNames();
00528     Cvar_Set( "sv_referencedPakNames", p );
00529 
00530     // save systeminfo and serverinfo strings
00531     Q_strncpyz( systemInfo, Cvar_InfoString_Big( CVAR_SYSTEMINFO ), sizeof( systemInfo ) );
00532     cvar_modifiedFlags &= ~CVAR_SYSTEMINFO;
00533     SV_SetConfigstring( CS_SYSTEMINFO, systemInfo );
00534 
00535     SV_SetConfigstring( CS_SERVERINFO, Cvar_InfoString( CVAR_SERVERINFO ) );
00536     cvar_modifiedFlags &= ~CVAR_SERVERINFO;
00537 
00538     // any media configstring setting now should issue a warning
00539     // and any configstring changes should be reliably transmitted
00540     // to all clients
00541     sv.state = SS_GAME;
00542 
00543     // send a heartbeat now so the master will get up to date info
00544     SV_Heartbeat_f();
00545 
00546     Hunk_SetMark();
00547 
00548     Com_Printf ("-----------------------------------\n");
00549 }

Here is the call graph for this function:

void SV_Startup void   ) 
 

Definition at line 219 of file sv_init.c.

References client_t, serverStatic_t::clients, com_dedicated, Com_Error(), Cvar_Set(), ERR_FATAL, serverStatic_t::initialized, cvar_s::integer, serverStatic_t::numSnapshotEntities, PACKET_BACKUP, SV_BoundMaxClients(), sv_maxclients, svs, and Z_Malloc().

Referenced by SV_SpawnServer().

00219                         {
00220     if ( svs.initialized ) {
00221         Com_Error( ERR_FATAL, "SV_Startup: svs.initialized" );
00222     }
00223     SV_BoundMaxClients( 1 );
00224 
00225     svs.clients = Z_Malloc (sizeof(client_t) * sv_maxclients->integer );
00226     if ( com_dedicated->integer ) {
00227         svs.numSnapshotEntities = sv_maxclients->integer * PACKET_BACKUP * 64;
00228     } else {
00229         // we don't need nearly as many when playing locally
00230         svs.numSnapshotEntities = sv_maxclients->integer * 4 * 64;
00231     }
00232     svs.initialized = qtrue;
00233 
00234     Cvar_Set( "sv_running", "1" );
00235 }

Here is the call graph for this function:

void SV_TouchCGame void   ) 
 

Definition at line 327 of file sv_init.c.

References Com_sprintf(), f, fileHandle_t, FS_FCloseFile(), FS_FOpenFileRead(), and qfalse.

Referenced by SV_SpawnServer().

00327                          {
00328     fileHandle_t    f;
00329     char filename[MAX_QPATH];
00330 
00331     Com_sprintf( filename, sizeof(filename), "vm/%s.qvm", "cgame" );
00332     FS_FOpenFileRead( filename, &f, qfalse );
00333     if ( f ) {
00334         FS_FCloseFile( f );
00335     }
00336 }

Here is the call graph for this function:


Generated on Thu Aug 25 15:32:09 2005 for Quake III Arena by  doxygen 1.3.9.1