Date:	Saturday July 1, 2000 @ 3:35
Author:	xyzzy

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

Modified Files:
	genspkt.c socket.c 
Log Message:
Fixed a few bugs with the putting of flags inside the SelfShip packet and the
UDP Sequence packet.  The UDP sequence packet is generated before the update,
so it used to reflect old flags.  I made a new function that updates the
sequence packet at the end of the update interval, so that the flags it
contains are current.


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

Index: Vanilla/ntserv/genspkt.c
diff -u Vanilla/ntserv/genspkt.c:1.16 Vanilla/ntserv/genspkt.c:1.17
--- Vanilla/ntserv/genspkt.c:1.16	Sat May 27 04:46:25 2000
+++ Vanilla/ntserv/genspkt.c	Sat Jul  1 03:35:44 2000
@@ -494,31 +494,33 @@
 
 	self->type = SP_S_YOU_SS;
 
-	if (f_many_self)
+	if (f_many_self) {
+	    /* f_many_self is turned on by cambot when it uses this code
+	       to record the game to a file.  The normal server doesn't use
+	       it.  Since the player number is stuck in pad1, it can't be
+	       used to send player flags */
 	    self->pad1 = pl->p_no;
-	else if (F_19flags) {
-	    u_int f = pl->p_flags;
-	    self->pad1 = ((f&PFGREEN )?2:(f&PFYELLOW  )?1:0) +
-			 ((f&PFBEAMUP)?2:(f&PFBEAMDOWN)?1:0)*3 +
-			 ((f&PFPLOCK )?2:(f&PFPLLOCK  )?1:0)*9 +
-			 ((f&PFPRESS )?1:(f&PFTRACT   )?2:0)*27 +   /* weird */
-			 ((f&PFORBIT )?2:(f&PFDOCK    )?1:0)*81;
-	    /* since flags are sent now, note the update */
-	    f = (PFGREEN|PFYELLOW|PFRED|PFBEAMUP|PFBEAMDOWN|PFPLOCK|PFPLLOCK|
-	         PFPRESS|PFTRACT|PFORBIT|PFDOCK);
-	    if(send_short > 1 && commMode == COMM_UDP)  
-	        /* well send these in the sequence packet */
-		f |= (PFSHIELD|PFREPAIR|PFBOMB|PFCLOAK|
-		     PFWEP|PFENG|PFREFITTING|PFDOCKOK);
-	    clientSelfShort.flags = (clientSelfShort.flags & htonl(~f)) |
-				    htonl(pl->p_flags & f);
-	} else if (F_self_8flags) {
-	    /* FEATURE SELF_8FLAGS */
-	    self->pad1 = pl->p_flags & 255; /* For future use */
+	} else {
+	    /* See if we can stuff some flags in the pad byte */
+	    u_int f=0;
+	    if (F_19flags) {
+		f = pl->p_flags;
+		self->pad1 = ((f&PFGREEN )?2:(f&PFYELLOW  )?1:0) +
+			     ((f&PFBEAMUP)?2:(f&PFBEAMDOWN)?1:0)*3 +
+			     ((f&PFPLOCK )?2:(f&PFPLLOCK  )?1:0)*9 +
+			     ((f&PFPRESS )?1:(f&PFTRACT   )?2:0)*27 +
+			     ((f&PFORBIT )?2:(f&PFDOCK    )?1:0)*81;
+		f = (PFGREEN|PFYELLOW|PFRED|PFBEAMUP|PFBEAMDOWN|PFPLOCK|
+		     PFPLLOCK|PFPRESS|PFTRACT|PFORBIT|PFDOCK);
+	    } else if (F_self_8flags) {
+		self->pad1 = pl->p_flags & 0xff;
+		f = 0xff;
+	    }
 	    /* since flags are sent now, note the update */
-	    clientSelfShort.flags = (clientSelfShort.flags & htonl(~0xff)) |
-				    htonl(pl->p_flags & 0xff);
-	};
+	    if(f)
+		clientSelfShort.flags = (clientSelfShort.flags & htonl(~f)) |
+					htonl(pl->p_flags & f);
+	}
 
 	self->damage=htons(pl->p_damage);
 	self->shield=htons(pl->p_shield);
@@ -2420,23 +2422,57 @@
     ssp = (struct sequence_spacket *) outbuf;
     ssp->type = SP_SEQUENCE;
     ssp->sequence = htons((u_short) *seq_no);
+    (*seq_no)++;
+
+    return (sizeof(struct sequence_spacket));
+}
+
+/* Add some of the player flags into the sequence packet.  This isn't done
+   when the sequence packet is made, because that is at the beginning of the
+   update.  The flags sent should be from the end of the update, nominally
+   100ms later. */
+void
+addSequenceFlags(struct sequence_spacket *ssp)
+{
+    u_int f=0;
+
+    /* Doesn't look like a sequence packet */
+    if(ssp->type != SP_SEQUENCE) return;
+
+    /* In cambot mode, we are dumping packets about all players, not 
+       just one. So sending the flags for "me" makes no sense.  */
+    if(f_many_self) return;
+
     if (F_19flags) {
+	/* Send the most useful flags that aren't packed into the
+	   SelfShip packet. */
 	ssp->flag8 = (me->p_flags&PFSHIELD    ? 0x01 : 0) |
-	             (me->p_flags&PFREPAIR    ? 0x02 : 0) |
-	             (me->p_flags&PFBOMB      ? 0x04 : 0) |
-	             (me->p_flags&PFCLOAK     ? 0x08 : 0) |
-	             (me->p_flags&PFWEP       ? 0x10 : 0) |
-	             (me->p_flags&PFENG       ? 0x20 : 0) |
-	             (me->p_flags&PFREFITTING ? 0x40 : 0) |
-	             (me->p_flags&PFDOCKOK    ? 0x80 : 0);
-    } else if (!f_many_self) {
+		     (me->p_flags&PFREPAIR    ? 0x02 : 0) |
+		     (me->p_flags&PFBOMB      ? 0x04 : 0) |
+		     (me->p_flags&PFCLOAK     ? 0x08 : 0) |
+		     (me->p_flags&PFWEP       ? 0x10 : 0) |
+		     (me->p_flags&PFENG       ? 0x20 : 0) |
+		     (me->p_flags&PFREFITTING ? 0x40 : 0) |
+		     (me->p_flags&PFDOCKOK    ? 0x80 : 0);
+	f = (PFSHIELD|PFREPAIR|PFBOMB|PFCLOAK|
+	     PFWEP|PFENG|PFREFITTING|PFDOCKOK);
+    } else {
+	/* S_P2 mode, send flags 8-15.  Flags 0-7 are in the SelfShip
+	   packet. */
 	ssp->flag8 = (((unsigned int)me->p_flags >> 8) & 0xff); /* S_P2 */
-	clientSelfShort.flags = (clientSelfShort.flags & htonl(~0xff)) |
-	                        htonl(me->p_flags & 0xff);
+	if(send_short > 1 ) {
+	    /* In S_P2 mode, consider the flags sent to the client */
+	    f = 0xff00;
+	} else {
+	    /* Non-SP2, probably the client doesn't understand these flags 
+	       but maybe it does.  Sent them, but consider them not sent. */
+	    f = 0;
+	}
     }
-    (*seq_no)++;
-
-    return (sizeof(struct sequence_spacket));
+    /* Consider the flags sent in this packet as sent, and do not resend
+       with a SelfShort or Self packet */
+    clientSelfShort.flags = (clientSelfShort.flags & htonl(~f)) |
+			    htonl(me->p_flags & f);
 }
 
 void
Index: Vanilla/ntserv/socket.c
diff -u Vanilla/ntserv/socket.c:1.24 Vanilla/ntserv/socket.c:1.25
--- Vanilla/ntserv/socket.c:1.24	Tue May 23 20:16:31 2000
+++ Vanilla/ntserv/socket.c	Sat Jul  1 03:35:44 2000
@@ -1,4 +1,4 @@
-/* $Id: socket.c,v 1.24 2000/05/24 01:16:31 jeffno Exp $
+/* $Id: socket.c,v 1.25 2000/07/01 08:35:44 xyzzy Exp $
  */
 
 /*
@@ -634,6 +634,7 @@
 
     if(send_short) {
 	updatePlasmas();
+	if(commMode == COMM_UDP) addSequenceFlags(udpbuf);
 	updateSelf(FALSE);
 	updatePhasers();
 	updateShips();
@@ -785,6 +786,7 @@
             packets_sent ++;
 #endif
 	    if (udpbufptr-udpbuf+size >= UDPBUFSIZE) {
+		addSequenceFlags(udpbuf);
 		t=udpbufptr-udpbuf;
 		if (gwrite(udpSock, udpbuf, t) != t) {
 		    ERROR(1,("%s: gwrite(UDP) failed, %s, client marked dead once more\n",