- emit displayMsg(Message::Info, bufferInfo.bufferName(), message);
- return;
- }
- network()->setBufferKey(parms[0], parms[1].toLocal8Bit());
-
- if(network()->isChannelName(parms[0]) && network()->channels().contains(parms[0]))
- network()->ircChannel(parms[0])->setEncrypted(true);
- else if(network()->nicks().contains(parms[0]))
- network()->ircUser(parms[0])->setEncrypted(true);
-
- QString message = tr("The key for %1 has been set.").arg(parms[0]);
- if (bufferInfo.bufferName().isEmpty())
- emit displayMsg(Message::Info, BufferInfo::StatusBuffer, "", message);
- else
- emit displayMsg(Message::Info, bufferInfo.bufferName(), message);
- #else
- emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Error: Setting an encryption key requires Quassel to have been built "
- "with support for the Qt Cryptographic Architecture (QCA) library. "
- "Contact your distributor about a Quassel package with QCA "
- "support, or rebuild Quassel with QCA present."));
- #endif
-}
-
-void CoreUserInputHandler::handleTopic(const BufferInfo &bufferInfo, const QString &msg) {
- if(bufferInfo.bufferName().isEmpty()) return;
- QList<QByteArray> params;
- params << serverEncode(bufferInfo.bufferName());
- if(!msg.isEmpty()) {
- #ifdef HAVE_QCA2
- const QByteArray bufferName = bufferInfo.bufferName().toAscii();
- QByteArray message = channelEncode(bufferInfo.bufferName(), msg);
- params << encrypt(bufferName, message);
- #else
- params << channelEncode(bufferInfo.bufferName(), msg);
- #endif
- }
-
- emit putCmd("TOPIC", params);
-}
-
-void CoreUserInputHandler::handleVoice(const BufferInfo &bufferInfo, const QString &msg) {
- QStringList nicks = msg.split(' ', QString::SkipEmptyParts);
- QString m = "+"; for(int i = 0; i < nicks.count(); i++) m += 'v';
- QStringList params;
- params << bufferInfo.bufferName() << m << nicks;
- emit putCmd("MODE", serverEncode(params));
-}
-
-void CoreUserInputHandler::handleWait(const BufferInfo &bufferInfo, const QString &msg) {
- int splitPos = msg.indexOf(';');
- if(splitPos <= 0)
- return;
-
- bool ok;
- int delay = msg.left(splitPos).trimmed().toInt(&ok);
- if(!ok)
- return;
-
- delay *= 1000;
-
- QString command = msg.mid(splitPos + 1).trimmed();
- if(command.isEmpty())
- return;
-
- _delayedCommands[startTimer(delay)] = Command(bufferInfo, command);
-}
-
-void CoreUserInputHandler::handleWho(const BufferInfo &bufferInfo, const QString &msg) {
- Q_UNUSED(bufferInfo)
- emit putCmd("WHO", serverEncode(msg.split(' ')));
-}
-
-void CoreUserInputHandler::handleWhois(const BufferInfo &bufferInfo, const QString &msg) {
- Q_UNUSED(bufferInfo)
- emit putCmd("WHOIS", serverEncode(msg.split(' ')));
-}
-
-void CoreUserInputHandler::handleWhowas(const BufferInfo &bufferInfo, const QString &msg) {
- Q_UNUSED(bufferInfo)
- emit putCmd("WHOWAS", serverEncode(msg.split(' ')));
-}
-
-void CoreUserInputHandler::defaultHandler(QString cmd, const BufferInfo &bufferInfo, const QString &msg) {
- Q_UNUSED(bufferInfo);
- emit putCmd(serverEncode(cmd.toUpper()), serverEncode(msg.split(" ")));
-}
-
-void CoreUserInputHandler::putPrivmsg(const QByteArray &target, const QByteArray &message, bool encrypted) {
-
- QByteArray temp = message;
-
- #ifdef HAVE_QCA2
- if(!encrypted) {
- temp = encrypt(target, temp);
- encrypted = true;
- }
- #endif
-
- static const char *cmd = "PRIVMSG";
- int overrun = lastParamOverrun(cmd, QList<QByteArray>() << target << temp);
- if(overrun) {
- static const char *splitter = " .,-";
- int maxSplitPos = temp.count() - overrun;
- int splitPos = -1;
- for(const char *splitChar = splitter; *splitChar != 0; splitChar++) {
- splitPos = qMax(splitPos, temp.lastIndexOf(*splitChar, maxSplitPos));
- }
- if(splitPos <= 0) {
- splitPos = maxSplitPos;
- }
- putCmd(cmd, QList<QByteArray>() << target << temp.left(splitPos));
- putPrivmsg(target, temp.mid(splitPos), encrypted);
- return;
- } else {
- putCmd(cmd, QList<QByteArray>() << target << temp);
- }
+ emit displayMsg(Message::Plain, BufferInfo::QueryBuffer, target, message, network()->myNick(), Message::Self);
+ handleMsg(bufferInfo, msg);
+}
+
+
+void CoreUserInputHandler::handleQuit(const BufferInfo &bufferInfo, const QString &msg)
+{
+ Q_UNUSED(bufferInfo)
+ network()->disconnectFromIrc(true, msg);
+}
+
+
+void CoreUserInputHandler::issueQuit(const QString &reason)
+{
+ emit putCmd("QUIT", serverEncode(reason));
+}
+
+
+void CoreUserInputHandler::handleQuote(const BufferInfo &bufferInfo, const QString &msg)
+{
+ Q_UNUSED(bufferInfo)
+ emit putRawLine(serverEncode(msg));
+}
+
+
+void CoreUserInputHandler::handleSay(const BufferInfo &bufferInfo, const QString &msg)
+{
+ if (bufferInfo.bufferName().isEmpty() || !bufferInfo.acceptsRegularMessages())
+ return; // server buffer
+
+ std::function<QByteArray(const QString &, const QString &)> encodeFunc = [this] (const QString &target, const QString &message) -> QByteArray {
+ return channelEncode(target, message);
+ };
+
+#ifdef HAVE_QCA2
+ putPrivmsg(bufferInfo.bufferName(), msg, encodeFunc, network()->cipher(bufferInfo.bufferName()));
+#else
+ putPrivmsg(bufferInfo.bufferName(), msg, encodeFunc);
+#endif
+ emit displayMsg(Message::Plain, bufferInfo.type(), bufferInfo.bufferName(), msg, network()->myNick(), Message::Self);
+}
+
+
+void CoreUserInputHandler::handleSetkey(const BufferInfo &bufferInfo, const QString &msg)
+{
+ QString bufname = bufferInfo.bufferName().isNull() ? "" : bufferInfo.bufferName();
+#ifdef HAVE_QCA2
+ if (!bufferInfo.isValid())
+ return;
+
+ if (!Cipher::neededFeaturesAvailable()) {
+ emit displayMsg(Message::Error, typeByTarget(bufname), bufname, tr("Error: QCA provider plugin not found. It is usually provided by the qca-ossl plugin."));
+ return;
+ }
+
+ QStringList parms = msg.split(' ', QString::SkipEmptyParts);
+
+ if (parms.count() == 1 && !bufferInfo.bufferName().isEmpty() && bufferInfo.acceptsRegularMessages())
+ parms.prepend(bufferInfo.bufferName());
+ else if (parms.count() != 2) {
+ emit displayMsg(Message::Info, typeByTarget(bufname), bufname,
+ tr("[usage] /setkey <nick|channel> <key> sets the encryption key for nick or channel. "
+ "/setkey <key> when in a channel or query buffer sets the key for it."));
+ return;
+ }
+
+ QString target = parms.at(0);
+ QByteArray key = parms.at(1).toLocal8Bit();
+ network()->setCipherKey(target, key);
+
+ emit displayMsg(Message::Info, typeByTarget(bufname), bufname, tr("The key for %1 has been set.").arg(target));
+#else
+ Q_UNUSED(msg)
+ emit displayMsg(Message::Error, typeByTarget(bufname), bufname, tr("Error: Setting an encryption key requires Quassel to have been built "
+ "with support for the Qt Cryptographic Architecture (QCA) library. "
+ "Contact your distributor about a Quassel package with QCA "
+ "support, or rebuild Quassel with QCA present."));
+#endif
+}
+
+
+void CoreUserInputHandler::handleShowkey(const BufferInfo &bufferInfo, const QString &msg)
+{
+ QString bufname = bufferInfo.bufferName().isNull() ? "" : bufferInfo.bufferName();
+#ifdef HAVE_QCA2
+ if (!bufferInfo.isValid())
+ return;
+
+ if (!Cipher::neededFeaturesAvailable()) {
+ emit displayMsg(Message::Error, typeByTarget(bufname), bufname, tr("Error: QCA provider plugin not found. It is usually provided by the qca-ossl plugin."));
+ return;
+ }
+
+ QStringList parms = msg.split(' ', QString::SkipEmptyParts);
+
+ if (parms.isEmpty() && !bufferInfo.bufferName().isEmpty() && bufferInfo.acceptsRegularMessages())
+ parms.prepend(bufferInfo.bufferName());
+
+ if (parms.isEmpty()) {
+ emit displayMsg(Message::Info, typeByTarget(bufname), bufname, tr("[usage] /showkey <nick|channel> shows the encryption key for nick or channel or just /showkey when in a channel or query."));
+ return;
+ }
+
+ QString target = parms.at(0);
+ QByteArray key = network()->cipherKey(target);
+
+ if (key.isEmpty()) {
+ emit displayMsg(Message::Info, typeByTarget(bufname), bufname, tr("No key has been set for %1.").arg(target));
+ return;
+ }
+
+ emit displayMsg(Message::Info, typeByTarget(bufname), bufname, tr("The key for %1 is %2:%3").arg(target, network()->cipherUsesCBC(target) ? "CBC" : "ECB", QString(key)));
+
+#else
+ Q_UNUSED(msg)
+ emit displayMsg(Message::Error, typeByTarget(bufname), bufname, tr("Error: Setting an encryption key requires Quassel to have been built "
+ "with support for the Qt Cryptographic Architecture (QCA2) library. "
+ "Contact your distributor about a Quassel package with QCA2 "
+ "support, or rebuild Quassel with QCA2 present."));
+#endif
+}
+
+
+void CoreUserInputHandler::handleTopic(const BufferInfo &bufferInfo, const QString &msg)
+{
+ if (bufferInfo.bufferName().isEmpty() || !bufferInfo.acceptsRegularMessages())
+ return;
+
+ QList<QByteArray> params;
+ params << serverEncode(bufferInfo.bufferName());
+
+ if (!msg.isEmpty()) {
+# ifdef HAVE_QCA2
+ params << encrypt(bufferInfo.bufferName(), channelEncode(bufferInfo.bufferName(), msg));
+# else
+ params << channelEncode(bufferInfo.bufferName(), msg);
+# endif
+ }
+
+ emit putCmd("TOPIC", params);
+}
+
+
+void CoreUserInputHandler::handleVoice(const BufferInfo &bufferInfo, const QString &msg)
+{
+ QStringList nicks = msg.split(' ', QString::SkipEmptyParts);
+ QString m = "+"; for (int i = 0; i < nicks.count(); i++) m += 'v';
+ QStringList params;
+ params << bufferInfo.bufferName() << m << nicks;
+ emit putCmd("MODE", serverEncode(params));
+}
+
+
+void CoreUserInputHandler::handleWait(const BufferInfo &bufferInfo, const QString &msg)
+{
+ int splitPos = msg.indexOf(';');
+ if (splitPos <= 0)
+ return;
+
+ bool ok;
+ int delay = msg.left(splitPos).trimmed().toInt(&ok);
+ if (!ok)
+ return;
+
+ delay *= 1000;
+
+ QString command = msg.mid(splitPos + 1).trimmed();
+ if (command.isEmpty())
+ return;
+
+ _delayedCommands[startTimer(delay)] = Command(bufferInfo, command);
+}
+
+
+void CoreUserInputHandler::handleWho(const BufferInfo &bufferInfo, const QString &msg)
+{
+ Q_UNUSED(bufferInfo)
+ emit putCmd("WHO", serverEncode(msg.split(' ')));
+}
+
+
+void CoreUserInputHandler::handleWhois(const BufferInfo &bufferInfo, const QString &msg)
+{
+ Q_UNUSED(bufferInfo)
+ emit putCmd("WHOIS", serverEncode(msg.split(' ')));
+}
+
+
+void CoreUserInputHandler::handleWhowas(const BufferInfo &bufferInfo, const QString &msg)
+{
+ Q_UNUSED(bufferInfo)
+ emit putCmd("WHOWAS", serverEncode(msg.split(' ')));
+}
+
+
+void CoreUserInputHandler::defaultHandler(QString cmd, const BufferInfo &bufferInfo, const QString &msg)
+{
+ Q_UNUSED(bufferInfo);
+ emit putCmd(serverEncode(cmd.toUpper()), serverEncode(msg.split(" ")));