Compare commits
No commits in common. "34da7e292915f202a17954365aecbf3e960f3b71" and "52316347dabd330aa9d64f6881f7cea33bbed445" have entirely different histories.
34da7e2929
...
52316347da
62
lb_store.lua
62
lb_store.lua
@ -122,26 +122,6 @@ local function stat_str(stat)
|
|||||||
return "0"
|
return "0"
|
||||||
end
|
end
|
||||||
|
|
||||||
local function djb2(message)
|
|
||||||
local digest = 5381
|
|
||||||
for c in message:gmatch(".") do
|
|
||||||
digest = (($ << 5) + $) + string.byte(c)
|
|
||||||
end
|
|
||||||
|
|
||||||
return digest
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Produce a checksum by using the maps title, subtitle and zone
|
|
||||||
local function mapChecksum(mapnum)
|
|
||||||
local mh = mapheaderinfo[mapnum]
|
|
||||||
if not mh then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local digest = string.format("%04x", djb2(mh.lvlttl..mh.subttl..mh.zonttl))
|
|
||||||
return string.sub(digest, #digest - 3)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- GLOBAL
|
-- GLOBAL
|
||||||
-- Save a record to the LiveStore and write to disk
|
-- Save a record to the LiveStore and write to disk
|
||||||
-- SaveRecord will replace the record holders previous record but it will not compare any record times
|
-- SaveRecord will replace the record holders previous record but it will not compare any record times
|
||||||
@ -161,11 +141,6 @@ local function SaveRecord(score, map, modeSep)
|
|||||||
|
|
||||||
for mapid, records in pairs(LiveStore) do
|
for mapid, records in pairs(LiveStore) do
|
||||||
for _, record in ipairs(records) do
|
for _, record in ipairs(records) do
|
||||||
-- Insert checksum if missing
|
|
||||||
if (not record.checksum) or record.checksum == "" then
|
|
||||||
record.checksum = mapChecksum(mapid)
|
|
||||||
end
|
|
||||||
|
|
||||||
f:write(
|
f:write(
|
||||||
mapid, "\t",
|
mapid, "\t",
|
||||||
record.name, "\t",
|
record.name, "\t",
|
||||||
@ -174,8 +149,7 @@ local function SaveRecord(score, map, modeSep)
|
|||||||
record.time, "\t",
|
record.time, "\t",
|
||||||
table.concat(record.splits, " "), "\t",
|
table.concat(record.splits, " "), "\t",
|
||||||
record.flags, "\t",
|
record.flags, "\t",
|
||||||
stat_str(record.stat), "\t",
|
stat_str(record.stat), "\n"
|
||||||
record.checksum or "", "\n"
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -190,7 +164,7 @@ end
|
|||||||
|
|
||||||
addHook("NetVars", netvars)
|
addHook("NetVars", netvars)
|
||||||
|
|
||||||
local function score_t(map, name, skin, color, time, splits, flags, stat, checksum)
|
local function score_t(map, name, skin, color, time, splits, flags, stat)
|
||||||
return {
|
return {
|
||||||
["map"] = map,
|
["map"] = map,
|
||||||
["name"] = name,
|
["name"] = name,
|
||||||
@ -199,8 +173,7 @@ local function score_t(map, name, skin, color, time, splits, flags, stat, checks
|
|||||||
["time"] = time,
|
["time"] = time,
|
||||||
["splits"] = splits,
|
["splits"] = splits,
|
||||||
["flags"] = flags,
|
["flags"] = flags,
|
||||||
["stat"] = stat,
|
["stat"] = stat
|
||||||
["checksum"] = checksum
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -233,8 +206,6 @@ local function parseScore(str)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local checksum = t[9]
|
|
||||||
|
|
||||||
return score_t(
|
return score_t(
|
||||||
tonumber(t[1]), -- Map
|
tonumber(t[1]), -- Map
|
||||||
t[2], -- Name
|
t[2], -- Name
|
||||||
@ -243,24 +214,25 @@ local function parseScore(str)
|
|||||||
tonumber(t[5]), -- Time
|
tonumber(t[5]), -- Time
|
||||||
splits,
|
splits,
|
||||||
flags,
|
flags,
|
||||||
stats,
|
stats
|
||||||
checksum
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
rawset(_G, "lb_parse_score", parseScore)
|
rawset(_G, "lb_parse_score", parseScore)
|
||||||
|
|
||||||
-- Load the livestore
|
-- Load the livestore
|
||||||
if isserver then
|
do
|
||||||
local f = assert(
|
if isserver then
|
||||||
io.open(LEADERBOARD_FILE, "r"),
|
local f = assert(
|
||||||
"Failed to open file: "..LEADERBOARD_FILE
|
io.open(LEADERBOARD_FILE, "r"),
|
||||||
)
|
"Failed to open file: "..LEADERBOARD_FILE
|
||||||
|
)
|
||||||
|
|
||||||
for l in f:lines() do
|
for l in f:lines() do
|
||||||
local score = parseScore(l)
|
local score = parseScore(l)
|
||||||
LiveStore[score.map] = $ or {}
|
LiveStore[score.map] = $ or {}
|
||||||
table.insert(LiveStore[score.map], score)
|
table.insert(LiveStore[score.map], score)
|
||||||
|
end
|
||||||
|
|
||||||
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
f:close()
|
|
||||||
end
|
end
|
||||||
|
@ -13,11 +13,6 @@ records_lua = sys.argv[3]
|
|||||||
def ParseScore(score):
|
def ParseScore(score):
|
||||||
# Map Name Skin Color Time Splits Flags Stat
|
# Map Name Skin Color Time Splits Flags Stat
|
||||||
split = score.split("\t")
|
split = score.split("\t")
|
||||||
|
|
||||||
checksum = ""
|
|
||||||
if len(split) > 8:
|
|
||||||
checksum = split[8]
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"map": split[0],
|
"map": split[0],
|
||||||
"name": split[1],
|
"name": split[1],
|
||||||
@ -26,8 +21,7 @@ def ParseScore(score):
|
|||||||
"time": int(split[4]),
|
"time": int(split[4]),
|
||||||
"splits": split[5],
|
"splits": split[5],
|
||||||
"flags": int(split[6]),
|
"flags": int(split[6]),
|
||||||
"stat": split[7],
|
"stat": split[7]
|
||||||
"checksum": checksum
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Compare scores
|
# Compare scores
|
||||||
@ -71,20 +65,14 @@ for score in recordsList:
|
|||||||
|
|
||||||
# convert records to flat list
|
# convert records to flat list
|
||||||
recordsList = []
|
recordsList = []
|
||||||
rejected = []
|
|
||||||
for mapTable in records.values():
|
for mapTable in records.values():
|
||||||
for score in mapTable:
|
for score in mapTable:
|
||||||
scoreStr = "\t".join([str(v) for v in list(score.values())])
|
recordsList.append("\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
|
# truncate and write records to coldstore
|
||||||
with open(coldstore_txt, "w") as f:
|
with open(coldstore_txt, "w") as f:
|
||||||
for score in recordsList:
|
for score in recordsList:
|
||||||
f.write(score + linesep)
|
f.write(score + linesep)
|
||||||
|
|
||||||
luaA = """local ParseScore = lb_parse_score
|
luaA = """local ParseScore = lb_parse_score
|
||||||
local AddColdStore = lb_add_coldstore_record
|
local AddColdStore = lb_add_coldstore_record
|
||||||
@ -102,7 +90,5 @@ with open(records_lua, "w") as f:
|
|||||||
f.write("\"{}\",{}".format(score, linesep))
|
f.write("\"{}\",{}".format(score, linesep))
|
||||||
f.write(luaB)
|
f.write(luaB)
|
||||||
|
|
||||||
# truncate and rewrite rejected scores to leaderboard.txt
|
# truncate leaderboard.txt
|
||||||
with open(leaderboard_txt, "w") as f:
|
with open(leaderboard_txt, "w"): pass
|
||||||
for score in rejected:
|
|
||||||
f.write(score + linesep)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user