1 /***************************************************************************
2 * Copyright (C) 2005-2010 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #include "coreuserinputhandler.h"
24 #include "ctcpparser.h"
32 CoreUserInputHandler::CoreUserInputHandler(CoreNetwork *parent)
33 : CoreBasicHandler(parent)
37 void CoreUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const QString &msg) {
41 AliasManager::CommandList list = coreSession()->aliasManager().processInput(bufferInfo, msg);
43 for(int i = 0; i < list.count(); i++) {
44 QString cmd = list.at(i).second.section(' ', 0, 0).remove(0, 1).toUpper();
45 QString payload = list.at(i).second.section(' ', 1);
46 handle(cmd, Q_ARG(BufferInfo, list.at(i).first), Q_ARG(QString, payload));
50 // ====================
52 // ====================
53 void CoreUserInputHandler::handleAway(const BufferInfo &bufferInfo, const QString &msg) {
55 if(msg.startsWith("-all")) {
56 if(msg.length() == 4) {
57 coreSession()->globalAway();
60 Q_ASSERT(msg.length() > 4);
62 coreSession()->globalAway(msg.mid(5));
69 void CoreUserInputHandler::issueAway(const QString &msg, bool autoCheck) {
70 QString awayMsg = msg;
71 IrcUser *me = network()->me();
73 // if there is no message supplied we have to check if we are already away or not
74 if(autoCheck && msg.isEmpty()) {
75 if(me && !me->isAway()) {
76 Identity *identity = network()->identityPtr();
78 awayMsg = identity->awayReason();
80 if(awayMsg.isEmpty()) {
86 me->setAwayMessage(awayMsg);
88 putCmd("AWAY", serverEncode(awayMsg));
91 void CoreUserInputHandler::handleBan(const BufferInfo &bufferInfo, const QString &msg) {
92 banOrUnban(bufferInfo, msg, true);
95 void CoreUserInputHandler::handleUnban(const BufferInfo &bufferInfo, const QString &msg) {
96 banOrUnban(bufferInfo, msg, false);
99 void CoreUserInputHandler::banOrUnban(const BufferInfo &bufferInfo, const QString &msg, bool ban) {
103 QStringList params = msg.split(" ");
105 if(!params.isEmpty() && isChannelName(params[0])) {
106 banChannel = params.takeFirst();
107 } else if(bufferInfo.type() == BufferInfo::ChannelBuffer) {
108 banChannel = bufferInfo.bufferName();
110 emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("Error: channel unknown in command: /BAN %1").arg(msg));
114 if(!params.isEmpty() && !params.contains("!") && network()->ircUser(params[0])) {
115 IrcUser *ircuser = network()->ircUser(params[0]);
116 // generalizedHost changes <nick> to *!ident@*.sld.tld.
117 QString generalizedHost = ircuser->host();
118 if(generalizedHost.isEmpty()) {
119 emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("Error: host unknown in command: /BAN %1").arg(msg));
123 static QRegExp ipAddress("\\d+\\.\\d+\\.\\d+\\.\\d+");
124 if(ipAddress.exactMatch(generalizedHost)) {
125 int lastDotPos = generalizedHost.lastIndexOf('.') + 1;
126 generalizedHost.replace(lastDotPos, generalizedHost.length() - lastDotPos, '*');
127 } else if(generalizedHost.lastIndexOf(".") != -1 && generalizedHost.lastIndexOf(".", generalizedHost.lastIndexOf(".")-1) != -1) {
128 int secondLastPeriodPosition = generalizedHost.lastIndexOf(".", generalizedHost.lastIndexOf(".")-1);
129 generalizedHost.replace(0, secondLastPeriodPosition, "*");
131 banUser = QString("*!%1@%2").arg(ircuser->user(), generalizedHost);
133 banUser = params.join(" ");
136 QString banMode = ban ? "+b" : "-b";
137 QString banMsg = QString("MODE %1 %2 %3").arg(banChannel, banMode, banUser);
138 emit putRawLine(serverEncode(banMsg));
141 void CoreUserInputHandler::handleCtcp(const BufferInfo &bufferInfo, const QString &msg) {
144 QString nick = msg.section(' ', 0, 0);
145 QString ctcpTag = msg.section(' ', 1, 1).toUpper();
146 if(ctcpTag.isEmpty())
149 QString message = msg.section(' ', 2);
150 QString verboseMessage = tr("sending CTCP-%1 request to %2").arg(ctcpTag).arg(nick);
152 if(ctcpTag == "PING") {
153 uint now = QDateTime::currentDateTime().toTime_t();
154 message = QString::number(now);
157 // FIXME make this a proper event
158 coreNetwork()->coreSession()->ctcpParser()->query(coreNetwork(), nick, ctcpTag, message);
159 emit displayMsg(Message::Action, BufferInfo::StatusBuffer, "", verboseMessage, network()->myNick());
162 void CoreUserInputHandler::handleDelkey(const BufferInfo &bufferInfo, const QString &msg) {
164 if(!bufferInfo.isValid())
167 if(!Cipher::neededFeaturesAvailable())
170 QStringList parms = msg.split(' ', QString::SkipEmptyParts);
172 if(parms.isEmpty() && !bufferInfo.bufferName().isEmpty())
173 parms.prepend(bufferInfo.bufferName());
175 if(parms.isEmpty()) {
176 emit displayMsg(Message::Info, bufferInfo.bufferName(), "",
177 tr("[usage] /delkey <nick|channel> deletes the encryption key for nick or channel or just /delkey when in a channel or query."));
181 QString target = parms.at(0);
183 if(network()->cipherKey(target).isEmpty()) {
184 emit displayMsg(Message::Info, bufferInfo.bufferName(), tr("No key has been set for %1.").arg(target));
188 network()->setCipherKey(target, QByteArray());
190 if(network()->isChannelName(target) && network()->channels().contains(target)) {
191 qobject_cast<CoreIrcChannel *>(network()->ircChannel(target))->setEncrypted(false);
193 else if(network()->nicks().contains(target)) {
194 qobject_cast<CoreIrcUser *>(network()->ircUser(target))->setEncrypted(false);
197 emit displayMsg(Message::Info, bufferInfo.bufferName(), tr("The key for %1 has been deleted.").arg(target));
201 emit displayMsg(Message::Error, bufferInfo.bufferName(), "", tr("Error: Setting an encryption key requires Quassel to have been built "
202 "with support for the Qt Cryptographic Architecture (QCA2) library. "
203 "Contact your distributor about a Quassel package with QCA2 "
204 "support, or rebuild Quassel with QCA2 present."));
208 void CoreUserInputHandler::handleDeop(const BufferInfo &bufferInfo, const QString &msg) {
209 QStringList nicks = msg.split(' ', QString::SkipEmptyParts);
210 QString m = "-"; for(int i = 0; i < nicks.count(); i++) m += 'o';
212 params << bufferInfo.bufferName() << m << nicks;
213 emit putCmd("MODE", serverEncode(params));
216 void CoreUserInputHandler::handleDevoice(const BufferInfo &bufferInfo, const QString &msg) {
217 QStringList nicks = msg.split(' ', QString::SkipEmptyParts);
218 QString m = "-"; for(int i = 0; i < nicks.count(); i++) m += 'v';
220 params << bufferInfo.bufferName() << m << nicks;
221 emit putCmd("MODE", serverEncode(params));
224 void CoreUserInputHandler::handleInvite(const BufferInfo &bufferInfo, const QString &msg) {
226 params << msg << bufferInfo.bufferName();
227 emit putCmd("INVITE", serverEncode(params));
230 void CoreUserInputHandler::handleJoin(const BufferInfo &bufferInfo, const QString &msg) {
231 Q_UNUSED(bufferInfo);
233 // trim spaces before chans or keys
234 QString sane_msg = msg;
235 sane_msg.replace(QRegExp(", +"), ",");
236 QStringList params = sane_msg.trimmed().split(" ");
238 QStringList chans = params[0].split(",", QString::SkipEmptyParts);
240 if(params.count() > 1)
241 keys = params[1].split(",");
244 for(i = 0; i < chans.count(); i++) {
245 if(!network()->isChannelName(chans[i]))
246 chans[i].prepend('#');
248 if(i < keys.count()) {
249 network()->addChannelKey(chans[i], keys[i]);
251 network()->removeChannelKey(chans[i]);
255 static const char *cmd = "JOIN";
257 QStringList joinChans, joinKeys;
258 int slicesize = chans.count();
259 QList<QByteArray> encodedParams;
261 // go through all to-be-joined channels and (re)build the join list
262 while(i < chans.count()) {
263 joinChans.append(chans.at(i));
265 joinKeys.append(keys.at(i));
267 // if the channel list we built so far either contains all requested channels or exceeds
268 // the desired amount of channels in this slice, try to send what we have so far
269 if(++i == chans.count() || joinChans.count() >= slicesize) {
271 params.append(joinChans.join(","));
272 params.append(joinKeys.join(","));
273 encodedParams = serverEncode(params);
274 // check if it fits in one command
275 if(lastParamOverrun(cmd, encodedParams) == 0) {
276 emit putCmd(cmd, encodedParams);
277 } else if(slicesize > 1) {
278 // back to start of slice, try again with half the amount of channels
288 void CoreUserInputHandler::handleKick(const BufferInfo &bufferInfo, const QString &msg) {
289 QString nick = msg.section(' ', 0, 0, QString::SectionSkipEmpty);
290 QString reason = msg.section(' ', 1, -1, QString::SectionSkipEmpty).trimmed();
292 reason = network()->identityPtr()->kickReason();
294 QList<QByteArray> params;
295 params << serverEncode(bufferInfo.bufferName()) << serverEncode(nick) << channelEncode(bufferInfo.bufferName(), reason);
296 emit putCmd("KICK", params);
299 void CoreUserInputHandler::handleKill(const BufferInfo &bufferInfo, const QString &msg) {
301 QString nick = msg.section(' ', 0, 0, QString::SectionSkipEmpty);
302 QString pass = msg.section(' ', 1, -1, QString::SectionSkipEmpty);
303 QList<QByteArray> params;
304 params << serverEncode(nick) << serverEncode(pass);
305 emit putCmd("KILL", params);
309 void CoreUserInputHandler::handleList(const BufferInfo &bufferInfo, const QString &msg) {
311 emit putCmd("LIST", serverEncode(msg.split(' ', QString::SkipEmptyParts)));
314 void CoreUserInputHandler::handleMe(const BufferInfo &bufferInfo, const QString &msg) {
315 if(bufferInfo.bufferName().isEmpty()) return; // server buffer
316 // FIXME make this a proper event
317 coreNetwork()->coreSession()->ctcpParser()->query(coreNetwork(), bufferInfo.bufferName(), "ACTION", msg);
318 emit displayMsg(Message::Action, bufferInfo.type(), bufferInfo.bufferName(), msg, network()->myNick(), Message::Self);
321 void CoreUserInputHandler::handleMode(const BufferInfo &bufferInfo, const QString &msg) {
324 QStringList params = msg.split(' ', QString::SkipEmptyParts);
325 // if the first argument is neither a channel nor us (user modes are only to oneself) the current buffer is assumed to be the target
326 if(!params.isEmpty()) {
327 if(!network()->isChannelName(params[0]) && !network()->isMyNick(params[0]))
328 params.prepend(bufferInfo.bufferName());
329 if(network()->isMyNick(params[0]) && params.count() == 2)
330 network()->updateIssuedModes(params[1]);
331 if(params[0] == "-reset" && params.count() == 1) {
332 // FIXME: give feedback to the user (I don't want to add new strings right now)
333 network()->resetPersistentModes();
338 // TODO handle correct encoding for buffer modes (channelEncode())
339 emit putCmd("MODE", serverEncode(params));
342 // TODO: show privmsgs
343 void CoreUserInputHandler::handleMsg(const BufferInfo &bufferInfo, const QString &msg) {
344 Q_UNUSED(bufferInfo);
345 if(!msg.contains(' '))
348 QString target = msg.section(' ', 0, 0);
349 QByteArray encMsg = userEncode(target, msg.section(' ', 1));
352 putPrivmsg(serverEncode(target), encMsg, network()->cipher(target));
354 putPrivmsg(serverEncode(target), encMsg);
358 void CoreUserInputHandler::handleNick(const BufferInfo &bufferInfo, const QString &msg) {
360 QString nick = msg.section(' ', 0, 0);
361 emit putCmd("NICK", serverEncode(nick));
364 void CoreUserInputHandler::handleNotice(const BufferInfo &bufferInfo, const QString &msg) {
365 QString bufferName = msg.section(' ', 0, 0);
366 QString payload = msg.section(' ', 1);
367 QList<QByteArray> params;
368 params << serverEncode(bufferName) << channelEncode(bufferInfo.bufferName(), payload);
369 emit putCmd("NOTICE", params);
370 emit displayMsg(Message::Notice, bufferName, payload, network()->myNick(), Message::Self);
373 void CoreUserInputHandler::handleOp(const BufferInfo &bufferInfo, const QString &msg) {
374 QStringList nicks = msg.split(' ', QString::SkipEmptyParts);
375 QString m = "+"; for(int i = 0; i < nicks.count(); i++) m += 'o';
377 params << bufferInfo.bufferName() << m << nicks;
378 emit putCmd("MODE", serverEncode(params));
381 void CoreUserInputHandler::handleOper(const BufferInfo &bufferInfo, const QString &msg) {
383 emit putRawLine(serverEncode(QString("OPER %1").arg(msg)));
386 void CoreUserInputHandler::handlePart(const BufferInfo &bufferInfo, const QString &msg) {
387 QList<QByteArray> params;
390 // msg might contain either a channel name and/or a reaon, so we have to check if the first word is a known channel
391 QString channelName = msg.section(' ', 0, 0);
392 if(channelName.isEmpty() || !network()->ircChannel(channelName)) {
393 channelName = bufferInfo.bufferName();
396 partReason = msg.mid(channelName.length() + 1);
399 if(partReason.isEmpty())
400 partReason = network()->identityPtr()->partReason();
402 params << serverEncode(channelName) << channelEncode(bufferInfo.bufferName(), partReason);
403 emit putCmd("PART", params);
406 void CoreUserInputHandler::handlePing(const BufferInfo &bufferInfo, const QString &msg) {
411 param = QTime::currentTime().toString("hh:mm:ss.zzz");
413 putCmd("PING", serverEncode(param));
416 // TODO: implement queries
417 void CoreUserInputHandler::handleQuery(const BufferInfo &bufferInfo, const QString &msg) {
419 QString target = msg.section(' ', 0, 0);
420 QString message = msg.section(' ', 1);
421 if(message.isEmpty())
422 emit displayMsg(Message::Server, BufferInfo::QueryBuffer, target, tr("Starting query with %1").arg(target), network()->myNick(), Message::Self);
424 emit displayMsg(Message::Plain, BufferInfo::QueryBuffer, target, message, network()->myNick(), Message::Self);
425 handleMsg(bufferInfo, msg);
428 void CoreUserInputHandler::handleQuit(const BufferInfo &bufferInfo, const QString &msg) {
430 network()->disconnectFromIrc(true, msg);
433 void CoreUserInputHandler::issueQuit(const QString &reason) {
434 emit putCmd("QUIT", serverEncode(reason));
437 void CoreUserInputHandler::handleQuote(const BufferInfo &bufferInfo, const QString &msg) {
439 emit putRawLine(serverEncode(msg));
442 void CoreUserInputHandler::handleSay(const BufferInfo &bufferInfo, const QString &msg) {
443 if(bufferInfo.bufferName().isEmpty())
444 return; // server buffer
446 QByteArray encMsg = channelEncode(bufferInfo.bufferName(), msg);
448 putPrivmsg(serverEncode(bufferInfo.bufferName()), encMsg, network()->cipher(bufferInfo.bufferName()));
450 putPrivmsg(serverEncode(bufferInfo.bufferName()), encMsg);
452 emit displayMsg(Message::Plain, bufferInfo.type(), bufferInfo.bufferName(), msg, network()->myNick(), Message::Self);
455 void CoreUserInputHandler::handleSetkey(const BufferInfo &bufferInfo, const QString &msg) {
457 if(!bufferInfo.isValid())
460 if(!Cipher::neededFeaturesAvailable())
463 QStringList parms = msg.split(' ', QString::SkipEmptyParts);
465 if(parms.count() == 1 && !bufferInfo.bufferName().isEmpty())
466 parms.prepend(bufferInfo.bufferName());
467 else if(parms.count() != 2) {
468 emit displayMsg(Message::Info, bufferInfo.bufferName(),
469 tr("[usage] /setkey <nick|channel> <key> sets the encryption key for nick or channel. "
470 "/setkey <key> when in a channel or query buffer sets the key for it."));
474 QString target = parms.at(0);
475 QByteArray key = parms.at(1).toLocal8Bit();
477 network()->setCipherKey(target, key);
479 if(network()->isChannelName(target) && network()->channels().contains(target))
480 qobject_cast<CoreIrcChannel *>(network()->ircChannel(target))->setEncrypted(true);
481 else if(network()->nicks().contains(target))
482 qobject_cast<CoreIrcUser *>(network()->ircUser(target))->setEncrypted(true);
484 emit displayMsg(Message::Info, bufferInfo.bufferName(), tr("The key for %1 has been set.").arg(target));
487 emit displayMsg(Message::Error, bufferInfo.bufferName(), tr("Error: Setting an encryption key requires Quassel to have been built "
488 "with support for the Qt Cryptographic Architecture (QCA) library. "
489 "Contact your distributor about a Quassel package with QCA "
490 "support, or rebuild Quassel with QCA present."));
494 void CoreUserInputHandler::handleShowkey(const BufferInfo &bufferInfo, const QString &msg) {
496 if(!bufferInfo.isValid())
499 if(!Cipher::neededFeaturesAvailable())
502 QStringList parms = msg.split(' ', QString::SkipEmptyParts);
504 if(parms.isEmpty() && !bufferInfo.bufferName().isEmpty())
505 parms.prepend(bufferInfo.bufferName());
507 if(parms.isEmpty()) {
508 emit displayMsg(Message::Info, bufferInfo.bufferName(), "",
509 tr("[usage] /showkey <nick|channel> shows the encryption key for nick or channel or just /showkey when in a channel or query."));
513 QString target = parms.at(0);
514 QByteArray key = network()->cipherKey(target);
517 emit displayMsg(Message::Info, bufferInfo.bufferName(), tr("No key has been set for %1.").arg(target));
521 emit displayMsg(Message::Info, bufferInfo.bufferName(), tr("The key for %1 is %2").arg(target).arg(QString(key)));
525 emit displayMsg(Message::Error, bufferInfo.bufferName(), "", tr("Error: Setting an encryption key requires Quassel to have been built "
526 "with support for the Qt Cryptographic Architecture (QCA2) library. "
527 "Contact your distributor about a Quassel package with QCA2 "
528 "support, or rebuild Quassel with QCA2 present."));
532 void CoreUserInputHandler::handleTopic(const BufferInfo &bufferInfo, const QString &msg) {
533 if(bufferInfo.bufferName().isEmpty())
536 QList<QByteArray> params;
537 params << serverEncode(bufferInfo.bufferName());
541 params << encrypt(bufferInfo.bufferName(), channelEncode(bufferInfo.bufferName(), msg));
543 params << channelEncode(bufferInfo.bufferName(), msg);
547 emit putCmd("TOPIC", params);
550 void CoreUserInputHandler::handleVoice(const BufferInfo &bufferInfo, const QString &msg) {
551 QStringList nicks = msg.split(' ', QString::SkipEmptyParts);
552 QString m = "+"; for(int i = 0; i < nicks.count(); i++) m += 'v';
554 params << bufferInfo.bufferName() << m << nicks;
555 emit putCmd("MODE", serverEncode(params));
558 void CoreUserInputHandler::handleWait(const BufferInfo &bufferInfo, const QString &msg) {
559 int splitPos = msg.indexOf(';');
564 int delay = msg.left(splitPos).trimmed().toInt(&ok);
570 QString command = msg.mid(splitPos + 1).trimmed();
571 if(command.isEmpty())
574 _delayedCommands[startTimer(delay)] = Command(bufferInfo, command);
577 void CoreUserInputHandler::handleWho(const BufferInfo &bufferInfo, const QString &msg) {
579 emit putCmd("WHO", serverEncode(msg.split(' ')));
582 void CoreUserInputHandler::handleWhois(const BufferInfo &bufferInfo, const QString &msg) {
584 emit putCmd("WHOIS", serverEncode(msg.split(' ')));
587 void CoreUserInputHandler::handleWhowas(const BufferInfo &bufferInfo, const QString &msg) {
589 emit putCmd("WHOWAS", serverEncode(msg.split(' ')));
592 void CoreUserInputHandler::defaultHandler(QString cmd, const BufferInfo &bufferInfo, const QString &msg) {
593 Q_UNUSED(bufferInfo);
594 emit putCmd(serverEncode(cmd.toUpper()), serverEncode(msg.split(" ")));
597 void CoreUserInputHandler::putPrivmsg(const QByteArray &target, const QByteArray &message, Cipher *cipher) {
598 // Encrypted messages need special care. There's no clear relation between cleartext and encrypted message length,
599 // so we can't just compute the maxSplitPos. Instead, we need to loop through the splitpoints until the crypted
600 // version is short enough...
601 // TODO: check out how the various possible encryption methods behave length-wise and make
602 // this clean by predicting the length of the crypted msg.
603 // For example, blowfish-ebc seems to create 8-char chunks.
605 static const char *cmd = "PRIVMSG";
606 static const char *splitter = " .,-";
608 int maxSplitPos = message.count();
609 int splitPos = maxSplitPos;
611 QByteArray crypted = message.left(splitPos);
612 bool isEncrypted = false;
614 if(cipher && !message.isEmpty()) {
615 isEncrypted = cipher->encrypt(crypted);
618 int overrun = lastParamOverrun(cmd, QList<QByteArray>() << target << crypted);
620 // In case this is not an encrypted msg, we can just cut off at the end
622 maxSplitPos = message.count() - overrun;
625 for(const char *splitChar = splitter; *splitChar != 0; splitChar++) {
626 splitPos = qMax(splitPos, message.lastIndexOf(*splitChar, maxSplitPos) + 1); // keep split char on old line
628 if(splitPos <= 0 || splitPos > maxSplitPos)
629 splitPos = maxSplitPos;
631 maxSplitPos = splitPos - 1;
632 if(maxSplitPos <= 0) { // this should never happen, but who knows...
633 qWarning() << tr("[Error] Could not encrypt your message: %1").arg(message.data());
636 continue; // we never come back here for !encrypted!
639 // now we have found a valid splitpos (or didn't need to split to begin with)
640 putCmd(cmd, QList<QByteArray>() << target << crypted);
641 if(splitPos < message.count())
642 putPrivmsg(target, message.mid(splitPos), cipher);
648 // returns 0 if the message will not be chopped by the irc server or number of chopped bytes if message is too long
649 int CoreUserInputHandler::lastParamOverrun(const QString &cmd, const QList<QByteArray> ¶ms) {
650 // the server will pass our message truncated to 512 bytes including CRLF with the following format:
651 // ":prefix COMMAND param0 param1 :lastparam"
652 // where prefix = "nickname!user@host"
653 // that means that the last message can be as long as:
654 // 512 - nicklen - userlen - hostlen - commandlen - sum(param[0]..param[n-1])) - 2 (for CRLF) - 4 (":!@" + 1space between prefix and command) - max(paramcount - 1, 0) (space for simple params) - 2 (space and colon for last param)
655 IrcUser *me = network()->me();
656 int maxLen = 480 - cmd.toAscii().count(); // educated guess in case we don't know us (yet?)
659 maxLen = 512 - serverEncode(me->nick()).count() - serverEncode(me->user()).count() - serverEncode(me->host()).count() - cmd.toAscii().count() - 6;
661 if(!params.isEmpty()) {
662 for(int i = 0; i < params.count() - 1; i++) {
663 maxLen -= (params[i].count() + 1);
665 maxLen -= 2; // " :" last param separator;
667 if(params.last().count() > maxLen) {
668 return params.last().count() - maxLen;
678 QByteArray CoreUserInputHandler::encrypt(const QString &target, const QByteArray &message_, bool *didEncrypt) const {
682 if(message_.isEmpty())
685 if(!Cipher::neededFeaturesAvailable())
688 Cipher *cipher = network()->cipher(target);
692 QByteArray message = message_;
693 bool result = cipher->encrypt(message);
695 *didEncrypt = result;
701 void CoreUserInputHandler::timerEvent(QTimerEvent *event) {
702 if(!_delayedCommands.contains(event->timerId())) {
703 QObject::timerEvent(event);
706 BufferInfo bufferInfo = _delayedCommands[event->timerId()].bufferInfo;
707 QString rawCommand = _delayedCommands[event->timerId()].command;
708 _delayedCommands.remove(event->timerId());
711 // the stored command might be the result of an alias expansion, so we need to split it up again
712 QStringList commands = rawCommand.split(QRegExp("; ?"));
713 foreach(QString command, commands) {
714 handleUserInput(bufferInfo, command);