capturetheflag/mods/ctf/ctf_match/chat.lua

106 lines
2.5 KiB
Lua
Raw Normal View History

2015-12-07 23:54:22 +00:00
minetest.register_privilege("ctf_match", {
description = "can skip matches"
})
2015-07-17 17:10:17 +00:00
minetest.register_chatcommand("ctf_next", {
description = "Skip to the next match",
privs = {
2015-12-07 23:54:22 +00:00
ctf_match = true
2015-07-17 17:10:17 +00:00
},
func = function(name, param)
ctf_match.next()
minetest.log("action", name .. " ran /ctf_next")
2015-07-17 17:10:17 +00:00
end
})
2015-12-08 00:24:46 +00:00
minetest.register_chatcommand("ctf_start", {
description = "End build time",
privs = {
ctf_match = true
},
func = function(name, param)
ctf_match.build_timer = 0.01
minetest.log("action", name .. " ran /ctf_start")
end
})
2015-12-08 00:24:46 +00:00
minetest.register_chatcommand("ctf_respawn", {
description = "Respawn a player (clean inv, send to base)",
privs = {
ctf_team_mgr = true
},
func = function(name, param)
2015-12-30 14:24:03 +00:00
minetest.log("action", name .. " ran /ctf_respawn " .. param)
2015-12-08 00:24:46 +00:00
local tplayer = ctf.player_or_nil(param)
if tplayer then
local player = minetest.get_player_by_name(param)
if player then
ctf.move_to_spawn(param)
give_initial_stuff(player)
minetest.chat_send_player(param,
"You were sent back to base and your inventory wiped (by " .. name .. ")")
return true, "Moved player to spawn and wiped inventory."
else
return false, "Player is not online."
end
else
return false, "Player does not exist or is not in any teams."
end
end
})
2015-12-30 14:17:06 +00:00
local restart_on_next_match = false
local restart_on_next_match_by = nil
2021-02-19 22:34:10 +00:00
minetest.register_chatcommand("restart", {
2016-01-02 14:20:22 +00:00
description = "Queue server restart",
2015-12-30 14:17:06 +00:00
privs = {
server = true
},
func = function(name, param)
restart_on_next_match = true
restart_on_next_match_by = name
minetest.log("action", name .. " queued a restart")
2015-12-30 14:17:06 +00:00
return true, "Restart queued."
end
})
2021-02-19 22:34:10 +00:00
minetest.register_chatcommand("unqueue_restart", {
2016-01-02 14:20:22 +00:00
description = "Unqueue server restart",
privs = {
server = true
},
func = function(name, param)
restart_on_next_match = false
minetest.log("action", name .. " un-queued a restart")
2016-01-02 14:20:22 +00:00
return true, "Restart cancelled."
end
})
2020-04-30 17:08:01 +00:00
local function file_exists(path)
local file = io.open(path, "r")
if file then
file:close()
return true
end
return false
end
2015-12-30 14:17:06 +00:00
ctf_match.register_on_new_match(function()
if restart_on_next_match then
minetest.chat_send_player(restart_on_next_match_by, "Shutting down now!")
minetest.request_shutdown("Restarting server at operator request.", true)
2020-04-30 17:08:01 +00:00
return
end
local path = minetest.get_worldpath() .. "/queue_restart.txt"
if file_exists(path) then
assert(os.remove(path))
minetest.request_shutdown("Restarting server at operator request.", true)
return
2015-12-30 14:17:06 +00:00
end
end)