UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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>

Go to the source code of this file.

Data Structures

struct  sv_edict_s
 
struct  sv_model_s
 static mesh models (none-animated) can have a server side flag set to be clipped for pathfinding More...
 
struct  worldSector_s
 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_s
 
struct  serverInstanceStatic_s
 
struct  serverInstanceGame_s
 Struct that is only valid for one map. It's deleted on every map load. More...
 
struct  client_s
 

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)
 

Typedefs

typedef struct sv_edict_s sv_edict_t
 
typedef struct sv_model_s sv_model_t
 static mesh models (none-animated) can have a server side flag set to be clipped for pathfinding More...
 
typedef struct worldSector_s 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...
 
typedef struct pending_event_s pending_event_t
 
typedef struct
serverInstanceStatic_s 
serverInstanceStatic_t
 
typedef enum server_state_e server_state_t
 
typedef struct serverInstanceGame_s serverInstanceGame_t
 Struct that is only valid for one map. It's deleted on every map load. More...
 
typedef struct client_s client_t
 

Enumerations

enum  server_state_e {
  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

#define AREA_NODES   32

Definition at line 64 of file server.h.

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

Definition at line 137 of file server.h.

Referenced by SVC_DirectConnect(), and TEST_F().

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

Definition at line 188 of file server.h.

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

Typedef Documentation

typedef struct client_s client_t

a client can leave the server in one of four ways:

  • dropping properly by quitting or disconnecting
  • timing out if no valid messages are received
  • getting kicked off by the server operator
  • a program error, like an overflowed reliable buffer

Struct that is only valid for one map. It's deleted on every map load.

typedef struct sv_edict_s sv_edict_t
typedef struct sv_model_s sv_model_t

static mesh models (none-animated) can have a server side flag set to be clipped for pathfinding

typedef struct worldSector_s 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.

Enumeration Type Documentation

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.

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

void void void SV_BroadcastPrintf ( int  level,
const char *  fmt,
  ... 
)
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().

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_s::mapBox, serverInstanceGame_s::mapData, sv, and SV_CreateWorldSector().

Referenced by SV_Map(), and TEST_F().

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

Referenced by SV_PlayerPrintf().

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_s::initialized, client_s::state, SV_GetNextClient(), and svs.

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_s::bounceFraction, and Com_GetTerrainType().

Referenced by SV_InitGameProgs().

client_t* SV_GetClient ( int  index)
int SV_GetConfigStringInteger ( int  index)

Definition at line 108 of file sv_main.cpp.

References SV_GetConfigString().

Referenced by SV_Map(), and SV_Status_f().

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_s::footstepSound.

Referenced by SV_InitGameProgs(), and TEST_F().

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 serverInstanceStatic_s::clients, cvar_s::integer, 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().

server_state_t SV_GetServerState ( void  )

Definition at line 312 of file sv_user.cpp.

References serverInstanceGame_s::state, and sv.

Referenced by Com_ServerState().

void SV_Heartbeat_f ( void  )

Definition at line 35 of file sv_ccmds.cpp.

References serverInstanceStatic_s::lastHeartbeat, and svs.

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

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_s::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_s::gameFrameCond, serverInstanceGame_s::gameSysPool, serverInstanceStatic_s::gameThread, serverInstanceStatic_s::ge, Grid_GetTUsForDirection(), Grid_MoveLength(), Grid_MoveNext(), Grid_MoveStore(), Grid_ShouldUseAutostand(), cvar_s::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().

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_s::aabb, Com_Error(), com_genericPool, Com_GetExtension(), Com_sprintf(), ERR_DROP, sv_model_s::frame, FS_FreeFile(), FS_LoadFile(), i, IDALIASHEADER, IDMD3HEADER, LittleLong, MAX_MOD_KNOWN, MAX_QPATH, Mem_PoolStrDup, mod_extensions, sv_model_s::name, serverInstanceGame_s::numSVModels, OBJZERO, Q_strcasecmp, Q_streq, AABB::reset(), AABB::set(), AABB::setNegativeVolume(), sv, SV_ModLoadAliasMD2Model(), SV_ModLoadAliasMD3Model(), SV_ModLoadObjModel(), and serverInstanceGame_s::svModels.

Referenced by SV_InitGameProgs().

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

Empty the mapcycle list.

See also
SV_MapcycleAdd

Definition at line 137 of file sv_mapcycle.cpp.

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

Referenced by SV_Clear(), and SV_MapcycleInit().

void SV_MapcycleInit ( void  )
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(), client_s::state, client_s::stream, and SV_GetNextClient().

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

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_s::contentFlags, AABB::EMPTY, trace_s::fraction, serverInstanceGame_s::mapTiles, MASK_ALL, sv, and TRACE_ALL_LEVELS.

Referenced by SV_InitGameProgs().

void SV_ReadPacket ( struct net_stream s)
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_s::endgame, serverInstanceStatic_s::ge, ss_game_shutdown, serverInstanceGame_s::state, sv, and svs.

Referenced by SV_Frame(), and 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_s::endgame, serverInstanceStatic_s::gameFrameCond, serverInstanceStatic_s::serverMutex, sv, SV_RunGameFrame(), and svs.

Referenced by SV_InitGameProgs().

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_s::name, and client_s::state.

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

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_s::integer, masterserver_url, port, cvar_s::string, sv_dedicated, SV_Heartbeat_f(), sv_maxclients, and va().

Referenced by SV_InitGame(), and SV_InitOperatorCommands().

void SV_SetServerState ( server_state_t  )

Definition at line 317 of file sv_user.cpp.

References serverInstanceGame_s::state, and sv.

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_s::entNum, trace_s::fraction, serverInstanceGame_s::mapTiles, MoveClip::moveLine, MoveClip::objBox, OBJZERO, MoveClipSV::passedict, Line::set(), AABB::set(), sv, SV_ClipMoveToEntities(), MoveClipSV::trace, and TRACE_ALL_LEVELS.

Referenced by SV_InitGameProgs(), and TEST_F().

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_s::entities, sv_edict_s::linked, sv_edict_s::nextEntityInWorldSector, SV_GetServerDataForEdict(), and sv_edict_s::worldSector.

Referenced by SV_InitGameProgs(), and SV_LinkEdict().

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 Com_DPrintf(), DEBUG_SERVER, serverInstanceStatic_s::ge, i, Info_IntegerForKey(), Info_ValueForKey(), client_s::messagelevel, client_s::name, client_s::player, Q_strncpyz(), serverInstanceStatic_s::serverMutex, svs, and client_s::userinfo.

Referenced by SV_ExecuteClientMessage(), and SVC_DirectConnect().

Variable Documentation

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

cvar_t* sv_mapname

Definition at line 53 of file sv_main.cpp.

Referenced by SV_Map().

cvar_t* sv_public

should heartbeats be sent? (only for public servers)

should heartbeats be sent

Definition at line 52 of file sv_main.cpp.

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

cvar_t* sv_rma
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(), and SV_AddMissingTiles_r().

cvar_t* sv_threads

run the game lib threaded

Definition at line 48 of file sv_main.cpp.

Referenced by RandomMapAssemblyTest::SetUpTestCase(), SV_AddMapTiles(), SV_DoMapAssemble(), SV_InitGameProgs(), SV_ParallelSearch(), and TEST_F().