mirror of https://github.com/dirtbags/moth.git
Remove some debugging
This commit is contained in:
parent
de8f8ff5ff
commit
f5b6373164
2
flagd.py
2
flagd.py
|
@ -50,14 +50,12 @@ class CategoryHandler(socketserver.StreamRequestHandler):
|
|||
catpass = self.rfile.readline().strip()
|
||||
cat, passwd = catpass.split(b':::')
|
||||
passwd = passwd.decode('utf-8')
|
||||
print(cat, passwd, hexdigest(cat))
|
||||
if passwd != hexdigest(cat):
|
||||
self.wfile.write(b'ERROR :Closing Link: Invalid password\n')
|
||||
return
|
||||
cat = cat.decode('utf-8')
|
||||
except ValueError as foo:
|
||||
self.wfile.write(b'ERROR :Closing Link: Invalid command\n')
|
||||
print(foo)
|
||||
return
|
||||
|
||||
flags[cat] = house
|
||||
|
|
|
@ -10,7 +10,7 @@ import io
|
|||
## Authentication
|
||||
##
|
||||
|
||||
key = b'mullosks peck my galloping genitals'
|
||||
key = b'mollusks peck my galloping genitals'
|
||||
def digest(data):
|
||||
return hmac.new(key, data).digest()
|
||||
|
||||
|
@ -131,6 +131,7 @@ class Storage:
|
|||
l = struct.pack('!I', len(b))
|
||||
self.f.write(l)
|
||||
self.f.write(b)
|
||||
print('added %d points to [%s] in [%s]' % (score, team, cat))
|
||||
|
||||
def categories(self):
|
||||
return sorted(self.points_by_cat)
|
||||
|
|
|
@ -1,9 +1,30 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import optparse
|
||||
import select
|
||||
import points
|
||||
import socket
|
||||
import time
|
||||
|
||||
def submit(sock, cat, team, score):
|
||||
now = int(time.time())
|
||||
req = points.encode_request(now, cat, team, score)
|
||||
while True:
|
||||
sock.send(req)
|
||||
r, w, x = select.select([sock], [], [], 0.2)
|
||||
if r:
|
||||
b = sock.recv(500)
|
||||
when, txt = points.decode_response(b)
|
||||
assert when == now
|
||||
if txt == 'OK':
|
||||
return
|
||||
raise ValueError(txt)
|
||||
|
||||
def makesock(host):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.connect((host, 6667))
|
||||
return s
|
||||
|
||||
def main():
|
||||
p = optparse.OptionParser(usage='%prog CATEGORY TEAM SCORE')
|
||||
p.add_option('-s', '--host', dest='host', default='localhost',
|
||||
|
@ -16,21 +37,13 @@ def main():
|
|||
except ValueError:
|
||||
return p.print_usage()
|
||||
|
||||
now = int(time.time())
|
||||
req = points.encode_request(now, cat, team, score)
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
while True:
|
||||
s.sendto(req, (opts.host, 6667))
|
||||
r, w, x = select.select([s], [], [], 0.2)
|
||||
if r:
|
||||
b = s.recv(500)
|
||||
when, txt = points.decode_response(b)
|
||||
assert when == now
|
||||
if txt == 'OK':
|
||||
return
|
||||
print(txt)
|
||||
raise ValueError(txt)
|
||||
s = makesock(opts.host)
|
||||
|
||||
try:
|
||||
submit(s, cat, team, score)
|
||||
except ValueError as err:
|
||||
print(err)
|
||||
raise
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -27,7 +27,7 @@ class MyHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
# Replays can happen legitimately.
|
||||
if not req in acked:
|
||||
if not (now - 2 < when < now):
|
||||
if not (now - 2 < when <= now):
|
||||
resp = points.encode_response(when, 'Your clock is off')
|
||||
peer.sendto(resp, self.client_address)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue