reject records missing checksum

This commit is contained in:
Not 2022-11-14 22:18:01 +01:00
parent 08c1af3073
commit 34da7e2929
1 changed files with 19 additions and 5 deletions

View File

@ -13,6 +13,11 @@ records_lua = sys.argv[3]
def ParseScore(score):
# Map Name Skin Color Time Splits Flags Stat
split = score.split("\t")
checksum = ""
if len(split) > 8:
checksum = split[8]
return {
"map": split[0],
"name": split[1],
@ -21,7 +26,8 @@ def ParseScore(score):
"time": int(split[4]),
"splits": split[5],
"flags": int(split[6]),
"stat": split[7]
"stat": split[7],
"checksum": checksum
}
# Compare scores
@ -65,14 +71,20 @@ for score in recordsList:
# convert records to flat list
recordsList = []
rejected = []
for mapTable in records.values():
for score in mapTable:
recordsList.append("\t".join([str(v) for v in list(score.values())]))
scoreStr = "\t".join([str(v) for v in list(score.values())])
# only allow records with checksums
if score["checksum"] != "":
recordsList.append(scoreStr)
else:
rejected.append(scoreStr)
# truncate and write records to coldstore
with open(coldstore_txt, "w") as f:
for score in recordsList:
f.write(score + linesep)
f.write(score + linesep)
luaA = """local ParseScore = lb_parse_score
local AddColdStore = lb_add_coldstore_record
@ -90,5 +102,7 @@ with open(records_lua, "w") as f:
f.write("\"{}\",{}".format(score, linesep))
f.write(luaB)
# truncate leaderboard.txt
with open(leaderboard_txt, "w"): pass
# truncate and rewrite rejected scores to leaderboard.txt
with open(leaderboard_txt, "w") as f:
for score in rejected:
f.write(score + linesep)