Merge pull request 'Only save/load files for the server' (#6) from Lonsfor/srb2k-leaderboard:lonsfor-patch-3 into master
Reviewed-on: #6
This commit is contained in:
commit
1d4eb423d6
138
leaderboard.lua
138
leaderboard.lua
@ -272,60 +272,62 @@ local function stat_str(stat)
|
||||
end
|
||||
|
||||
-- Read the leaderboard
|
||||
local f = io.open(FILENAME, "r")
|
||||
if f then
|
||||
for l in f:lines() do
|
||||
-- Leaderboard is stored in the following tab separated format
|
||||
-- mapnum, name, skin, color, time, splits, flags, stat
|
||||
local t = {}
|
||||
for word in (l+"\t"):gmatch("(.-)\t") do
|
||||
table.insert(t, word)
|
||||
end
|
||||
|
||||
local flags = 0
|
||||
if t[7] != nil then
|
||||
flags = tonumber(t[7])
|
||||
end
|
||||
|
||||
scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
|
||||
|
||||
local spl = {}
|
||||
if t[6] != nil then
|
||||
for str in t[6]:gmatch("([^ ]+)") do
|
||||
table.insert(spl, tonumber(str))
|
||||
if isserver then
|
||||
local f = io.open(FILENAME, "r")
|
||||
if f then
|
||||
for l in f:lines() do
|
||||
-- Leaderboard is stored in the following tab separated format
|
||||
-- mapnum, name, skin, color, time, splits, flags, stat
|
||||
local t = {}
|
||||
for word in (l+"\t"):gmatch("(.-)\t") do
|
||||
table.insert(t, word)
|
||||
end
|
||||
end
|
||||
|
||||
local stats = nil
|
||||
if t[8] != nil then
|
||||
if #t[8] >= 2 then
|
||||
local speed = tonumber(string.sub(t[8], 1, 1))
|
||||
local weight = tonumber(string.sub(t[8], 2, 2))
|
||||
stats = stat_t(speed, weight)
|
||||
local flags = 0
|
||||
if t[7] != nil then
|
||||
flags = tonumber(t[7])
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(
|
||||
scoreTable,
|
||||
score_t(
|
||||
tonumber(t[1]),
|
||||
t[2],
|
||||
t[3],
|
||||
t[4],
|
||||
tonumber(t[5]),
|
||||
spl,
|
||||
flags,
|
||||
stats
|
||||
scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
|
||||
|
||||
local spl = {}
|
||||
if t[6] != nil then
|
||||
for str in t[6]:gmatch("([^ ]+)") do
|
||||
table.insert(spl, tonumber(str))
|
||||
end
|
||||
end
|
||||
|
||||
local stats = nil
|
||||
if t[8] != nil then
|
||||
if #t[8] >= 2 then
|
||||
local speed = tonumber(string.sub(t[8], 1, 1))
|
||||
local weight = tonumber(string.sub(t[8], 2, 2))
|
||||
stats = stat_t(speed, weight)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(
|
||||
scoreTable,
|
||||
score_t(
|
||||
tonumber(t[1]),
|
||||
t[2],
|
||||
t[3],
|
||||
t[4],
|
||||
tonumber(t[5]),
|
||||
spl,
|
||||
flags,
|
||||
stats
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
setScoreTable(tonumber(t[1]), flags, scoreTable)
|
||||
setScoreTable(tonumber(t[1]), flags, scoreTable)
|
||||
end
|
||||
|
||||
sortScores()
|
||||
f:close()
|
||||
else
|
||||
print("Failed to open file: ", FILENAME)
|
||||
end
|
||||
|
||||
sortScores()
|
||||
f:close()
|
||||
else
|
||||
print("Failed to open file: ", FILENAME)
|
||||
end
|
||||
|
||||
function allowJoin(v)
|
||||
@ -1315,30 +1317,32 @@ local function saveTime(player)
|
||||
StatTrack = true
|
||||
end
|
||||
|
||||
local f = assert(io.open(FILENAME, "w"))
|
||||
if f == nil then
|
||||
print("Failed to open file for writing: " + FILENAME)
|
||||
return
|
||||
end
|
||||
if isserver then
|
||||
local f = assert(io.open(FILENAME, "w"))
|
||||
if f == nil then
|
||||
print("Failed to open file for writing: " + FILENAME)
|
||||
return
|
||||
end
|
||||
|
||||
for _, tbl in pairs(lb) do
|
||||
for _, scoreTable in pairs(tbl) do
|
||||
for _, score in ipairs(scoreTable) do
|
||||
f:write(
|
||||
score["map"], "\t",
|
||||
score["name"], "\t",
|
||||
score["skin"], "\t",
|
||||
score["color"], "\t",
|
||||
score["time"], "\t",
|
||||
table.concat(score["splits"], " "), "\t",
|
||||
score["flags"], "\t",
|
||||
stat_str(score["stat"]), "\n"
|
||||
)
|
||||
for _, tbl in pairs(lb) do
|
||||
for _, scoreTable in pairs(tbl) do
|
||||
for _, score in ipairs(scoreTable) do
|
||||
f:write(
|
||||
score["map"], "\t",
|
||||
score["name"], "\t",
|
||||
score["skin"], "\t",
|
||||
score["color"], "\t",
|
||||
score["time"], "\t",
|
||||
table.concat(score["splits"], " "), "\t",
|
||||
score["flags"], "\t",
|
||||
stat_str(score["stat"]), "\n"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
f:close()
|
||||
f:close()
|
||||
end
|
||||
end
|
||||
|
||||
-- DEBUGGING
|
||||
|
Loading…
Reference in New Issue
Block a user