]> icculus.org git repositories - taylor/freespace2.git/blob - src/network/multi_options.cpp
sync up rest of big-endian network changes. it should at least be as good as what...
[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_gui.h"
210 #include "multiutil.h"
211 #include "multi_voice.h"
212 #include "multi_options.h"
213 #include "multi_team.h"
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 // load in the config file
237 #define NEXT_TOKEN()                                            do { tok = strtok(NULL, "\n"); if(tok != NULL){ drop_leading_white_space(tok); drop_trailing_white_space(tok); } } while(0);
238 #define SETTING(s)                                              ( !stricmp(tok, s) )
239 void multi_options_read_config()
240 {
241         CFILE *in;
242         char str[512];
243         char *tok = NULL;
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
249         // do we have a forced port via commandline or registry?
250         ushort forced_port = (ushort)os_config_read_uint(NULL, "ForcePort", 0); 
251         Multi_options_g.port = (Cmdline_network_port >= 0) ? (ushort)Cmdline_network_port : forced_port == 0 ? (ushort)DEFAULT_GAME_PORT : forced_port;
252
253         Multi_options_g.log = (Cmdline_multi_log) ? 1 : 0;
254         Multi_options_g.datarate_cap = OO_HIGH_RATE_DEFAULT;
255         strcpy(Multi_options_g.user_tracker_ip, "");    
256         strcpy(Multi_options_g.game_tracker_ip, "");    
257         strcpy(Multi_options_g.pxo_ip, "");     
258         strcpy(Multi_options_g.pxo_rank_url, "");       
259         strcpy(Multi_options_g.pxo_create_url, "");     
260         strcpy(Multi_options_g.pxo_verify_url, "");     
261         strcpy(Multi_options_g.pxo_banner_url, "");
262
263         // standalone values
264         Multi_options_g.std_max_players = -1;
265         Multi_options_g.std_datarate = OBJ_UPDATE_HIGH;
266         Multi_options_g.std_voice = 1;
267         memset(Multi_options_g.std_passwd, 0, STD_PASSWD_LEN);
268         memset(Multi_options_g.std_pname, 0, STD_NAME_LEN);
269         Multi_options_g.std_framecap = 30;
270         
271         // read in the config file
272         in = cfopen(MULTI_CFG_FILE, "rt", CFILE_NORMAL, CF_TYPE_DATA);
273         
274         // if we failed to open the config file, user default settings
275         if(in == NULL){
276                 nprintf(("Network","Failed to open network config file, using default settings\n"));            
277                 return;
278         }
279
280         while(!cfeof(in)){
281                 // read in the game info
282                 memset(str,0,512);
283                 cfgets(str,512,in);
284
285                 // parse the first line
286                 tok = strtok(str," \t");
287
288                 // check the token
289                 if(tok != NULL){
290                         drop_leading_white_space(tok);
291                         drop_trailing_white_space(tok);                 
292                 } else {
293                         continue;
294                 }               
295
296                 // all possible options
297                 // only standalone cares about the following options
298                 if(Is_standalone){
299                         if(SETTING("+pxo")){                    
300                                 // setup PXO mode
301                                 NEXT_TOKEN();
302                                 if(tok != NULL){
303                                         // whee!
304                                 }
305                         } else 
306                         if(SETTING("+name")){
307                                 // set the standalone server's permanent name
308                                 NEXT_TOKEN();
309                                 if(tok != NULL){
310                                         strncpy(Multi_options_g.std_pname, tok, STD_NAME_LEN);
311                                 }
312                         } else 
313                         if(SETTING("+no_voice")){
314                                 // standalone won't allow voice transmission
315                                 Multi_options_g.std_voice = 0;
316                         } else
317                         if(SETTING("+max_players")){
318                                 // set the max # of players on the standalone
319                                 NEXT_TOKEN();
320                                 if(tok != NULL){
321                                         if(!((atoi(tok) < 1) || (atoi(tok) > MAX_PLAYERS))){
322                                                 Multi_options_g.std_max_players = atoi(tok);
323                                         }
324                                 }
325                         } else 
326                         if(SETTING("+ban")){
327                                 // ban a player
328                                 NEXT_TOKEN();
329                                 if(tok != NULL){
330                                         std_add_ban(tok);
331                                 }
332                         } else 
333                         if(SETTING("+passwd")){
334                                 // set the standalone host password
335                                 NEXT_TOKEN();
336                                 if(tok != NULL){
337                                         strncpy(Multi_options_g.std_passwd, tok, STD_PASSWD_LEN);
338
339                                         // yuck
340 #ifdef PLAT_UNIX
341                                         STUB_FUNCTION;
342 #else
343                                         extern HWND Multi_std_host_passwd;
344                                         SetWindowText(Multi_std_host_passwd, Multi_options_g.std_passwd);
345 #endif
346                                 }
347                         } else 
348                         if(SETTING("+low_update")){
349                                 // set standalone to low updates
350                                 Multi_options_g.std_datarate = OBJ_UPDATE_LOW;
351                         } else
352                         if(SETTING("+med_update")){
353                                 // set standalone to medium updates
354                                 Multi_options_g.std_datarate = OBJ_UPDATE_MEDIUM;
355                         } else 
356                         if(SETTING("+high_update")){
357                                 // set standalone to high updates
358                                 Multi_options_g.std_datarate = OBJ_UPDATE_HIGH;
359                         } else 
360                         if(SETTING("+lan_update")){
361                                 // set standalone to high updates
362                                 Multi_options_g.std_datarate = OBJ_UPDATE_LAN;
363                         } 
364                 }
365
366                 // common to all modes
367                 if(SETTING("+user_server")){
368                         // ip addr of user tracker
369                         NEXT_TOKEN();
370                         if(tok != NULL){
371                                 strcpy(Multi_options_g.user_tracker_ip, tok);
372                         }
373                 } else
374                 if(SETTING("+game_server")){
375                         // ip addr of game tracker
376                         NEXT_TOKEN();
377                         if(tok != NULL){
378                                 strcpy(Multi_options_g.game_tracker_ip, tok);
379                         }
380                 } else
381                 if(SETTING("+chat_server")){
382                         // ip addr of pxo chat server
383                         NEXT_TOKEN();
384                         if(tok != NULL){
385                                 strcpy(Multi_options_g.pxo_ip, tok);
386                         }
387                 } else
388                 if(SETTING("+rank_url")){
389                         // url of pilot rankings page
390                         NEXT_TOKEN();
391                         if(tok != NULL){
392                                 strcpy(Multi_options_g.pxo_rank_url, tok);
393                         }
394                 } else
395                 if(SETTING("+create_url")){
396                         // url of pxo account create page
397                         NEXT_TOKEN();
398                         if(tok != NULL){
399                                 strcpy(Multi_options_g.pxo_create_url, tok);
400                         }
401                 } else
402                 if(SETTING("+verify_url")){
403                         // url of pxo account verify page
404                         NEXT_TOKEN();
405                         if(tok != NULL){
406                                 strcpy(Multi_options_g.pxo_verify_url, tok);
407                         }
408                 } else
409                 if(SETTING("+banner_url")){
410                         // url of pxo account verify page
411                         NEXT_TOKEN();
412                         if(tok != NULL){
413                                 strcpy(Multi_options_g.pxo_banner_url, tok);
414                         }
415                 } else
416                 if(SETTING("+datarate")){
417                         // set the max datarate for high updates
418                         NEXT_TOKEN();
419                         if(tok != NULL){
420                                 if(atoi(tok) >= 4000){
421                                         Multi_options_g.datarate_cap = atoi(tok);
422                                 }
423                         }                       
424                 }
425                 if(SETTING("+http_proxy")){
426                         // get the proxy server
427                         NEXT_TOKEN();
428                         if(tok != NULL){                                
429                                 char *ip = strtok(tok, ":");
430                                 if(ip != NULL){
431                                         strcpy(Multi_options_proxy, ip);
432                                 }
433                                 ip = strtok(NULL, "");
434                                 if(ip != NULL){
435                                         Multi_options_proxy_port = (ushort)atoi(ip);
436                                 } else {
437                                         strcpy(Multi_options_proxy, "");
438                                 }
439                         }
440                 }
441         }
442
443         // close the config file
444         cfclose(in);
445         in = NULL;
446 }
447
448 // set netgame defaults 
449 // NOTE : should be used when creating a newpilot
450 void multi_options_set_netgame_defaults(multi_server_options *options)
451 {
452         // any player can do squadmate messaging
453         options->squad_set = MSO_SQUAD_ANY;
454
455         // only the host can end the game
456         options->endgame_set = MSO_END_HOST;
457
458         // allow ingame file xfer and custom pilot pix
459         options->flags = (MSO_FLAG_INGAME_XFER | MSO_FLAG_ACCEPT_PIX);
460
461         // set the default time limit to be -1 (no limit)
462         options->mission_time_limit = fl2f(-1.0f);
463
464         // set the default max kills for a mission
465         options->kill_limit = 9999;
466
467         // set the default # of respawns
468         options->respawn = 2;
469
470         // set the default # of max observers
471         options->max_observers = 2;
472
473         // set the default netgame qos
474         options->voice_qos = 10;
475
476         // set the default token timeout
477         options->voice_token_wait = 2000;                               // he must wait 2 seconds between voice gets
478
479         // set the default max voice record time
480         options->voice_record_time = 5000;
481 }
482
483 // set local netplayer defaults
484 // NOTE : should be used when creating a newpilot
485 void multi_options_set_local_defaults(multi_local_options *options)
486 {
487         // accept pix by default and broadcast on the local subnet
488         options->flags = (MLO_FLAG_ACCEPT_PIX | MLO_FLAG_LOCAL_BROADCAST);      
489
490         // set the object update level based on the type of network connection specified by the user
491         // at install (or launcher) time.
492         if ( Psnet_connection == NETWORK_CONNECTION_DIALUP ) {
493                 options->obj_update_level = OBJ_UPDATE_LOW;
494         } else {
495                 options->obj_update_level = OBJ_UPDATE_HIGH;
496         }
497 }
498
499 // fill in the passed netgame options struct with the data from my player file data (only host/server should do this)
500 void multi_options_netgame_load(multi_server_options *options)
501 {
502         if(options != NULL){
503                 memcpy(options,&Player->m_server_options,sizeof(multi_server_options));
504         }       
505 }
506
507 // fill in the passed local options struct with the data from my player file data (all machines except standalone should do this)
508 void multi_options_local_load(multi_local_options *options, net_player *pxo_pl)
509 {
510         if(options != NULL){
511                 memcpy(options,&Player->m_local_options,sizeof(multi_local_options));
512         }
513
514         // stuff pxo squad info
515 #ifndef MAKE_FS1
516         if(pxo_pl != NULL){
517                 strcpy(pxo_pl->p_info.pxo_squad_name, Multi_tracker_squad_name);                
518         }
519 #endif
520 }
521
522 // update everyone on the current netgame options
523 void multi_options_update_netgame()
524 {
525         ubyte data[MAX_PACKET_SIZE],code;
526         int packet_size = 0;
527         
528         Assert(Net_player->flags & NETINFO_FLAG_GAME_HOST);
529
530         // build the header and add the opcode
531         BUILD_HEADER(OPTIONS_UPDATE);
532         code = MULTI_OPTION_SERVER;
533         ADD_DATA(code);
534
535         // add the netgame options
536     Netgame.options.flags = INTEL_INT( Netgame.options.flags );
537     Netgame.options.respawn = INTEL_INT( Netgame.options.respawn );
538     Netgame.options.voice_token_wait = INTEL_INT( Netgame.options.voice_token_wait );
539     Netgame.options.voice_record_time = INTEL_INT( Netgame.options.voice_record_time );
540     Netgame.options.kill_limit= INTEL_INT( Netgame.options.kill_limit );
541     Netgame.options.mission_time_limit = (fix)INTEL_INT( Netgame.options.mission_time_limit );
542         ADD_DATA(Netgame.options);
543
544         // send the packet
545         if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
546                 multi_io_send_to_all_reliable(data, packet_size);
547         } else {
548                 multi_io_send_reliable(Net_player, data, packet_size);
549         }
550 }
551
552 // update everyone with my local settings
553 void multi_options_update_local()
554 {
555         ubyte data[MAX_PACKET_SIZE],code;
556         int packet_size = 0;
557         
558         // if i'm the server, don't do anything
559         if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
560                 return;
561         }
562
563         // build the header and add the opcode
564         BUILD_HEADER(OPTIONS_UPDATE);
565         code = MULTI_OPTION_LOCAL;
566         ADD_DATA(code);
567
568         // add the netgame options
569     Net_player->p_info.options.flags = INTEL_INT( Net_player->p_info.options.flags );
570     Net_players->p_info.options.obj_update_level = INTEL_INT( Net_player->p_info.options.obj_update_level );
571         ADD_DATA(Net_player->p_info.options);
572
573         // send the packet              
574         multi_io_send_reliable(Net_player, data, packet_size);
575 }
576
577 // update the standalone with the settings I have picked at the "start game" screen
578 void multi_options_update_start_game(netgame_info *ng)
579 {
580         ubyte data[MAX_PACKET_SIZE],code;
581         int packet_size = 0;
582
583         // should be a host on a standalone
584         Assert((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER));
585
586         // build the header
587         BUILD_HEADER(OPTIONS_UPDATE);
588         code = MULTI_OPTION_START_GAME;
589         ADD_DATA(code);
590
591         // add the start game options
592         ADD_STRING(ng->name);
593         ADD_INT(ng->mode);
594         ADD_INT(ng->security);
595
596         // add mode-specific data
597         switch(ng->mode){
598         case NG_MODE_PASSWORD:
599                 ADD_STRING(ng->passwd);
600                 break;
601         case NG_MODE_RANK_ABOVE:
602         case NG_MODE_RANK_BELOW:
603                 ADD_INT(ng->rank_base);
604                 break;
605         }
606
607         // send to the standalone server        
608         multi_io_send_reliable(Net_player, data, packet_size);
609 }
610
611 // update the standalone with the mission settings I have picked (mission filename, etc)
612 void multi_options_update_mission(netgame_info *ng, int campaign_mode)
613 {
614         ubyte data[MAX_PACKET_SIZE],code;
615         int packet_size = 0;
616
617         // should be a host on a standalone
618         Assert((Net_player->flags & NETINFO_FLAG_GAME_HOST) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER));
619
620         // build the header
621         BUILD_HEADER(OPTIONS_UPDATE);
622         code = MULTI_OPTION_MISSION;
623         ADD_DATA(code);
624
625         // type (coop or team vs. team)
626         ADD_INT(ng->type_flags);
627
628         // respawns
629         ADD_UINT(ng->respawn);
630
631         // add the mission/campaign filename
632         code = (ubyte)campaign_mode;
633         ADD_DATA(code);
634         if(campaign_mode){
635                 ADD_STRING(ng->campaign_name);
636         } else {
637                 ADD_STRING(ng->mission_name);
638         }
639
640         // send to the server   
641         multi_io_send_reliable(Net_player, data, packet_size);
642 }
643
644
645 // ----------------------------------------------------------------------------------
646 // MULTI OPTIONS FUNCTIONS
647 //
648
649 // process an incoming multi options packet
650 void multi_options_process_packet(unsigned char *data, header *hinfo)
651 {
652         ubyte code;     
653         multi_local_options bogus;
654         int idx,player_index;
655         char str[255];
656         int offset = HEADER_LENGTH;
657
658         // find out who is sending this data    
659         player_index = find_player_id(hinfo->id);
660
661         // get the packet code
662         GET_DATA(code);
663         switch(code){
664         // get the start game options
665         case MULTI_OPTION_START_GAME:
666                 Assert(Game_mode & GM_STANDALONE_SERVER);
667
668                 // get the netgame name
669                 GET_STRING(Netgame.name);               
670
671                 // get the netgame mode
672                 GET_INT(Netgame.mode);
673
674                 // get the security #
675                 GET_INT(Netgame.security);
676
677                 // get mode specific data
678                 switch(Netgame.mode){
679                 case NG_MODE_PASSWORD:
680                         GET_STRING(Netgame.passwd);
681                         break;
682                 case NG_MODE_RANK_ABOVE:
683                 case NG_MODE_RANK_BELOW:
684                         GET_INT(Netgame.rank_base);
685                         break;
686                 }
687
688                 // update standalone stuff
689                 std_connect_set_gamename(Netgame.name);
690                 std_multi_update_netgame_info_controls();
691                 break;
692
693         // get mission choice options
694         case MULTI_OPTION_MISSION:
695                 netgame_info ng;
696                 char title[NAME_LENGTH+1];
697                 int campaign_type,max_players;
698                 
699                 memset(&ng,0,sizeof(netgame_info));
700
701                 Assert(Game_mode & GM_STANDALONE_SERVER);
702
703                 // coop or team vs. team mode
704                 GET_INT(ng.type_flags);
705                 if((ng.type_flags & NG_TYPE_TEAM) && !(Netgame.type_flags & NG_TYPE_TEAM)){
706                         multi_team_reset();
707                 }
708                 // if squad war was switched on
709                 if((ng.type_flags & NG_TYPE_SW) && !(Netgame.type_flags & NG_TYPE_SW)){
710                         mprintf(("STANDALONE TURNED ON SQUAD WAR!!\n"));
711                 }
712                 Netgame.type_flags = ng.type_flags;
713
714                 // new respawn count
715                 GET_UINT(Netgame.respawn);
716
717                 // name string
718                 memset(str,255,0);
719
720                 GET_DATA(code);
721                 // campaign mode
722                 if(code){
723                         GET_STRING(ng.campaign_name);
724
725                         // set the netgame max players here if the filename has changed
726                         if(strcmp(Netgame.campaign_name,ng.campaign_name)){                             
727                                 memset(title,0,NAME_LENGTH+1);                  
728                                 if(!mission_campaign_get_info(ng.campaign_name,title,&campaign_type,&max_players)){
729                                         Netgame.max_players = 0;
730                                 } else {
731                                         Netgame.max_players = max_players;
732                                 }
733
734                                 strcpy(Netgame.campaign_name,ng.campaign_name);
735                         }
736
737                         Netgame.campaign_mode = 1;
738
739                         // put brackets around the campaign name
740                         if(Game_mode & GM_STANDALONE_SERVER){
741                                 strcpy(str,"(");
742                                 strcat(str,Netgame.campaign_name);
743                                 strcat(str,")");
744                                 std_multi_set_standalone_mission_name(str);
745                         }
746                 }
747                 // non-campaign mode
748                 else {
749                         GET_STRING(ng.mission_name);
750
751                         if(strcmp(Netgame.mission_name,ng.mission_name)){
752                                 if(strlen(ng.mission_name)){
753                                         Netgame.max_players = mission_parse_get_multi_mission_info( ng.mission_name );
754                                 } else {
755                                         // setting this to -1 will prevent us from being seen on the network
756                                         Netgame.max_players = -1;                               
757                                 }
758                                 strcpy(Netgame.mission_name,ng.mission_name);
759                                 strcpy(Game_current_mission_filename,Netgame.mission_name);                             
760                         }                       
761
762                         Netgame.campaign_mode = 0;
763
764                         // set the mission name
765                         if(Game_mode & GM_STANDALONE_SERVER){
766                                 std_multi_set_standalone_mission_name(Netgame.mission_name);                    
767                         }
768                 }
769                 
770                 send_netgame_update_packet();      
771                 break;
772
773         // get the netgame options
774         case MULTI_OPTION_SERVER:               
775                 GET_DATA(Netgame.options);
776         Netgame.options.flags = INTEL_INT( Netgame.options.flags );
777         Netgame.options.respawn = INTEL_INT( Netgame.options.respawn );
778         Netgame.options.voice_token_wait = INTEL_INT( Netgame.options.voice_token_wait );
779         Netgame.options.voice_record_time = INTEL_INT( Netgame.options.voice_record_time );
780         Netgame.options.kill_limit = INTEL_INT( Netgame.options.kill_limit );
781         Netgame.options.mission_time_limit = (fix)INTEL_INT( Netgame.options.mission_time_limit );
782
783                 // if we're a standalone set for no sound, do so here
784                 if((Game_mode & GM_STANDALONE_SERVER) && !Multi_options_g.std_voice){
785                         Netgame.options.flags |= MSO_FLAG_NO_VOICE;
786                 } else {
787                         // maybe update the quality of sound
788                         multi_voice_maybe_update_vars(Netgame.options.voice_qos,Netgame.options.voice_record_time);
789                 }
790
791                 // set the skill level
792                 Game_skill_level = Netgame.options.skill_level;         
793
794                 if((Game_mode & GM_STANDALONE_SERVER) && !(Game_mode & GM_CAMPAIGN_MODE)){
795                         Netgame.respawn = Netgame.options.respawn;
796                 }
797
798                 // if we have the "temp closed" flag toggle
799                 if(Netgame.options.flags & MLO_FLAG_TEMP_CLOSED){
800                         Netgame.flags ^= NG_FLAG_TEMP_CLOSED;
801                 }
802                 Netgame.options.flags &= ~(MLO_FLAG_TEMP_CLOSED);
803
804                 // if i'm the standalone server, I should rebroadcast to all other players
805                 if(Game_mode & GM_STANDALONE_SERVER){
806                         for(idx=0;idx<MAX_PLAYERS;idx++){
807                                 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx]) && (&Net_players[idx] != &Net_players[player_index]) ){
808                                         multi_io_send_reliable(&Net_players[idx], data, offset);
809                                 }
810                         }
811
812                         send_netgame_update_packet();
813                 }
814                 break;
815         
816         // local netplayer options
817         case MULTI_OPTION_LOCAL:
818                 if(player_index == -1){
819                         GET_DATA(bogus);        //data not used, so don't swap!
820         } else {
821                         GET_DATA(Net_players[player_index].p_info.options);
822             Net_players[player_index].p_info.options.flags = INTEL_INT( Net_players[player_index].p_info.options.flags );
823             Net_players[player_index].p_info.options.obj_update_level = INTEL_INT( Net_players[player_index].p_info.options.obj_update_level );            
824                 }               
825                 break;
826         }
827         PACKET_SET_SIZE();
828 }
829
830
831
832