From a8ed4c596d7a3a4092f607d3ccc319dd25b7afda Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Sun, 5 Nov 2017 12:24:05 -0800 Subject: [PATCH] Initial Checkin --- .luacheckrc | 15 +++++++++++++ depends.txt | 0 description.txt | 1 + init.lua | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ mod.conf | 1 + readme.md | 11 ++++++++++ 6 files changed, 84 insertions(+) create mode 100644 .luacheckrc create mode 100644 depends.txt create mode 100644 description.txt create mode 100644 init.lua create mode 100644 mod.conf create mode 100644 readme.md diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..15eed66 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,15 @@ +unused_args = false +allow_defined_top = true + +read_globals = { + "DIR_DELIM", + "minetest", "core", + "dump", + "vector", "nodeupdate", + "VoxelManip", "VoxelArea", + "PseudoRandom", "ItemStack", + "intllib", + "default", + table = { fields = { "copy", "getn" } } +} + diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..e69de29 diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..d18dae7 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +Shut down the server after the last player leaves. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..4ad0e23 --- /dev/null +++ b/init.lua @@ -0,0 +1,56 @@ + +--[[ + + Copyright 2017 Auke Kok + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject + to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY + KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +]]-- + +local def = 300 -- server must be empty for this long +local int = 6 -- check interval in seconds + +local to = def + +local function do_shutdown() + local i, _ = next(minetest.get_connected_players()) + if not i then + to = to - int + else + to = def + minetest.after(int, do_shutdown) + return + end + if to < 0 then + minetest.log("action", "autoshutdown") + minetest.request_shutdown() + else + minetest.after(int, do_shutdown) + end +end + +minetest.register_chatcommand("autoshutdown", { + params = "autoshutdown server", + description = "shut the server down after the last player leaves", + privs = {server = true}, + func = function(name, param) + do_shutdown() + end, +}) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..542baa2 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = autoshutdown diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..84e5540 --- /dev/null +++ b/readme.md @@ -0,0 +1,11 @@ + +## autoshutdown mod + +Allows admins to schedule a shutdown when the last player leaves. + +The server shuts down a little time after the last player leaves, +to make sure all areas are slowly unloaded. + +To schedule an automatic shutdown, issue the `/autoshutdown` command +in chat. The shutdown will only happen once. +