From: Daniel Albers Date: Wed, 2 Dec 2009 00:22:58 +0000 (+0100) Subject: Handle 512 byte limitation sensibly for /join X-Git-Tag: 0.6-beta1~126 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=ca8f178da7892a9b8b16a4c9bac286b15c2a53d5 Handle 512 byte limitation sensibly for /join Fixes #745 --- diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index b8d92e2e..a2feda9a 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -176,12 +176,40 @@ void CoreUserInputHandler::handleJoin(const BufferInfo &bufferInfo, const QStrin if(!network()->isChannelName(chans[i])) chans[i].prepend('#'); } - params[0] = chans.join(","); - if(params.count() > 1) keys = params[1].split(","); - emit putCmd("JOIN", serverEncode(params)); // FIXME handle messages longer than 512 bytes! + + if(params.count() > 1) + keys = params[1].split(","); + + static const char *cmd = "JOIN"; + i = 0; + QStringList joinChans, joinKeys; + int slicesize = chans.count(); + QList encodedParams; + + while(i < chans.count()) { + joinChans.append(chans.at(i)); + if(i < keys.count()) + joinKeys.append(keys.at(i)); + + if(++i == chans.count() || joinChans.count() >= slicesize) { + params[0] = joinChans.join(","); + params[1] = joinKeys.join(","); + encodedParams = serverEncode(params); + if(lastParamOverrun(cmd, encodedParams) == 0) { + emit putCmd(cmd, encodedParams); + } else if(slicesize > 1) { + i -= slicesize; + slicesize /= 2; + } + joinChans.clear(); + joinKeys.clear(); + } + } + i = 0; for(; i < keys.count(); i++) { - if(i >= chans.count()) break; + if(i >= chans.count()) + break; network()->addChannelKey(chans[i], keys[i]); } for(; i < chans.count(); i++) { @@ -413,7 +441,7 @@ void CoreUserInputHandler::putPrivmsg(const QByteArray &target, const QByteArray // returns 0 if the message will not be chopped by the irc server or number of chopped bytes if message is too long int CoreUserInputHandler::lastParamOverrun(const QString &cmd, const QList ¶ms) { - // the server will pass our message trunkated to 512 bytes including CRLF with the following format: + // the server will pass our message truncated to 512 bytes including CRLF with the following format: // ":prefix COMMAND param0 param1 :lastparam" // where prefix = "nickname!user@host" // that means that the last message can be as long as: