comparison mod_muc_limits/mod_muc_limits.lua @ 1036:a44e755f7579

mod_muc_limits: Add muc_max_nick_length option, defaulting to 23 (bytes)
author Matthew Wild <mwild1@gmail.com>
date Sat, 01 Jun 2013 23:02:40 +0100
parents 09a5082a8162
children edb06824a5a4
comparison
equal deleted inserted replaced
1035:09a5082a8162 1036:a44e755f7579
5 5
6 local xmlns_muc = "http://jabber.org/protocol/muc"; 6 local xmlns_muc = "http://jabber.org/protocol/muc";
7 7
8 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); 8 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0);
9 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); 9 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1);
10
11 local max_nick_length = module:get_option_number("muc_max_nick_length", 23); -- Default chosen through scientific methods
10 12
11 local function handle_stanza(event) 13 local function handle_stanza(event)
12 local origin, stanza = event.origin, event.stanza; 14 local origin, stanza = event.origin, event.stanza;
13 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving 15 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving
14 return; 16 return;
19 local from_jid = stanza.attr.from; 21 local from_jid = stanza.attr.from;
20 local occupant = room._occupants[room._jid_nick[from_jid]]; 22 local occupant = room._occupants[room._jid_nick[from_jid]];
21 if occupant and occupant.affiliation then 23 if occupant and occupant.affiliation then
22 module:log("debug", "Skipping stanza from affiliated user..."); 24 module:log("debug", "Skipping stanza from affiliated user...");
23 return; 25 return;
26 elseif max_nick_length and stanza.name == "presence" and not room._occupants[stanza.attr.to] and #dest_nick > max_nick_length then
27 module:log("debug", "Forbidding long (%d bytes) nick in %s", #dest_nick, dest_room)
28 origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your nick name is too long, please use a shorter one")
29 :up():tag("x", { xmlns = xmlns_muc }));
30 return true;
24 end 31 end
25 local throttle = room.throttle; 32 local throttle = room.throttle;
26 if not room.throttle then 33 if not room.throttle then
27 throttle = new_throttle(period*burst, burst); 34 throttle = new_throttle(period*burst, burst);
28 room.throttle = throttle; 35 room.throttle = throttle;