Debian Codegraph @

Descent3/multi_external.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * 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, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/multi_external.h $
21 * $Revision: 24 $
22 * $Date: 9/01/99 4:12p $
23 * $Author: Kevin $
24 *
25 * defines, structs, etc. that can be exported to DLLs
26 *
27 * $Log: /DescentIII/main/multi_external.h $
28 *
29 * 24 9/01/99 4:12p Kevin
30 * Byte ordering fixes for the macintosh
31 *
32 * 23 7/08/99 5:45p Jason
33 * added some extra netgame flags
34 *
35 * 22 7/06/99 5:52p Kevin
36 * PXO & multiplayer fixes for the patch
37 *
38 * 21 5/23/99 3:05a Jason
39 * fixed bug with player rankings not being updated correctly
40 *
41 * 20 5/20/99 2:52p Jason
42 * made autowaypoints work in coop
43 *
44 * 19 5/10/99 10:22p Ardussi
45 * changes to compile on Mac
46 *
47 * 18 5/10/99 12:11a Jason
48 * added little endian/big endian safeness
49 *
50 * 17 5/09/99 1:34p Kevin
51 * Added diffuculty level system to multiplayer
52 *
53 * 16 5/07/99 2:51p Jason
54 * fixed a bunch of endlevel multiplayer issues
55 *
56 * 15 4/21/99 11:26a Jason
57 * lowered max players
58 *
59 * 14 4/21/99 11:05a Kevin
60 * new ps_rand and ps_srand to replace rand & srand
61 *
62 * 13 4/17/99 4:34p Jason
63 * changes for robot/turret tracking
64 *
65 * 12 4/15/99 3:36p Kevin
66 * Added mouselook UI stuff to the multiplayer options menu
67 *
68 * 11 4/14/99 3:56a Jeff
69 * fixed case mismatch in #includes
70 *
71 * 10 3/25/99 3:29p Jason
72 * added option to randomize powerup respawn points
73 *
74 * 9 3/22/99 6:22p Jeff
75 * added 2 more audio taunts. a mulitplayer event when someone plays an
76 * audio taunt. option to disable audio taunts.
77 *
78 * 8 3/17/99 4:08p Kevin
79 * Changed the way games appear and timeout in the game list.
80 *
81 * 7 3/01/99 4:17p Jeff
82 * added net flag whether buddy bot allowed
83 *
84 * 6 2/19/99 5:21p Kevin
85 * Fixed some connection DLLs and a Direct Sound bug with threads.
86 *
87 * 5 2/03/99 4:26p Jason
88 * made multiplayer coop actually work!
89 *
90 * 4 2/03/99 4:20p Kevin
91 * Got multiplayer working with .mn3 files, and setup autodownloading
92 *
93 * 3 2/02/99 7:06p Jason
94 * added ranking system
95 *
96 * 2 1/21/99 11:15p Jeff
97 * pulled out some structs and defines from header files and moved them
98 * into seperate header files so that multiplayer dlls don't require major
99 * game headers, just those new headers. Side effect is a shorter build
100 * time. Also cleaned up some header file #includes that weren't needed.
101 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
102 * manage.h and multi.h
103 *
104 * $NoKeywords: $
105 */
106
107 #ifndef __MULTI_EXTERNAL_H_
108 #define __MULTI_EXTERNAL_H_
109
110 #if defined(POSIX)
111 #include <cstring>
112 #include <cstdint>
113 typedef uintptr_t DWORD;
114 typedef int HANDLE;
115 #endif
116
117 #include "pstypes.h"
118 #include "manage_external.h"
119 #include "cfile.h"
120 #include "networking.h"
121 #include "descent.h" //for MSN_NAMELEN
122 #include "byteswap.h"
123 #include <cassert>
124
125 #define NETGAME_NAME_LEN 32
126 #define NETGAME_SCRIPT_LEN 32
127
128 #define LR_CLIENT 0
129 #define LR_SERVER 1
130
131 // Max number of network players
132 #define MAX_NET_PLAYERS 32
133
134 #define MAX_GAME_DATA_SIZE (MAX_PACKET_SIZE - 4)
135
136 // Stuff for the connection DLLs
137 #define MT_EVT_LOGIN 1
138 #define MT_EVT_FIRST_FRAME 2
139 #define MT_EVT_FRAME 3
140 #define MT_EVT_GAME_OVER 4
141 #define MT_EVT_GET_HELP 5
142 #define MT_AUTO_LOGIN 6
143 #define MT_AUTO_START 7
144 #define MT_RETURN_TO_GAME_LIST 8
145
146 // Net sequencing
147
148 #define NETSEQ_PREGAME 0 // Not in a game
149 #define NETSEQ_WAITING_FOR_LEVEL 1 // Client - waiting for level name and checksum
150 #define NETSEQ_LEVEL_START 2 // Waiting for level object stuff
151 #define NETSEQ_NEED_GAMETIME 3 // Need to ask for gametime
152 #define NETSEQ_WAIT_GAMETIME 4 // Waiting for server response in gametime
153 #define NETSEQ_REQUEST_PLAYERS 5 // Requesting players
154 #define NETSEQ_PLAYERS 6 // Getting player stuff
155 #define NETSEQ_REQUEST_BUILDINGS 7 // Requesting buildings
156 #define NETSEQ_BUILDINGS 8 // Getting buildings
157 #define NETSEQ_REQUEST_OBJECTS 9 // Getting objects
158 #define NETSEQ_OBJECTS 10 // Got objects
159 #define NETSEQ_REQUEST_WORLD 11 // Getting world states
160 #define NETSEQ_WORLD 12 // Got World
161 #define NETSEQ_PLAYING 13 // Playing the game
162 #define NETSEQ_LEVEL_END 14 // At the post-level stage
163
164 // Netplayer flags
165 #define NPF_CONNECTED 1 // This player is connected
166 #define NPF_SERVER 2 // This player is the server
167 #define NPF_MASTER_TRACKER 4 // This is a master tracker game
168 #define NPF_MT_READING_PILOT 8 // Waiting for a response from the mastertracker about this pilot's stats
169 #define NPF_MT_WRITING_PILOT 16 // Waiting to finish updating the mastertracker with this pilot's stats
170 #define NPF_MT_HAS_PILOT_DATA 32 // We got data from the mastertracker
171 #define NPF_WROTE_RANK 64 // We told the clients about this clients rank
172
173 struct netplayer {
174 network_address addr;
175 int flags;
176 SOCKET reliable_socket;
177 float last_packet_time;
178 float packet_time; // for making sure we don't get position packets out of order
179 uint32_t total_bytes_sent;
180 uint32_t total_bytes_rcvd;
181 uint32_t secret_net_id; // We use this to determine who we are getting packets from
182 int file_xfer_flags; // Are we sending,receiving, or neither
183 uint32_t file_xfer_total_len; // Total length of the file we are receiving
184 uint32_t file_xfer_pos; // Position for sending and/or receiving
185 uint32_t file_xfer_id; // File id that we are sending
186 uint32_t file_xfer_who; // Who the file is for
187 CFILE *file_xfer_cfile; // File handle for src/target file
188 uint16_t position_counter; // for making sure we don't get position packets out of order
189 char ship_logo[_MAX_PATH];
190 char voice_taunt1[_MAX_PATH];
191 char voice_taunt2[_MAX_PATH];
192 char voice_taunt3[_MAX_PATH];
193 char voice_taunt4[_MAX_PATH];
194 uint8_t custom_file_seq;
195 uint8_t sequence; // where we are in the sequence chain
196 uint8_t pps;
197 HANDLE hPlayerEvent; // player event to use for directplay
198 DWORD dpidPlayer; // directplay ID of player created
199 float ping_time;
200 float last_ping_time;
201 uint16_t pilot_pic_id;
202 float percent_loss;
203 uint8_t digest[16];
204 };
205
206 #define MISSION_NAME_LEN 50
207
208 struct network_game {
209 network_address addr;
210 char name[NETGAME_NAME_LEN];
211 char mission[MSN_NAMELEN];
212 char mission_name[MISSION_NAME_LEN];
213 char scriptname[NETGAME_SCRIPT_LEN];
214 uint16_t level_num;
215 uint16_t curr_num_players;
216 uint16_t max_num_players;
217 float server_response_time;
218 uint32_t flags;
219 float last_update;
220 bool dedicated_server;
221 uint8_t difficulty; // Game difficulty level
222 uint32_t handle;
223 };
224
225 // netgame flags
226 #define NF_TIMER 0x01 // This level will end when the timer runs out
227 #define NF_KILLGOAL 0x02 // This level will end when the number of kills reaches a certain point
228 #define NF_USE_ROBOTS 0x04 // This game uses robots
229 #define NF_EXIT_NOW 0x08 // This game needs to bail right now
230 #define NF_PEER_PEER 0x10 // This game is a psuedo peer-peer game, so send position packets to all clients.
231 #define NF_SENDROTVEL 0x20 // Use low resolution packets
232 #define NF_ALLOWGUIDEBOT 0x40 // Whether the Guide bot is allowed in the game
233 #define NF_DIRECTPLAY 0x80 // This game is a directplay game
234 #define NF_ATTACK_FRIENDLY 0x100 // Homers and gunboys will attack friendlies
235 #define NF_DAMAGE_FRIENDLY 0x200 // Friendly fire will cause damage
236 #define NF_USE_ACC_WEAP 0x400 // Use big weapon spheres against player ships.
237 #define NF_USE_SMOOTHING 0x800 // Smooth out positional movement via curve interpolation
238 #define NF_BRIGHT_PLAYERS 0x1000 // Bright players in netgame
239 #define NF_PERMISSABLE 0x2000 // Clients need server permission to fire
240 #define NF_RESPAWN_WAYPOINT 0x4000 // Players should use waypoints to respawn
241 #define NF_RANDOMIZE_RESPAWN 0x8000 // Powerups should move around randomly when respawning
242 #define NF_ALLOW_MLOOK 0x10000 // Allow mouse lookers
243 #define NF_TRACK_RANK 0x20000 // Track rankings for PXO
244 #define NF_COOP 0x40000 // This game is a cooperative game
245
246 struct netgame_info {
247 uint16_t server_version; // This is so client and server code matches
248 char name[NETGAME_NAME_LEN];
249 char mission[MSN_NAMELEN];
250 char mission_name[MISSION_NAME_LEN];
251 char scriptname[NETGAME_SCRIPT_LEN];
252 char server_config_name[PAGENAME_LEN];
253 char connection_name[PAGENAME_LEN];
254 network_address server_address; // The address of the server that we're talking to - not used if we are the server
255
256 uint8_t local_role;
257 uint8_t server_sequence;
258 float last_server_time; // last time we got a packet from the server
259 uint8_t packets_per_second; // how many packets per second we'll send out
260 int flags;
261 int timelimit; // how many minutes to play this level
262 int killgoal; // kill goal for this level
263 int respawn_time;
264 int max_players;
265 uint8_t difficulty; // Game difficulty level
266 u_char digest[16];
267 };
268
269 // Inline functions for extracting/packing multiplayer data
270 inline void MultiAddUbyte(uint8_t element, uint8_t *data, int *count) {
271 data[*count] = element;
272 *count += sizeof(uint8_t);
273 }
274
275 inline void MultiAddByte(uint8_t element, uint8_t *data, int *count) {
276 data[*count] = element;
277 *count += sizeof(uint8_t);
278 }
279
280 inline void MultiAddSbyte(int8_t element, uint8_t *data, int *count) {
281 data[*count] = element;
282 *count += sizeof(int8_t);
283 }
284
285 inline void MultiAddShort(int16_t element, uint8_t *data, int *count) {
286 *(int16_t *)(data + *count) = INTEL_SHORT(element);
287 *count += sizeof(int16_t);
288 }
289
290 inline void MultiAddUshort(uint16_t element, uint8_t *data, int *count) {
291 *(uint16_t *)(data + *count) = INTEL_SHORT(element);
292 *count += sizeof(uint16_t);
293 }
294
295 inline void MultiAddInt(int element, uint8_t *data, int *count) {
296 *(int *)(data + *count) = INTEL_INT(element);
297 *count += sizeof(int);
298 }
299
300 inline void MultiAddUint(uint32_t element, uint8_t *data, int *count) {
301 *(uint32_t *)(data + *count) = INTEL_INT(element);
302 *count += sizeof(uint32_t);
303 }
304
305 inline void MultiAddFloat(float element, uint8_t *data, int *count) {
306 *(float *)(data + *count) = INTEL_FLOAT(element);
307 *count += sizeof(float);
308 }
309
310 inline void MultiAddString(const char *str, uint8_t *data, int *count) {
311 size_t len = strlen(str) + 1;
312 assert(len <= 0xFF);
313
314 MultiAddByte((uint8_t)len, data, count);
315 memcpy(&data[*count], str, len);
316 *count += static_cast<int>(len);
317 }
318
319 inline uint8_t MultiGetUbyte(uint8_t *data, int *count) {
320 uint8_t element = (*(uint8_t *)(data + *count));
321 (*count) += sizeof(uint8_t);
322 return element;
323 }
324
325 inline uint8_t MultiGetByte(uint8_t *data, int *count) {
326 uint8_t element = (*(uint8_t *)(data + *count));
327 (*count) += sizeof(uint8_t);
328 return element;
329 }
330
331 inline int8_t MultiGetSbyte(uint8_t *data, int *count) {
332 int8_t element = (*(int8_t *)(data + *count));
333 (*count) += sizeof(int8_t);
334 return element;
335 }
336
337 inline int16_t MultiGetShort(uint8_t *data, int *count) {
338 int16_t element = (*(int16_t *)(data + *count));
339 *count += sizeof(int16_t);
340 return INTEL_SHORT(element);
341 }
342
343 inline uint16_t MultiGetUshort(uint8_t *data, int *count) {
344 uint16_t element = (*(uint16_t *)(data + *count));
345 *count += sizeof(int16_t);
346 return INTEL_SHORT(element);
347 }
348
349 inline int MultiGetInt(uint8_t *data, int *count) {
350 int element = (*(int *)(data + *count));
351 *count += sizeof(int);
352 return INTEL_INT(element);
353 }
354
355 inline uint32_t MultiGetUint(uint8_t *data, int *count) {
356 uint32_t element = (*(uint32_t *)(data + *count));
357 *count += sizeof(int);
358 return INTEL_INT(element);
359 }
360
361 inline float MultiGetFloat(uint8_t *data, int *count) {
362 float element = (*(float *)(data + *count));
363 *count += sizeof(float);
364 return INTEL_FLOAT(element);
365 }
366
367 inline void MultiGetString(char *str, uint8_t *data, int *count) {
368 uint8_t len = MultiGetByte(data, count);
369 memcpy(str, &data[*count], len);
370 *count += len;
371 }
372
373 inline void MultiAddVector(vector v, uint8_t *data, int *count) {
374 MultiAddFloat(v.x, data, count);
375 MultiAddFloat(v.y, data, count);
376 MultiAddFloat(v.z, data, count);
377 }
378
379 inline vector MultiGetVector(uint8_t *data, int *count) {
380 vector v;
381
382 v.x = MultiGetFloat(data, count);
383 v.y = MultiGetFloat(data, count);
384 v.z = MultiGetFloat(data, count);
385 return v;
386 }
387 #endif