From c4ab550ec719a80abada719dbe8680be806c370f Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 21 Feb 2024 16:35:27 +0000 Subject: Add Uplink::Send, rework message formatting. This is the new way of sending messages to the uplink inspired by the work done in the old git master. This will allow us to do new things involving tags in the future. --- src/process.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 5 deletions(-) (limited to 'src/process.cpp') diff --git a/src/process.cpp b/src/process.cpp index 94d2b538a..a81340250 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -123,12 +123,68 @@ bool IRCDProto::Parse(const Anope::string &buffer, Anope::map &ta return true; } -Anope::string IRCDProto::Format(const Anope::string &source, const Anope::string &message) +bool IRCDProto::Format(Anope::string &message, const Anope::map &tags, const MessageSource &source, const Anope::string &command, const std::vector ¶ms) { - if (!source.empty()) - return ":" + source + " " + message; - else - return message; + std::stringstream buffer; + if (CanSendTags && !tags.empty()) + { + char separator = '@'; + for (const auto &[tname, tvalue] : tags) + { + buffer << separator << tname; + if (!tvalue.empty()) + buffer << '=' << tvalue; + separator = ';'; + } + buffer << ' '; + } + + if (source.GetServer()) + { + const auto *s = source.GetServer(); + if (s != Me && !s->IsJuped()) + { + Log(LOG_DEBUG) << "Attempted to send \"" << command << "\" from " << s->GetName() << " who is not from me"; + return false; + } + + buffer << ':' << s->GetSID() << ' '; + } + else if (source.GetUser()) + { + const auto *u = source.GetUser(); + if (u->server != Me && !u->server->IsJuped()) + { + Log(LOG_DEBUG) << "Attempted to send \"" << command << "\" from " << u->nick << " who is not from me"; + return false; + } + + const auto *bi = source.GetBot(); + if (bi && !bi->introduced) + { + Log(LOG_DEBUG) << "Attempted to send \"" << command << "\" from " << bi->nick << " when not introduced"; + return false; + } + + buffer << ':' << u->GetUID() << ' '; + } + + buffer << command; + if (!params.empty()) + { + buffer << ' '; + for (auto it = params.begin(); it != params.end() - 1; ++it) + buffer << *it << ' '; + + + const auto &last = params.back(); + if (last.empty() || last[0] == ':' || last.find(' ') != std::string::npos) + buffer << ':'; + buffer << last; + } + + message = buffer.str(); + return true; } MessageTokenizer::MessageTokenizer(const Anope::string &msg) -- cgit