Main server code? More...
#include "server.h"
#include "../ports/system.h"
Go to the source code of this file.
Defines | |
#define | SV_OUTPUTBUF_LENGTH 1024 |
#define | HEARTBEAT_SECONDS 300 |
Functions | |
char * | SV_GetConfigString (int index) |
int | SV_GetConfigStringInteger (int index) |
char * | SV_SetConfigString (int index,...) |
client_t * | SV_GetNextClient (client_t *lastClient) |
Iterates through clients. | |
client_t * | SV_GetClient (int index) |
void | SV_DropClient (client_t *drop, const char *message) |
Called when the player is totally leaving the server, either willingly or unwillingly. This is NOT called if the entire server is quitting or crashing. | |
static void | SVC_TeamInfo (struct net_stream *s) |
Responds with teaminfo such as free team num. | |
static void | SVC_Status (struct net_stream *s) |
Responds with all the info that the server browser can see. | |
static void | SVC_Info (struct net_stream *s) |
Responds with short info for broadcast scans. | |
static void | SVC_DirectConnect (struct net_stream *stream) |
A connection request that did not come from the master. | |
static qboolean | Rcon_Validate (const char *password) |
Checks whether the remote connection is allowed (rcon_password must be set on the server) - and verify the user given password with the cvar value. | |
static void | SVC_RemoteCommand (struct net_stream *stream) |
A client issued an rcon command. Shift down the remaining args. Redirect all printfs. | |
static void | SV_ConnectionlessPacket (struct net_stream *stream, struct dbuffer *msg) |
Handles a connectionless message from a client. | |
void | SV_ReadPacket (struct net_stream *s) |
static int | Master_HeartbeatThread (void *data) |
Send a message to the master every few minutes to let it know we are alive, and log information. | |
static void | Master_Heartbeat (void) |
static void | SV_CheckGameStart (void) |
If all connected clients have set their ready flag the server will spawn the clients and that change the client state. | |
void | SV_Frame (int now, void *data) |
static void | Master_Shutdown (void) |
Informs all masters that this server is going down. | |
void | SV_UserinfoChanged (client_t *cl) |
Pull specific info from a newly changed userinfo string into a more C friendly form. | |
static qboolean | SV_CheckMaxSoldiersPerPlayer (cvar_t *cvar) |
mapData_t * | SV_GetMapData (void) |
mapTiles_t * | SV_GetMapTiles (void) |
void | SV_Init (void) |
Only called once at startup, not for each game. | |
static void | SV_FinalMessage (const char *message, qboolean reconnect) |
Used by SV_Shutdown to send a final message to all connected clients before the server goes down. | |
void | SV_Clear (void) |
Cleanup when the whole game process is shutting down. | |
void | SV_Shutdown (const char *finalmsg, qboolean reconnect) |
Called when each game quits, before Sys_Quit or Sys_Error. | |
void | SV_ShutdownWhenEmpty (void) |
Will eventually shutdown the server once all clients have disconnected. | |
int | SV_CountPlayers (void) |
Returns the number of spawned players. | |
Variables | |
static cvar_t * | rcon_password |
static cvar_t * | sv_http_downloadserver |
static cvar_t * | sv_enablemorale |
static cvar_t * | sv_maxsoldiersperteam |
static cvar_t * | sv_maxsoldiersperplayer |
static cvar_t * | sv_hostname |
static cvar_t * | sv_reconnect_limit |
cvar_t * | sv_maxclients = NULL |
cvar_t * | sv_dumpmapassembly |
cvar_t * | sv_threads |
cvar_t * | sv_public |
cvar_t * | sv_mapname |
memPool_t * | sv_genericPool |
static char | sv_outputbuf [SV_OUTPUTBUF_LENGTH] |
static SDL_Thread * | masterServerHeartBeatThread |
Main server code?
Definition in file sv_main.c.
#define HEARTBEAT_SECONDS 300 |
Definition at line 513 of file sv_main.c.
Referenced by Master_Heartbeat().
#define SV_OUTPUTBUF_LENGTH 1024 |
Definition at line 416 of file sv_main.c.
Referenced by SVC_RemoteCommand().
static void Master_Heartbeat | ( | void | ) | [static] |
Definition at line 540 of file sv_main.c.
References HEARTBEAT_SECONDS, cvar_s::integer, serverInstanceStatic_t::lastHeartbeat, Master_HeartbeatThread(), masterServerHeartBeatThread, serverInstanceStatic_t::realtime, sv_dedicated, and svs.
Referenced by SV_Frame().
static int Master_HeartbeatThread | ( | void * | data | ) | [static] |
Send a message to the master every few minutes to let it know we are alive, and log information.
Definition at line 521 of file sv_main.c.
References Com_DPrintf(), Com_Printf(), DEBUG_SERVER, HTTP_GetURL(), masterserver_url, masterServerHeartBeatThread, Mem_Free, port, cvar_s::string, and va().
Referenced by Master_Heartbeat().
static void Master_Shutdown | ( | void | ) | [static] |
Informs all masters that this server is going down.
Definition at line 646 of file sv_main.c.
References Com_DPrintf(), DEBUG_SERVER, HTTP_GetURL(), cvar_s::integer, masterserver_url, Mem_Free, port, cvar_s::string, sv_dedicated, and va().
Referenced by SV_Shutdown().
static qboolean Rcon_Validate | ( | const char * | password | ) | [inline, static] |
Checks whether the remote connection is allowed (rcon_password must be set on the server) - and verify the user given password with the cvar value.
Definition at line 403 of file sv_main.c.
References qfalse, qtrue, and cvar_s::string.
Referenced by SVC_RemoteCommand().
static void SV_CheckGameStart | ( | void | ) | [static] |
If all connected clients have set their ready flag the server will spawn the clients and that change the client state.
Definition at line 568 of file sv_main.c.
References cl, cs_began, cs_free, cvar_s::integer, player_s::isReady, client_s::player, qtrue, serverInstanceGame_t::started, client_s::state, sv, SV_ClientCommand(), SV_GetClient(), and SV_GetNextClient().
Referenced by SV_Frame().
Definition at line 691 of file sv_main.c.
References Cvar_AssertValue(), MAX_ACTIVETEAM, and qtrue.
Referenced by SV_Init().
void SV_Clear | ( | void | ) |
Cleanup when the whole game process is shutting down.
Definition at line 781 of file sv_main.c.
References SV_MapcycleClear().
Referenced by Com_Quit().
static void SV_ConnectionlessPacket | ( | struct net_stream * | stream, | |
struct dbuffer * | msg | |||
) | [static] |
Handles a connectionless message from a client.
[out] | stream | The stream to write to |
msg | The message buffer to read the connectionless data from |
Definition at line 462 of file sv_main.c.
References Cmd_Argv(), Cmd_TokenizeString(), Com_DPrintf(), Com_Printf(), DEBUG_SERVER, NET_ReadStringLine(), NET_StreamPeerToName(), qfalse, qtrue, SVC_DirectConnect(), SVC_Info(), SVC_RemoteCommand(), SVC_Status(), and SVC_TeamInfo().
Referenced by SV_ReadPacket().
int SV_CountPlayers | ( | void | ) |
Returns the number of spawned players.
Definition at line 851 of file sv_main.c.
References cl, count, cs_spawned, serverInstanceStatic_t::initialized, client_s::state, SV_GetNextClient(), and svs.
Referenced by Sys_ConsoleProc().
void SV_DropClient | ( | client_t * | drop, | |
const char * | message | |||
) |
Called when the player is totally leaving the server, either willingly or unwillingly. This is NOT called if the entire server is quitting or crashing.
Definition at line 136 of file sv_main.c.
References serverInstanceStatic_t::abandon, cl, count, cs_connected, cs_free, cs_spawned, cs_spawning, serverInstanceStatic_t::ge, player_s::inuse, serverInstanceStatic_t::killserver, client_s::name, NET_StreamFinished(), NET_WriteByte(), NET_WriteMsg(), NET_WriteString(), new_dbuffer(), client_s::player, PRINT_CHAT, qfalse, qtrue, serverInstanceStatic_t::serverMutex, client_s::state, client_s::stream, SV_BroadcastPrintf(), SV_GetNextClient(), SV_SetClientState(), svc_disconnect, and svs.
Referenced by SV_Begin_f(), SV_Disconnect_f(), SV_ExecuteClientMessage(), SV_Kick_f(), SV_New_f(), and SV_Spawn_f().
static void SV_FinalMessage | ( | const char * | message, | |
qboolean | reconnect | |||
) | [static] |
Used by SV_Shutdown to send a final message to all connected clients before the server goes down.
Definition at line 751 of file sv_main.c.
References cl, cs_connected, free_dbuffer(), NET_StreamFinished(), NET_Wait(), NET_WriteByte(), NET_WriteConstMsg(), NET_WriteString(), new_dbuffer(), client_s::state, client_s::stream, SV_GetNextClient(), svc_disconnect, and svc_reconnect.
Referenced by SV_Shutdown().
void SV_Frame | ( | int | now, | |
void * | data | |||
) |
Definition at line 600 of file sv_main.c.
References serverInstanceStatic_t::abandon, Cbuf_AddText(), Com_SetGameType(), serverInstanceGame_t::endgame, serverInstanceStatic_t::initialized, cvar_s::integer, serverInstanceStatic_t::killserver, Master_Heartbeat(), cvar_s::modified, qfalse, serverInstanceStatic_t::realtime, sv, SV_CheckGameStart(), sv_dedicated, sv_gametype, SV_NextMapcycle(), SV_RunGameFrame(), SV_Shutdown(), svs, Sys_ConsoleInput(), and va().
Referenced by Qcommon_Init().
client_t* SV_GetClient | ( | int | index | ) |
Definition at line 126 of file sv_main.c.
References serverInstanceStatic_t::clients, and svs.
Referenced by SV_CheckGameStart(), SV_New_f(), SV_PlayerPrintf(), and SVC_DirectConnect().
char* SV_GetConfigString | ( | int | index | ) |
Definition at line 51 of file sv_main.c.
References Com_Error(), serverInstanceGame_t::configstrings, ERR_FATAL, MAX_CONFIGSTRINGS, and sv.
Referenced by SV_FindIndex(), SV_Map(), SV_New_f(), and SV_PrintConfigStrings_f().
int SV_GetConfigStringInteger | ( | int | index | ) |
Definition at line 58 of file sv_main.c.
References Com_Error(), serverInstanceGame_t::configstrings, ERR_FATAL, MAX_CONFIGSTRINGS, and sv.
Referenced by SV_Map(), and SV_Status_f().
mapData_t* SV_GetMapData | ( | void | ) |
Definition at line 697 of file sv_main.c.
References serverInstanceGame_t::mapData, and sv.
Referenced by CL_RequestNextDownload().
mapTiles_t* SV_GetMapTiles | ( | void | ) |
Definition at line 702 of file sv_main.c.
References serverInstanceGame_t::mapTiles, and sv.
Referenced by CL_RequestNextDownload().
Iterates through clients.
[in] | lastClient | Pointer of the client to iterate from. call with NULL to get the first one. |
Definition at line 104 of file sv_main.c.
References serverInstanceStatic_t::clients, cvar_s::integer, and svs.
Referenced by SV_BroadcastPrintf(), SV_CheckGameStart(), SV_CountPlayers(), SV_DropClient(), SV_FinalMessage(), SV_GetPlayerClientStructure(), SV_Map(), SV_Multicast(), SV_StartGame_f(), SV_Status_f(), SVC_DirectConnect(), SVC_Info(), SVC_Status(), and SVC_TeamInfo().
void SV_Init | ( | void | ) |
Only called once at startup, not for each game.
Definition at line 710 of file sv_main.c.
References Com_Printf(), CVAR_ARCHIVE, Cvar_Get(), CVAR_LATCH, CVAR_NOSET, CVAR_SERVERINFO, Cvar_Set(), Cvar_SetCheckFunction(), DOUBLEQUOTE, cvar_s::integer, Mem_CreatePool, cvar_s::modified, PROTOCOL_VERSION, qfalse, SV_CheckMaxSoldiersPerPlayer(), sv_dedicated, SV_InitOperatorCommands(), SV_MapcycleInit(), and svs.
void SV_ReadPacket | ( | struct net_stream * | s | ) |
Definition at line 494 of file sv_main.c.
References cl, clc_oob, free_dbuffer(), NET_ReadByte(), NET_ReadMsg(), NET_StreamFree(), NET_StreamGetData(), SV_ConnectionlessPacket(), and SV_ExecuteClientMessage().
Referenced by SV_InitGame().
char* SV_SetConfigString | ( | int | index, | |
... | ||||
) |
Definition at line 65 of file sv_main.c.
References Com_Error(), serverInstanceGame_t::configstrings, CS_LIGHTMAP, CS_MAPCHECKSUM, CS_OBJECTAMOUNT, CS_POSITIONS, CS_TILES, CS_UFOCHECKSUM, ERR_FATAL, MAX_CONFIGSTRINGS, MAX_TILESTRINGS, MAX_TOKEN_CHARS, Q_strncpyz(), sv, and va().
void SV_Shutdown | ( | const char * | finalmsg, | |
qboolean | reconnect | |||
) |
Called when each game quits, before Sys_Quit or Sys_Error.
[in] | finalmsg | The message all clients get as server shutdown message |
[in] | reconnect | True if this is only a restart (new map or map restart), false if the server shutdown completely and you also want to disconnect all clients |
Definition at line 792 of file sv_main.c.
References serverInstanceStatic_t::clients, Com_Printf(), CVAR_LATCH, CVAR_NOSET, cvar_s::flags, i, serverInstanceStatic_t::initialized, Master_Shutdown(), Mem_Free, sv_model_s::name, NET_DatagramSocketClose(), serverInstanceStatic_t::netDatagramSocket, serverInstanceGame_t::numSVModels, serverInstanceStatic_t::serverMutex, sv, SV_FinalMessage(), SV_ShutdownGameProgs(), SV_Stop(), serverInstanceGame_t::svModels, and svs.
void SV_ShutdownWhenEmpty | ( | void | ) |
Will eventually shutdown the server once all clients have disconnected.
Definition at line 840 of file sv_main.c.
References serverInstanceStatic_t::abandon, Com_SetServerState(), qtrue, ss_dead, and svs.
Referenced by CL_Disconnect_f().
void SV_UserinfoChanged | ( | client_t * | cl | ) |
Pull specific info from a newly changed userinfo string into a more C friendly form.
Definition at line 667 of file sv_main.c.
References Com_DPrintf(), DEBUG_SERVER, serverInstanceStatic_t::ge, i, Info_ValueForKey(), client_s::messagelevel, client_s::name, client_s::player, serverInstanceStatic_t::serverMutex, svs, and client_s::userinfo.
Referenced by SV_ExecuteClientMessage(), and SVC_DirectConnect().
static void SVC_DirectConnect | ( | struct net_stream * | stream | ) | [static] |
A connection request that did not come from the master.
Definition at line 293 of file sv_main.c.
References cl, Cmd_Argv(), Com_DPrintf(), Com_Printf(), cs_connected, cs_free, DEBUG_SERVER, serverInstanceStatic_t::ge, Info_SetValueForKey(), Info_ValueForKey(), player_s::inuse, client_s::lastconnect, MAX_INFO_STRING, NET_OOB_Printf(), NET_StreamPeerToName(), NET_StreamSetData(), player_s::num, client_s::peername, client_s::player, PLAYER_NUM, PROTOCOL_VERSION, Q_strncpyz(), qfalse, qtrue, serverInstanceStatic_t::realtime, serverInstanceStatic_t::serverMutex, serverInstanceGame_t::started, client_s::state, client_s::stream, cvar_s::string, sv, SV_GetClient(), SV_GetNextClient(), SV_SetClientState(), SV_UserinfoChanged(), svs, UFO_VERSION, and client_s::userinfo.
Referenced by SV_ConnectionlessPacket().
static void SVC_Info | ( | struct net_stream * | s | ) | [static] |
Responds with short info for broadcast scans.
Definition at line 249 of file sv_main.c.
References cl, Cmd_Argv(), Com_DPrintf(), Com_sprintf(), count, cs_spawning, DEBUG_SERVER, DOUBLEQUOTE, Info_SetValueForKey(), Info_SetValueForKeyAsInteger(), cvar_s::integer, MAX_INFO_STRING, MAX_VAR, serverInstanceGame_t::name, NET_OOB_Printf(), PROTOCOL_VERSION, client_s::state, cvar_s::string, sv, sv_dedicated, sv_gametype, SV_GetNextClient(), and UFO_VERSION.
Referenced by SV_ConnectionlessPacket().
static void SVC_RemoteCommand | ( | struct net_stream * | stream | ) | [static] |
A client issued an rcon command. Shift down the remaining args. Redirect all printfs.
Definition at line 423 of file sv_main.c.
References Cmd_Argc(), Cmd_Argv(), Cmd_ExecuteString(), Com_BeginRedirect(), Com_EndRedirect(), Com_Printf(), i, NET_StreamPeerToName(), Q_strcat(), qfalse, Rcon_Validate(), sv_outputbuf, and SV_OUTPUTBUF_LENGTH.
Referenced by SV_ConnectionlessPacket().
static void SVC_Status | ( | struct net_stream * | s | ) | [static] |
Responds with all the info that the server browser can see.
Definition at line 219 of file sv_main.c.
References cl, clc_oob, Com_sprintf(), cs_free, Cvar_Serverinfo(), serverInstanceStatic_t::ge, client_s::name, NET_WriteByte(), NET_WriteMsg(), NET_WriteRawString(), new_dbuffer(), client_s::player, client_s::state, SV_GetNextClient(), and svs.
Referenced by SV_ConnectionlessPacket().
static void SVC_TeamInfo | ( | struct net_stream * | s | ) | [static] |
Responds with teaminfo such as free team num.
Definition at line 181 of file sv_main.c.
References cl, clc_oob, cs_connected, Cvar_GetString(), serverInstanceStatic_t::ge, Info_SetValueForKey(), Info_SetValueForKeyAsInteger(), MAX_INFO_STRING, client_s::name, NET_WriteByte(), NET_WriteMsg(), NET_WriteRawString(), NET_WriteString(), new_dbuffer(), client_s::player, client_s::state, SV_GetNextClient(), svs, and TEAM_NO_ACTIVE.
Referenced by SV_ConnectionlessPacket().
SDL_Thread* masterServerHeartBeatThread [static] |
Definition at line 515 of file sv_main.c.
Referenced by Master_Heartbeat(), and Master_HeartbeatThread().
cvar_t* rcon_password [static] |
cvar_t* sv_enablemorale [static] |
Definition at line 49 of file sv_main.c.
Referenced by SV_InitGame(), and SV_MapcycleAdd().
cvar_t* sv_hostname [static] |
cvar_t* sv_http_downloadserver [static] |
cvar_t* sv_maxclients = NULL |
Definition at line 42 of file sv_main.c.
Referenced by AI_CreatePlayer(), AI_FighterCalcBestAction(), AI_SetStats(), CL_InitLocal(), G_ActorSpawnIsAllowed(), G_CheckForceEndRound(), G_Damage(), G_GetStartingTeam(), G_GetTeam(), G_IsMoraleEnabled(), G_Morale(), G_MoraleBehaviour(), G_SpawnEntities(), SP_2x2_start(), SP_alien_start(), SP_civilian_start(), SP_human_start(), SP_player_start(), SP_worldspawn(), SV_InitGame(), SV_ParseAssembly(), SV_SetMaster_f(), and UFO_AddRandomMapAssemblyTests().
cvar_t* sv_maxsoldiersperplayer [static] |
cvar_t* sv_maxsoldiersperteam [static] |
char sv_outputbuf[SV_OUTPUTBUF_LENGTH] [static] |
Definition at line 418 of file sv_main.c.
Referenced by SVC_RemoteCommand().
cvar_t* sv_reconnect_limit [static] |