diff --git a/minetest.conf b/minetest.conf index 109d6e4..201cabf 100644 --- a/minetest.conf +++ b/minetest.conf @@ -12,6 +12,7 @@ server_announce = true server_name = Legends Of Survival server_description = A server dedicated to survival and building via teamwork, this server is a continuation of the legacy of MM-Survival static_spawnpoint = -444 29 -869 +ts.duration = 86360 #-------------------------------------------------- #Game #-------------------------------------------------- diff --git a/mods/ts/init.lua b/mods/ts/init.lua new file mode 100644 index 0000000..5117b42 --- /dev/null +++ b/mods/ts/init.lua @@ -0,0 +1,36 @@ +--[[ +timed server shutdown mod for minetest +by shivajiva101@hotmail.com + +Useage: you can set a value in minetest.conf, the default length is ~24 hours + minus 30 seconds. + e.g. ts.duration = 86360 + should be used in conjunction with a shell script that restarts the server + +]] + +local duration = minetest.setting_get("ts.duration") or 86370 -- 23h 59m 30s + +local function chatsend(txt) + minetest.chat_send_all(txt) +end + +local function notify() + minetest.after(0, chatsend, "Daily restart in 30 seconds\nThe server will take ~30s to reload") + minetest.after(10, chatsend, "restarting in 20 seconds") + minetest.after(20, chatsend, "restarting in 10 seconds") + minetest.after(25, chatsend, "restarting in 5 seconds") + -- kick all player with a message + minetest.after(29, function() + chatsend("kicking players...") + for _,player in ipairs(minetest.get_connected_players()) do + local name = player:get_player_name() + -- player potentially attached to an entity + player:set_detach() + minetest.kick_player(name, name.." please rejoin in 30 seconds") + end + minetest.request_shutdown() + end) +end + +minetest.after(duration, notify)