# HG changeset patch # User Kim Alvefur # Date 1687643773 -7200 # Node ID f71d66bd87befec241b9d98d7d10a554f246ce3b # Parent b97ae1cd78130c34df5c9d7449aa93077656aee4 mod_muc_limits: Add a limit on number of lines per message More vertical space -> more cost diff -r b97ae1cd7813 -r f71d66bd87be mod_muc_limits/README.markdown --- a/mod_muc_limits/README.markdown Sat Jun 24 23:53:48 2023 +0200 +++ b/mod_muc_limits/README.markdown Sat Jun 24 23:56:13 2023 +0200 @@ -36,10 +36,11 @@ You can define (globally or per-MUC component) the following options: Name Default value Description - --------------------- --------------- ---------------------------------------------- + --------------------- --------------- -------------------------------------------------- muc_event_rate 0.5 The maximum number of events per second. muc_burst_factor 6 Allow temporary bursts of this multiple. muc_max_nick_length 23 The maximum allowed length of user nicknames + muc_max_line_count 23 The maximum allowed number of lines in a message For more understanding of how these values are used, see the algorithm section below. diff -r b97ae1cd7813 -r f71d66bd87be mod_muc_limits/mod_muc_limits.lua --- a/mod_muc_limits/mod_muc_limits.lua Sat Jun 24 23:53:48 2023 +0200 +++ b/mod_muc_limits/mod_muc_limits.lua Sat Jun 24 23:56:13 2023 +0200 @@ -13,6 +13,8 @@ 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 max_line_count = module:get_option_number("muc_max_line_count", 23); -- Default chosen through s/scientific methods/copy and paste/ + local join_only = module:get_option_boolean("muc_limit_joins_only", false); local dropped_count = 0; local dropped_jids; @@ -52,6 +54,11 @@ -- TODO calculate a text diagonal cross-section or some mathemagical -- number, maybe some cost multipliers local body_lines = select(2, body:gsub("\n[^\n]*", "")); + if body_lines > max_line_count then + origin.send(st.error_reply(stanza, "modify", "policy-violation", "Your message is too long, please write a shorter one"):up() + :tag("x", { xmlns = xmlns_muc; })); + return true; + end cost = cost + body_lines; end if not throttle:poll(cost) then