Update of /cvsroot/netrek/client/netrekxp/src In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv20255/src Modified Files: death.c socket.c Log Message: SP_RANK, update to new packet protocol. Adopt COW handleRank(), more robust code. Add check to promotion message for valid rank. Index: death.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/death.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- death.c 16 Apr 2008 00:08:09 -0000 1.22 +++ death.c 28 May 2009 01:19:16 -0000 1.23 @@ -89,7 +89,10 @@ if (promoted) { - sprintf (rankmessage, "Congratulations, You have scummed up to %s", + if (mystats->st_rank >= nranks) + sprintf (rankmessage, "Congratulations, you have been promoted!"); + else + sprintf (rankmessage, "Congratulations, you have scummed up to %s!", paradise ? ranks2[mystats->st_rank].name : ranks[mystats->st_rank].name); W_WriteText (w, 50, 80, W_Yellow, rankmessage, strlen (rankmessage), W_BoldFont); Index: socket.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/socket.c,v retrieving revision 1.63 retrieving revision 1.64 diff -u -d -r1.63 -r1.64 --- socket.c 27 May 2009 23:07:05 -0000 1.63 +++ socket.c 28 May 2009 01:19:16 -0000 1.64 @@ -2812,24 +2812,22 @@ void handleRank (struct rank_spacket *packet) { - int i = packet->rankn; - int size; + int i = packet->rnum; + int j = packet->rmax + 1; #ifdef CORRUPTED_PACKETS - if (i > nranks) + if (i < 0 || j < 0 || i > j) { - LineToConsole ("handleRanks: bad index\n"); + LineToConsole ("handleRanks: invalid rnum or rmax\n"); return; } #endif - /* A new rank. Reallocate memory as necessary. */ - if (i == nranks) + /* Reallocate rank memory as necessary. */ + if (j > nranks) { - size = sizeof(struct rank) * ( nranks + 1 ); - ranks = (struct rank *) realloc(ranks, size); - ranks[nranks].name = strdup("blank"); - ranks[nranks].cname = strdup("UNKN"); - nranks++; + ranks = (struct rank *) realloc(ranks, j * sizeof(struct rank)); + memset(&ranks[nranks], 0, (j - nranks) * sizeof(struct rank)); + nranks = j; W_ResizeTextWindow(rankw, 80, nranks + 9); } packet->name[15] = 0; @@ -5319,8 +5317,9 @@ case SP_RANK : LineToConsole("\nS->C SP_RANK\t"); if (log_packets > 1) - LineToConsole(" rankn=%d, name=\"%s\", hours=%d, ratings=%d, offense=%d, cname=\"%s\"", - ((struct rank_spacket *) packet)->rankn, + LineToConsole(" rnum=%d, rmax=%d, name=\"%s\", hours=%d, ratings=%d, offense=%d, cname=\"%s\"", + ((struct rank_spacket *) packet)->rnum, + ((struct rank_spacket *) packet)->rmax, ((struct rank_spacket *) packet)->name, ntohl(((struct rank_spacket *) packet)->hours), ntohl(((struct rank_spacket *) packet)->ratings),