|
|
1.1 root 1: // server.h
2:
3:
4: //define PARANOID // speed sapping error checking
5:
6: #include "../qcommon/qcommon.h"
7: #include "../game/game.h"
8:
9: //=============================================================================
10:
11: #define MAX_MASTERS 8 // max recipients for heartbeat packets
12:
13: typedef enum {
14: ss_dead, // no map loaded
15: ss_loading, // spawning level edicts
16: ss_game, // actively running
17: ss_cinematic,
18: ss_demo,
19: ss_pic
20: } server_state_t;
21: // some qc commands are only valid before the server has finished
22: // initializing (precache commands, static sounds / objects, etc)
23:
24: typedef struct
25: {
26: server_state_t state; // precache commands are only valid during load
27:
28: qboolean attractloop; // running cinematics and demos for the local system only
29: qboolean loadgame; // client begins should reuse existing entity
30:
1.1.1.2 ! root 31: unsigned time; // always sv.framenum * 100 msec
1.1 root 32: int framenum;
33:
34: char name[MAX_QPATH]; // map name, or cinematic name
35: struct cmodel_s *models[MAX_MODELS];
36:
37: char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH];
38: entity_state_t baselines[MAX_EDICTS];
39:
40: // the multicast buffer is used to send a message to a set of clients
41: // it is only used to marshall data until SV_Multicast is called
42: sizebuf_t multicast;
43: byte multicast_buf[MAX_MSGLEN];
44:
45: // demo server information
46: FILE *demofile;
47: qboolean timedemo; // don't time sync
48: } server_t;
49:
50: #define EDICT_NUM(n) ((edict_t *)((byte *)ge->edicts + ge->edict_size*(n)))
51: #define NUM_FOR_EDICT(e) ( ((byte *)(e)-(byte *)ge->edicts ) / ge->edict_size)
52:
53:
54: typedef enum
55: {
56: cs_free, // can be reused for a new connection
57: cs_zombie, // client has been disconnected, but don't reuse
58: // connection for a couple seconds
59: cs_connected, // has been assigned to a client_t, but not in game yet
60: cs_spawned // client is fully in game
61: } client_state_t;
62:
63: typedef struct
64: {
65: int areabytes;
66: byte areabits[MAX_MAP_AREAS/8]; // portalarea visibility bits
67: player_state_t ps;
68: int num_entities;
69: int first_entity; // into the circular sv_packet_entities[]
1.1.1.2 ! root 70: int senttime; // for ping calculations
1.1 root 71: } client_frame_t;
72:
73: #define LATENCY_COUNTS 16
74: #define RATE_MESSAGES 10
75:
76: typedef struct client_s
77: {
78: client_state_t state;
79:
80: char userinfo[MAX_INFO_STRING]; // name, etc
81:
82: int lastframe; // for delta compression
83: usercmd_t lastcmd; // for filling in big drops
84:
85: int commandMsec; // every seconds this is reset, if user
86: // commands exhaust it, assume time cheating
87:
88: int frame_latency[LATENCY_COUNTS];
89: int ping;
90:
91: int message_size[RATE_MESSAGES]; // used to rate drop packets
92: int rate;
93: int surpressCount; // number of messages rate supressed
94:
95: edict_t *edict; // EDICT_NUM(clientnum+1)
96: char name[32]; // extracted from userinfo, high bits masked
97: int messagelevel; // for filtering printed messages
98:
99: // The datagram is written to by sound calls, prints, temp ents, etc.
100: // It can be harmlessly overflowed.
101: sizebuf_t datagram;
102: byte datagram_buf[MAX_MSGLEN];
103:
104: client_frame_t frames[UPDATE_BACKUP]; // updates can be delta'd from here
105:
106: byte *download; // file being downloaded
107: int downloadsize; // total bytes (can't use EOF because of paks)
108: int downloadcount; // bytes sent
109:
110: int lastmessage; // sv.framenum when packet was last received
111: int lastconnect;
112:
1.1.1.2 ! root 113: int challenge; // challenge of this user, randomly generated
! 114:
1.1 root 115: netchan_t netchan;
116: } client_t;
117:
118: // a client can leave the server in one of four ways:
119: // dropping properly by quiting or disconnecting
120: // timing out if no valid messages are received for timeout.value seconds
121: // getting kicked off by the server operator
122: // a program error, like an overflowed reliable buffer
123:
124: //=============================================================================
125:
126: // MAX_CHALLENGES is made large to prevent a denial
127: // of service attack that could cycle all of them
128: // out before legitimate users connected
129: #define MAX_CHALLENGES 1024
130:
131: typedef struct
132: {
133: netadr_t adr;
134: int challenge;
135: int time;
136: } challenge_t;
137:
138:
139: typedef struct
140: {
141: qboolean initialized; // sv_init has completed
1.1.1.2 ! root 142: int realtime; // always increasing, no clamping, etc
1.1 root 143:
144: char mapcmd[MAX_TOKEN_CHARS]; // ie: *intro.cin+base
145:
146: int spawncount; // incremented each server start
147: // used to check late spawns
148:
149: client_t *clients; // [maxclients->value];
150: int num_client_entities; // maxclients->value*UPDATE_BACKUP*MAX_PACKET_ENTITIES
151: int next_client_entities; // next client_entity to use
152: entity_state_t *client_entities; // [num_client_entities]
153:
154: int last_heartbeat;
155:
156: challenge_t challenges[MAX_CHALLENGES]; // to prevent invalid IPs from connecting
157:
158: // serverrecord values
159: FILE *demofile;
160: sizebuf_t demo_multicast;
161: byte demo_multicast_buf[MAX_MSGLEN];
162: } server_static_t;
163:
164: //=============================================================================
165:
166: extern netadr_t net_from;
167: extern sizebuf_t net_message;
168:
169: extern netadr_t master_adr[MAX_MASTERS]; // address of the master server
170:
171: extern server_static_t svs; // persistant server info
172: extern server_t sv; // local server
173:
174: extern cvar_t *sv_paused;
175: extern cvar_t *maxclients;
176: extern cvar_t *sv_noreload; // don't reload level state when reentering
177: // development tool
178: extern cvar_t *sv_enforcetime;
179:
180: extern client_t *sv_client;
181: extern edict_t *sv_player;
182:
183: //===========================================================
184:
185: //
186: // sv_main.c
187: //
188: void SV_FinalMessage (char *message, qboolean reconnect);
189: void SV_DropClient (client_t *drop);
190:
191: int SV_ModelIndex (char *name);
192: int SV_SoundIndex (char *name);
193: int SV_ImageIndex (char *name);
194:
195: void SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg);
196:
197: void SV_ExecuteUserCommand (char *s);
198: void SV_InitOperatorCommands (void);
199:
200: void SV_SendServerinfo (client_t *client);
201: void SV_UserinfoChanged (client_t *cl);
202:
203:
204: void Master_Heartbeat (void);
205: void Master_Packet (void);
206:
207: //
208: // sv_init.c
209: //
210: void SV_InitGame (void);
211: void SV_Map (qboolean attractloop, char *levelstring, qboolean loadgame);
212:
213:
214: //
215: // sv_phys.c
216: //
217: void SV_PrepWorldFrame (void);
218:
219: //
220: // sv_send.c
221: //
222: typedef enum {RD_NONE, RD_CLIENT, RD_PACKET} redirect_t;
223: #define SV_OUTPUTBUF_LENGTH (MAX_MSGLEN - 16)
224:
225: extern char sv_outputbuf[SV_OUTPUTBUF_LENGTH];
226:
227: void SV_FlushRedirect (int sv_redirected, char *outputbuf);
228:
229: void SV_DemoCompleted (void);
230: void SV_SendClientMessages (void);
231:
232: void SV_Multicast (vec3_t origin, multicast_t to);
233: void SV_StartSound (vec3_t origin, edict_t *entity, int channel,
234: int soundindex, float volume,
235: float attenuation, float timeofs);
236: void SV_ClientPrintf (client_t *cl, int level, char *fmt, ...);
237: void SV_BroadcastPrintf (int level, char *fmt, ...);
238: void SV_BroadcastCommand (char *fmt, ...);
239:
240: //
241: // sv_user.c
242: //
243: void SV_Nextserver (void);
244: void SV_ExecuteClientMessage (client_t *cl);
245:
246: //
247: // sv_ccmds.c
248: //
249: void SV_ReadLevelFile (void);
250: void SV_Status_f (void);
251:
252: //
253: // sv_ents.c
254: //
255: void SV_WriteFrameToClient (client_t *client, sizebuf_t *msg);
256: void SV_RecordDemoMessage (void);
257: void SV_BuildClientFrame (client_t *client);
258:
259:
260: void SV_Error (char *error, ...);
261:
262: //
263: // sv_game.c
264: //
265: extern game_export_t *ge;
266:
267: void SV_InitGameProgs (void);
268: void SV_ShutdownGameProgs (void);
269: void SV_InitEdict (edict_t *e);
270:
271:
272:
273: //============================================================
274:
275: //
276: // high level object sorting to reduce interaction tests
277: //
278:
279: void SV_ClearWorld (void);
280: // called after the world model has been loaded, before linking any entities
281:
282: void SV_UnlinkEdict (edict_t *ent);
283: // call before removing an entity, and before trying to move one,
284: // so it doesn't clip against itself
285:
286: void SV_LinkEdict (edict_t *ent);
287: // Needs to be called any time an entity changes origin, mins, maxs,
288: // or solid. Automatically unlinks if needed.
289: // sets ent->v.absmin and ent->v.absmax
290: // sets ent->leafnums[] for pvs determination even if the entity
291: // is not solid
292:
293: int SV_AreaEdicts (vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
294: // fills in a table of edict pointers with edicts that have bounding boxes
295: // that intersect the given area. It is possible for a non-axial bmodel
296: // to be returned that doesn't actually intersect the area on an exact
297: // test.
298: // returns the number of pointers filled in
1.1.1.2 ! root 299: // ??? does this always return the world?
1.1 root 300:
301: //===================================================================
302:
303: //
304: // functions that interact with everything apropriate
305: //
306: int SV_PointContents (vec3_t p);
307: // returns the CONTENTS_* value from the world at the given point.
308: // Quake 2 extends this to also check entities, to allow moving liquids
309:
310:
311: trace_t SV_Trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passedict, int contentmask);
312: // mins and maxs are relative
313:
314: // if the entire move stays in a solid volume, trace.allsolid will be set,
315: // trace.startsolid will be set, and trace.fraction will be 0
316:
317: // if the starting point is in a solid, it will be allowed to move out
318: // to an open area
319:
320: // passedict is explicitly excluded from clipping checks (normally NULL)
321:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.