2 * $Logfile: /Freespace2/code/Network/MultiUtil.h $
7 * Header file to support misc. multiplayer support functions
10 * Revision 1.1 2002/05/03 03:28:12 root
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
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.
22 * 11 7/30/99 7:01p Dave
23 * Dogfight escort gauge. Fixed up laser rendering in Glide.
25 * 10 5/04/99 5:20p Dave
26 * Fixed up multiplayer join screen and host options screen. Should both
29 * 9 3/08/99 7:03p Dave
30 * First run of new object update system. Looks very promising.
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.
36 * 7 2/23/99 2:29p Dave
37 * First run of oldschool dogfight mode.
39 * 6 12/14/98 12:13p Dave
40 * Spiffed up xfer system a bit. Put in support for squad logo file xfer.
43 * 5 11/19/98 4:19p Dave
44 * Put IPX sockets back in psnet. Consolidated all multiplayer config
47 * 4 11/17/98 11:12a Dave
48 * Removed player identification by address. Now assign explicit id #'s.
50 * 3 11/05/98 5:55p Dave
51 * Big pass at reducing #includes
53 * 2 10/07/98 10:53a Dave
56 * 1 10/07/98 10:50a Dave
58 * 121 9/11/98 5:08p Dave
59 * More tweaks to kick notification system.
61 * 120 9/04/98 3:52p Dave
62 * Put in validated mission updating and application during stats
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.
69 * 118 7/24/98 11:15a Allender
70 * added 32bit checksumming stuff for validated missions
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.
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.
82 * 115 6/12/98 2:49p Dave
85 * 114 6/10/98 2:56p Dave
86 * Substantial changes to reduce bandwidth and latency problems.
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.
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)
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.
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.
106 * 109 5/11/98 11:40p Dave
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.
114 * 107 5/07/98 6:31p Dave
115 * Fix sticky situations where players are dying/respawning when the game
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.
122 * 105 4/30/98 12:57a Dave
123 * Put in new mode for ship/weapon selection. Rearranged how game querying
135 // prototypes instead of headers :)
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
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 );
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);
174 extern int multi_num_players();
175 extern int multi_num_observers();
176 extern int multi_num_connections();
178 extern char* multi_random_death_word();
179 extern char* multi_random_chat_start();
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 );
186 extern object *multi_get_network_object( ushort net_signature ); // find a network object
188 void multi_find_ingame_join_pos(object *new_obj);
190 // return size of packed matrix
191 void multi_pack_orient_matrix(ubyte *data,matrix *m);
193 // return bytes processed
194 void multi_unpack_orient_matrix(ubyte *data,matrix *m);
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);
199 void multi_assign_player_ship( int net_player, object *objp, int ship_class );
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);
207 // called client-side every frame
208 void multi_maybe_send_ship_status();
210 // will be used server side _and_ client side.
211 void multi_apply_ship_status(net_player *p,button_info *bi, int locally);
213 void multiplayer_match_target_speed(net_player *p);
215 void multi_subsys_update_all();
217 void server_verify_filesig(short player_id, ushort sum_sig, int length_sig);
218 int server_all_filesigs_ok();
220 void multi_untag_player_ships();
222 // broadcast alltime stats to everyone in the game
223 void multi_broadcast_stats(int stats_code);
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);
230 void multi_eval_socket_error(PSNET_SOCKET sock, int error);
232 void multi_maybe_send_repair_info(object *dest_obj, object *source_objp, int code);
234 int multi_is_valid_unknown_packet(ubyte type);
236 // create a bogus object for the standalone
237 void multi_create_standalone_object();
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);
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();
247 server_item *multi_new_server_item( void );
248 void multi_free_server_list();
250 // netgame options evaluation stuff
251 int multi_can_message(net_player *p);
252 int multi_can_end_mission(net_player *p);
254 int multi_eval_join_request(join_request *jr,net_addr *addr);
256 // called by any machine (client, host, server, standalone, etc), to begin warping out all player objects
257 void multi_warpout_all_players();
259 // determine the highest rank of any of the players in the game
260 int multi_get_highest_rank();
262 // called on the machine of the player who hit alt+j
263 void multi_handle_end_mission_request();
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();
268 // called by the file xfer subsytem when we start receiving a file
269 void multi_file_xfer_notify(int handle);
271 // return the lag/disconnected status of the game
272 int multi_query_lag_status();
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);
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);
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);
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);
286 // flush the multidata cache directory
287 void multi_flush_multidata_cache();
289 // flush all data from a previous mission before starting the next
290 void multi_flush_mission_stuff();
292 // should we ignore all controls and keypresses because of some multiplayer
293 int multi_ignore_controls(int key = -1);
295 // if the kill limit has been reached by any given player
296 int multi_kill_limit_reached();
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);
301 // fill in Current_file_checksum and Current_file_length
302 void multi_get_mission_checksum(char *filename);
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);
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);
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);
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);
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);
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);
334 char multi_unit_to_char(float unit);
335 float multi_char_to_unit(float val);
337 // if we should render our ping time to the server in a multiplayer game
338 int multi_show_ingame_ping();
340 // if Game_current_mission_filename is a builtin multiplayer mission
341 int multi_is_builtin_mission();
343 int multi_get_connection_speed();
345 // if we're in tracker mode, do a validation update on all known missions
346 void multi_update_valid_missions();
348 // get a new id# for a player
349 short multi_get_new_id();
351 // make a bunch of fake players - don't rely on this to be very safe - its mostly used for interface testing
353 void multi_make_fake_players(int count);