]> icculus.org git repositories - taylor/freespace2.git/blob - src/network/multi_options.cpp
clean up Windows #include's and use winsock2
[taylor/freespace2.git] / src / network / multi_options.cpp
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/multi_options.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * $Log$
16  * Revision 1.6  2005/10/02 09:30:10  taylor
17  * sync up rest of big-endian network changes.  it should at least be as good as what's in FS2_Open now, only better :)
18  *
19  * Revision 1.5  2004/06/11 01:34:41  tigital
20  * byte-swapping changes for bigendian systems
21  *
22  * Revision 1.4  2003/05/25 02:30:43  taylor
23  * Freespace 1 support
24  *
25  * Revision 1.3  2002/06/09 04:41:23  relnev
26  * added copyright header
27  *
28  * Revision 1.2  2002/05/26 20:22:48  theoddone33
29  * Most of network/ works
30  *
31  * Revision 1.1.1.1  2002/05/03 03:28:10  root
32  * Initial import.
33  * 
34  * 
35  * 22    8/27/99 12:32a Dave
36  * Allow the user to specify a local port through the launcher.
37  * 
38  * 21    8/22/99 1:19p Dave
39  * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
40  * which d3d cards are detected.
41  * 
42  * 20    8/04/99 6:01p Dave
43  * Oops. Make sure standalones log in.
44  * 
45  * 19    7/09/99 9:51a Dave
46  * Added thick polyline code.
47  * 
48  * 18    5/03/99 8:32p Dave
49  * New version of multi host options screen.
50  * 
51  * 17    4/25/99 7:43p Dave
52  * Misc small bug fixes. Made sun draw properly.
53  * 
54  * 16    4/20/99 6:39p Dave
55  * Almost done with artillery targeting. Added support for downloading
56  * images on the PXO screen.
57  * 
58  * 15    3/10/99 6:50p Dave
59  * Changed the way we buffer packets for all clients. Optimized turret
60  * fired packets. Did some weapon firing optimizations.
61  * 
62  * 14    3/09/99 6:24p Dave
63  * More work on object update revamping. Identified several sources of
64  * unnecessary bandwidth.
65  * 
66  * 13    3/08/99 7:03p Dave
67  * First run of new object update system. Looks very promising.
68  * 
69  * 12    2/21/99 6:01p Dave
70  * Fixed standalone WSS packets. 
71  * 
72  * 11    2/19/99 2:55p Dave
73  * Temporary checking to report the winner of a squad war match.
74  * 
75  * 10    2/12/99 6:16p Dave
76  * Pre-mission Squad War code is 95% done.
77  * 
78  * 9     2/11/99 3:08p Dave
79  * PXO refresh button. Very preliminary squad war support.
80  * 
81  * 8     11/20/98 11:16a Dave
82  * Fixed up IPX support a bit. Making sure that switching modes and
83  * loading/saving pilot files maintains proper state.
84  * 
85  * 7     11/19/98 4:19p Dave
86  * Put IPX sockets back in psnet. Consolidated all multiplayer config
87  * files into one.
88  * 
89  * 6     11/19/98 8:03a Dave
90  * Full support for D3-style reliable sockets. Revamped packet lag/loss
91  * system, made it receiver side and at the lowest possible level.
92  * 
93  * 5     11/17/98 11:12a Dave
94  * Removed player identification by address. Now assign explicit id #'s.
95  * 
96  * 4     10/13/98 9:29a Dave
97  * Started neatening up freespace.h. Many variables renamed and
98  * reorganized. Added AlphaColors.[h,cpp]
99  * 
100  * 3     10/07/98 6:27p Dave
101  * Globalized mission and campaign file extensions. Removed Silent Threat
102  * special code. Moved \cache \players and \multidata into the \data
103  * directory.
104  * 
105  * 2     10/07/98 10:53a Dave
106  * Initial checkin.
107  * 
108  * 1     10/07/98 10:50a Dave
109  * 
110  * 20    9/10/98 1:17p Dave
111  * Put in code to flag missions and campaigns as being MD or not in Fred
112  * and Freespace. Put in multiplayer support for filtering out MD
113  * missions. Put in multiplayer popups for warning of non-valid missions.
114  * 
115  * 19    7/07/98 2:49p Dave
116  * UI bug fixes.
117  * 
118  * 18    6/04/98 11:04a Allender
119  * object update level stuff.  Don't reset to high when becoming an
120  * observer of any type.  default to low when guy is a dialup customer
121  * 
122  * 17    5/24/98 3:45a Dave
123  * Minor object update fixes. Justify channel information on PXO. Add a
124  * bunch of configuration stuff for the standalone.
125  * 
126  * 16    5/19/98 1:35a Dave
127  * Tweaked pxo interface. Added rankings url to pxo.cfg. Make netplayer
128  * local options update dynamically in netgames.
129  * 
130  * 15    5/08/98 5:05p Dave
131  * Go to the join game screen when quitting multiplayer. Fixed mission
132  * text chat bugs. Put mission type symbols on the create game list.
133  * Started updating standalone gui controls.
134  * 
135  * 14    5/06/98 12:36p Dave
136  * Make sure clients can leave the debrief screen easily at all times. Fix
137  * respawn count problem.
138  * 
139  * 13    5/03/98 7:04p Dave
140  * Make team vs. team work mores smoothly with standalone. Change how host
141  * interacts with standalone for picking missions. Put in a time limit for
142  * ingame join ship select. Fix ingame join ship select screen for Vasudan
143  * ship icons.
144  * 
145  * 12    5/03/98 2:52p Dave
146  * Removed multiplayer furball mode.
147  * 
148  * 11    4/23/98 6:18p Dave
149  * Store ETS values between respawns. Put kick feature in the text
150  * messaging system. Fixed text messaging system so that it doesn't
151  * process or trigger ship controls. Other UI fixes.
152  * 
153  * 10    4/22/98 5:53p Dave
154  * Large reworking of endgame sequencing. Updated multi host options
155  * screen for new artwork. Put in checks for host or team captains leaving
156  * midgame.
157  * 
158  * 9     4/16/98 11:39p Dave
159  * Put in first run of new multiplayer options screen. Still need to
160  * complete final tab.
161  * 
162  * 8     4/13/98 4:50p Dave
163  * Maintain status of weapon bank/links through respawns. Put # players on
164  * create game mission list. Make observer not have engine sounds. Make
165  * oberver pivot point correct. Fixed respawn value getting reset every
166  * time host options screen started.
167  * 
168  * 7     4/09/98 11:01p Dave
169  * Put in new multi host options screen. Tweaked multiplayer options a
170  * bit.
171  * 
172  * 6     4/09/98 5:43p Dave
173  * Remove all command line processing from the demo. Began work fixing up
174  * the new multi host options screen.
175  * 
176  * 5     4/06/98 6:37p Dave
177  * Put in max_observers netgame server option. Make sure host is always
178  * defaulted to alpha 1 or zeta 1. Changed create game so that MAX_PLAYERS
179  * can always join but need to be kicked before commit can happen. Put in
180  * support for server ending a game and notifying clients of a special
181  * condition.
182  * 
183  * 4     4/04/98 4:22p Dave
184  * First rev of UDP reliable sockets is done. Seems to work well if not
185  * overly burdened.
186  * 
187  * 3     4/03/98 1:03a Dave
188  * First pass at unreliable guaranteed delivery packets.
189  * 
190  * 2     3/31/98 4:51p Dave
191  * Removed medals screen and multiplayer buttons from demo version. Put in
192  * new pilot popup screen. Make ships in mp team vs. team have proper team
193  * ids. Make mp respawns a permanent option saved in the player file.
194  * 
195  * 1     3/30/98 6:24p Dave
196  *  
197  * 
198  * $NoKeywords: $
199  */
200
201 #include "cmdline.h"
202 #include "osregistry.h"
203 #include "multi.h"
204 #include "multimsgs.h"
205 #include "freespace.h"
206 #include "stand_server.h"
207 #include "multiutil.h"
208 #include "multi_voice.h"
209 #include "multi_options.h"
210 #include "multi_team.h"
211 #include "multi_fstracker.h"
212
213
214 // ----------------------------------------------------------------------------------
215 // MULTI OPTIONS DEFINES/VARS
216 //
217
218 // packet codes
219 #define MULTI_OPTION_SERVER                                             0                               // server update follows
220 #define MULTI_OPTION_LOCAL                                                      1                               // local netplayer options follow
221 #define MULTI_OPTION_START_GAME                                 2                               // host's start game options on the standalone server
222 #define MULTI_OPTION_MISSION                                            3                               // host's mission selection stuff on a standalone server
223
224 // global options
225 #define MULTI_CFG_FILE                                                          NOX("multi.cfg")
226 multi_global_options Multi_options_g;
227
228 char Multi_options_proxy[512] = "";
229 ushort Multi_options_proxy_port = 0;
230
231 // ----------------------------------------------------------------------------------
232 // MULTI OPTIONS FUNCTIONS
233 //
234
235 #ifdef MAKE_FS1
236 void multi_options_read_config_fs1();
237 #endif
238
239 // load in the config file
240 #define NEXT_TOKEN()                                            do { tok = strtok(NULL, "\n"); if(tok != NULL){ drop_leading_white_space(tok); drop_trailing_white_space(tok); } } while(0);
241 #define SETTING(s)                                              ( !SDL_strcasecmp(tok, s) )
242 void multi_options_read_config()
243 {
244         // set default value for the global multi options
245         memset(&Multi_options_g, 0, sizeof(multi_global_options));
246         Multi_options_g.protocol = NET_TCP;     
247
248         // do we have a forced port via commandline or registry?
249         ushort forced_port = (ushort)os_config_read_uint("Network", "ForcePort", 0);
250         Multi_options_g.port = (Cmdline_network_port >= 0) ? (ushort)Cmdline_network_port : forced_port == 0 ? (ushort)DEFAULT_GAME_PORT : forced_port;
251
252         Multi_options_g.log = (Cmdline_multi_log) ? 1 : 0;
253         Multi_options_g.datarate_cap = OO_HIGH_RATE_DEFAULT;
254         SDL_strlcpy(Multi_options_g.user_tracker_ip, "", SDL_arraysize(Multi_options_g.user_tracker_ip));
255         SDL_strlcpy(Multi_options_g.game_tracker_ip, "", SDL_arraysize(Multi_options_g.game_tracker_ip));
256         SDL_strlcpy(Multi_options_g.pxo_ip, "", SDL_arraysize(Multi_options_g.pxo_ip));
257         SDL_strlcpy(Multi_options_g.pxo_rank_url, "", SDL_arraysize(Multi_options_g.pxo_rank_url));
258         SDL_strlcpy(Multi_options_g.pxo_create_url, "", SDL_arraysize(Multi_options_g.pxo_create_url));
259         SDL_strlcpy(Multi_options_g.pxo_verify_url, "", SDL_arraysize(Multi_options_g.pxo_verify_url));
260         SDL_strlcpy(Multi_options_g.pxo_banner_url, "", SDL_arraysize(Multi_options_g.pxo_banner_url));
261
262         // standalone values
263         Multi_options_g.std_max_players = -1;
264         Multi_options_g.std_datarate = OBJ_UPDATE_HIGH;
265         Multi_options_g.std_voice = 1;
266         memset(Multi_options_g.std_passwd, 0, STD_PASSWD_LEN);
267         memset(Multi_options_g.std_pname, 0, STD_NAME_LEN);
268         Multi_options_g.std_framecap = 30;
269
270 #ifndef MAKE_FS1
271         CFILE *in;
272         char str[512];
273         char *tok = NULL;
274
275         // read in the config file
276         in = cfopen(MULTI_CFG_FILE, "rt", CFILE_NORMAL, CF_TYPE_DATA);
277         
278         // if we failed to open the config file, user default settings
279         if(in == NULL){
280                 nprintf(("Network","Failed to open network config file, using default settings\n"));            
281                 return;
282         }
283
284         while(!cfeof(in)){
285                 // read in the game info
286                 memset(str,0,512);
287                 cfgets(str,512,in);
288
289                 // parse the first line
290                 tok = strtok(str," \t");
291
292                 // check the token
293                 if(tok != NULL){
294                         drop_leading_white_space(tok);
295                         drop_trailing_white_space(tok);                 
296                 } else {
297                         continue;
298                 }               
299
300                 // all possible options
301                 // only standalone cares about the following options
302                 if(Is_standalone){
303                         if(SETTING("+pxo")){                    
304                                 // setup PXO mode
305                                 Multi_options_g.pxo = 1;
306                                 NEXT_TOKEN();
307                                 if(tok != NULL){
308                                         SDL_strlcpy(Multi_fs_tracker_channel, tok, SDL_arraysize(Multi_fs_tracker_channel));
309                                 }
310                         } else 
311                         if(SETTING("+name")){
312                                 // set the standalone server's permanent name
313                                 NEXT_TOKEN();
314                                 if(tok != NULL){
315                                         SDL_strlcpy(Multi_options_g.std_pname, tok, STD_NAME_LEN);
316                                 }
317                         } else 
318                         if(SETTING("+no_voice")){
319                                 // standalone won't allow voice transmission
320                                 Multi_options_g.std_voice = 0;
321                         } else
322                         if(SETTING("+max_players")){
323                                 // set the max # of players on the standalone
324                                 NEXT_TOKEN();
325                                 if(tok != NULL){
326                                         if(!((atoi(tok) < 1) || (atoi(tok) > MAX_PLAYERS))){
327                                                 Multi_options_g.std_max_players = atoi(tok);
328                                         }
329                                 }
330                         } else 
331                         if(SETTING("+ban")){
332                                 // ban a player
333                                 NEXT_TOKEN();
334                                 if(tok != NULL){
335                                         std_add_ban(tok);
336                                 }
337                         } else 
338                         if(SETTING("+passwd")){
339                                 // set the standalone host password
340                                 NEXT_TOKEN();
341                                 if(tok != NULL){
342                                         SDL_strlcpy(Multi_options_g.std_passwd, tok, STD_PASSWD_LEN);
343
344                                         STUB_FUNCTION;
345                                 }
346                         } else 
347                         if(SETTING("+low_update")){
348                                 // set standalone to low updates
349                                 Multi_options_g.std_datarate = OBJ_UPDATE_LOW;
350                         } else
351                         if(SETTING("+med_update")){
352                                 // set standalone to medium updates
353                                 Multi_options_g.std_datarate = OBJ_UPDATE_MEDIUM;
354                         } else 
355                         if(SETTING("+high_update")){
356                                 // set standalone to high updates
357                                 Multi_options_g.std_datarate = OBJ_UPDATE_HIGH;
358                         } else 
359                         if(SETTING("+lan_update")){
360                                 // set standalone to high updates
361                                 Multi_options_g.std_datarate = OBJ_UPDATE_LAN;
362                         } 
363                 }
364
365                 // common to all modes
366                 if(SETTING("+user_server")){
367                         // ip addr of user tracker
368                         NEXT_TOKEN();
369                         if(tok != NULL){
370                                 SDL_strlcpy(Multi_options_g.user_tracker_ip, tok, SDL_arraysize(Multi_options_g.user_tracker_ip));
371                         }
372                 } else
373                 if(SETTING("+game_server")){
374                         // ip addr of game tracker
375                         NEXT_TOKEN();
376                         if(tok != NULL){
377                                 SDL_strlcpy(Multi_options_g.game_tracker_ip, tok, SDL_arraysize(Multi_options_g.game_tracker_ip));
378                         }
379                 } else
380                 if(SETTING("+chat_server")){
381                         // ip addr of pxo chat server
382                         NEXT_TOKEN();
383                         if(tok != NULL){
384                                 SDL_strlcpy(Multi_options_g.pxo_ip, tok, SDL_arraysize(Multi_options_g.pxo_ip));
385                         }
386                 } else
387                 if(SETTING("+rank_url")){
388                         // url of pilot rankings page
389                         NEXT_TOKEN();
390                         if(tok != NULL){
391                                 SDL_strlcpy(Multi_options_g.pxo_rank_url, tok, SDL_arraysize(Multi_options_g.pxo_rank_url));
392                         }
393                 } else
394                 if(SETTING("+create_url")){
395                         // url of pxo account create page
396                         NEXT_TOKEN();
397                         if(tok != NULL){
398                                 SDL_strlcpy(Multi_options_g.pxo_create_url, tok, SDL_arraysize(Multi_options_g.pxo_create_url));
399                         }
400                 } else
401                 if(SETTING("+verify_url")){
402                         // url of pxo account verify page
403                         NEXT_TOKEN();
404                         if(tok != NULL){
405                                 SDL_strlcpy(Multi_options_g.pxo_verify_url, tok, SDL_arraysize(Multi_options_g.pxo_verify_url));
406                         }
407                 } else
408                 if(SETTING("+banner_url")){
409                         // url of pxo account verify page
410                         NEXT_TOKEN();
411                         if(tok != NULL){
412                                 SDL_strlcpy(Multi_options_g.pxo_banner_url, tok, SDL_arraysize(Multi_options_g.pxo_banner_url));
413                         }
414                 } else
415                 if(SETTING("+datarate")){
416                         // set the max datarate for high updates
417                         NEXT_TOKEN();
418                         if(tok != NULL){
419                                 if(atoi(tok) >= 4000){
420                                         Multi_options_g.datarate_cap = atoi(tok);
421                                 }
422                         }                       
423                 }
424                 if(SETTING("+http_proxy")){
425                         // get the proxy server
426                         NEXT_TOKEN();
427                         if(tok != NULL){                                
428                                 char *ip = strtok(tok, ":");
429                                 if(ip != NULL){
430                                         SDL_strlcpy(Multi_options_proxy, ip, SDL_arraysize(Multi_options_proxy));
431                                 }
432                                 ip = strtok(NULL, "");
433                                 if(ip != NULL){
434                                         Multi_options_proxy_port = (ushort)atoi(ip);
435                                 } else {
436                                         SDL_strlcpy(Multi_options_proxy, "", SDL_arraysize(Multi_options_proxy));
437                                 }
438                         }
439                 }
440         }
441
442         // close the config file
443         cfclose(in);
444         in = NULL;
445 #else
446         multi_options_read_config_fs1();
447 #endif
448 }
449
450 #ifdef MAKE_FS1
451 void multi_options_read_config_fs1()
452 {
453         CFILE *in;
454         char str[512];
455         char *tok = NULL;
456
457         SDL_zero(str);
458
459         // read in the pxo config file
460         in = cfopen("pxo.cfg", "rt", CFILE_NORMAL, CF_TYPE_DATA);
461
462         if (in != NULL) {
463                 // first line should be user tracker
464                 if ( cfgets(str, 512, in) ) {
465                         drop_leading_white_space(str);
466                         drop_trailing_white_space(str);
467
468                         SDL_strlcpy(Multi_options_g.user_tracker_ip, str, SDL_arraysize(Multi_options_g.user_tracker_ip));
469                 }
470
471                 // next line should be game tracker
472                 if ( cfgets(str, 512, in) ) {
473                         drop_leading_white_space(str);
474                         drop_trailing_white_space(str);
475
476                         SDL_strlcpy(Multi_options_g.game_tracker_ip, str, SDL_arraysize(Multi_options_g.game_tracker_ip));
477                 }
478
479                 // next, irc/chat server
480                 if ( cfgets(str, 512, in) ) {
481                         drop_leading_white_space(str);
482                         drop_trailing_white_space(str);
483
484                         SDL_strlcpy(Multi_options_g.pxo_ip, str, SDL_arraysize(Multi_options_g.pxo_ip));
485                 }
486
487                 // web link: rankings
488                 if ( cfgets(str, 512, in) ) {
489                         drop_leading_white_space(str);
490                         drop_trailing_white_space(str);
491
492                         SDL_strlcpy(Multi_options_g.pxo_rank_url, str, SDL_arraysize(Multi_options_g.pxo_rank_url));
493                 }
494
495                 // web link: register/create account
496                 if ( cfgets(str, 512, in) ) {
497                         drop_leading_white_space(str);
498                         drop_trailing_white_space(str);
499
500                         SDL_strlcpy(Multi_options_g.pxo_create_url, str, SDL_arraysize(Multi_options_g.pxo_create_url));
501                 }
502
503                 // web link: verify account/user
504                 if ( cfgets(str, 512, in) ) {
505                         drop_leading_white_space(str);
506                         drop_trailing_white_space(str);
507
508                         SDL_strlcpy(Multi_options_g.pxo_verify_url, str, SDL_arraysize(Multi_options_g.pxo_verify_url));
509                 }
510
511                 cfclose(in);
512                 in = NULL;
513         }
514
515         // maybe read standalone config
516         if (Is_standalone) {
517                 // read in the config file
518                 in = cfopen("std.cfg", "rt", CFILE_NORMAL, CF_TYPE_DATA);
519
520                 if (in != NULL) {
521                         while(!cfeof(in)){
522                                 // read in the game info
523                                 memset(str,0,512);
524                                 cfgets(str,512,in);
525
526                                 // parse the first line
527                                 tok = strtok(str," \t");
528
529                                 // check the token
530                                 if(tok != NULL){
531                                         drop_leading_white_space(tok);
532                                         drop_trailing_white_space(tok);
533                                 } else {
534                                         continue;
535                                 }
536
537                                 if(SETTING("+pxo")){
538                                         // setup PXO mode
539                                         NEXT_TOKEN();
540                                         if(tok != NULL){
541                                                 // whee!
542                                         }
543                                 } else
544                                 if(SETTING("+name")){
545                                         // set the standalone server's permanent name
546                                         NEXT_TOKEN();
547                                         if(tok != NULL){
548                                                 SDL_strlcpy(Multi_options_g.std_pname, tok, STD_NAME_LEN);
549                                         }
550                                 } else
551                                 if(SETTING("+no_voice")){
552                                         // standalone won't allow voice transmission
553                                         Multi_options_g.std_voice = 0;
554                                 } else
555                                 if(SETTING("+max_players")){
556                                         // set the max # of players on the standalone
557                                         NEXT_TOKEN();
558                                         if(tok != NULL){
559                                                 if(!((atoi(tok) < 1) || (atoi(tok) > MAX_PLAYERS))){
560                                                         Multi_options_g.std_max_players = atoi(tok);
561                                                 }
562                                         }
563                                 } else
564                                 if(SETTING("+ban")){
565                                         // ban a player
566                                         NEXT_TOKEN();
567                                         if(tok != NULL){
568                                                 std_add_ban(tok);
569                                         }
570                                 } else
571                                 if(SETTING("+passwd")){
572                                         // set the standalone host password
573                                         NEXT_TOKEN();
574                                         if(tok != NULL){
575                                                 SDL_strlcpy(Multi_options_g.std_passwd, tok, STD_PASSWD_LEN);
576
577                                                 STUB_FUNCTION;
578                                         }
579                                 } else
580                                 if(SETTING("+low_update")){
581                                         // set standalone to low updates
582                                         Multi_options_g.std_datarate = OBJ_UPDATE_LOW;
583                                 } else
584                                 if(SETTING("+med_update")){
585                                         // set standalone to medium updates
586                                         Multi_options_g.std_datarate = OBJ_UPDATE_MEDIUM;
587                                 } else
588                                 if(SETTING("+high_update")){
589                                         // set standalone to high updates
590                                         Multi_options_g.std_datarate = OBJ_UPDATE_HIGH;
591                                 } else
592                                 if(SETTING("+lan_update")){
593                                         // set standalone to high updates
594                                         Multi_options_g.std_datarate = OBJ_UPDATE_LAN;
595                                 }
596                         }
597                 }
598
599                 cfclose(in);
600                 in = NULL;
601         }
602 }
603 #endif
604
605 // set netgame defaults 
606 // NOTE : should be used when creating a newpilot
607 void multi_options_set_netgame_defaults(multi_server_options *options)
608 {
609         // any player can do squadmate messaging
610         options->squad_set = MSO_SQUAD_ANY;
611
612         // only the host can end the game
613         options->endgame_set = MSO_END_HOST;
614
615         // allow ingame file xfer and custom pilot pix
616         options->flags = (MSO_FLAG_INGAME_XFER | MSO_FLAG_ACCEPT_PIX);
617
618         // set the default time limit to be -1 (no limit)
619         options->mission_time_limit = fl2f(-1.0f);
620
621         // set the default max kills for a mission
622         options->kill_limit = 9999;
623
624         // set the default # of respawns
625         options->respawn = 2;
626
627         // set the default # of max observers
628         options->max_observers = 2;
629
630         // set the default netgame qos
631         options->voice_qos = 10;
632
633         // set the default token timeout
634         options->voice_token_wait = 2000;                               // he must wait 2 seconds between voice gets
635
636         // set the default max voice record time
637         options->voice_record_time = 5000;
638 }
639
640 // set local netplayer defaults
641 // NOTE : should be used when creating a newpilot
642 void multi_options_set_local_defaults(multi_local_options *options)
643 {
644         // accept pix by default and broadcast on the local subnet
645         options->flags = (MLO_FLAG_ACCEPT_PIX | MLO_FLAG_LOCAL_BROADCAST);      
646
647         // set the object update level based on the type of network connection specified by the user
648         // at install (or launcher) time.
649         if ( Psnet_connection == NETWORK_CONNECTION_DIALUP ) {
650                 options->obj_update_level = OBJ_UPDATE_LOW;
651         } else {
652                 options->obj_update_level = OBJ_UPDATE_HIGH;
653         }
654 }
655
656 // fill in the passed netgame options struct with the data from my player file data (only host/server should do this)
657 void multi_options_netgame_load(multi_server_options *options)
658 {
659         if(options != NULL){
660                 memcpy(options,&Player->m_server_options,sizeof(multi_server_options));
661         }       
662 }
663
664 // fill in the passed local options struct with the data from my player file data (all machines except standalone should do this)
665 void multi_options_local_load(multi_local_options *options, net_player *pxo_pl)
666 {
667         if(options != NULL){
668                 memcpy(options,&Player->m_local_options,sizeof(multi_local_options));
669         }
670
671         // stuff pxo squad info
672 #ifndef MAKE_FS1
673         if(pxo_pl != NULL){
674                 SDL_strlcpy(pxo_pl->p_info.pxo_squad_name, Multi_tracker_squad_name, LOGIN_LEN);
675         }
676 #endif
677 }
678
679 // update everyone on the current netgame options
680 void multi_options_update_netgame()
681 {
682         ubyte data[MAX_PACKET_SIZE],code;
683         int packet_size = 0;
684         
685         SDL_assert(Net_player->flags & NETINFO_FLAG_GAME_HOST);
686
687         // build the header and add the opcode
688         BUILD_HEADER(OPTIONS_UPDATE);
689         code = MULTI_OPTION_SERVER;
690         ADD_DATA(code);
691
692         // add the netgame options
693     Netgame.options.flags = INTEL_INT( Netgame.options.flags );
694     Netgame.options.respawn = INTEL_INT( Netgame.options.respawn );
695     Netgame.options.voice_token_wait = INTEL_INT( Netgame.options.voice_token_wait );
696     Netgame.options.voice_record_time = INTEL_INT( Netgame.options.voice_record_time );
697     Netgame.options.kill_limit= INTEL_INT( Netgame.options.kill_limit );
698     Netgame.options.mission_time_limit = (fix)INTEL_INT( Netgame.options.mission_time_limit );
699         ADD_DATA(Netgame.options);
700
701         // send the packet
702         if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
703                 multi_io_send_to_all_reliable(data, packet_size);
704         } else {
705                 multi_io_send_reliable(Net_player, data, packet_size);
706         }
707 }
708
709 // update everyone with my local settings
710 void multi_options_update_local()
711 {
712         ubyte data[MAX_PACKET_SIZE],code;
713         int packet_size = 0;
714         
715         // if i'm the server, don't do anything
716         if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
717                 return;
718         }
719
720         // build the header and add the opcode
721         BUILD_HEADER(OPTIONS_UPDATE);
722         code = MULTI_OPTION_LOCAL;
723         ADD_DATA(code);
724
725         // add the netgame options
726     Net_player->p_info.options.flags = INTEL_INT( Net_player->p_info.options.flags );
727     Net_players->p_info.options.obj_update_level = INTEL_INT( Net_player->p_info.options.obj_update_level );
728         ADD_DATA(Net_player->p_info.options);
729
730         // send the packet              
731         multi_io_send_reliable(Net_player, data, packet_size);
732 }
733
734 // update the standalone with the settings I have picked at the "start game" screen
735 void multi_options_update_start_game(netgame_info *ng)
736 {
737         ubyte data[MAX_PACKET_SIZE],code;
738         int packet_size = 0;
739
740         // should be a host on a standalone
741         SDL_assert((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER));
742
743         // build the header
744         BUILD_HEADER(OPTIONS_UPDATE);
745         code = MULTI_OPTION_START_GAME;
746         ADD_DATA(code);
747
748         // add the start game options
749         ADD_STRING(ng->name);
750         ADD_INT(ng->mode);
751         ADD_INT(ng->security);
752
753         // add mode-specific data
754         switch(ng->mode){
755         case NG_MODE_PASSWORD:
756                 ADD_STRING(ng->passwd);
757                 break;
758         case NG_MODE_RANK_ABOVE:
759         case NG_MODE_RANK_BELOW:
760                 ADD_INT(ng->rank_base);
761                 break;
762         }
763
764         // send to the standalone server        
765         multi_io_send_reliable(Net_player, data, packet_size);
766 }
767
768 // update the standalone with the mission settings I have picked (mission filename, etc)
769 void multi_options_update_mission(netgame_info *ng, int campaign_mode)
770 {
771         ubyte data[MAX_PACKET_SIZE],code;
772         int packet_size = 0;
773
774         // should be a host on a standalone
775         SDL_assert((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER));
776
777         // build the header
778         BUILD_HEADER(OPTIONS_UPDATE);
779         code = MULTI_OPTION_MISSION;
780         ADD_DATA(code);
781
782         // type (coop or team vs. team)
783         ADD_INT(ng->type_flags);
784
785         // respawns
786         ADD_UINT(ng->respawn);
787
788         // add the mission/campaign filename
789         code = (ubyte)campaign_mode;
790         ADD_DATA(code);
791         if(campaign_mode){
792                 ADD_STRING(ng->campaign_name);
793         } else {
794                 ADD_STRING(ng->mission_name);
795         }
796
797         // send to the server   
798         multi_io_send_reliable(Net_player, data, packet_size);
799 }
800
801
802 // ----------------------------------------------------------------------------------
803 // MULTI OPTIONS FUNCTIONS
804 //
805
806 // process an incoming multi options packet
807 void multi_options_process_packet(unsigned char *data, header *hinfo)
808 {
809         ubyte code;     
810         multi_local_options bogus;
811         int idx,player_index;
812         char str[255];
813         int offset = HEADER_LENGTH;
814
815         // find out who is sending this data    
816         player_index = find_player_id(hinfo->id);
817
818         // get the packet code
819         GET_DATA(code);
820         switch(code){
821         // get the start game options
822         case MULTI_OPTION_START_GAME:
823                 SDL_assert(Game_mode & GM_STANDALONE_SERVER);
824
825                 // get the netgame name
826                 GET_STRING(Netgame.name);               
827
828                 // get the netgame mode
829                 GET_INT(Netgame.mode);
830
831                 // get the security #
832                 GET_INT(Netgame.security);
833
834                 // get mode specific data
835                 switch(Netgame.mode){
836                 case NG_MODE_PASSWORD:
837                         GET_STRING(Netgame.passwd);
838                         break;
839                 case NG_MODE_RANK_ABOVE:
840                 case NG_MODE_RANK_BELOW:
841                         GET_INT(Netgame.rank_base);
842                         break;
843                 }
844
845                 // update standalone stuff
846                 std_connect_set_gamename(Netgame.name);
847                 std_multi_update_netgame_info_controls();
848                 break;
849
850         // get mission choice options
851         case MULTI_OPTION_MISSION:
852                 netgame_info ng;
853                 char title[NAME_LENGTH+1];
854                 int campaign_type,max_players;
855                 
856                 SDL_zero(ng);
857
858                 SDL_assert(Game_mode & GM_STANDALONE_SERVER);
859
860                 // coop or team vs. team mode
861                 GET_INT(ng.type_flags);
862                 if((ng.type_flags & NG_TYPE_TEAM) && !(Netgame.type_flags & NG_TYPE_TEAM)){
863                         multi_team_reset();
864                 }
865                 // if squad war was switched on
866                 if((ng.type_flags & NG_TYPE_SW) && !(Netgame.type_flags & NG_TYPE_SW)){
867                         mprintf(("STANDALONE TURNED ON SQUAD WAR!!\n"));
868                 }
869                 Netgame.type_flags = ng.type_flags;
870
871                 // new respawn count
872                 GET_UINT(Netgame.respawn);
873
874                 // name string
875                 SDL_zero(str);
876
877                 GET_DATA(code);
878                 // campaign mode
879                 if(code){
880                         GET_STRING(ng.campaign_name);
881
882                         // set the netgame max players here if the filename has changed
883                         if(strcmp(Netgame.campaign_name,ng.campaign_name)){
884                                 SDL_zero(title);
885                                 if(!mission_campaign_get_info(ng.campaign_name,title,&campaign_type,&max_players)){
886                                         Netgame.max_players = 0;
887                                 } else {
888                                         Netgame.max_players = max_players;
889                                 }
890
891                                 SDL_strlcpy(Netgame.campaign_name, ng.campaign_name, SDL_arraysize(Netgame.campaign_name));
892                         }
893
894                         Netgame.campaign_mode = 1;
895
896                         // put brackets around the campaign name
897                         if(Game_mode & GM_STANDALONE_SERVER){
898                                 SDL_snprintf(str, SDL_arraysize(str), "(%s)", Netgame.campaign_name);
899                                 std_multi_set_standalone_mission_name(str);
900                         }
901                 }
902                 // non-campaign mode
903                 else {
904                         GET_STRING(ng.mission_name);
905
906                         if(strcmp(Netgame.mission_name,ng.mission_name)){
907                                 if(strlen(ng.mission_name)){
908                                         Netgame.max_players = mission_parse_get_multi_mission_info( ng.mission_name );
909                                 } else {
910                                         // setting this to -1 will prevent us from being seen on the network
911                                         Netgame.max_players = -1;                               
912                                 }
913                                 SDL_strlcpy(Netgame.mission_name, ng.mission_name, SDL_arraysize(Netgame.mission_name));
914                                 SDL_strlcpy(Game_current_mission_filename, Netgame.mission_name, SDL_arraysize(Game_current_mission_filename));
915                         }                       
916
917                         Netgame.campaign_mode = 0;
918
919                         // set the mission name
920                         if(Game_mode & GM_STANDALONE_SERVER){
921                                 std_multi_set_standalone_mission_name(Netgame.mission_name);                    
922                         }
923                 }
924                 
925                 send_netgame_update_packet();      
926                 break;
927
928         // get the netgame options
929         case MULTI_OPTION_SERVER:               
930                 GET_DATA(Netgame.options);
931         Netgame.options.flags = INTEL_INT( Netgame.options.flags );
932         Netgame.options.respawn = INTEL_INT( Netgame.options.respawn );
933         Netgame.options.voice_token_wait = INTEL_INT( Netgame.options.voice_token_wait );
934         Netgame.options.voice_record_time = INTEL_INT( Netgame.options.voice_record_time );
935         Netgame.options.kill_limit = INTEL_INT( Netgame.options.kill_limit );
936         Netgame.options.mission_time_limit = (fix)INTEL_INT( Netgame.options.mission_time_limit );
937
938                 // if we're a standalone set for no sound, do so here
939                 if((Game_mode & GM_STANDALONE_SERVER) && !Multi_options_g.std_voice){
940                         Netgame.options.flags |= MSO_FLAG_NO_VOICE;
941                 } else {
942                         // maybe update the quality of sound
943                         multi_voice_maybe_update_vars(Netgame.options.voice_qos,Netgame.options.voice_record_time);
944                 }
945
946                 // set the skill level
947                 Game_skill_level = Netgame.options.skill_level;         
948
949                 if((Game_mode & GM_STANDALONE_SERVER) && !(Game_mode & GM_CAMPAIGN_MODE)){
950                         Netgame.respawn = Netgame.options.respawn;
951                 }
952
953                 // if we have the "temp closed" flag toggle
954                 if(Netgame.options.flags & MLO_FLAG_TEMP_CLOSED){
955                         Netgame.flags ^= NG_FLAG_TEMP_CLOSED;
956                 }
957                 Netgame.options.flags &= ~(MLO_FLAG_TEMP_CLOSED);
958
959                 // if i'm the standalone server, I should rebroadcast to all other players
960                 if(Game_mode & GM_STANDALONE_SERVER){
961                         for(idx=0;idx<MAX_PLAYERS;idx++){
962                                 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx]) && (&Net_players[idx] != &Net_players[player_index]) ){
963                                         multi_io_send_reliable(&Net_players[idx], data, offset);
964                                 }
965                         }
966
967                         send_netgame_update_packet();
968                 }
969                 break;
970         
971         // local netplayer options
972         case MULTI_OPTION_LOCAL:
973                 if(player_index == -1){
974                         GET_DATA(bogus);        //data not used, so don't swap!
975         } else {
976                         GET_DATA(Net_players[player_index].p_info.options);
977             Net_players[player_index].p_info.options.flags = INTEL_INT( Net_players[player_index].p_info.options.flags );
978             Net_players[player_index].p_info.options.obj_update_level = INTEL_INT( Net_players[player_index].p_info.options.obj_update_level );            
979                 }               
980                 break;
981         }
982         PACKET_SET_SIZE();
983 }
984
985
986
987