UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
server.h
Go to the documentation of this file.
1 
6 /*
7 All original material Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 Original file from Quake 2 v3.21: quake2-2.31/server/server.h
10 Copyright (C) 1997-2001 Id Software, Inc.
11 
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
16 
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 
21 See the GNU General Public License for more details.
22 
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 
27 */
28 
29 #pragma once
30 
31 #include "../common/common.h"
32 #include "../common/http.h"
33 #include "../shared/infostring.h"
34 #include "../game/game.h"
35 #include <SDL_thread.h>
36 
38 
39 typedef struct sv_edict_s {
42  bool linked;
44 } sv_edict_t;
45 
47 typedef struct sv_model_s {
49  int frame;
50  char* name;
51 } sv_model_t;
52 
57 typedef struct worldSector_s {
58  int axis;
59  float dist;
60  struct worldSector_s* children[2];
63 
64 #define AREA_NODES 32
65 
66 typedef struct pending_event_s {
68  bool pending;
71  int type;
72  int entnum;
75 
76 typedef struct serverInstanceStatic_s {
77  bool initialized;
78  int realtime;
80  struct client_s* clients;
83  int lastPing;
84  bool abandon;
85  bool killserver;
86  SDL_mutex* serverMutex;
87  SDL_cond* gameFrameCond;
88  SDL_Thread* gameThread;
89 #ifndef HARD_LINKED_GAME
90  void* gameLibrary;
91 #endif
94 
95 typedef enum server_state_e {
102 
106 typedef struct serverInstanceGame_s {
109  char name[MAX_QPATH];
112 
113  bool endgame;
114  bool spawned;
115  bool started;
118 
123 
125 
127 
129  unsigned int numSVModels;
132  unsigned int numWorldSectors;
133 
136 
137 #define PLAYER_NUM(n) ((player_t*)((byte*)svs.ge->players + svs.ge->player_size * (n)))
138 
139 typedef enum {
147 
155 typedef struct client_s {
159  char name[32];
162  char peername[256];
164 } client_t;
165 
167 extern serverInstanceGame_t* sv;
169 extern cvar_t* sv_mapname;
170 extern cvar_t* sv_rma;
173 extern cvar_t* sv_public;
174 extern cvar_t* sv_dumpmapassembly;
175 extern cvar_t* sv_threads;
177 /* sv_main.c */
178 void SV_DropClient(client_t* drop, const char* message);
179 int SV_CountPlayers(void);
180 void SV_InitOperatorCommands(void);
182 void SV_ReadPacket(struct net_stream* s);
183 char* SV_GetConfigString(int index);
186 char* SV_SetConfigString(int index, ...);
187 /* ensure that always two parameters are used */
188 #define SV_SetConfigString(index, value) SV_SetConfigString(index, value)
189 client_t* SV_GetNextClient(client_t* lastClient);
191 
192 /* sv_mapcycle.c */
193 void SV_MapcycleInit(void);
194 void SV_NextMapcycle(void);
195 void SV_MapcycleClear(void);
196 
197 /* sv_init.c */
198 void SV_Map(bool day, const char* levelstring, const char* assembly, bool verbose = true);
199 
200 void SV_Multicast(int mask, const dbuffer& msg);
201 void SV_ClientCommand(client_t* client, const char* fmt, ...) __attribute__((format(__printf__,2,3)));
202 void SV_ClientPrintf(client_t* cl, int level, const char* fmt, ...) __attribute__((format(__printf__,3,4)));
203 void SV_BroadcastPrintf(int level, const char* fmt, ...) __attribute__((format(__printf__,2,3)));
204 
205 /* sv_user.c */
206 void SV_ExecuteClientMessage(client_t* cl, int cmd, dbuffer* msg);
207 void SV_SetClientState(client_t* client, client_state_t state);
208 
209 /* sv_ccmds.c */
210 void SV_SetMaster_f(void);
211 void SV_Heartbeat_f(void);
212 bool SV_CheckMap(const char* map, const char* assembly);
213 
214 /* sv_game.c */
215 int SV_RunGameFrameThread(void* data);
216 void SV_RunGameFrame(void);
217 void SV_InitGameProgs(void);
218 void SV_ShutdownGameProgs(void);
219 
220 /*============================================================ */
221 
222 void SV_ClearWorld(void);
223 
224 void SV_UnlinkEdict(edict_t* ent);
225 void SV_LinkEdict(edict_t* ent);
226 
227 /*=================================================================== */
228 
229 /* returns the CONTENTS_* value from the world at the given point. */
230 int SV_PointContents(const vec3_t p);
231 const char* SV_GetFootstepSound(const char* texture);
232 float SV_GetBounceFraction(const char* texture);
233 bool SV_LoadModelAABB(const char* model, int frame, AABB& aabb);
234 trace_t SV_Trace(const Line& traceLine, const AABB& box, const edict_t* passedict, int contentmask);
sv_model_t svModels[MAX_MOD_KNOWN]
Definition: server.h:128
pending_event_t eventQueue[64]
Definition: server.h:121
edict_t * ent
Definition: server.h:43
Definition: server.h:99
void void void SV_BroadcastPrintf(int level, const char *fmt,...) __attribute__((format(__printf__
char peername[256]
Definition: server.h:162
server_state_t SV_GetServerState(void)
Definition: sv_user.cpp:312
char * SV_GetConfigString(int index)
Definition: sv_main.cpp:77
SDL_mutex * serverMutex
Definition: server.h:86
int frame
Definition: server.h:49
float dist
Definition: server.h:59
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition: cvar.h:71
struct worldSector_s * worldSector
Definition: server.h:40
Definition: game.h:45
int messagelevel
Definition: server.h:160
bool linked
Definition: server.h:42
Definition: aabb.h:42
char userinfo[MAX_INFO_STRING]
Definition: server.h:157
enum server_state_e server_state_t
memPool_t * sv_genericPool
Definition: sv_main.cpp:55
client_state_t
Definition: server.h:139
void SV_SetMaster_f(void)
Add the server to the master server list so that others can see the server in the server list...
Definition: sv_ccmds.cpp:45
cvar_t * sv_rma
Definition: sv_main.cpp:49
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.
Definition: sv_init.cpp:113
int SV_CountPlayers(void)
Returns the number of spawned players.
Definition: sv_main.cpp:1096
player_t * player
Definition: server.h:158
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: sv_world.cpp:97
client_t * SV_GetNextClient(client_t *lastClient)
Iterates through clients.
Definition: sv_main.cpp:152
struct cBspModel_s * models[MAX_MODELS]
Definition: server.h:111
void SV_SetClientState(client_t *client, client_state_t state)
Set the client state.
Definition: sv_user.cpp:36
sv_edict_t * entities
Definition: server.h:61
void SV_MapcycleClear(void)
Empty the mapcycle list.
bool SV_LoadModelAABB(const char *model, int frame, AABB &aabb)
Load the bounding box for the model on the serverside for pathfinding and clipping.
Definition: sv_world.cpp:543
cvar_t * sv_mapname
Definition: sv_main.cpp:53
#define __attribute__(x)
Definition: cxx.h:37
void SV_LinkEdict(edict_t *ent)
Needs to be called any time an entity changes origin, mins, maxs, or solid. Automatically unlinks if ...
Definition: sv_world.cpp:131
void SV_InitOperatorCommands(void)
Definition: sv_ccmds.cpp:542
int lastmessage
Definition: server.h:161
dbuffer * buf
Definition: server.h:73
client_t * SV_GetClient(int index)
Definition: sv_main.cpp:174
Struct that is only valid for one map. It's deleted on every map load.
Definition: server.h:106
void SV_Multicast(int mask, const dbuffer &msg)
Sends the contents of msg to a subset of the clients, then frees msg.
Definition: sv_send.cpp:126
serverInstanceGame_t * sv
Definition: sv_init.cpp:36
pending_event_t pendingEvent
Definition: server.h:120
#define SV_SetConfigString(index, value)
Definition: server.h:188
functions exported by the game subsystem
Definition: game.h:317
unsigned int numSVModels
Definition: server.h:129
#define MAX_INFO_STRING
Definition: infostring.h:36
#define AREA_NODES
Definition: server.h:64
#define MAX_MOD_KNOWN
Definition: defines.h:160
cvar_t * sv_threads
Definition: sv_main.cpp:48
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: sv_main.cpp:184
struct pending_event_s pending_event_t
Definition: server.h:96
struct worldSector_s * children[2]
Definition: server.h:60
bool pending
Definition: server.h:68
void SV_MapcycleInit(void)
char * name
Definition: server.h:50
int SV_RunGameFrameThread(void *data)
Thread for the game frame function.
Definition: sv_game.cpp:741
struct worldSector_s worldSector_t
To avoid linearly searching through lists of entities during environment testing, the world is carved...
clientBattleScape_t cl
char assembly[MAX_QPATH]
Definition: server.h:110
mapData_t mapData
Definition: server.h:124
server_state_t state
Definition: server.h:107
void SV_RunGameFrame(void)
Calls the G_RunFrame function from game api let everything in the world think and move...
Definition: sv_game.cpp:758
#define MAX_TOKEN_CHARS
Definition: defines.h:372
Definition: line.h:31
#define MAX_CONFIGSTRINGS
Definition: q_shared.h:330
bool SV_CheckMap(const char *map, const char *assembly)
Checks whether a map exists.
Definition: sv_ccmds.cpp:101
struct sv_edict_s * nextEntityInWorldSector
Definition: server.h:41
int SV_PointContents(const vec3_t p)
Returns the content flags for a given point.
Definition: sv_world.cpp:395
char name[32]
Definition: server.h:159
QGL_EXTERN GLuint index
Definition: r_gl.h:110
#define MAX_MODELS
Definition: defines.h:100
char name[MAX_QPATH]
Definition: server.h:109
void SV_ClearWorld(void)
Clear physics interaction links.
Definition: sv_world.cpp:81
int axis
Definition: server.h:58
mapTiles_t mapTiles
Definition: server.h:126
struct sv_model_s sv_model_t
static mesh models (none-animated) can have a server side flag set to be clipped for pathfinding ...
void SV_Heartbeat_f(void)
Definition: sv_ccmds.cpp:35
void SV_SetServerState(server_state_t)
Definition: sv_user.cpp:317
void SV_ClientCommand(client_t *client, const char *fmt,...) __attribute__((format(__printf__
cvar_t * sv_public
Definition: sv_main.cpp:52
#define MAX_QPATH
Definition: filesys.h:40
float SV_GetBounceFraction(const char *texture)
Different terrain types might have different bounce fraction.
Definition: sv_world.cpp:462
struct net_stream * stream
Definition: server.h:163
struct client_s * clients
Definition: server.h:80
struct sv_edict_s sv_edict_t
cvar_t * sv_rmadisplaythemap
display a character graphic of the tiles placed when RMA2 reaches a dead end.
Definition: sv_main.cpp:50
void SV_InitGameProgs(void)
Init the game subsystem for a new map.
Definition: sv_game.cpp:769
sv_edict_t edicts[MAX_EDICTS]
Definition: server.h:130
AABB aabb
Definition: server.h:48
unsigned int numWorldSectors
Definition: server.h:132
To avoid linearly searching through lists of entities during environment testing, the world is carved...
Definition: server.h:57
vec_t vec3_t[3]
Definition: ufotypes.h:39
struct serverInstanceGame_s serverInstanceGame_t
Struct that is only valid for one map. It's deleted on every map load.
const char * SV_GetFootstepSound(const char *texture)
Query the footstep sound for the given surface texture.
Definition: sv_world.cpp:451
server_state_e
Definition: server.h:95
void void SV_ClientPrintf(client_t *cl, int level, const char *fmt,...) __attribute__((format(__printf__
worldSector_t worldSectors[AREA_NODES]
Definition: server.h:131
client_state_t state
Definition: server.h:156
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.
Definition: sv_world.cpp:417
dbuffer * messageBuffer
Definition: server.h:119
void void void void SV_ExecuteClientMessage(client_t *cl, int cmd, dbuffer *msg)
The current net_message is parsed for the given client.
Definition: sv_user.cpp:235
GLsizei const GLvoid * data
Definition: r_gl.h:152
struct serverInstanceStatic_s serverInstanceStatic_t
void SV_ReadPacket(struct net_stream *s)
Definition: sv_main.cpp:669
char configstrings[MAX_CONFIGSTRINGS][MAX_TOKEN_CHARS]
Definition: server.h:117
void SV_NextMapcycle(void)
Start the next map in the cycle.
Definition: sv_mapcycle.cpp:20
void SV_ShutdownGameProgs(void)
Called when either the entire server is being killed, or it is changing to a different game directory...
Definition: sv_game.cpp:703
static mesh models (none-animated) can have a server side flag set to be clipped for pathfinding ...
Definition: server.h:47
int SV_GetConfigStringLength(int index)
Definition: sv_main.cpp:85
struct client_s client_t
cvar_t * sv_dumpmapassembly
Definition: sv_main.cpp:47
serverInstanceStatic_t svs
Definition: sv_init.cpp:35
SDL_Thread * gameThread
Definition: server.h:88
void SV_UserinfoChanged(client_t *cl)
Pull specific info from a newly changed userinfo string into a more C friendly form.
Definition: sv_main.cpp:921
memPool_t * gameSysPool
Definition: server.h:134
int SV_GetConfigStringInteger(int index)
Definition: sv_main.cpp:108
void format(__printf__, 1, 2)))
level_locals_t level
Definition: g_main.cpp:38
SDL_cond * gameFrameCond
Definition: server.h:87
struct datagram_socket * netDatagramSocket
Definition: server.h:79
#define MAX_EDICTS
Definition: defines.h:99
game_export_t * ge
Definition: server.h:92
int playerMask
Definition: server.h:70