Fix race between player purge and reregister

If a player quits before agreeing to the terms, and gets added to
the purge queue, but then reauths immediately, they can get
re-purged before they finish emerging, causing an assert fail on
trying to record their last login time.

If a player re-registers, immediately remove them from the purge
retry queue, so their login time can safely be recorded.

Also, if the server shuts down with incomplete players in the
"lobby", then add them all to the purge queue too.
This commit is contained in:
Aaron Suen 2024-08-27 07:16:09 -04:00
parent 96537348d3
commit 068dd46ec1

View File

@ -1,6 +1,6 @@
-- LUALOCALS < ---------------------------------------------------------
local error, math, minetest, next, pairs, string, type
= error, math, minetest, next, pairs, string, type
local error, ipairs, math, minetest, next, pairs, string, type
= error, ipairs, math, minetest, next, pairs, string, type
local math_ceil, math_random, string_format, string_gsub, string_lower,
string_sub
= math.ceil, math.random, string.format, string.gsub, string.lower,
@ -249,10 +249,25 @@ if purge then
end
minetest.after(0, processqueue)
minetest.register_on_authplayer(function(pname, _, is_success)
if not is_success then return end
cache[pname] = nil
end)
local function purgecheck(player)
local pname = player:get_player_name()
if minetest.check_player_privs(pname, modname) then return end
cache[pname] = 10
end
minetest.register_on_leaveplayer(function(player)
local pname = player:get_player_name()
if minetest.check_player_privs(pname, modname) then return end
cache[pname] = 10
purgecheck(player)
save()
end)
minetest.register_on_shutdown(function()
for _, player in ipairs(minetest.get_connected_players()) do
purgecheck(player)
end
save()
end)
if purgetag and purgetag ~= "" then