1
0
mirror of https://github.com/anope/anope.git synced 2026-06-26 04:06:41 +02:00

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.
This commit is contained in:
Sadie Powell
2024-02-21 16:35:27 +00:00
parent 3ecf6b495b
commit c4ab550ec7
6 changed files with 130 additions and 56 deletions
+61 -5
View File
@@ -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> &params)
{
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)