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