UFO: Alien Invasion
Loading...
Searching...
No Matches
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)
#define 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.
int SV_CountPlayers (void)
 Returns the number of spawned players.
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.
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.
client_tSV_GetClient (int index)
void SV_MapcycleInit (void)
void SV_NextMapcycle (void)
 Start the next map in the cycle.
void SV_MapcycleClear (void)
 Empty the mapcycle list.
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.
void SV_Multicast (int mask, const dbuffer &msg)
 Sends the contents of msg to a subset of the clients, then frees msg.
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.
void SV_SetClientState (client_t *client, client_state_t state)
 Set the client state.
void SV_SetMaster_f (void)
 Add the server to the master server list so that others can see the server in the server list.
void SV_Heartbeat_f (void)
bool SV_CheckMap (const char *map, const char *assembly)
 Checks whether a map exists.
int SV_RunGameFrameThread (void *data)
 Thread for the game frame function.
void SV_RunGameFrame (void)
 Calls the G_RunFrame function from game api let everything in the world think and move.
void SV_InitGameProgs (void)
 Init the game subsystem for a new map.
void SV_ShutdownGameProgs (void)
 Called when either the entire server is being killed, or it is changing to a different game directory.
void SV_ClearWorld (void)
 Clear physics interaction links.
void SV_UnlinkEdict (edict_t *ent)
 call before removing an entity, and before trying to move one, so it doesn't clip against itself
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.
int SV_PointContents (const vec3_t p)
 Returns the content flags for a given point.
const char * SV_GetFootstepSound (const char *texture)
 Query the footstep sound for the given surface texture.
float SV_GetBounceFraction (const char *texture)
 Different terrain types might have different bounce fraction.
bool SV_LoadModelAABB (const char *model, int frame, AABB &aabb)
 Load the bounding box for the model on the serverside for pathfinding and clipping.
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.
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.
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)
Value:
((player_t*)((byte*)svs.ge->players + svs.ge->player_size * (n)))
SrvPlayer player_t
Definition game.h:72
serverInstanceStatic_t svs
Definition sv_init.cpp:35

Definition at line 137 of file server.h.

Referenced by SVC_DirectConnect(), and TEST_F().

◆ SV_SetConfigString

#define SV_SetConfigString ( index,
value )
Value:
QGL_EXTERN GLuint index
Definition r_gl.h:110
#define SV_SetConfigString(index, value)
Definition server.h:188

Definition at line 188 of file server.h.

Referenced by SV_Configstring(), SV_FindIndex(), and SV_Map().

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

◆ 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_BroadcastPrintf(), 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 sv, and SV_CreateWorldSector().

Referenced by SV_BroadcastPrintf(), 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,
... )

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

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_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_BroadcastPrintf(), and SV_InitGameProgs().

◆ 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_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_BroadcastPrintf(), SV_InitGameProgs(), and TEST_F().

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

server_state_t SV_GetServerState ( void )

Definition at line 312 of file sv_user.cpp.

References sv.

Referenced by Com_ServerState(), and SV_BroadcastPrintf().

◆ SV_Heartbeat_f()

void SV_Heartbeat_f ( void )

Definition at line 35 of file sv_ccmds.cpp.

References svs.

Referenced by SV_BroadcastPrintf(), 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 747 of file sv_game.cpp.

References 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, gameSysPoolName, Grid_GetTUsForDirection(), Grid_MoveLength(), Grid_MoveNext(), Grid_MoveStore(), Grid_ShouldUseAutostand(), 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_BroadcastPrintf(), 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, OBJZERO, Q_strcasecmp, Q_streq, AABB::reset(), AABB::set(), AABB::setNegativeVolume(), sv, SV_ModLoadAliasMD2Model(), SV_ModLoadAliasMD3Model(), and SV_ModLoadObjModel().

Referenced by SV_BroadcastPrintf(), and SV_InitGameProgs().

◆ SV_Map()

◆ 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, MASK_ALL, sv, and TRACE_ALL_LEVELS.

Referenced by SV_BroadcastPrintf(), and 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 736 of file sv_game.cpp.

References ss_game_shutdown, sv, and svs.

Referenced by SV_BroadcastPrintf(), 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 719 of file sv_game.cpp.

References data, sv, SV_RunGameFrame(), and svs.

Referenced by SV_BroadcastPrintf(), and SV_InitGameProgs().

◆ SV_SetClientState()

void SV_SetClientState ( client_t * client,
client_state_t state )

◆ 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(), masterserver_url, port, sv_dedicated, SV_Heartbeat_f(), sv_maxclients, and va().

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

◆ SV_SetServerState()

void SV_SetServerState ( server_state_t state)

Definition at line 317 of file sv_user.cpp.

References sv.

Referenced by SV_BroadcastPrintf().

◆ 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, MoveClip::moveLine, MoveClip::objBox, OBJZERO, MoveClipSV::passedict, AABB::set(), Line::set(), sv, SV_ClipMoveToEntities(), MoveClipSV::trace, and TRACE_ALL_LEVELS.

Referenced by SV_BroadcastPrintf(), 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_BroadcastPrintf(), 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, i, Info_IntegerForKey(), Info_ValueForKey(), Q_strncpyz(), 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(), 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(), MapDefMassRMATest::SetUpTestCase(), MapDefStatsTest::SetUpTestCase(), MapDefTest::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

◆ svs