]> icculus.org git repositories - taylor/freespace2.git/blob - include/multiutil.h
fix issue with looping audio streams
[taylor/freespace2.git] / include / multiutil.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Network/MultiUtil.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file to support misc. multiplayer support functions
16  *
17  * $Log$
18  * Revision 1.3  2002/06/09 04:41:14  relnev
19  * added copyright header
20  *
21  * Revision 1.2  2002/05/27 00:40:47  theoddone33
22  * Fix net_addr vs net_addr_t
23  *
24  * Revision 1.1.1.1  2002/05/03 03:28:12  root
25  * Initial import.
26  *
27  * 
28  * 13    9/15/99 1:45a Dave
29  * Don't init joystick on standalone. Fixed campaign mode on standalone.
30  * Fixed no-score-report problem in TvT
31  * 
32  * 12    8/22/99 5:53p Dave
33  * Scoring fixes. Added self destruct key. Put callsigns in the logfile
34  * instead of ship designations for multiplayer players.
35  * 
36  * 11    7/30/99 7:01p Dave
37  * Dogfight escort gauge. Fixed up laser rendering in Glide.
38  * 
39  * 10    5/04/99 5:20p Dave
40  * Fixed up multiplayer join screen and host options screen. Should both
41  * be at 100% now.
42  * 
43  * 9     3/08/99 7:03p Dave
44  * First run of new object update system. Looks very promising.
45  * 
46  * 8     2/24/99 2:25p Dave
47  * Fixed up chatbox bugs. Made squad war reporting better. Fixed a respawn
48  * bug for dogfight more.
49  * 
50  * 7     2/23/99 2:29p Dave
51  * First run of oldschool dogfight mode. 
52  * 
53  * 6     12/14/98 12:13p Dave
54  * Spiffed up xfer system a bit. Put in support for squad logo file xfer.
55  * Need to test now.
56  * 
57  * 5     11/19/98 4:19p Dave
58  * Put IPX sockets back in psnet. Consolidated all multiplayer config
59  * files into one.
60  * 
61  * 4     11/17/98 11:12a Dave
62  * Removed player identification by address. Now assign explicit id #'s.
63  * 
64  * 3     11/05/98 5:55p Dave
65  * Big pass at reducing #includes
66  * 
67  * 2     10/07/98 10:53a Dave
68  * Initial checkin.
69  * 
70  * 1     10/07/98 10:50a Dave
71  * 
72  * 121   9/11/98 5:08p Dave
73  * More tweaks to kick notification system.
74  * 
75  * 120   9/04/98 3:52p Dave
76  * Put in validated mission updating and application during stats
77  * updating.
78  * 
79  * 119   8/12/98 4:53p Dave
80  * Put in 32 bit checksumming for PXO missions. No validation on the
81  * actual tracker yet, though.
82  * 
83  * 118   7/24/98 11:15a Allender
84  * added 32bit checksumming stuff for validated missions
85  * 
86  * 117   7/10/98 1:13a Allender
87  * lots of small multiplayer update changes.  Code in launcher to specify
88  * connection speed.  A couple of small fixes regarding empty mission
89  * files.  Time out players after 10 second when they don't connect on
90  * their reliable socket.
91  * 
92  * 116   6/30/98 2:17p Dave
93  * Revised object update system. Removed updates for all weapons. Put
94  * button info back into control info packet.
95  * 
96  * 115   6/12/98 2:49p Dave
97  * Patch 1.02 changes.
98  * 
99  * 114   6/10/98 2:56p Dave
100  * Substantial changes to reduce bandwidth and latency problems.
101  * 
102  * 113   6/04/98 11:46a Dave
103  * Drastically reduce size/rate of client control info update packets. Put
104  * in rate limiting for object updating from server.
105  * 
106  * 112   6/03/98 2:15p Dave
107  * Added special code from john to drastically reduce physics info packet
108  * fields. (30-50% reduction in bandwidth)
109  * 
110  * 111   5/21/98 1:52a Dave
111  * Remove obsolete command line functions. Reduce shield explosion packets
112  * drastically. Tweak PXO screen even more. Fix file xfer system so that
113  * we can guarantee file uniqueness.
114  * 
115  * 110   5/15/98 5:16p Dave
116  * Fix a standalone resetting bug.Tweaked PXO interface. Display captaincy
117  * status for team vs. team. Put in asserts to check for invalid team vs.
118  * team situations.
119  * 
120  * 109   5/11/98 11:40p Dave
121  * Stuff.
122  * 
123  * 108   5/10/98 7:06p Dave
124  * Fix endgame sequencing ESC key. Changed how host options warning popups
125  * are done. Fixed pause/message scrollback/options screen problems in mp.
126  * Make sure observer HUD doesn't try to lock weapons.
127  * 
128  * 107   5/07/98 6:31p Dave
129  * Fix sticky situations where players are dying/respawning when the game
130  * is ended.
131  * 
132  * 106   5/04/98 10:39p Dave
133  * Put in endgame sequencing.  Need to check campaign situations.
134  * Realigned ship info on team select screen.
135  * 
136  * 105   4/30/98 12:57a Dave
137  * Put in new mode for ship/weapon selection. Rearranged how game querying
138  * is done a bit.
139  * 
140  * $NoKeywords: $
141  */
142
143
144 #ifndef MULTI_UTIL_H
145 #define MULTI_UTIL_H
146
147 #include "psnet.h"
148
149 // prototypes instead of headers :)
150 struct net_player;
151 struct player;
152 struct button_info;
153 struct join_request;
154 struct physics_info;
155 struct object;
156 struct active_game;
157 struct ship;
158 struct server_item;
159 struct ship_info;
160
161 // two types of signatures that we can request,  permanent signatures are all below 1000.  non-permanent are above 1000
162 #define MULTI_SIG_SHIP                                  1
163 #define MULTI_SIG_ASTEROID                              2
164 #define MULTI_SIG_NON_PERMANENT         3
165 #define MULTI_SIG_DEBRIS                                4
166
167 extern ushort multi_assign_network_signature( int what_kind );
168 extern ushort multi_get_next_network_signature( int what_kind );
169 extern void multi_set_network_signature( ushort signature, int what_kind );
170
171 extern void stuff_netplayer_info( net_player *nplayer, net_addr_t *addr, int ship_class, player *pplayer );
172 extern int find_player(net_addr_t* addr);
173 extern int find_player_no_port(net_addr_t *addr);
174 extern int find_player_id(short player_id);
175 extern int find_player_socket(PSNET_SOCKET_RELIABLE sock);      // note this is only valid to do on a server!
176 extern int multi_find_player_by_object( object *obj );
177 extern int multi_find_player_by_signature( int signature );
178 extern int multi_find_player_by_callsign(const char *callsign);
179 extern int multi_find_player_by_net_signature(ushort net_signature);
180 extern int multi_find_player_by_ship_name(const char *ship_name);
181 extern int multi_create_player(int player_num, player *pl,char* name, net_addr_t* addr, int ship_class, short id);
182 extern int multi_find_open_netplayer_slot();
183 extern int multi_find_open_player_slot();
184 extern void delete_player(int player_num, int kicked_reason = -1);
185 extern int multi_get_player_ship(int np_index);
186
187 extern int multi_num_players();
188 extern int multi_num_observers();
189 extern int multi_num_connections();
190
191 extern const char* multi_random_death_word();
192 extern const char* multi_random_chat_start();
193
194 extern int multi_ship_class_lookup(const char* ship_name);
195 extern ushort netmisc_calc_checksum( void * vptr, int len );
196 extern void fill_net_addr(net_addr_t* addr, ubyte* address, ushort port);
197 extern char* get_text_address(char * text, const int max_textlen, ubyte * address );
198
199 extern object *multi_get_network_object( ushort net_signature );                // find a network object
200
201 void multi_find_ingame_join_pos(object *new_obj);
202
203 // return size of packed matrix
204 void multi_pack_orient_matrix(ubyte *data,matrix *m);
205
206 // return bytes processed
207 void multi_unpack_orient_matrix(ubyte *data,matrix *m);
208
209 // catchall to do any necessary client-side simulation processing or master side process for menu pauses, etc.
210 void multi_do_client_warp(float flFrametime);
211
212 void multi_assign_player_ship( int net_player, object *objp, int ship_class );
213
214 // -------------------------------------------------------------------
215 // ship status change functions (used both client and server side)
216 int lookup_ship_status(net_player *p, int unique_id, int remove=0);        // auto-remove if remove == 1
217 void remove_ship_status_item(net_player *p, int id);     
218 void add_net_button_info(net_player *p, button_info *bi, int unique_id);
219
220 // called client-side every frame
221 void multi_maybe_send_ship_status();
222
223 // will be used server side _and_ client side. 
224 void multi_apply_ship_status(net_player *p,button_info *bi, int locally);
225
226 void multiplayer_match_target_speed(net_player *p);
227
228 void multi_subsys_update_all();
229
230 void server_verify_filesig(short player_id, ushort sum_sig, int length_sig);
231 int server_all_filesigs_ok();
232
233 void multi_untag_player_ships();
234
235 // broadcast alltime stats to everyone in the game
236 void multi_broadcast_stats(int stats_code);
237
238 int multi_netplayer_state_check(int state, int ignore_standalone = 0);
239 int multi_netplayer_state_check2(int state, int state2, int ignore_standalone = 0);
240 int multi_netplayer_state_check3(int state, int state2, int state3, int ignore_standalone = 0);
241 int multi_netplayer_flag_check(int flags, int ignore_standalone = 0);
242
243 void multi_eval_socket_error(PSNET_SOCKET sock, int error);
244
245 void multi_maybe_send_repair_info(object *dest_obj, object *source_objp, int code);
246
247 int multi_is_valid_unknown_packet(ubyte type);
248
249 // create a bogus object for the standalone
250 void multi_create_standalone_object();
251
252 // determine whether (as a server), you should be rebroadcasting certain messages to everyone in the game
253 int multi_message_should_broadcast(int type);
254
255 // the active game list manager functions
256 active_game *multi_new_active_game( void );
257 active_game *multi_update_active_games(active_game *ag);
258 void multi_free_active_games();
259
260 server_item *multi_new_server_item( void );
261 void multi_free_server_list();
262
263 // netgame options evaluation stuff
264 int multi_can_message(net_player *p);
265 int multi_can_end_mission(net_player *p);
266
267 int multi_eval_join_request(join_request *jr,net_addr_t *addr);
268
269 // called by any machine (client, host, server, standalone, etc), to begin warping out all player objects
270 void multi_warpout_all_players();
271
272 // determine the highest rank of any of the players in the game
273 int multi_get_highest_rank();
274
275 // called on the machine of the player who hit alt+j
276 void multi_handle_end_mission_request();
277
278 // called to handle any special cases where a player is in some submenu when he needs to get pushed into some other state
279 void multi_handle_state_special();
280
281 // called by the file xfer subsytem when we start receiving a file
282 void multi_file_xfer_notify(int handle);
283
284 // return the lag/disconnected status of the game
285 int multi_query_lag_status();
286
287 // process a valid join request
288 void multi_process_valid_join_request(join_request *jr, net_addr_t *who_from, int ingame_join_team = -1);
289
290 // if a player is trying to join a restricted game, evaluate the keypress (accept or not, etc)
291 int multi_process_restricted_keys(int k);
292
293 // determine the status of available player ships (use team_0 for non team vs. team situations)
294 void multi_player_ships_available(int *team_0, int *team_1);
295
296 // server should update the player's bank/link status with the data in the passed ship
297 void multi_server_update_player_weapons(net_player *pl, ship *shipp);
298
299 // flush the multidata cache directory
300 void multi_flush_multidata_cache();
301
302 // flush all data from a previous mission before starting the next
303 void multi_flush_mission_stuff();
304
305 // should we ignore all controls and keypresses because of some multiplayer 
306 int multi_ignore_controls(int key = -1);
307
308 // if the kill limit has been reached by any given player
309 int multi_kill_limit_reached();
310
311 // display a chat message (write to the correct spot - hud, standalone gui, chatbox, etc)
312 void multi_display_chat_msg(const char *msg, int player_index, int add_id);
313
314 // fill in Current_file_checksum and Current_file_length
315 void multi_get_mission_checksum(const char *filename);
316
317 // Packs/unpacks an object position.
318 // Returns number of bytes read or written.
319 #define OO_POS_RET_SIZE                                                 9
320 int multi_pack_unpack_position(int write, ubyte *data, vector *pos);
321
322 // Packs/unpacks an orientation matrix.
323 // Returns number of bytes read or written.
324 #define OO_ORIENT_RET_SIZE                                              6
325 int multi_pack_unpack_orient(int write, ubyte *data, matrix *orient);
326
327 // Packs/unpacks velocity
328 // Returns number of bytes read or written.
329 #define OO_VEL_RET_SIZE                                                 4
330 int multi_pack_unpack_vel(int write, ubyte *data, matrix *orient, vector *pos, physics_info *pi);
331
332 // Packs/unpacks desired_velocity
333 // Returns number of bytes read or written.
334 #define OO_DESIRED_VEL_RET_SIZE                         3
335 int multi_pack_unpack_desired_vel(int write, ubyte *data, matrix *orient, vector *pos, physics_info *pi, ship_info *sip);
336
337 // Packs/unpacks rotational velocity
338 // Returns number of bytes read or written.
339 #define OO_ROTVEL_RET_SIZE                                              4
340 int multi_pack_unpack_rotvel(int write, ubyte *data, matrix *orient, vector *pos, physics_info *pi);
341
342 // Packs/unpacks desired rotvel
343 // Returns number of bytes read or written.
344 #define OO_DESIRED_ROTVEL_RET_SIZE                      3
345 int multi_pack_unpack_desired_rotvel(int write, ubyte *data, matrix *orient, vector *pos, physics_info *pi, ship_info *sip);
346
347 char multi_unit_to_char(float unit);
348 float multi_char_to_unit(float val);
349
350 // if we should render our ping time to the server in a multiplayer game
351 int multi_show_ingame_ping();
352
353 // if Game_current_mission_filename is a builtin multiplayer mission
354 int multi_is_builtin_mission();
355
356 int multi_get_connection_speed();
357
358 // if we're in tracker mode, do a validation update on all known missions
359 void multi_update_valid_missions();
360
361 // get a new id# for a player
362 short multi_get_new_id();
363
364 // make a bunch of fake players - don't rely on this to be very safe - its mostly used for interface testing
365 #ifndef NDEBUG
366 void multi_make_fake_players(int count);
367 #endif
368
369 #endif
370