Update of /cvsroot/netrek/server/Vanilla/ntserv
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6880/ntserv

Modified Files:
	commands.c daemonII.c feature.c findslot.c openmem.c rsa_key.c 
	socket.c wander2.c 
Log Message:


Index: rsa_key.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/rsa_key.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rsa_key.c	21 Mar 2005 05:23:44 -0000	1.1
+++ rsa_key.c	22 Apr 2006 02:16:46 -0000	1.2
@@ -7,6 +7,7 @@
  */
 #include "copyright2.h"
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -41,20 +42,21 @@
 {
     struct rsa_key key;
     struct sockaddr_in saddr;
+    socklen_t addrlen;
     u_char temp[KEY_SIZE], *data;
 #ifdef SHOW_RSA
     char format[MSG_LEN];
 #endif
     int fd;
     FILE *logfile;
-    int done, found, curtime, len;
+    int done, found, curtime;
     int foo;
     int total;
 
 /*    SIGNAL(SIGALRM, SIG_IGN);*/
 
-    len = sizeof(saddr);
-    if (getsockname(sock, &saddr, &len) < 0) {
+    addrlen = sizeof(saddr);
+    if (getsockname(sock, (struct sockaddr *) &saddr, &addrlen) < 0) {
         perror("getsockname(sock)");
         exit(1);
     }

Index: findslot.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/findslot.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- findslot.c	27 Sep 2005 12:26:37 -0000	1.3
+++ findslot.c	22 Apr 2006 02:16:46 -0000	1.4
@@ -9,6 +9,7 @@
 
 #include <stdio.h>
 #include <sys/types.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include "defs.h"
 #include "struct.h"

Index: openmem.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/openmem.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- openmem.c	21 Mar 2005 05:23:44 -0000	1.1
+++ openmem.c	22 Apr 2006 02:16:46 -0000	1.2
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
 #include <errno.h>
@@ -117,7 +118,7 @@
     if (sharedMemory == (struct memory *) -1) {
 	printf("Error number: %d\n",errno);
 	perror("shared memory");
-	exit (1);
+	exit(1);
     }
     setup_memory(sharedMemory);
 

Index: commands.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/commands.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- commands.c	21 Mar 2005 05:23:43 -0000	1.1
+++ commands.c	22 Apr 2006 02:16:46 -0000	1.2
@@ -15,6 +15,7 @@
 #include <time.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include "defs.h"
 #include "struct.h"
 #include "data.h"

Index: feature.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/feature.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- feature.c	21 Mar 2005 05:23:43 -0000	1.1
+++ feature.c	22 Apr 2006 02:16:46 -0000	1.2
@@ -67,6 +67,11 @@
 static int                    num_features;
 static struct feature_spacket *features;
 
+static void freeFeatures(void)
+{
+  free(features);
+}
+
 /*
  * Called once to read in feature strings
  */
@@ -97,6 +102,7 @@
       num_features = 0;
       return;
    }
+   atexit(freeFeatures);
 
    f = fopen(Feature_File, "r");
    i=0;

Index: daemonII.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/daemonII.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- daemonII.c	15 Apr 2006 12:10:57 -0000	1.7
+++ daemonII.c	22 Apr 2006 02:16:46 -0000	1.8
@@ -67,7 +67,7 @@
 /* file scope prototypes */
 static void check_load(void);
 static int tournamentMode(void);
-static int check_scummers(void);
+static int check_scummers(int);
 static void move(int ignored);
 static void udplayersight(void);
 static void udplayers(void);
@@ -394,7 +394,7 @@
    Nick Trown   12/19/92
 */
 
-static int check_scummers(void)
+static int check_scummers(int verbose)
 {
     int i, j;
     int num;
@@ -443,7 +443,8 @@
             }
           }
         }
-        if (num>1){
+        if (num>(check_scum-1)){
+            if (!verbose) return 1;
             pmessage(0,MALL,"GOD->ALL", "*****************************************");
             pmessage(0,MALL,"GOD->ALL","Possible t-mode scummers have been found.");
             pmessage(0,MALL,"GOD->ALL","They have been noted for god to review.");
@@ -553,6 +554,13 @@
     static int oldtourn=0;
     static int oldmessage;
     int old_robot;
+    static enum ts {
+	    TS_PICKUP, 
+	    TS_SCUMMERS,
+	    TS_BEGIN,
+	    TS_TOURNAMENT,
+	    TS_END
+    } ts = TS_PICKUP;
 
     /* Don't tell us it's time for another move in the middle of a move. */
     (void) SIGNAL(SIGALRM, SIG_IGN);
@@ -618,24 +626,49 @@
         pmessage(0, MALL, "GOD->ALL","Loading new server configuration.");
     }
 
-    if (tournamentMode()) {
-        if (!oldtourn) {
-            if (check_scum)     
-                check_scummers();               /* NBT */
-            oldmessage=(random() % 8);
+    switch (ts) {
+    case TS_PICKUP:
+	    status->tourn = 0;
+	    if (tournamentMode()) {
+		    ts = TS_BEGIN;
+		    if (check_scum && check_scummers(1))
+			    ts = TS_SCUMMERS;
+	    }
+	    break;
+
+    case TS_SCUMMERS:
+	    status->tourn = 0;
+	    if (!tournamentMode()) {
+		    ts = TS_PICKUP;
+	    } else {
+		    if (!check_scum) {
+			    ts = TS_BEGIN;
+			    break;
+		    }
+		    if (!check_scummers(0))
+			    ts = TS_BEGIN;
+	    }
+	    break;
+
+    case TS_BEGIN:
+	    oldmessage = (random() % 8);
 	    political_begin(oldmessage);
-        }
-        oldtourn=1;
-        status->tourn=1;
-        status->time++;
-        tourntimestamp = ticks;
-    } else {
-        if (oldtourn) {
+	    ts = TS_TOURNAMENT;
+            /* break; */
+
+    case TS_TOURNAMENT:
+            status->tourn = 1;
+            status->time++;
+            tourntimestamp = ticks;
+            if (tournamentMode()) break;
+            ts = TS_END;
+            /* break; */
+
+    case TS_END:
             tourntimestamp = ticks; /* record end of Tmode 8/2/91 TC */
-	    political_end(oldmessage);
-        }
-        oldtourn=0;
-        status->tourn=0;
+            political_end(oldmessage);
+            ts = TS_PICKUP;
+            break;
     }
 
 #ifdef PUCK_FIRST

Index: socket.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/socket.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- socket.c	10 Apr 2006 10:56:33 -0000	1.5
+++ socket.c	22 Apr 2006 02:16:46 -0000	1.6
@@ -13,6 +13,7 @@
  */
 #include "copyright2.h"
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/time.h>
@@ -364,7 +365,8 @@
 
 int connectToClient(char *machine, int port)
 {
-    int ns, stat, derrno, derrnol;
+    int ns, stat, derrno;
+    socklen_t derrnol;
     struct sockaddr_in addr;
     struct hostent *hp;
     struct timeval timeout;
@@ -488,7 +490,7 @@
 void checkSocket(void)
 {
     struct sockaddr_in sin;
-    int len = sizeof(sin);
+    socklen_t len = sizeof(sin);
     if (getpeername(sock, (struct sockaddr *) &sin, &len) < 0) {
 	return;
     }
@@ -961,7 +963,7 @@
     int temp;
 #ifdef UDP_PORTSWAP
     struct sockaddr_in moo;
-    int s;
+    socklen_t moolen;
 #endif
 
 #ifdef PING             /* need the socket in the ping handler routine */
@@ -978,10 +980,10 @@
      */
 
     if (portswapflags == (PORTSWAP_UDPRECEIVED | PORTSWAP_ENABLED)) {
-        s = sizeof(moo);
+        moolen = sizeof(moo);
         UDPDIAG(("portswap hack entered\n"));
         if (0 > recvfrom(asock, buf, BUFSIZ*2, MSG_PEEK,
-                         (struct sockaddr *)&moo, &s)) {
+                         (struct sockaddr *)&moo, &moolen)) {
 	    ERROR(1,("%s: portswap recvfrom() failed, %s\n",
 		     whoami(), strerror(errno)));
         }
@@ -2255,7 +2257,7 @@
 static int connUdpConn(void)
 {
     struct sockaddr_in addr;
-    int len;
+    socklen_t addrlen;
 
     if (udpSock > 0) {
 	ERROR(2,( "ntserv: tried to open udpSock twice\n"));
@@ -2273,8 +2275,8 @@
 
 #ifdef UDP_FIX 			/* 15/6/93 SK UDP connection time out fix */
     /* Bind to interface used by the TCP socket 10/13/99 TAP */
-    len = sizeof(addr);
-    if (getsockname(sock, (struct sockaddr *)&addr, &len) < 0) {
+    addrlen = sizeof(addr);
+    if (getsockname(sock, (struct sockaddr *)&addr, &addrlen) < 0) {
 	perror("netrek: unable to getsockname(TCP)");
 	UDPDIAG(("Can't get our own socket; using default interface\n"));
 	addr.sin_family = AF_INET;
@@ -2292,8 +2294,8 @@
     }
 
     /* determine what our port is */
-    len = sizeof(addr);
-    if (getsockname(udpSock, (struct sockaddr *)&addr, &len) < 0) {
+    addrlen = sizeof(addr);
+    if (getsockname(udpSock, (struct sockaddr *)&addr, &addrlen) < 0) {
 	perror("netrek: unable to getsockname(UDP)");
 	UDPDIAG(("Can't get our own socket; connection failed\n"));
 	close(udpSock);
@@ -2345,8 +2347,8 @@
 	     me->p_name, udpClientPort, remoteaddr));
 
     /* determine what our port is */
-    len = sizeof(addr);
-    if (getsockname(udpSock, (struct sockaddr *) &addr, &len) < 0) {
+    addrlen = sizeof(addr);
+    if (getsockname(udpSock, (struct sockaddr *) &addr, &addrlen) < 0) {
 	perror("netrek: unable to getsockname(UDP)");
 	UDPDIAG(("Can't get our own socket; connection failed\n"));
 	close(udpSock);
@@ -2384,17 +2386,17 @@
 static void printUdpInfo(void)
 {
     struct sockaddr_in addr;
-    int len;
+    socklen_t addrlen;
 
-    len = sizeof(addr);
-    if (getsockname(udpSock, (struct sockaddr *) &addr, &len) < 0) {
+    addrlen = sizeof(addr);
+    if (getsockname(udpSock, (struct sockaddr *) &addr, &addrlen) < 0) {
 	perror("printUdpInfo: getsockname");
 	return;
     }
     UDPDIAG(("LOCAL: addr=0x%x, family=%d, port=%d\n", addr.sin_addr.s_addr,
 	     addr.sin_family, ntohs(addr.sin_port)));
 
-    if (getpeername(udpSock, (struct sockaddr *) &addr, &len) < 0) {
+    if (getpeername(udpSock, (struct sockaddr *) &addr, &addrlen) < 0) {
 	perror("printUdpInfo: getpeername");
 	return;
     }

Index: wander2.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/ntserv/wander2.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- wander2.c	21 Mar 2005 05:23:44 -0000	1.1
+++ wander2.c	22 Apr 2006 02:16:46 -0000	1.2
@@ -14,6 +14,12 @@
 static const double incrementrecip = 62.5;
 static float *Cosine, *Sine;
 
+static void pfree(void)
+{
+  free(Cosine);
+  free(Sine);
+}
+
 /* call only once */
 void pinit(void)
 {
@@ -25,7 +31,11 @@
     pre = 3.5/increment;
 
     Cosine = (float*) calloc(sizeof(float), pre);
+    if (Cosine == NULL) abort();
     Sine = (float*) calloc(sizeof(float), pre);
+    if (Sine == NULL) abort();
+    atexit(pfree);
+
     for (i = 0; i < pre; i++) {
 	Cosine[i] = cos((double)i*increment);
 	Sine[i] = sin((double)i*increment);