forked from Not/srb2k-leaderboard
map identity by checksum
This commit is contained in:
@ -44,3 +44,23 @@ rawset(_G, "lb_comp", function(a, b)
|
||||
local s = (a.flags & (F_SPBEXP | F_SPBBIG)) - (b.flags & (F_SPBEXP | F_SPBBIG))
|
||||
return s > 0 or not(s < 0 or a.time >= b.time)
|
||||
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
|
||||
rawset(_G, "lb_map_checksum", function(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)
|
||||
|
Reference in New Issue
Block a user