Tanks now working (!), scoreboard fixes

This commit is contained in:
Neale Pickett 2010-10-26 16:43:51 -06:00
parent 9c472de526
commit fb9ffa8b5c
17 changed files with 116 additions and 97 deletions

View File

@ -1,2 +1,2 @@
* claim.cgi not exiting (maybe fixed?) * claim.cgi not exiting (maybe fixed?)
* get LAUR for contest

View File

@ -51,4 +51,5 @@ echo "$color" > $base/teams/colors/$hash
echo "Registered with hash: $hash" echo "Registered with hash: $hash"
# Create encrypted listing of teams # Create encrypted listing of teams
ls $base/teams/names | KEY="Too much cheese." | /opt/mcp/bin/arc4 > $www/teams.txt ls $base/teams/names | KEY="Too much cheese." /opt/mcp/bin/arc4 > $www/teams.txt.$$
mv $www/teams.txt.$$ $www/teams.txt

View File

@ -30,18 +30,18 @@ function escape(s) {
return s return s
} }
function print_bar(cat, team, n, d) { function print_bar(cat, teamid, teamname, n, d) {
printf("<div class=\"t%s score\"" \ printf("<div class=\"t%s score\"" \
" style=\"height: %.2f%%;\"" \ " style=\"height: %.2f%%;\"" \
" onmouseover=\"highlight('%s')\"" \ " onmouseover=\"highlight('%s')\"" \
" onmouseout=\"restore('%s')\">\n" \ " onmouseout=\"restore('%s')\">\n" \
"<!-- %s --> %s: %s\n" \ "<!-- %s --> %s: %s\n" \
"</div>", "</div>",
team, teamid,
100 * n / d, 100 * n / d,
team, teamid,
team, teamid,
cat, escape(names_by_team[team]), n) cat, escape(name), n)
} }
function output( t, c) { function output( t, c) {
@ -203,7 +203,7 @@ BEGIN {
for (team in teams) { for (team in teams) {
if (scores[i] == scores_by_team_time[team, lasttime]) { if (scores[i] == scores_by_team_time[team, lasttime]) {
name = names_by_team[team] name = names_by_team[team]
print_bar("total", teams[team], scores[i], ncats) print_bar("total", teams[team], name, scores[i], ncats)
} }
} }
} }
@ -232,7 +232,7 @@ BEGIN {
points = points_by_cat_team[cat, team] points = points_by_cat_team[cat, team]
if (l[j] == points) { if (l[j] == points) {
name = names_by_team[team] name = names_by_team[team]
print_bar(cat, teams[team], points, points_by_cat[cat]) print_bar(cat, teams[team], name, points, points_by_cat[cat])
} }
} }
} }
@ -242,7 +242,7 @@ BEGIN {
print " </tr>" print " </tr>"
print " </table>" print " </table>"
print " <canvas id=\"chart\" width=\"800\" height=\"400\"></canvas>" print " <canvas id=\"chart\" width=\"800\" height=\"300\"></canvas>"
print " <p><a href=\"scoring.html\">About scoring</a></p>" print " <p><a href=\"scoring.html\">About scoring</a></p>"
print " </body>" print " </body>"
print "</html>" print "</html>"

View File

@ -8,6 +8,7 @@ mcp-install: mcp-build
cp packages/mcp/src/pointscli $(MCP_PKGDIR)/bin/ cp packages/mcp/src/pointscli $(MCP_PKGDIR)/bin/
cp packages/mcp/src/tokencli $(MCP_PKGDIR)/bin/ cp packages/mcp/src/tokencli $(MCP_PKGDIR)/bin/
cp packages/mcp/src/puzzles.cgi $(MCP_PKGDIR)/bin/ cp packages/mcp/src/puzzles.cgi $(MCP_PKGDIR)/bin/
cp packages/mcp/src/arc4 $(MCP_PKGDIR)/bin/
$(call COPYTREE, packages/mcp/service, $(MCP_PKGDIR)/service) $(call COPYTREE, packages/mcp/service, $(MCP_PKGDIR)/service)

View File

@ -4,7 +4,7 @@ exec 2>&1
DB=/var/lib/ctf/tokens.db DB=/var/lib/ctf/tokens.db
if [ ! -f $DB ]; do if [ ! -f $DB ]; then
# Append any package-provided tokens # Append any package-provided tokens
cat /opt/*/tokens >$DB 2>/dev/null cat /opt/*/tokens >$DB 2>/dev/null
chown ctf $DB chown ctf $DB

View File

@ -37,12 +37,11 @@ a img {
a { a {
text-decoration: underline; text-decoration: underline;
color: #84b; color: #84b;
font-weight: bold;
} }
a:hover { a:hover {
color: #2a4;
background: #333; background: #333;
font-weight: bold;
} }
@ -69,7 +68,11 @@ th {
} }
td { td {
vertical-align: top; vertical-align: top;
text-align: right; text-align: left;
}
dt {
font-weight: bold;
} }
p { p {
@ -83,42 +86,28 @@ hr {
/*** left side bar ***/ /*** navigation bar ***/
#navigation { nav h2 {
position: absolute; display: none;
background: HBG;
opacity: 0.9;
top: 80px;
left: 0px;
padding: 0;
} }
#navigation h3 { nav ul {
font-size: 100%;
border-bottom: 2px solid #333;
}
#navigation ul {
list-style: none; list-style: none;
padding: 0; text-align: center;
margin: 0;
} }
#navigation li a { nav li {
display: block; display: inline;
height: 25px; }
width: 90px;
padding: 5px; nav li a {
margin: 5px;
border-right: 4px solid #ddc;
text-transform: lowercase; text-transform: lowercase;
font-size: 0.9em; font-size: 0.9em;
} }
#navigation li a:hover { nav li + li:before {
background: #333; content: " | ";
border-right-color: #b71;
} }
/**** special cases ****/ /**** special cases ****/
@ -134,12 +123,12 @@ hr {
text-align: center; text-align: center;
} }
.scoreboard { #scoreboard {
background: #112; background: #112;
} }
.scoreboard td { #scoreboard td {
height: 400px; height: 300px;
} }
#battlefield { #battlefield {
@ -149,19 +138,3 @@ hr {
.solved { .solved {
text-decoration: line-through; text-decoration: line-through;
} }
table.pollster {
margin-left: 5em;
}
table.pollster td {
padding: 2px 1em 2px 5px;
}
table.pollster thead {
font-weight: bold;
}
table.scoreboard {
height: 400px;
}

View File

@ -0,0 +1,4 @@
#! /bin/sh
BASE_PATH=/var/lib/ctf/tanks/players/; export BASE_PATH
exec /opt/tanks/bin/designer.cgi

View File

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title>Tank Designer</title> <title>Tank Designer</title>
<link rel="stylesheet" href="dirtbags.css" type="text/css"> <link rel="stylesheet" href="style.css" type="text/css">
<style type="text/css"> <style type="text/css">
#preview { #preview {
float: right; float: right;

View File

@ -0,0 +1 @@
summary.html

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Tanks</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<h1>Tanks</h1>
<p>
Nothing here yet. You could <a href="intro.html">read the
intro</a> while you're waiting,
or <a href="designer.html">submit a tank</a> to get things
started.
</p>
<p>
Hopefully it goes without saying that you'll need to reload
this page to see if anything's happened.
</p>
</body>
</html>

View File

@ -1,6 +0,0 @@
#! /bin/sh
mkdir -p /var/lib/ctf/tanks
mkdir -p /var/lib/ctf/tanks/www
mkdir -p /var/lib/ctf/tanks/players
exec ./tanksd

View File

@ -0,0 +1,3 @@
#! /bin/sh
exec logger -t tanks

View File

@ -0,0 +1,10 @@
#! /bin/sh
exec 2>&1
mkdir -p /var/www/tanks
ln -s /opt/tanks/html/* /var/www/tanks/
ln -sf summary.html /var/www/tanks/index.html
install -o ctf -d /var/lib/ctf/tanks/players
exec ./tanksd

View File

@ -2,9 +2,7 @@
d=/var/lib/ctf/tanks d=/var/lib/ctf/tanks
p=$d/players p=$d/players
w=$d/www w=/var/www/tanks
mkdir -p $w $p
summary () { summary () {
cat <<EOF cat <<EOF
@ -12,18 +10,18 @@ summary () {
<html> <html>
<head> <head>
<title>Tanks</title> <title>Tanks</title>
<link rel=\"stylesheet\" href=\"http://10.0.0.2/ctf.css\" type=\"text/css\"> <link rel="stylesheet" href="style.css" type="text/css">
</head> </head>
<body> <body>
<h1>Tanks</h1> <h1>Tanks</h1>
<p>New here? Start with the <a href=\"intro.html\">introduction</a>.</p> <p>New here? Start with the <a href="intro.html">introduction</a>.</p>
<p>New round every minute.</p> <p>New round every minute.</p>
<h2>Round results</h2> <h2>Round results</h2>
<ul> <ul>
EOF EOF
printed=0 printed=0
find $w -name "round-*.html" | sort -r | while read fn; do find $w -name "round-*.html" | sort -r | while read fn; do
$b=$(basename $fn) b=$(basename $fn)
if [ $printed -lt 20 ]; then if [ $printed -lt 20 ]; then
echo "<li><a href=\"$b\">$b</a></li>" echo "<li><a href=\"$b\">$b</a></li>"
else else
@ -34,7 +32,7 @@ EOF
cat <<EOF cat <<EOF
</ul> </ul>
EOF EOF
cat /opt/tanks/www/nav.html.inc cat /opt/tanks/html/nav.html.inc
cat <<EOF cat <<EOF
</body> </body>
</html> </html>
@ -44,13 +42,19 @@ EOF
while true; do while true; do
# Make sure all teams exist # Make sure all teams exist
# XXX: pull this out into another daemon # XXX: pull this out into another daemon
wget -O - http://10.0.0.2/teams.txt | \ wget -q -O - http://10.0.0.2/teams.txt | \
KEY="Too much cheese." /opt/tokens/bin/arc4 | \ KEY="Too much cheese." /opt/tokens/bin/arc4 | \
while read hash; do while read hash; do
mkdir -p $p/$hash install -o ctf -d $p/$hash
chown ctf $p/$hash
done done
# Has anyone submitted a program yet?
if [ $(find $p -name program | wc -l) = 0 ]; then
sleep 15
continue
fi
# Round number? # Round number?
if [ -f $d/next-round ]; then if [ -f $d/next-round ]; then
next=$(cat $d/next-round) next=$(cat $d/next-round)
@ -59,7 +63,7 @@ while true; do
fi fi
expr $next + 1 > $d/next-round expr $next + 1 > $d/next-round
fn=$(printf "%s/round-%04d.html" $d $next) fn=$(printf "%s/round-%04d.html" $w $next)
rfn=$(printf "/tmp/tanks-results-%04d.txt" $next) rfn=$(printf "/tmp/tanks-results-%04d.txt" $next)
tfn=$(printf "/tmp/tanks-token-%04d.txt" $next) tfn=$(printf "/tmp/tanks-token-%04d.txt" $next)
@ -71,13 +75,13 @@ while true; do
<head> <head>
<title>Tanks Round $next</title> <title>Tanks Round $next</title>
<script type="application/javascript" src="tanks.js"></script> <script type="application/javascript" src="tanks.js"></script>
<link rel="stylesheet" href="http://10.0.0.2/ctf.css" type="text/css"> <link rel="stylesheet" href="style.css" type="text/css">
<script type="application/javascript"> <script type="application/javascript">
function go() { function go() {
start("battlefield", start("battlefield",
// Start JSON data // Start JSON data
EOF EOF
/opt/tanks/bin/forftanks $d/*/ >>$fn 3>$rfn /opt/tanks/bin/forftanks $p/* >>$fn 3>$rfn
cat <<EOF >>$fn cat <<EOF >>$fn
// end JSON data // end JSON data
); );
@ -91,7 +95,7 @@ window.onload = go;
<p><span id="fps">0</span> fps</p> <p><span id="fps">0</span> fps</p>
EOF EOF
/opt/tanks/bin/rank.awk $rfn >>$fn /opt/tanks/bin/rank.awk $rfn >>$fn
cat /opt/tanks/www/nav.html.inc cat /opt/tanks/html/nav.html.inc >>$fn
cat <<EOF >>$fn cat <<EOF >>$fn
</body> </body>
</html> </html>
@ -101,16 +105,21 @@ EOF
nc 10.0.0.2 1 -e /opt/tokens/bin/tokencli tanks ./category.key 3> $tfn nc 10.0.0.2 1 -e /opt/tokens/bin/tokencli tanks ./category.key 3> $tfn
k=$(cat $tfn) k=$(cat $tfn)
/opt/tanks/bin/winners.awk $rfn | while read winner; do /opt/tanks/bin/winners.awk $rfn | while read winner; do
echo "Round $next winner: $winner" hash=$(basename $winner)
echo "Round $next winner: $hash"
# Squirrel it away just in case # Squirrel it away just in case
cat $tfn >> $p/$winner/tokens cat $tfn >> $winner/tokens
# XXX: pull this out into another daemon # XXX: pull this out into another daemon
# XXX: this puts the token in /proc/self/cmdline # XXX: this puts the token in /proc/self/cmdline
wget -O /dev/null "http://10.0.0.2/claim.cgi?t=$winner&k=$k" wget -q -s "http://10.0.0.2/claim.cgi?t=$hash&k=$k"
done done
summary > $d/summary.html.$$ summary > $w/summary.html.$$
mv $d/summary.html.$$ $d/summary.html mv -f $w/summary.html.$$ $w/summary.html
rm -f $tfn $rfn
sleep 60
done done

View File

@ -15,6 +15,7 @@ $(TANKS_BUILDDIR)/ctanks: $(TANKS_TAR)
tanks-build: tanks-source tanks-build: tanks-source
$(MAKE) -C $(TANKS_BUILDDIR)/ctanks $(MAKE) -C $(TANKS_BUILDDIR)/ctanks
# "html" instead of "www" to prevent automatic links
tanks-install: tanks-build tanks-install: tanks-build
mkdir -p $(TANKS_PKGDIR)/bin mkdir -p $(TANKS_PKGDIR)/bin
cp $(TANKS_BUILDDIR)/ctanks/forftanks $(TANKS_PKGDIR)/bin cp $(TANKS_BUILDDIR)/ctanks/forftanks $(TANKS_PKGDIR)/bin
@ -22,18 +23,22 @@ tanks-install: tanks-build
cp $(TANKS_BUILDDIR)/ctanks/rank.awk $(TANKS_PKGDIR)/bin cp $(TANKS_BUILDDIR)/ctanks/rank.awk $(TANKS_PKGDIR)/bin
cp $(TANKS_BUILDDIR)/ctanks/winners.awk $(TANKS_PKGDIR)/bin cp $(TANKS_BUILDDIR)/ctanks/winners.awk $(TANKS_PKGDIR)/bin
$(call COPYTREE, packages/tanks/www, $(TANKS_PKGDIR)/www/tanks) $(call COPYTREE, packages/tanks/html, $(TANKS_PKGDIR)/html)
cp $(TANKS_BUILDDIR)/ctanks/nav.html.inc $(TANKS_PKGDIR)/www/tanks cp packages/mcp/www/ctf.css $(TANKS_PKGDIR)/html/style.css
cp $(TANKS_BUILDDIR)/ctanks/tanks.js $(TANKS_PKGDIR)/www/tanks cp packages/mcp/www/grunge.png $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/forf.html $(TANKS_PKGDIR)/www/tanks cp $(TANKS_BUILDDIR)/ctanks/nav.html.inc $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/intro.html $(TANKS_PKGDIR)/www/tanks cp $(TANKS_BUILDDIR)/ctanks/tanks.js $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/figures.js $(TANKS_PKGDIR)/www/tanks cp $(TANKS_BUILDDIR)/ctanks/forf.html $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/procs.html $(TANKS_PKGDIR)/www/tanks cp $(TANKS_BUILDDIR)/ctanks/intro.html $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/designer.js $(TANKS_PKGDIR)/www/tanks cp $(TANKS_BUILDDIR)/ctanks/figures.js $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/procs.html $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/designer.js $(TANKS_PKGDIR)/html
$(call COPYTREE, packages/tanks/service, $(TANKS_PKGDIR)/service) $(call COPYTREE, packages/tanks/service, $(TANKS_PKGDIR)/service)
$(call COPYTREE, $(TANKS_BUILDDIR)/ctanks/examples, $(TANKS_PKGDIR)/examples) $(call COPYTREE, $(TANKS_BUILDDIR)/ctanks/examples, $(TANKS_PKGDIR)/examples)
tanks-clean: tanks-clean:
rm -f $(TANKS_BUILDDIR) rm -rf $(TANKS_BUILDDIR)
PACKAGES += tanks

View File

@ -1,4 +0,0 @@
#! /bin/sh
BASE_PATH=/var/lib/ctf/tanks/players; export BASE_PATH
exec /opt/tanks/bin/design.cgi