diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2018-02-23 21:53:48 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2018-02-23 21:53:48 +0100 |
commit | 435b612c46dcb73ab55659f89f85f3d6bc5aa869 (patch) | |
tree | 043bd585b9f44121d12e4749147c21d870a11233 /stalinizer.py | |
parent | 61d799871d3662b7f4282820c0423b6ae524a927 (diff) |
Keep track of player slots.
It turns out a ClientConnect doesn't necessarily have to have a matching ClientDisconnect. This commit makes sure duplicates aren't counted.
Diffstat (limited to 'stalinizer.py')
-rwxr-xr-x | stalinizer.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/stalinizer.py b/stalinizer.py index af580f9..598f43d 100755 --- a/stalinizer.py +++ b/stalinizer.py @@ -16,13 +16,14 @@ def parse_gametime(text): class StateTracker: def __init__(self): self.hist = list() + self.hist_pings = list() + self.slots = [False] * 64; self.time_ref = None self.time = None self.time_last = None self.pcount = None self.pcount_last = None self.pings = list() - self.hist_pings = list() def update(self): if self.time_last and self.time > self.time_last: @@ -41,6 +42,7 @@ class StateTracker: self.pings = list() def ev_begin(self, realtime): + self.slots = [False] * 64 self.time_ref = parse_realtime(realtime) self.time = self.time_ref self.pcount = 0 @@ -50,7 +52,11 @@ class StateTracker: self.hist_pings.append((self.time_ref, self.pings)) self.pings = list() - def ev_connect(self, gametime): + def ev_connect(self, gametime, slot): + if self.slots[slot]: + return + + self.slots[slot] = True self.time = self.time_ref + parse_gametime(gametime) self.pcount += 1 self.update() @@ -58,7 +64,8 @@ class StateTracker: if self.pcount > 64: raise ValueError("too many players") - def ev_disconnect(self, gametime): + def ev_disconnect(self, gametime, slot): + self.slots[slot] = False self.time = self.time_ref + parse_gametime(gametime) self.pcount -= 1 self.update() @@ -186,8 +193,8 @@ def main(): state = StateTracker() re_realtime = re.compile("^\s*\d+:\d\d RealTime: (.*)$") - re_connect = re.compile("^\s*(\d+:\d\d) ClientConnect:") - re_disconnect = re.compile("^\s*(\d+:\d\d) ClientDisconnect:") + re_connect = re.compile("^\s*(\d+:\d\d) ClientConnect: ([0-9]+)") + re_disconnect = re.compile("^\s*(\d+:\d\d) ClientDisconnect: ([0-9]+)") re_endgame_stat = re.compile("^\s*(\d+:\d\d) score: (-?[0-9]+) ping: ([0-9]+)") for (i, line) in enumerate(map(decoder, sys.stdin.buffer)): @@ -200,12 +207,14 @@ def main(): elif "ClientConnect" in line: rv = re.search(re_connect, line) if rv: - state.ev_connect(rv.group(1)) + state.ev_connect(rv.group(1), + int(rv.group(2))) continue elif "ClientDisconnect" in line: rv = re.search(re_disconnect, line) if rv: - state.ev_disconnect(rv.group(1)) + state.ev_disconnect(rv.group(1), + int(rv.group(2))) continue elif "score:" in line: rv = re.search(re_endgame_stat, line) @@ -215,7 +224,7 @@ def main(): rv.group(3)) continue except: - print("ERROR on line %d:" % (i + 1)) + print("ERROR on line %d:" % (i + 1), file=sys.stderr) raise state.finish() |