Add userlimit skip if sufficient score

This commit is contained in:
rubenwardy 2018-01-02 23:51:38 +00:00
parent 15653f7648
commit d66cabe446
4 changed files with 30 additions and 11 deletions

View file

@ -104,6 +104,20 @@ function chatplus.save()
end
end
local function clean_player(name, value)
if value.messages then
value.inbox = value.messages
value.messages = nil
end
if (
(not value.inbox or #value.inbox==0) and
(not value.ignore or #value.ignore==0)
) then
chatplus.players[name] = nil
end
end
function chatplus.clean_players()
if not chatplus.players then
chatplus.players = {}
@ -112,17 +126,7 @@ function chatplus.clean_players()
minetest.log("[Chatplus] Cleaning player lists")
for key,value in pairs(chatplus.players) do
if value.messages then
value.inbox = value.messages
value.messages = nil
end
if (
(not value.inbox or #value.inbox==0) and
(not value.ignore or #value.ignore==0)
) then
chatplus.players[key] = nil
end
clean_player(key, value)
end
chatplus.save()
end
@ -151,6 +155,7 @@ function chatplus.poke(name,player)
if player=="end" then
chatplus.players[name].enabled = false
chatplus.loggedin[name] = nil
clean_player(name, chatplus.players[name])
else
if not chatplus.loggedin[name] then
chatplus.loggedin[name] = {}

View file

@ -76,6 +76,10 @@ ctf.register_on_save(function()
return nil
end)
function ctf_stats.player_or_nil(name)
return ctf_stats.players[name], ctf_stats.current.red[name] or ctf_stats.current.blue[name]
end
-- Returns a tuple: `player_stats`, `match_player_stats`
function ctf_stats.player(name)
local player_stats = ctf_stats.players[name]

View file

@ -0,0 +1,2 @@
ctf
ctf_stats

View file

@ -0,0 +1,8 @@
minetest.register_can_bypass_userlimit(function(name, ip)
local pstat, discard = ctf_stats.player_or_nil(name)
local actual_max_users = tonumber(minetest.settings:get("max_users")) +
tonumber(minetest.settings:get("max_extra_users") or "10")
local req_score = tonumber(minetest.settings:get("userlimit_bypass_required_score") or "10000")
return pstat and pstat.score > req_score and #minetest.get_connected_players() < actual_max_users
end)