2010-10-26 13:02:26 -06:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
d=/var/lib/ctf/tanks
|
|
|
|
p=$d/players
|
2010-10-26 16:43:51 -06:00
|
|
|
w=/var/www/tanks
|
2011-11-05 14:27:56 -06:00
|
|
|
log=$d/winners.log
|
2010-10-26 13:02:26 -06:00
|
|
|
|
|
|
|
summary () {
|
|
|
|
cat <<EOF
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Tanks</title>
|
2010-10-26 16:43:51 -06:00
|
|
|
<link rel="stylesheet" href="style.css" type="text/css">
|
2010-10-26 13:02:26 -06:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>Tanks</h1>
|
2010-10-26 16:43:51 -06:00
|
|
|
<p>New here? Start with the <a href="intro.html">introduction</a>.</p>
|
2010-10-26 13:02:26 -06:00
|
|
|
<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
|
2010-10-26 16:43:51 -06:00
|
|
|
b=$(basename $fn)
|
2010-10-26 13:02:26 -06:00
|
|
|
if [ $printed -lt 20 ]; then
|
|
|
|
echo "<li><a href=\"$b\">$b</a></li>"
|
|
|
|
else
|
|
|
|
rm -f $fn
|
|
|
|
fi
|
|
|
|
printed=$(expr $printed + 1)
|
|
|
|
done
|
|
|
|
cat <<EOF
|
|
|
|
</ul>
|
|
|
|
EOF
|
2010-10-26 16:43:51 -06:00
|
|
|
cat /opt/tanks/html/nav.html.inc
|
2010-10-26 13:02:26 -06:00
|
|
|
cat <<EOF
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
while true; do
|
2012-04-19 17:40:30 -06:00
|
|
|
find /var/lib/ctf/teams/names -type f | while read dn; do
|
2011-11-05 14:27:56 -06:00
|
|
|
hash=${dn##*/}
|
2010-10-26 16:43:51 -06:00
|
|
|
install -o ctf -d $p/$hash
|
2010-10-26 13:02:26 -06:00
|
|
|
done
|
|
|
|
|
2010-10-26 16:43:51 -06:00
|
|
|
# Has anyone submitted a program yet?
|
|
|
|
if [ $(find $p -name program | wc -l) = 0 ]; then
|
|
|
|
sleep 15
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2010-10-26 13:02:26 -06:00
|
|
|
# Round number?
|
|
|
|
if [ -f $d/next-round ]; then
|
|
|
|
next=$(cat $d/next-round)
|
|
|
|
else
|
|
|
|
next=0
|
|
|
|
fi
|
|
|
|
expr $next + 1 > $d/next-round
|
|
|
|
|
2010-10-26 16:43:51 -06:00
|
|
|
fn=$(printf "%s/round-%04d.html" $w $next)
|
2010-10-26 13:02:26 -06:00
|
|
|
rfn=$(printf "/tmp/tanks-results-%04d.txt" $next)
|
|
|
|
tfn=$(printf "/tmp/tanks-token-%04d.txt" $next)
|
|
|
|
|
|
|
|
# Run a game
|
|
|
|
echo "Running round $next"
|
|
|
|
cat <<EOF >$fn
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Tanks Round $next</title>
|
|
|
|
<script type="application/javascript" src="tanks.js"></script>
|
2010-10-26 16:43:51 -06:00
|
|
|
<link rel="stylesheet" href="style.css" type="text/css">
|
2010-10-26 13:02:26 -06:00
|
|
|
<script type="application/javascript">
|
|
|
|
function go() {
|
|
|
|
start("battlefield",
|
|
|
|
// Start JSON data
|
|
|
|
EOF
|
2010-10-26 16:43:51 -06:00
|
|
|
/opt/tanks/bin/forftanks $p/* >>$fn 3>$rfn
|
2010-10-26 13:02:26 -06:00
|
|
|
cat <<EOF >>$fn
|
|
|
|
// end JSON data
|
|
|
|
);
|
|
|
|
}
|
|
|
|
window.onload = go;
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>Tanks Round $next</h1>
|
|
|
|
<div id="game_box"><canvas id="battlefield"></canvas></div>
|
|
|
|
<p><span id="fps">0</span> fps</p>
|
|
|
|
EOF
|
2012-04-19 17:40:30 -06:00
|
|
|
awk -f /opt/tanks/bin/rank.awk $rfn >>$fn
|
2010-10-26 16:43:51 -06:00
|
|
|
cat /opt/tanks/html/nav.html.inc >>$fn
|
2010-10-26 13:02:26 -06:00
|
|
|
cat <<EOF >>$fn
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOF
|
|
|
|
|
2012-04-19 17:40:30 -06:00
|
|
|
awk -f /opt/tanks/bin/winner.awk $rfn | while read winner; do
|
2010-10-26 16:43:51 -06:00
|
|
|
hash=$(basename $winner)
|
2011-11-05 14:27:56 -06:00
|
|
|
echo "Round $next winner: $hash" >> $log
|
|
|
|
nwinners=$(wc -l $log)
|
|
|
|
|
2012-05-31 13:57:34 -06:00
|
|
|
/opt/mcp/bin/pointscli $hash tanks 1 "tanks round $next"
|
2010-10-26 13:02:26 -06:00
|
|
|
done
|
|
|
|
|
2011-03-14 10:52:25 -06:00
|
|
|
ln -sf $fn $w/current.html
|
|
|
|
|
2010-10-26 16:43:51 -06:00
|
|
|
summary > $w/summary.html.$$
|
|
|
|
mv -f $w/summary.html.$$ $w/summary.html
|
|
|
|
|
|
|
|
rm -f $tfn $rfn
|
|
|
|
|
|
|
|
sleep 60
|
2010-10-26 13:02:26 -06:00
|
|
|
done
|