Skip to content

Commit 5d7ac73

Browse files
committed
Made the message parsing more resiliant to tampered messages
1 parent 49e7274 commit 5d7ac73

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

sc2reader/parsers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,16 @@ def load(self, replay, filecontents):
178178
length += 128
179179

180180
text = bytes.get_string(length)
181-
replay.messages.append(Message(time, replay.player[player_id], target, text))
182-
181+
try:
182+
replay.messages.append(Message(time, replay.player[player_id], target, text))
183+
except KeyError:
184+
# This was added because some replay sites added their own tampered
185+
# messages to replays with non-existent player_id.
186+
#
187+
# This will simply ignore and fail silently if such message is
188+
# found.
189+
pass
190+
183191
recorders = [player for player in replay.players if player and player.recorder==True]
184192
if len(recorders) > 1:
185193
raise ValueError("There should be 1 and only 1 recorder; %s were found" % len(recorders))

test_replays/test_all.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# encoding: UTF-8
1+
# Encoding: UTF-8
22

33
# Run tests with "py.test" in the project root dir
44
import os, sys
@@ -147,6 +147,7 @@ def test_us_realm():
147147
assert replay.player['ShadesofGray'].url == "http://us.battle.net/sc2/en/profile/2358439/1/ShadesofGray/"
148148
assert replay.player['reddawn'].url == "http://us.battle.net/sc2/en/profile/2198663/1/reddawn/"
149149

150+
# TODO: Current problem.. both players are set as the recording players
150151
def test_kr_realm_and_tampered_messages():
151152
replay = Replay("test_replays/build17811/11.SC2Replay")
152153
assert replay.player['명지대학교'].url == "http://kr.battle.net/sc2/en/profile/258945/1/명지대학교/"

0 commit comments

Comments
 (0)