Use checksums to identify maps #5
@ -289,9 +289,30 @@ local function writeScore(fh, score)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function saveScores()
|
||||||
|
local f = assert(io.open(FILENAME + ".txt", "w"))
|
||||||
|
if f == nil then
|
||||||
|
print("Failed to open file for writing: " + FILENAME + ".txt")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, tbl in pairs(lb) do
|
||||||
|
for _, scoreTable in pairs(tbl) do
|
||||||
|
for _, score in ipairs(scoreTable) do
|
||||||
|
writeScore(f, score)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
|
||||||
-- Read the leaderboard
|
-- Read the leaderboard
|
||||||
local f = io.open(FILENAME + ".txt", "r")
|
local f = io.open(FILENAME + ".txt", "r")
|
||||||
if f then
|
if f then
|
||||||
|
-- track if scores checksums have been written
|
||||||
|
local checksumWrite = false
|
||||||
|
|
||||||
for l in f:lines() do
|
for l in f:lines() do
|
||||||
-- Leaderboard is stored in the following tab separated format
|
-- Leaderboard is stored in the following tab separated format
|
||||||
-- mapnum, name, skin, color, time, splits, flags, stat, map_checksum
|
-- mapnum, name, skin, color, time, splits, flags, stat, map_checksum
|
||||||
@ -326,11 +347,14 @@ if f then
|
|||||||
local mapnum = tonumber(t[1])
|
local mapnum = tonumber(t[1])
|
||||||
|
|
||||||
-- Checksums
|
-- Checksums
|
||||||
local cks = t[9] or mapChecksum(mapnum)
|
local cks = t[9]
|
||||||
|
|
||||||
|
if cks == nil then
|
||||||
|
checksumWrite = true
|
||||||
|
cks = mapChecksum(mapnum)
|
||||||
|
|
||||||
-- We have no previous recognition of this map
|
-- We have no previous recognition of this map
|
||||||
-- remove it
|
-- remove it
|
||||||
if cks == nil then
|
|
||||||
if cks == nil then
|
if cks == nil then
|
||||||
local rsfh = io.open(FILENAME + "_removed_scores.txt", "a")
|
local rsfh = io.open(FILENAME + "_removed_scores.txt", "a")
|
||||||
if not rsfh then
|
if not rsfh then
|
||||||
@ -363,6 +387,11 @@ if f then
|
|||||||
|
|
||||||
sortScores()
|
sortScores()
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
|
-- save scores
|
||||||
|
if checksumWrite then
|
||||||
|
saveScores()
|
||||||
|
end
|
||||||
else
|
else
|
||||||
print("Failed to open file: ", FILENAME + ".txt")
|
print("Failed to open file: ", FILENAME + ".txt")
|
||||||
end
|
end
|
||||||
@ -1232,21 +1261,7 @@ local function saveTime(player)
|
|||||||
StatTrack = true
|
StatTrack = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local f = assert(io.open(FILENAME + ".txt", "w"))
|
saveScores()
|
||||||
if f == nil then
|
|
||||||
print("Failed to open file for writing: " + FILENAME + ".txt")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, tbl in pairs(lb) do
|
|
||||||
for _, scoreTable in pairs(tbl) do
|
|
||||||
for _, score in ipairs(scoreTable) do
|
|
||||||
writeScore(f, score)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
f:close()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- DEBUGGING
|
-- DEBUGGING
|
||||||
|
Loading…
Reference in New Issue
Block a user