Fixed: command line options are better checked

origin
patty21 19 years ago
parent ed4e9c7dda
commit c7743b0538

@ -1,4 +1,4 @@
/* $Id: configuration.c,v 1.77 2005/07/08 15:19:34 stpohle Exp $ /* $Id: configuration.c,v 1.78 2006/08/13 21:20:54 patty21 Exp $
* configuration */ * configuration */
#include <SDL.h> #include <SDL.h>
@ -658,9 +658,9 @@ void
ReadPrgArgs (int argc, char **argv) ReadPrgArgs (int argc, char **argv)
{ {
int i = 0; int i = 0;
char s;
while (argv[++i] != NULL) { while (argv[++i] != NULL) {
if (!strcmp (argv[i], "-help")) { if (!strcmp (argv[i], "-h")||!strcmp (argv[i], "-help")||!strcmp (argv[i], "--help")) {
printf ("BomberClone Version " VERSION "\n"); printf ("BomberClone Version " VERSION "\n");
printf (" WebPage : http://www.bomberclone.de\n"); printf (" WebPage : http://www.bomberclone.de\n");
printf (" Bug Report to :\n"); printf (" Bug Report to :\n");
@ -682,24 +682,81 @@ ReadPrgArgs (int argc, char **argv)
printf (" -autostart SECONDS - time before a game starts\n"); printf (" -autostart SECONDS - time before a game starts\n");
exit (0); exit (0);
} }
if (!strcmp (argv[i], "-port")) }
strncpy (bman.port, argv[++i], LEN_PORT); i=0;
if (!strcmp (argv[i], "-ogcport")) while (argv[++i] != NULL) {
strncpy (bman.ogc_port, argv[++i], LEN_PORT); if (argv[i][0]=='-') {
if (!strcmp (argv[i], "-name")) if (argv[i+1] != NULL)
strncpy (bman.playername, argv[++i], LEN_PLAYERNAME); s=argv[i+1][0];
if (!strcmp (argv[i], "-name2")) else
strncpy (bman.player2name, argv[++i], LEN_PLAYERNAME); s='-';
if (!strcmp (argv[i], "-gamename")) if (!strcmp (argv[i], "-port")) {
strncpy (bman.gamename, argv[++i], LEN_GAMENAME); if (s!='-')
if (!strcmp (argv[i], "-ogc")) strncpy (bman.port, argv[++i], LEN_PORT);
bman.notifygamemaster = atoi (argv[++i]); else {
if (!strcmp (argv[i], "-broadcast")) printf("Error: Parameter required for -port\n");
bman.broadcast = atoi (argv[++i]); exit(1);
if (!strcmp (argv[i], "-debug")) }
debug = atoi (argv[++i]); }
if (!strcmp (argv[i], "-autostart")) if (!strcmp (argv[i], "-ogcport")) {
bman.autostart = atoi (argv[++i]); if (s!='-')
strncpy (bman.ogc_port, argv[++i], LEN_PORT);
else {
printf("Error: Parameter required for -ogcport\n");
exit(1);
}
}
if (!strcmp (argv[i], "-name")) {
if (s!='-')
strncpy (bman.playername, argv[++i], LEN_PLAYERNAME);
else {
printf("Error: Parameter required for -name\n");
exit(1);
}
}
if (!strcmp (argv[i], "-name2")) {
if (s!='-')
strncpy (bman.player2name, argv[++i], LEN_PLAYERNAME);
else {
printf("Error: Parameter required for -name2\n");
exit(1);
}
}
if (!strcmp (argv[i], "-gamename")) {
if (s!='-')
strncpy (bman.gamename, argv[++i], LEN_GAMENAME);
else {
printf("Error: Parameter required for -gamename\n");
exit(1);
}
}
if (!strcmp (argv[i], "-autostart")) {
if (s!='-')
bman.autostart = atoi (argv[++i]);
else {
printf("Error: Parameter required for -autostart\n");
exit(1);
}
}
if (!strcmp (argv[i], "-ogc")) {
if (s!='-')
bman.notifygamemaster = atoi (argv[++i]);
else
bman.notifygamemaster = 1;
}
if (!strcmp (argv[i], "-broadcast")) {
if (s!='-')
bman.broadcast = atoi (argv[++i]);
else
bman.broadcast = 1;
}
if (!strcmp (argv[i], "-debug")) {
if (s!='-')
debug = atoi (argv[++i]);
else
debug = 1;
}
}
} }
}; };

Loading…
Cancel
Save