# HG changeset patch # User Matthew Wild # Date 1370124160 -3600 # Node ID a44e755f757984c09e410a979813bb50955b062f # Parent 09a5082a81621fec1872055863a798028f35bdf1 mod_muc_limits: Add muc_max_nick_length option, defaulting to 23 (bytes) diff -r 09a5082a8162 -r a44e755f7579 mod_muc_limits/mod_muc_limits.lua --- a/mod_muc_limits/mod_muc_limits.lua Sat Jun 01 22:47:55 2013 +0100 +++ b/mod_muc_limits/mod_muc_limits.lua Sat Jun 01 23:02:40 2013 +0100 @@ -8,6 +8,8 @@ local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); +local max_nick_length = module:get_option_number("muc_max_nick_length", 23); -- Default chosen through scientific methods + local function handle_stanza(event) local origin, stanza = event.origin, event.stanza; if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving @@ -21,6 +23,11 @@ if occupant and occupant.affiliation then module:log("debug", "Skipping stanza from affiliated user..."); return; + elseif max_nick_length and stanza.name == "presence" and not room._occupants[stanza.attr.to] and #dest_nick > max_nick_length then + module:log("debug", "Forbidding long (%d bytes) nick in %s", #dest_nick, dest_room) + origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your nick name is too long, please use a shorter one") + :up():tag("x", { xmlns = xmlns_muc })); + return true; end local throttle = room.throttle; if not room.throttle then