From f5b63731643ec7adc2768060d486337619b468de Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 20 Aug 2009 16:20:44 -0600 Subject: [PATCH] Remove some debugging --- flagd.py | 2 -- points.py | 3 ++- pointscli.py | 41 +++++++++++++++++++++++++++-------------- pointsd.py | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-) mode change 100644 => 100755 pointscli.py diff --git a/flagd.py b/flagd.py index 27e198d..32b39ce 100755 --- a/flagd.py +++ b/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 diff --git a/points.py b/points.py index af40fc7..8180329 100755 --- a/points.py +++ b/points.py @@ -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) diff --git a/pointscli.py b/pointscli.py old mode 100644 new mode 100755 index 2e26d3a..920f345 --- a/pointscli.py +++ b/pointscli.py @@ -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() diff --git a/pointsd.py b/pointsd.py index 49ad8a8..d2d1f59 100755 --- a/pointsd.py +++ b/pointsd.py @@ -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