summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-03-30 10:40:01 +0200
committerSebastien Helleu <flashcode@flashtux.org>2010-03-30 10:40:01 +0200
commit12afdb29c4cf2b3d2987b8365e60aee95ea4a9c5 (patch)
treed1554d657c2fa6f6efccbc3506691e5dee159636 /src
parent5ff1742c86cc3ae66d6343dcc853c6691561e71e (diff)
downloadweechat-12afdb29c4cf2b3d2987b8365e60aee95ea4a9c5.zip
Fix bug with IRC nicks on reconnection: try all nicks in list, even if nick used was not the first in list of nicks
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-protocol.c64
-rw-r--r--src/plugins/irc/irc-server.c30
-rw-r--r--src/plugins/irc/irc-server.h3
3 files changed, 54 insertions, 43 deletions
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index b795c5803..72f6fc9ac 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -3542,7 +3542,7 @@ IRC_PROTOCOL_CALLBACK(368)
IRC_PROTOCOL_CALLBACK(432)
{
- int i, nick_found, nick_to_use;
+ int nick_index;
struct t_gui_buffer *ptr_buffer;
/*
@@ -3559,24 +3559,13 @@ IRC_PROTOCOL_CALLBACK(432)
ptr_buffer = irc_msgbuffer_get_target_buffer (server, NULL,
command, NULL, NULL);
- nick_found = -1;
- nick_to_use = -1;
- for (i = 0; i < server->nicks_count; i++)
- {
- if (strcmp (server->nick, server->nicks_array[i]) == 0)
- {
- nick_found = i;
- break;
- }
- }
- if (nick_found < 0)
- nick_to_use = 0;
+ nick_index = irc_server_get_nick_index (server);
+ if (nick_index < 0)
+ nick_index = 0;
else
- {
- if (nick_found < server->nicks_count - 1)
- nick_to_use = nick_found + 1;
- }
- if (nick_to_use < 0)
+ nick_index = (nick_index + 1) % server->nicks_count;
+
+ if (nick_index == server->nick_first_tried)
{
weechat_printf (ptr_buffer,
_("%s%s: all declared nicknames are "
@@ -3592,10 +3581,10 @@ IRC_PROTOCOL_CALLBACK(432)
_("%s%s: nickname \"%s\" is invalid, "
"trying nickname #%d (\"%s\")"),
weechat_prefix ("error"),
- IRC_PLUGIN_NAME, server->nick, nick_to_use + 1,
- server->nicks_array[nick_to_use]);
+ IRC_PLUGIN_NAME, server->nick, nick_index + 1,
+ server->nicks_array[nick_index]);
- irc_server_set_nick (server, server->nicks_array[nick_to_use]);
+ irc_server_set_nick (server, server->nicks_array[nick_index]);
irc_server_sendf (server, 0, "NICK %s", server->nick);
}
@@ -3609,7 +3598,7 @@ IRC_PROTOCOL_CALLBACK(432)
IRC_PROTOCOL_CALLBACK(433)
{
- int i, nick_found, nick_to_use;
+ int nick_index;
struct t_gui_buffer *ptr_buffer;
/*
@@ -3621,25 +3610,14 @@ IRC_PROTOCOL_CALLBACK(433)
{
ptr_buffer = irc_msgbuffer_get_target_buffer (server, NULL,
command, NULL, NULL);
-
- nick_found = -1;
- nick_to_use = -1;
- for (i = 0; i < server->nicks_count; i++)
- {
- if (strcmp (server->nick, server->nicks_array[i]) == 0)
- {
- nick_found = i;
- break;
- }
- }
- if (nick_found < 0)
- nick_to_use = 0;
+
+ nick_index = irc_server_get_nick_index (server);
+ if (nick_index < 0)
+ nick_index = 0;
else
- {
- if (nick_found < server->nicks_count - 1)
- nick_to_use = nick_found + 1;
- }
- if (nick_to_use < 0)
+ nick_index = (nick_index + 1) % server->nicks_count;
+
+ if (nick_index == server->nick_first_tried)
{
weechat_printf (ptr_buffer,
_("%s%s: all declared nicknames are "
@@ -3654,10 +3632,10 @@ IRC_PROTOCOL_CALLBACK(433)
weechat_printf (ptr_buffer,
_("%s: nickname \"%s\" is already in use, "
"trying nickname #%d (\"%s\")"),
- IRC_PLUGIN_NAME, server->nick,
- nick_to_use + 1, server->nicks_array[nick_to_use]);
+ IRC_PLUGIN_NAME, server->nick, nick_index + 1,
+ server->nicks_array[nick_index]);
- irc_server_set_nick (server, server->nicks_array[nick_to_use]);
+ irc_server_set_nick (server, server->nicks_array[nick_index]);
irc_server_sendf (server, 0, "NICK %s", server->nick);
}
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 4d269fc89..859a5ef07 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -273,6 +273,32 @@ irc_server_set_nick (struct t_irc_server *server, const char *nick)
}
/*
+ * irc_server_get_nick_index: get index of nick in array "nicks_array"
+ * return -1 if nick is not set or not found in
+ * "nicks_array"
+ */
+
+int
+irc_server_get_nick_index (struct t_irc_server *server)
+{
+ int i;
+
+ if (!server->nick)
+ return -1;
+
+ for (i = 0; i < server->nicks_count; i++)
+ {
+ if (strcmp (server->nick, server->nicks_array[i]) == 0)
+ {
+ return i;
+ }
+ }
+
+ /* nick not found */
+ return -1;
+}
+
+/*
* irc_server_alloc: allocate a new server and add it to the servers queue
*/
@@ -327,6 +353,7 @@ irc_server_alloc (const char *name)
new_server->unterminated_message = NULL;
new_server->nicks_count = 0;
new_server->nicks_array = NULL;
+ new_server->nick_first_tried = 0;
new_server->nick = NULL;
new_server->nick_modes = NULL;
new_server->prefix = NULL;
@@ -2022,7 +2049,10 @@ irc_server_login (struct t_irc_server *server)
irc_server_set_nick (server,
(server->nicks_array) ?
server->nicks_array[0] : "weechat");
+ server->nick_first_tried = 0;
}
+ else
+ server->nick_first_tried = irc_server_get_nick_index (server);
if (irc_server_sasl_enabled (server))
{
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index 32fb57aa2..c2c34dae1 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -133,6 +133,8 @@ struct t_irc_server
char *unterminated_message; /* beginning of a message in input buf */
int nicks_count; /* number of nicknames */
char **nicks_array; /* nicknames (after split) */
+ int nick_first_tried; /* first nick tried in list of nicks */
+ /* when (re-)connecting to server */
char *nick; /* current nickname */
char *nick_modes; /* nick modes */
char *prefix; /* nick prefix allowed (from msg 005) */
@@ -186,6 +188,7 @@ extern void irc_server_set_addresses (struct t_irc_server *server,
const char *addresses);
extern void irc_server_set_nicks (struct t_irc_server *server, const char *nicks);
extern void irc_server_set_nick (struct t_irc_server *server, const char *nick);
+extern int irc_server_get_nick_index (struct t_irc_server *server);
extern struct t_irc_server *irc_server_alloc (const char *name);
extern int irc_server_alloc_with_url (const char *irc_url);
extern void irc_server_apply_command_line_options (struct t_irc_server *server,