Vanilla Development Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS update: Vanilla/ntserv



Date:	Tuesday February 29, 2000 @ 22:08
Author:	cameron

Update of /home/netrek/cvsroot/Vanilla/ntserv
In directory swashbuckler.fortress.real-time.com:/var/tmp/cvs-serv5277

Modified Files:
	solicit.c 
Log Message:
check return from fgets(),
code simplification,
allow comment to contain spaces.



****************************************

Index: Vanilla/ntserv/solicit.c
diff -u Vanilla/ntserv/solicit.c:1.15 Vanilla/ntserv/solicit.c:1.16
--- Vanilla/ntserv/solicit.c:1.15	Tue Feb 29 21:38:25 2000
+++ Vanilla/ntserv/solicit.c	Tue Feb 29 22:08:34 2000
@@ -113,11 +113,9 @@
   char *name, *login;             /* name and login guaranteed not blank */
   char unknown[] = "unknown";     /* unknown player/login string */
   char *here = packet;
-  char line[256];                /* where to hold the .metaservers line */
-  char *token;                   /* current line token */
   time_t now = time(NULL);
-  int gamefull = 0;              /* is the game full? */
-  int isrsa = 0;                 /* is this server RSA? */
+  int gamefull = 0;               /* is the game full? */
+  int isrsa = 0;                  /* is this server RSA? */
 
   /* perform first time initialisation */ 
   if (initialised == 0) {
@@ -136,69 +134,54 @@
     /* read the metaserver list file */
     for (i=0; i<MAXMETASERVERS; i++) {
       struct metaserver *m = &metaservers[i];
+      char buffer[256];         /* where to hold the .metaservers line */
+      char *line;		/* return from fgets() */
+      char *token;		/* current line token */
       
-      /* scan the line */
+      /* read a line */
+      line = fgets(buffer, 256, file);
 
-      fgets(line, 255, file);
-
-      /* if end of file reached, stop assumes there is a \n before a eof */
-      
+      /* if end of file reached, stop */
+      if (line == NULL) break;
       if (feof(file)) break;
 
-      token = strtok(line, " ");
-      if(token != NULL)
-	strncpy(m->host, token, 32); /* meta host name */
-      else
-	continue;         /* bad line, try next one */
-
-      token = strtok(NULL, " ");
-      if(token != NULL)
-	m->port = atoi(token);     /* meta port */
-      else
-	continue;         /* bad line, try next one */
-
-      token = strtok(NULL, " ");
-      if(token != NULL)
-	m->minimum = atoi(token); /* min solicit time */
-      else
-	continue;         /* bad line, try next one */
-
-      token = strtok(NULL, " ");
-      if(token != NULL)
-	m->maximum = atoi(token); /* max solicit time */
-      else
-	continue;         /* bad line, try next one */
-
-      token = strtok(NULL, " ");
-      if(token != NULL)
-	strncpy(m->ours, token, 32); /* our host name */
-      else
-	continue;         /* bad line, try next one */
+      /* parse each field, ignore the line if insufficient fields found */
+
+      token = strtok(line, " ");	/* meta host name */
+      if (token == NULL) continue;
+      strncpy(m->host, token, 32);
+
+      token = strtok(NULL, " ");	/* meta port */
+      if (token == NULL) continue;
+      m->port = atoi(token);
+
+      token = strtok(NULL, " ");	/* min solicit time */
+      if (token == NULL) continue;
+      m->minimum = atoi(token);
+
+      token = strtok(NULL, " ");	/* max solicit time */
+      if (token == NULL) continue;
+      m->maximum = atoi(token);
+
+      token = strtok(NULL, " ");	/* our host name */
+      if (token == NULL) continue;
+      strncpy(m->ours, token, 32);
       
-      token = strtok(NULL, " ");
-      if(token != NULL)
-	strncpy(m->type, token, 2); /* server type */
-      else
-	continue;         /* bad line, try next one */
-
-      token = strtok(NULL, " ");
-      if(token != NULL)
-	m->pport = atoi(token);     /* player port */
-      else
-	continue;         /* bad line, try next one */
+      token = strtok(NULL, " ");	/* server type */
+      if (token == NULL) continue;
+      strncpy(m->type, token, 2);
+
+      token = strtok(NULL, " ");	/* player port */
+      if (token == NULL) continue;
+      m->pport = atoi(token);
       
-      token = strtok(NULL, " ");
-      if(token != NULL)
-	m->oport = atoi(token);     /* observer port */
-      else
-	  continue;         /* bad line, try next one */
-
-      token = strtok(NULL, " ");
-      if(token != NULL)
-	strncpy(m->comment, token, 32); /* comment line */
-      else
-	continue;         /* bad line, try next one */
-
+      token = strtok(NULL, " ");	/* observer port */
+      if (token == NULL) continue;
+      m->oport = atoi(token);
+
+      token = strtok(NULL, "\n");	/* comment text */
+      if (token == NULL) continue;
+      strncpy(m->comment, token, 32);
 
       /* force minimum and maximum delays (see note on #define) */
       if (m->minimum < META_MINIMUM_DELAY)