UFO: Alien Invasion
server.h File Reference

Main server include file. More...

#include "../common/common.h"
#include "../common/http.h"
#include "../shared/infostring.h"
#include "../game/game.h"
#include <SDL_thread.h>
Include dependency graph for server.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sv_edict_t
 
struct  sv_model_t
 static mesh models (none-animated) can have a server side flag set to be clipped for pathfinding More...
 
struct  worldSector_t
 To avoid linearly searching through lists of entities during environment testing, the world is carved up with an evenly spaced, axially aligned bsp tree. More...
 
struct  pending_event_t
 
struct  serverInstanceStatic_t
 
struct  serverInstanceGame_t
 Struct that is only valid for one map. It's deleted on every map load. More...
 
struct  client_t
 

Macros

#define AREA_NODES   32
 
#define PLAYER_NUM(n)   ((player_t*)((byte*)svs.ge->players + svs.ge->player_size * (n)))
 
#define SV_SetConfigString(index, value)   SV_SetConfigString(index, value)
 

Enumerations

enum  server_state_t {
  ss_dead , ss_restart , ss_loading , ss_game ,
  ss_game_shutdown
}
 
enum  client_state_t {
  cs_free , cs_connected , cs_spawning , cs_began ,
  cs_spawned
}
 

Functions

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. More...
 
int SV_CountPlayers (void)
 Returns the number of spawned players. More...
 
void SV_InitOperatorCommands (void)
 
void SV_UserinfoChanged (client_t *cl)
 Pull specific info from a newly changed userinfo string into a more C friendly form. More...
 
void SV_ReadPacket (struct net_stream *s)
 
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. More...
 
client_tSV_GetClient (int index)
 
void SV_MapcycleInit (void)
 
void SV_NextMapcycle (void)
 Start the next map in the cycle. More...
 
void SV_MapcycleClear (void)
 Empty the mapcycle list. More...
 
void SV_Map (bool day, const char *levelstring, const char *assembly, bool verbose=true)
 Change the server to a new map, taking all connected clients along with it. More...
 
void SV_Multicast (int mask, const dbuffer &msg)
 Sends the contents of msg to a subset of the clients, then frees msg. More...
 
void SV_ClientCommand (client_t *client, const char *fmt,...) __attribute__((format(__printf__
 
void void SV_ClientPrintf (client_t *cl, int level, const char *fmt,...) __attribute__((format(__printf__
 
void void void SV_BroadcastPrintf (int level, const char *fmt,...) __attribute__((format(__printf__
 
void void void void SV_ExecuteClientMessage (client_t *cl, int cmd, dbuffer *msg)
 The current net_message is parsed for the given client. More...
 
void SV_SetClientState (client_t *client, client_state_t state)
 Set the client state. More...
 
void SV_SetMaster_f (void)
 Add the server to the master server list so that others can see the server in the server list. More...
 
void SV_Heartbeat_f (void)
 
bool SV_CheckMap (const char *map, const char *assembly)
 Checks whether a map exists. More...
 
int SV_RunGameFrameThread (void *data)
 Thread for the game frame function. More...
 
void SV_RunGameFrame (void)
 Calls the G_RunFrame function from game api let everything in the world think and move. More...
 
void SV_InitGameProgs (void)
 Init the game subsystem for a new map. More...
 
void SV_ShutdownGameProgs (void)
 Called when either the entire server is being killed, or it is changing to a different game directory. More...
 
void SV_ClearWorld (void)
 Clear physics interaction links. More...
 
void SV_UnlinkEdict (edict_t *ent)
 call before removing an entity, and before trying to move one, so it doesn't clip against itself More...
 
void SV_LinkEdict (edict_t *ent)
 Needs to be called any time an entity changes origin, mins, maxs, or solid. Automatically unlinks if needed. Sets ent->absmin and ent->absBox.maxs. More...
 
int SV_PointContents (const vec3_t p)
 Returns the content flags for a given point. More...
 
const char * SV_GetFootstepSound (const char *texture)
 Query the footstep sound for the given surface texture. More...
 
float SV_GetBounceFraction (const char *texture)
 Different terrain types might have different bounce fraction. More...
 
bool SV_LoadModelAABB (const char *model, int frame, AABB &aabb)
 Load the bounding box for the model on the serverside for pathfinding and clipping. More...
 
trace_t SV_Trace (const Line &traceLine, const AABB &box, const edict_t *passedict, int contentmask)
 Moves the given mins/maxs volume through the world from start to end. More...
 
server_state_t SV_GetServerState (void)
 
void SV_SetServerState (server_state_t)
 

Variables

memPool_tsv_genericPool
 
serverInstanceStatic_t svs
 
serverInstanceGame_tsv
 
cvar_tsv_mapname
 
cvar_tsv_rma
 
cvar_tsv_rmadisplaythemap
 display a character graphic of the tiles placed when RMA2 reaches a dead end. More...
 
cvar_tsv_public
 
cvar_tsv_dumpmapassembly
 
cvar_tsv_threads
 

Detailed Description

Main server include file.

Definition in file server.h.

Macro Definition Documentation

◆ AREA_NODES

#define AREA_NODES   32

Definition at line 64 of file server.h.

◆ PLAYER_NUM

#define PLAYER_NUM (   n)    ((player_t*)((byte*)svs.ge->players + svs.ge->player_size * (n)))

Definition at line 137 of file server.h.

◆ SV_SetConfigString

#define SV_SetConfigString (   index,
  value 
)    SV_SetConfigString(index, value)

Definition at line 188 of file server.h.

Enumeration Type Documentation

◆ client_state_t

Enumerator
cs_free 

can be reused for a new connection

cs_connected 

has been assigned to a client_t, but not in game yet

cs_spawning 

received new, not begin yet

cs_began 

began was received, client side rendering is active - in this stage the player is an spectator and still has to spawn his soldiers

cs_spawned 

client is fully in game and soldiers were spawned

Definition at line 139 of file server.h.

◆ server_state_t

Enumerator
ss_dead 

no map loaded

ss_restart 

clients should reconnect, the server switched the map

ss_loading 

spawning level edicts

ss_game 

actively running

ss_game_shutdown 

tell the game lib to end

Definition at line 95 of file server.h.

Function Documentation

◆ SV_BroadcastPrintf()

void void void SV_BroadcastPrintf ( int  level,
const char *  fmt,
  ... 
)

◆ SV_CheckMap()

bool SV_CheckMap ( const char *  map,
const char *  assembly 
)

Checks whether a map exists.

Definition at line 101 of file sv_ccmds.cpp.

References Com_Printf(), Com_sprintf(), FS_CheckFile(), and MAX_QPATH.

Referenced by SV_Map_f(), and SV_MapcycleAdd_f().

◆ SV_ClearWorld()

void SV_ClearWorld ( void  )

Clear physics interaction links.

Note
Called after the world model has been loaded, before linking any entities
See also
SV_SpawnServer
SV_CreateAreaNode

Definition at line 81 of file sv_world.cpp.

References mapData_t::mapBox, serverInstanceGame_t::mapData, sv, and SV_CreateWorldSector().

Referenced by SV_Map(), and TEST_F().

◆ SV_ClientCommand()

void SV_ClientCommand ( client_t client,
const char *  fmt,
  ... 
)

◆ SV_ClientPrintf()

void void SV_ClientPrintf ( client_t cl,
int  level,
const char *  fmt,
  ... 
)

Referenced by SV_PlayerPrintf().

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

◆ SV_DropClient()

◆ SV_ExecuteClientMessage()

◆ SV_GetBounceFraction()

float SV_GetBounceFraction ( const char *  texture)

Different terrain types might have different bounce fraction.

See also
Com_GetTerrainType
GenerateFootstepList

Definition at line 462 of file sv_world.cpp.

References terrainType_t::bounceFraction, and Com_GetTerrainType().

Referenced by SV_InitGameProgs().

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

Referenced by SV_Map(), and SV_Status_f().

◆ SV_GetConfigStringLength()

◆ SV_GetFootstepSound()

const char * SV_GetFootstepSound ( const char *  texture)

Query the footstep sound for the given surface texture.

See also
Com_GetTerrainType
GenerateFootstepList
Returns
either nullptr or the footstep sound filename if there is one assigned in the scripts

Definition at line 451 of file sv_world.cpp.

References Com_GetTerrainType(), and terrainType_t::footstepSound.

Referenced by SV_InitGameProgs(), and TEST_F().

◆ SV_GetNextClient()

client_t * SV_GetNextClient ( client_t lastClient)

◆ SV_GetServerState()

server_state_t SV_GetServerState ( void  )

Definition at line 312 of file sv_user.cpp.

References serverInstanceGame_t::state, and sv.

Referenced by Com_ServerState().

◆ SV_Heartbeat_f()

void SV_Heartbeat_f ( void  )

Definition at line 35 of file sv_ccmds.cpp.

References serverInstanceStatic_t::lastHeartbeat, and svs.

Referenced by SV_InitGame(), SV_InitOperatorCommands(), and SV_SetMaster_f().

◆ SV_InitGameProgs()

void SV_InitGameProgs ( void  )

Init the game subsystem for a new map.

See also
SV_ShutdownGameProgs

Definition at line 769 of file sv_game.cpp.

References game_export_t::apiversion, Cbuf_AddText(), Cmd_Argc(), Cmd_Args(), Cmd_Argv(), Com_CreateThread(), Com_Error(), Com_GetCharacterValues(), Com_GetConstInt(), Com_GetConstIntFromNamespace(), Com_GetConstVariable(), Com_GrenadeTarget(), Com_Printf(), Com_RegisterConstInt(), Com_UnregisterConstVariable(), csi, Cvar_Get(), Cvar_GetString(), Cvar_Set(), ERR_DROP, FS_FreeFile(), FS_Gamedir(), FS_LoadFile(), GAME_API_VERSION, serverInstanceStatic_t::gameFrameCond, serverInstanceGame_t::gameSysPool, gameSysPoolName, serverInstanceStatic_t::gameThread, serverInstanceStatic_t::ge, Grid_GetTUsForDirection(), Grid_MoveLength(), Grid_MoveNext(), Grid_MoveStore(), Grid_ShouldUseAutostand(), cvar_t::integer, Mem_CreatePool, sv, SV_AbortEvents(), SV_AddEvent(), SV_BroadcastPrintf(), SV_CanActorStandHere(), SV_Configstring(), SV_dprintf(), SV_EndEvents(), SV_error(), SV_FreeTags(), SV_GetBounceFraction(), SV_GetEvent(), SV_GetEventEdict(), SV_GetFootstepSound(), SV_GetGameAPI(), SV_GetInlineModelAABB(), SV_GetVisibility(), SV_GridCalcPathing(), SV_GridFall(), SV_GridFindPath(), SV_GridIsOnMap(), SV_GridPosToVec(), SV_LinkEdict(), SV_LoadModelAABB(), SV_MemFree(), SV_ModelIndex(), SV_PlayerPrintf(), SV_PointContents(), SV_QueueEvent(), SV_QueueWriteByte(), SV_QueueWritePos(), SV_QueueWriteShort(), SV_QueueWriteString(), SV_ReadAngle(), SV_ReadByte(), SV_ReadChar(), SV_ReadData(), SV_ReadDir(), SV_ReadFormat(), SV_ReadGPos(), SV_ReadLong(), SV_ReadPos(), SV_ReadShort(), SV_ReadString(), SV_RecalcRouting(), SV_RunGameFrameThread(), SV_SetInlineModelOrientation(), SV_SetModel(), SV_TagAlloc(), SV_TestLine(), SV_TestLineWithEnt(), sv_threads, SV_Trace(), SV_UnlinkEdict(), SV_WriteAngle(), SV_WriteByte(), SV_WriteChar(), SV_WriteDir(), SV_WriteFormat(), SV_WriteGPos(), SV_WriteLong(), SV_WritePos(), SV_WriteShort(), SV_WriteString(), svs, Sys_Fopen(), and Sys_Milliseconds().

Referenced by SV_InitGame(), and TEST_F().

◆ SV_InitOperatorCommands()

◆ SV_LinkEdict()

◆ SV_LoadModelAABB()

bool SV_LoadModelAABB ( const char *  model,
int  frame,
AABB aabb 
)

Load the bounding box for the model on the serverside for pathfinding and clipping.

Parameters
[in]modelThe relative model path to load the bounding box for
[in]frameThe frame to load the bounding box for
[out]aabbThe bounding box of the model - this is absolute to the worldorigin (0,0,0)

Definition at line 543 of file sv_world.cpp.

References sv_model_t::aabb, Com_Error(), com_genericPool, Com_GetExtension(), Com_sprintf(), ERR_DROP, sv_model_t::frame, FS_FreeFile(), FS_LoadFile(), i, IDALIASHEADER, IDMD3HEADER, LittleLong, MAX_MOD_KNOWN, MAX_QPATH, Mem_PoolStrDup, mod_extensions, sv_model_t::name, serverInstanceGame_t::numSVModels, OBJZERO, Q_strcasecmp, Q_streq, AABB::reset(), AABB::set(), AABB::setNegativeVolume(), sv, SV_ModLoadAliasMD2Model(), SV_ModLoadAliasMD3Model(), SV_ModLoadObjModel(), and serverInstanceGame_t::svModels.

Referenced by SV_InitGameProgs().

◆ SV_Map()

void SV_Map ( bool  day,
const char *  levelstring,
const char *  assembly,
bool  verbose 
)

◆ SV_MapcycleClear()

void SV_MapcycleClear ( void  )

Empty the mapcycle list.

See also
SV_MapcycleAdd

Definition at line 137 of file sv_mapcycle.cpp.

References i, mapcycle_t::map, mapcycleCount, mapcycleList, Mem_Free, mapcycle_t::next, and mapcycle_t::type.

Referenced by SV_Clear(), and SV_MapcycleInit().

◆ SV_MapcycleInit()

void SV_MapcycleInit ( void  )

◆ SV_Multicast()

void SV_Multicast ( int  mask,
const dbuffer msg 
)

Sends the contents of msg to a subset of the clients, then frees msg.

Parameters
[in]maskBitmask of the players to send the multicast to
[in,out]msgThe message to send to the clients

Definition at line 126 of file sv_send.cpp.

References cl, cs_connected, NET_WriteConstMsg(), and SV_GetNextClient().

Referenced by SV_Configstring(), SV_EndEvents(), SV_FindIndex(), and SV_SendQueuedEvents().

◆ SV_NextMapcycle()

◆ SV_PointContents()

int SV_PointContents ( const vec3_t  p)

Returns the content flags for a given point.

Note
Useful to determine whether an actor is e.g. inside of a water brush
See also
CM_TestInLeaf
CM_TestBoxInBrush
CM_CompleteBoxTrace

Definition at line 395 of file sv_world.cpp.

References CM_CompleteBoxTrace(), trace_t::contentFlags, AABB::EMPTY, trace_t::fraction, serverInstanceGame_t::mapTiles, MASK_ALL, sv, and TRACE_ALL_LEVELS.

Referenced by SV_InitGameProgs().

◆ SV_ReadPacket()

void SV_ReadPacket ( struct net_stream s)

◆ SV_RunGameFrame()

void SV_RunGameFrame ( void  )

Calls the G_RunFrame function from game api let everything in the world think and move.

See also
G_RunFrame
SV_Frame

Definition at line 758 of file sv_game.cpp.

References serverInstanceGame_t::endgame, serverInstanceStatic_t::ge, ss_game_shutdown, serverInstanceGame_t::state, sv, and svs.

Referenced by SV_Frame(), and SV_RunGameFrameThread().

◆ SV_RunGameFrameThread()

int SV_RunGameFrameThread ( void data)

Thread for the game frame function.

See also
SV_RunGameFrame
SV_Frame

Definition at line 741 of file sv_game.cpp.

References serverInstanceGame_t::endgame, serverInstanceStatic_t::gameFrameCond, serverInstanceStatic_t::serverMutex, sv, SV_RunGameFrame(), and svs.

Referenced by SV_InitGameProgs().

◆ SV_SetClientState()

void SV_SetClientState ( client_t client,
client_state_t  state 
)

Set the client state.

See also
client_state_t

Definition at line 36 of file sv_user.cpp.

References Com_DPrintf(), DEBUG_SERVER, client_t::name, and client_t::state.

Referenced by SV_Begin_f(), SV_DropClient(), SV_ExecuteClientMessage(), SV_Map(), SV_New_f(), and SVC_DirectConnect().

◆ SV_SetConfigString()

◆ SV_SetMaster_f()

void SV_SetMaster_f ( void  )

Add the server to the master server list so that others can see the server in the server list.

See also
SV_InitGame

Definition at line 45 of file sv_ccmds.cpp.

References Com_Printf(), Cvar_Set(), HTTP_GetURL(), cvar_t::integer, masterserver_url, port, cvar_t::string, sv_dedicated, SV_Heartbeat_f(), sv_maxclients, and va().

Referenced by SV_InitGame(), and SV_InitOperatorCommands().

◆ SV_SetServerState()

void SV_SetServerState ( server_state_t  state)

Definition at line 317 of file sv_user.cpp.

References serverInstanceGame_t::state, and sv.

◆ SV_ShutdownGameProgs()

◆ SV_Trace()

trace_t SV_Trace ( const Line traceLine,
const AABB box,
const edict_t passedict,
int  contentmask 
)

Moves the given mins/maxs volume through the world from start to end.

Note
Passedict and edicts owned by passedict are explicitly not checked.
See also
SV_TraceBounds
CL_Trace
Parameters
[in]traceLineThe from/to position in the world for this trace
[in]boxThe bounding box that is moved through the world
[in]passedictis explicitly excluded from clipping checks (normally nullptr) if the entire move stays in a solid volume, trace.allsolid will be set, trace.startsolid will be set, and trace.fraction will be 0 if the starting point is in a solid, it will be allowed to move out to an open area
[in]contentmaskbrushes the trace should stop at (see MASK_*)
Todo:
There is more than one world in case of a map assembly - use clip.trace.mapTile to get the correct one

Definition at line 417 of file sv_world.cpp.

References MoveClip::calcBounds(), CM_CompleteBoxTrace(), MoveClip::contentmask, trace_t::entNum, trace_t::fraction, serverInstanceGame_t::mapTiles, MoveClip::moveLine, MoveClip::objBox, OBJZERO, MoveClipSV::passedict, AABB::set(), Line::set(), sv, SV_ClipMoveToEntities(), MoveClipSV::trace, and TRACE_ALL_LEVELS.

Referenced by SV_InitGameProgs(), and TEST_F().

◆ SV_UnlinkEdict()

void SV_UnlinkEdict ( edict_t ent)

call before removing an entity, and before trying to move one, so it doesn't clip against itself

Definition at line 97 of file sv_world.cpp.

References Com_Printf(), worldSector_t::entities, sv_edict_t::linked, sv_edict_t::nextEntityInWorldSector, SV_GetServerDataForEdict(), and sv_edict_t::worldSector.

Referenced by SV_InitGameProgs(), and SV_LinkEdict().

◆ 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, and svs.

Referenced by SV_ExecuteClientMessage(), and SVC_DirectConnect().

Variable Documentation

◆ sv

server data per game/map

Definition at line 36 of file sv_init.cpp.

Referenced by Com_SetServerState(), GameTest::SetUp(), SV_AbortEvents(), SV_AddEvent(), SV_AreaEdicts(), SV_CanActorStandHere(), SV_CheckSpawnSoldiers(), SV_CheckStartMatch(), SV_ClearWorld(), SV_ClipMoveToEntities(), SV_CreateWorldSector(), SV_EndEvents(), SV_ExecuteClientMessage(), SV_Frame(), SV_FreeTags(), SV_GetConfigString(), SV_GetEvent(), SV_GetEventEdict(), SV_GetInlineModelAABB(), SV_GetMapData(), SV_GetMapTiles(), SV_GetServerDataForEdict(), SV_GetServerState(), SV_GetVisibility(), SV_GridCalcPathing(), SV_GridFall(), SV_GridFindPath(), SV_GridIsOnMap(), SV_GridPosToVec(), SV_HullForEntity(), SV_Init(), SV_InitGameProgs(), SV_LinkEdict(), SV_LoadModelAABB(), SV_Map(), SV_NextMapcycle(), SV_PointContents(), SV_QueueEvent(), SV_QueueWriteByte(), SV_QueueWritePos(), SV_QueueWriteShort(), SV_QueueWriteString(), SV_ReadAngle(), SV_ReadByte(), SV_ReadChar(), SV_ReadData(), SV_ReadDir(), SV_ReadFormat(), SV_ReadGPos(), SV_ReadLong(), SV_ReadPos(), SV_ReadShort(), SV_ReadString(), SV_RecalcRouting(), SV_RunGameFrame(), SV_RunGameFrameThread(), SV_SendQueuedEvents(), SV_SetConfigString(), SV_SetInlineModelOrientation(), SV_SetModel(), SV_SetServerState(), SV_Shutdown(), SV_ShutdownGameProgs(), SV_Status_f(), SV_TagAlloc(), SV_TestLine(), SV_TestLineWithEnt(), SV_Trace(), SV_WriteAngle(), SV_WriteByte(), SV_WriteChar(), SV_WriteDir(), SV_WriteFormat(), SV_WriteGPos(), SV_WriteLong(), SV_WritePos(), SV_WriteShort(), SV_WriteString(), SVC_DirectConnect(), SVC_Info(), TEST_F(), and TexinfoForBrushTexture().

◆ sv_dumpmapassembly

◆ sv_genericPool

◆ sv_mapname

cvar_t* sv_mapname
extern

Definition at line 53 of file sv_main.cpp.

Referenced by SV_Map(), and SV_Shutdown().

◆ sv_public

cvar_t* sv_public
extern

should heartbeats be sent? (only for public servers)

should heartbeats be sent

Definition at line 52 of file sv_main.cpp.

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

◆ sv_rma

cvar_t* sv_rma
extern

◆ sv_rmadisplaythemap

cvar_t* sv_rmadisplaythemap
extern

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

cvar_t* sv_threads
extern

◆ svs