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?)
* get LAUR for contest

View File

@ -51,4 +51,5 @@ echo "$color" > $base/teams/colors/$hash
echo "Registered with hash: $hash"
# 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
}
function print_bar(cat, team, n, d) {
function print_bar(cat, teamid, teamname, n, d) {
printf("<div class=\"t%s score\"" \
" style=\"height: %.2f%%;\"" \
" onmouseover=\"highlight('%s')\"" \
" onmouseout=\"restore('%s')\">\n" \
"<!-- %s --> %s: %s\n" \
"</div>",
team,
teamid,
100 * n / d,
team,
team,
cat, escape(names_by_team[team]), n)
teamid,
teamid,
cat, escape(name), n)
}
function output( t, c) {
@ -203,7 +203,7 @@ BEGIN {
for (team in teams) {
if (scores[i] == scores_by_team_time[team, lasttime]) {
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]
if (l[j] == points) {
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 " </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 " </body>"
print "</html>"

View File

@ -8,6 +8,7 @@ mcp-install: mcp-build
cp packages/mcp/src/pointscli $(MCP_PKGDIR)/bin/
cp packages/mcp/src/tokencli $(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)

View File

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

View File

@ -37,12 +37,11 @@ a img {
a {
text-decoration: underline;
color: #84b;
font-weight: bold;
}
a:hover {
color: #2a4;
background: #333;
font-weight: bold;
}
@ -69,7 +68,11 @@ th {
}
td {
vertical-align: top;
text-align: right;
text-align: left;
}
dt {
font-weight: bold;
}
p {
@ -83,42 +86,28 @@ hr {
/*** left side bar ***/
/*** navigation bar ***/
#navigation {
position: absolute;
background: HBG;
opacity: 0.9;
top: 80px;
left: 0px;
padding: 0;
nav h2 {
display: none;
}
#navigation h3 {
font-size: 100%;
border-bottom: 2px solid #333;
nav ul {
list-style: none;
text-align: center;
}
#navigation ul {
list-style: none;
padding: 0;
margin: 0;
nav li {
display: inline;
}
#navigation li a {
display: block;
height: 25px;
width: 90px;
padding: 5px;
margin: 5px;
border-right: 4px solid #ddc;
nav li a {
text-transform: lowercase;
font-size: 0.9em;
}
#navigation li a:hover {
background: #333;
border-right-color: #b71;
nav li + li:before {
content: " | ";
}
/**** special cases ****/
@ -134,12 +123,12 @@ hr {
text-align: center;
}
.scoreboard {
#scoreboard {
background: #112;
}
.scoreboard td {
height: 400px;
#scoreboard td {
height: 300px;
}
#battlefield {
@ -149,19 +138,3 @@ hr {
.solved {
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>
<head>
<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">
#preview {
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
p=$d/players
w=$d/www
mkdir -p $w $p
w=/var/www/tanks
summary () {
cat <<EOF
@ -12,18 +10,18 @@ summary () {
<html>
<head>
<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>
<body>
<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>
<h2>Round results</h2>
<ul>
EOF
printed=0
find $w -name "round-*.html" | sort -r | while read fn; do
$b=$(basename $fn)
b=$(basename $fn)
if [ $printed -lt 20 ]; then
echo "<li><a href=\"$b\">$b</a></li>"
else
@ -34,7 +32,7 @@ EOF
cat <<EOF
</ul>
EOF
cat /opt/tanks/www/nav.html.inc
cat /opt/tanks/html/nav.html.inc
cat <<EOF
</body>
</html>
@ -44,13 +42,19 @@ EOF
while true; do
# Make sure all teams exist
# 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 | \
while read hash; do
mkdir -p $p/$hash
chown ctf $p/$hash
install -o ctf -d $p/$hash
done
# Has anyone submitted a program yet?
if [ $(find $p -name program | wc -l) = 0 ]; then
sleep 15
continue
fi
# Round number?
if [ -f $d/next-round ]; then
next=$(cat $d/next-round)
@ -59,7 +63,7 @@ while true; do
fi
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)
tfn=$(printf "/tmp/tanks-token-%04d.txt" $next)
@ -71,13 +75,13 @@ while true; do
<head>
<title>Tanks Round $next</title>
<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">
function go() {
start("battlefield",
// Start JSON data
EOF
/opt/tanks/bin/forftanks $d/*/ >>$fn 3>$rfn
/opt/tanks/bin/forftanks $p/* >>$fn 3>$rfn
cat <<EOF >>$fn
// end JSON data
);
@ -91,7 +95,7 @@ window.onload = go;
<p><span id="fps">0</span> fps</p>
EOF
/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
</body>
</html>
@ -101,16 +105,21 @@ EOF
nc 10.0.0.2 1 -e /opt/tokens/bin/tokencli tanks ./category.key 3> $tfn
k=$(cat $tfn)
/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
cat $tfn >> $p/$winner/tokens
cat $tfn >> $winner/tokens
# XXX: pull this out into another daemon
# 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
summary > $d/summary.html.$$
mv $d/summary.html.$$ $d/summary.html
summary > $w/summary.html.$$
mv -f $w/summary.html.$$ $w/summary.html
rm -f $tfn $rfn
sleep 60
done

View File

@ -15,6 +15,7 @@ $(TANKS_BUILDDIR)/ctanks: $(TANKS_TAR)
tanks-build: tanks-source
$(MAKE) -C $(TANKS_BUILDDIR)/ctanks
# "html" instead of "www" to prevent automatic links
tanks-install: tanks-build
mkdir -p $(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/winners.awk $(TANKS_PKGDIR)/bin
$(call COPYTREE, packages/tanks/www, $(TANKS_PKGDIR)/www/tanks)
cp $(TANKS_BUILDDIR)/ctanks/nav.html.inc $(TANKS_PKGDIR)/www/tanks
cp $(TANKS_BUILDDIR)/ctanks/tanks.js $(TANKS_PKGDIR)/www/tanks
cp $(TANKS_BUILDDIR)/ctanks/forf.html $(TANKS_PKGDIR)/www/tanks
cp $(TANKS_BUILDDIR)/ctanks/intro.html $(TANKS_PKGDIR)/www/tanks
cp $(TANKS_BUILDDIR)/ctanks/figures.js $(TANKS_PKGDIR)/www/tanks
cp $(TANKS_BUILDDIR)/ctanks/procs.html $(TANKS_PKGDIR)/www/tanks
cp $(TANKS_BUILDDIR)/ctanks/designer.js $(TANKS_PKGDIR)/www/tanks
$(call COPYTREE, packages/tanks/html, $(TANKS_PKGDIR)/html)
cp packages/mcp/www/ctf.css $(TANKS_PKGDIR)/html/style.css
cp packages/mcp/www/grunge.png $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/nav.html.inc $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/tanks.js $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/forf.html $(TANKS_PKGDIR)/html
cp $(TANKS_BUILDDIR)/ctanks/intro.html $(TANKS_PKGDIR)/html
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, $(TANKS_BUILDDIR)/ctanks/examples, $(TANKS_PKGDIR)/examples)
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