rules/init.lua

193 lines
5.6 KiB
Lua
Raw Normal View History

2018-11-11 18:57:07 +00:00
-- License: WTFPL
rules = {}
local items = {
"By playing on this server you agree to these rules:",
"",
"1. No swearing, dating, or other inappriopriate behaviour.",
"2. No spamming, using all-caps, or any other method of chat abuse.",
"3. Don't be a cheater. No hacked clients.",
"4. Don't excessively spawnkill. Some spawn killing to stop players chasing",
2018-11-11 18:57:07 +00:00
" the flag bearer is OK, but hogging the flag and repeatedly killing",
" the same players definitely isn't.",
"5. Don't be a traitor. Don't:",
2018-11-11 18:57:07 +00:00
" a. Dig blocks in your base to make it less secure or",
" to trap team mates on purpose.",
" b. Help the other team win.",
" c. Change teams.",
2019-10-24 08:50:56 +00:00
"6. Don't leave the game whilst in a fight",
"7. Don't impersonate other community members",
"8. Do not share your password with ANYONE.",
"9. Avoid controversial topics like politics/religion",
"10. Moderator decisions are final.",
2018-11-11 18:57:07 +00:00
"",
"Failure to follow these rules may result in a kick or ban",
" (temp or permanent) depending on severity.",
"",
"Developed and hosted by rubenwardy",
"Moderators: Thomas-S, ANAND, IceAgeComing, Waterbug, DragonsVolcanoDance,",
2019-07-14 12:57:10 +00:00
" Gael-de-Sailly, Shara, Calinou, Aurika, Lone_Wolf, Xenon",
2018-11-11 18:57:07 +00:00
"",
"Though the server owner will not actively read private messages or disclose",
2019-01-19 23:43:19 +00:00
"their content outside the mod team, random checks will be done to make sure",
2018-11-11 18:57:07 +00:00
"they are not being abused and they will be reviewed if abuse or inappropriate",
"behaviour is suspected. ",
"",
"Use /report to send a message to a moderator.",
"For example, /report bobgreen is destroying our base"}
for i = 1, #items do
items[i] = minetest.formspec_escape(items[i])
end
rules.txt = table.concat(items, ",")
if minetest.global_exists("sfinv") then
sfinv.register_page("rules:rules", {
title = "Rules",
get = function(self, player, context)
return sfinv.make_formspec(player, context,
"textlist[0,0;7.85,8.5;help;" .. rules.txt .. "]", false)
end
})
end
local function can_grant_interact(player)
2019-01-20 23:43:34 +00:00
local pname = player:get_player_name()
return not minetest.check_player_privs(pname, { interact = true }) and
not minetest.check_player_privs(pname, { fly = true })
2018-11-11 18:57:07 +00:00
end
2019-01-19 23:43:19 +00:00
local function has_password(pname)
local handler = minetest.get_auth_handler()
local auth = handler.get_auth(pname)
return auth and not minetest.check_password_entry(pname, auth.password, "")
end
2018-11-11 18:57:07 +00:00
function rules.show(player)
2019-01-19 23:43:19 +00:00
local pname = player:get_player_name()
2019-01-20 00:07:26 +00:00
local fs = "size[8,8.6]bgcolor[#080808BB;true]" ..
2018-11-11 18:57:07 +00:00
default.gui_bg ..
default.gui_bg_img ..
2019-01-20 00:07:26 +00:00
"textlist[0.1,0.1;7.8,7.9;msg;" .. rules.txt .. ";-1;true]"
2018-11-11 18:57:07 +00:00
2019-01-19 23:43:19 +00:00
if not has_password(pname) then
2019-01-20 00:07:26 +00:00
fs = fs .. "box[4,8.1;3.1,0.7;#900]"
fs = fs .. "label[4.2,8.2;Please set a password]"
fs = fs .. "button_exit[0.5,7.6;3.5,2;ok;Okay]"
2019-01-19 23:43:19 +00:00
elseif not can_grant_interact(player) then
2019-01-20 00:07:26 +00:00
fs = fs .. "button_exit[0.5,7.6;7,2;ok;Okay]"
2018-11-11 18:57:07 +00:00
else
local yes = minetest.formspec_escape("Yes, let me play!")
local no = minetest.formspec_escape("No, get me out of here!")
2019-01-20 00:07:26 +00:00
fs = fs .. "button_exit[0.5,7.6;3.5,2;no;" .. no .. "]"
fs = fs .. "button_exit[4,7.6;3.5,2;yes;" .. yes .. "]"
2018-11-11 18:57:07 +00:00
end
2019-01-19 23:43:19 +00:00
minetest.show_formspec(pname, "rules:rules", fs)
2018-11-11 18:57:07 +00:00
end
2019-01-20 23:43:34 +00:00
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
2018-11-11 18:57:07 +00:00
minetest.register_chatcommand("rules", {
2019-01-20 23:43:34 +00:00
func = function(pname, param)
2018-11-11 18:57:07 +00:00
if param ~= "" and
2019-01-20 23:43:34 +00:00
minetest.check_player_privs(pname, { kick = true }) then
pname = param
2018-11-11 18:57:07 +00:00
end
2019-01-20 23:43:34 +00:00
local player = minetest.get_player_by_name(pname)
2018-11-11 18:57:07 +00:00
if player then
rules.show(player)
return true, "Rules shown."
else
2019-01-20 23:43:34 +00:00
return false, "Player " .. pname .. " does not exist or is not online"
2018-11-11 18:57:07 +00:00
end
end
})
minetest.register_on_joinplayer(function(player)
2019-01-19 23:43:19 +00:00
local pname = player:get_player_name()
local privs = minetest.get_player_privs(pname)
2018-11-11 18:57:07 +00:00
if privs.interact and privs.fly then
privs.interact = false
2019-01-20 23:43:34 +00:00
minetest.set_player_privs(pname, privs)
2018-11-11 18:57:07 +00:00
end
2019-01-19 23:43:19 +00:00
if not has_password(pname) then
privs.shout = false
privs.interact = false
privs.kick = false
privs.ban = false
minetest.set_player_privs(pname, privs)
2019-01-20 23:43:34 +00:00
rules.show_pwd(pname)
2019-01-19 23:43:19 +00:00
elseif can_grant_interact(player) then
2018-11-11 18:57:07 +00:00
rules.show(player)
end
end)
minetest.register_on_player_receive_fields(function(player, form, fields)
2019-01-20 23:43:34 +00:00
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
2018-11-11 18:57:07 +00:00
if form ~= "rules:rules" then
return
end
2019-01-20 23:43:34 +00:00
local pname = player:get_player_name()
if not can_grant_interact(player) or not has_password(pname) then
2018-11-11 18:57:07 +00:00
return true
end
if fields.msg then
return true
elseif not fields.yes or fields.no then
2019-01-20 23:43:34 +00:00
minetest.kick_player(pname,
2018-11-11 18:57:07 +00:00
"You need to agree to the rules to play on this server. " ..
"Please rejoin and confirm another time.")
return true
end
2019-01-20 23:43:34 +00:00
local privs = minetest.get_player_privs(pname)
2018-11-11 18:57:07 +00:00
privs.shout = true
privs.interact = true
2019-01-20 23:43:34 +00:00
minetest.set_player_privs(pname, privs)
2018-11-11 18:57:07 +00:00
2019-01-20 23:43:34 +00:00
minetest.chat_send_player(pname, "Welcome "..pname.."! You have now permission to play!")
2018-11-11 18:57:07 +00:00
return true
end)