Software /
code /
prosody-modules
Comparison
mod_muc_limits/mod_muc_limits.lua @ 1042:5fd0860c86cd
mod_muc_limits: Allow stanzas from affiliated users even if they are not in the room
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 03 Jun 2013 08:36:00 +0100 |
parent | 1040:6574303a8169 |
child | 1057:0b41122b19f9 |
comparison
equal
deleted
inserted
replaced
1041:7153b723fd87 | 1042:5fd0860c86cd |
---|---|
1 | 1 |
2 local jid = require "util.jid"; | 2 local jid_split, jid_bare = require "util.jid".split, require "util.jid".bare; |
3 local st = require "util.stanza"; | 3 local st = require "util.stanza"; |
4 local new_throttle = require "util.throttle".create; | 4 local new_throttle = require "util.throttle".create; |
5 local t_insert, t_concat = table.insert, table.concat; | 5 local t_insert, t_concat = table.insert, table.concat; |
6 local hosts = prosody.hosts; | |
6 | 7 |
7 local xmlns_muc = "http://jabber.org/protocol/muc"; | 8 local xmlns_muc = "http://jabber.org/protocol/muc"; |
8 | 9 |
9 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); | 10 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); |
10 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); | 11 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); |
22 local function handle_stanza(event) | 23 local function handle_stanza(event) |
23 local origin, stanza = event.origin, event.stanza; | 24 local origin, stanza = event.origin, event.stanza; |
24 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving | 25 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving |
25 return; | 26 return; |
26 end | 27 end |
27 local dest_room, dest_host, dest_nick = jid.split(stanza.attr.to); | 28 local dest_room, dest_host, dest_nick = jid_split(stanza.attr.to); |
28 local room = hosts[module.host].modules.muc.rooms[dest_room.."@"..dest_host]; | 29 local room = hosts[module.host].modules.muc.rooms[dest_room.."@"..dest_host]; |
29 if not room then return; end | 30 if not room then return; end |
30 local from_jid = stanza.attr.from; | 31 local from_jid = stanza.attr.from; |
31 local occupant = room._occupants[room._jid_nick[from_jid]]; | 32 local occupant = room._occupants[room._jid_nick[from_jid]]; |
32 if occupant and occupant.affiliation then | 33 if (occupant and occupant.affiliation) or (not(occupant) and room._affiliations[jid_bare(from_jid)]) then |
33 module:log("debug", "Skipping stanza from affiliated user..."); | 34 module:log("debug", "Skipping stanza from affiliated user..."); |
34 return; | 35 return; |
35 elseif max_nick_length and stanza.name == "presence" and not room._occupants[stanza.attr.to] and #dest_nick > max_nick_length then | 36 elseif max_nick_length and stanza.name == "presence" and not room._occupants[stanza.attr.to] and #dest_nick > max_nick_length then |
36 module:log("debug", "Forbidding long (%d bytes) nick in %s", #dest_nick, dest_room) | 37 module:log("debug", "Forbidding long (%d bytes) nick in %s", #dest_nick, dest_room) |
37 origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your nick name is too long, please use a shorter one") | 38 origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your nick name is too long, please use a shorter one") |