Mercurial > prosody-modules
comparison mod_muc_limits/mod_muc_limits.lua @ 3965:2b10e51d85a6
mod_muc_limits: Add config option to limit to join stanzas only
This is a bit more limited in pre-0.11 MUC modules, because it just
detects stanzas sent to full JIDs (which would include all presence
and nick changes).
This option is useful for setups where users are typically unaffiliated,
but trusted (e.g. if access to the room is gated through some other
means such as password/token auth).
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 03 Apr 2020 12:26:56 +0100 |
parents | 15355caf4553 |
children | 731ba9400c10 |
comparison
equal
deleted
inserted
replaced
3964:15355caf4553 | 3965:2b10e51d85a6 |
---|---|
11 | 11 |
12 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); | 12 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); |
13 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); | 13 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); |
14 | 14 |
15 local max_nick_length = module:get_option_number("muc_max_nick_length", 23); -- Default chosen through scientific methods | 15 local max_nick_length = module:get_option_number("muc_max_nick_length", 23); -- Default chosen through scientific methods |
16 local join_only = module:get_option_boolean("muc_limit_joins_only", false); | |
16 local dropped_count = 0; | 17 local dropped_count = 0; |
17 local dropped_jids; | 18 local dropped_jids; |
18 | 19 |
19 local function log_dropped() | 20 local function log_dropped() |
20 module:log("warn", "Dropped %d stanzas from %d JIDs: %s", dropped_count, #dropped_jids, t_concat(dropped_jids, ", ")); | 21 module:log("warn", "Dropped %d stanzas from %d JIDs: %s", dropped_count, #dropped_jids, t_concat(dropped_jids, ", ")); |
77 for room_jid, room in pairs(rooms) do --luacheck: ignore 213/room_jid | 78 for room_jid, room in pairs(rooms) do --luacheck: ignore 213/room_jid |
78 room.throttle = nil; | 79 room.throttle = nil; |
79 end | 80 end |
80 end | 81 end |
81 | 82 |
82 module:hook("message/bare", handle_stanza, 501); | |
83 module:hook("message/full", handle_stanza, 501); | |
84 module:hook("presence/bare", handle_stanza, 501); | |
85 module:hook("presence/full", handle_stanza, 501); | 83 module:hook("presence/full", handle_stanza, 501); |
84 if not join_only then | |
85 module:hook("message/bare", handle_stanza, 501); | |
86 module:hook("message/full", handle_stanza, 501); | |
87 module:hook("presence/bare", handle_stanza, 501); | |
88 end | |
86 else | 89 else |
87 module:hook("muc-occupant-pre-join", handle_stanza); | 90 module:hook("muc-occupant-pre-join", handle_stanza); |
88 module:hook("muc-occupant-pre-change", handle_stanza); | 91 if not join_only then |
89 module:hook("muc-occupant-groupchat", handle_stanza); | 92 module:hook("muc-occupant-pre-change", handle_stanza); |
93 module:hook("muc-occupant-groupchat", handle_stanza); | |
94 end | |
90 end | 95 end |