Software /
code /
prosody
Comparison
plugins/muc/lock.lib.lua @ 7408:cf53081ce767
MUC: Use a timestamp to keep track of when to unlock room instead of a timer (so timer does not unlock an evicted room)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 28 Apr 2016 23:20:41 +0200 |
parent | 7407:e465b584547b |
child | 7999:980606856882 |
comparison
equal
deleted
inserted
replaced
7407:e465b584547b | 7408:cf53081ce767 |
---|---|
12 local lock_rooms = module:get_option_boolean("muc_room_locking", false); | 12 local lock_rooms = module:get_option_boolean("muc_room_locking", false); |
13 local lock_room_timeout = module:get_option_number("muc_room_lock_timeout", 300); | 13 local lock_room_timeout = module:get_option_number("muc_room_lock_timeout", 300); |
14 | 14 |
15 local function lock(room) | 15 local function lock(room) |
16 module:fire_event("muc-room-locked", {room = room;}); | 16 module:fire_event("muc-room-locked", {room = room;}); |
17 room._data.locked = true; | 17 room._data.locked = os.time() + lock_room_timeout; |
18 end | 18 end |
19 local function unlock(room) | 19 local function unlock(room) |
20 module:fire_event("muc-room-unlocked", {room = room;}); | 20 module:fire_event("muc-room-unlocked", {room = room;}); |
21 room._data.locked = nil; | 21 room._data.locked = nil; |
22 end | 22 end |
23 local function is_locked(room) | 23 local function is_locked(room) |
24 return not not room._data.locked; | 24 local ts = room._data.locked or false; |
25 if ts then | |
26 if ts < os.time() then return true; end | |
27 unlock(room); | |
28 end | |
29 return false; | |
25 end | 30 end |
26 | 31 |
27 if lock_rooms then | 32 if lock_rooms then |
28 module:hook("muc-room-pre-create", function(event) | 33 module:hook("muc-room-pre-create", function(event) |
29 -- Older groupchat protocol doesn't lock | 34 -- Older groupchat protocol doesn't lock |
30 if not event.stanza:get_child("x", "http://jabber.org/protocol/muc") then return end | 35 if not event.stanza:get_child("x", "http://jabber.org/protocol/muc") then return end |
31 -- Lock room at creation | 36 -- Lock room at creation |
32 local room = event.room; | 37 local room = event.room; |
33 lock(room); | 38 lock(room); |
34 if lock_room_timeout and lock_room_timeout > 0 then | |
35 module:add_timer(lock_room_timeout, function () | |
36 if is_locked(room) then | |
37 room:destroy(); -- Not unlocked in time | |
38 end | |
39 end); | |
40 end | |
41 end, 10); | 39 end, 10); |
42 end | 40 end |
43 | 41 |
44 -- Don't let users into room while it is locked | 42 -- Don't let users into room while it is locked |
45 module:hook("muc-occupant-pre-join", function(event) | 43 module:hook("muc-occupant-pre-join", function(event) |