]> icculus.org git repositories - taylor/freespace2.git/blob - include/multiutil.h
Fix net_addr vs net_addr_t
[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.2  2002/05/27 00:40:47  theoddone33
11  * Fix net_addr vs net_addr_t
12  *
13  * Revision 1.1.1.1  2002/05/03 03:28:12  root
14  * Initial import.
15  *
16  * 
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
20  * 
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.
24  * 
25  * 11    7/30/99 7:01p Dave
26  * Dogfight escort gauge. Fixed up laser rendering in Glide.
27  * 
28  * 10    5/04/99 5:20p Dave
29  * Fixed up multiplayer join screen and host options screen. Should both
30  * be at 100% now.
31  * 
32  * 9     3/08/99 7:03p Dave
33  * First run of new object update system. Looks very promising.
34  * 
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.
38  * 
39  * 7     2/23/99 2:29p Dave
40  * First run of oldschool dogfight mode. 
41  * 
42  * 6     12/14/98 12:13p Dave
43  * Spiffed up xfer system a bit. Put in support for squad logo file xfer.
44  * Need to test now.
45  * 
46  * 5     11/19/98 4:19p Dave
47  * Put IPX sockets back in psnet. Consolidated all multiplayer config
48  * files into one.
49  * 
50  * 4     11/17/98 11:12a Dave
51  * Removed player identification by address. Now assign explicit id #'s.
52  * 
53  * 3     11/05/98 5:55p Dave
54  * Big pass at reducing #includes
55  * 
56  * 2     10/07/98 10:53a Dave
57  * Initial checkin.
58  * 
59  * 1     10/07/98 10:50a Dave
60  * 
61  * 121   9/11/98 5:08p Dave
62  * More tweaks to kick notification system.
63  * 
64  * 120   9/04/98 3:52p Dave
65  * Put in validated mission updating and application during stats
66  * updating.
67  * 
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.
71  * 
72  * 118   7/24/98 11:15a Allender
73  * added 32bit checksumming stuff for validated missions
74  * 
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.
80  * 
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.
84  * 
85  * 115   6/12/98 2:49p Dave
86  * Patch 1.02 changes.
87  * 
88  * 114   6/10/98 2:56p Dave
89  * Substantial changes to reduce bandwidth and latency problems.
90  * 
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.
94  * 
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)
98  * 
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.
103  * 
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.
107  * team situations.
108  * 
109  * 109   5/11/98 11:40p Dave
110  * Stuff.
111  * 
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.
116  * 
117  * 107   5/07/98 6:31p Dave
118  * Fix sticky situations where players are dying/respawning when the game
119  * is ended.
120  * 
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.
124  * 
125  * 105   4/30/98 12:57a Dave
126  * Put in new mode for ship/weapon selection. Rearranged how game querying
127  * is done a bit.
128  * 
129  * $NoKeywords: $
130  */
131
132
133 #ifndef MULTI_UTIL_H
134 #define MULTI_UTIL_H
135
136 #include "psnet.h"
137
138 // prototypes instead of headers :)
139 struct net_player;
140 struct player;
141 struct button_info;
142 struct join_request;
143 struct physics_info;
144 struct object;
145 struct active_game;
146 struct ship;
147 struct server_item;
148 struct ship_info;
149
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
155
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 );
159
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);
175
176 extern int multi_num_players();
177 extern int multi_num_observers();
178 extern int multi_num_connections();
179
180 extern char* multi_random_death_word();
181 extern char* multi_random_chat_start();
182
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 );
187
188 extern object *multi_get_network_object( ushort net_signature );                // find a network object
189
190 void multi_find_ingame_join_pos(object *new_obj);
191
192 // return size of packed matrix
193 void multi_pack_orient_matrix(ubyte *data,matrix *m);
194
195 // return bytes processed
196 void multi_unpack_orient_matrix(ubyte *data,matrix *m);
197
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);
200
201 void multi_assign_player_ship( int net_player, object *objp, int ship_class );
202
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);
208
209 // called client-side every frame
210 void multi_maybe_send_ship_status();
211
212 // will be used server side _and_ client side. 
213 void multi_apply_ship_status(net_player *p,button_info *bi, int locally);
214
215 void multiplayer_match_target_speed(net_player *p);
216
217 void multi_subsys_update_all();
218
219 void server_verify_filesig(short player_id, ushort sum_sig, int length_sig);
220 int server_all_filesigs_ok();
221
222 void multi_untag_player_ships();
223
224 // broadcast alltime stats to everyone in the game
225 void multi_broadcast_stats(int stats_code);
226
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);
231
232 void multi_eval_socket_error(PSNET_SOCKET sock, int error);
233
234 void multi_maybe_send_repair_info(object *dest_obj, object *source_objp, int code);
235
236 int multi_is_valid_unknown_packet(ubyte type);
237
238 // create a bogus object for the standalone
239 void multi_create_standalone_object();
240
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);
243
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();
248
249 server_item *multi_new_server_item( void );
250 void multi_free_server_list();
251
252 // netgame options evaluation stuff
253 int multi_can_message(net_player *p);
254 int multi_can_end_mission(net_player *p);
255
256 int multi_eval_join_request(join_request *jr,net_addr_t *addr);
257
258 // called by any machine (client, host, server, standalone, etc), to begin warping out all player objects
259 void multi_warpout_all_players();
260
261 // determine the highest rank of any of the players in the game
262 int multi_get_highest_rank();
263
264 // called on the machine of the player who hit alt+j
265 void multi_handle_end_mission_request();
266
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();
269
270 // called by the file xfer subsytem when we start receiving a file
271 void multi_file_xfer_notify(int handle);
272
273 // return the lag/disconnected status of the game
274 int multi_query_lag_status();
275
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);
278
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);
281
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);
284
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);
287
288 // flush the multidata cache directory
289 void multi_flush_multidata_cache();
290
291 // flush all data from a previous mission before starting the next
292 void multi_flush_mission_stuff();
293
294 // should we ignore all controls and keypresses because of some multiplayer 
295 int multi_ignore_controls(int key = -1);
296
297 // if the kill limit has been reached by any given player
298 int multi_kill_limit_reached();
299
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);
302
303 // fill in Current_file_checksum and Current_file_length
304 void multi_get_mission_checksum(char *filename);
305
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);
310
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);
315
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);
320
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);
325
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);
330
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);
335
336 char multi_unit_to_char(float unit);
337 float multi_char_to_unit(float val);
338
339 // if we should render our ping time to the server in a multiplayer game
340 int multi_show_ingame_ping();
341
342 // if Game_current_mission_filename is a builtin multiplayer mission
343 int multi_is_builtin_mission();
344
345 int multi_get_connection_speed();
346
347 // if we're in tracker mode, do a validation update on all known missions
348 void multi_update_valid_missions();
349
350 // get a new id# for a player
351 short multi_get_new_id();
352
353 // make a bunch of fake players - don't rely on this to be very safe - its mostly used for interface testing
354 #ifndef NDEBUG
355 void multi_make_fake_players(int count);
356 #endif
357
358 #endif
359