Date:	Tuesday August 29, 2000 @ 22:07
Author:	unbelver

Update of /home/netrek/cvsroot/metaserver
In directory swashbuckler.fortress.real-time.com:/var/tmp/cvs-serv15839

Modified Files:
	Makefile main.c meta.h scan.c 
Log Message:

Added a method to de-list solicit servers that have died.

If solicited server has to get queried by meta, that may just mean
that nobody is playing there.  If solicited server is queried by meta
and meta can't connect, that means server is dead.  De-lists that
server.

--Carlos V.



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

Index: metaserver/Makefile
diff -u metaserver/Makefile:2.3 metaserver/Makefile:2.4
--- metaserver/Makefile:2.3	Tue Jul 13 01:33:29 1999
+++ metaserver/Makefile	Tue Aug 29 22:07:40 2000
@@ -1,7 +1,8 @@
 #
 # Makefile for MetaServerII
 #
-CC = purify -log-file="/home/netrek/metaserver/purify.log" -show-directory=yes -show-pc=yes -user-path="/home/netrek/metaserver" gcc
+#CC = purify -log-file="/home/netrek/metaserver/purify.log" -show-directory=yes -show-pc=yes -user-path="/home/netrek/metaserver" gcc
+CC = gcc
 CFILES	= main.c scan.c server.c disp_old.c disp_new.c disp_web.c disp_udp.c disp_info.c BecomeDaemon.c
 OFILES	= $(CFILES:.c=.o)
 HDRS	= meta.h packets.h copyright2.h
Index: metaserver/main.c
diff -u metaserver/main.c:2.1 metaserver/main.c:2.2
--- metaserver/main.c:2.1	Thu Nov 11 19:12:41 1999
+++ metaserver/main.c	Tue Aug 29 22:07:40 2000
@@ -4,7 +4,7 @@
  * MetaServerII
  * Copyright (c) 1993 by Andy McFadden
  * 
- * $Id: main.c,v 2.1 1999/11/12 01:12:41 unbelver Exp $
+ * $Id: main.c,v 2.2 2000/08/30 03:07:40 unbelver Exp $
  * 
  */
 #include <stdio.h>
@@ -176,6 +176,7 @@
   else
     strcpy(servers[server_count].comment, comment);
   servers[server_count].player_count = 0;
+  servers[server_count].solicit = FALSE;
   server_count++;
 }
 
Index: metaserver/meta.h
diff -u metaserver/meta.h:2.3 metaserver/meta.h:2.4
--- metaserver/meta.h:2.3	Wed Mar  8 00:17:47 2000
+++ metaserver/meta.h	Tue Aug 29 22:07:40 2000
@@ -4,7 +4,7 @@
  * MetaServerII
  * Copyright (c) 1993 by Andy McFadden
  * 
- * $Id: meta.h,v 2.3 2000/03/08 06:17:47 unbelver Exp $
+ * $Id: meta.h,v 2.4 2000/08/30 03:07:40 unbelver Exp $
  * 
  */
 /*#define DEBUG*/
@@ -118,6 +118,7 @@
 
   int  player_count;
   int  queue_size;
+  int  solicit;         /* we got this as a solicit packet */
   PLAYER players[MAX_PLAYER];
 } SERVER;		/* (if you add pointers here, update checkpointing) */
 
Index: metaserver/scan.c
diff -u metaserver/scan.c:2.10 metaserver/scan.c:2.11
--- metaserver/scan.c:2.10	Wed Mar  8 00:17:47 2000
+++ metaserver/scan.c	Tue Aug 29 22:07:40 2000
@@ -4,7 +4,7 @@
  * MetaServerII
  * Copyright (c) 1993 by Andy McFadden
  * 
- * $Id: scan.c,v 2.10 2000/03/08 06:17:47 unbelver Exp $
+ * $Id: scan.c,v 2.11 2000/08/30 03:07:40 unbelver Exp $
  * 
  */
 #include <stdio.h>
@@ -745,7 +745,32 @@
   }
 }
 
+/* delete server #which and close the hole behind it */
 
+void delete_server(int which)
+{
+  SERVER *sp1, *sp2;
+  int i, j;
+
+  for ( i = which, j = (which + 1); j < server_count; i++, j++ )
+    memcpy( &servers[i], &servers[j], sizeof(SERVER) );
+
+  server_count--;
+
+  if ( server_count == 0 )
+    free(servers);
+  else
+    {
+      realloc( servers, (sizeof(SERVER) * (server_count + 1)) );
+      if ( servers == NULL )
+	{
+	  fprintf(stderr, "ERROR: delete_server: realloc failure to get smaller buffer!\n");
+	  log_msg("ERROR: delete_server: realloc failure to get smaller buffer!\n");
+	  exit(1);
+	}
+    }
+}
+
 /*
  * Update the structures associated with the server connection.  Assumes
  * that the sockets have been closed.  The "status" field should be set.
@@ -766,6 +791,20 @@
   switch (sp->status) {
   case SS_NOCONN:
     plustime = wait_noconn;
+
+    /* if solicit is true, and we had to query server, that just means */
+    /* nobody is playing there.  If we queried server and server       */
+    /* timed out, that means server is dead.  Get rid of it.           */
+
+    if(sp->solicit == TRUE)  
+      {
+        log_msg("Deleting server %s. Query timeout on solicit fall-through\n", 
+		sp->hostname);
+        delete_server(busy);
+        coffee = TRUE;
+        busy = -1;
+        return(0);
+      }
     break;
   case SS_EMPTY:
     plustime = wait_empty;
@@ -925,7 +964,7 @@
   srvbuf.cstate = CS_CLOSED;
   srvbuf.down_time = (time_t) 0;
   srvbuf.max_players = MAX_PLAYER;
-  
+  srvbuf.solicit = TRUE;
 
   /* null terminate it so we can use strtok on it */
   packet[bytes] = 0;