Only save/load files for the server

This commit is contained in:
Lonsfor 2022-08-24 19:25:53 +02:00
parent a840a5fa83
commit 518e9f7893
1 changed files with 71 additions and 67 deletions

View File

@ -257,60 +257,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)
@ -1259,30 +1261,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