From c79e690e885af85e62653560b3a6ff93f6e34277 Mon Sep 17 00:00:00 2001 From: Valentin Batz Date: Wed, 11 May 2005 18:52:12 +0000 Subject: [PATCH] Fixed a bug where the channel list to join/rejoin on reconnect gets too long, not all channels will be joined. The channel list is splitted into multiple lines right now when it's too long. (http://bugs.irssi.org/index.php?id=108&do=details) git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3746 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/irc/core/irc-channels.c | 92 +++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/src/irc/core/irc-channels.c b/src/irc/core/irc-channels.c index b4ec55a2..431f2458 100644 --- a/src/irc/core/irc-channels.c +++ b/src/irc/core/irc-channels.c @@ -70,9 +70,9 @@ static void irc_channels_join(IRC_SERVER_REC *server, const char *data, IRC_CHANNEL_REC *chanrec; GString *outchans, *outkeys; char *channels, *keys, *key; - char **chanlist, **keylist, **tmp, **tmpkey, *channel, *channame; + char **chanlist, **keylist, **tmp, **tmpkey, **tmpstr, *channel, *channame; void *free_arg; - int use_keys; + int use_keys, cmdlen; g_return_if_fail(data != NULL); g_return_if_fail(IS_IRC_SERVER(server) && server->connected); @@ -90,44 +90,68 @@ static void irc_channels_join(IRC_SERVER_REC *server, const char *data, use_keys = *keys != '\0'; tmpkey = keylist; - for (tmp = chanlist; *tmp != NULL; tmp++) { - channel = ischannel(**tmp) ? g_strdup(*tmp) : + tmp = chanlist; + for (;; tmp++) { + if (*tmp != NULL) { + channel = ischannel(**tmp) ? g_strdup(*tmp) : g_strdup_printf("#%s", *tmp); - chanrec = irc_channel_find(server, channel); - if (chanrec == NULL) { - schannel = channel_setup_find(channel, server->connrec->chatnet); + chanrec = irc_channel_find(server, channel); + if (chanrec == NULL) { + schannel = channel_setup_find(channel, server->connrec->chatnet); - g_string_sprintfa(outchans, "%s,", channel); - if (*tmpkey != NULL && **tmpkey != '\0') - key = *tmpkey; - else if (schannel != NULL && schannel->password != NULL) { - /* get password from setup record */ - use_keys = TRUE; - key = schannel->password; - } else key = NULL; + g_string_sprintfa(outchans, "%s,", channel); + if (*tmpkey != NULL && **tmpkey != '\0') + key = *tmpkey; + else if (schannel != NULL && schannel->password != NULL) { + /* get password from setup record */ + use_keys = TRUE; + key = schannel->password; + } else key = NULL; + + g_string_sprintfa(outkeys, "%s,", get_join_key(key)); + channame = channel + (channel[0] == '!' && + channel[1] == '!'); + chanrec = irc_channel_create(server, channame, NULL, + automatic); + if (key != NULL) chanrec->key = g_strdup(key); + } + g_free(channel); - g_string_sprintfa(outkeys, "%s,", get_join_key(key)); - channame = channel + (channel[0] == '!' && - channel[1] == '!'); - chanrec = irc_channel_create(server, channame, NULL, - automatic); - if (key != NULL) chanrec->key = g_strdup(key); + if (*tmpkey != NULL) + tmpkey++; + + tmpstr = tmp; + tmpstr++; + cmdlen = outchans->len-1; + + if (use_keys) + cmdlen += outkeys->len; + if (*tmpstr != NULL) + cmdlen += ischannel(**tmpstr) ? strlen(*tmpstr) : + strlen(*tmpstr)+1; + if (*tmpkey != NULL) + cmdlen += strlen(*tmpkey); + + /* don't try to send too long lines + make sure it's not longer than 510 + so 510 - strlen("JOIN ") = 505 */ + if (cmdlen < 505) + continue; } - g_free(channel); - - if (*tmpkey != NULL) - tmpkey++; + if (outchans->len > 0) { + g_string_truncate(outchans, outchans->len-1); + g_string_truncate(outkeys, outkeys->len-1); + irc_send_cmdv(IRC_SERVER(server), + use_keys ? "JOIN %s %s" : "JOIN %s", + outchans->str, outkeys->str); + } + cmdlen = 0; + g_string_truncate(outchans,0); + g_string_truncate(outkeys,0); + if (*tmp == NULL || tmp[1] == NULL) + break; } - - if (outchans->len > 0) { - g_string_truncate(outchans, outchans->len-1); - g_string_truncate(outkeys, outkeys->len-1); - irc_send_cmdv(IRC_SERVER(server), - use_keys ? "JOIN %s %s" : "JOIN %s", - outchans->str, outkeys->str); - } - g_string_free(outchans, TRUE); g_string_free(outkeys, TRUE);