server.h File Reference

Main server include file. More...

#include "../common/common.h"
#include "../shared/infostring.h"
#include "../game/game.h"
#include <SDL_thread.h>
#include "../game/game.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_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_t
struct  serverInstanceGame_t
 Struct that is only valid for one map. It's deleted on every map load. More...
struct  client_s

Defines

#define AREA_NODES   32
#define EDICT_NUM(n)   ((edict_t *)((byte *)svs.ge->edicts + svs.ge->edict_size * (n)))
#define NUM_FOR_EDICT(e)   (((byte *)(e) - (byte *)svs.ge->edicts) / svs.ge->edict_size)
#define PLAYER_NUM(n)   ((player_t *)((byte *)svs.ge->players + svs.ge->player_size * (n)))
#define NUM_FOR_PLAYER(e)   (((byte *)(e) - (byte *)svs.ge->players) / svs.ge->player_size)
#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
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.
typedef struct pending_event_s pending_event_t
typedef struct client_s client_t

Enumerations

enum  server_state_t { ss_dead, ss_restart, ss_loading, ss_game }
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_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 (qboolean day, const char *levelstring, const char *assembly)
 Change the server to a new map, taking all connected clients along with it.
void SV_Multicast (int mask, struct dbuffer *msg)
 Sends the contents of msg to a subset of the clients, then frees msg.
void SV_StartSound (int mask, const vec3_t origin, const edict_t *entity, const char *sound)
 If origin is NULL, the origin is determined from the entity origin or the midpoint of the entity box for bmodels.
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, struct dbuffer *msg)
 The current net_message is parsed for the given client.
void SV_SetClientState (client_t *client, int state)
 Set the client state.
void SV_SetMaster_f (void)
 Specify a list of master servers.
void SV_Heartbeat_f (void)
qboolean 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->absmax.
int SV_AreaEdicts (const vec3_t mins, const vec3_t maxs, edict_t **list, int maxcount)
int SV_TouchEdicts (const vec3_t mins, const vec3_t maxs, edict_t **list, int maxCount, edict_t *skip)
 Fills a list with edicts that are in use and are touching the given bounding box.
int SV_PointContents (vec3_t p)
 Returns the content flags for a given point.
const char * SV_GetFootstepSound (const char *texture)
float SV_GetBounceFraction (const char *texture)
 Different terrain types might have different bounce fraction.
qboolean SV_LoadModelMinsMaxs (const char *model, int frame, vec3_t mins, vec3_t maxs)
 Load the mins, maxs for the model on the serverside for pathfinding and clipping.
trace_t SV_Trace (const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, const edict_t *passedict, int contentmask)
 Moves the given mins/maxs volume through the world from start to end.

Variables

memPool_tsv_genericPool
serverInstanceStatic_t svs
serverInstanceGame_t sv
cvar_tsv_mapname
cvar_tsv_public
cvar_tsv_dumpmapassembly
cvar_tsv_threads

Detailed Description

Main server include file.

Definition in file server.h.


Define Documentation

#define AREA_NODES   32

Definition at line 64 of file server.h.

#define EDICT_NUM (  )     ((edict_t *)((byte *)svs.ge->edicts + svs.ge->edict_size * (n)))

Definition at line 128 of file server.h.

Referenced by SV_TouchEdicts().

#define NUM_FOR_EDICT (  )     (((byte *)(e) - (byte *)svs.ge->edicts) / svs.ge->edict_size)

Definition at line 129 of file server.h.

#define NUM_FOR_PLAYER (  )     (((byte *)(e) - (byte *)svs.ge->players) / svs.ge->player_size)

Definition at line 132 of file server.h.

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

Definition at line 131 of file server.h.

Referenced by SVC_DirectConnect().

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

Definition at line 179 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
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 134 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

Definition at line 90 of file server.h.


Function Documentation

int SV_AreaEdicts ( const vec3_t  mins,
const vec3_t  maxs,
edict_t **  list,
int  maxCount 
)
See also:
SV_AreaEdicts_r
Parameters:
[in] mins The mins of the bounding box
[in] maxs The maxs of the bounding box
[out] list The edict list that this trace is hitting
[in] maxCount The size of the given list
Returns:
the number of pointers filled in

Definition at line 313 of file sv_world.c.

References areaParms_t::areaEdictList, areaParms_t::areaEdictListCount, areaParms_t::areaEdictListMaxCount, areaParms_t::areaMaxs, areaParms_t::areaMins, sv, SV_AreaEdicts_r(), and serverInstanceGame_t::worldSectors.

Referenced by SV_ClipMoveToEntities(), and SV_InitGameProgs().

void void void SV_BroadcastPrintf ( int  level,
const char *  fmt,
  ... 
)
qboolean SV_CheckMap ( const char *  map,
const char *  assembly 
)

Checks whether a map exists.

Definition at line 105 of file sv_ccmds.c.

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

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 87 of file sv_world.c.

References serverInstanceGame_t::mapData, mapData_s::mapMax, mapData_s::mapMin, sv, and SV_CreateWorldSector().

Referenced by SV_Map().

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

Referenced by SV_CheckGameStart(), and SV_New_f().

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 851 of file sv_main.c.

References cl, count, cs_spawned, serverInstanceStatic_t::initialized, client_s::state, SV_GetNextClient(), and svs.

void SV_DropClient ( client_t drop,
const char *  message 
)
void void void void SV_ExecuteClientMessage ( client_t cl,
int  cmd,
struct dbuffer msg 
)
float SV_GetBounceFraction ( const char *  texture  ) 

Different terrain types might have different bounce fraction.

See also:
Com_GetTerrainType
GenerateFootstepList

Definition at line 604 of file sv_world.c.

References terrainType_s::bounceFraction, and Com_GetTerrainType().

Referenced by SV_InitGameProgs().

client_t* SV_GetClient ( int  index  ) 

Definition at line 126 of file sv_main.c.

References serverInstanceStatic_t::clients, and svs.

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

char* SV_GetConfigString ( int  index  ) 
int SV_GetConfigStringInteger ( int  index  ) 

Definition at line 58 of file sv_main.c.

References Com_Error(), serverInstanceGame_t::configstrings, ERR_FATAL, MAX_CONFIGSTRINGS, and sv.

Referenced by SV_Map(), and SV_Status_f().

const char* SV_GetFootstepSound ( const char *  texture  ) 
client_t* SV_GetNextClient ( client_t lastClient  ) 

Iterates through clients.

Parameters:
[in] lastClient Pointer of the client to iterate from. call with NULL to get the first one.

Definition at line 104 of file sv_main.c.

References serverInstanceStatic_t::clients, cvar_s::integer, and svs.

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

void SV_Heartbeat_f ( void   ) 

Definition at line 33 of file sv_ccmds.c.

References serverInstanceStatic_t::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 563 of file sv_game.c.

References game_export_t::apiversion, Cbuf_AddText(), Cmd_Argc(), Cmd_Args(), Cmd_Argv(), Com_Error(), Com_GetCharacterValues(), Com_GetConstInt(), Com_GetConstIntFromNamespace(), Com_GetConstVariable(), Com_GrenadeTarget(), Com_RegisterConstInt(), Com_UnregisterConstVariable(), csi, Cvar_Get(), Cvar_GetString(), Cvar_Set(), ERR_DROP, FS_FreeFile(), FS_Gamedir(), FS_LoadFile(), GAME_API_VERSION, serverInstanceGame_t::gameSysPool, serverInstanceStatic_t::gameThread, serverInstanceStatic_t::ge, Grid_Fall(), Grid_Floor(), Grid_GetTUsForDirection(), Grid_MoveCalc(), Grid_MoveLength(), Grid_MoveNext(), Grid_MoveStore(), Grid_PosToVec(), cvar_s::integer, mapData_s::map, serverInstanceGame_t::mapData, Mem_CreatePool, sv, SV_AbortEvents(), SV_AddEvent(), SV_AreaEdicts(), SV_BroadcastPrintf(), SV_Configstring(), SV_dprintf(), SV_EndEvents(), SV_error(), SV_FreeTags(), SV_GetBounceFraction(), SV_GetEvent(), SV_GetFootstepSound(), SV_GetGameAPI(), SV_LinkEdict(), SV_LoadModelMinsMaxs(), SV_MemFree(), SV_ModelIndex(), SV_PlayerPrintf(), SV_PointContents(), 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_StartSound(), SV_TagAlloc(), SV_TestLine(), SV_TestLineWithEnt(), sv_threads, SV_TouchEdicts(), SV_Trace(), SV_UnlinkEdict(), SV_WriteAngle(), SV_WriteByte(), SV_WriteChar(), SV_WriteDir(), SV_WriteDummyByte(), SV_WriteFormat(), SV_WriteGPos(), SV_WriteLong(), SV_WritePos(), SV_WriteShort(), SV_WriteString(), svs, and Sys_Milliseconds().

Referenced by SV_InitGame().

void SV_InitOperatorCommands ( void   ) 
void SV_LinkEdict ( edict_t ent  ) 
qboolean SV_LoadModelMinsMaxs ( const char *  model,
int  frame,
vec3_t  mins,
vec3_t  maxs 
)

Load the mins, maxs for the model on the serverside for pathfinding and clipping.

Parameters:
[in] model The relative model path to load the mins, maxs for
[in] frame The frame to load the mins and maxs vectors for
[out] mins The mins vector of the model - this is absolute to the worldorigin (0,0,0)
[out] maxs The maxs vector of the model - this is absolute to the worldorigin (0,0,0)

Definition at line 708 of file sv_world.c.

References byte, ClearBounds(), Com_Error(), com_genericPool, DPMHEADER, ERR_DROP, sv_model_s::frame, FS_FreeFile(), FS_LoadFile(), i, IDALIASHEADER, IDMD3HEADER, LittleLong(), MAX_MOD_KNOWN, sv_model_s::maxs, Mem_PoolStrDup, sv_model_s::mins, sv_model_s::name, serverInstanceGame_t::numSVModels, Q_strcasecmp, qfalse, qtrue, sv, SV_ModLoadAliasDPMModel(), SV_ModLoadAliasMD2Model(), SV_ModLoadAliasMD3Model(), SV_ModLoadObjModel(), serverInstanceGame_t::svModels, vec3_origin, and VectorCopy.

Referenced by SV_InitGameProgs().

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

Empty the mapcycle list.

See also:
SV_MapcycleAdd

Definition at line 142 of file sv_mapcycle.c.

References i, mapcycle_s::map, mapcycleCount, 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,
struct dbuffer msg 
)

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

Parameters:
[in] mask Bitmask of the players to send the multicast to
[in,out] msg The message to send to the clients

Definition at line 130 of file sv_send.c.

References cl, cs_connected, free_dbuffer(), NET_WriteConstMsg(), client_s::state, client_s::stream, and SV_GetNextClient().

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

void SV_NextMapcycle ( void   ) 
int SV_PointContents ( 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 491 of file sv_world.c.

References CM_CompleteBoxTrace(), trace_s::contentFlags, trace_s::fraction, serverInstanceGame_t::mapTiles, MASK_ALL, sv, TRACING_ALL_VISIBLE_LEVELS, and vec3_origin.

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 550 of file sv_game.c.

References serverInstanceGame_t::endgame, serverInstanceStatic_t::ge, serverInstanceStatic_t::serverMutex, 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 535 of file sv_game.c.

References serverInstanceGame_t::endgame, sv, and SV_RunGameFrame().

Referenced by SV_InitGameProgs().

void SV_SetClientState ( client_t client,
int  state 
)

Set the client state.

See also:
client_state_t

Definition at line 35 of file sv_user.c.

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

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

char* SV_SetConfigString ( int  index,
  ... 
)
void SV_SetMaster_f ( void   ) 
void SV_ShutdownGameProgs ( void   ) 

Called when either the entire server is being killed, or it is changing to a different game directory.

See also:
G_Shutdown
SV_InitGameProgs

Definition at line 501 of file sv_game.c.

References Cmd_ExecuteString(), Com_Printf(), serverInstanceGame_t::gameSysPool, serverInstanceStatic_t::gameThread, serverInstanceStatic_t::ge, Mem_DeletePool, Mem_PoolSize, memPool_s::name, sv, SV_UnloadGame(), svs, and va().

Referenced by SV_Shutdown().

void SV_StartSound ( int  mask,
const vec3_t  origin,
const edict_t entity,
const char *  sound 
)

If origin is NULL, the origin is determined from the entity origin or the midpoint of the entity box for bmodels.

Definition at line 155 of file sv_send.c.

References edict_s::maxs, edict_s::mins, NET_WriteByte(), NET_WritePos(), NET_WriteString(), new_dbuffer(), edict_s::origin, edict_s::solid, SOLID_BSP, SV_Multicast(), svc_sound, VectorAdd, VectorCenterFromMinsMaxs(), and VectorCopy.

Referenced by SV_InitGameProgs().

int SV_TouchEdicts ( const vec3_t  mins,
const vec3_t  maxs,
edict_t **  list,
int  maxCount,
edict_t skip 
)

Fills a list with edicts that are in use and are touching the given bounding box.

Parameters:
[in] mins The mins of the bounding box
[in] maxs The maxs of the bounding box
[out] list The edict list that this trace is hitting
[in] maxCount The size of the given list
[in] skip An edict to skip (e.g. pointer to the calling edict)
Returns:
the number of pointers filled in

Definition at line 338 of file sv_world.c.

References EDICT_NUM, serverInstanceStatic_t::ge, i, game_export_t::num_edicts, edict_s::solid, SOLID_NOT, SV_BoundingBoxesIntersect(), and svs.

Referenced by SV_InitGameProgs().

trace_t SV_Trace ( const vec3_t  start,
const vec3_t  mins,
const vec3_t  maxs,
const vec3_t  end,
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] start The starting position in the world for this trace
[in] end The position in the world where this trace should stop
[in] passedict is explicitly excluded from clipping checks (normally NULL) 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] contentmask brushes the trace should stop at (see MASK_*)
[in] mins The mins of the bounding box that is moved through the world
[in] maxs The maxs of the bounding box that is moved through the world

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 546 of file sv_world.c.

References moveclip_t::boxmaxs, moveclip_t::boxmins, CM_CompleteBoxTrace(), Com_Printf(), moveclip_t::contentmask, game_export_t::edicts, moveclip_t::end, trace_s::ent, trace_s::fraction, serverInstanceStatic_t::ge, serverInstanceGame_t::mapTiles, moveclip_t::maxs, moveclip_t::mins, moveclip_t::passedict, moveclip_t::start, sv, SV_ClipMoveToEntities(), SV_TraceBounds(), svs, moveclip_t::trace, TRACING_ALL_VISIBLE_LEVELS, and vec3_origin.

Referenced by SV_InitGameProgs().

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 103 of file sv_world.c.

References edict_s::child, Com_Printf(), worldSector_s::entities, sv_edict_s::linked, sv_edict_s::nextEntityInWorldSector, qfalse, SV_GetServerDataForEdict(), SV_UnlinkEdict(), and sv_edict_s::worldSector.

Referenced by SV_InitGameProgs(), SV_LinkEdict(), and SV_UnlinkEdict().

void SV_UserinfoChanged ( client_t cl  ) 

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

Definition at line 667 of file sv_main.c.

References Com_DPrintf(), DEBUG_SERVER, serverInstanceStatic_t::ge, i, Info_ValueForKey(), client_s::messagelevel, client_s::name, client_s::player, serverInstanceStatic_t::serverMutex, svs, and client_s::userinfo.

Referenced by SV_ExecuteClientMessage(), and SVC_DirectConnect().


Variable Documentation

Definition at line 43 of file sv_main.c.

Referenced by SV_AssembleMap(), and SV_CalcRating().

Definition at line 49 of file sv_main.c.

Referenced by SV_InitGame(), and SV_MapcycleAdd().

Definition at line 47 of file sv_main.c.

Referenced by SV_Map().

should heartbeats be sent? (only for public servers)

should heartbeats be sent

Definition at line 46 of file sv_main.c.

Referenced by SV_InitGame().

run the game lib threaded

Definition at line 44 of file sv_main.c.

Referenced by SV_AddMapTiles(), SV_AssembleMap(), SV_InitGameProgs(), and SV_ParallelSearch().


Generated by  doxygen 1.6.2