+ // Check if the sender is our own nick. If so, treat message as if sent by ourself.
+ // See http://ircv3.net/specs/extensions/echo-message-3.2.html
+ // Cache the result to avoid multiple redundant comparisons
+ bool isSelfMessage = net->isMyNick(senderNick);
+
+ QByteArray msg = params.count() < 2 ? QByteArray() : params.at(1);
+
+ QStringList targets = net->serverDecode(params.at(0)).split(',', QString::SkipEmptyParts);
+ QStringList::const_iterator targetIter;
+ for (targetIter = targets.constBegin(); targetIter != targets.constEnd(); ++targetIter) {
+ // For self-messages, keep the target, don't set it to the senderNick
+ QString target = net->isChannelName(*targetIter) || net->isStatusMsg(*targetIter) || isSelfMessage ? *targetIter : senderNick;
+
+ // Note: self-messages could be encrypted with a different key. If issues arise,
+ // consider including this within an if (!isSelfMessage) block
+ msg = decrypt(net, target, msg);
+
+ IrcEventRawMessage* rawMessage = new IrcEventRawMessage(EventManager::IrcEventRawPrivmsg,
+ net,
+ tags,
+ msg,
+ prefix,
+ target,
+ e->timestamp());
+ if (isSelfMessage) {
+ // Self-messages need processed differently, tag as such via flag.
+ rawMessage->setFlag(EventManager::Self);
+ }
+ events << rawMessage;
+ }
+ }
+ break;
+
+ case EventManager::IrcEventNotice:
+ defaultHandling = false;
+
+ if (checkParamCount(cmd, params, 2)) {
+ // Check if the sender is our own nick. If so, treat message as if sent by ourself.
+ // See http://ircv3.net/specs/extensions/echo-message-3.2.html
+ // Cache the result to avoid multiple redundant comparisons
+ bool isSelfMessage = net->isMyNick(nickFromMask(prefix));
+
+ // Only update from the prefix once during the loop
+ bool updatedFromPrefix = false;
+
+ QStringList targets = net->serverDecode(params.at(0)).split(',', QString::SkipEmptyParts);
+ QStringList::const_iterator targetIter;
+ for (targetIter = targets.constBegin(); targetIter != targets.constEnd(); ++targetIter) {
+ QString target = *targetIter;
+
+ // special treatment for welcome messages like:
+ // :ChanServ!ChanServ@services. NOTICE egst :[#apache] Welcome, this is #apache. Please read the in-channel topic message.
+ // This channel is being logged by IRSeekBot. If you have any question please see http://blog.freenode.net/?p=68
+ if (!net->isChannelName(target)) {
+ QString decMsg = net->serverDecode(params.at(1));
+ QRegExp welcomeRegExp(R"(^\[([^\]]+)\] )");
+ if (welcomeRegExp.indexIn(decMsg) != -1) {
+ QString channelname = welcomeRegExp.cap(1);
+ decMsg = decMsg.mid(welcomeRegExp.matchedLength());
+ // we only have CoreIrcChannels in the core, so this cast is safe
+ CoreIrcChannel* chan = static_cast<CoreIrcChannel*>(net->ircChannel(channelname)); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
+ if (chan && !chan->receivedWelcomeMsg()) {
+ chan->setReceivedWelcomeMsg();
+ events << new MessageEvent(Message::Notice, net, decMsg, prefix, channelname, Message::None, e->timestamp());
+ continue;
+ }
+ }
+ }
+
+ if (prefix.isEmpty() || target == "AUTH") {
+ target = QString();
+ }
+ else {
+ if (!target.isEmpty() && net->prefixes().contains(target.at(0)))
+ target = target.mid(1);
+
+ if (!net->isChannelName(target)) {
+ // For self-messages, keep the target, don't set it to the sender prefix
+ if (!isSelfMessage) {
+ target = nickFromMask(prefix);
+ }
+
+ if (!updatedFromPrefix) {
+ // Don't repeat this within the loop, the prefix doesn't change
+ updatedFromPrefix = true;
+
+ // Fetch/create the relevant IrcUser, and store it for later updates
+ IrcUser* ircuser = net->updateNickFromMask(prefix);
+
+ // Handle account-tag
+ if (ircuser && net->capEnabled(IrcCap::ACCOUNT_TAG)) {
+ if (tags.contains(IrcTags::ACCOUNT)) {
+ // Account tag available, set account.
+ // This duplicates the generic account-tag handling in case a
+ // new IrcUser object was just created.
+ ircuser->setAccount(tags[IrcTags::ACCOUNT]);
+ }
+ else {
+ // NOTICE is user sent; it's safe to assume the user has
+ // logged out. "*" is used to represent logged-out.
+ ircuser->setAccount("*");
+ }
+ }
+ }
+ }
+ }