]> icculus.org git repositories - taylor/freespace2.git/blob - src/cmdline/cmdline.cpp
remove obsolete no_grab cmdline option
[taylor/freespace2.git] / src / cmdline / cmdline.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/Cmdline/cmdline.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * $Log$
16  * Revision 1.7  2005/10/01 21:40:38  taylor
17  * deal with OS X apps a little better, sets the path only based on ".app" in the name rather than the name itself
18  * make sure a global cmdline.cfg file works with OS X when built as an app
19  *
20  * Revision 1.6  2003/06/22 12:50:11  taylor
21  * fix memory error, code cleanup
22  *
23  * Revision 1.5  2003/05/06 07:20:14  taylor
24  * implement command line options
25  *
26  * Revision 1.4  2002/06/21 03:34:05  relnev
27  * implemented a stub and fixed a path
28  *
29  * Revision 1.3  2002/06/09 04:41:15  relnev
30  * added copyright header
31  *
32  * Revision 1.2  2002/05/07 03:16:43  theoddone33
33  * The Great Newline Fix
34  *
35  * Revision 1.1.1.1  2002/05/03 03:28:08  root
36  * Initial import.
37  *
38  * 
39  * 8     8/26/99 8:51p Dave
40  * Gave multiplayer TvT messaging a heavy dose of sanity. Cheat codes.
41  * 
42  * 7     7/15/99 3:07p Dave
43  * 32 bit detection support. Mouse coord commandline.
44  * 
45  * 6     7/13/99 1:15p Dave
46  * 32 bit support. Whee!
47  * 
48  * 5     6/22/99 9:37p Dave
49  * Put in pof spewing.
50  * 
51  * 4     1/12/99 5:45p Dave
52  * Moved weapon pipeline in multiplayer to almost exclusively client side.
53  * Very good results. Bandwidth goes down, playability goes up for crappy
54  * connections. Fixed object update problem for ship subsystems.
55  * 
56  * 3     11/17/98 11:12a Dave
57  * Removed player identification by address. Now assign explicit id #'s.
58  * 
59  * 2     10/07/98 10:52a Dave
60  * Initial checkin.
61  * 
62  * 1     10/07/98 10:48a Dave
63  * 
64  * 38    10/02/98 3:22p Allender
65  * fix up the -connect option and fix the -port option
66  * 
67  * 37    9/15/98 4:04p Allender
68  * added back in the -ip_addr command line switch because it needs to be
69  * in the standalone server only executable
70  * 
71  * 36    9/14/98 11:52a Allender
72  * don't use cfile
73  * 
74  * 35    9/14/98 11:28a Allender
75  * support for server bashing of address when received from client.  Added
76  * a cmdline.cfg file to process command line arguments from a file
77  * 
78  * 34    9/08/98 2:20p Allender
79  * temporary code to force IP address to a specific value.
80  * 
81  * 33    8/20/98 5:30p Dave
82  * Put in handy multiplayer logfile system. Now need to put in useful
83  * applications of it all over the code.
84  * 
85  * 32    8/07/98 10:39a Allender
86  * fixed debug standalone problem where stats would continually get sent
87  * to tracker.  more debug code to help find stats problem
88  * 
89  * 31    7/24/98 11:14a Allender
90  * start of new command line options for version 1.04
91  * 
92  * 30    5/21/98 1:50a Dave
93  * Remove obsolete command line functions. Reduce shield explosion packets
94  * drastically. Tweak PXO screen even more. Fix file xfer system so that
95  * we can guarantee file uniqueness.
96  * 
97  * 29    5/18/98 9:10p Dave
98  * Put in many new PXO features. Fixed skill level bashing in multiplayer.
99  * Removed several old command line options. Put in network config files.
100  * 
101  * 28    5/09/98 7:16p Dave
102  * Put in CD checking. Put in standalone host password. Made pilot into
103  * popup scrollable.
104  * 
105  * 27    4/23/98 8:27p Allender
106  * basic support for cutscene playback.  Into movie code in place.  Tech
107  * room can view cutscenes stored in CDROM_dir variable
108  * 
109  * 26    4/09/98 5:43p Dave
110  * Remove all command line processing from the demo. Began work fixing up
111  * the new multi host options screen.
112  * 
113  * 25    4/02/98 11:40a Lawrance
114  * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
115  * 
116  * 24    4/01/98 5:56p Dave
117  * Fixed a messaging bug which caused msg_all mode in multiplayer not to
118  * work. Compile out a host of multiplayer options not available in the
119  * demo.
120  * 
121  * 23    3/14/98 2:48p Dave
122  * Cleaned up observer joining code. Put in support for file xfers to
123  * ingame joiners (observers or not). Revamped and reinstalled pseudo
124  * lag/loss system.
125  * 
126  * 22    2/22/98 12:19p John
127  * Externalized some strings
128  * 
129  * 21    1/31/98 4:32p Dave
130  * Put in new support for VMT player validation, game logging in and game
131  * logging out.
132  * 
133  * 20    12/10/97 4:45p Dave
134  * Added in more detailed support for multiplayer packet lag/loss. Fixed
135  * some multiplayer stuff. Added some controls to the standalone.
136  * 
137  * 19    12/09/97 6:14p Lawrance
138  * add -nomusic flag
139  * 
140  * 18    12/01/97 5:10p Dave
141  * Fixed a syntax bug.
142  * 
143  * 17    12/01/97 4:59p Dave
144  * Synchronized multiplayer debris objects. Put in pilot popup in main
145  * hall. Optimized simulated multiplayer lag module. Fixed a potential
146  * file_xfer bug.
147  * 
148  * 16    11/28/97 7:04p Dave
149  * Emergency checkin due to big system crash.
150  * 
151  * 15    11/28/97 5:06p Dave
152  * Put in facilities for simulating multiplayer lag.
153  * 
154  * 14    11/24/97 5:42p Dave
155  * Fixed a file xfer buffer free/malloc problem. Lengthened command line
156  * switch string parse length.
157  * 
158  * 13    11/12/97 4:39p Dave
159  * Put in multiplayer campaign support parsing, loading and saving. Made
160  * command-line variables better named. Changed some things on the initial
161  * pilot select screen.
162  * 
163  * 12    11/11/97 4:54p Dave
164  * Put in support for single vs. multiplayer pilots. Put in initial player
165  * selection screen (no command line option yet). Started work on
166  * multiplayer campaign file save gaming.
167  * 
168  * 11    11/11/97 11:55a Allender
169  * initialize network at beginning of application.  create new call to set
170  * which network protocol to use
171  * 
172  * 10    9/18/97 10:12p Dave
173  * Added -gimmemedals, which gives the current pilot all the medals in the
174  * game (debug)
175  * 
176  * 9     9/18/97 9:20a Dave
177  * Minor modifications
178  * 
179  * 8     9/15/97 11:40p Lawrance
180  * remove demo granularity switch
181  * 
182  * 7     9/09/97 3:39p Sandeep
183  * warning level 4 bugs
184  * 
185  * 6     9/03/97 5:03p Lawrance
186  * add support for -nosound command line parm
187  * 
188  * 5     8/22/97 8:52a Dave
189  * Removed a return statement which would have broken the parser out too
190  * early.
191  * 
192  * 4     8/21/97 4:55p Dave
193  * Added a switch for multiplayer chat streaming. Added a section for
194  * global command line vars.
195  * 
196  * 3     8/06/97 2:26p Dave
197  * Made the command line parse more robust. Made it easier to add and
198  * process new command-line switches.
199  * 
200  * 2     8/04/97 3:13p Dave
201  * Added command line functions. See cmdline.cpp for directions on adding
202  * new switches
203  * 
204  * 1     8/04/97 9:58a Dave
205  * 
206  * $NoKeywords: $
207  */
208
209 #include <string.h>
210 #include <stdlib.h>
211 #include <new>
212 #include "cmdline.h"
213 #include "linklist.h"
214 #include "systemvars.h"
215 #include "multi.h"
216 #include "cfile.h"
217 #include "osapi.h"
218 #include "osregistry.h"
219 #include "version.h"
220 #include "cfile.h"
221 #include "cfilesystem.h"
222
223 // variables
224 class cmdline_parm {
225 public:
226         cmdline_parm *next, *prev;
227         const char *name;                                               // name of parameter, must start with '-' char
228         const char *name2;                                      // name - alternate
229         const char *help;                                               // help text for this parameter
230         char *args;                                             // string value for parameter arguements (NULL if no arguements)
231         int name_found;                         // true if parameter on command line, otherwise false
232
233         cmdline_parm(const char *name, const char *name2, const char *help);
234         ~cmdline_parm();
235         int found();
236         int get_int();
237         float get_float();
238         char *str();
239 };
240
241 // here are the command line parameters that we will be using for FreeSpace
242 cmdline_parm standalone_arg("-standalone", "-d", NULL);
243 cmdline_parm nosound_arg("-nosound", "-s", NULL);
244 cmdline_parm nomusic_arg("-nomusic", NULL, NULL);
245 cmdline_parm startgame_arg("-startgame", "-S", NULL);
246 cmdline_parm gamename_arg("-gamename", "-N", NULL);
247 cmdline_parm gamepassword_arg("-password", "-p", NULL);
248 cmdline_parm gameclosed_arg("-closed", "-c", NULL);
249 cmdline_parm gamerestricted_arg("-restricted", "-r", NULL);
250 cmdline_parm allowabove_arg("-allowabove", "-a", NULL);
251 cmdline_parm allowbelow_arg("-allowbelow", "-b", NULL);
252 cmdline_parm port_arg("-port", "-o", NULL);
253 cmdline_parm connect_arg("-connect", "-C", NULL);
254 cmdline_parm multilog_arg("-multilog", "-m", NULL);
255 cmdline_parm server_firing_arg("-oldfire", "-F", NULL);
256 cmdline_parm client_dodamage("-clientdamage", "-D", NULL);
257 cmdline_parm pof_spew("-pofspew", "-P", NULL);
258 cmdline_parm d3d_32bit("-32bit", NULL, NULL);
259 cmdline_parm mouse_coords("-coords", "-M", NULL);
260 cmdline_parm timeout("-timeout", "-t", NULL);
261 cmdline_parm d3d_window("-window", "-w", NULL);
262 cmdline_parm d3d_fullscreen("-fullscreen", "-f", NULL);
263 cmdline_parm help("-help", "-h", NULL);
264 cmdline_parm fs_version("-version", "-v", NULL);
265 cmdline_parm no_movies("-nomovies", "-n", NULL);
266
267
268 int Cmdline_multi_stream_chat_to_file = 0;
269 int Cmdline_freespace_no_sound = 0;
270 int Cmdline_freespace_no_music = 0;
271 int Cmdline_gimme_all_medals = 0;
272 int Cmdline_use_last_pilot = 0;
273 int Cmdline_multi_protocol = -1;
274 int Cmdline_cd_check = 1;
275 int Cmdline_start_netgame = 0;
276 int Cmdline_closed_game = 0;
277 int Cmdline_restricted_game = 0;
278 int Cmdline_network_port = -1;
279 char *Cmdline_game_name = NULL;
280 char *Cmdline_game_password = NULL;
281 char *Cmdline_rank_above= NULL;
282 char *Cmdline_rank_below = NULL;
283 char *Cmdline_connect_addr = NULL;
284 int Cmdline_multi_log = 0;
285 int Cmdline_server_firing = 0;
286 int Cmdline_client_dodamage = 0;
287 int Cmdline_spew_pof_info = 0;
288 int Cmdline_force_32bit = 0;
289 int Cmdline_mouse_coords = 0;
290 int Cmdline_timeout = -1;
291 int Cmdline_play_movies = 1;
292 int Cmdline_fullscreen = 0;
293 int Cmdline_window = 0;
294
295 static cmdline_parm Parm_list(NULL, NULL, NULL);
296
297 static int Parm_list_inited = 0;
298
299
300 //      Return true if this character is an extra char (white space and quotes)
301 static int is_extra_space(char ch)
302 {
303         return ((ch == ' ') || (ch == '\t') || (ch == 0x0a) || (ch == '\'') || (ch == '\"'));
304 }
305
306
307 // eliminates all leading and trailing extra chars from a string.  Returns pointer passed in.
308 static char *drop_extra_chars(char *str)
309 {
310         int s, e;
311
312         s = 0;
313         while (str[s] && is_extra_space(str[s]))
314                 s++;
315
316         e = strlen(str) - 1;
317         while (e > s) {
318                 if (!is_extra_space(str[e])){
319                         break;
320                 }
321
322                 e--;
323         }
324
325         if (e > s){
326                 memmove(str, str + s, e - s + 1);
327         }
328
329         str[e - s + 1] = 0;
330         return str;
331 }
332
333
334 // internal function - copy the value for a parameter agruement into the cmdline_parm arg field
335 static void parm_stuff_args(cmdline_parm *parm, char *cmdline)
336 {
337         char buffer[1024] = { 0 };
338         char *dest = buffer;
339
340         while ((*cmdline != 0) && (*cmdline != '-') && ((size_t)(dest-buffer) < SDL_arraysize(buffer))) {
341                 *dest++ = *cmdline++;
342         }
343
344         drop_extra_chars(buffer);
345
346         // mwa 9/14/98 -- made it so that newer command line arguments found will overwrite
347         // the old arguments
348 //      SDL_assert(parm->args == NULL);
349         if ( parm->args != NULL ) {
350                 delete [] parm->args;
351                 parm->args = NULL;
352         }
353
354         int size = strlen(buffer);
355         if (size > 0) {
356                 parm->args = new (std::nothrow) char[size+1];
357
358                 if (parm->args != NULL) {
359                         memset(parm->args, 0, size+1);
360                         SDL_strlcpy(parm->args, buffer, size+1);
361                 }
362         }
363 }
364
365
366 // internal function - parse the command line, extracting parameter arguements if they exist
367 // cmdline - command line string passed to the application
368 static void os_parse_parms(char *cmdline)
369 {
370         // locate command line parameters
371         cmdline_parm *parmp;
372         char *cmdline_offset = NULL;
373         char pname[33] = { 0 };
374
375         if ( !cmdline || (strlen(cmdline) <= 1) ) {
376                 return;
377         }
378
379         for (parmp = GET_FIRST(&Parm_list); parmp !=END_OF_LIST(&Parm_list); parmp = GET_NEXT(parmp) ) {
380                 // check with space to make sure we get the correct option name
381                 SDL_snprintf(pname, SDL_arraysize(pname)-1, "%s ", parmp->name);
382                 cmdline_offset = strstr(cmdline, pname);
383
384                 if (cmdline_offset) {
385                         cmdline_offset += strlen(parmp->name);
386                 } else if (parmp->name2 != NULL) {
387                         // check with space to make sure we get the correct option name
388                         SDL_snprintf(pname, SDL_arraysize(pname)-1, "%s ", parmp->name2);
389                         cmdline_offset = strstr(cmdline, pname);
390
391                         if (cmdline_offset) {
392                                 cmdline_offset += strlen(parmp->name2);
393                         }
394                 }
395
396                 if (cmdline_offset) {
397                         parmp->name_found = 1;
398                         parm_stuff_args(parmp, cmdline_offset);
399                 }
400         }
401 }
402
403 static bool os_find_parm(const cmdline_parm *parmp, const char *token)
404 {
405         // allow for double '-'
406         if ( (strlen(token) > 2) && (token[1] == '-') ) {
407                 token++;
408         }
409
410         if ( !strcmp(parmp->name, token) ) {
411                 return true;
412         }
413
414         if ( (parmp->name2 != NULL) && !strcmp(parmp->name2, token) ) {
415                 return true;
416         }
417
418         return false;
419 }
420
421 // help for available cmdline options
422 static void print_instructions()
423 {
424         printf("http://icculus.org/freespace2\n");
425         printf("Support - FAQ: http://icculus.org/lgfaq\n");
426         printf("          Web: http://bugzilla.icculus.org\n\n");
427
428 #ifdef MAKE_FS1
429         printf("Usage: freespace [options]\n");
430 #else
431         printf("Usage: freespace2 [options]\n");
432 #endif
433         printf("\n");
434         printf("  General:\n");
435         printf("     [-h | --help]           Show this help message\n");
436         printf("     [-v | --version]        Show game version\n");
437         printf("     [-s | --nosound]        Do not access the sound card\n");
438         printf("     [-f | --fullscreen]     Run the game fullscreen\n");
439         printf("     [-w | --window]         Run the game in a window\n");
440         printf("     [-n | --nomovies]       Do not play movies\n");
441         printf("     [-P | --pofspew]        Save model info to pofspew.txt\n");
442         printf("     [-M | --coords]         Show coordinates of the mouse cursor\n");
443         printf("     [--nomusic]             Do not play music\n");
444         printf("\n");
445         printf("  Multiplayer:\n");
446         printf("     [-d | --standalone]     Run as a dedicated server\n");
447         printf("     [-S | --startgame]      Start a multiplayer game\n");
448         printf("     [-N | --gamename]       Name of the multiplayer game\n");
449         printf("     [-p | --password]       Use this password to connect\n");
450         printf("     [-c | --closed]         Closed multiplayer game\n");
451         printf("     [-r | --restricted]     Restricted multiplayer game\n");
452         printf("     [-a | --allowabove]     Only allow above certain rank\n");
453         printf("     [-b | --allowbelow]     Only allow below certain rank\n");
454         printf("     [-o | --port]           Port to use for multiplayer games\n");
455         printf("     [-C | --connect]        Connect to particular IP address\n");
456         printf("     [-m | --multilog]       Log multiplayer events\n");
457         printf("     [-F | --oldfire]        Server side firing\n");
458         printf("     [-D | --clientdamage]   Client does damage\n");
459         printf("     [-t | --timeout]        Multiplayer game timeout\n");
460         printf("\n");
461
462 #ifdef MAKE_FS1
463         printf("FreeSpace v%d.%02d\n", FS_VERSION_MAJOR, FS_VERSION_MINOR);
464 #else
465         printf("Freespace 2 v%d.%02d\n", FS_VERSION_MAJOR, FS_VERSION_MINOR);
466 #endif
467         printf("icculus.org client v%d.%02d\n\n", IO_VERSION_MAJOR, IO_VERSION_MINOR);
468
469         exit(0);
470 }
471
472 // validate the command line parameters.  Display an error if an unrecognized parameter is located.
473 static void os_validate_parms(char *cmdline)
474 {
475         cmdline_parm *parmp;
476         char seps[] = " ,\t\n";
477         char *token;
478         int parm_found;
479
480         if ( !cmdline || (strlen(cmdline) <= 1) ) {
481                 return;
482         }
483
484    token = strtok(cmdline, seps);
485    while(token != NULL) {
486                 if (token[0] == '-') {
487                         parm_found = 0;
488                         for (parmp = GET_FIRST(&Parm_list); parmp !=END_OF_LIST(&Parm_list); parmp = GET_NEXT(parmp) ) {
489                                 if ( os_find_parm(parmp, token) ) {
490                                         parm_found = 1;
491                                         break;
492                                 }
493                         }
494
495                         if (parm_found == 0) {
496                                 print_instructions();
497                         }
498                 }
499
500                 token = strtok(NULL, seps);
501         }
502 }
503
504
505 // Call once to initialize the command line system
506 //
507 // cmdline - command line string passed to the application
508 static void os_init_cmdline(const char *cmdline)
509 {
510         FILE *fp = NULL;
511         char cmdname[1024] = { 0 };
512
513         // read the cmdline.cfg file from the data folder, and pass the command line arguments to
514         // the the parse_parms and validate_parms line.  Read these first so anything actually on
515         // the command line will take precedence
516
517         if ( cfile_init_paths() ) {
518                 exit(-2);
519         }
520
521         mprintf(("Command line: "));
522
523         SDL_snprintf(cmdname, SDL_arraysize(cmdname), "%s%s%scmdline.cfg", Cfile_user_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR);
524
525         fp = fopen (cmdname, "rt");
526
527         if ( !fp ) {
528                 // if not already found check exec directory
529                 SDL_snprintf(cmdname, SDL_arraysize(cmdname), "%s%s%scmdline.cfg", Cfile_root_dir, Pathtypes[CF_TYPE_DATA].path, DIR_SEPARATOR_STR);
530
531                 fp = fopen (cmdname, "rt");
532         }
533
534         // if the file exists, get a single line, and deal with it
535         if ( fp ) {
536                 char buf[1024] = { 0 }, *p;
537
538                 while (fgets(buf, SDL_arraysize(buf), fp) != NULL) {
539                         // replace the newline character with a NUL:
540                         if ( (p = strrchr(buf, '\n')) != NULL ) {
541                                 *p = '\0';
542                         }
543
544                         // make sure that we have a trailing space for option finding to
545                         // work properly with single args
546                         SDL_strlcat(buf, " ", SDL_arraysize(buf));
547
548                         mprintf(("%s", buf));
549
550                         os_parse_parms(buf);
551                         os_validate_parms(buf);
552                 }
553
554                 fclose(fp);
555         }
556
557         if ( cmdline && strlen(cmdline) ) {
558                 mprintf(("%s", cmdline));
559
560                 // for proper arg handling make sure cmdline has trailing space
561                 int len = strlen(cmdline) + 2;
562                 char *m_cmdline = (char*) malloc(len);
563
564                 if (m_cmdline) {
565                         SDL_strlcpy(m_cmdline, cmdline, len);
566                         SDL_strlcat(m_cmdline, " ", len);
567
568                         os_parse_parms(m_cmdline);
569                         os_validate_parms(m_cmdline);
570
571                         free(m_cmdline);
572                 }
573         }
574
575         mprintf(("\n"));
576 }
577
578 // arg constructor
579 // name_ - name of the parameter, must start with '-' character
580 // help_ - help text for this parameter
581 cmdline_parm::cmdline_parm(const char *name_, const char *name2_, const char *help_)
582 {
583         name = name_;
584         name2 = name2_;
585         help = help_;
586         args = NULL;
587         name_found = 0;
588
589         if (Parm_list_inited == 0) {
590                 list_init(&Parm_list);
591                 Parm_list_inited = 1;
592         }
593
594         if (name != NULL) {
595                 list_append(&Parm_list, this);
596         }
597 }
598
599
600 // destructor - frees any allocated memory
601 cmdline_parm::~cmdline_parm()
602 {
603         if (args) {
604                 delete [] args;
605                 args = NULL;
606         }
607 }
608
609
610 // returns - true if the parameter exists on the command line, otherwise false
611 int cmdline_parm::found()
612 {
613         return name_found;
614 }
615
616
617 // returns - the interger representation for the parameter arguement
618 int cmdline_parm::get_int()
619 {
620         SDL_assert(args);
621         return atoi(args);
622 }
623
624
625 // returns - the float representation for the parameter arguement
626 float cmdline_parm::get_float()
627 {
628         SDL_assert(args);
629         return (float)atof(args);
630 }
631
632
633 // returns - the string value for the parameter arguement
634 char *cmdline_parm::str()
635 {
636         SDL_assert(args);
637         return args;
638 }
639
640 // external entry point into this modules
641 int parse_cmdline(const char *cmdline)
642 {
643         os_init_cmdline(cmdline);
644
645         // is this a standalone server??
646         if (standalone_arg.found()) {
647                 Is_standalone = 1;
648         }
649
650         // run with no sound
651         if ( nosound_arg.found() ) {
652                 Cmdline_freespace_no_sound = 1;
653         }
654
655         // run with no music
656         if ( nomusic_arg.found() ) {
657                 Cmdline_freespace_no_music = 1;
658         }
659
660         // should we start a network game
661         if ( startgame_arg.found() ) {
662                 Cmdline_use_last_pilot = 1;
663                 Cmdline_start_netgame = 1;
664         }
665
666         // closed network game
667         if ( gameclosed_arg.found() ) {
668                 Cmdline_closed_game = 1;
669         }
670
671         // restircted network game
672         if ( gamerestricted_arg.found() ) {
673                 Cmdline_restricted_game = 1;
674         }
675
676         // get the name of the network game
677         if ( gamename_arg.found() ) {
678                 Cmdline_game_name = gamename_arg.str();
679
680                 // be sure that this string fits in our limits
681                 if ( Cmdline_game_name && (strlen(Cmdline_game_name) > MAX_GAMENAME_LEN) ) {
682                         Cmdline_game_name[MAX_GAMENAME_LEN-1] = '\0';
683                 }
684         }
685
686         // get the password for a pssword game
687         if ( gamepassword_arg.found() ) {
688                 Cmdline_game_password = gamepassword_arg.str();
689
690                 // be sure that this string fits in our limits
691                 if ( Cmdline_game_password && (strlen(Cmdline_game_password) > MAX_PASSWD_LEN) ) {
692                         Cmdline_game_password[MAX_PASSWD_LEN-1] = '\0';
693                 }
694         }
695
696         // set the rank above/below arguments
697         if ( allowabove_arg.found() ) {
698                 Cmdline_rank_above = allowabove_arg.str();
699         }
700         if ( allowbelow_arg.found() ) {
701                 Cmdline_rank_below = allowbelow_arg.str();
702         }
703
704         // get the port number for games
705         if ( port_arg.found() ) {
706                 Cmdline_network_port = port_arg.get_int();
707         }
708
709         // the connect argument specifies to join a game at this particular address
710         if ( connect_arg.found() ) {
711                 Cmdline_use_last_pilot = 1;
712                 Cmdline_connect_addr = connect_arg.str();
713         }
714
715         // see if the multilog flag was set
716         if ( multilog_arg.found() ){
717                 Cmdline_multi_log = 1;
718         }       
719
720         // maybe use old-school server-side firing
721         if (server_firing_arg.found() ){
722                 Cmdline_server_firing = 1;
723         }
724
725         // maybe use old-school client damage
726         if(client_dodamage.found()){
727                 Cmdline_client_dodamage = 1;
728         }       
729
730         // spew pof info
731         if(pof_spew.found()){
732                 Cmdline_spew_pof_info = 1;
733         }
734
735         // 32 bit
736         if(d3d_32bit.found()){
737                 Cmdline_force_32bit = 1;
738         }
739
740         // mouse coords
741         if(mouse_coords.found()){
742                 Cmdline_mouse_coords = 1;
743         }
744
745         // net timeout
746         if(timeout.found()){
747                 Cmdline_timeout = timeout.get_int();
748         }
749
750         // d3d windowed
751         if(d3d_window.found()){
752                 Cmdline_window = 1;
753         }
754
755         // run fullscreen
756         if(d3d_fullscreen.found()){
757                 Cmdline_fullscreen = 1;
758         }
759
760         // help!!
761         if(help.found()){
762                 print_instructions();
763         }
764
765         // play movies?
766         if(no_movies.found()){
767                 Cmdline_play_movies = 0;
768         }
769
770         // display game version
771         if(fs_version.found()){
772                 printf("Freespace 2 version:  %d.%02d\n", FS_VERSION_MAJOR, FS_VERSION_MINOR);
773                 printf("icculus.org client version:  %d.%02d\n", IO_VERSION_MAJOR, IO_VERSION_MINOR);
774                 exit(0);
775         }
776
777 #ifndef NDEBUG
778         // default to windowed mode in debug builds
779         Cmdline_fullscreen = 0;
780         Cmdline_window = 1;
781 #endif
782
783         return 1;
784 }