Skip to content

Commit

Permalink
irc: add server option "anti_flood", remove server options "anti_floo…
Browse files Browse the repository at this point in the history
…d_prio_{high|low}" (issue #1039)

The new option is set in milliseconds.
  • Loading branch information
flashcode committed Nov 29, 2023
1 parent e51152e commit f7b7e39
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 268 deletions.
1 change: 1 addition & 0 deletions ChangeLog.adoc
Expand Up @@ -27,6 +27,7 @@ New features::
* core: add number of processes in command `/sys waitpid`
* core, alias, trigger: allow wildcard in commands `/bar`, `/item`, `/proxy`, `/alias` and `/trigger` (issue #1956)
* buflist: jump to previous/next buffer displayed in buflist item with ctrl+wheel up/down on a buflist item (issue #1473)
* irc: add server option "anti_flood" (now in milliseconds), remove server options "anti_flood_prio_{high|low}" (issue #1039)
* irc: add option irc.look.list_buffer
* irc: change default value of server option "tls_priorities" to `NORMAL`
* irc: add support of RGB colors in messages, add option irc.color.term_remap (issue #2025)
Expand Down
27 changes: 27 additions & 0 deletions ReleaseNotes.adoc
Expand Up @@ -14,6 +14,33 @@ For a complete list of changes, please look at ChangeLog.
[[v4.2.0]]
== Version 4.2.0 (under dev)

[[v4.2.0_irc_anti_flood]]
=== IRC anti-flood

The anti-flood mechanism in IRC plugin has been improved and is now configured
in milliseconds instead of seconds. +
It is done with a single option `irc.server_default.anti_flood` (and same option
in servers), which replaces both options `anti_flood_prio_high` and
`anti_flood_prio_low`.

The default value is 2000 (2 seconds), and for example if you want to set
a delay of 0.5 seconds between your messages sent:

----
/set irc.server_default.anti_flood 500
----

When upgrading from an old WeeChat version, you'll see such messages, which are
perfectly normal (they're displayed to warn you about unknown options, and then
you have to set the new option if needed):

----
=!= | Warning: /home/user/.config/weechat/irc.conf, line 131: ignoring unknown option for section "server_default": anti_flood_prio_high = 2
=!= | Warning: /home/user/.config/weechat/irc.conf, line 132: ignoring unknown option for section "server_default": anti_flood_prio_low = 2
=!= | Warning: /home/user/.config/weechat/irc.conf, line 212: ignoring invalid value for option in section "server": libera.anti_flood_prio_high
=!= | Warning: //home/user/.config/weechat/irc.conf, line 213: ignoring invalid value for option in section "server": libera.anti_flood_prio_low
----

[[v4.2.0_search_commands_history]]
=== Search in commands history

Expand Down
35 changes: 14 additions & 21 deletions src/plugins/irc/irc-command.c
Expand Up @@ -2366,11 +2366,13 @@ irc_command_quit_server (struct t_irc_server *server, const char *arguments)
if (ptr_arg && ptr_arg[0])
{
msg = irc_server_get_default_msg (ptr_arg, server, NULL, NULL);
irc_server_sendf (server, 0, NULL, "QUIT :%s", msg);
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_IMMEDIATE, NULL,
"QUIT :%s", msg);
}
else
{
irc_server_sendf (server, 0, NULL, "QUIT");
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_IMMEDIATE, NULL,
"QUIT");
}

if (msg)
Expand Down Expand Up @@ -5495,26 +5497,16 @@ irc_command_display_server (struct t_irc_server *server, int with_detail)
IRC_COLOR_CHAT_VALUE,
weechat_config_integer (server->options[IRC_SERVER_OPTION_CONNECTION_TIMEOUT]),
NG_("second", "seconds", weechat_config_integer (server->options[IRC_SERVER_OPTION_CONNECTION_TIMEOUT])));
/* anti_flood_prio_high */
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH]))
weechat_printf (NULL, " anti_flood_prio_high : (%d %s)",
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH),
NG_("second", "seconds", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH)));
/* anti_flood */
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_ANTI_FLOOD]))
weechat_printf (NULL, " anti_flood . . . . . : (%d %s)",
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD),
NG_("second", "seconds", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD)));
else
weechat_printf (NULL, " anti_flood_prio_high : %s%d %s",
weechat_printf (NULL, " anti_flood . . . . . : %s%d %s",
IRC_COLOR_CHAT_VALUE,
weechat_config_integer (server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH]),
NG_("second", "seconds", weechat_config_integer (server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH])));
/* anti_flood_prio_low */
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW]))
weechat_printf (NULL, " anti_flood_prio_low. : (%d %s)",
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW),
NG_("second", "seconds", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW)));
else
weechat_printf (NULL, " anti_flood_prio_low. : %s%d %s",
IRC_COLOR_CHAT_VALUE,
weechat_config_integer (server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW]),
NG_("second", "seconds", weechat_config_integer (server->options[IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW])));
weechat_config_integer (server->options[IRC_SERVER_OPTION_ANTI_FLOOD]),
NG_("second", "seconds", weechat_config_integer (server->options[IRC_SERVER_OPTION_ANTI_FLOOD])));
/* away_check */
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_AWAY_CHECK]))
weechat_printf (NULL, " away_check . . . . . : (%d %s)",
Expand Down Expand Up @@ -6176,7 +6168,8 @@ IRC_COMMAND_CALLBACK(squit)

WEECHAT_COMMAND_MIN_ARGS(2, "");

irc_server_sendf (ptr_server, 0, NULL, "SQUIT %s", argv_eol[1]);
irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_IMMEDIATE, NULL,
"SQUIT %s", argv_eol[1]);

return WEECHAT_RC_OK;
}
Expand Down
61 changes: 32 additions & 29 deletions src/plugins/irc/irc-config.c
Expand Up @@ -179,12 +179,7 @@ struct t_config_option *irc_config_network_whois_double_nick = NULL;

/* IRC config, server section */

struct t_config_option *irc_config_server_default[IRC_SERVER_NUM_OPTIONS] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
};
struct t_config_option *irc_config_server_default[IRC_SERVER_NUM_OPTIONS];
struct t_hook *irc_config_hook_config_nick_color_options = NULL;
struct t_hook *irc_config_hook_config_chat_nick_colors = NULL;
struct t_hashtable *irc_config_hashtable_display_join_message = NULL;
Expand Down Expand Up @@ -1102,6 +1097,13 @@ irc_config_server_default_change_cb (const void *pointer, void *data,
irc_server_set_nicks (ptr_server,
weechat_config_string (option));
break;
case IRC_SERVER_OPTION_ANTI_FLOOD:
if (ptr_server->hook_timer_anti_flood)
{
irc_server_outqueue_timer_remove (ptr_server);
irc_server_outqueue_timer_add (ptr_server);
}
break;
case IRC_SERVER_OPTION_AWAY_CHECK:
case IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS:
if (IRC_SERVER_OPTION_INTEGER(
Expand Down Expand Up @@ -1401,6 +1403,13 @@ irc_config_server_change_cb (const void *pointer, void *data,
IRC_SERVER_OPTION_STRING(ptr_server,
IRC_SERVER_OPTION_NICKS));
break;
case IRC_SERVER_OPTION_ANTI_FLOOD:
if (ptr_server->hook_timer_anti_flood)
{
irc_server_outqueue_timer_remove (ptr_server);
irc_server_outqueue_timer_add (ptr_server);
}
break;
case IRC_SERVER_OPTION_AWAY_CHECK:
case IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS:
if (IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AWAY_CHECK) > 0)
Expand Down Expand Up @@ -2503,32 +2512,19 @@ irc_config_server_new_option (struct t_config_file *config_file,
callback_change_data,
NULL, NULL, NULL);
break;
case IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_HIGH:
case IRC_SERVER_OPTION_ANTI_FLOOD:
new_option = weechat_config_new_option (
config_file, section,
option_name, "integer",
N_("anti-flood for high priority queue: number of seconds "
"between two user messages or commands sent to IRC server "
"(0 = no anti-flood)"),
NULL, 0, 60,
default_value, value,
null_value_allowed,
callback_check_value,
callback_check_value_pointer,
callback_check_value_data,
callback_change,
callback_change_pointer,
callback_change_data,
NULL, NULL, NULL);
break;
case IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW:
new_option = weechat_config_new_option (
config_file, section,
option_name, "integer",
N_("anti-flood for low priority queue: number of seconds "
"between two messages sent to IRC server (messages like "
"automatic CTCP replies) (0 = no anti-flood)"),
NULL, 0, 60,
N_("delay in milliseconds between two messages sent to server "
"(anti-flood); 0 = disable anti-flood and always send "
"all messages immediately (not recommended as you can be "
"quickly killed by the server); "
"internally there are queues with different priorities: "
"when connecting to the server all messages are sent "
"immediately and your messages have higher priority than "
"some automatic messages that are sent in background"),
NULL, 0, 60000,
default_value, value,
null_value_allowed,
callback_check_value,
Expand Down Expand Up @@ -3010,6 +3006,8 @@ irc_config_update_cb (const void *pointer, void *data,
int
irc_config_init ()
{
int i;

irc_config_hashtable_display_join_message = weechat_hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
Expand All @@ -3031,6 +3029,11 @@ irc_config_init ()
WEECHAT_HASHTABLE_STRING,
NULL, NULL);

for (i = 0; i < IRC_SERVER_NUM_OPTIONS; i++)
{
irc_config_server_default[i] = NULL;
}

irc_config_file = weechat_config_new (IRC_CONFIG_PRIO_NAME,
&irc_config_reload, NULL, NULL);
if (!irc_config_file)
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/irc/irc-protocol.c
Expand Up @@ -2965,7 +2965,8 @@ IRC_PROTOCOL_CALLBACK(ping)

str_params = irc_protocol_string_params (ctxt->params, 0, ctxt->num_params - 1);

irc_server_sendf (ctxt->server, 0, NULL, "PONG :%s", str_params);
irc_server_sendf (ctxt->server, IRC_SERVER_SEND_OUTQ_PRIO_IMMEDIATE, NULL,
"PONG :%s", str_params);

if (str_params)
free (str_params);
Expand Down Expand Up @@ -7060,7 +7061,7 @@ IRC_PROTOCOL_CALLBACK(432)
irc_server_set_nick (ctxt->server, alternate_nick);

irc_server_sendf (
ctxt->server, 0, NULL,
ctxt->server, IRC_SERVER_SEND_OUTQ_PRIO_IMMEDIATE, NULL,
"NICK %s%s",
(ctxt->server->nick && strchr (ctxt->server->nick, ':')) ? ":" : "",
ctxt->server->nick);
Expand Down Expand Up @@ -7111,7 +7112,7 @@ IRC_PROTOCOL_CALLBACK(433)
irc_server_set_nick (ctxt->server, alternate_nick);

irc_server_sendf (
ctxt->server, 0, NULL,
ctxt->server, IRC_SERVER_SEND_OUTQ_PRIO_IMMEDIATE, NULL,
"NICK %s%s",
(ctxt->server->nick && strchr (ctxt->server->nick, ':')) ? ":" : "",
ctxt->server->nick);
Expand Down Expand Up @@ -7168,7 +7169,7 @@ IRC_PROTOCOL_CALLBACK(437)
irc_server_set_nick (ctxt->server, alternate_nick);

irc_server_sendf (
ctxt->server, 0, NULL,
ctxt->server, IRC_SERVER_SEND_OUTQ_PRIO_IMMEDIATE, NULL,
"NICK %s%s",
(ctxt->server->nick && strchr (ctxt->server->nick, ':')) ? ":" : "",
ctxt->server->nick);
Expand Down

0 comments on commit f7b7e39

Please sign in to comment.