]> icculus.org git repositories - taylor/freespace2.git/blob - src/cmdline/cmdline.cpp
const-char warning fixes
[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 "cmdline.h"
212 #include "linklist.h"
213 #include "systemvars.h"
214 #include "multi.h"
215 #include "cfile.h"
216 #include "osapi.h"
217 #include "osregistry.h"
218 #include "version.h"
219
220 // variables
221 class cmdline_parm {
222 public:
223         cmdline_parm *next, *prev;
224         const char *name;                                               // name of parameter, must start with '-' char
225 #ifdef PLAT_UNIX
226         const char *name_s;                                     // single letter argument
227 #endif
228         const char *help;                                               // help text for this parameter
229         char *args;                                             // string value for parameter arguements (NULL if no arguements)
230         int name_found;                         // true if parameter on command line, otherwise false
231
232 #ifndef PLAT_UNIX
233         cmdline_parm(const char *name, const char *help);
234 #else
235         cmdline_parm(const char *name, const char *name_s, const char *help);
236 #endif
237         ~cmdline_parm();
238         int found();
239         int get_int();
240         float get_float();
241         char *str();
242 };
243
244 // here are the command line parameters that we will be using for FreeSpace
245 #ifndef PLAT_UNIX
246 cmdline_parm standalone_arg("-standalone", NULL);
247 cmdline_parm nosound_arg("-nosound", NULL);
248 cmdline_parm nomusic_arg("-nomusic", NULL);
249 cmdline_parm startgame_arg("-startgame", NULL);
250 cmdline_parm gamename_arg("-gamename", NULL);
251 cmdline_parm gamepassword_arg("-password", NULL);
252 cmdline_parm gameclosed_arg("-closed", NULL);
253 cmdline_parm gamerestricted_arg("-restricted", NULL);
254 cmdline_parm allowabove_arg("-allowabove", NULL);
255 cmdline_parm allowbelow_arg("-allowbelow", NULL);
256 cmdline_parm port_arg("-port", NULL);
257 cmdline_parm connect_arg("-connect", NULL);
258 cmdline_parm multilog_arg("-multilog", NULL);
259 cmdline_parm server_firing_arg("-oldfire", NULL);
260 cmdline_parm client_dodamage("-clientdamage", NULL);
261 cmdline_parm pof_spew("-pofspew", NULL);
262 cmdline_parm d3d_32bit("-32bit", NULL);
263 cmdline_parm mouse_coords("-coords", NULL);
264 cmdline_parm timeout("-timeout", NULL);
265 cmdline_parm d3d_window("-window", NULL);
266 #else
267 cmdline_parm standalone_arg("--standalone", "-d", NULL);
268 cmdline_parm nosound_arg("--nosound", "-s", NULL);
269 cmdline_parm nomusic_arg("--nomusic", "--nomusic", NULL);
270 cmdline_parm startgame_arg("--startgame", "-S", NULL);
271 cmdline_parm gamename_arg("--gamename", "-N", NULL);
272 cmdline_parm gamepassword_arg("--password", "-p", NULL);
273 cmdline_parm gameclosed_arg("--closed", "-c", NULL);
274 cmdline_parm gamerestricted_arg("--restricted", "-r", NULL);
275 cmdline_parm allowabove_arg("--allowabove", "-a", NULL);
276 cmdline_parm allowbelow_arg("--allowbelow", "-b", NULL);
277 cmdline_parm port_arg("--port", "-o", NULL);
278 cmdline_parm connect_arg("--connect", "-C", NULL);
279 cmdline_parm multilog_arg("--multilog", "-m", NULL);
280 cmdline_parm server_firing_arg("--oldfire", "-F", NULL);
281 cmdline_parm client_dodamage("--clientdamage", "-D", NULL);
282 cmdline_parm pof_spew("--pofspew", "-P", NULL);
283 cmdline_parm mouse_coords("-coords", "-M", NULL);
284 cmdline_parm timeout("--timeout", "-t", NULL);
285 cmdline_parm d3d_window("--window", "-w", NULL);
286 cmdline_parm d3d_fullscreen("--fullscreen", "-f", NULL);
287 cmdline_parm help("--help", "-h", NULL);
288 cmdline_parm no_grab("--nograb", "-g", NULL);
289 cmdline_parm fs_version("--version", "-v", NULL);
290 cmdline_parm no_movies("--nomovies", "-n", NULL);
291 #endif
292
293 int Cmdline_multi_stream_chat_to_file = 0;
294 int Cmdline_freespace_no_sound = 0;
295 int Cmdline_freespace_no_music = 0;
296 int Cmdline_gimme_all_medals = 0;
297 int Cmdline_use_last_pilot = 0;
298 int Cmdline_multi_protocol = -1;
299 int Cmdline_cd_check = 1;
300 int Cmdline_start_netgame = 0;
301 int Cmdline_closed_game = 0;
302 int Cmdline_restricted_game = 0;
303 int Cmdline_network_port = -1;
304 char *Cmdline_game_name = NULL;
305 char *Cmdline_game_password = NULL;
306 char *Cmdline_rank_above= NULL;
307 char *Cmdline_rank_below = NULL;
308 char *Cmdline_connect_addr = NULL;
309 int Cmdline_multi_log = 0;
310 int Cmdline_server_firing = 0;
311 int Cmdline_client_dodamage = 0;
312 int Cmdline_spew_pof_info = 0;
313 int Cmdline_force_32bit = 0;
314 int Cmdline_mouse_coords = 0;
315 int Cmdline_timeout = -1;
316 #ifdef PLAT_UNIX
317 int Cmdline_no_grab = 0;
318 int Cmdline_play_movies = 1;
319 int Cmdline_fullscreen = 0;
320 #endif
321
322 int Cmdline_window = 0;
323
324 #ifndef PLAT_UNIX
325 static cmdline_parm Parm_list(NULL, NULL);
326 #else
327 static cmdline_parm Parm_list(NULL, NULL, NULL);
328 void print_instructions();
329 #endif
330 static int Parm_list_inited = 0;
331
332 //      Return true if this character is an extra char (white space and quotes)
333 int is_extra_space(char ch)
334 {
335         return ((ch == ' ') || (ch == '\t') || (ch == 0x0a) || (ch == '\'') || (ch == '\"'));
336 }
337
338
339 // eliminates all leading and trailing extra chars from a string.  Returns pointer passed in.
340 char *drop_extra_chars(char *str)
341 {
342         int s, e;
343
344         s = 0;
345         while (str[s] && is_extra_space(str[s]))
346                 s++;
347
348         e = strlen(str) - 1;
349         while (e > s) {
350                 if (!is_extra_space(str[e])){
351                         break;
352                 }
353
354                 e--;
355         }
356
357         if (e > s){
358                 memmove(str, str + s, e - s + 1);
359         }
360
361         str[e - s + 1] = 0;
362         return str;
363 }
364
365
366 // internal function - copy the value for a parameter agruement into the cmdline_parm arg field
367 void parm_stuff_args(cmdline_parm *parm, char *cmdline)
368 {
369         char buffer[1024];
370         memset(buffer, 0, 1024);
371         char *dest = buffer;
372
373         cmdline += strlen(parm->name);
374
375         while ((*cmdline != 0) && (*cmdline != '-')) {
376                 *dest++ = *cmdline++;
377         }
378
379         drop_extra_chars(buffer);
380
381         // mwa 9/14/98 -- made it so that newer command line arguments found will overwrite
382         // the old arguments
383 //      Assert(parm->args == NULL);
384         if ( parm->args != NULL ) {
385                 delete( parm->args );
386                 parm->args = NULL;
387         }
388
389         int size = strlen(buffer) + 1;
390         if (size > 0) {
391                 parm->args = new char[size];
392                 memset(parm->args, 0, size);
393                 strcpy(parm->args, buffer);
394         }
395 }
396
397
398 // internal function - parse the command line, extracting parameter arguements if they exist
399 // cmdline - command line string passed to the application
400 void os_parse_parms(char *cmdline)
401 {
402         // locate command line parameters
403         cmdline_parm *parmp;
404         char *cmdline_offset = NULL;
405
406         for (parmp = GET_FIRST(&Parm_list); parmp !=END_OF_LIST(&Parm_list); parmp = GET_NEXT(parmp) ) {
407                 cmdline_offset = strstr(cmdline, parmp->name);
408
409 #ifdef PLAT_UNIX
410                 // if a match isn't found check for single args
411                 // tack a space on the single args so they don't get mixed up with double args
412                 if (!cmdline_offset) {
413                         char single_tmp[32];
414                         strcpy(single_tmp, parmp->name_s);
415                         strcat(single_tmp, " ");
416                         cmdline_offset = strstr(cmdline, single_tmp);
417                 }
418 #endif
419
420                 if (cmdline_offset) {
421                         parmp->name_found = 1;
422                         parm_stuff_args(parmp, cmdline_offset);
423                 }
424         }
425 }
426
427
428 // validate the command line parameters.  Display an error if an unrecognized parameter is located.
429 void os_validate_parms(char *cmdline)
430 {
431         cmdline_parm *parmp;
432         char seps[] = " ,\t\n";
433         char *token;
434         int parm_found;
435
436    token = strtok(cmdline, seps);
437    while(token != NULL) {
438                 if (token[0] == '-') {
439                         parm_found = 0;
440                         for (parmp = GET_FIRST(&Parm_list); parmp !=END_OF_LIST(&Parm_list); parmp = GET_NEXT(parmp) ) {
441 #ifndef PLAT_UNIX
442                                 if (!stricmp(parmp->name, token)) {
443 #else
444                                 // make sure to do a case sensitive check here
445                                 if (!strcmp(parmp->name, token) || !strcmp(parmp->name_s, token)) {
446 #endif
447                                         parm_found = 1;
448                                         break;
449                                 }
450                         }
451
452                         if (parm_found == 0) {
453 #ifndef PLAT_UNIX
454                                 Error(LOCATION,"Unrecogzined command line parameter %s", token);
455 #else
456                                 print_instructions();
457 #endif
458                         }
459                 }
460
461                 token = strtok(NULL, seps);
462         }
463 }
464
465
466 // Call once to initialize the command line system
467 //
468 // cmdline - command line string passed to the application
469 void os_init_cmdline(char *cmdline)
470 {
471         FILE *fp;
472
473         // read the cmdline.cfg file from the data folder, and pass the command line arguments to
474         // the the parse_parms and validate_parms line.  Read these first so anything actually on
475         // the command line will take precedence
476 #ifdef PLAT_UNIX
477         char cmdname[MAX_PATH];
478
479         snprintf(cmdname, MAX_PATH, "%s/%s/Data/cmdline.cfg", detect_home(), Osreg_user_dir);
480         fp = fopen(cmdname, "rt");
481         
482         if (!fp) {
483                 // if not already found check exec directory
484 #if defined(__APPLE__) && !defined(MACOSX)
485                 // we may end up doing this twice but it would largely get skipped the second time anyway
486                 char *c = NULL;
487                 c = strstr(full_path, ".app");
488                 
489                 if ( c != NULL) {
490                         while (c && (*c != '/'))
491                                 c--;
492                         
493                         *c = '\0';
494                 }
495                 
496                 memset(cmdname, 0, MAX_PATH);
497                 snprintf(cmdname, MAX_PATH-1, "%s/Data/cmdline.cfg", full_path);
498
499                 fp = fopen(cmdname, "rt");
500 #else
501                 fp = fopen("Data/cmdline.cfg", "rt");
502 #endif // __APPLE__ && !__MACOSX__
503         }
504 #else
505         fp = fopen("data\\cmdline.cfg", "rt");
506 #endif
507
508         // if the file exists, get a single line, and deal with it
509         if ( fp ) {
510                 char buf[1024], *p;
511
512                 fgets(buf, 1024, fp);
513
514                 // replace the newline character with a NUL:
515                 if ( (p = strrchr(buf, '\n')) != NULL ) {
516                         *p = '\0';
517                 }
518
519 #ifdef PLAT_UNIX
520                 // append a space for the os_parse_parms() check
521                 strcat(buf, " ");
522 #endif
523
524                 os_parse_parms(buf);
525                 os_validate_parms(buf);
526                 fclose(fp);
527         }
528
529
530
531         os_parse_parms(cmdline);
532         os_validate_parms(cmdline);
533
534 }
535
536 #ifdef PLAT_UNIX
537 // help for available cmdline options
538 void print_instructions()
539 {
540         printf("http://icculus.org/freespace2\n");
541         printf("Support - FAQ: http://icculus.org/lgfaq\n");
542         printf("          Web: http://bugzilla.icculus.org\n\n");
543
544         printf("Usage: freespace2 [options]\n");
545         printf("     [-h | --help]           Show this help message\n");
546         printf("     [-v | --version]        Show game version\n");
547         printf("     [-s | --nosound]        Do no access the sound card\n");
548         printf("     [-f | --fullscreen]     Run the game fullscreen\n");
549         printf("     [-w | --window]         Run the game in a window\n");
550         printf("     [-g | --nograb]         Do not automatically grab mouse\n");
551         printf("     [-n | --nomovies]       Do not play movies\n");
552         printf("     [-d | --standalone]     Run as a dedicated server\n");
553         printf("     [-S | --startgame]      Start a multiplayer game\n");
554         printf("     [-N | --gamename]       Name of the multiplayer game\n");
555         printf("     [-p | --password]       Use this password to connect\n");
556         printf("     [-c | --closed]         Closed multiplayer game\n");
557         printf("     [-r | --restricted]     Restricted multiplayer game\n");
558         printf("     [-a | --allowabove]     Only allow above certain rank\n");
559         printf("     [-b | --allowbelow]     Only allow below certain rank\n");
560         printf("     [-o | --port]           Port to use for multiplayer games\n");
561         printf("     [-C | --connect]        Connect to particular IP address\n");
562         printf("     [-m | --multilog]       Log multiplayer events\n");
563         printf("     [-F | --oldfire]        Server side firing\n");
564         printf("     [-D | --clientdamage]   Client does damage\n");
565         printf("     [-t | --timeout]        Multiplayer game timeout\n");
566         printf("     [-P | --pofspew]        Save model info to pofspew.txt\n");
567         printf("     [-M | --coords]         Show coordinates of the mouse cursor\n\n");
568
569         printf("Freespace 2 v%d.%02d -- Linux Client v%d.%02d\n\n", FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_UNIX_VERSION_MAJOR, FS_UNIX_VERSION_MINOR);
570
571         exit(0);
572 }
573 #endif
574
575 // arg constructor
576 // name_ - name of the parameter, must start with '-' character
577 // help_ - help text for this parameter
578 #ifndef PLAT_UNIX
579 cmdline_parm::cmdline_parm(const char *name_, const char *help_)
580 #else
581 cmdline_parm::cmdline_parm(const char *name_, const char *name_s_, const char *help_)
582 #endif
583 {
584         name = name_;
585 #ifdef PLAT_UNIX
586         name_s = name_s_;
587 #endif
588         help = help_;
589         args = NULL;
590         name_found = 0;
591
592         if (Parm_list_inited == 0) {
593                 list_init(&Parm_list);
594                 Parm_list_inited = 1;
595         }
596
597         if (name != NULL) {
598                 list_append(&Parm_list, this);
599         }
600 }
601
602
603 // destructor - frees any allocated memory
604 cmdline_parm::~cmdline_parm()
605 {
606         if (args) {
607                 delete [] args;
608                 args = NULL;
609         }
610 }
611
612
613 // returns - true if the parameter exists on the command line, otherwise false
614 int cmdline_parm::found()
615 {
616         return name_found;
617 }
618
619
620 // returns - the interger representation for the parameter arguement
621 int cmdline_parm::get_int()
622 {
623         Assert(args);
624         return atoi(args);
625 }
626
627
628 // returns - the float representation for the parameter arguement
629 float cmdline_parm::get_float()
630 {
631         Assert(args);
632         return (float)atof(args);
633 }
634
635
636 // returns - the string value for the parameter arguement
637 char *cmdline_parm::str()
638 {
639         Assert(args);
640         return args;
641 }
642
643 // external entry point into this modules
644 int parse_cmdline(char *cmdline)
645 {
646         os_init_cmdline(cmdline);
647
648         // is this a standalone server??
649         if (standalone_arg.found()) {
650                 Is_standalone = 1;
651         }
652
653         // run with no sound
654         if ( nosound_arg.found() ) {
655                 Cmdline_freespace_no_sound = 1;
656         }
657
658         // run with no music
659         if ( nomusic_arg.found() ) {
660                 Cmdline_freespace_no_music = 1;
661         }
662
663         // should we start a network game
664         if ( startgame_arg.found() ) {
665                 Cmdline_use_last_pilot = 1;
666                 Cmdline_start_netgame = 1;
667         }
668
669         // closed network game
670         if ( gameclosed_arg.found() ) {
671                 Cmdline_closed_game = 1;
672         }
673
674         // restircted network game
675         if ( gamerestricted_arg.found() ) {
676                 Cmdline_restricted_game = 1;
677         }
678
679         // get the name of the network game
680         if ( gamename_arg.found() ) {
681                 Cmdline_game_name = gamename_arg.str();
682
683 #ifdef PLAT_UNIX
684                 // if there wasn't an argument then complain and exit
685                 if ( !(strlen(Cmdline_game_name) > 0) ) {
686                         fprintf(stderr, "ERROR: The --gamename (-N) option requires an additional argument!\n");
687                         exit(0);
688                 }
689 #endif
690
691                 // be sure that this string fits in our limits
692                 if ( strlen(Cmdline_game_name) > MAX_GAMENAME_LEN ) {
693                         Cmdline_game_name[MAX_GAMENAME_LEN-1] = '\0';
694                 }
695         }
696
697         // get the password for a pssword game
698         if ( gamepassword_arg.found() ) {
699                 Cmdline_game_password = gamepassword_arg.str();
700
701 #ifdef PLAT_UNIX
702                 // if there wasn't an argument then complain and exit
703                 if ( !(strlen(Cmdline_game_password) > 0) ) {
704                         fprintf(stderr, "ERROR: The --password (-p) option requires an additional argument!\n");
705                         exit(0);
706                 }
707 #endif
708
709                 // be sure that this string fits in our limits
710                 if ( strlen(Cmdline_game_password) > MAX_PASSWD_LEN ) {
711                         Cmdline_game_password[MAX_PASSWD_LEN-1] = '\0';
712                 }
713         }
714
715         // set the rank above/below arguments
716         if ( allowabove_arg.found() ) {
717                 Cmdline_rank_above = allowabove_arg.str();
718         }
719         if ( allowbelow_arg.found() ) {
720                 Cmdline_rank_below = allowbelow_arg.str();
721         }
722
723         // get the port number for games
724         if ( port_arg.found() ) {
725                 Cmdline_network_port = port_arg.get_int();
726
727 #ifdef PLAT_UNIX
728                 // if there wasn't an argument then complain and exit
729                 if ( !Cmdline_network_port ) {
730                         fprintf(stderr, "ERROR: The --port (-P) option requires an additional argument!\n");
731                         exit(0);
732                 }
733 #endif
734         }
735
736         // the connect argument specifies to join a game at this particular address
737         if ( connect_arg.found() ) {
738                 Cmdline_use_last_pilot = 1;
739                 Cmdline_connect_addr = connect_arg.str();
740
741 #ifdef PLAT_UNIX
742                 // if there wasn't an argument then complain and exit
743                 if ( !(strlen(Cmdline_connect_addr) > 0) ) {
744                         fprintf(stderr, "ERROR: The --connect (-C) option requires an additional argument!\n");
745                         exit(0);
746                 }
747 #endif
748         }
749
750         // see if the multilog flag was set
751         if ( multilog_arg.found() ){
752                 Cmdline_multi_log = 1;
753         }       
754
755         // maybe use old-school server-side firing
756         if (server_firing_arg.found() ){
757                 Cmdline_server_firing = 1;
758         }
759
760         // maybe use old-school client damage
761         if(client_dodamage.found()){
762                 Cmdline_client_dodamage = 1;
763         }       
764
765         // spew pof info
766         if(pof_spew.found()){
767                 Cmdline_spew_pof_info = 1;
768         }
769
770 #ifndef PLAT_UNIX
771         // 32 bit
772         if(d3d_32bit.found()){
773                 Cmdline_force_32bit = 1;
774         }
775 #endif
776
777         // mouse coords
778         if(mouse_coords.found()){
779                 Cmdline_mouse_coords = 1;
780         }
781
782         // net timeout
783         if(timeout.found()){
784                 Cmdline_timeout = timeout.get_int();
785         }
786
787         // d3d windowed
788         if(d3d_window.found()){
789                 Cmdline_window = 1;
790         }
791
792 #ifdef PLAT_UNIX
793         // run fullscreen
794         if(d3d_fullscreen.found()){
795                 Cmdline_fullscreen = 1;
796         }
797
798         // help!!
799         if(help.found()){
800                 print_instructions();
801         }
802
803         // no key/mouse grab
804         if(no_grab.found()){
805                 Cmdline_no_grab = 1;
806         }
807
808         // play movies?
809         if(no_movies.found()){
810                 Cmdline_play_movies = 0;
811         }
812
813         // display game version
814         if(fs_version.found()){
815                 printf("Freespace 2 version:  %d.%02d\n", FS_VERSION_MAJOR, FS_VERSION_MINOR);
816                 printf("Linux client version:  %d.%02d\n", FS_UNIX_VERSION_MAJOR, FS_UNIX_VERSION_MINOR);
817                 exit(0);
818         }
819 #endif
820
821         return 1;
822 }