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 
21 #ifndef SERVER_H
22 #define SERVER_H
23 
24 #include "model.h"
25 #include "progs.h"
26 #include "client.h"
27 
28 typedef enum { ss_loading, ss_active, ENSURE_INT_SERVER_STATE = 0x70000000 } server_state_t;
29 
30 typedef struct {
31     qboolean active;		// false if only a net client
32 
33     qboolean paused;
34     qboolean loadgame;		// handle connections specially
35 
36     double time;
37 
38     int lastcheck;		// used by PF_checkclient
39     double lastchecktime;
40     const mleaf_t *checkleaf;
41 
42     char name[64];		// map name
43 
44     char modelname[64];		// maps/<name>.bsp, for model_precache[0]
45     struct model_s *worldmodel;
46     const char *model_precache[MAX_MODELS];	// NULL terminated
47     struct model_s *models[MAX_MODELS];
48     const char *sound_precache[MAX_SOUNDS];	// NULL terminated
49     const char *lightstyles[MAX_LIGHTSTYLES];
50     int num_edicts;
51     int max_edicts;
52     edict_t *edicts;		/* can NOT be array indexed, because
53 				   edict_t is variable sized, but can
54 				   be used to reference the world ent */
55     server_state_t state;	// some actions are only valid during load
56 
57     sizebuf_t datagram;
58     byte datagram_buf[MAX_DATAGRAM];
59 
60     sizebuf_t reliable_datagram; // copied to all clients at end of frame
61     byte reliable_datagram_buf[MAX_MSGLEN];
62 
63     sizebuf_t signon;
64     byte signon_buf[MAX_MSGLEN];
65 
66     int protocol;		/* Active network protocol version */
67 } server_t;
68 
69 
70 #define	NUM_PING_TIMES		16
71 #define	NUM_SPAWN_PARMS		16
72 
73 typedef struct client_s {
74     qboolean active;		// false = client is free
75     qboolean spawned;		// false = don't send datagrams
76     qboolean dropasap;		// has been told to go to another level
77     qboolean sendsignon;	// only valid before spawned
78 
79     double last_message;	// reliable messages must be sent
80     // periodically
81 
82     struct qsocket_s *netconnection;	// communications handle
83 
84     usercmd_t cmd;		// movement
85     vec3_t wishdir;		// intended motion calced from cmd
86 
87     sizebuf_t message;		// can be added to at any time,
88 				// copied and clear once per frame
89     byte msgbuf[MAX_MSGLEN];
90     edict_t *edict;		// EDICT_NUM(clientnum+1)
91     char name[32];		// for printing to other people
92     int colors;
93 
94     float ping_times[NUM_PING_TIMES];
95     int num_pings;		// ping_times[num_pings%NUM_PING_TIMES]
96 
97 // spawn parms are carried from level to level
98     float spawn_parms[NUM_SPAWN_PARMS];
99 
100 // client known data for deltas
101     int old_frags;
102 } client_t;
103 
104 
105 //=============================================================================
106 
107 typedef struct {
108     int maxclients;
109     int maxclientslimit;
110     struct client_s *clients;		// [maxclients]
111     int serverflags;			// episode completion information
112     qboolean changelevel_issued;	// cleared when at SV_SpawnServer
113 } server_static_t;
114 
115 
116 //=============================================================================
117 
118 // edict->movetype values
119 #define	MOVETYPE_NONE		0	// never moves
120 #define	MOVETYPE_ANGLENOCLIP	1
121 #define	MOVETYPE_ANGLECLIP	2
122 #define	MOVETYPE_WALK		3	// gravity
123 #define	MOVETYPE_STEP		4	// gravity, special edge handling
124 #define	MOVETYPE_FLY		5
125 #define	MOVETYPE_TOSS		6	// gravity
126 #define	MOVETYPE_PUSH		7	// no clip to world, push and crush
127 #define	MOVETYPE_NOCLIP		8
128 #define	MOVETYPE_FLYMISSILE	9	// extra size to monsters
129 #define	MOVETYPE_BOUNCE		10
130 
131 // edict->solid values
132 #define	SOLID_NOT		0	// no interaction with other objects
133 #define	SOLID_TRIGGER		1	// touch on edge, but not blocking
134 #define	SOLID_BBOX		2	// touch on edge, block
135 #define	SOLID_SLIDEBOX		3	// touch on edge, but not an onground
136 #define	SOLID_BSP		4	// bsp clip, touch on edge, block
137 
138 // edict->deadflag values
139 #define	DEAD_NO			0
140 #define	DEAD_DYING		1
141 #define	DEAD_DEAD		2
142 
143 #define	DAMAGE_NO		0
144 #define	DAMAGE_YES		1
145 #define	DAMAGE_AIM		2
146 
147 // edict->flags
148 #define	FL_FLY			1
149 #define	FL_SWIM			2
150 //#define FL_GLIMPSE		4
151 #define	FL_CONVEYOR		4
152 #define	FL_CLIENT		8
153 #define	FL_INWATER		16
154 #define	FL_MONSTER		32
155 #define	FL_GODMODE		64
156 #define	FL_NOTARGET		128
157 #define	FL_ITEM			256
158 #define	FL_ONGROUND		512
159 #define	FL_PARTIALGROUND	1024	// not all corners are valid
160 #define	FL_WATERJUMP		2048	// player jumping out of water
161 #define	FL_JUMPRELEASED		4096	// for jump debouncing
162 
163 // entity effects
164 
165 #define	EF_BRIGHTFIELD		1
166 #define	EF_MUZZLEFLASH 		2
167 #define	EF_BRIGHTLIGHT 		4
168 #define	EF_DIMLIGHT 		8
169 
170 #define	SPAWNFLAG_NOT_EASY		256
171 #define	SPAWNFLAG_NOT_MEDIUM		512
172 #define	SPAWNFLAG_NOT_HARD		1024
173 #define	SPAWNFLAG_NOT_DEATHMATCH	2048
174 
175 //============================================================================
176 
177 extern cvar_t teamplay;
178 extern cvar_t skill;
179 extern cvar_t deathmatch;
180 extern cvar_t coop;
181 extern cvar_t fraglimit;
182 extern cvar_t timelimit;
183 extern cvar_t pausable;
184 
185 extern cvar_t sv_maxvelocity;
186 extern cvar_t sv_gravity;
187 extern cvar_t sv_nostep;
188 extern cvar_t sv_friction;
189 extern cvar_t sv_edgefriction;
190 extern cvar_t sv_stopspeed;
191 extern cvar_t sv_maxspeed;
192 extern cvar_t sv_accelerate;
193 extern cvar_t sv_idealpitchscale;
194 extern cvar_t sv_aim;
195 
196 extern server_static_t svs;	// persistant server info
197 extern server_t sv;		// local server
198 
199 extern client_t *host_client;
200 
201 extern double host_time;
202 
203 extern edict_t *sv_player;
204 
205 //===========================================================
206 
207 void SV_Init(void);
208 
209 void SV_StartParticle(vec3_t org, vec3_t dir, int color, int count);
210 void SV_StartSound(edict_t *entity, int channel, const char *sample,
211 		   int volume, float attenuation);
212 
213 void SV_DropClient(qboolean crash);
214 
215 void SV_SendClientMessages(void);
216 void SV_ClearDatagram(void);
217 
218 int SV_ModelIndex(const char *name);
219 
220 void SV_SetIdealPitch(void);
221 
222 void SV_AddUpdates(void);
223 
224 void SV_ClientThink(void);
225 void SV_AddClientToServer(struct qsocket_s *ret);
226 
227 void SV_ClientPrintf(const char *fmt, ...);
228 void SV_BroadcastPrintf(const char *fmt, ...);
229 
230 void SV_Physics(void);
231 
232 qboolean SV_CheckBottom(edict_t *ent);
233 qboolean SV_movestep(edict_t *ent, vec3_t move, qboolean relink);
234 
235 void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg);
236 
237 void SV_MoveToGoal(void);
238 
239 void SV_CheckForNewClients(void);
240 void SV_RunClients(void);
241 void SV_SaveSpawnparms();
242 
243 void SV_SpawnServer(char *server);
244 
245 /*
246  * Protocol dependent write of model index to buffer
247  * (shared with pr_cmds.c)
248  */
249 void SV_WriteModelIndex(sizebuf_t *sb, int c, unsigned int bits);
250 
251 #endif /* SERVER_H */
252