Remove some debugging

This commit is contained in:
Neale Pickett 2009-08-20 16:20:44 -06:00
parent de8f8ff5ff
commit f5b6373164
4 changed files with 30 additions and 18 deletions

View File

@ -50,14 +50,12 @@ class CategoryHandler(socketserver.StreamRequestHandler):
catpass = self.rfile.readline().strip() catpass = self.rfile.readline().strip()
cat, passwd = catpass.split(b':::') cat, passwd = catpass.split(b':::')
passwd = passwd.decode('utf-8') passwd = passwd.decode('utf-8')
print(cat, passwd, hexdigest(cat))
if passwd != hexdigest(cat): if passwd != hexdigest(cat):
self.wfile.write(b'ERROR :Closing Link: Invalid password\n') self.wfile.write(b'ERROR :Closing Link: Invalid password\n')
return return
cat = cat.decode('utf-8') cat = cat.decode('utf-8')
except ValueError as foo: except ValueError as foo:
self.wfile.write(b'ERROR :Closing Link: Invalid command\n') self.wfile.write(b'ERROR :Closing Link: Invalid command\n')
print(foo)
return return
flags[cat] = house flags[cat] = house

View File

@ -10,7 +10,7 @@ import io
## Authentication ## Authentication
## ##
key = b'mullosks peck my galloping genitals' key = b'mollusks peck my galloping genitals'
def digest(data): def digest(data):
return hmac.new(key, data).digest() return hmac.new(key, data).digest()
@ -131,6 +131,7 @@ class Storage:
l = struct.pack('!I', len(b)) l = struct.pack('!I', len(b))
self.f.write(l) self.f.write(l)
self.f.write(b) self.f.write(b)
print('added %d points to [%s] in [%s]' % (score, team, cat))
def categories(self): def categories(self):
return sorted(self.points_by_cat) return sorted(self.points_by_cat)

41
pointscli.py Normal file → Executable file
View File

@ -1,9 +1,30 @@
#! /usr/bin/env python3
import optparse import optparse
import select import select
import points import points
import socket import socket
import time 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(): def main():
p = optparse.OptionParser(usage='%prog CATEGORY TEAM SCORE') p = optparse.OptionParser(usage='%prog CATEGORY TEAM SCORE')
p.add_option('-s', '--host', dest='host', default='localhost', p.add_option('-s', '--host', dest='host', default='localhost',
@ -16,21 +37,13 @@ def main():
except ValueError: except ValueError:
return p.print_usage() return p.print_usage()
now = int(time.time()) s = makesock(opts.host)
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)
try:
submit(s, cat, team, score)
except ValueError as err:
print(err)
raise
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -27,7 +27,7 @@ class MyHandler(socketserver.BaseRequestHandler):
# Replays can happen legitimately. # Replays can happen legitimately.
if not req in acked: 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') resp = points.encode_response(when, 'Your clock is off')
peer.sendto(resp, self.client_address) peer.sendto(resp, self.client_address)
return return