forked from Not/srb2k-leaderboard
ghosts alpha
This commit is contained in:
@ -124,3 +124,44 @@ rawset(_G, "lb_fire_event", function(event, ...)
|
||||
pcall(callback, ...)
|
||||
end
|
||||
end)
|
||||
|
||||
local b62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
local function base62_encode(n)
|
||||
if n <= 0 then return "0" end
|
||||
local b62 = b62
|
||||
local q = n
|
||||
local r = ""
|
||||
local t
|
||||
while q > 0 do
|
||||
t = q % 62 + 1
|
||||
r = b62:sub(t, t)..r
|
||||
q = q / 62
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
local function base62_decode(s)
|
||||
local n = b62:find(s:sub(1,1)) - 1
|
||||
for i = 2, #s do
|
||||
n = n * 62 + b62:find(s:sub(i, i)) - 1
|
||||
end
|
||||
|
||||
return n
|
||||
end
|
||||
|
||||
local function neg_base62_encode(n)
|
||||
if n == INT32_MIN then
|
||||
return "-2lkCB2"
|
||||
end
|
||||
|
||||
if n < 0 then return "-"..base62_encode(abs(n)) end
|
||||
return base62_encode(n)
|
||||
end
|
||||
|
||||
local function neg_base62_decode(s)
|
||||
if s:sub(1, 1) == "-" then return -base62_decode(s:sub(2)) end
|
||||
return base62_decode(s)
|
||||
end
|
||||
|
||||
rawset(_G, "lb_base62_encode", neg_base62_encode)
|
||||
rawset(_G, "lb_base62_decode", neg_base62_decode)
|
||||
|
Reference in New Issue
Block a user