+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); };
+
+ // Split apart messages at line feeds. The IRC protocol uses those to separate commands, so
+ // they need to be split into multiple messages.
+ QStringList messages = msg.split(QChar::LineFeed, QString::SkipEmptyParts);
+
+ for (const auto& message : messages) {
+ // Handle each separated message independently
+#ifdef HAVE_QCA2
+ putPrivmsg(bufferInfo.bufferName(), message, encodeFunc, network()->cipher(bufferInfo.bufferName()));
+#else
+ putPrivmsg(bufferInfo.bufferName(), message, encodeFunc);
+#endif
+ emit displayMsg(NetworkInternalMessage(
+ Message::Plain,
+ bufferInfo.type(),
+ bufferInfo.bufferName(),
+ message,
+ 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(NetworkInternalMessage(
+ 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(NetworkInternalMessage(
+ 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(NetworkInternalMessage(
+ Message::Info,
+ typeByTarget(bufname),
+ bufname,
+ tr("The key for %1 has been set.").arg(target)
+ ));
+#else
+ Q_UNUSED(msg)
+ emit displayMsg(NetworkInternalMessage(
+ 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(NetworkInternalMessage(
+ 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(NetworkInternalMessage(
+ 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(NetworkInternalMessage(
+ Message::Info,
+ typeByTarget(bufname),
+ bufname,
+ tr("No key has been set for %1.").arg(target)
+ ));
+ return;
+ }
+
+ emit displayMsg(NetworkInternalMessage(
+ 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(NetworkInternalMessage(
+ 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