]> icculus.org git repositories - taylor/freespace2.git/blob - src/network/multi_options.cpp
make PXO off by default globally, on by default for new pilots
[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 #include "multi_pxo.h"
213
214
215 // ----------------------------------------------------------------------------------
216 // MULTI OPTIONS DEFINES/VARS
217 //
218
219 // packet codes
220 #define MULTI_OPTION_SERVER                                             0                               // server update follows
221 #define MULTI_OPTION_LOCAL                                                      1                               // local netplayer options follow
222 #define MULTI_OPTION_START_GAME                                 2                               // host's start game options on the standalone server
223 #define MULTI_OPTION_MISSION                                            3                               // host's mission selection stuff on a standalone server
224
225 // global options
226 #define MULTI_CFG_FILE                                                          NOX("multi.cfg")
227 multi_global_options Multi_options_g;
228
229 char Multi_options_proxy[512] = "";
230 ushort Multi_options_proxy_port = 0;
231
232 // ----------------------------------------------------------------------------------
233 // MULTI OPTIONS FUNCTIONS
234 //
235
236 #ifdef MAKE_FS1
237 void multi_options_read_config_fs1();
238 #endif
239
240 // load in the config file
241 #define NEXT_TOKEN()                                            do { tok = strtok(NULL, "\n"); if(tok != NULL){ drop_leading_white_space(tok); drop_trailing_white_space(tok); } } while(0);
242 #define SETTING(s)                                              ( !SDL_strcasecmp(tok, s) )
243 void multi_options_read_config()
244 {
245         // set default value for the global multi options
246         memset(&Multi_options_g, 0, sizeof(multi_global_options));
247         Multi_options_g.protocol = NET_TCP;
248         Multi_options_g.pxo = 0;
249
250         // do we have a forced port via commandline or registry?
251         ushort forced_port = (ushort)os_config_read_uint("Network", "ForcePort", 0);
252         Multi_options_g.port = (Cmdline_network_port >= 0) ? (ushort)Cmdline_network_port : forced_port == 0 ? (ushort)DEFAULT_GAME_PORT : forced_port;
253
254         Multi_options_g.log = (Cmdline_multi_log) ? 1 : 0;
255         Multi_options_g.datarate_cap = OO_HIGH_RATE_DEFAULT;
256         SDL_strlcpy(Multi_options_g.user_tracker_ip, MULTI_PXO_USER_TRACKER_IP, SDL_arraysize(Multi_options_g.user_tracker_ip));
257         SDL_strlcpy(Multi_options_g.game_tracker_ip, MULTI_PXO_GAME_TRACKER_IP, SDL_arraysize(Multi_options_g.game_tracker_ip));
258         SDL_strlcpy(Multi_options_g.pxo_ip, MULTI_PXO_CHAT_IP, SDL_arraysize(Multi_options_g.pxo_ip));
259         SDL_strlcpy(Multi_options_g.pxo_rank_url, MULTI_PXO_RANKINGS_URL, SDL_arraysize(Multi_options_g.pxo_rank_url));
260         SDL_strlcpy(Multi_options_g.pxo_create_url, MULTI_PXO_CREATE_URL, SDL_arraysize(Multi_options_g.pxo_create_url));
261         SDL_strlcpy(Multi_options_g.pxo_verify_url, MULTI_PXO_VERIFY_URL, SDL_arraysize(Multi_options_g.pxo_verify_url));
262         SDL_strlcpy(Multi_options_g.pxo_banner_url, MULTI_PXO_BANNER_URL, SDL_arraysize(Multi_options_g.pxo_banner_url));
263
264         // standalone values
265         Multi_options_g.std_max_players = -1;
266         Multi_options_g.std_datarate = OBJ_UPDATE_HIGH;
267         Multi_options_g.std_voice = 1;
268         memset(Multi_options_g.std_passwd, 0, STD_PASSWD_LEN);
269         memset(Multi_options_g.std_pname, 0, STD_NAME_LEN);
270         Multi_options_g.std_framecap = 60;
271
272 #ifndef MAKE_FS1
273         CFILE *in;
274         char str[512];
275         char *tok = NULL;
276
277         // read in the config file
278         in = cfopen(MULTI_CFG_FILE, "rt", CFILE_NORMAL, CF_TYPE_DATA);
279         
280         // if we failed to open the config file, user default settings
281         if(in == NULL){
282                 nprintf(("Network","Failed to open network config file, using default settings\n"));            
283                 return;
284         }
285
286         while(!cfeof(in)){
287                 // read in the game info
288                 memset(str,0,512);
289                 cfgets(str,512,in);
290
291                 // parse the first line
292                 tok = strtok(str," \t");
293
294                 // check the token
295                 if(tok != NULL){
296                         drop_leading_white_space(tok);
297                         drop_trailing_white_space(tok);                 
298                 } else {
299                         continue;
300                 }               
301
302                 // all possible options
303                 // only standalone cares about the following options
304                 if(Is_standalone){
305                         if(SETTING("+pxo")){                    
306                                 // setup PXO mode
307                                 Multi_options_g.pxo = 1;
308                                 NEXT_TOKEN();
309                                 if(tok != NULL){
310                                         SDL_strlcpy(Multi_fs_tracker_channel, tok, SDL_arraysize(Multi_fs_tracker_channel));
311                                 }
312                         } else 
313                         if(SETTING("+name")){
314                                 // set the standalone server's permanent name
315                                 NEXT_TOKEN();
316                                 if(tok != NULL){
317                                         SDL_strlcpy(Multi_options_g.std_pname, tok, STD_NAME_LEN);
318                                 }
319                         } else 
320                         if(SETTING("+no_voice")){
321                                 // standalone won't allow voice transmission
322                                 Multi_options_g.std_voice = 0;
323                         } else
324                         if(SETTING("+max_players")){
325                                 // set the max # of players on the standalone
326                                 NEXT_TOKEN();
327                                 if(tok != NULL){
328                                         if(!((atoi(tok) < 1) || (atoi(tok) > MAX_PLAYERS))){
329                                                 Multi_options_g.std_max_players = atoi(tok);
330                                         }
331                                 }
332                         } else 
333                         if(SETTING("+ban")){
334                                 // ban a player
335                                 NEXT_TOKEN();
336                                 if(tok != NULL){
337                                         std_add_ban(tok);
338                                 }
339                         } else 
340                         if(SETTING("+passwd")){
341                                 // set the standalone host password
342                                 NEXT_TOKEN();
343                                 if(tok != NULL){
344                                         SDL_strlcpy(Multi_options_g.std_passwd, tok, STD_PASSWD_LEN);
345
346                                         STUB_FUNCTION;
347                                 }
348                         } else 
349                         if(SETTING("+low_update")){
350                                 // set standalone to low updates
351                                 Multi_options_g.std_datarate = OBJ_UPDATE_LOW;
352                         } else
353                         if(SETTING("+med_update")){
354                                 // set standalone to medium updates
355                                 Multi_options_g.std_datarate = OBJ_UPDATE_MEDIUM;
356                         } else 
357                         if(SETTING("+high_update")){
358                                 // set standalone to high updates
359                                 Multi_options_g.std_datarate = OBJ_UPDATE_HIGH;
360                         } else 
361                         if(SETTING("+lan_update")){
362                                 // set standalone to high updates
363                                 Multi_options_g.std_datarate = OBJ_UPDATE_LAN;
364                         } 
365                 }
366
367                 if (tok == NULL) {
368                         continue;
369                 }
370
371                 // common to all modes
372                 if(SETTING("+user_server")){
373                         // ip addr of user tracker
374                         NEXT_TOKEN();
375                         if(tok != NULL){
376                                 SDL_strlcpy(Multi_options_g.user_tracker_ip, tok, SDL_arraysize(Multi_options_g.user_tracker_ip));
377                         }
378                 } else
379                 if(SETTING("+game_server")){
380                         // ip addr of game tracker
381                         NEXT_TOKEN();
382                         if(tok != NULL){
383                                 SDL_strlcpy(Multi_options_g.game_tracker_ip, tok, SDL_arraysize(Multi_options_g.game_tracker_ip));
384                         }
385                 } else
386                 if(SETTING("+chat_server")){
387                         // ip addr of pxo chat server
388                         NEXT_TOKEN();
389                         if(tok != NULL){
390                                 SDL_strlcpy(Multi_options_g.pxo_ip, tok, SDL_arraysize(Multi_options_g.pxo_ip));
391                         }
392                 } else
393                 if(SETTING("+rank_url")){
394                         // url of pilot rankings page
395                         NEXT_TOKEN();
396                         if(tok != NULL){
397                                 SDL_strlcpy(Multi_options_g.pxo_rank_url, tok, SDL_arraysize(Multi_options_g.pxo_rank_url));
398                         }
399                 } else
400                 if(SETTING("+create_url")){
401                         // url of pxo account create page
402                         NEXT_TOKEN();
403                         if(tok != NULL){
404                                 SDL_strlcpy(Multi_options_g.pxo_create_url, tok, SDL_arraysize(Multi_options_g.pxo_create_url));
405                         }
406                 } else
407                 if(SETTING("+verify_url")){
408                         // url of pxo account verify page
409                         NEXT_TOKEN();
410                         if(tok != NULL){
411                                 SDL_strlcpy(Multi_options_g.pxo_verify_url, tok, SDL_arraysize(Multi_options_g.pxo_verify_url));
412                         }
413                 } else
414                 if(SETTING("+banner_url")){
415                         // url of pxo account verify page
416                         NEXT_TOKEN();
417                         if(tok != NULL){
418                                 SDL_strlcpy(Multi_options_g.pxo_banner_url, tok, SDL_arraysize(Multi_options_g.pxo_banner_url));
419                         }
420                 } else
421                 if(SETTING("+datarate")){
422                         // set the max datarate for high updates
423                         NEXT_TOKEN();
424                         if(tok != NULL){
425                                 if(atoi(tok) >= 4000){
426                                         Multi_options_g.datarate_cap = atoi(tok);
427                                 }
428                         }                       
429                 } else
430                 if(SETTING("+http_proxy")){
431                         // get the proxy server
432                         NEXT_TOKEN();
433                         if(tok != NULL){                                
434                                 char *ip = strtok(tok, ":");
435                                 if(ip != NULL){
436                                         SDL_strlcpy(Multi_options_proxy, ip, SDL_arraysize(Multi_options_proxy));
437                                 }
438                                 ip = strtok(NULL, "");
439                                 if(ip != NULL){
440                                         Multi_options_proxy_port = (ushort)atoi(ip);
441                                 } else {
442                                         SDL_strlcpy(Multi_options_proxy, "", SDL_arraysize(Multi_options_proxy));
443                                 }
444                         }
445                 }
446         }
447
448         // close the config file
449         cfclose(in);
450         in = NULL;
451 #else
452         multi_options_read_config_fs1();
453 #endif
454 }
455
456 #ifdef MAKE_FS1
457 void multi_options_read_config_fs1()
458 {
459         CFILE *in;
460         char str[512];
461         char *tok = NULL;
462
463 #ifdef FS1_DEMO
464         // FS1 demo is single-player only, so don't bother with this
465         return;
466 #endif
467
468         SDL_zero(str);
469
470         // read in the pxo config file
471         in = cfopen("pxo.cfg", "rt", CFILE_NORMAL, CF_TYPE_DATA);
472
473         if (in != NULL) {
474                 // first line should be user tracker
475                 if ( cfgets(str, 512, in) ) {
476                         drop_leading_white_space(str);
477                         drop_trailing_white_space(str);
478
479                         SDL_strlcpy(Multi_options_g.user_tracker_ip, str, SDL_arraysize(Multi_options_g.user_tracker_ip));
480                 }
481
482                 // next line should be game tracker
483                 if ( cfgets(str, 512, in) ) {
484                         drop_leading_white_space(str);
485                         drop_trailing_white_space(str);
486
487                         SDL_strlcpy(Multi_options_g.game_tracker_ip, str, SDL_arraysize(Multi_options_g.game_tracker_ip));
488                 }
489
490                 // next, irc/chat server
491                 if ( cfgets(str, 512, in) ) {
492                         drop_leading_white_space(str);
493                         drop_trailing_white_space(str);
494
495                         SDL_strlcpy(Multi_options_g.pxo_ip, str, SDL_arraysize(Multi_options_g.pxo_ip));
496                 }
497
498                 // web link: rankings
499                 if ( cfgets(str, 512, in) ) {
500                         drop_leading_white_space(str);
501                         drop_trailing_white_space(str);
502
503                         SDL_strlcpy(Multi_options_g.pxo_rank_url, str, SDL_arraysize(Multi_options_g.pxo_rank_url));
504                 }
505
506                 // web link: register/create account
507                 if ( cfgets(str, 512, in) ) {
508                         drop_leading_white_space(str);
509                         drop_trailing_white_space(str);
510
511                         SDL_strlcpy(Multi_options_g.pxo_create_url, str, SDL_arraysize(Multi_options_g.pxo_create_url));
512                 }
513
514                 // web link: verify account/user
515                 if ( cfgets(str, 512, in) ) {
516                         drop_leading_white_space(str);
517                         drop_trailing_white_space(str);
518
519                         SDL_strlcpy(Multi_options_g.pxo_verify_url, str, SDL_arraysize(Multi_options_g.pxo_verify_url));
520                 }
521
522                 cfclose(in);
523                 in = NULL;
524         }
525
526         // maybe read standalone config
527         if (Is_standalone) {
528                 // read in the config file
529                 in = cfopen("std.cfg", "rt", CFILE_NORMAL, CF_TYPE_DATA);
530
531                 if (in != NULL) {
532                         while(!cfeof(in)){
533                                 // read in the game info
534                                 memset(str,0,512);
535                                 cfgets(str,512,in);
536
537                                 // parse the first line
538                                 tok = strtok(str," \t");
539
540                                 // check the token
541                                 if(tok != NULL){
542                                         drop_leading_white_space(tok);
543                                         drop_trailing_white_space(tok);
544                                 } else {
545                                         continue;
546                                 }
547
548                                 if(SETTING("+pxo")){
549                                         // setup PXO mode
550                                         NEXT_TOKEN();
551                                         if(tok != NULL){
552                                                 // whee!
553                                         }
554                                 } else
555                                 if(SETTING("+name")){
556                                         // set the standalone server's permanent name
557                                         NEXT_TOKEN();
558                                         if(tok != NULL){
559                                                 SDL_strlcpy(Multi_options_g.std_pname, tok, STD_NAME_LEN);
560                                         }
561                                 } else
562                                 if(SETTING("+no_voice")){
563                                         // standalone won't allow voice transmission
564                                         Multi_options_g.std_voice = 0;
565                                 } else
566                                 if(SETTING("+max_players")){
567                                         // set the max # of players on the standalone
568                                         NEXT_TOKEN();
569                                         if(tok != NULL){
570                                                 if(!((atoi(tok) < 1) || (atoi(tok) > MAX_PLAYERS))){
571                                                         Multi_options_g.std_max_players = atoi(tok);
572                                                 }
573                                         }
574                                 } else
575                                 if(SETTING("+ban")){
576                                         // ban a player
577                                         NEXT_TOKEN();
578                                         if(tok != NULL){
579                                                 std_add_ban(tok);
580                                         }
581                                 } else
582                                 if(SETTING("+passwd")){
583                                         // set the standalone host password
584                                         NEXT_TOKEN();
585                                         if(tok != NULL){
586                                                 SDL_strlcpy(Multi_options_g.std_passwd, tok, STD_PASSWD_LEN);
587
588                                                 STUB_FUNCTION;
589                                         }
590                                 } else
591                                 if(SETTING("+low_update")){
592                                         // set standalone to low updates
593                                         Multi_options_g.std_datarate = OBJ_UPDATE_LOW;
594                                 } else
595                                 if(SETTING("+med_update")){
596                                         // set standalone to medium updates
597                                         Multi_options_g.std_datarate = OBJ_UPDATE_MEDIUM;
598                                 } else
599                                 if(SETTING("+high_update")){
600                                         // set standalone to high updates
601                                         Multi_options_g.std_datarate = OBJ_UPDATE_HIGH;
602                                 } else
603                                 if(SETTING("+lan_update")){
604                                         // set standalone to high updates
605                                         Multi_options_g.std_datarate = OBJ_UPDATE_LAN;
606                                 }
607                         }
608                 }
609
610                 cfclose(in);
611                 in = NULL;
612         }
613 }
614 #endif
615
616 // set netgame defaults 
617 // NOTE : should be used when creating a newpilot
618 void multi_options_set_netgame_defaults(multi_server_options *options)
619 {
620         // any player can do squadmate messaging
621         options->squad_set = MSO_SQUAD_ANY;
622
623         // only the host can end the game
624         options->endgame_set = MSO_END_HOST;
625
626         // allow ingame file xfer and custom pilot pix
627         options->flags = (MSO_FLAG_INGAME_XFER | MSO_FLAG_ACCEPT_PIX);
628
629         // set the default time limit to be -1 (no limit)
630         options->mission_time_limit = fl2f(-1.0f);
631
632         // set the default max kills for a mission
633 #ifdef MAKE_FS1
634         options->kill_limit = 99999;
635 #else
636         options->kill_limit = 9999;
637 #endif
638
639         // set the default # of respawns
640         options->respawn = 2;
641
642         // set the default # of max observers
643         options->max_observers = 2;
644
645         // set the default netgame qos
646         options->voice_qos = 10;
647
648         // set the default token timeout
649         options->voice_token_wait = 2000;                               // he must wait 2 seconds between voice gets
650
651         // set the default max voice record time
652         options->voice_record_time = 5000;
653 }
654
655 // set local netplayer defaults
656 // NOTE : should be used when creating a newpilot
657 void multi_options_set_local_defaults(multi_local_options *options)
658 {
659         // accept pix by default and broadcast on the local subnet
660         options->flags = (MLO_FLAG_ACCEPT_PIX | MLO_FLAG_LOCAL_BROADCAST);      
661
662         // set the object update level based on the type of network connection specified by the user
663         // at install (or launcher) time.
664         if ( Psnet_connection == NETWORK_CONNECTION_DIALUP ) {
665                 options->obj_update_level = OBJ_UPDATE_LOW;
666         } else {
667                 options->obj_update_level = OBJ_UPDATE_HIGH;
668         }
669 }
670
671 // fill in the passed netgame options struct with the data from my player file data (only host/server should do this)
672 void multi_options_netgame_load(multi_server_options *options)
673 {
674         if(options != NULL){
675                 memcpy(options,&Player->m_server_options,sizeof(multi_server_options));
676         }       
677 }
678
679 // fill in the passed local options struct with the data from my player file data (all machines except standalone should do this)
680 void multi_options_local_load(multi_local_options *options, net_player *pxo_pl)
681 {
682         if(options != NULL){
683                 memcpy(options,&Player->m_local_options,sizeof(multi_local_options));
684         }
685
686         // stuff pxo squad info
687 #ifndef MAKE_FS1
688         if(pxo_pl != NULL){
689                 SDL_strlcpy(pxo_pl->p_info.pxo_squad_name, Multi_tracker_squad_name, LOGIN_LEN);
690         }
691 #endif
692 }
693
694 // update everyone on the current netgame options
695 void multi_options_update_netgame()
696 {
697         ubyte data[MAX_PACKET_SIZE],code;
698         int packet_size = 0;
699         
700         SDL_assert(Net_player->flags & NETINFO_FLAG_GAME_HOST);
701
702         // build the header and add the opcode
703         BUILD_HEADER(OPTIONS_UPDATE);
704         code = MULTI_OPTION_SERVER;
705         ADD_DATA(code);
706
707         // add the netgame options
708     Netgame.options.flags = INTEL_INT( Netgame.options.flags );
709     Netgame.options.respawn = INTEL_INT( Netgame.options.respawn );
710     Netgame.options.voice_token_wait = INTEL_INT( Netgame.options.voice_token_wait );
711     Netgame.options.voice_record_time = INTEL_INT( Netgame.options.voice_record_time );
712     Netgame.options.kill_limit= INTEL_INT( Netgame.options.kill_limit );
713     Netgame.options.mission_time_limit = (fix)INTEL_INT( Netgame.options.mission_time_limit );
714         ADD_DATA(Netgame.options);
715
716         // send the packet
717         if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
718                 multi_io_send_to_all_reliable(data, packet_size);
719         } else {
720                 multi_io_send_reliable(Net_player, data, packet_size);
721         }
722 }
723
724 // update everyone with my local settings
725 void multi_options_update_local()
726 {
727         ubyte data[MAX_PACKET_SIZE],code;
728         int packet_size = 0;
729         
730         // if i'm the server, don't do anything
731         if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
732                 return;
733         }
734
735         // build the header and add the opcode
736         BUILD_HEADER(OPTIONS_UPDATE);
737         code = MULTI_OPTION_LOCAL;
738         ADD_DATA(code);
739
740         // add the netgame options
741     Net_player->p_info.options.flags = INTEL_INT( Net_player->p_info.options.flags );
742     Net_players->p_info.options.obj_update_level = INTEL_INT( Net_player->p_info.options.obj_update_level );
743         ADD_DATA(Net_player->p_info.options);
744
745         // send the packet              
746         multi_io_send_reliable(Net_player, data, packet_size);
747 }
748
749 // update the standalone with the settings I have picked at the "start game" screen
750 void multi_options_update_start_game(netgame_info *ng)
751 {
752         ubyte data[MAX_PACKET_SIZE],code;
753         int packet_size = 0;
754
755         // should be a host on a standalone
756         SDL_assert((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER));
757
758         // build the header
759         BUILD_HEADER(OPTIONS_UPDATE);
760         code = MULTI_OPTION_START_GAME;
761         ADD_DATA(code);
762
763         // add the start game options
764         ADD_STRING(ng->name);
765         ADD_INT(ng->mode);
766         ADD_INT(ng->security);
767
768         // add mode-specific data
769         switch(ng->mode){
770         case NG_MODE_PASSWORD:
771                 ADD_STRING(ng->passwd);
772                 break;
773         case NG_MODE_RANK_ABOVE:
774         case NG_MODE_RANK_BELOW:
775                 ADD_INT(ng->rank_base);
776                 break;
777         }
778
779         // send to the standalone server        
780         multi_io_send_reliable(Net_player, data, packet_size);
781 }
782
783 // update the standalone with the mission settings I have picked (mission filename, etc)
784 void multi_options_update_mission(netgame_info *ng, int campaign_mode)
785 {
786         ubyte data[MAX_PACKET_SIZE],code;
787         int packet_size = 0;
788
789         // should be a host on a standalone
790         SDL_assert((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER));
791
792         // build the header
793         BUILD_HEADER(OPTIONS_UPDATE);
794         code = MULTI_OPTION_MISSION;
795         ADD_DATA(code);
796
797         // type (coop or team vs. team)
798         ADD_INT(ng->type_flags);
799
800         // respawns
801         ADD_UINT(ng->respawn);
802
803         // add the mission/campaign filename
804         code = (ubyte)campaign_mode;
805         ADD_DATA(code);
806         if(campaign_mode){
807                 ADD_STRING(ng->campaign_name);
808         } else {
809                 ADD_STRING(ng->mission_name);
810         }
811
812         // send to the server   
813         multi_io_send_reliable(Net_player, data, packet_size);
814 }
815
816
817 // ----------------------------------------------------------------------------------
818 // MULTI OPTIONS FUNCTIONS
819 //
820
821 // process an incoming multi options packet
822 void multi_options_process_packet(unsigned char *data, header *hinfo)
823 {
824         ubyte code;     
825         multi_local_options bogus;
826         int idx,player_index;
827         char str[255];
828         int offset = HEADER_LENGTH;
829
830         // find out who is sending this data    
831         player_index = find_player_id(hinfo->id);
832
833         // get the packet code
834         GET_DATA(code);
835         switch(code){
836         // get the start game options
837         case MULTI_OPTION_START_GAME:
838                 SDL_assert(Game_mode & GM_STANDALONE_SERVER);
839
840                 // get the netgame name
841                 GET_STRING(Netgame.name);               
842
843                 // get the netgame mode
844                 GET_INT(Netgame.mode);
845
846                 // get the security #
847                 GET_INT(Netgame.security);
848
849                 // get mode specific data
850                 switch(Netgame.mode){
851                 case NG_MODE_PASSWORD:
852                         GET_STRING(Netgame.passwd);
853                         break;
854                 case NG_MODE_RANK_ABOVE:
855                 case NG_MODE_RANK_BELOW:
856                         GET_INT(Netgame.rank_base);
857                         break;
858                 }
859
860                 // update standalone stuff
861                 std_connect_set_gamename(Netgame.name);
862                 std_multi_update_netgame_info_controls();
863                 break;
864
865         // get mission choice options
866         case MULTI_OPTION_MISSION:
867                 netgame_info ng;
868                 char title[NAME_LENGTH+1];
869                 int campaign_type,max_players;
870                 
871                 SDL_zero(ng);
872
873                 SDL_assert(Game_mode & GM_STANDALONE_SERVER);
874
875                 // coop or team vs. team mode
876                 GET_INT(ng.type_flags);
877                 if((ng.type_flags & NG_TYPE_TEAM) && !(Netgame.type_flags & NG_TYPE_TEAM)){
878                         multi_team_reset();
879                 }
880                 // if squad war was switched on
881                 if((ng.type_flags & NG_TYPE_SW) && !(Netgame.type_flags & NG_TYPE_SW)){
882                         mprintf(("STANDALONE TURNED ON SQUAD WAR!!\n"));
883                 }
884                 Netgame.type_flags = ng.type_flags;
885
886                 // new respawn count
887                 GET_UINT(Netgame.respawn);
888
889                 // name string
890                 SDL_zero(str);
891
892                 GET_DATA(code);
893                 // campaign mode
894                 if(code){
895                         GET_STRING(ng.campaign_name);
896
897                         // set the netgame max players here if the filename has changed
898                         if(strcmp(Netgame.campaign_name,ng.campaign_name)){
899                                 SDL_zero(title);
900                                 if(!mission_campaign_get_info(ng.campaign_name,title,&campaign_type,&max_players)){
901                                         Netgame.max_players = 0;
902                                 } else {
903                                         Netgame.max_players = max_players;
904                                 }
905
906                                 SDL_strlcpy(Netgame.campaign_name, ng.campaign_name, SDL_arraysize(Netgame.campaign_name));
907                         }
908
909                         Netgame.campaign_mode = 1;
910
911                         // put brackets around the campaign name
912                         if(Game_mode & GM_STANDALONE_SERVER){
913                                 SDL_snprintf(str, SDL_arraysize(str), "(%s)", Netgame.campaign_name);
914                                 std_multi_set_standalone_mission_name(str);
915                         }
916                 }
917                 // non-campaign mode
918                 else {
919                         GET_STRING(ng.mission_name);
920
921                         if(strcmp(Netgame.mission_name,ng.mission_name)){
922                                 if(strlen(ng.mission_name)){
923                                         Netgame.max_players = mission_parse_get_multi_mission_info( ng.mission_name );
924                                 } else {
925                                         // setting this to -1 will prevent us from being seen on the network
926                                         Netgame.max_players = -1;                               
927                                 }
928                                 SDL_strlcpy(Netgame.mission_name, ng.mission_name, SDL_arraysize(Netgame.mission_name));
929                                 SDL_strlcpy(Game_current_mission_filename, Netgame.mission_name, SDL_arraysize(Game_current_mission_filename));
930                         }                       
931
932                         Netgame.campaign_mode = 0;
933
934                         // set the mission name
935                         if(Game_mode & GM_STANDALONE_SERVER){
936                                 std_multi_set_standalone_mission_name(Netgame.mission_name);                    
937                         }
938                 }
939                 
940                 send_netgame_update_packet();      
941                 break;
942
943         // get the netgame options
944         case MULTI_OPTION_SERVER:               
945                 GET_DATA(Netgame.options);
946         Netgame.options.flags = INTEL_INT( Netgame.options.flags );
947         Netgame.options.respawn = INTEL_INT( Netgame.options.respawn );
948         Netgame.options.voice_token_wait = INTEL_INT( Netgame.options.voice_token_wait );
949         Netgame.options.voice_record_time = INTEL_INT( Netgame.options.voice_record_time );
950         Netgame.options.kill_limit = INTEL_INT( Netgame.options.kill_limit );
951         Netgame.options.mission_time_limit = (fix)INTEL_INT( Netgame.options.mission_time_limit );
952
953                 // if we're a standalone set for no sound, do so here
954                 if((Game_mode & GM_STANDALONE_SERVER) && !Multi_options_g.std_voice){
955                         Netgame.options.flags |= MSO_FLAG_NO_VOICE;
956                 } else {
957                         // maybe update the quality of sound
958                         multi_voice_maybe_update_vars(Netgame.options.voice_qos,Netgame.options.voice_record_time);
959                 }
960
961                 // set the skill level
962                 Game_skill_level = Netgame.options.skill_level;         
963
964                 if((Game_mode & GM_STANDALONE_SERVER) && !(Game_mode & GM_CAMPAIGN_MODE)){
965                         Netgame.respawn = Netgame.options.respawn;
966                 }
967
968                 // if we have the "temp closed" flag toggle
969                 if(Netgame.options.flags & MLO_FLAG_TEMP_CLOSED){
970                         Netgame.flags ^= NG_FLAG_TEMP_CLOSED;
971                 }
972                 Netgame.options.flags &= ~(MLO_FLAG_TEMP_CLOSED);
973
974                 // if i'm the standalone server, I should rebroadcast to all other players
975                 if(Game_mode & GM_STANDALONE_SERVER){
976                         for(idx=0;idx<MAX_PLAYERS;idx++){
977                                 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx]) && (&Net_players[idx] != &Net_players[player_index]) ){
978                                         multi_io_send_reliable(&Net_players[idx], data, offset);
979                                 }
980                         }
981
982                         send_netgame_update_packet();
983                 }
984                 break;
985         
986         // local netplayer options
987         case MULTI_OPTION_LOCAL:
988                 if(player_index == -1){
989                         GET_DATA(bogus);        //data not used, so don't swap!
990         } else {
991                         GET_DATA(Net_players[player_index].p_info.options);
992             Net_players[player_index].p_info.options.flags = INTEL_INT( Net_players[player_index].p_info.options.flags );
993             Net_players[player_index].p_info.options.obj_update_level = INTEL_INT( Net_players[player_index].p_info.options.obj_update_level );            
994                 }               
995                 break;
996         }
997         PACKET_SET_SIZE();
998 }
999
1000
1001
1002