summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/process.cpp66
-rw-r--r--src/uplink.cpp69
2 files changed, 84 insertions, 51 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> &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)
diff --git a/src/uplink.cpp b/src/uplink.cpp
index f173bf10c..c3c6dbd41 100644
--- a/src/uplink.cpp
+++ b/src/uplink.cpp
@@ -61,6 +61,22 @@ void Uplink::Connect()
UplinkSock->Connect(ip, u.port);
}
+void Uplink::SendInternal(const Anope::map<Anope::string> &tags, const MessageSource &source, const Anope::string &command, const std::vector<Anope::string> &params)
+{
+ if (!UplinkSock)
+ {
+ Log(LOG_DEBUG) << "Attempted to send \"" << command << "\" from " << source.GetName() << " with a null uplink socket";
+ return;
+ }
+
+ Anope::string message;
+ if (!IRCD->Format(message, tags, source, command, params))
+ return;
+
+ UplinkSock->Write(message);
+ Log(LOG_RAWIO) << "Sent: " << message;
+}
+
UplinkSocket::UplinkSocket() : Socket(-1, Config->Uplinks[Anope::CurrentUplink].protocol), ConnectionSocket(), BufferedSocket()
{
error = false;
@@ -165,50 +181,11 @@ UplinkSocket::Message::Message(const MessageSource &src) : source(src)
UplinkSocket::Message::~Message()
{
- Anope::string message_source;
-
- if (this->source.GetServer() != NULL)
- {
- const Server *s = this->source.GetServer();
-
- if (s != Me && !s->IsJuped())
- {
- Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << s->GetName() << " who is not from me?";
- return;
- }
-
- message_source = s->GetSID();
- }
- else if (this->source.GetUser() != NULL)
- {
- const User *u = this->source.GetUser();
-
- if (u->server != Me && !u->server->IsJuped())
- {
- Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << u->nick << " who is not from me?";
- return;
- }
-
- const BotInfo *bi = this->source.GetBot();
- if (bi != NULL && bi->introduced == false)
- {
- Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << bi->nick << " when not introduced";
- return;
- }
-
- message_source = u->GetUID();
- }
-
- if (!UplinkSock)
- {
- if (!message_source.empty())
- Log(LOG_DEBUG) << "Attempted to send \"" << message_source << " " << this->buffer.str() << "\" with UplinkSock NULL";
- else
- Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" with UplinkSock NULL";
- return;
- }
-
- Anope::string sent = IRCD->Format(message_source, this->buffer.str());
- UplinkSock->Write(sent);
- Log(LOG_RAWIO) << "Sent: " << sent;
+ // This is all temporary as UplinkSocket::Message is going to to die as soon
+ // as everything is migrated to Uplink::Send.
+ Anope::map<Anope::string> tags;
+ Anope::string unused, command;
+ std::vector<Anope::string> params;
+ if (IRCD->Parse(this->buffer.str(), tags, unused, command, params))
+ Uplink::SendInternal(tags, source, command, params);
}