From b43620565dedf3dd9df0bee504d7b97183534e77 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Thu, 16 Jun 2016 21:38:50 +0200 Subject: [PATCH] [shutdown] Update with colours and complex tick mechanism - Messages now come with colour - The tick function is launched at the first second of a new minute which is determined at startup --- mods/shutdown/init.lua | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/mods/shutdown/init.lua b/mods/shutdown/init.lua index 446c208c..d5ff81d5 100755 --- a/mods/shutdown/init.lua +++ b/mods/shutdown/init.lua @@ -28,31 +28,40 @@ end local timer = 0 +local function send(msg, col) + core.chat_send_all(core.colorize(col, msg)) +end + local function tick() local heure = os.date("%H") local minute = os.date("%M") -- Warn every days if heure == "04" then if minute == "00" then - minetest.chat_send_all("Rappel : Redémarrage journalier du serveur dans 30 minutes. (Dure 30 minutes)") - minetest.chat_send_all("Reminder : Daily reboot of the server in 30 minutes. (Lasts 30 minutes)") + send("Rappel : Redémarrage journalier du serveur dans 30 minutes. (Dure 30 minutes)", "#ffff00") + send("Reminder : Daily reboot of the server in 30 minutes. (Lasts 30 minutes)", "#ffff00") sound_play_all("shutdown_shutdown") elseif minute == "15" then - minetest.chat_send_all("Rappel : Redémarrage journalier du serveur dans 15 minutes. (Dure 30 minutes)") - minetest.chat_send_all("Reminder : Daily reboot of the server in 15 minutes. (Lasts 30 minutes)") + send("Rappel : Redémarrage journalier du serveur dans 15 minutes. (Dure 30 minutes)", "#FF6600") + send("Reminder : Daily reboot of the server in 15 minutes. (Lasts 30 minutes)", "#FF6600") sound_play_all("shutdown_shutdown") elseif minute == "25" then - minetest.chat_send_all("Rappel : Redémarrage journalier du serveur dans 5 minutes - Pensez à vous deconnecter !") - minetest.chat_send_all("Reminder : Daily reboot of the server in 5 minutes - Think about logout!") + send("Rappel : Redémarrage journalier du serveur dans 5 minutes - Pensez à vous deconnecter !", "#ff0000") + send("Reminder : Daily reboot of the server in 5 minutes - Prepare to log out!", "#ff0000") sound_play_all("shutdown_shutdown") elseif minute == "29" then - minetest.chat_send_all("=== ARRET DU SERVEUR - DE NOUVEAU EN LIGNE DANS 30 MIN ===") - minetest.chat_send_all("=== SERVER SHUTTING DOWN - ONLINE AGAIN IN 30 MIN ===") + send("=== ARRET DU SERVEUR - DE NOUVEAU EN LIGNE DANS 30 MIN ===", "#ff0000") + send("=== SERVER SHUTTING DOWN - ONLINE AGAIN IN 30 MIN ===", "#ff0000") sound_play_all("shutdown_shutdown") -- minetest.request_shutdown() end end - minetest.after(20, tick) + minetest.after(60, tick) end -tick() +minetest.after(0, function() -- When server has just started + -- Calculate time until next minute to start laps (+1 sec to be sure) + minetest.after(61 - tonumber(os.date("%S")), function() + tick() + end) +end)