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