From 6afb884e5901fd0541c3bd3bfe6d41e1f4929234 Mon Sep 17 00:00:00 2001 From: Not Date: Wed, 31 Aug 2022 19:25:40 +0200 Subject: [PATCH] fix uninitialized variables, add browser timeout --- leaderboard.lua | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/leaderboard.lua b/leaderboard.lua index 1f91836..cbb3f45 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -55,6 +55,7 @@ local clearcheats = false local START_TIME = 6 * TICRATE + (3 * TICRATE / 4) + 1 local AFK_TIMEOUT = TICRATE * 5 +local AFK_BROWSER = TICRATE * 15 local AFK_BALANCE = TICRATE * 60 local AFK_BALANCE_WARN = AFK_BALANCE - TICRATE * 10 local PREVENT_JOIN_TIME = START_TIME + TICRATE * 5 @@ -407,18 +408,16 @@ local function initBrowser(player) CONS_Printf(player, "Please exit battle first") return end - if not DrawBrowser then - DrawBrowser = rawget(_G, "DrawBrowser") - if not DrawBrowser then - print("Browser is not loaded") - return - end - BrowserController = rawget(_G, "BrowserController") + if not rawget(_G, "DrawBrowser") then + print("Browser is not loaded") + return end rawget(_G, "InitBrowser")(lb) drawState = DS_BROWSER + + player.afkTime = leveltime end COM_AddCommand("levelselect", initBrowser) @@ -1144,6 +1143,9 @@ local function drawScrollTo(v, player, scoreTable, gui) end local function drawBrowser(v, player) + if not DrawBrowser then + DrawBrowser = rawget(_G, "DrawBrowser") + end DrawBrowser(v, lb) end @@ -1364,7 +1366,7 @@ local function think() if not singleplayer() then for p in players.iterate do if p.valid and not p.spectator and not p.exiting and p.lives > 0 then - if p.cmd.buttons then + if p.cmd.buttons or p.cmd.driftturn then p.afkTime = leveltime end @@ -1490,6 +1492,9 @@ local function think() end end elseif drawState == DS_BROWSER then + if not BrowserController then + BrowserController = rawget(_G, "BrowserController") + end if BrowserController(p) then drawState = DS_DEFAULT end @@ -1505,11 +1510,17 @@ local function think() p.pflags = $ & !(PF_TIMEOVER) p.exiting = 100 end + + -- prevent softlocking the server + if p.afkTime + AFK_BROWSER < leveltime then + drawState = DS_DEFAULT + S_StartSound(nil, 100) + end elseif p.lives == 0 then drawState = DS_SCROLL end - if p.cmd.buttons then + if p.cmd.buttons or p.cmd.driftturn then p.afkTime = leveltime end