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