Add password field to rules:pwd
This commit is contained in:
parent
c4bf9f2514
commit
4001e684cf
1 changed files with 49 additions and 27 deletions
76
init.lua
76
init.lua
|
@ -54,8 +54,9 @@ if minetest.global_exists("sfinv") then
|
||||||
end
|
end
|
||||||
|
|
||||||
local function can_grant_interact(player)
|
local function can_grant_interact(player)
|
||||||
local name = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
return not minetest.check_player_privs(name, { interact = true }) and not minetest.check_player_privs(name, { fly = true })
|
return not minetest.check_player_privs(pname, { interact = true }) and
|
||||||
|
not minetest.check_player_privs(pname, { fly = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
local function has_password(pname)
|
local function has_password(pname)
|
||||||
|
@ -88,19 +89,31 @@ function rules.show(player)
|
||||||
minetest.show_formspec(pname, "rules:rules", fs)
|
minetest.show_formspec(pname, "rules:rules", fs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function rules.show_pwd(pname, msg)
|
||||||
|
msg = msg or "You must set a password to be able to play"
|
||||||
|
|
||||||
|
minetest.show_formspec(pname, "rules:pwd", [[
|
||||||
|
size[8,3]
|
||||||
|
no_prepends[]
|
||||||
|
bgcolor[#600]
|
||||||
|
pwdfield[0.8,1.5;7,1;pwd;Password;]
|
||||||
|
button[0.5,2;7,2;setpwd;Set]
|
||||||
|
label[0.2,0.2;]] .. minetest.formspec_escape(msg) .. "]")
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_chatcommand("rules", {
|
minetest.register_chatcommand("rules", {
|
||||||
func = function(name, param)
|
func = function(pname, param)
|
||||||
if param ~= "" and
|
if param ~= "" and
|
||||||
minetest.check_player_privs(name, { kick = true }) then
|
minetest.check_player_privs(pname, { kick = true }) then
|
||||||
name = param
|
pname = param
|
||||||
end
|
end
|
||||||
|
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(pname)
|
||||||
if player then
|
if player then
|
||||||
rules.show(player)
|
rules.show(player)
|
||||||
return true, "Rules shown."
|
return true, "Rules shown."
|
||||||
else
|
else
|
||||||
return false, "Player " .. name .. " does not exist or is not online"
|
return false, "Player " .. pname .. " does not exist or is not online"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -111,58 +124,67 @@ minetest.register_on_joinplayer(function(player)
|
||||||
local privs = minetest.get_player_privs(pname)
|
local privs = minetest.get_player_privs(pname)
|
||||||
if privs.interact and privs.fly then
|
if privs.interact and privs.fly then
|
||||||
privs.interact = false
|
privs.interact = false
|
||||||
minetest.set_player_privs(player:get_player_name(), privs)
|
minetest.set_player_privs(pname, privs)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not has_password(pname) then
|
if not has_password(pname) then
|
||||||
local privs = minetest.get_player_privs(pname)
|
|
||||||
privs.shout = false
|
privs.shout = false
|
||||||
privs.interact = false
|
privs.interact = false
|
||||||
privs.kick = false
|
privs.kick = false
|
||||||
privs.ban = false
|
privs.ban = false
|
||||||
minetest.set_player_privs(pname, privs)
|
minetest.set_player_privs(pname, privs)
|
||||||
|
rules.show_pwd(pname)
|
||||||
minetest.show_formspec(pname, "rules:pwd", [[
|
|
||||||
size[8,3]
|
|
||||||
no_prepends[]
|
|
||||||
bgcolor[#600]
|
|
||||||
label[0.2,0.2;Please set a password]
|
|
||||||
button_exit[0.5,2;7,2;yes;Okay]
|
|
||||||
textarea[0.2,1;7.9,2;;;]] ..
|
|
||||||
minetest.formspec_escape("Press escape or the back button. " ..
|
|
||||||
"Select 'change password'.\n" ..
|
|
||||||
"When done, type /rules.\n" ..
|
|
||||||
"You will not be able to obtain interact until you get this.") .. "]")
|
|
||||||
elseif can_grant_interact(player) then
|
elseif can_grant_interact(player) then
|
||||||
rules.show(player)
|
rules.show(player)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, form, fields)
|
minetest.register_on_player_receive_fields(function(player, form, fields)
|
||||||
|
if form == "rules:pwd" then
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
if fields.setpwd then
|
||||||
|
local handler = minetest.get_auth_handler()
|
||||||
|
if not fields.pwd or fields.pwd:trim() == "" then
|
||||||
|
rules.show_pwd(pname)
|
||||||
|
elseif #fields.pwd < 5 then
|
||||||
|
rules.show_pwd(pname, "Needs at least 5 characters")
|
||||||
|
else
|
||||||
|
handler.set_password(pname,
|
||||||
|
minetest.get_password_hash(pname, fields.pwd))
|
||||||
|
rules.show(player)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
minetest.kick_player(pname,
|
||||||
|
"You need to set a password to play on this server.")
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if form ~= "rules:rules" then
|
if form ~= "rules:rules" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local name = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
if not can_grant_interact(player) or not has_password(name) then
|
if not can_grant_interact(player) or not has_password(pname) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields.msg then
|
if fields.msg then
|
||||||
return true
|
return true
|
||||||
elseif not fields.yes or fields.no then
|
elseif not fields.yes or fields.no then
|
||||||
minetest.kick_player(name,
|
minetest.kick_player(pname,
|
||||||
"You need to agree to the rules to play on this server. " ..
|
"You need to agree to the rules to play on this server. " ..
|
||||||
"Please rejoin and confirm another time.")
|
"Please rejoin and confirm another time.")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local privs = minetest.get_player_privs(name)
|
local privs = minetest.get_player_privs(pname)
|
||||||
privs.shout = true
|
privs.shout = true
|
||||||
privs.interact = true
|
privs.interact = true
|
||||||
minetest.set_player_privs(name, privs)
|
minetest.set_player_privs(pname, privs)
|
||||||
|
|
||||||
minetest.chat_send_player(name, "Welcome "..name.."! You have now permission to play!")
|
minetest.chat_send_player(pname, "Welcome "..pname.."! You have now permission to play!")
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in a new issue