Improve spectator crash prevention (#20)

This commit is contained in:
Xenon 2021-03-06 16:37:57 +01:00 committed by GitHub
parent 6e7ee25095
commit 4d5800a62b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,14 +21,15 @@ minetest.register_chatcommand("watch", {
param = param:trim()
local target = minetest.get_player_by_name(param)
if target == player then
return false, "You can't spectate yourself!"
end
if not target then
return false, "Player " .. param .. " isn't online!"
end
if minetest.check_player_privs(target, {spectate = true}) then
return false, "Can't spectate yourself or another spectator!"
end
if player:get_attach() then
player:set_detach()
end
@ -37,10 +38,6 @@ minetest.register_chatcommand("watch", {
spectators[name] = {}
end
if minetest.check_player_privs(target, {spectate = true}) then
return false, "Can't spectate another spectator!"
end
spectators[name].target = param
local hud_text = "Spectating " .. param .. "..."
local hud_id = spectators[name].hud