summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-channel.c61
-rw-r--r--src/plugins/irc/irc-channel.h4
-rw-r--r--src/plugins/irc/irc-config.c14
-rw-r--r--src/plugins/irc/irc-display.c9
-rw-r--r--src/plugins/irc/irc-protocol.c17
-rw-r--r--src/plugins/irc/irc-server.c23
-rw-r--r--src/plugins/irc/irc-server.h7
7 files changed, 124 insertions, 11 deletions
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c
index 822259159..ce6922f03 100644
--- a/src/plugins/irc/irc-channel.c
+++ b/src/plugins/irc/irc-channel.c
@@ -29,6 +29,7 @@
#include "irc.h"
#include "irc-channel.h"
#include "irc-buffer.h"
+#include "irc-command.h"
#include "irc-config.h"
#include "irc-nick.h"
#include "irc-server.h"
@@ -244,6 +245,7 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
new_channel->display_creation_date = 0;
new_channel->nick_completion_reset = 0;
new_channel->pv_remote_nick_color = NULL;
+ new_channel->hook_autorejoin = NULL;
new_channel->nicks_count = 0;
new_channel->nicks = NULL;
new_channel->last_nick = NULL;
@@ -616,6 +618,62 @@ irc_channel_nick_speaking_time_rename (struct t_irc_channel *channel,
}
/*
+ * irc_channel_rejoin: rejoin a channel (for example after kick)
+ */
+
+void
+irc_channel_rejoin (struct t_irc_server *server, struct t_irc_channel *channel)
+{
+ char join_args[256];
+
+ snprintf (join_args, sizeof (join_args), "%s%s%s",
+ channel->name,
+ (channel->key) ? " " : "",
+ (channel->key) ? channel->key : "");
+
+ irc_command_join_server (server, join_args);
+}
+
+/*
+ * irc_channel_autorejoin_cb: callback for autorejoin on a channel
+ */
+
+int
+irc_channel_autorejoin_cb (void *data, int remaining_calls)
+{
+ struct t_irc_server *ptr_server, *ptr_server_found;
+ struct t_irc_channel *ptr_channel_arg, *ptr_channel;
+
+ /* make C compiler happy */
+ (void) remaining_calls;
+
+ ptr_channel_arg = (struct t_irc_channel *)data;
+
+ ptr_server_found = NULL;
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ for (ptr_channel = ptr_server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if (ptr_channel == ptr_channel_arg)
+ {
+ ptr_server_found = ptr_server;
+ break;
+ }
+ }
+ }
+
+ if (ptr_server_found && (ptr_channel_arg->hook_autorejoin))
+ {
+ irc_channel_rejoin (ptr_server_found, ptr_channel_arg);
+ ptr_channel_arg->hook_autorejoin = NULL;
+ }
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* irc_channel_free: free a channel and remove it from channels list
*/
@@ -655,6 +713,8 @@ irc_channel_free (struct t_irc_server *server, struct t_irc_channel *channel)
free (channel->away_message);
if (channel->pv_remote_nick_color)
free (channel->pv_remote_nick_color);
+ if (channel->hook_autorejoin)
+ weechat_unhook(channel->hook_autorejoin);
if (channel->nicks_speaking[0])
weechat_list_free (channel->nicks_speaking[0]);
if (channel->nicks_speaking[1])
@@ -805,6 +865,7 @@ irc_channel_print_log (struct t_irc_channel *channel)
weechat_log_printf (" display_creation_date. . : %d", channel->display_creation_date);
weechat_log_printf (" nick_completion_reset. . : %d", channel->nick_completion_reset);
weechat_log_printf (" pv_remote_nick_color . . : '%s'", channel->pv_remote_nick_color);
+ weechat_log_printf (" hook_autorejoin. . . . . : 0x%lx", channel->hook_autorejoin);
weechat_log_printf (" nicks_count. . . . . . . : %d", channel->nicks_count);
weechat_log_printf (" nicks. . . . . . . . . . : 0x%lx", channel->nicks);
weechat_log_printf (" last_nick. . . . . . . . : 0x%lx", channel->last_nick);
diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h
index 031625c58..cd9380dcc 100644
--- a/src/plugins/irc/irc-channel.h
+++ b/src/plugins/irc/irc-channel.h
@@ -54,6 +54,7 @@ struct t_irc_channel
int nick_completion_reset; /* 1 for resetting nick completion */
/* there was some join/part on chan */
char *pv_remote_nick_color; /* color for remote nick in pv */
+ struct t_hook *hook_autorejoin; /* this time+delay = autorejoin time */
int nicks_count; /* # nicks on channel (0 if pv) */
struct t_irc_nick *nicks; /* nicks on the channel */
struct t_irc_nick *last_nick; /* last nick on the channel */
@@ -106,6 +107,9 @@ extern void irc_channel_nick_speaking_time_add (struct t_irc_channel *channel,
extern void irc_channel_nick_speaking_time_rename (struct t_irc_channel *channel,
const char *old_nick,
const char *new_nick);
+extern void irc_channel_rejoin (struct t_irc_server *server,
+ struct t_irc_channel *channel);
+extern int irc_channel_autorejoin_cb (void *data, int remaining_calls);
extern int irc_channel_add_to_infolist (struct t_infolist *infolist,
struct t_irc_channel *channel);
extern void irc_channel_print_log (struct t_irc_channel *channel);
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index 0ea853566..89423d9b1 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -985,7 +985,7 @@ irc_config_server_new_option (struct t_config_file *config_file,
new_option = weechat_config_new_option (
config_file, section,
option_name, "boolean",
- N_("automatically rejoin channels when kicked"),
+ N_("automatically rejoin channels after kick"),
NULL, 0, 0,
default_value, value,
null_value_allowed,
@@ -993,6 +993,18 @@ irc_config_server_new_option (struct t_config_file *config_file,
callback_change, callback_change_data,
NULL, NULL);
break;
+ case IRC_SERVER_OPTION_AUTOREJOIN_DELAY:
+ new_option = weechat_config_new_option (
+ config_file, section,
+ option_name, "integer",
+ N_("delay (in seconds) before autorejoin (after kick)"),
+ NULL, 0, 3600*24,
+ default_value, value,
+ null_value_allowed,
+ NULL, NULL,
+ callback_change, callback_change_data,
+ NULL, NULL);
+ break;
case IRC_SERVER_NUM_OPTIONS:
break;
}
diff --git a/src/plugins/irc/irc-display.c b/src/plugins/irc/irc-display.c
index ce84997b7..bcf3ed3c6 100644
--- a/src/plugins/irc/irc-display.c
+++ b/src/plugins/irc/irc-display.c
@@ -337,6 +337,15 @@ irc_display_server (struct t_irc_server *server, int with_detail)
IRC_COLOR_CHAT_VALUE,
weechat_config_boolean (server->options[IRC_SERVER_OPTION_AUTOREJOIN]) ?
_("on") : _("off"));
+ if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_AUTOREJOIN_DELAY]))
+ weechat_printf (NULL, " autorejoin_delay . . : (%d %s)",
+ IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOREJOIN_DELAY),
+ NG_("second", "seconds", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOREJOIN_DELAY)));
+ else
+ weechat_printf (NULL, " autorejoin_delay . . : %s%d %s",
+ IRC_COLOR_CHAT_VALUE,
+ weechat_config_integer (server->options[IRC_SERVER_OPTION_AUTOREJOIN_DELAY]),
+ NG_("second", "seconds", weechat_config_integer (server->options[IRC_SERVER_OPTION_AUTOREJOIN_DELAY])));
}
else
{
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 05adc7b95..087d03b02 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -464,7 +464,22 @@ irc_protocol_cmd_kick (struct t_irc_server *server, const char *command,
more */
irc_nick_free_all (ptr_channel);
if (IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOREJOIN))
- irc_command_join_server (server, ptr_channel->name);
+ {
+ if (IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOREJOIN_DELAY) == 0)
+ {
+ /* immediately rejoin if delay is 0 */
+ irc_channel_rejoin (server, ptr_channel);
+ }
+ else
+ {
+ /* rejoin channel later, according to delay */
+ ptr_channel->hook_autorejoin =
+ weechat_hook_timer (IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOREJOIN_DELAY) * 1000,
+ 0, 1,
+ &irc_channel_autorejoin_cb,
+ ptr_channel);
+ }
+ }
}
else
{
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 669c4053d..aeb84b619 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -58,15 +58,17 @@ struct t_irc_message *irc_recv_msgq = NULL;
struct t_irc_message *irc_msgq_last_msg = NULL;
char *irc_server_option_string[IRC_SERVER_NUM_OPTIONS] =
-{ "addresses", "proxy", "ipv6", "ssl", "password", "autoconnect",
- "autoreconnect", "autoreconnect_delay", "nicks", "username", "realname",
- "local_hostname", "command", "command_delay", "autojoin", "autorejoin",
- "ssl_cert", "ssl_dhkey_size", "ssl_verify",
+{ "addresses", "proxy", "ipv6", "ssl", "ssl_cert", "ssl_dhkey_size",
+ "ssl_verify", "password", "autoconnect", "autoreconnect",
+ "autoreconnect_delay", "nicks", "username", "realname", "local_hostname",
+ "command", "command_delay", "autojoin", "autorejoin", "autorejoin_delay",
};
char *irc_server_option_default[IRC_SERVER_NUM_OPTIONS] =
-{ "", "", "off", "off", "", "off", "on", "30", "",
- "", "", "", "", "0", "", "off", "", "2048", "on",
+{ "", "", "off", "off", "", "2048",
+ "on", "", "off", "on",
+ "30", "", "", "", "",
+ "", "0", "", "off", "30",
};
@@ -3253,6 +3255,9 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
if (!weechat_infolist_new_var_integer (ptr_item, "autorejoin",
IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTOREJOIN)))
return 0;
+ if (!weechat_infolist_new_var_integer (ptr_item, "autorejoin_delay",
+ IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOREJOIN_DELAY)))
+ return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "temp_server", server->temp_server))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "index_current_address", server->index_current_address))
@@ -3437,6 +3442,12 @@ irc_server_print_log ()
weechat_log_printf (" autorejoin . . . . . : %s",
weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN]) ?
"on" : "off");
+ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN_DELAY]))
+ weechat_log_printf (" autorejoin_delay . . : null (%d)",
+ IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTOREJOIN_DELAY));
+ else
+ weechat_log_printf (" autorejoin_delay . . : %d",
+ weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AUTOREJOIN_DELAY]));
weechat_log_printf (" temp_server. . . . . : %d", ptr_server->temp_server);
weechat_log_printf (" reloading_from_config: %d", ptr_server->reloaded_from_config);
weechat_log_printf (" reloaded_from_config : %d", ptr_server->reloaded_from_config);
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index 4b456567a..053107bea 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -37,6 +37,9 @@ enum t_irc_server_option
IRC_SERVER_OPTION_PROXY, /* proxy used for server (optional) */
IRC_SERVER_OPTION_IPV6, /* use IPv6 protocol */
IRC_SERVER_OPTION_SSL, /* SSL protocol */
+ IRC_SERVER_OPTION_SSL_CERT, /* client ssl certificate file */
+ IRC_SERVER_OPTION_SSL_DHKEY_SIZE, /* Diffie Hellman key size */
+ IRC_SERVER_OPTION_SSL_VERIFY, /* check if the connection is trusted */
IRC_SERVER_OPTION_PASSWORD, /* password for server */
IRC_SERVER_OPTION_AUTOCONNECT, /* autoconnect to server at startup */
IRC_SERVER_OPTION_AUTORECONNECT, /* autoreconnect when disconnected */
@@ -49,9 +52,7 @@ enum t_irc_server_option
IRC_SERVER_OPTION_COMMAND_DELAY, /* delay after execution of command */
IRC_SERVER_OPTION_AUTOJOIN, /* channels to automatically join */
IRC_SERVER_OPTION_AUTOREJOIN, /* auto rejoin channels when kicked */
- IRC_SERVER_OPTION_SSL_CERT, /* client ssl certificate file */
- IRC_SERVER_OPTION_SSL_DHKEY_SIZE, /* Diffie Hellman key size */
- IRC_SERVER_OPTION_SSL_VERIFY, /* check if the connection is trusted */
+ IRC_SERVER_OPTION_AUTOREJOIN_DELAY, /* delay before auto rejoin */
/* number of server options */
IRC_SERVER_NUM_OPTIONS,
};