2018-01-07 03:53:12 +00:00
|
|
|
|
|
|
|
-- register bypass priv
|
|
|
|
minetest.register_privilege("news_bypass", {
|
2018-01-07 20:18:26 +00:00
|
|
|
description = "Skip the news.", give_to_singleplayer = false})
|
2018-01-07 03:53:12 +00:00
|
|
|
|
|
|
|
-- create formspec from text file
|
|
|
|
local function get_formspec()
|
|
|
|
local news_file = io.open(minetest.get_worldpath().."/news.txt", "r")
|
2018-01-14 02:17:24 +00:00
|
|
|
local news_fs = 'size[12,8.25]'..
|
|
|
|
"button_exit[-0.05,7.8;2,1;exit;Close]"
|
2018-01-07 03:53:12 +00:00
|
|
|
if news_file then
|
|
|
|
local news = news_file:read("*a")
|
2018-01-07 20:18:26 +00:00
|
|
|
news_file:close()
|
2019-05-26 11:59:49 +02:00
|
|
|
news_fs = news_fs.."textarea[0.25,0;12.1,9;news;;"..minetest.formspec_escape(news).."]"
|
2018-01-07 03:53:12 +00:00
|
|
|
else
|
2018-01-14 02:17:24 +00:00
|
|
|
news_fs = news_fs.."textarea[0.25,0;12.1,9;news;;No current news.]"
|
2018-01-07 03:53:12 +00:00
|
|
|
end
|
|
|
|
return news_fs
|
|
|
|
end
|
|
|
|
|
|
|
|
-- show news formspec on player join, unless player has bypass priv
|
|
|
|
minetest.register_on_joinplayer(function (player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if minetest.get_player_privs(name).news_bypass then
|
|
|
|
return
|
|
|
|
else
|
|
|
|
minetest.show_formspec(name, "news", get_formspec())
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- command to display server news at any time
|
|
|
|
minetest.register_chatcommand("news", {
|
|
|
|
description = "Shows server news to the player",
|
2018-01-07 20:18:26 +00:00
|
|
|
func = function (name)
|
2018-01-07 03:53:12 +00:00
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
minetest.show_formspec(name, "news", get_formspec())
|
|
|
|
end
|
2018-01-07 20:18:26 +00:00
|
|
|
})
|