mirror of https://github.com/dirtbags/moth.git
Merge branch 'master' of cfl:/var/projects/gctf
This commit is contained in:
commit
91ee387600
|
@ -142,6 +142,8 @@ class FlagServer(asynchat.async_chat):
|
||||||
self.inbuf.append(data)
|
self.inbuf.append(data)
|
||||||
|
|
||||||
def set_flag(self, team):
|
def set_flag(self, team):
|
||||||
|
if not self.cat:
|
||||||
|
return
|
||||||
self.flag = team
|
self.flag = team
|
||||||
self.submitter.set_flag(self.cat, team)
|
self.submitter.set_flag(self.cat, team)
|
||||||
f = open(os.path.join(flags_dir, self.cat), 'w')
|
f = open(os.path.join(flags_dir, self.cat), 'w')
|
||||||
|
|
|
@ -18,4 +18,4 @@ target:
|
||||||
$(MAKE) -C daemons TARGET=$(TARGET) install
|
$(MAKE) -C daemons TARGET=$(TARGET) install
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf target
|
rm -rf target pwnables.tce
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
/var/lib/cat/flag
|
|
@ -24,7 +24,7 @@ target:
|
||||||
$(INSTALL) -d target/usr/lib/www/tanks/
|
$(INSTALL) -d target/usr/lib/www/tanks/
|
||||||
$(INSTALL) www/* target/usr/lib/www/tanks/
|
$(INSTALL) www/* target/usr/lib/www/tanks/
|
||||||
|
|
||||||
ln -s /var/lib/tanks target/usr/lib/www/tanks/results
|
ln -s /var/lib/tanks/results target/usr/lib/www/tanks/results
|
||||||
|
|
||||||
$(INSTALL) -d target/usr/lib/python2.6/site-packages/tanks/
|
$(INSTALL) -d target/usr/lib/python2.6/site-packages/tanks/
|
||||||
$(INSTALL) lib/* target/usr/lib/python2.6/site-packages/tanks/
|
$(INSTALL) lib/* target/usr/lib/python2.6/site-packages/tanks/
|
||||||
|
|
|
@ -201,16 +201,25 @@ class Pflanzarr:
|
||||||
break
|
break
|
||||||
winner = random.choice(winners)
|
winner = random.choice(winners)
|
||||||
|
|
||||||
html = ['<html><body>',
|
html = ['<html>',
|
||||||
|
'<head><title>Game %d results</title>',
|
||||||
|
'<link href="../ctf.css" rel="stylesheet" type="text/css">',
|
||||||
|
'</head>',
|
||||||
|
'<body>',
|
||||||
'<table><tr><th>Team<th>Kills<th>Cause of Death']
|
'<table><tr><th>Team<th>Kills<th>Cause of Death']
|
||||||
for tank in tanks:
|
for tank in tanks:
|
||||||
if tank is winner:
|
if tank is winner:
|
||||||
rowStyle = 'style="color:red;"'
|
rowStyle = 'style="font-weight:bold; '\
|
||||||
|
'background-color:%s"' % tank._color
|
||||||
else:
|
else:
|
||||||
rowStyle = ''
|
rowStyle = 'style="background-color:%s"' % tank._color
|
||||||
|
if name:
|
||||||
|
name = xml.sax.saxutils.escape(tank.name)
|
||||||
|
else:
|
||||||
|
name = '#default'
|
||||||
html.append('<tr %s><td>%s<td>%d<td>%s' %
|
html.append('<tr %s><td>%s<td>%d<td>%s' %
|
||||||
(rowStyle,
|
(rowStyle,
|
||||||
xml.sax.saxutils.escape(tank.name),
|
name,
|
||||||
len(kills[tank]),
|
len(kills[tank]),
|
||||||
xml.sax.saxutils.escape(tank.deathReason)))
|
xml.sax.saxutils.escape(tank.deathReason)))
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Tank(object):
|
||||||
else:
|
else:
|
||||||
self._tAngle = tAngle
|
self._tAngle = tAngle
|
||||||
|
|
||||||
self._color = color
|
self.color = color
|
||||||
|
|
||||||
# You can't fire until fireReady is 0.
|
# You can't fire until fireReady is 0.
|
||||||
self._fireReady = self.FIRE_RATE
|
self._fireReady = self.FIRE_RATE
|
||||||
|
@ -466,7 +466,7 @@ class Tank(object):
|
||||||
|
|
||||||
# The base body rectangle.
|
# The base body rectangle.
|
||||||
for poly in gm.displacePoly(hood, self.pos, self._limits):
|
for poly in gm.displacePoly(hood, self.pos, self._limits):
|
||||||
d.polygon( poly, fill=self._color )
|
d.polygon( poly, fill=self.color )
|
||||||
|
|
||||||
# The treads
|
# The treads
|
||||||
for poly in gm.displacePoly(tread1, self.pos, self._limits) + \
|
for poly in gm.displacePoly(tread1, self.pos, self._limits) + \
|
||||||
|
@ -475,7 +475,7 @@ class Tank(object):
|
||||||
|
|
||||||
# The turret circle
|
# The turret circle
|
||||||
for poly in gm.displacePoly(self.body, self.pos, self._limits):
|
for poly in gm.displacePoly(self.body, self.pos, self._limits):
|
||||||
d.ellipse( poly, fill=self._color, outline='black')
|
d.ellipse( poly, fill=self.color, outline='black')
|
||||||
|
|
||||||
self._drawLaser(d)
|
self._drawLaser(d)
|
||||||
|
|
||||||
|
@ -491,7 +491,7 @@ class Tank(object):
|
||||||
if self._fired:
|
if self._fired:
|
||||||
laser = gm.rotatePoly( self.laser, self._angle + self._tAngle )
|
laser = gm.rotatePoly( self.laser, self._angle + self._tAngle )
|
||||||
for poly in gm.displacePoly(laser, self.pos, self._limits):
|
for poly in gm.displacePoly(laser, self.pos, self._limits):
|
||||||
drawing.polygon(poly, fill=self._color)
|
drawing.polygon(poly, fill=self.color)
|
||||||
|
|
||||||
self._fired = False
|
self._fired = False
|
||||||
|
|
||||||
|
@ -522,7 +522,7 @@ class Tank(object):
|
||||||
if self._sensorState[i]:
|
if self._sensorState[i]:
|
||||||
color = '#000000'
|
color = '#000000'
|
||||||
else:
|
else:
|
||||||
color = self._color
|
color = self.color
|
||||||
|
|
||||||
r, angle, width, tAttached = self._sensors[i]
|
r, angle, width, tAttached = self._sensors[i]
|
||||||
r = int(r)
|
r = int(r)
|
||||||
|
|
|
@ -1,11 +1,73 @@
|
||||||
#! /usr/bin/python
|
#! /usr/bin/python
|
||||||
|
|
||||||
import time
|
|
||||||
import optparse
|
import optparse
|
||||||
|
import shutil
|
||||||
|
import time
|
||||||
|
import asyncore
|
||||||
|
import asynchat
|
||||||
from tanks import Pflanzarr
|
from tanks import Pflanzarr
|
||||||
|
|
||||||
T = 60*5
|
T = 60*5
|
||||||
|
MAX_HIST = 30
|
||||||
|
HIST_STEP = 100
|
||||||
|
key = 'tanks:::2bac5e912ff2e1ad559b177eb5aeecca'
|
||||||
|
|
||||||
|
class Flagger(asynchat.async_chat):
|
||||||
|
"""Use to connect to flagd and submit the current flag holder."""
|
||||||
|
|
||||||
|
def __init__(self, addr, auth):
|
||||||
|
asynchat.async_chat.__init__(self)
|
||||||
|
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
self.connect((addr, 6668))
|
||||||
|
self.push(auth + '\n')
|
||||||
|
self.flag = None
|
||||||
|
|
||||||
|
def handle_read(self):
|
||||||
|
msg = self.recv(4096)
|
||||||
|
raise ValueError("Flagger died: %r" % msg)
|
||||||
|
|
||||||
|
def handle_error(self):
|
||||||
|
# If we lose the connection to flagd, nobody can score any
|
||||||
|
# points. Terminate everything.
|
||||||
|
asyncore.close_all()
|
||||||
|
asynchat.async_chat.handle_error(self)
|
||||||
|
|
||||||
|
def set_flag(self, team):
|
||||||
|
if team:
|
||||||
|
eteam = team
|
||||||
|
else:
|
||||||
|
eteam = ''
|
||||||
|
self.push(eteam + '\n')
|
||||||
|
self.flag = team
|
||||||
|
|
||||||
|
|
||||||
|
def run_tanks():
|
||||||
|
p = Pflanzarr.Pflanzarr(args[0], args[1])
|
||||||
|
p.run(turns)
|
||||||
|
|
||||||
|
path = os.path.join(args[0], 'results')
|
||||||
|
files = os.listdir(path)
|
||||||
|
gameNums = []
|
||||||
|
for file in files:
|
||||||
|
try:
|
||||||
|
gameNums.append( int(file) )
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
gameNums.sort(reverse=True)
|
||||||
|
highest = gameNums[0]
|
||||||
|
for num in gameNums:
|
||||||
|
if highest - MAX_HIST > num and not (num % HIST_STEP == 0):
|
||||||
|
shutil.rmtree(os.path.join(path, num))
|
||||||
|
|
||||||
|
try:
|
||||||
|
winner = open('/var/lib/tanks/winner').read().strip()
|
||||||
|
except:
|
||||||
|
winner = None
|
||||||
|
flagger.set_flag(winner)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
parser = optparse.OptionParser('DATA_DIR easy|medium|hard MAX_TURNS')
|
parser = optparse.OptionParser('DATA_DIR easy|medium|hard MAX_TURNS')
|
||||||
opts, args = parser.parse_args()
|
opts, args = parser.parse_args()
|
||||||
if (len(args) != 3) or (args[1] not in ('easy', 'medium', 'hard')):
|
if (len(args) != 3) or (args[1] not in ('easy', 'medium', 'hard')):
|
||||||
|
@ -15,11 +77,15 @@ try:
|
||||||
except:
|
except:
|
||||||
parser.error('Invalid number of turns')
|
parser.error('Invalid number of turns')
|
||||||
|
|
||||||
while True:
|
|
||||||
start = time.time()
|
|
||||||
p = Pflanzarr.Pflanzarr(args[0], args[1])
|
|
||||||
p.run(turns)
|
|
||||||
|
|
||||||
diff = time.time() - start
|
flagger = Flagger('localhost', key)
|
||||||
if diff - T > 0:
|
lastrun = 0
|
||||||
time.sleep( diff - T )
|
while True:
|
||||||
|
asyncore.loop(60, count=1)
|
||||||
|
now = time.time()
|
||||||
|
if now - lastrun >= 60:
|
||||||
|
run_tanks()
|
||||||
|
lastrun = now
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
|
@ -28,22 +28,28 @@ except:
|
||||||
|
|
||||||
if not games:
|
if not games:
|
||||||
print "<p>No games have occurred yet."
|
print "<p>No games have occurred yet."
|
||||||
|
|
||||||
gameNums = []
|
gameNums = []
|
||||||
for game in games:
|
for game in games:
|
||||||
try:
|
try:
|
||||||
num = int(game)
|
gameNums.append( int(game) )
|
||||||
path = os.path.join( 'results', game, 'results.html')
|
|
||||||
if os.path.exists( path ):
|
|
||||||
gameNums.append( int(num) )
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
gameNums.sort(reverse=True)
|
gameNums.sort(reverse=True)
|
||||||
|
|
||||||
|
# Don't include games that haven't completed
|
||||||
|
i = 0
|
||||||
|
num = str(gameNums[i])
|
||||||
|
for i in range(len(gameNums)):
|
||||||
|
path = os.path.join( 'results', str(gameNums[i]), 'results.html') )
|
||||||
|
if os.path.exists( path ):
|
||||||
|
break
|
||||||
|
gameNums = gameNums[i:]
|
||||||
|
|
||||||
for num in gameNums:
|
for num in gameNums:
|
||||||
print '<p>%d - ' % num,
|
print '<p>%d - ' % num,
|
||||||
print '<a href="results/%d/game.avi">v</a>' % num,
|
print '<a href="results/%d/game.avi">v</a>' % num,
|
||||||
print '<a href="results/%d/results.html">r</a>' % num
|
print '<a href="results/%d/results.html">r</a>' % num
|
||||||
|
|
||||||
|
print '</body></html>'
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
FAKE = fakeroot -s fake -i fake
|
||||||
|
INSTALL = $(FAKE) install -o 100
|
||||||
|
|
||||||
|
all: tanksFlagger.tce
|
||||||
|
|
||||||
|
push: tanksFlagger.tce
|
||||||
|
netcat -l -q 0 -p 3333 < tanksFlagger.tce
|
||||||
|
|
||||||
|
tanksFlagger.tce: target
|
||||||
|
$(FAKE) sh -c 'cd target && tar -czf - .' > $@
|
||||||
|
|
||||||
|
target:
|
||||||
|
$(INSTALL) -d target/var/service/tanksFlagger
|
||||||
|
$(INSTALL) run report_score.py target/var/service/tanksFlagger/
|
||||||
|
|
||||||
|
$(INSTALL) -d target/var/service/tanksFlagger/log/
|
||||||
|
$(INSTALL) log.run target/var/service/tanksFlagger/log/run
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf target tanksFlagger.tce fake
|
|
@ -0,0 +1,3 @@
|
||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
exec logger -t tanksFlagger
|
|
@ -0,0 +1,5 @@
|
||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
[ -f /var/lib/ctf/disabled/tanks ] && exit 0
|
||||||
|
|
||||||
|
exec envuidgid ctf python3 report_score.py 2>&1
|
Loading…
Reference in New Issue