svs.clients is now allocated dynamically according to svs.maxclients, and there is...
[divverent/darkplaces.git] / server.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // server.h
21
22 #ifndef SERVER_H
23 #define SERVER_H
24
25 typedef struct
26 {
27         int                     maxclients;
28         struct client_s *clients;               // [maxclients]
29         int                     serverflags;            // episode completion information
30         qboolean        changelevel_issued;     // cleared when at SV_SpawnServer
31 } server_static_t;
32
33 //=============================================================================
34
35 typedef enum {ss_loading, ss_active} server_state_t;
36
37 typedef struct
38 {
39         qboolean        active;                         // false if only a net client
40
41         qboolean        paused;
42         qboolean        loadgame;                       // handle connections specially
43
44         double          time;
45
46         double          frametime;
47
48         int                     lastcheck;                      // used by PF_checkclient
49         double          lastchecktime;
50
51         char            name[64];                       // map name
52         char            modelname[64];          // maps/<name>.bsp, for model_precache[0]
53         struct model_s  *worldmodel;
54         char            *model_precache[MAX_MODELS];    // NULL terminated
55         struct model_s  *models[MAX_MODELS];
56         char            *sound_precache[MAX_SOUNDS];    // NULL terminated
57         char            *lightstyles[MAX_LIGHTSTYLES];
58         int                     num_edicts;
59         int                     max_edicts;
60         edict_t         *edicts;                        // can NOT be array indexed, because
61                                                                         // edict_t is variable sized, but can
62                                                                         // be used to reference the world ent
63         server_state_t  state;                  // some actions are only valid during load
64
65         sizebuf_t       datagram;
66         qbyte           datagram_buf[MAX_DATAGRAM];
67
68         sizebuf_t       reliable_datagram;      // copied to all clients at end of frame
69         qbyte           reliable_datagram_buf[MAX_DATAGRAM];
70
71         sizebuf_t       signon;
72         qbyte           signon_buf[32768]; // LordHavoc: increased signon message buffer from 8192 to 32768
73 } server_t;
74
75
76 #define NUM_PING_TIMES          16
77 #define NUM_SPAWN_PARMS         16
78
79 typedef struct client_s
80 {
81         qboolean                active;                         // false = client is free
82         qboolean                spawned;                        // false = don't send datagrams
83         qboolean                dropasap;                       // has been told to go to another level
84         qboolean                sendsignon;                     // only valid before spawned
85
86 #ifndef NOROUTINGFIX
87         // LordHavoc: to make netquake protocol get through NAT routers, have to wait for client to ack
88         qboolean                waitingforconnect;      // waiting for connect from client (stage 1)
89         qboolean                sendserverinfo;         // send server info in next datagram (stage 2)
90 #endif
91
92         double                  last_message;           // reliable messages must be sent
93                                                                                 // periodically
94
95         struct qsocket_s *netconnection;        // communications handle
96
97         usercmd_t               cmd;                            // movement
98         vec3_t                  wishdir;                        // intended motion calced from cmd
99
100         sizebuf_t               message;                        // can be added to at any time,
101                                                                                 // copied and clear once per frame
102         qbyte                   msgbuf[MAX_MSGLEN];
103         edict_t                 *edict;                         // EDICT_NUM(clientnum+1)
104         char                    name[32];                       // for printing to other people
105         int                             colors;
106
107         float                   ping_times[NUM_PING_TIMES];
108         int                             num_pings;                      // ping_times[num_pings%NUM_PING_TIMES]
109         float                   ping;                           // LordHavoc: can be used for prediction or whatever...
110         float                   latency;                        // LordHavoc: specifically used for prediction, accounts for sys_ticrate too
111
112 // spawn parms are carried from level to level
113         float                   spawn_parms[NUM_SPAWN_PARMS];
114
115 // client known data for deltas
116         int                             old_frags;
117         int                             pmodel;
118
119 #ifdef QUAKEENTITIES
120         // delta compression state
121         float                   nextfullupdate[MAX_EDICTS];
122 #endif
123         // visibility state
124         float                   visibletime[MAX_EDICTS];
125
126 #ifndef QUAKEENTITIES
127         entity_database_t entitydatabase;
128         int                             entityframenumber; // incremented each time an entity frame is sent
129 #endif
130 } client_t;
131
132
133 //=============================================================================
134
135 // edict->movetype values
136 #define MOVETYPE_NONE                   0               // never moves
137 #define MOVETYPE_ANGLENOCLIP    1
138 #define MOVETYPE_ANGLECLIP              2
139 #define MOVETYPE_WALK                   3               // gravity
140 #define MOVETYPE_STEP                   4               // gravity, special edge handling
141 #define MOVETYPE_FLY                    5
142 #define MOVETYPE_TOSS                   6               // gravity
143 #define MOVETYPE_PUSH                   7               // no clip to world, push and crush
144 #define MOVETYPE_NOCLIP                 8
145 #define MOVETYPE_FLYMISSILE             9               // extra size to monsters
146 #define MOVETYPE_BOUNCE                 10
147 #define MOVETYPE_BOUNCEMISSILE  11              // bounce w/o gravity
148 #define MOVETYPE_FOLLOW                 12              // track movement of aiment
149
150 // edict->solid values
151 #define SOLID_NOT                               0               // no interaction with other objects
152 #define SOLID_TRIGGER                   1               // touch on edge, but not blocking
153 #define SOLID_BBOX                              2               // touch on edge, block
154 #define SOLID_SLIDEBOX                  3               // touch on edge, but not an onground
155 #define SOLID_BSP                               4               // bsp clip, touch on edge, block
156 // LordHavoc: corpse code
157 #define SOLID_CORPSE                    5               // same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters)
158
159 // edict->deadflag values
160 #define DEAD_NO                                 0
161 #define DEAD_DYING                              1
162 #define DEAD_DEAD                               2
163
164 #define DAMAGE_NO                               0
165 #define DAMAGE_YES                              1
166 #define DAMAGE_AIM                              2
167
168 // edict->flags
169 #define FL_FLY                                  1
170 #define FL_SWIM                                 2
171 #define FL_CONVEYOR                             4
172 #define FL_CLIENT                               8
173 #define FL_INWATER                              16
174 #define FL_MONSTER                              32
175 #define FL_GODMODE                              64
176 #define FL_NOTARGET                             128
177 #define FL_ITEM                                 256
178 #define FL_ONGROUND                             512
179 #define FL_PARTIALGROUND                1024    // not all corners are valid
180 #define FL_WATERJUMP                    2048    // player jumping out of water
181 #define FL_JUMPRELEASED                 4096    // for jump debouncing
182
183 // entity effects
184
185 #define EF_BRIGHTFIELD                  1
186 #define EF_MUZZLEFLASH                  2
187 #define EF_BRIGHTLIGHT                  4
188 #define EF_DIMLIGHT                     8
189 // added EF_ effects:
190 #define EF_NODRAW                               16
191 #define EF_ADDITIVE                             32  // LordHavoc: Additive Rendering
192 #define EF_BLUE                                 64
193 #define EF_RED                                  128
194
195 #define SPAWNFLAG_NOT_EASY                      256
196 #define SPAWNFLAG_NOT_MEDIUM            512
197 #define SPAWNFLAG_NOT_HARD                      1024
198 #define SPAWNFLAG_NOT_DEATHMATCH        2048
199
200 //============================================================================
201
202 extern cvar_t teamplay;
203 extern cvar_t skill;
204 extern cvar_t deathmatch;
205 extern cvar_t coop;
206 extern cvar_t fraglimit;
207 extern cvar_t timelimit;
208 extern cvar_t pausable;
209 extern cvar_t sv_deltacompress;
210 extern cvar_t sv_maxvelocity;
211 extern cvar_t sv_gravity;
212 extern cvar_t sv_nostep;
213 extern cvar_t sv_friction;
214 extern cvar_t sv_edgefriction;
215 extern cvar_t sv_stopspeed;
216 extern cvar_t sv_maxspeed;
217 extern cvar_t sv_accelerate;
218 extern cvar_t sv_idealpitchscale;
219 extern cvar_t sv_aim;
220 extern cvar_t sv_predict;
221 extern cvar_t sv_stepheight;
222 extern cvar_t sv_jumpstep;
223
224 extern server_static_t svs;                             // persistant server info
225 extern server_t sv;                                     // local server
226
227 extern client_t *host_client;
228
229 extern jmp_buf host_abortserver;
230
231 extern edict_t *sv_player;
232
233 //===========================================================
234
235 void SV_Init (void);
236
237 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
238 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
239 void SV_StartSound (edict_t *entity, int channel, char *sample, int volume, float attenuation);
240
241 void SV_DropClient (qboolean crash);
242
243 void SV_SendClientMessages (void);
244 void SV_ClearDatagram (void);
245
246 int SV_ModelIndex (char *name);
247
248 void SV_SetIdealPitch (void);
249
250 void SV_AddUpdates (void);
251
252 void SV_ClientThink (void);
253 void SV_AddClientToServer (struct qsocket_s     *ret);
254
255 void SV_ClientPrintf (char *fmt, ...);
256 void SV_BroadcastPrintf (char *fmt, ...);
257
258 void SV_Physics (void);
259
260 qboolean SV_CheckBottom (edict_t *ent);
261 qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink);
262
263 void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg);
264
265 void SV_MoveToGoal (void);
266
267 void SV_CheckForNewClients (void);
268 void SV_RunClients (void);
269 void SV_SaveSpawnparms (void);
270 void SV_SpawnServer (char *server);
271
272 void SV_SetMaxClients(int n);
273
274 #endif
275