- }
-
- static const char *cmd = "JOIN";
- i = 0;
- QStringList joinChans, joinKeys;
- int slicesize = chans.count();
- QList<QByteArray> encodedParams;
-
- // go through all to-be-joined channels and (re)build the join list
- while(i < chans.count()) {
- joinChans.append(chans.at(i));
- if(i < keys.count())
- joinKeys.append(keys.at(i));
-
- // if the channel list we built so far either contains all requested channels or exceeds
- // the desired amount of channels in this slice, try to send what we have so far
- if(++i == chans.count() || joinChans.count() >= slicesize) {
- params.clear();
- params.append(joinChans.join(","));
- params.append(joinKeys.join(","));
- encodedParams = serverEncode(params);
- // check if it fits in one command
- if(lastParamOverrun(cmd, encodedParams) == 0) {
- emit putCmd(cmd, encodedParams);
- } else if(slicesize > 1) {
- // back to start of slice, try again with half the amount of channels
- i -= slicesize;
- slicesize /= 2;
- }
- joinChans.clear();
- joinKeys.clear();
+}
+
+
+void CoreUserInputHandler::handleKeyx(const BufferInfo &bufferInfo, const QString &msg)
+{
+#ifdef HAVE_QCA2
+ if (!bufferInfo.isValid())
+ return;
+
+ if (!Cipher::neededFeaturesAvailable())
+ return;
+
+ QStringList parms = msg.split(' ', QString::SkipEmptyParts);
+
+ if (parms.count() == 0 && !bufferInfo.bufferName().isEmpty())
+ parms.prepend(bufferInfo.bufferName());
+ else if (parms.count() != 1) {
+ emit displayMsg(Message::Info, bufferInfo.bufferName(),
+ tr("[usage] /keyx [<nick|channel>] Initiates a DH1080 key exchange with the target."));
+ return;
+ }
+
+ QString target = parms.at(0);
+
+ Cipher *cipher = network()->cipher(target);
+ if (!cipher) // happens when there is no CoreIrcChannel for the target
+ return;
+
+ QByteArray pubKey = cipher->initKeyExchange();
+ if (pubKey.isEmpty())
+ emit displayMsg(Message::Error, bufferInfo.bufferName(), tr("Failed to initiate key exchange with %1.").arg(target));
+ else {
+ QList<QByteArray> params;
+ params << serverEncode(target) << serverEncode("DH1080_INIT ") + pubKey;
+ emit putCmd("NOTICE", params);
+ emit displayMsg(Message::Info, bufferInfo.bufferName(), tr("Initiated key exchange with %1.").arg(target));