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