Compare commits

..

3 Commits

Author SHA1 Message Date
518e9f7893 Only save/load files for the server 2022-08-24 19:25:53 +02:00
Not
a840a5fa83 revert maploaded cvars 2022-08-24 16:18:24 +02:00
Not
bd5e3f24c6 add extra checks for spbattack 2022-08-23 17:10:10 +02:00

View File

@ -12,7 +12,6 @@ local splits = {}
local PATCH = nil local PATCH = nil
local help = true local help = true
local EncoreInitial = nil local EncoreInitial = nil
local cv_teamchange
local scoreTable local scoreTable
@ -91,6 +90,10 @@ local ticsToTime
local allowJoin local allowJoin
--------------- ---------------
-- cvars
local cv_teamchange
local cv_spbatk
local cv_gui = CV_RegisterVar({ local cv_gui = CV_RegisterVar({
name = "lb_gui", name = "lb_gui",
defaultvalue = GUI_ON, defaultvalue = GUI_ON,
@ -254,60 +257,62 @@ local function stat_str(stat)
end end
-- Read the leaderboard -- Read the leaderboard
local f = io.open(FILENAME, "r") if isserver then
if f then local f = io.open(FILENAME, "r")
for l in f:lines() do if f then
-- Leaderboard is stored in the following tab separated format for l in f:lines() do
-- mapnum, name, skin, color, time, splits, flags, stat -- Leaderboard is stored in the following tab separated format
local t = {} -- mapnum, name, skin, color, time, splits, flags, stat
for word in (l+"\t"):gmatch("(.-)\t") do local t = {}
table.insert(t, word) for word in (l+"\t"):gmatch("(.-)\t") do
end table.insert(t, word)
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))
end end
end
local stats = nil local flags = 0
if t[8] != nil then if t[7] != nil then
if #t[8] >= 2 then flags = tonumber(t[7])
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
end
table.insert( scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
scoreTable,
score_t( local spl = {}
tonumber(t[1]), if t[6] != nil then
t[2], for str in t[6]:gmatch("([^ ]+)") do
t[3], table.insert(spl, tonumber(str))
t[4], end
tonumber(t[5]), end
spl,
flags, local stats = nil
stats 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 end
sortScores()
f:close()
else
print("Failed to open file: ", FILENAME)
end end
function allowJoin(v) function allowJoin(v)
@ -1256,30 +1261,32 @@ local function saveTime(player)
StatTrack = true StatTrack = true
end end
local f = assert(io.open(FILENAME, "w")) if isserver then
if f == nil then local f = assert(io.open(FILENAME, "w"))
print("Failed to open file for writing: " + FILENAME) if f == nil then
return print("Failed to open file for writing: " + FILENAME)
end return
end
for _, tbl in pairs(lb) do for _, tbl in pairs(lb) do
for _, scoreTable in pairs(tbl) do for _, scoreTable in pairs(tbl) do
for _, score in ipairs(scoreTable) do for _, score in ipairs(scoreTable) do
f:write( f:write(
score["map"], "\t", score["map"], "\t",
score["name"], "\t", score["name"], "\t",
score["skin"], "\t", score["skin"], "\t",
score["color"], "\t", score["color"], "\t",
score["time"], "\t", score["time"], "\t",
table.concat(score["splits"], " "), "\t", table.concat(score["splits"], " "), "\t",
score["flags"], "\t", score["flags"], "\t",
stat_str(score["stat"]), "\n" stat_str(score["stat"]), "\n"
) )
end
end end
end end
end
f:close() f:close()
end
end end
-- DEBUGGING -- DEBUGGING
@ -1379,10 +1386,15 @@ local function think()
end end
end end
end end
if not cv_spbatk then
cv_spbatk = CV_FindVar("spbatk")
end
-- Gamemode flags -- Gamemode flags
Flags = $ & !(F_SPBATK | F_SPBEXP | F_SPBBIG | F_SPBJUS) Flags = $ & !(F_SPBATK | F_SPBEXP | F_SPBBIG | F_SPBJUS)
if leveltime > START_TIME - (3 * TICRATE) / 2 and server.SPBArunning then if server.SPBArunning
and cv_spbatk.value
and leveltime > START_TIME - (3 * TICRATE) / 2 then
Flags = $ | F_SPBATK Flags = $ | F_SPBATK
if server.SPBAexpert then if server.SPBAexpert then
Flags = $ | F_SPBEXP Flags = $ | F_SPBEXP
@ -1405,10 +1417,18 @@ local function think()
end end
end end
end -- make sure the spb actually spawned
if not (Flags & F_SPBATK) then if leveltime == START_TIME - 1 then
if not (server.SPBAbomb and server.SPBAbomb.valid) then
-- it didn't spawn, clear spb flags
Flags = $ & !(F_SPBATK | F_SPBEXP | F_SPBBIG | F_SPBJUS)
end
end
else
hud.enable("freeplay") hud.enable("freeplay")
end end
end end
scoreTable = getScoreTable(gamemap, Flags) scoreTable = getScoreTable(gamemap, Flags)