mirror of https://github.com/dirtbags/moth.git
119 lines
2.5 KiB
Bash
Executable File
119 lines
2.5 KiB
Bash
Executable File
#! /bin/sh
|
|
|
|
d=/var/lib/ctf/tanks
|
|
p=$d/players
|
|
w=/var/www/tanks
|
|
log=$d/winners.log
|
|
|
|
summary () {
|
|
cat <<EOF
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Tanks</title>
|
|
<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 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)
|
|
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
|
|
cat /opt/tanks/html/nav.html.inc
|
|
cat <<EOF
|
|
</body>
|
|
</html>
|
|
EOF
|
|
}
|
|
|
|
while true; do
|
|
find /var/lib/ctf/teams/names -type f | while read dn; do
|
|
hash=${dn##*/}
|
|
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)
|
|
else
|
|
next=0
|
|
fi
|
|
expr $next + 1 > $d/next-round
|
|
|
|
fn=$(printf "%s/round-%04d.html" $w $next)
|
|
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>
|
|
<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 $p/* >>$fn 3>$rfn
|
|
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
|
|
awk -f /opt/tanks/bin/rank.awk $rfn >>$fn
|
|
cat /opt/tanks/html/nav.html.inc >>$fn
|
|
cat <<EOF >>$fn
|
|
</body>
|
|
</html>
|
|
EOF
|
|
|
|
awk -f /opt/tanks/bin/winner.awk $rfn | while read winner; do
|
|
hash=$(basename $winner)
|
|
echo "Round $next winner: $hash" >> $log
|
|
nwinners=$(wc -l $log)
|
|
|
|
/opt/mcp/bin/pointscli $hash tanks 1
|
|
done
|
|
|
|
ln -sf $fn $w/current.html
|
|
|
|
summary > $w/summary.html.$$
|
|
mv -f $w/summary.html.$$ $w/summary.html
|
|
|
|
rm -f $tfn $rfn
|
|
|
|
sleep 60
|
|
done
|