Date:	Tuesday July 1, 2003 @ 7:54
Author:	xyzzy

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

Modified Files:
	genspkt.c 
Log Message:
Fix major bugs with short packets VPlanet code and armies.  Someone forgot
that the army count in the planet packet is in network byte order.  This
resulted in VPlanet style packets always having 0 for the army count.  But
another bug of the same nature kept short packets from getting used when the
army count was less than 128 and more than 0, so no one noticed.  Short
packets would only get used for planets where armies%256 >= 128, resulting in
strange behavior when stockpiling huge numbers.  Fixed both bugs and added a
few comments.


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

Index: Vanilla/ntserv/genspkt.c
diff -u Vanilla/ntserv/genspkt.c:1.26 Vanilla/ntserv/genspkt.c:1.27
--- Vanilla/ntserv/genspkt.c:1.26	Sun Jan 12 15:58:41 2003
+++ Vanilla/ntserv/genspkt.c	Tue Jul  1 07:54:58 2003
@@ -757,6 +757,9 @@
     return (FALSE);
 }
 
+/* Determines if the planet's info has changed since it was last sent to the
+   client.  If so, it updates the planet packet with current data and returns
+   true. */
 inline static int
 updtPlanet(struct planet_spacket *pl, struct planet *plan, int howmuch)
 {
@@ -776,7 +779,7 @@
 	    pl->owner=plan->pl_owner;
 	    return (TRUE);
 	} 
-    } else {
+    } else { /* UPDT_LITTLE */
 	if (pl->info & me->p_team) {
 	    pl->type=SP_PLANET;
 	    pl->pnum=plan->pl_no;
@@ -790,6 +793,9 @@
     return (FALSE);
 }
 
+/* Given a normal planet packet in pl, pack the data onto the end of the
+   VPlanet buffer and increment the count.  The vplanet packet is a more
+   efficient way to send multiple planet updates with typical values.  */
 inline static int
 addVPlanet(struct planet_spacket *pl)
 {
@@ -800,17 +806,22 @@
     npl->pnum=pl->pnum;
     npl->info=pl->info;
     npl->flags=pl->flags;
-    npl->armies=(u_char) pl->armies;
+    npl->armies=(u_char) ntohl(pl->armies);
     npl->owner=pl->owner;
     npl++;
     clientVPlanetCount++;
     return (TRUE);
 }
 
+/* howmuch is how much info to send, UPDT_LITTLE means just the information
+   sent for unscouted planets, UPDT_ALL means send everything.  The return
+   value isn't actually used.  */
 int sndPlanet(struct planet_spacket *pl, struct planet *plan, int howmuch)
 {
     if (updtPlanet(pl, plan, howmuch)) {
-	if ( send_short  && pl->armies < 256 )
+	/* Vplanet is more efficient, but only works when there are less than
+	   256 armies */
+	if ( send_short  && plan->pl_armies < 256 )
 	    addVPlanet(pl);
 	else
 	    sendClientPacket(pl);
@@ -1411,10 +1422,12 @@
 	 */
 	if ((me->p_x > 0) && (me->p_y > 0) && (me->p_team == NOBODY) ) {
 	    sndPlanet(pl, plan, UPDT_ALL);
-	} else if ((plan->pl_info & me->p_team)==0) {
-	    sndPlanet(pl, plan, UPDT_LITTLE);
 	} else if ( plan->pl_info & me->p_team ) {
+	    /* scouted */
 	    sndPlanet(pl, plan, UPDT_ALL);
+	} else {
+	    /* Not scouted */
+	    sndPlanet(pl, plan, UPDT_LITTLE);
 	}
 	/* Assume that the planet only needs to be updated once... */
 

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