-- Time to shut down server.
local H, M = 23, 30
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 1 then return end
timer = 0
local t = os.date("*t")
if (t.hour == H) and (t.min == M) and (t.sec <= 5) then
minetest.chat_send_all("Scheduled shutdown. "
.."Please come back in a few minutes.")
minetest.after(2, minetest.request_shutdown)
end
end)
Minetestforfun wrote:@kaeza
interresting simple code for shutting down a server in lua, can you add days in your code, please ?
-- Time to shut down server.
local H, M = 23, 30
-- Day to shut down server.
-- 1=Sunday, ..., 7=Saturday, nil=Shutdown daily
local D = nil
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 1 then return end
timer = 0
local t = os.date("*t")
if ((t.hour == H) and (t.min == M) and (t.sec <= 5)
and ((D == nil) or (t.wday == D))) then
minetest.chat_send_all("Scheduled shutdown. "
.."Please come back in a few minutes.")
minetest.after(2, minetest.request_shutdown)
end
end)
kaeza wrote:Minetestforfun wrote:@kaeza
interresting simple code for shutting down a server in lua, can you add days in your code, please ?
Sure:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
-- Time to shut down server.
local H, M = 23, 30
-- Day to shut down server.
-- 1=Sunday, ..., 7=Saturday, nil=Shutdown daily
local D = nil
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < 1 then return end
timer = 0
local t = os.date("*t")
if ((t.hour == H) and (t.min == M) and (t.sec <= 5)
and ((D == nil) or (t.wday == D))) then
minetest.chat_send_all("Scheduled shutdown. "
.."Please come back in a few minutes.")
minetest.after(2, minetest.request_shutdown)
end
end)
rubenwardy wrote:Minetest accepts SIGINT and runs minetest.register_on_shutdown etc.
rubenwardy wrote:Minetest accepts SIGINT and runs minetest.register_on_shutdown etc.
Users browsing this forum: No registered users and 22 guests