diff options
author | Sadie Powell <sadie@witchery.services> | 2024-02-21 16:35:27 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-02-22 00:14:08 +0000 |
commit | c4ab550ec719a80abada719dbe8680be806c370f (patch) | |
tree | 371e5b11134303336719c9a18affdfeab3afcb25 /src/process.cpp | |
parent | 3ecf6b495b02bdabe317547fe4bcf2179e3fb6d7 (diff) |
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.
Diffstat (limited to 'src/process.cpp')
-rw-r--r-- | src/process.cpp | 66 |
1 files changed, 61 insertions, 5 deletions
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<Anope::string> &ta return true; } -Anope::string IRCDProto::Format(const Anope::string &source, const Anope::string &message) +bool IRCDProto::Format(Anope::string &message, const Anope::map<Anope::string> &tags, const MessageSource &source, const Anope::string &command, const std::vector<Anope::string> ¶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) |