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_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 leakyBucket_t * SVC_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 *streamstream)
 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 *streamstream)
 A client issued an rcon command. Shift down the remaining args. Redirect all printfs.
static void SV_ConnectionlessPacket (struct net_stream *streamstream, 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_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, 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_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
static cvar_t * sv_timeout
cvar_t * sv_maxclients = nullptr
cvar_t * sv_dumpmapassembly
cvar_t * sv_threads
cvar_t * sv_rma
cvar_t * sv_rmadisplaythemap
 display a character graphic of the tiles placed when RMA2 reaches a dead end.
cvar_t * sv_public
cvar_t * sv_mapname
memPool_t * sv_genericPool
static leakyBucket_t buckets [MAX_BUCKETS]
static leakyBucket_t * bucketHashes [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()

◆ 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(), Master_HeartbeatThread(), masterserver_url, masterServerHeartBeatThread, port, and cvar_t::string.

Referenced by Master_Heartbeat(), and Master_HeartbeatThread().

◆ 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(), cvar_t::integer, Master_Shutdown(), masterserver_url, port, cvar_t::string, sv_dedicated, sv_public, and va().

Referenced by Master_Shutdown(), and 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(), rcon_password, Rcon_Validate(), and cvar_t::string.

Referenced by Rcon_Validate(), and SVC_RemoteCommand().

◆ SV_CheckMaxSoldiersPerPlayer()

bool SV_CheckMaxSoldiersPerPlayer ( cvar_t * cvar)
static

◆ 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, serverInstanceGame_t::spawned, sv, SV_CheckSpawnSoldiers(), SV_ClientCommand(), and SV_GetNextClient().

Referenced by SV_CheckSpawnSoldiers(), and SV_Frame().

◆ SV_CheckStartMatch()

◆ SV_CheckTimeouts()

◆ 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_Clear(), SV_LogShutdown(), and SV_MapcycleClear().

Referenced by Com_Quit(), and SV_Clear().

◆ 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, SV_ConnectionlessPacket(), SVC_DirectConnect(), SVC_Info(), SVC_RemoteCommand(), SVC_Status(), and SVC_TeamInfo().

Referenced by SV_ConnectionlessPacket(), and 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, serverInstanceStatic_t::initialized, SV_CountPlayers(), SV_GetNextClient(), and svs.

Referenced by SV_CountPlayers(), and Sys_ConsoleProc().

◆ SV_DropClient()

◆ 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_FinalMessage(), SV_GetNextClient(), svc_disconnect, and svc_reconnect.

Referenced by SV_FinalMessage(), and SV_Shutdown().

◆ SV_Frame()

◆ SV_GetClient()

client_t * SV_GetClient ( int index)

◆ SV_GetConfigString()

◆ SV_GetConfigStringInteger()

int SV_GetConfigStringInteger ( int index)

Definition at line 108 of file sv_main.cpp.

References index, SV_GetConfigString(), and SV_GetConfigStringInteger().

Referenced by SV_GetConfigStringInteger(), 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 serverInstanceGame_t::mapData, sv, and SV_GetMapData().

Referenced by CL_RequestNextDownload(), and SV_GetMapData().

◆ SV_GetMapTiles()

mapTiles_t * SV_GetMapTiles ( void )

Definition at line 952 of file sv_main.cpp.

References serverInstanceGame_t::mapTiles, sv, and SV_GetMapTiles().

Referenced by CL_RequestNextDownload(), and SV_GetMapTiles().

◆ SV_GetNextClient()

client_t * SV_GetNextClient ( client_t * lastClient)

◆ SV_Init()

◆ SV_PingPlayers()

◆ SV_ReadPacket()

◆ 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 serverInstanceStatic_t::clients, Com_Printf(), CVAR_LATCH, CVAR_NOSET, cvar_t::flags, i, serverInstanceStatic_t::initialized, Master_Shutdown(), Mem_Free, sv_model_t::name, NET_DatagramSocketClose(), serverInstanceStatic_t::netDatagramSocket, serverInstanceGame_t::numSVModels, OBJZERO, serverInstanceStatic_t::serverMutex, sv, SV_FinalMessage(), sv_mapname, sv_maxclients, SV_Shutdown(), SV_ShutdownGameProgs(), SV_Stop(), serverInstanceGame_t::svModels, and svs.

Referenced by Com_Error(), Com_Quit(), Com_SetServerState(), GAME_Drop(), GAME_GetImportData(), Qcommon_Frame(), SV_Frame(), SV_KillServer_f(), SV_Shutdown(), 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 serverInstanceStatic_t::abandon, Com_SetServerState(), ss_dead, SV_ShutdownWhenEmpty(), and svs.

Referenced by GAME_GetImportData(), SV_ShutdownWhenEmpty(), 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, serverInstanceStatic_t::ge, i, Info_IntegerForKey(), Info_ValueForKey(), Q_strncpyz(), serverInstanceStatic_t::serverMutex, SV_UserinfoChanged(), and svs.

Referenced by SV_ExecuteClientMessage(), SV_UserinfoChanged(), and SVC_DirectConnect().

◆ SVC_BucketForAddress()

◆ 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(), cvar_t::integer, MAX_INFO_STRING, MAX_VAR, serverInstanceGame_t::name, NET_OOB_Printf(), NET_StreamToString(), outboundLeakyBucket, PROTOCOL_VERSION, cvar_t::string, sv, SV_CMD_INFO, SV_CMD_PRINT, sv_dedicated, sv_gametype, SV_GetNextClient(), sv_hostname, sv_maxclients, SVC_Info(), SVC_RateLimit(), SVC_RateLimitAddress(), and UFO_VERSION.

Referenced by SV_ConnectionlessPacket(), and SVC_Info().

◆ 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(), SVC_RateLimit(), and SVC_RateLimitAddress().

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

◆ SVC_RemoteCommand()

void SVC_RemoteCommand ( struct net_stream * stream)
static

◆ SVC_Status()

◆ 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

cvar_t* sv_public

should heartbeats be sent

should heartbeats be sent? (only for public servers)

Definition at line 52 of file sv_main.cpp.

Referenced by Master_Heartbeat(), Master_Shutdown(), FootStepTest::SetUpTestCase(), MapDefMassRMATest::SetUpTestCase(), MapDefStatsTest::SetUpTestCase(), MapDefTest::SetUpTestCase(), SV_Init(), and SV_InitGame().

◆ 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().