From 3182a58a40f09ec41ae51eb4b5bd1a778df0dcda Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 6 Jun 2012 17:51:37 -0600 Subject: [PATCH] more p2 scoreboard work --- packages/p2/bin/scoreboard | 52 +++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/packages/p2/bin/scoreboard b/packages/p2/bin/scoreboard index fe873e0..64b312b 100755 --- a/packages/p2/bin/scoreboard +++ b/packages/p2/bin/scoreboard @@ -30,20 +30,42 @@ function escape(s) { return s } +function head() { + print "" + print "Project 2 Scoreboard" + print "" + print "" + print "" + print "
" +} + +function foot() { + print "
" +} + BEGIN { base = ENVIRON["CTF_BASE"] if (! base) { base = "/var/lib/ctf" } - # Only display two decimal places - CONVFMT = "%.2f" - - # New point at least every 2.5 minutes - interval = 150 - tslen = 0 - - nteams = 0; + head() } # MAINLOOP @@ -57,7 +79,6 @@ BEGIN { if (! (hash in team_names)) { fn = sprintf("%s/teams/names/%s", base, hash) getline team_names[hash] < fn - print (hash, team_names[hash]) close(fn) } @@ -85,6 +106,9 @@ END { total_score[hash] += cat_score[hash, cat] } scores[nteams++] = total_score[hash] + if (total_score[hash] > max_score) { + max_score = total_score[hash] + } } # Sort scores @@ -99,7 +123,7 @@ END { continue; } - name = team_names[hash] + name = escape(team_names[hash]) printf("%s\n", name) for (ncat = 0; ncat < ncats; ncat += 1) { @@ -107,11 +131,15 @@ END { points = cat_points[hash, cat]; if (cat_points[hash, cat] > 0) { - printf("", cat, points, escape(name)) + width = cat_score[hash, cat] / max_score * 80 + printf("", cat, points, name) printf(" %d\n", - ncat, cat_score[hash, cat] * 100, cat_points[hash, cat]) + ncat, width, cat_points[hash, cat]) } } } } + + foot() } +