border/init.lua

52 lines
1.3 KiB
Lua
Raw Normal View History

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()
local border = "OPEN"
2017-07-05 14:31:20 -07:00
-- initialise
if mod_data:get_string("status") == "" then
mod_data:set_string("status", "CLOSED")
2017-07-05 14:31:20 -07:00
end
--set
border = mod_data:get_string("status")
-- 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)
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
border = "CLOSED"
minetest.chat_send_player(name, "[border:info] refusing new players.")
2017-07-05 14:31:20 -07:00
end
mod_data:set_string("flag", border) -- save
end
})
-- register hook
minetest.register_on_prejoinplayer(function(name, ip)
2017-07-05 16:20:51 -07:00
-- owner exception
if minetest.setting_get("name") == name then
return
end
2017-07-05 14:31:20 -07:00
-- stop NEW players from joining
if border == "CLOSED" and not core.auth_table[name] then
2017-07-05 14:31:20 -07:00
return ("\nSorry, no new players being admitted at this time!")
end
end
)