Update of /cvsroot/netrek/client/netrekxp/src
In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv29214/src

Modified Files:
	cowmain.c data.c feature.c newwin.c playerlist.c ranklist.c 
	socket.c 
Log Message:
Support for server feature packet SP_RANKS.
NUMRANKS removed, replaced with dynamic variable
nranks.
Nranks treated like nranks2 (paradise), rank table is
loaded upon client initialization, table can be resized
if server sends additional ranks.
Ranklist window will always resize to proper size
based on number of ranks.

Index: newwin.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/newwin.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- newwin.c	28 Mar 2009 02:50:24 -0000	1.77
+++ newwin.c	25 May 2009 14:43:53 -0000	1.78
@@ -998,8 +998,8 @@
     planetw = W_MakeTextWindow ("planet", TWINSIDE + 2 * THICKBORDER + 10, 10, 57, nplanets + 3, baseWin, 2);
     W_SetWindowExposeHandler (planetw, planetlist);
 
-    // Rank window sized assuming only 9 (NUMRANKS) ranks, resized in paradise, see ranklist.c
-    rankw = W_MakeTextWindow ("rank", 10, 300, 80, NUMRANKS + 9, baseWin, 2);
+    // Rank window sized assuming only 9 (nranks) ranks, may be resized, see ranklist.c
+    rankw = W_MakeTextWindow ("rank", 10, 300, 80, nranks + 9, baseWin, 2);
     W_SetWindowExposeHandler (rankw, ranklist);
 
     // Player list windows will be too small if players > 36, which is possible in paradise
@@ -1932,7 +1932,7 @@
                     (me->p_stats2.st_royal == 0 ? ranks2[me->p_stats2.st_rank].name : royal[me->p_stats2.st_royal].name));
         else
         {
-            if (me->p_stats.st_rank >= NUMRANKS)
+            if (me->p_stats.st_rank >= nranks)
                 sprintf (buf, "Welcome aboard!");
             else
                 sprintf (buf, "Welcome aboard %s!", ranks[me->p_stats.st_rank].name);

Index: cowmain.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/cowmain.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- cowmain.c	19 Apr 2008 16:22:58 -0000	1.39
+++ cowmain.c	25 May 2009 14:43:53 -0000	1.40
@@ -779,7 +779,7 @@
         ind_ship_bmp_HR = stringDefault ("indshipHRbmpfile");
 
     resetdefaults ();
-    build_default_configuration(); // for paradise
+    build_default_configuration(); // load ranks/royals
     newwin (display_host, name);
 
     if (hideConsole)

Index: playerlist.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/playerlist.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- playerlist.c	28 Mar 2009 02:50:24 -0000	1.18
+++ playerlist.c	25 May 2009 14:43:53 -0000	1.19
@@ -1130,7 +1130,7 @@
                 format (buffPoint, "UNKN", 4, 0);
             else
             {
-                if (j->p_stats.st_rank >= NUMRANKS)
+                if (j->p_stats.st_rank >= nranks)
                     format (buffPoint, "UNKN", 4, 0);
                 else
                     format (buffPoint, ranks[j->p_stats.st_rank].cname, 4, 0);
@@ -1143,7 +1143,7 @@
                 format (buffPoint, (j->p_stats2.st_royal == 0 ? ranks2[j->p_stats2.st_rank].name : royal[j->p_stats2.st_royal].name), 10, 0);
             else
             {
-                if (j->p_stats.st_rank >= NUMRANKS)
+                if (j->p_stats.st_rank >= nranks)
                     format (buffPoint, "Unknown!  ", 10, 0);
                 else
                     format (buffPoint, ranks[j->p_stats.st_rank].name, 10, 0);

Index: ranklist.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/ranklist.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ranklist.c	16 Apr 2008 00:08:20 -0000	1.6
+++ ranklist.c	25 May 2009 14:43:53 -0000	1.7
@@ -117,9 +117,10 @@
     char buf[100];
 
     /* W_ClearWindow(rankw); */
+    W_ResizeTextWindow(rankw, 80, nranks2 + 9);
     (void) strcpy (buf, "  Rank       Hours  Offense  Ratings      DI");
     W_WriteText (rankw, 1, 1, textColor, buf, strlen (buf), W_BoldFont);
-    for (i = 0; i < NUMRANKS; i++)
+    for (i = 0; i < nranks; i++)
     {
         sprintf (buf, "%-11.11s %5.0f %8.2f %8.2f   %7.2f",
                  ranks[i].name,
@@ -128,7 +129,7 @@
                  ranks[i].ratings, ranks[i].ratings * ranks[i].hours);
         if (mystats->st_rank == i)
         {
-            if (i < NUMRANKS-1)
+            if (i < nranks-1)
             {
                 char buf2[35];
                 float DI;

Index: data.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/data.c,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -d -r1.122 -r1.123
--- data.c	23 May 2009 13:23:39 -0000	1.122
+++ data.c	25 May 2009 14:43:53 -0000	1.123
@@ -453,19 +453,9 @@
 
 struct ship shipvals[NUM_TYPES_BRONCO];
 
-/* 10 Aug 96 - Added curt (short) names -SAC */
-struct rank ranks[NUMRANKS] = {
-    {0.0, 0.0, 0.0, "Ensign", "Esgn"},
-    {2.0, 1.0, 0.0, "Lieutenant", "Lt "},
-    {4.0, 2.0, 0.0, "Lt. Cmdr.", "LtCm"},
-    {8.0, 3.0, 0.0, "Commander", "Cder",},
-    {15.0, 4.0, 0.0, "Captain", "Capt"},
-    {20.0, 5.0, 0.0, "Flt. Capt.", "FltC"},
-    {25.0, 6.0, 0.0, "Commodore", "Cdor"},
-    {30.0, 7.0, 0.0, "Rear Adm.", "RAdm"},
-    {40.0, 8.0, 0.0, "Admiral", "Admr"}
-};
+int nranks = 9;
 int nranks2 = 18;
+struct rank *ranks;
 struct rank2 *ranks2;
 int nroyals = 5;
 struct royalty *royal = 0;
@@ -770,6 +760,7 @@
 int F_sp_flags_all = 0;
 int F_why_dead_2 = 0;
 int F_auto_weapons = 0;
+int F_sp_ranks = 0;
 int F_terrain = 0;		/* paradise */
 int F_armies_shipcap = 0;	/* paradise */
 

Index: feature.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/feature.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- feature.c	23 May 2009 13:23:39 -0000	1.29
+++ feature.c	25 May 2009 14:43:53 -0000	1.30
@@ -104,6 +104,7 @@
     {"TERRAIN", &F_terrain, 'S', 1, 0, 0},
     /* armies in paradise ship_cap_spacket */
     {"ARMIES_IN_SHIPCAP", &F_armies_shipcap, 'S', 1, 0, 0},
+    {"SP_RANKS", &F_sp_ranks, 'S', 1, 0, 0},
     {0, 0, 0, 0, 0, 0}
 };
 

Index: socket.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/socket.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- socket.c	9 May 2009 21:21:43 -0000	1.59
+++ socket.c	25 May 2009 14:43:53 -0000	1.60
@@ -197,7 +197,7 @@
 #ifdef FEATURE_PACKETS
     {sizeof (struct feature_cpacket), handleFeature},   /* CP_FEATURE; 60 */
 #endif
-
+    {sizeof (struct ranks_spacket), handleRanks},      /* SP_RANKS */
 };
 
 int sizes[] = {
@@ -2448,7 +2448,7 @@
        servers.  Sanity check on pl->p_stats.st_rank moved to playerlist.c and newwin.c 
        as needed.  BB*/
     /*
-    if (packet->rank >= NUMRANKS)
+    if (packet->rank >= nranks)
     {
         LineToConsole ("handlePlyrLogin: bad rank %d\n", packet->rank);
         return;
@@ -2810,6 +2810,36 @@
 }
 
 void
+handleRanks (struct ranks_spacket *packet)
+{
+    int rankn;
+    int size;
+
+#ifdef CORRUPTED_PACKETS
+    if (packet->rankn > nranks)
+    {
+        LineToConsole ("handleRanks: bad index\n");
+        return;
+    }
+#endif
+    /* A new rank.  Reallocate memory as necessary. */
+    if (packet->rankn == nranks)
+    {
+        size = sizeof(struct rank) * ( nranks + 1 );
+        ranks = (struct rank *) realloc(ranks, size);
+        ranks[nranks].name = strdup("blank");
+        ranks[nranks].cname = strdup("UNKN");
+        nranks++;
+    }
+    rankn = packet->rankn;
+    STRNCPY(ranks[rankn].name, packet->name, 11);
+    STRNCPY(ranks[rankn].cname, packet->cname, 5);
+    ranks[rankn].hours = (float) (ntohl (packet->hours) / 100.0);
+    ranks[rankn].ratings = (float) (ntohl (packet->ratings) / 100.0);
+    ranks[rankn].offense = (float) (ntohl (packet->offense) / 100.0);
+}
+
+void
 initialize_players(void)
 {
     int i;
@@ -3333,7 +3363,63 @@
 void
 initialize_ranks(void)
 {
+    ranks = (struct rank *) malloc(sizeof(*ranks) * nranks);
     ranks2 = (struct rank2 *) malloc(sizeof(*ranks2) * nranks2);
+
+    ranks[0].hours = 0.0;
+    ranks[0].ratings = 0.0;
+    ranks[0].offense = 0.0;
+    ranks[0].name = strdup("Ensign");
+    ranks[0].cname = strdup("Esgn");
+
+    ranks[1].hours = 2.0;
+    ranks[1].ratings = 1.0;
+    ranks[1].offense = 0.0;
+    ranks[1].name = strdup("Lieutenant");
+    ranks[1].cname = strdup("Lt  ");
+
+    ranks[2].hours = 4.0;
+    ranks[2].ratings = 2.0;
+    ranks[2].offense = 0.0;
+    ranks[2].name = strdup("Lt. Cmdr.");
+    ranks[2].cname = strdup("LtCm");
+
+    ranks[3].hours = 8.0;
+    ranks[3].ratings = 3.0;
+    ranks[3].offense = 0.0;
+    ranks[3].name = strdup("Commander");
+    ranks[3].cname = strdup("Cder");
+
+    ranks[4].hours = 15.0;
+    ranks[4].ratings = 4.0;
+    ranks[4].offense = 0.0;
+    ranks[4].name = strdup("Captain");
+    ranks[4].cname = strdup("Capt");
+
+    ranks[5].hours = 20.0;
+    ranks[5].ratings = 5.0;
+    ranks[5].offense = 0.0;
+    ranks[5].name = strdup("Flt. Capt.");
+    ranks[5].cname = strdup("FltC");
+
+    ranks[6].hours = 25.0;
+    ranks[6].ratings = 6.0;
+    ranks[6].offense = 0.0;
+    ranks[6].name = strdup("Commodore");
+    ranks[6].cname = strdup("Cdor");
+
+    ranks[7].hours = 30.0;
+    ranks[7].ratings = 7.0;
+    ranks[7].offense = 0.0;
+    ranks[7].name = strdup("Rear Adm.");
+    ranks[7].cname = strdup("RAdm");
+
+    ranks[8].hours = 40.0;
+    ranks[8].ratings = 8.0;
+    ranks[8].offense = 0.0;
+    ranks[8].name = strdup("Admiral");
+    ranks[8].cname = strdup("Admr");
+    
     ranks2[0].genocides = 0;
     ranks2[0].di = 0;
     ranks2[0].battle = 0.0;
@@ -3476,6 +3562,7 @@
 void
 reinitialize_ranks(void)
 {
+    // Only used by paradise (when receive GPsizes packet)
     int     i;
     ranks2 = (struct rank2 *) malloc(sizeof(*ranks2) * nranks2);
 
@@ -3625,11 +3712,20 @@
 void
 free_ranks(void)
 {
-    int     i;
+    int i;
+    for (i = 0; i < nranks; i++)
+    {
+        if (ranks[i].name)
+            free(ranks[i].name);
+        if (ranks[i].cname)
+            free(ranks[i].cname);
+    }
     for (i = 0; i < nranks2; i++)
-	if (ranks2[i].name)
-	    free(ranks2[i].name);
+        if (ranks2[i].name)
+            free(ranks2[i].name);
+    free(ranks);
     free(ranks2);
+    ranks = 0;
     ranks2 = 0;
 }