2017-07-05 14:31:20 -07:00
|
|
|
--[[
|
|
|
|
original code provided by tenplus1
|
|
|
|
This mod instigates an effective border for new players joining a server
|
|
|
|
with persistence of the last state across server restarts
|
|
|
|
]]
|
|
|
|
|
|
|
|
local mod_data = minetest.get_mod_storage()
|
2017-07-05 16:30:14 -07:00
|
|
|
local border = "OPEN"
|
2018-01-28 17:02:42 -08:00
|
|
|
local visa = {}
|
2018-03-21 10:12:54 -07:00
|
|
|
local duration = 300
|
2017-07-05 14:31:20 -07:00
|
|
|
|
|
|
|
-- initialise
|
|
|
|
if mod_data:get_string("status") == "" then
|
2017-07-05 16:30:14 -07:00
|
|
|
mod_data:set_string("status", "CLOSED")
|
2017-07-05 14:31:20 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
--set
|
|
|
|
border = mod_data:get_string("status")
|
|
|
|
|
2017-07-05 16:30:14 -07:00
|
|
|
-- announce status
|
|
|
|
minetest.after(5, function()
|
|
|
|
minetest.chat_send_all("[border:info] border is "..border)
|
|
|
|
end)
|
|
|
|
|
2017-07-05 14:31:20 -07:00
|
|
|
-- toggle new players
|
|
|
|
minetest.register_chatcommand("border", {
|
|
|
|
params = "",
|
|
|
|
description = "Toggles if new players are allowed",
|
|
|
|
privs = {server = true},
|
|
|
|
func = function (name, param)
|
2017-07-05 16:30:14 -07:00
|
|
|
if border == "CLOSED" then
|
|
|
|
border = "OPEN"
|
|
|
|
minetest.chat_send_player(name, "[border:info] allowing new players.")
|
2017-07-05 14:31:20 -07:00
|
|
|
else
|
2017-07-05 16:30:14 -07:00
|
|
|
border = "CLOSED"
|
|
|
|
minetest.chat_send_player(name, "[border:info] refusing new players.")
|
2017-07-05 14:31:20 -07:00
|
|
|
end
|
2018-03-21 10:12:54 -07:00
|
|
|
mod_data:set_string("status", border) -- save
|
2017-07-05 14:31:20 -07:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2018-01-28 17:02:42 -08:00
|
|
|
minetest.register_chatcommand("visa", {
|
|
|
|
params = "player",
|
|
|
|
description = "Adds a temporary visa allowing a new player to create an account",
|
|
|
|
privs = {server = true},
|
|
|
|
func = function (name, param)
|
|
|
|
if not param then
|
|
|
|
minetest.chat_send_player(name, "Use: /visa <name>")
|
|
|
|
end
|
|
|
|
if not visa[param] then
|
|
|
|
visa[param] = true
|
2018-03-21 10:12:54 -07:00
|
|
|
minetest.after(duration, function(name)
|
2018-01-28 17:02:42 -08:00
|
|
|
if visa[name] then visa[name] = nil end
|
|
|
|
end, param)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2017-07-05 14:31:20 -07:00
|
|
|
-- register hook
|
|
|
|
minetest.register_on_prejoinplayer(function(name, ip)
|
2017-10-22 10:19:14 -07:00
|
|
|
-- owner exception
|
2017-07-05 16:20:51 -07:00
|
|
|
if minetest.setting_get("name") == name then
|
2017-10-22 10:19:14 -07:00
|
|
|
return
|
2017-07-05 16:20:51 -07:00
|
|
|
end
|
2017-10-22 10:19:14 -07:00
|
|
|
-- stop NEW players from joining
|
2018-01-28 14:25:44 -08:00
|
|
|
local player = minetest.get_auth_handler().get_auth(name)
|
2018-01-28 17:02:42 -08:00
|
|
|
if border == "CLOSED" and not player and not visa[name] then
|
2017-10-22 10:19:14 -07:00
|
|
|
return ("\nSorry, no new players being admitted at this time!")
|
|
|
|
end
|
2018-01-28 17:02:42 -08:00
|
|
|
if visa[name] then visa[name] = nil end
|
2017-10-22 10:19:14 -07:00
|
|
|
end
|
2017-07-05 14:31:20 -07:00
|
|
|
)
|