irc: send all channels in a single JOIN command when reconnecting to the server (closes #1551)

This commit is contained in:
Sébastien Helleu 2020-08-05 20:05:36 +02:00
parent 36c55f6973
commit 0cc5df6649
8 changed files with 1189 additions and 22 deletions

View File

@ -27,6 +27,7 @@ New features::
Bug fixes::
* core: do not add line with highlight and tag "notify_none" to hotlist (issue #1529)
* irc: send all channels in a single JOIN command when reconnecting to the server (issue #1551)
* trigger: fix recursive calls to triggers using regex (issue #1546)
* trigger: add `${tg_tags} !!- ,notify_none,` in conditions of default trigger "beep" (issue #1529)

View File

@ -419,6 +419,7 @@ WeeChat "core" is located in following directories:
|             test-irc-mode.cpp | Tests: IRC modes.
|             test-irc-nick.cpp | Tests: IRC nicks.
|             test-irc-protocol.cpp | Tests: IRC protocol.
|             test-irc-server.cpp | Tests: IRC server.
|          relay/ | Root of unit tests for Relay plugin.
|             test-relay-auth.cpp | Tests: clients authentication.

View File

@ -421,6 +421,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants :
|             test-irc-mode.cpp | Tests : modes IRC.
|             test-irc-nick.cpp | Tests : pseudos IRC.
|             test-irc-protocol.cpp | Tests : protocole IRC.
|             test-irc-server.cpp | Tests : serveur IRC.
|          relay/ | Racine des tests unitaires pour l'extension Relay.
|             test-relay-auth.cpp | Tests : authentification des clients.
|===

View File

@ -439,6 +439,8 @@ WeeChat "core" は以下のディレクトリに配置されています:
|             test-irc-nick.cpp | Tests: IRC nicks.
|             test-irc-protocol.cpp | テスト: IRC プロトコル
// TRANSLATION MISSING
|             test-irc-server.cpp | Tests: IRC server.
// TRANSLATION MISSING
|          relay/ | Root of unit tests for Relay plugin.
// TRANSLATION MISSING
|             test-relay-auth.cpp | Tests: clients authentication.

View File

@ -5310,6 +5310,95 @@ irc_server_autojoin_create_buffers (struct t_irc_server *server)
free (autojoin);
}
/*
* Build the arguments for JOIN command using channels in server, only if the
* channel is not in "part" state (/part command issued).
*
* The arguments have the following format, where keys are optional (this is
* the syntax of JOIN command in IRC protocol):
*
* #channel1,#channel2,#channel3 key1,key2
*
* Note: result must be freed after use.
*/
char *
irc_server_build_autojoin (struct t_irc_server *server)
{
struct t_irc_channel *ptr_channel;
char **channels_with_key, **channels_others, **keys;
channels_with_key = NULL;
channels_others = NULL;
keys = NULL;
channels_with_key = weechat_string_dyn_alloc (1024);
if (!channels_with_key)
goto error;
channels_others = weechat_string_dyn_alloc (1024);
if (!channels_others)
goto error;
keys = weechat_string_dyn_alloc (1024);
if (!keys)
goto error;
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
if ((ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
&& !ptr_channel->part)
{
if (ptr_channel->key)
{
/* add channel with key and the key */
if (*channels_with_key[0])
weechat_string_dyn_concat (channels_with_key, ",");
weechat_string_dyn_concat (channels_with_key, ptr_channel->name);
if (*keys[0])
weechat_string_dyn_concat (keys, ",");
weechat_string_dyn_concat (keys, ptr_channel->key);
}
else
{
/* add channel without key */
if (*channels_others[0])
weechat_string_dyn_concat (channels_others, ",");
weechat_string_dyn_concat (channels_others, ptr_channel->name);
}
}
}
/*
* concatenate channels_with_key + channels_others + keys
* into channels_with_key
*/
if (*channels_others[0])
{
if (*channels_with_key[0])
weechat_string_dyn_concat (channels_with_key, ",");
weechat_string_dyn_concat (channels_with_key, *channels_others);
}
if (*keys[0])
{
weechat_string_dyn_concat (channels_with_key, " ");
weechat_string_dyn_concat (channels_with_key, *keys);
}
weechat_string_dyn_free (channels_others, 1);
weechat_string_dyn_free (keys, 1);
return weechat_string_dyn_free (channels_with_key, 0);
error:
if (channels_with_key)
weechat_string_dyn_free (channels_with_key, 1);
if (channels_others)
weechat_string_dyn_free (channels_others, 1);
if (keys)
weechat_string_dyn_free (keys, 1);
return NULL;
}
/*
* Autojoins (or auto-rejoins) channels.
*/
@ -5317,33 +5406,19 @@ irc_server_autojoin_create_buffers (struct t_irc_server *server)
void
irc_server_autojoin_channels (struct t_irc_server *server)
{
struct t_irc_channel *ptr_channel;
char *autojoin;
/* auto-join after disconnection (only rejoins opened channels) */
if (!server->disable_autojoin && server->reconnect_join && server->channels)
{
for (ptr_channel = server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
autojoin = irc_server_build_autojoin (server);
if (autojoin)
{
if ((ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
&& !ptr_channel->part)
{
if (ptr_channel->key)
{
irc_server_sendf (server,
IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
"JOIN %s %s",
ptr_channel->name, ptr_channel->key);
}
else
{
irc_server_sendf (server,
IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
"JOIN %s",
ptr_channel->name);
}
}
irc_server_sendf (server,
IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
"JOIN %s",
autojoin);
free (autojoin);
}
server->reconnect_join = 0;
}

View File

@ -58,6 +58,7 @@ if(ENABLE_IRC)
unit/plugins/irc/test-irc-mode.cpp
unit/plugins/irc/test-irc-nick.cpp
unit/plugins/irc/test-irc-protocol.cpp
unit/plugins/irc/test-irc-server.cpp
)
endif()

View File

@ -72,7 +72,8 @@ tests_irc = unit/plugins/irc/test-irc-channel.cpp \
unit/plugins/irc/test-irc-message.cpp \
unit/plugins/irc/test-irc-mode.cpp \
unit/plugins/irc/test-irc-nick.cpp \
unit/plugins/irc/test-irc-protocol.cpp
unit/plugins/irc/test-irc-protocol.cpp \
unit/plugins/irc/test-irc-server.cpp
endif
if PLUGIN_RELAY

File diff suppressed because it is too large Load Diff