Date:	Monday February 16, 2004 @ 18:21
Author:	cameron

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

Modified Files:
	findslot.c main.c 
Log Message:
add NO_DUPLICATE_HOSTS feature

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

Index: Vanilla/ntserv/findslot.c
diff -u Vanilla/ntserv/findslot.c:1.2 Vanilla/ntserv/findslot.c:1.3
--- Vanilla/ntserv/findslot.c:1.2	Fri Apr 30 15:18:43 1999
+++ Vanilla/ntserv/findslot.c	Mon Feb 16 18:21:20 2004
@@ -15,6 +15,20 @@
 #include "data.h"
 #include "proto.h"
 
+/* return true if the host is not already in the game */
+static int absent(int w_queue, char *host) {
+  int i, here = 0;
+  for (i=0; i<MAXPLAYER; i++) {
+    if (players[i].p_status == PFREE) continue;
+    if ((players[i].p_flags & PFROBOT)) continue;
+#ifdef OBSERVERS
+    /* if we want a pickup slot, ignore any observer slot we have */
+    if (w_queue == QU_PICKUP && players[i].p_status == POBSERV) continue;
+#endif	
+    if (strcmp(players[i].p_full_hostname, host) == 0) return 0;
+  }
+  return 1;
+}
 
 /*
  * The following code for findslot() is really nice.
@@ -30,7 +44,7 @@
  *   oldcount:      (local) My position last time I looked.
  */
 
-int findslot(int w_queue)
+int findslot(int w_queue, char *host)
 {
     u_int oldcount;	/* My old number */
     pid_t mypid = getpid();
@@ -41,6 +55,19 @@
     /* Ensure that the queue is open */
     if (!(queues[w_queue].q_flags & QU_OPEN)) return (-1);
 
+#ifdef NO_DUPLICATE_HOSTS
+    /* pre-queue if client from same ip address is already playing */
+    if ((w_queue == QU_PICKUP) || (w_queue == QU_PICKUP_OBS)) {
+      for (;;) {
+	if (absent(w_queue, host)) break;
+	if (rep++ % 10 == 1) { sendQueuePacket((short) MAXPLAYER); }
+	if (isClientDead()) { fflush(stderr); exit(0); }
+	if (!(status->gameup & GU_GAMEOK)) { return (-1); }
+	sleep(1);
+      }
+    }
+#endif
+
     /* If no one is waiting, I will try to enter now */
     if (queues[w_queue].first == -1)
 	if ( (i=pickslot(w_queue)) >= 0 )  return (i);
@@ -48,6 +75,7 @@
     mywait = queue_add(w_queue);    /* Get me into the queue */
     if (mywait == -1) return (-1);   /* The queue is full! */
 
+    rep = 0;
     oldcount = waiting[mywait].count;
 
     for (;;) {
Index: Vanilla/ntserv/main.c
diff -u Vanilla/ntserv/main.c:1.27 Vanilla/ntserv/main.c:1.28
--- Vanilla/ntserv/main.c:1.27	Sat Aug 23 01:14:19 2003
+++ Vanilla/ntserv/main.c	Mon Feb 16 18:21:20 2004
@@ -176,7 +176,8 @@
 
     sendMotd();
 
-    pno = findslot(w_queue);
+    /* wait for a slot to become free */
+    pno = findslot(w_queue, host);
     if (pno < 0) {
 	/* trigger client's "Sorry, but you cannot play xtrek now.
 	   Try again later." */
@@ -186,7 +187,6 @@
 	sendClientPacket (&packet);
 	flushSockBuf ();
 	ERROR(2,("ntserv/main.c: Quitting: No slot available on queue %d\n",w_queue));
-	/* print some appropriate message */
 	exit(1);
     }
 

_______________________________________________
vanilla-devel mailing list
vanilla-devel at us.netrek.org
https://mailman.real-time.com/mailman/listinfo/vanilla-devel