Date: Wednesday July 18, 2001 @ 2:53 Author: xyzzy Update of /home/netrek/cvsroot/Vanilla/ntserv In directory swashbuckler.fortress.real-time.com:/var/tmp/cvs-serv18334 Modified Files: genspkt.c Log Message: Make sending of player stats much more punctual. The old system went through the player slots (all 32 of them), in order, one slot per second. If that packet was too big, then sending stats was skipped for that slot until its turn came around again in another 32 seconds. The new system only checks real players, empty slots and observers are skipped. If the packet is too big, then the stats will get sent on the next packet that isn't too big. A slot doesn't get skipped, just delayed a bit until there is a lull in bandwidth. **************************************** Index: Vanilla/ntserv/genspkt.c diff -u Vanilla/ntserv/genspkt.c:1.21 Vanilla/ntserv/genspkt.c:1.22 --- Vanilla/ntserv/genspkt.c:1.21 Thu May 10 18:19:46 2001 +++ Vanilla/ntserv/genspkt.c Wed Jul 18 02:53:09 2001 @@ -2043,165 +2043,50 @@ } /* Function */ -#ifdef LTD_STATS - void updatePlayerStats(void) { - struct stats_spacket *stats; + struct stats_spacket *stats; struct stats_s_spacket *s_stats = &singleStats; - struct player *pl; - int i = efticks(5); - - unsigned int total_kills, total_deaths, total_armies_bombed, total_ticks, - total_planets_taken, sb_kills, sb_deaths, sb_ticks; - - unsigned int my_kills, my_deaths, my_armies_bombed, my_ticks, - my_planets_taken, my_sb_kills, my_sb_deaths, my_sb_ticks; - - - if(repCount % i) - return; - - i = (repCount/i) % MAXPLAYER; - - pl = &players[i]; - if(!pl->p_status) return; - - stats = &clientStats[i]; - - /* Taken from inl source, socket.c. Hack for INL robot (when stats are - reset). Stick it in here for lack of a better place. Needed because - these are ntserv process variables, so robot can't touch them. */ - - my_kills = ltd_kills(me, LTD_TOTAL); - my_deaths = ltd_deaths(me, LTD_TOTAL); - my_armies_bombed = ltd_armies_bombed(me, LTD_TOTAL); - my_ticks = ltd_ticks(me, LTD_TOTAL); - my_planets_taken = ltd_planets_taken(me, LTD_TOTAL); - my_sb_kills = ltd_kills(me, LTD_SB); - my_sb_deaths = ltd_deaths(me, LTD_SB); - my_sb_ticks = ltd_ticks(me, LTD_SB); - - total_kills = ltd_kills(pl, LTD_TOTAL); - total_deaths = ltd_deaths(pl, LTD_TOTAL); - total_armies_bombed = ltd_armies_bombed(pl, LTD_TOTAL); - total_ticks = ltd_ticks(pl, LTD_TOTAL); - total_planets_taken = ltd_planets_taken(pl, LTD_TOTAL); - sb_kills = ltd_kills(pl, LTD_SB); - sb_deaths = ltd_deaths(pl, LTD_SB); - sb_ticks = ltd_ticks(pl, LTD_SB); - - - - if (startTkills > my_kills || - startTlosses > my_deaths || - startTarms > my_armies_bombed || - startTplanets > my_planets_taken || - startTticks > my_ticks) - { - startTkills = my_kills; - startTlosses = my_deaths; - startTarms = my_armies_bombed; - startTplanets = my_planets_taken; - startTticks = my_ticks; - } - - /* - * Send stat packets once per five updates. But, only send one. We - * will cycle through them all eventually. - */ - if ( stats->tkills != htonl((long) total_kills) || - stats->tlosses != htonl((long) total_deaths) || - stats->kills != htonl((long) 0) || - stats->losses != htonl((long) 0) || - stats->tticks != htonl((long) total_ticks) || - stats->tplanets != htonl((long) total_planets_taken) || - stats->tarmies != htonl((long) total_armies_bombed) || - stats->sbkills != htonl((long) sb_kills) || - stats->sblosses != htonl((long) sb_deaths) || - stats->armies != htonl((long) 0) || - stats->planets != htonl((long) 0)) { - - stats->tkills = htonl((long) total_kills); - stats->tlosses = htonl((long) total_deaths); - stats->kills = htonl((long) 0); - stats->losses = htonl((long) 0); - stats->tticks = htonl((long) total_ticks); - stats->tplanets = htonl((long) total_planets_taken); - stats->tarmies = htonl((long) total_armies_bombed); - stats->sbkills = htonl((long) sb_kills); - stats->sblosses = htonl((long) sb_deaths); - stats->armies = htonl((long) 0); - stats->planets = htonl((long) 0); - - if ((pl->p_ship.s_type == STARBASE) && (SBhours)) { - stats->maxkills=htonl((long) sb_ticks); - } else { - stats->maxkills=htonl(ltd_kills_max(pl, LTD_TOTAL) * 100); - } - stats->sbmaxkills = htonl(ltd_kills_max(pl, LTD_SB) * 100); - - stats->type = SP_STATS; - stats->pnum = i; - if (send_short > 1 && - total_kills < 0xffff && - total_deaths < 0xffff && - total_deaths < 0xffff && - total_planets_taken < 0xffff && - sb_kills < 0xffff && - sb_deaths < 0xffff && - total_planets_taken < 0xffff ) { - - s_stats->tkills = htons(total_kills); - s_stats->tlosses = htons(total_deaths); - s_stats->kills = htons(0); - s_stats->losses = htons(0); - s_stats->tticks = htonl(total_ticks); - s_stats->tplanets = htons(total_planets_taken); - s_stats->tarmies = htonl(total_armies_bombed); - s_stats->sbkills = htons(sb_kills); - s_stats->sblosses = htons(sb_deaths); - s_stats->armies = htons(0); - s_stats->planets = htons(0); - - if ((pl->p_ship.s_type == STARBASE) && (SBhours)) { - s_stats->maxkills=htonl(sb_ticks); - } else { - s_stats->maxkills=htonl(ltd_kills_max(pl, LTD_TOTAL) * 100); - } - s_stats->sbmaxkills=htonl(ltd_kills_max(pl, LTD_SB) * 100); - - s_stats->type=SP_S_STATS; - s_stats->pnum=i; - sendClientPacket(s_stats); - } - else - sendClientPacket((CVOID) stats); + struct player *pl; + static int lastrep=0; + static int lastpno=MAXPLAYER; + int i; + + /* Wait at least 1 second before sending another stats packet */ + if((repCount - lastrep) < efticks(5)) return; + lastrep = repCount; + + /* Look for the next non-empty non-observer slot */ + for(i=1;i<=MAXPLAYER;i++) { + pl = &players[(lastpno+i)%MAXPLAYER]; + if(pl->p_status!=PFREE && pl->p_status!=POBSERV) break; } -} -#else /* LTD_STATS */ - -void updatePlayerStats(void) -{ - struct stats_spacket *stats; - struct stats_s_spacket *s_stats = &singleStats; - struct player *pl; - int i = efticks(5); - - if(repCount % i) - return; + /* No one playing...? */ + if(i>MAXPLAYER) return; - i = (repCount/i) % MAXPLAYER; + lastpno = pl->p_no; + stats = &clientStats[pl->p_no]; - pl = &players[i]; - if(!pl->p_status) return; - - stats = &clientStats[i]; +#ifdef LTD_STATS + me->p_stats.st_tkills = ltd_kills(me, LTD_TOTAL); + me->p_stats.st_tlosses = ltd_deaths(me, LTD_TOTAL); + me->p_stats.st_tarmsbomb = ltd_armies_bombed(me, LTD_TOTAL); + me->p_stats.st_tticks = ltd_ticks(me, LTD_TOTAL); + me->p_stats.st_tplanets = ltd_planets_taken(me, LTD_TOTAL); + me->p_stats.st_sbkills = ltd_kills(me, LTD_SB); + me->p_stats.st_sblosses = ltd_deaths(me, LTD_SB); + me->p_stats.st_sbticks = ltd_ticks(me, LTD_SB); + me->p_stats.st_maxkills = ltd_kills_max(pl, LTD_TOTAL) + me->p_stats.st_sbmaxkills = ltd_kills_max(pl, LTD_SB) + me->p_stats.st_kills = 0; + me->p_stats.st_losses = 0; + me->p_stats.st_armsbomb = 0; + me->p_stats.st_planets = 0; +#endif /* LTD_STATS */ /* Taken from inl source, socket.c. Hack for INL robot (when stats are reset). Stick it in here for lack of a better place. Needed because these are ntserv process variables, so robot can't touch them. */ - if (startTkills > me->p_stats.st_tkills || startTlosses > me->p_stats.st_tlosses || startTarms > me->p_stats.st_tarmsbomb || @@ -2250,7 +2135,7 @@ } stats->sbmaxkills = htonl((int) (pl->p_stats.st_sbmaxkills * 100)); stats->type = SP_STATS; - stats->pnum = i; + stats->pnum = pl->p_no; if (send_short > 1 && pl->p_stats.st_tkills < 0xffff && pl->p_stats.st_tlosses < 0xffff && @@ -2270,22 +2155,16 @@ s_stats->sblosses = htons(pl->p_stats.st_sblosses); s_stats->armies = htons(pl->p_stats.st_armsbomb); s_stats->planets = htons(pl->p_stats.st_planets); - if ((pl->p_ship.s_type == STARBASE) && (SBhours)) { - s_stats->maxkills=htonl((int) (pl->p_stats.st_sbticks)); - } else { - s_stats->maxkills=htonl((int) (pl->p_stats.st_maxkills * 100)); - } - s_stats->sbmaxkills=htonl((int) (pl->p_stats.st_sbmaxkills * 100)); + s_stats->maxkills = stats->maxkills; + s_stats->sbmaxkills = stats->sbmaxkills; s_stats->type=SP_S_STATS; - s_stats->pnum=i; + s_stats->pnum=pl->p_no; sendClientPacket(s_stats); - } - else + } else sendClientPacket((CVOID) stats); } } -#endif /* LTD_STATS */ /* Called by initClientData - This routine initialized the local packet information to an unobtainable state. (Which then forces updates to