UFO: Alien Invasion
Loading...
Searching...
No Matches
sv_main.cpp File Reference

Main server code? More...

#include "server.h"
#include "sv_log.h"
#include "../ports/system.h"
#include "../shared/scopedmutex.h"
#include "../shared/thread.h"
Include dependency graph for sv_main.cpp:

Go to the source code of this file.

Data Structures

struct  leakyBucket_t

Macros

#define MAX_BUCKETS   16384
#define MAX_HASHES   1024
#define HEARTBEAT_SECONDS   30
#define PING_SECONDS   5

Functions

char * SV_GetConfigString (int index)
int SV_GetConfigStringLength (int index)
int SV_GetConfigStringInteger (int index)
char * SV_SetConfigString (int index,...)
client_tSV_GetNextClient (client_t *lastClient)
 Iterates through clients.
client_tSV_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 leakyBucket_tSVC_BucketForAddress (struct net_stream &address, int burst, int period)
 Find or allocate a bucket for an address.
static bool SVC_RateLimit (leakyBucket_t *bucket, int burst=10, int period=100)
static bool SVC_RateLimitAddress (struct net_stream &from, int burst=10, int period=1000)
 Rate limit for a particular address.
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 bool 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, 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_CheckSpawnSoldiers (void)
 If all connected clients have set their ready flag the server will spawn the clients and that change the client state.
static void SV_CheckStartMatch (void)
static void SV_PingPlayers (void)
static void SV_CheckTimeouts (void)
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 bool SV_CheckMaxSoldiersPerPlayer (cvar_t *cvar)
mapData_tSV_GetMapData (void)
mapTiles_tSV_GetMapTiles (void)
void SV_Init (void)
 Only called once at startup, not for each game.
static void SV_FinalMessage (const char *message, bool 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, bool 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_trcon_password
static cvar_tsv_http_downloadserver
static cvar_tsv_enablemorale
static cvar_tsv_maxsoldiersperteam
static cvar_tsv_maxsoldiersperplayer
static cvar_tsv_hostname
static cvar_tsv_reconnect_limit
static cvar_tsv_timeout
cvar_tsv_maxclients = nullptr
cvar_tsv_dumpmapassembly
cvar_tsv_threads
cvar_tsv_rma
cvar_tsv_rmadisplaythemap
 display a character graphic of the tiles placed when RMA2 reaches a dead end.
cvar_tsv_public
cvar_tsv_mapname
memPool_tsv_genericPool
static leakyBucket_t buckets [MAX_BUCKETS]
static leakyBucket_tbucketHashes [MAX_HASHES]
static leakyBucket_t outboundLeakyBucket
static SDL_Thread * masterServerHeartBeatThread

Detailed Description

Main server code?

Definition in file sv_main.cpp.

Macro Definition Documentation

◆ HEARTBEAT_SECONDS

#define HEARTBEAT_SECONDS   30

Definition at line 690 of file sv_main.cpp.

Referenced by Master_Heartbeat().

◆ MAX_BUCKETS

#define MAX_BUCKETS   16384

Definition at line 70 of file sv_main.cpp.

Referenced by SVC_BucketForAddress().

◆ MAX_HASHES

#define MAX_HASHES   1024

Definition at line 71 of file sv_main.cpp.

Referenced by SVC_BucketForAddress().

◆ PING_SECONDS

#define PING_SECONDS   5

Definition at line 791 of file sv_main.cpp.

Referenced by SV_PingPlayers().

Function Documentation

◆ Master_Heartbeat()

void Master_Heartbeat ( void )
static
See also
CL_PingServers_f

Definition at line 714 of file sv_main.cpp.

References Com_CreateThread(), HEARTBEAT_SECONDS, Master_HeartbeatThread(), masterServerHeartBeatThread, sv_dedicated, sv_public, and svs.

Referenced by SV_Frame().

◆ Master_HeartbeatThread()

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 698 of file sv_main.cpp.

References Com_Printf(), Com_sprintf(), data, HTTP_GetURL(), masterserver_url, masterServerHeartBeatThread, and port.

Referenced by Master_Heartbeat().

◆ Master_Shutdown()

void Master_Shutdown ( void )
static

Informs all masters that this server is going down.

Definition at line 906 of file sv_main.cpp.

References HTTP_GetURL(), masterserver_url, port, sv_dedicated, sv_public, and va().

Referenced by SV_Shutdown().

◆ Rcon_Validate()

bool Rcon_Validate ( const char * password)
inlinestatic

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 569 of file sv_main.cpp.

References password, Q_streq, Q_strnull(), and rcon_password.

Referenced by SVC_RemoteCommand().

◆ SV_CheckMaxSoldiersPerPlayer()

bool SV_CheckMaxSoldiersPerPlayer ( cvar_t * cvar)
static

Definition at line 941 of file sv_main.cpp.

References Cvar_AssertValue(), and MAX_ACTIVETEAM.

Referenced by SV_Init().

◆ SV_CheckSpawnSoldiers()

void SV_CheckSpawnSoldiers ( void )
static

If all connected clients have set their ready flag the server will spawn the clients and that change the client state.

See also
SV_Spawn_f

Definition at line 742 of file sv_main.cpp.

References cl, CL_SPAWNSOLDIERS, cs_began, cs_free, sv, SV_ClientCommand(), and SV_GetNextClient().

Referenced by SV_Frame().

◆ SV_CheckStartMatch()

void SV_CheckStartMatch ( void )
static

◆ SV_CheckTimeouts()

void SV_CheckTimeouts ( void )
static

Definition at line 813 of file sv_main.cpp.

References cl, cs_free, SV_DropClient(), SV_GetNextClient(), sv_maxclients, sv_timeout, and svs.

Referenced by SV_Frame().

◆ SV_Clear()

void SV_Clear ( void )

Cleanup when the whole game process is shutting down.

See also
SV_Shutdown
Com_Quit

Definition at line 1030 of file sv_main.cpp.

References SV_LogShutdown(), and SV_MapcycleClear().

Referenced by Com_Quit().

◆ SV_ConnectionlessPacket()

void SV_ConnectionlessPacket ( struct net_stream * stream,
dbuffer * msg )
static

Handles a connectionless message from a client.

See also
NET_OOB_Printf
Parameters
[out]streamThe stream to write to
msgThe message buffer to read the connectionless data from

Definition at line 638 of file sv_main.cpp.

References Cmd_Argv(), Cmd_TokenizeString(), Com_DPrintf(), Com_Printf(), DEBUG_SERVER, NET_ReadStringLine(), NET_StreamPeerToName(), Q_streq, SV_CMD_CONNECT, SV_CMD_INFO, SV_CMD_RCON, SV_CMD_STATUS, SV_CMD_TEAMINFO, SVC_DirectConnect(), SVC_Info(), SVC_RemoteCommand(), SVC_Status(), and SVC_TeamInfo().

Referenced by SV_ReadPacket().

◆ SV_CountPlayers()

int SV_CountPlayers ( void )

Returns the number of spawned players.

See also
SV_ShutdownWhenEmpty

Definition at line 1096 of file sv_main.cpp.

References cl, count, cs_spawned, SV_GetNextClient(), and svs.

Referenced by Sys_ConsoleProc().

◆ SV_DropClient()

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 184 of file sv_main.cpp.

References cl, count, cs_connected, cs_free, cs_spawned, cs_spawning, client_t::name, NET_StreamFinished(), NET_WriteByte(), NET_WriteMsg(), NET_WriteString(), client_t::player, PRINT_CHAT, SrvPlayer::setInUse(), client_t::state, client_t::stream, SV_BroadcastPrintf(), SV_GetNextClient(), SV_SetClientState(), svc_disconnect, and svs.

Referenced by SV_Begin_f(), SV_CheckTimeouts(), SV_Disconnect_f(), SV_ExecuteClientMessage(), SV_Kick_f(), SV_New_f(), and SV_StartMatch_f().

◆ SV_FinalMessage()

void SV_FinalMessage ( const char * message,
bool reconnect )
static

Used by SV_Shutdown to send a final message to all connected clients before the server goes down.

See also
SV_Shutdown

Definition at line 1002 of file sv_main.cpp.

References cl, cs_connected, NET_StreamFinished(), NET_Wait(), NET_WriteByte(), NET_WriteConstMsg(), NET_WriteString(), SV_GetNextClient(), svc_disconnect, and svc_reconnect.

Referenced by SV_Shutdown().

◆ SV_Frame()

◆ SV_GetClient()

client_t * SV_GetClient ( int index)

Definition at line 174 of file sv_main.cpp.

References index, and svs.

Referenced by SV_CheckStartMatch(), SV_New_f(), SV_PlayerPrintf(), and SVC_DirectConnect().

◆ SV_GetConfigString()

char * SV_GetConfigString ( int index)

◆ SV_GetConfigStringInteger()

int SV_GetConfigStringInteger ( int index)

Definition at line 108 of file sv_main.cpp.

References index, and SV_GetConfigString().

Referenced by SV_Map(), and SV_Status_f().

◆ SV_GetConfigStringLength()

◆ SV_GetMapData()

mapData_t * SV_GetMapData ( void )

Definition at line 947 of file sv_main.cpp.

References sv.

Referenced by CL_RequestNextDownload().

◆ SV_GetMapTiles()

mapTiles_t * SV_GetMapTiles ( void )

Definition at line 952 of file sv_main.cpp.

References sv.

Referenced by CL_RequestNextDownload().

◆ SV_GetNextClient()

client_t * SV_GetNextClient ( client_t * lastClient)

Iterates through clients.

Parameters
[in]lastClientPointer of the client to iterate from. call with nullptr to get the first one.

Definition at line 152 of file sv_main.cpp.

References sv_maxclients, and svs.

Referenced by SV_BroadcastPrintf(), SV_CheckSpawnSoldiers(), SV_CheckStartMatch(), SV_CheckTimeouts(), SV_CountPlayers(), SV_DropClient(), SV_FinalMessage(), SV_GetPlayerClientStructure(), SV_Map(), SV_Multicast(), SV_PingPlayers(), SV_StartGame_f(), SV_Status_f(), SVC_DirectConnect(), SVC_Info(), SVC_Status(), and SVC_TeamInfo().

◆ SV_Init()

◆ SV_PingPlayers()

void SV_PingPlayers ( void )
static

Definition at line 793 of file sv_main.cpp.

References cl, cs_free, NET_WriteByte(), NET_WriteMsg(), PING_SECONDS, SV_GetNextClient(), svc_ping, and svs.

Referenced by SV_Frame().

◆ SV_ReadPacket()

void SV_ReadPacket ( struct net_stream * s)

◆ SV_SetConfigString()

◆ SV_Shutdown()

void SV_Shutdown ( const char * finalmsg,
bool reconnect )

Called when each game quits, before Sys_Quit or Sys_Error.

Parameters
[in]finalmsgThe message all clients get as server shutdown message
[in]reconnectTrue 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 1042 of file sv_main.cpp.

References Com_Printf(), CVAR_LATCH, CVAR_NOSET, i, Master_Shutdown(), Mem_Free, sv_model_t::name, NET_DatagramSocketClose(), OBJZERO, sv, SV_FinalMessage(), sv_mapname, sv_maxclients, SV_ShutdownGameProgs(), SV_Stop(), and svs.

Referenced by Com_Error(), Com_Quit(), Com_SetServerState(), GAME_Drop(), GAME_GetImportData(), Qcommon_Frame(), SV_Frame(), SV_KillServer_f(), and TEST_Shutdown().

◆ SV_ShutdownWhenEmpty()

void SV_ShutdownWhenEmpty ( void )

Will eventually shutdown the server once all clients have disconnected.

See also
SV_CountPlayers

Definition at line 1085 of file sv_main.cpp.

References Com_SetServerState(), ss_dead, and svs.

Referenced by GAME_GetImportData(), and cgame_import_t::void().

◆ SV_UserinfoChanged()

void SV_UserinfoChanged ( client_t * cl)

Pull specific info from a newly changed userinfo string into a more C friendly form.

Definition at line 921 of file sv_main.cpp.

References cl, Com_DPrintf(), DEBUG_SERVER, i, Info_IntegerForKey(), Info_ValueForKey(), Q_strncpyz(), and svs.

Referenced by SV_ExecuteClientMessage(), and SVC_DirectConnect().

◆ SVC_BucketForAddress()

leakyBucket_t * SVC_BucketForAddress ( struct net_stream & address,
int burst,
int period )
static

◆ SVC_DirectConnect()

◆ SVC_Info()

void SVC_Info ( struct net_stream * s)
static

Responds with short info for broadcast scans.

Note
The second parameter should be the current protocol version number.
Only a short server description - the user can determine whether he is interested in a full status
See also
CL_ParseStatusMessage
CL_ProcessPingReply

Definition at line 411 of file sv_main.cpp.

References cl, Cmd_Argv(), Com_DPrintf(), Com_sprintf(), count, cs_spawning, DEBUG_SERVER, DOUBLEQUOTE, Info_SetValueForKey(), Info_SetValueForKeyAsInteger(), MAX_INFO_STRING, MAX_VAR, NET_OOB_Printf(), NET_StreamToString(), outboundLeakyBucket, PROTOCOL_VERSION, sv, SV_CMD_INFO, SV_CMD_PRINT, sv_dedicated, sv_gametype, SV_GetNextClient(), sv_hostname, sv_maxclients, SVC_RateLimit(), SVC_RateLimitAddress(), and UFO_VERSION.

Referenced by SV_ConnectionlessPacket().

◆ SVC_RateLimit()

bool SVC_RateLimit ( leakyBucket_t * bucket,
int burst = 10,
int period = 100 )
static

◆ SVC_RateLimitAddress()

bool SVC_RateLimitAddress ( struct net_stream & from,
int burst = 10,
int period = 1000 )
static

Rate limit for a particular address.

Definition at line 313 of file sv_main.cpp.

References SVC_BucketForAddress(), and SVC_RateLimit().

Referenced by SVC_Info(), SVC_RemoteCommand(), SVC_Status(), and SVC_TeamInfo().

◆ SVC_RemoteCommand()

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 585 of file sv_main.cpp.

References BAD_RCON_PASSWORD, Cmd_Argc(), Cmd_Argv(), Cmd_ExecuteString(), Com_BeginRedirect(), Com_DPrintf(), Com_EndRedirect(), Com_Printf(), DEBUG_SERVER, i, NET_StreamPeerToName(), Q_strcat(), Rcon_Validate(), SVC_RateLimit(), and SVC_RateLimitAddress().

Referenced by SV_ConnectionlessPacket().

◆ SVC_Status()

void SVC_Status ( struct net_stream * s)
static

◆ SVC_TeamInfo()

Variable Documentation

◆ bucketHashes

leakyBucket_t* bucketHashes[MAX_HASHES]
static

Definition at line 74 of file sv_main.cpp.

Referenced by SVC_BucketForAddress().

◆ buckets

leakyBucket_t buckets[MAX_BUCKETS]
static

Definition at line 73 of file sv_main.cpp.

Referenced by SVC_BucketForAddress().

◆ masterServerHeartBeatThread

SDL_Thread* masterServerHeartBeatThread
static

Definition at line 692 of file sv_main.cpp.

Referenced by Master_Heartbeat(), and Master_HeartbeatThread().

◆ outboundLeakyBucket

leakyBucket_t outboundLeakyBucket
static

Definition at line 75 of file sv_main.cpp.

Referenced by SVC_Info(), SVC_Status(), and SVC_TeamInfo().

◆ rcon_password

cvar_t* rcon_password
static

password for remote server commands

Definition at line 36 of file sv_main.cpp.

Referenced by Rcon_Validate(), and SV_Init().

◆ sv_dumpmapassembly

◆ sv_enablemorale

cvar_t* sv_enablemorale
static

Definition at line 38 of file sv_main.cpp.

◆ sv_genericPool

◆ sv_hostname

cvar_t* sv_hostname
static

Definition at line 41 of file sv_main.cpp.

Referenced by SV_Init(), and SVC_Info().

◆ sv_http_downloadserver

cvar_t* sv_http_downloadserver
static

Definition at line 37 of file sv_main.cpp.

Referenced by SV_Init(), and SVC_DirectConnect().

◆ sv_mapname

cvar_t* sv_mapname

Definition at line 53 of file sv_main.cpp.

Referenced by SV_Map(), and SV_Shutdown().

◆ sv_maxclients

◆ sv_maxsoldiersperplayer

cvar_t* sv_maxsoldiersperplayer
static

Definition at line 40 of file sv_main.cpp.

◆ sv_maxsoldiersperteam

cvar_t* sv_maxsoldiersperteam
static

Definition at line 39 of file sv_main.cpp.

◆ sv_public

◆ sv_reconnect_limit

cvar_t* sv_reconnect_limit
static

minimum seconds between connect messages

Definition at line 43 of file sv_main.cpp.

Referenced by SV_Init().

◆ sv_rma

◆ sv_rmadisplaythemap

cvar_t* sv_rmadisplaythemap

display a character graphic of the tiles placed when RMA2 reaches a dead end.

Definition at line 50 of file sv_main.cpp.

Referenced by RandomMapAssemblyTest::SetUpTestCase(), SV_AddMapTiles(), SV_AddMissingTiles_r(), and SV_Init().

◆ sv_threads

◆ sv_timeout

cvar_t* sv_timeout
static

Definition at line 44 of file sv_main.cpp.

Referenced by SV_CheckTimeouts(), and SV_Init().