Bladeren bron

feat: Dynamically limit the number of participants in a room (#9880)

* Dynamically limit the number of participants in a room

* Remove log
master
abora8x8 3 jaren geleden
bovenliggende
commit
a5fc75ed35
No account linked to committer's email address
1 gewijzigde bestanden met toevoegingen van 10 en 4 verwijderingen
  1. 10
    4
      resources/prosody-plugins/mod_muc_max_occupants.lua

+ 10
- 4
resources/prosody-plugins/mod_muc_max_occupants.lua Bestand weergeven

7
 local split_jid = require "util.jid".split;
7
 local split_jid = require "util.jid".split;
8
 local st = require "util.stanza";
8
 local st = require "util.stanza";
9
 local it = require "util.iterators";
9
 local it = require "util.iterators";
10
+local is_healthcheck_room = module:require "util".is_healthcheck_room;
10
 
11
 
11
 local whitelist = module:get_option_set("muc_access_whitelist");
12
 local whitelist = module:get_option_set("muc_access_whitelist");
12
 local MAX_OCCUPANTS = module:get_option_number("muc_max_occupants", -1);
13
 local MAX_OCCUPANTS = module:get_option_number("muc_max_occupants", -1);
17
 
18
 
18
 local function check_for_max_occupants(event)
19
 local function check_for_max_occupants(event)
19
   local room, origin, stanza = event.room, event.origin, event.stanza;
20
   local room, origin, stanza = event.room, event.origin, event.stanza;
20
-
21
-	local actor = stanza.attr.from;
22
   local user, domain, res = split_jid(stanza.attr.from);
21
   local user, domain, res = split_jid(stanza.attr.from);
23
 
22
 
23
+  if is_healthcheck_room(room.jid) then
24
+    return;
25
+  end
26
+
24
   --no user object means no way to check for max occupants
27
   --no user object means no way to check for max occupants
25
   if user == nil then
28
   if user == nil then
26
     return
29
     return
32
   end
35
   end
33
 
36
 
34
 	if room and not room._jid_nick[stanza.attr.from] then
37
 	if room and not room._jid_nick[stanza.attr.from] then
38
+        local max_occupants_by_room = event.room._data.max_occupants;
35
 		local count = count_keys(room._occupants);
39
 		local count = count_keys(room._occupants);
36
-		local slots = MAX_OCCUPANTS;
40
+        -- if no of occupants limit is set per room basis use
41
+        -- that settings otherwise use the global one
42
+        local slots = max_occupants_by_room or MAX_OCCUPANTS;
37
 
43
 
38
 		-- If there is no whitelist, just check the count.
44
 		-- If there is no whitelist, just check the count.
39
-		if not whitelist and count >= MAX_OCCUPANTS then
45
+		if not whitelist and count >= slots then
40
 			module:log("info", "Attempt to enter a maxed out MUC");
46
 			module:log("info", "Attempt to enter a maxed out MUC");
41
 			origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
47
 			origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
42
 			return true;
48
 			return true;

Laden…
Annuleren
Opslaan