Add a lobby limit
This commit is contained in:
parent
590ae04fe5
commit
00ca2124d5
@ -21,6 +21,11 @@ Optionally, by setting szutil_motdagree_purge to true, users who log off
|
||||
without agreeing to the terms will be purged from the system and need
|
||||
to re-register each time until they agree to the terms.
|
||||
|
||||
The "lobby" is limited to only a few players at a time, and new players
|
||||
beyond this will be rejected, while players that have already agreed to
|
||||
the terms bypass this limit. There is both a soft and hard limit
|
||||
between which the probability of being rejected slides from 0% to 100%.
|
||||
|
||||
Moderators (who have the ban priv) can enable/disable new registrations
|
||||
using the /szutil_motdagree command. When registration is closed,
|
||||
players can enter the "lobby" but cannot agree to the terms until
|
||||
|
@ -1,8 +1,10 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local math, minetest, pairs, string, type
|
||||
= math, minetest, pairs, string, type
|
||||
local math_random, string_format, string_gsub, string_lower, string_sub
|
||||
= math.random, string.format, string.gsub, string.lower, string.sub
|
||||
local error, math, minetest, pairs, string, type
|
||||
= error, math, minetest, 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,
|
||||
string.sub
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
@ -16,6 +18,12 @@ end
|
||||
|
||||
local motddesc = conf("get", "desc") or "terms"
|
||||
|
||||
local limitsoft = conf("get", "limitsoft") or 3
|
||||
local limithard = conf("get", "limithard") or math_ceil(limitsoft * 1.5)
|
||||
if limithard < limitsoft then error("hard limit cannot be less than soft limit") end
|
||||
local limitmsg = conf("get", "limitmsg") or "There are too many new players"
|
||||
.. " right now; please try again in a few minutes."
|
||||
|
||||
local cmdname = conf("get", "cmdname") or "agree"
|
||||
local cmdparam = conf("get", "cmdparam") or ("to " .. motddesc)
|
||||
local cmdinstruct = conf("get", "cmdinstruct")
|
||||
@ -50,6 +58,25 @@ local function phsub(line, pname)
|
||||
return string_gsub(line, "<phash>", phash(pname))
|
||||
end
|
||||
|
||||
if limitsoft >= 0 and limithard > 0 then
|
||||
local emerging = {}
|
||||
minetest.register_on_prejoinplayer(function(name)
|
||||
if minetest.check_player_privs(name, modname) then return end
|
||||
local lobby = 0
|
||||
for _, p in pairs(minetest.get_connected_players()) do
|
||||
local pname = p:get_player_name()
|
||||
emerging[pname] = nil
|
||||
if not minetest.check_player_privs(p:get_player_name(), modname)
|
||||
then lobby = lobby + 1 end
|
||||
end
|
||||
for _, t in pairs(emerging) do
|
||||
if t + 60 < minetest.get_us_time() then lobby = lobby + 1 end
|
||||
end
|
||||
if lobby > math_random(limitsoft, limithard) then return limitmsg end
|
||||
emerging[name] = minetest.get_us_time() / 1000000
|
||||
end)
|
||||
end
|
||||
|
||||
local huds = {}
|
||||
local function dohud(player, id, offset, text)
|
||||
if not id then
|
||||
|
Loading…
x
Reference in New Issue
Block a user