Index: lib/netplay/netlog.c
===================================================================
--- lib/netplay/netlog.c	(revision 3771)
+++ lib/netplay/netlog.c	(working copy)
@@ -33,83 +33,115 @@
 // ////////////////////////////////////////////////////////////////////////
 
 // kluge, since I do not want to include src/multiplay.h here
-#define NET_MAX 52
+#define NET_MAX 52	//Update this if you update multiplay.h enums!
+#define MSG_MAX 6	//Update this if you update netplay.c enums!
 
+//matches multiplay.h now.
 static const char *packetname[NET_MAX] =
 {
-	"NET_DROID",
-	"NET_DROIDINFO",
-	"NET_DROIDDEST",
-	"NET_DROIDMOVE",
-	"NET_GROUPORDER",
-	"NET_TEMPLATE",
-	"NET_TEMPLATEDEST",
-	"NET_FEATUREDEST",
-	"NET_PING",
-	"NET_CHECK_DROID",
-	"NET_CHECK_STRUCT",
-	"NET_CHECK_POWER",
-	"NET_PLAYER_STATS",
-	"NET_BUILD",
-	"NET_STRUCTDEST",
-	"NET_BUILDFINISHED",
-	"NET_RESEARCH",
-	"NET_TEXTMSG",
-	"NET_LEAVING",
-	"NET_REQUESTDROID",
-	"NET_PLAYERCOMPLETE",
-	"NET_REQUESTPLAYER",
-	"NET_STRUCT",
-	"NET_WHOLEDROID",
-	"NET_FEATURES",
-	"NET_PLAYERRESPONDING",
-	"NET_OPTIONS",
-	"NET_KICK",
-	"NET_SECONDARY",
-	"NET_FIREUP",
-	"NET_ALLIANCE",
-	"NET_GIFT",
-	"NET_DEMOLISH",
-	"NET_COLOURREQUEST",
-	"NET_ARTIFACTS",
-	"NET_DMATCHWIN",
-	"NET_SCORESUBMIT",
-	"NET_DESTROYXTRA",
-	"NET_VTOL",
-	"NET_UNUSED_39",
-	"NET_WHITEBOARD",
-	"NET_SECONDARY_ALL",
-	"NET_DROIDEMBARK",
-	"NET_DROIDDISEMBARK",
-	"NET_RESEARCHSTATUS",
-	"NET_LASSAT",
-	"NET_REQUESTMAP",
-	"NET_AITEXTMSG",
+	"NET_DROID",				//0 a new droid
+	"NET_DROIDINFO",			//1 update a droid order.
+	"NET_DROIDDEST",			//2 issue a droid destruction
+	"NET_DROIDMOVE",			//3 move a droid, don't change anything else though..
+	"NET_GROUPORDER",			//4 order a group of droids.
+	"NET_TEMPLATE",			//5 a new template
+	"NET_TEMPLATEDEST",		//6 remove template
+	"NET_FEATUREDEST",		//7 destroy a game feature.
+	"NET_PING",				//8 ping players.
+	"NET_CHECK_DROID",		//9 check & update bot position and damage.
+	"NET_CHECK_STRUCT",		//10 check & update struct damage.
+	"NET_CHECK_POWER",		//11 power levels for a player.
+	"NET_PLAYER_STATS",			//12 player stats: HACK-NOTE: lib/netplay/netplay.c depends on this being 12
+	"NET_BUILD",				//13 build a new structure
+	"NET_STRUCTDEST",			//14 specify a strucutre to destroy
+	"NET_BUILDFINISHED",		//15 a building is complete.
+	"NET_RESEARCH",			//16 Research has been completed.
+	"NET_TEXTMSG",			//17 A simple text message between machines.
+	"NET_LEAVING",			//18 A player is leaving, (nicely)
+	"NET_UNUSED_19",			//19 a message has been recvd for an unknown droid, request the droid to resolve issues.
+	// JOINING TYPES. these msgs are used when a player joins a game in progress.
+	"NET_PLAYERCOMPLETE",		//20 All Setup information about player x has been sent
+	"NET_UNUSED_21",			//21 NOTUSED please send me info about a player; is unused now; but some code depends on this enum having these numbers (BAD!!!)
+	"NET_STRUCT",				//22 a complete structure
+	"NET_UNUSED_23",			//23 a complete droid
+	"NET_FEATURES",			//24 information regarding features.
+	"NET_PLAYERRESPONDING",	//25 computer that sent this is now playing warzone!
+	// RECENT TYPES
+	"NET_OPTIONS",			//26 welcome a player to a game.
+	"NET_KICK",				//27 kick a player .
+	"NET_SECONDARY",			//28 set a droids secondary order
+	"NET_FIREUP",				//29 campaign game has started, we can go too.. Shortcut message, not to be used in dmatch.
+	"NET_ALLIANCE",			//30 alliance data.
+	"NET_GIFT",				//31 a luvly gift between players.
+	"NET_DEMOLISH",			//32 a demolish is complete.
+	"NET_COLOURREQUEST",		//33 player requests a colour change.
+	"NET_ARTIFACTS",			//34 artifacts randomly placed.
+	"NET_DMATCHWIN",			//35 winner of a deathmatch. NOTUSED
+	"NET_SCORESUBMIT",		//36 submission of scores to host.
+	"NET_DESTROYXTRA",		//37 destroy droid with destroyer intact.
+	"NET_VTOL",				//38 vtol rearmed
+	"NET_UNUSED_39",			//39 unused
+	"NET_WHITEBOARD",			//40 whiteboard.
+    "NET_SECONDARY_ALL",      //41 complete secondary order.
+    "NET_DROIDEMBARK",        //42 droid embarked on a Transporter
+    "NET_DROIDDISEMBARK",     //43 droid disembarked from a Transporter
+	"NET_RESEARCHSTATUS",		//44 105, research state.
+	"NET_LASSAT",				//45 107, lassat firing.
+	"NET_REQUESTMAP",			//46 107 dont have map, please send it.
+	"NET_AITEXTMSG",			//chat between AIs
 	"NET_TEAMS_ON",
 	"NET_BEACONMSG",
 	"NET_SET_TEAMS",
 	"NET_TEAMREQUEST"
 };
+static const char *Msgpacketname[MSG_MAX]=
+{
+//these are from netplay.c
+//**note, MSG_PLAYER_STATS is NOT here because of the hack that is starts with 12
+// to match the NET_PLAYER_STATS in src/multiplay.h.
+	"MSG_JOIN", // needs to start at 90
+	"MSG_ACCEPTED",
+	"MSG_PLAYER_INFO",
+	"MSG_PLAYER_JOINED",
+	"MSG_PLAYER_LEFT",
+	"MSG_GAME_FLAGS"
+};
 
 static PHYSFS_file	*pFileHandle;
 static uint32_t		packetcount[2][NET_MAX];
 static uint32_t		packetsize[2][NET_MAX];
+static uint32_t		MSGpacketcount[2][MSG_MAX];
+static uint32_t		MSGpacketsize[2][MSG_MAX];
 
+const char *GetNETpacketName(uint8_t packet);
+
+// Used to get the string name of the packet type in question
+//
+const char *GetNETpacketName(uint8_t packet)
+{
+	if(packet > NET_MAX)
+	{
+		if (packet > 90  && packet < 96)		// that is range of other message types
+		return Msgpacketname[packet - 90];
+		else
+		return "UNKNOWN TYPE!";					// should never happen?
+	}
+	else
+	return packetname[packet];
+}
+
 BOOL NETstartLogging(void)
 {
 	time_t aclock;
 	struct tm *newtime;
 	char buf[256];
 	char *filename = "netplay.log";
-	int i;
 
-	for (i = 0; i < NET_MAX; i++)
-	{
-		packetcount[0][i] = 0;
-		packetsize[0][i] = 0;
-		packetcount[1][i] = 0;
-		packetsize[1][i] = 0;
-	}
+	//clear the stats arrays
+	memset(packetcount,0x0,sizeof(packetcount));
+	memset(packetsize,0x0,sizeof(packetsize));
+	memset(MSGpacketcount,0x0,sizeof(MSGpacketcount));
+	memset(MSGpacketsize,0x0,sizeof(MSGpacketsize));
 
 	time( &aclock );                 /* Get time in seconds */
 	newtime = localtime( &aclock );  /* Convert time to struct */
@@ -127,22 +159,36 @@
 	PHYSFS_write( pFileHandle, buf, strlen( buf ), 1 );
 	return TRUE;
 }
-
+// Finishes up the logging routine by printing the stats for all the packets we used.
 BOOL NETstopLogging(void)
 {
+	static const char nstats_line[] = "----------------------NET STATS-------------------------------\n";
+	static const char mstats_line[] = "----------------------MSG STATS-----------------------------\n";
 	char buf[256];
 	int i;
 
+	PHYSFS_write(pFileHandle, nstats_line, strlen(nstats_line), 1);
 	/* Output stats */
 	for (i = 0; i < NET_MAX; i++)
 	{
-		snprintf(buf, sizeof(buf), "%s: received %u times, %u bytes; sent %u times, %u bytes\n", packetname[i],
+		snprintf(buf, sizeof(buf), "[%02d]%22.22s:\t received %u times, %u bytes; sent %u times, %u bytes\n",i, packetname[i],
 			packetcount[0][i], packetsize[0][i], packetcount[1][i], packetsize[1][i]);
 		// Guarantee to nul-terminate
 		buf[sizeof(buf) - 1] = '\0';
 		PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
 	}
+	// the next set
+	PHYSFS_write(pFileHandle, mstats_line, strlen(mstats_line), 1);
+	for (i = 0; i < MSG_MAX; i++)
+	{
+		snprintf(buf, sizeof(buf), "[%02d]%22.22s:\t received %u times, %u bytes; sent %u times, %u bytes\n",i, Msgpacketname[i],
+			MSGpacketcount[0][i], MSGpacketsize[0][i], MSGpacketcount[1][i], MSGpacketsize[1][i]);
+		// Guarantee to nul-terminate
+		buf[sizeof(buf) - 1] = '\0';
+		PHYSFS_write(pFileHandle, buf, strlen(buf), 1);
+	}
 
+
 	if (!PHYSFS_close(pFileHandle))
 	{
 		debug(LOG_ERROR, "Could not close net log: %s", PHYSFS_getLastError());
@@ -151,11 +197,16 @@
 
 	return TRUE;
 }
-
+// keeps a running tally of times of packet is sent/received & bytes passed.
 void NETlogPacket(NETMSG *msg, BOOL received)
 {
 	if (msg->type >= NET_MAX)
-	{
+	{	
+		if (msg->type > 90  && msg->type < 96)	//only packets we know about
+		{	// need to subtract 90 to get start of array
+			MSGpacketcount[received][msg->type-90]++;
+			MSGpacketsize[received][msg->type-90] += msg->size;
+		}
 		return;
 	}
 	packetcount[received][msg->type]++;
@@ -192,10 +243,18 @@
 	}
 
 	if (a <= 51)
+	{
 		// replace common msgs with txt descriptions
 		snprintf(buf, sizeof(buf), "%s \t: %s \t:%d\t\t%s", str, packetname[a], b, asctime(newtime));
+	}
+	else if (a > 90 && a < 96)	//because of the enums need to get that range
+	{
+		snprintf(buf, sizeof(buf), "%s \t:%s \t\t\t:%d\t\t%s", str, Msgpacketname[a-90], b, asctime(newtime));
+	}
 	else
+	{	// no idea what packet was
 		snprintf(buf, sizeof(buf), "%s \t:%d \t\t\t:%d\t\t%s", str, a, b, asctime(newtime));
+	}
 
 	// Guarantee to nul-terminate
 	buf[sizeof(buf) - 1] = '\0';
