Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend mod to also support invites #15

Merged
merged 22 commits into from Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions init.lua
Expand Up @@ -33,7 +33,11 @@ do
end
temp = minetest.settings:get('spectator_mode.extra_observe_privs_moderator')
if (not temp) or ('' == temp) then
-- if no extra settings for moderators are set, then the table for observers
-- is linked and both use the same table reference.
sm.extra_observe_privs_moderator = sm.extra_observe_privs
-- if you prefer to keep the lists separate, uncomment next line
--sm.extra_observe_privs_moderator = table.copy(sm.extra_observe_privs)
else
sm.extra_observe_privs_moderator = {}
SmallJoker marked this conversation as resolved.
Show resolved Hide resolved
for _, priv in ipairs(temp:split(',')) do
Expand Down Expand Up @@ -242,8 +246,13 @@ local function attach(name_watcher, name_target)
target = name_target,
visual_size = properties.visual_size,
}
local privs_extra = invites[name_watcher] and sm.extra_observe_privs
or sm.extra_observe_privs_moderator
local privs_extra
if invites[name_watcher] then
privs_extra = sm.extra_observe_privs
else
-- wasn't invited -> '/watch' used by moderator
privs_extra = sm.extra_observe_privs_moderator
end

for key, _ in pairs(privs_extra) do
state.privs_extra[key] = privs_watcher[key]
Expand Down Expand Up @@ -298,8 +307,10 @@ local function watch(name_watcher, name_target)

-- avoid infinite loops
-- TODO: should we just watch the watched one then? Griefers can be a nuisance both ways.
SmallJoker marked this conversation as resolved.
Show resolved Hide resolved
if original_state[name_target] then return true, '"' .. name_target .. '" is watching "'
.. original_state[name_target].target .. '". You may not watch a watcher.' end
if original_state[name_target] then
return true, '"' .. name_target .. '" is watching "'
.. original_state[name_target].target .. '". You may not watch a watcher.'
end

attach(name_watcher, name_target)
return true, 'Watching "' .. name_target .. '" at '
Expand Down Expand Up @@ -484,10 +495,13 @@ function spectator_mode.on_respawnplayer(watcher)
local name_target = state.target
local name_watcher = watcher:get_player_name()
player_api.player_attached[name_watcher] = true
-- detach destroys invited entry, we need to restore that
if invited[name_watcher] then
detach(name_watcher)
-- mark as invited so players get info in chat on detach.
invited[name_watcher] = name_target
else
-- was a moderator using '/watch' -> conceal the spy.
detach(name_watcher)
end
after(.4, attach, name_watcher, name_target)
Expand Down
2 changes: 1 addition & 1 deletion settingtypes.txt
Expand Up @@ -11,7 +11,7 @@ spectator_mode.command_detach (Chatcommand to stop observing a player) string un
spectator_mode.extra_observe_privs (Extra privs for observers) string

# Additional privs granted to observers that used '/watch' command. e.g. jail,kick,teleport
# If left empty will use spectator_mode.extra_observe_privs
# If left empty will use spectator_mode.extra_observe_privs (same table reference).
spectator_mode.extra_observe_privs_moderator (Extra privs for observing moderators) string

# To invite another player to observe player that issued this command
Expand Down