diff options
author | Adam <Adam@anope.org> | 2016-09-23 15:46:03 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2016-09-23 15:46:03 -0400 |
commit | 2916943316c0d3c53d347fb43abe98a374c75e36 (patch) | |
tree | 45611b5583dca607e9a513b6b2f7d88975c56231 | |
parent | a6b14a9fb6afc5e16874ed7e4c0a135a4f5bfa53 (diff) |
Remove rfc1459 message framing everywhere
-rw-r--r-- | include/protocol.h | 67 | ||||
-rw-r--r-- | include/uplink.h | 33 | ||||
-rw-r--r-- | modules/protocol/bahamut.cpp | 64 | ||||
-rw-r--r-- | modules/protocol/charybdis.cpp | 77 | ||||
-rw-r--r-- | modules/protocol/hybrid.cpp | 59 | ||||
-rw-r--r-- | modules/protocol/inspircd20.cpp | 111 | ||||
-rw-r--r-- | modules/protocol/ngircd.cpp | 50 | ||||
-rw-r--r-- | modules/protocol/plexus.cpp | 34 | ||||
-rw-r--r-- | modules/protocol/ratbox.cpp | 18 | ||||
-rw-r--r-- | modules/protocol/unreal.cpp | 88 | ||||
-rw-r--r-- | src/process.cpp | 23 | ||||
-rw-r--r-- | src/protocol.cpp | 68 | ||||
-rw-r--r-- | src/uplink.cpp | 43 |
13 files changed, 412 insertions, 323 deletions
diff --git a/include/protocol.h b/include/protocol.h index 1005e7e64..898d1a51b 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -23,6 +23,8 @@ #include "anope.h" #include "service.h" +class IRCMessage; + /* Encapsultes the IRCd protocol we are speaking. */ class CoreExport IRCDProto : public Service { @@ -49,7 +51,7 @@ class CoreExport IRCDProto : public Service const Anope::string &GetProtocolName(); virtual void Parse(const Anope::string &, Anope::string &, Anope::string &, std::vector<Anope::string> &); - virtual Anope::string Format(const Anope::string &source, const Anope::string &message); + virtual Anope::string Format(IRCMessage &); /* Modes used by default by our clients */ Anope::string DefaultPseudoclientModes; @@ -157,6 +159,13 @@ class CoreExport IRCDProto : public Service virtual void SendQuit(User *u, const char *fmt, ...); virtual void SendPing(const Anope::string &servname, const Anope::string &who); + + /** + * Send a PONG reply to a received PING. + * servname should be left empty to send a one param reply. + * @param servname Daemon or client that is responding to the PING. + * @param who Origin of the PING and destination of the PONG message. + **/ virtual void SendPong(const Anope::string &servname, const Anope::string &who); /** Joins one of our users to a channel. @@ -264,6 +273,7 @@ class CoreExport MessageSource MessageSource(User *u); MessageSource(Server *s); const Anope::string &GetName() const; + const Anope::string &GetUID() const; const Anope::string &GetSource() const; User *GetUser() const; ServiceBot *GetBot() const; @@ -295,3 +305,58 @@ class CoreExport IRCDMessage : public Service extern CoreExport IRCDProto *IRCD; +class IRCMessage +{ + MessageSource source; + Anope::string command; + std::vector<Anope::string> parameters; + + void Push() { } + + public: + template<typename... Args> + IRCMessage(const MessageSource &_source, const Anope::string &_command, Args&&... args) + : source(_source) + , command(_command) + { + parameters.reserve(sizeof...(args)); + + Push(std::forward<Args>(args)...); + } + + template<typename T, typename... Args> + void Push(const T& t, Args&&... args) + { + parameters.push_back(stringify(t)); + + Push(std::forward<Args>(args)...); + } + + void TokenizeAndPush(const Anope::string &buf, char sepToken = ' ') + { + sepstream sep(buf, sepToken); + Anope::string token; + while (sep.GetToken(token)) + Push(token); + } + + const MessageSource &GetSource() const + { + return source; + } + + void SetSource(const MessageSource &source) + { + this->source = source; + } + + const Anope::string &GetCommand() const + { + return command; + } + + const std::vector<Anope::string> &GetParameters() const + { + return parameters; + } +}; diff --git a/include/uplink.h b/include/uplink.h index b20d1e686..0075b5d44 100644 --- a/include/uplink.h +++ b/include/uplink.h @@ -25,6 +25,21 @@ namespace Uplink { extern void Connect(); + extern void SendMessage(IRCMessage &); + + template<typename... Args> + void Send(const MessageSource &source, const Anope::string &command, Args&&... args) + { + IRCMessage message(source, command, std::forward<Args>(args)...); + SendMessage(message); + } + + template<typename... Args> + void Send(const Anope::string &command, Args&&... args) + { + IRCMessage message(MessageSource(""), command, std::forward<Args>(args)...); + SendMessage(message); + } } /* This is the socket to our uplink */ @@ -37,23 +52,7 @@ class UplinkSocket : public ConnectionSocket, public BufferedSocket bool ProcessRead() override; void OnConnect() override; void OnError(const Anope::string &) override; - - /* A message sent over the uplink socket */ - class CoreExport Message - { - MessageSource source; - std::stringstream buffer; - - public: - Message(); - Message(const MessageSource &); - ~Message(); - template<typename T> Message &operator<<(const T &val) - { - this->buffer << val; - return *this; - } - }; }; + extern CoreExport UplinkSocket *UplinkSock; diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 8c44c1d9d..a32a7606d 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -57,58 +57,64 @@ class BahamutIRCdProto : public IRCDProto { if (Servers::Capab.count("TSMODE") > 0) { - UplinkSocket::Message(source) << "MODE " << dest->name << " " << dest->creation_time << " " << buf; + IRCMessage message(source, "MODE", dest->name, dest->creation_time); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } else + { IRCDProto::SendModeInternal(source, dest, buf); + } } void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { - UplinkSocket::Message(source) << "SVSMODE " << u->nick << " " << u->timestamp << " " << buf; + IRCMessage message(source, "SVSMODE", u->nick, u->timestamp); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } /* SVSHOLD - set */ void SendSVSHold(const Anope::string &nick, time_t time) override { - UplinkSocket::Message(Me) << "SVSHOLD " << nick << " " << time << " :Being held for registered user"; + Uplink::Send(Me, "SVSHOLD", nick, time, "Being held for registered user"); } /* SVSHOLD - release */ void SendSVSHoldDel(const Anope::string &nick) override { - UplinkSocket::Message(Me) << "SVSHOLD " << nick << " 0"; + Uplink::Send(Me, "SVSHOLD", nick, 0); } /* SQLINE */ void SendSQLine(User *, XLine *x) override { - UplinkSocket::Message() << "SQLINE " << x->GetMask() << " :" << x->GetReason(); + Uplink::Send(Me, "SQLINE", x->GetMask(), x->GetReason()); } /* UNSLINE */ void SendSGLineDel(XLine *x) override { - UplinkSocket::Message() << "UNSGLINE 0 :" << x->GetMask(); + Uplink::Send("UNSGLINE", 0, x->GetMask()); } /* UNSZLINE */ void SendSZLineDel(XLine *x) override { /* this will likely fail so its only here for legacy */ - UplinkSocket::Message() << "UNSZLINE 0 " << x->GetHost(); + Uplink::Send("UNSZLINE", 0, x->GetHost()); /* this is how we are supposed to deal with it */ - UplinkSocket::Message() << "RAKILL " << x->GetHost() << " *"; + Uplink::Send("RAKILL", x->GetHost(), "*"); } /* SZLINE */ @@ -119,21 +125,21 @@ class BahamutIRCdProto : public IRCDProto if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; /* this will likely fail so its only here for legacy */ - UplinkSocket::Message() << "SZLINE " << x->GetHost() << " :" << x->GetReason(); + Uplink::Send("SZLINE", x->GetHost(), x->GetReason()); /* this is how we are supposed to deal with it */ - UplinkSocket::Message() << "AKILL " << x->GetHost() << " * " << timeleft << " " << x->GetBy() << " " << Anope::CurTime << " :" << x->GetReason(); + Uplink::Send("AKILL", x->GetHost(), "*", timeleft, x->GetBy(), Anope::CurTime, x->GetReason()); } /* SVSNOOP */ void SendSVSNOOP(const Server *server, bool set) override { - UplinkSocket::Message() << "SVSNOOP " << server->GetName() << " " << (set ? "+" : "-"); + Uplink::Send("SVSNOOP", server->GetName(), set ? "+" : "-"); } /* SGLINE */ void SendSGLine(User *, XLine *x) override { - UplinkSocket::Message() << "SGLINE " << x->GetMask().length() << " :" << x->GetMask() << ":" << x->GetReason(); + Uplink::Send("SGLINE", x->GetMask().length(), x->GetMask() + ":" + x->GetReason()); } /* RAKILL */ @@ -153,25 +159,26 @@ class BahamutIRCdProto : public IRCDProto } } - UplinkSocket::Message() << "RAKILL " << x->GetHost() << " " << x->GetUser(); + Uplink::Send("RAKKILL", x->GetHost(), x->GetUser()); } /* TOPIC */ void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic; + Uplink::Send(source, "TOPIC", c->name, c->topic_setter, c->topic_ts, c->topic); } /* UNSQLINE */ void SendSQLineDel(XLine *x) override { - UplinkSocket::Message() << "UNSQLINE " << x->GetMask(); + Uplink::Send("UNSQLINE", x->GetMask()); } /* JOIN - SJOIN */ void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { - UplinkSocket::Message(user) << "SJOIN " << c->creation_time << " " << c->name; + Uplink::Send(user, "SJOIN", c->creation_time, c->name); + if (status) { /* First save the channel status incase uc->Status == status */ @@ -237,7 +244,8 @@ class BahamutIRCdProto : public IRCDProto time_t timeleft = x->GetExpires() - Anope::CurTime; if (timeleft > 172800) timeleft = 172800; - UplinkSocket::Message() << "AKILL " << x->GetHost() << " " << x->GetUser() << " " << timeleft << " " << x->GetBy() << " " << Anope::CurTime << " :" << x->GetReason(); + + Uplink::Send("AKILL", x->GetHost(), x->GetUser(), timeleft, x->GetBy(), Anope::CurTime, x->GetReason()); } /* @@ -245,35 +253,35 @@ class BahamutIRCdProto : public IRCDProto */ void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override { - UplinkSocket::Message(source) << "SVSKILL " << user->nick << " :" << buf; + Uplink::Send(source, "SVSKILL", user->nick, buf); } void SendBOB() override { - UplinkSocket::Message() << "BURST"; + Uplink::Send("BURST"); } void SendEOB() override { - UplinkSocket::Message() << "BURST 0"; + Uplink::Send("BURST", 0); } void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message() << "NICK " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " " << u->server->GetName() << " 0 0 :" << u->realname; + Uplink::Send("NICK", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, u->server->GetName(), 0, 0, u->realname); } /* SERVER */ void SendServer(const Server *server) override { - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription()); } void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " :TS"; - UplinkSocket::Message() << "CAPAB SSJOIN NOQUIT BURST UNCONNECT NICKIP TSMODE TS3"; + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS"); + Uplink::Send("CAPAB", "SSJOIN NOQUIT BURST UNCONNECT NICKIP TSMODE TS3"); SendServer(Me); /* * SVINFO @@ -283,7 +291,7 @@ class BahamutIRCdProto : public IRCDProto * parv[3] = server is standalone or connected to non-TS only * parv[4] = server's idea of UTC time */ - UplinkSocket::Message() << "SVINFO 3 1 0 :" << Anope::CurTime; + Uplink::Send("SVINFO", 3, 1, 0, Anope::CurTime); this->SendBOB(); } @@ -292,7 +300,7 @@ class BahamutIRCdProto : public IRCDProto Anope::string modes = c->GetModes(true, true); if (modes.empty()) modes = "+"; - UplinkSocket::Message() << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :"; + Uplink::Send("SJOIN", c->creation_time, c->name, modes, ""); } void SendLogin(User *u, NickServ::Nick *) override diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp index 77dc52847..121915924 100644 --- a/modules/protocol/charybdis.cpp +++ b/modules/protocol/charybdis.cpp @@ -17,15 +17,12 @@ * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ -#if 0 #include "module.h" #include "modules/chanserv/mode.h" #include "modules/sasl.h" static Anope::string UplinkSID; -static ServiceReference<IRCDProto> ratbox("IRCDProto", "ratbox"); - class ChannelModeLargeBan : public ChannelMode { public: @@ -40,8 +37,10 @@ class ChannelModeLargeBan : public ChannelMode class CharybdisProto : public IRCDProto { + ServiceReference<IRCDProto> ratbox; // XXX public: CharybdisProto(Module *creator) : IRCDProto(creator, "Charybdis 3.4+") + , ratbox("ratbox") { DefaultPseudoclientModes = "+oiS"; CanCertFP = true; @@ -74,12 +73,13 @@ class CharybdisProto : public IRCDProto void SendSQLine(User *, XLine *x) override { - UplinkSocket::Message(Me) << "RESV * " << x->GetMask() << " :" << x->GetReason(); + Uplink::Send(Me, "RESV", "*", x->GetMask(), x->GetReason()); } void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID(); + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID()); + /* * Received: CAPAB :BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN * KNOCK MLOCK QS RSFNC SAVE SERVICES TB UNKLN @@ -103,7 +103,7 @@ class CharybdisProto : public IRCDProto * UNKLN - Can do UNKLINE (encap only) * QS - Can handle quit storm removal */ - UplinkSocket::Message() << "CAPAB :BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN KNOCK MLOCK QS RSFNC SERVICES TB UNKLN"; + Uplink::Send("CAPAB", "BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN KNOCK MLOCK QS RSFNC SERVICES TB UNKLN"); /* Make myself known to myself in the serverlist */ SendServer(Me); @@ -115,34 +115,34 @@ class CharybdisProto : public IRCDProto * arg[2] = '0' * arg[3] = server's idea of UTC time */ - UplinkSocket::Message() << "SVINFO 6 6 0 :" << Anope::CurTime; + Uplink::Send("SVINFO", 6, 6, Anope::CurTime); } void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "EUID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " * * :" << u->realname; + Uplink::Send(Me, "EUID", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, 0, u->GetUID(), "*", "*", u->realname); } void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override { - UplinkSocket::Message(Me) << "ENCAP " << u->server->GetName() << " RSFNC " << u->GetUID() - << " " << newnick << " " << when << " " << u->timestamp; + Uplink::Send(Me, "ENCAP", u->server->GetName(), "RSFNC", u->GetUID(), + newnick, when, u->timestamp); } void SendSVSHold(const Anope::string &nick, time_t delay) override { - UplinkSocket::Message(Me) << "ENCAP * NICKDELAY " << delay << " " << nick; + Uplink::Send(Me, "ENCAP", "*", "NICKDELAY", delay, nick); } void SendSVSHoldDel(const Anope::string &nick) override { - UplinkSocket::Message(Me) << "ENCAP * NICKDELAY 0 " << nick; + Uplink::Send(Me, "ENCAP", "*", "NICKDELAY", 0, nick); } void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override { - UplinkSocket::Message(Me) << "ENCAP * CHGHOST " << u->GetUID() << " :" << host; + Uplink::Send(Me, "ENCAP", "*", "CHGHOST", u->GetUID(), host); } void SendVhostDel(User *u) override @@ -153,19 +153,21 @@ class CharybdisProto : public IRCDProto void SendSASLMessage(const SASL::Message &message) override { Server *s = Server::Find(message.target.substr(0, 3)); - UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : message.target.substr(0, 3)) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext)); + Uplink::Send(Me, "ENCAP", s ? s->GetName() : message.target.substr(0, 3), "SASL", message.source, message.target, message.type, message.data, message.ext.empty() ? "" : message.ext); } void SendSVSLogin(const Anope::string &uid, const Anope::string &acc) override { Server *s = Server::Find(uid.substr(0, 3)); - UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : uid.substr(0, 3)) << " SVSLOGIN " << uid << " * * * " << acc; + Uplink::Send(Me, "ENCAP", s ? s->GetName() : uid.substr(0, 3), "SVSLOGIN", uid, "*", "*", "*", acc); } }; struct IRCDMessageEncap : IRCDMessage { + ServiceReference<SASL::Service> sasl; + IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT);} void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override @@ -197,7 +199,7 @@ struct IRCDMessageEncap : IRCDMessage * * Charybdis only accepts messages from SASL agents; these must have umode +S */ - if (params[1] == "SASL" && SASL::sasl && params.size() >= 6) + if (params[1] == "SASL" && sasl && params.size() >= 6) { SASL::Message m; m.source = params[2]; @@ -206,7 +208,7 @@ struct IRCDMessageEncap : IRCDMessage m.data = params[5]; m.ext = params.size() > 6 ? params[6] : ""; - SASL::sasl->ProcessMessage(m); + sasl->ProcessMessage(m); } } }; @@ -271,6 +273,7 @@ class ProtoCharybdis : public Module , public EventHook<Event::MLockEvents> { Module *m_ratbox; + ServiceReference<ModeLocks> mlocks; CharybdisProto ircd_proto; @@ -307,32 +310,10 @@ class ProtoCharybdis : public Module bool use_server_side_mlock; - void AddModes() - { - /* Add user modes */ - ModeManager::AddUserMode(new UserMode("NOFORWARD", 'Q')); - ModeManager::AddUserMode(new UserMode("REGPRIV", 'R')); - ModeManager::AddUserMode(new UserModeOperOnly("OPERWALLS", 'z')); - ModeManager::AddUserMode(new UserModeNoone("SSL", 'Z')); - - /* b/e/I */ - ModeManager::AddChannelMode(new ChannelModeList("QUIET", 'q')); - - /* Add channel modes */ - ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c')); - ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C')); - ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'f')); - ModeManager::AddChannelMode(new ChannelMode("ALLOWFORWARD", 'F')); - ModeManager::AddChannelMode(new ChannelMode("ALLINVITE", 'g')); - ModeManager::AddChannelMode(new ChannelModeParam("JOINFLOOD", 'j')); - ModeManager::AddChannelMode(new ChannelModeLargeBan("LBAN", 'L')); - ModeManager::AddChannelMode(new ChannelMode("PERM", 'P')); - ModeManager::AddChannelMode(new ChannelMode("NOFORWARD", 'Q')); - ModeManager::AddChannelMode(new ChannelMode("OPMODERATED", 'z')); - } - public: ProtoCharybdis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::ChannelSync>(this) + , EventHook<Event::MLockEvents>(this) , ircd_proto(this) , message_away(this) , message_capab(this) @@ -377,10 +358,9 @@ class ProtoCharybdis : public Module m_ratbox = ModuleManager::FindModule("ratbox"); if (!m_ratbox) throw ModuleException("Unable to find ratbox"); - if (!ratbox) - throw ModuleException("No protocol interface for ratbox"); - - this->AddModes(); +#warning "" +// if (!ratbox) +// throw ModuleException("No protocol interface for ratbox"); } ~ProtoCharybdis() @@ -402,7 +382,7 @@ class ProtoCharybdis : public Module if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0) { Anope::string modes = mlocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->GetName() << " " << modes; + Uplink::Send(Me, "MLOCK", c->creation_time, c->ci->GetName(), modes); } } @@ -415,7 +395,7 @@ class ProtoCharybdis : public Module if (use_server_side_mlock && cm && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->GetName() << " " << modes; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; @@ -430,7 +410,7 @@ class ProtoCharybdis : public Module if (use_server_side_mlock && cm && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->GetName() << " " << modes; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; @@ -438,4 +418,3 @@ class ProtoCharybdis : public Module }; MODULE_INIT(ProtoCharybdis) -#endif diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index 90b3581b2..d733dadee 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -68,37 +68,37 @@ class HybridProto : public IRCDProto void SendInvite(const MessageSource &source, const Channel *c, User *u) override { - UplinkSocket::Message(source) << "INVITE " << u->GetUID() << " " << c->name << " " << c->creation_time; + Uplink::Send(source, "INVITE", u->GetUID(), c->name, c->creation_time); } void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "NOTICE $$" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "NOTICE", "$$" + dest->GetName(), msg); } void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "PRIVMSG $$" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "PRIVMSG", "$$" + dest->GetName(), msg); } void SendSQLine(User *, XLine *x) override { - UplinkSocket::Message(FindIntroduced()) << "ENCAP * RESV " << (x->GetExpires() ? x->GetExpires() - Anope::CurTime : 0) << " " << x->GetMask() << " 0 :" << x->GetReason(); + Uplink::Send(FindIntroduced(), "ENCAP", "*", "RESV", x->GetExpires() ? x->GetExpires() - Anope::CurTime : 0, x->GetMask(), "0", x->GetReason()); } void SendSGLineDel(XLine *x) override { - UplinkSocket::Message(Config->GetClient("OperServ")) << "UNXLINE * " << x->GetMask(); + Uplink::Send(Config->GetClient("OperServ"), "UNXLINE", "*", x->GetMask()); } void SendSGLine(User *, XLine *x) override { - UplinkSocket::Message(Config->GetClient("OperServ")) << "XLINE * " << x->GetMask() << " 0 :" << x->GetReason(); + Uplink::Send(Config->GetClient("OperServ"), "XLINE", "*", x->GetMask(), "0", x->GetReason()); } void SendSZLineDel(XLine *x) override { - UplinkSocket::Message(Config->GetClient("OperServ")) << "UNDLINE * " << x->GetHost(); + Uplink::Send(Config->GetClient("OperServ"), "UNDLINE", "*", x->GetHost()); } void SendSZLine(User *, XLine *x) override @@ -109,7 +109,7 @@ class HybridProto : public IRCDProto if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message(Config->GetClient("OperServ")) << "DLINE * " << timeleft << " " << x->GetHost() << " :" << x->GetReason(); + Uplink::Send(Config->GetClient("OperServ"), "DLINE", "*", timeleft, x->GetHost(), x->GetReason()); } void SendAkillDel(XLine *x) override @@ -117,12 +117,12 @@ class HybridProto : public IRCDProto if (x->IsRegex() || x->HasNickOrReal()) return; - UplinkSocket::Message(Config->GetClient("OperServ")) << "UNKLINE * " << x->GetUser() << " " << x->GetHost(); + Uplink::Send(Config->GetClient("OperServ"), "UNKLINE", "*", x->GetUser(), x->GetHost()); } void SendSQLineDel(XLine *x) override { - UplinkSocket::Message(Config->GetClient("OperServ")) << "UNRESV * " << x->GetMask(); + Uplink::Send(Config->GetClient("OperServ"), "UNRESV", "*", x->GetMask()); } void SendJoin(User *user, Channel *c, const ChannelStatus *status) override @@ -132,9 +132,7 @@ class HybridProto : public IRCDProto * can not add them to the mode stacker because ircd-hybrid * does not allow *any* client to op itself */ - UplinkSocket::Message() << "SJOIN " << c->creation_time << " " << c->name << " +" - << c->GetModes(true, true) << " :" - << (status != NULL ? status->BuildModePrefixList() : "") << user->GetUID(); + Uplink::Send("SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), (status != NULL ? status->BuildModePrefixList() : "") + user->GetUID()); /* And update our internal status for this user since this is not going through our mode handling system */ if (status != NULL) @@ -189,23 +187,23 @@ class HybridProto : public IRCDProto if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message(Config->GetClient("OperServ")) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason(); + Uplink::Send(Config->GetClient("OperServ"), "KLINE", timeleft, x->GetUser(), x->GetHost(), x->GetReason()); } void SendServer(const Server *server) override { if (server == Me) - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() + 1 << " :" << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), server->GetHops() + 1, server->GetDescription()); else - UplinkSocket::Message(Me) << "SID " << server->GetName() << " " << server->GetHops() + 1 << " " << server->GetSID() << " :" << server->GetDescription(); + Uplink::Send(Me, "SID", server->GetName(), server->GetHops() + 1, server->GetSID(), server->GetDescription()); } void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID(); + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID()); /* - * As of October 13, 2012, ircd-hybrid-8 does support the following capabilities + * As of October 13, 2012, ircd-hybrid-8 supports the following capabilities * which are required to work with IRC-services: * * QS - Can handle quit storm removal @@ -220,29 +218,30 @@ class HybridProto : public IRCDProto * EOB - Supports End Of Burst message * TS6 - Capable of TS6 support */ - UplinkSocket::Message() << "CAPAB :QS EX CHW IE ENCAP TBURST SVS HOPS EOB TS6"; + Uplink::Send("CAPAB", "QS EX CHW IE ENCAP TBURST SVS HOPS EOB TS6"); SendServer(Me); - UplinkSocket::Message() << "SVINFO 6 6 0 :" << Anope::CurTime; + Uplink::Send("SVINFO", 6, 6, 0, Anope::CurTime); } void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " - << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " * :" << u->realname; + Uplink::Send(Me, "UID", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, 0, u->GetUID(), "*", u->realname); } void SendEOB() override { - UplinkSocket::Message(Me) << "EOB"; + Uplink::Send(Me, "EOB"); } void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { - UplinkSocket::Message(source) << "SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf; + IRCMessage message(source, "SVSMODE", u->GetUID(), u->timestamp); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void SendLogin(User *u, NickServ::Nick *na) override @@ -262,30 +261,30 @@ class HybridProto : public IRCDProto if (modes.empty()) modes = "+"; - UplinkSocket::Message() << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :"; + Uplink::Send("SJOIN", c->creation_time, c->name, modes, ""); } void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "TBURST " << c->creation_time << " " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic; + Uplink::Send(source, "TBURST", c->creation_time, c->name, c->topic_ts, c->topic_setter, c->topic); } void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override { - UplinkSocket::Message(Me) << "SVSNICK " << u->GetUID() << " " << newnick << " " << when; + Uplink::Send(Me, "SVSNICK", u->GetUID(), newnick, when); } void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) override { - UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan; + Uplink::Send(source, "SVSJOIN", u->GetUID(), chan); } void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) override { if (!param.empty()) - UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan << " :" << param; + Uplink::Send(source, "SVSPART", u->GetUID(), chan, param); else - UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan; + Uplink::Send(source, "SVSPART", u->GetUID(), chan); } void SendSVSHold(const Anope::string &nick, time_t t) override diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index b9406f55a..1d457df58 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -47,7 +47,7 @@ class InspIRCd20Proto : public IRCDProto if (!Servers::Capab.count("CHGIDENT")) Log() << "CHGIDENT not loaded!"; else - UplinkSocket::Message(Me) << "CHGIDENT " << nick << " " << vIdent; + Uplink::Send(Me, "CHGIDENT", nick, vIdent); } void SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost) @@ -55,17 +55,17 @@ class InspIRCd20Proto : public IRCDProto if (!Servers::Capab.count("CHGHOST")) Log() << "CHGHOST not loaded!"; else - UplinkSocket::Message(Me) << "CHGHOST " << nick << " " << vhost; + Uplink::Send(Me, "CHGHOST", nick, vhost); } void SendAddLine(const Anope::string &xtype, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason) { - UplinkSocket::Message(Me) << "ADDLINE " << xtype << " " << mask << " " << addedby << " " << Anope::CurTime << " " << duration << " :" << reason; + Uplink::Send(Me, "ADDLINE", xtype, mask, addedby, Anope::CurTime, duration, reason); } void SendDelLine(const Anope::string &xtype, const Anope::string &mask) { - UplinkSocket::Message(Me) << "DELLINE " << xtype << " " << mask; + Uplink::Send(Me, "DELLINE", xtype, mask); } public: @@ -86,20 +86,20 @@ class InspIRCd20Proto : public IRCDProto void SendConnect() override { - UplinkSocket::Message() << "CAPAB START 1202"; - UplinkSocket::Message() << "CAPAB CAPABILITIES :PROTOCOL=1202"; - UplinkSocket::Message() << "CAPAB END"; + Uplink::Send("CAPAB START 1202"); + Uplink::Send("CAPAB CAPABILITIES :PROTOCOL=1202"); + Uplink::Send("CAPAB END"); SendServer(Me); } void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } void SendAkillDel(XLine *x) override @@ -135,7 +135,7 @@ class InspIRCd20Proto : public IRCDProto { if (Servers::Capab.count("SVSTOPIC")) { - UplinkSocket::Message(c->ci->WhoSends()) << "SVSTOPIC " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic; + Uplink::Send(c->ci->WhoSends(), "SVSTOPIC", c->name, c->topic_ts, c->topic_setter, c->topic); } else { @@ -144,7 +144,7 @@ class InspIRCd20Proto : public IRCDProto if (c->topic_time > ts) ts = Anope::CurTime; /* But don't modify c->topic_ts, it should remain set to the real TS we want as ci->last_topic_time pulls from it */ - UplinkSocket::Message(source) << "FTOPIC " << c->name << " " << ts << " " << c->topic_setter << " :" << c->topic; + Uplink::Send(source, "FTOPIC", c->name, ts, c->topic_setter, c->topic); } } @@ -219,20 +219,22 @@ class InspIRCd20Proto : public IRCDProto void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) override { - UplinkSocket::Message() << "PUSH " << dest << " ::" << Me->GetName() << " " << numeric << " " << dest << " " << buf; + Uplink::Send("PUSH", dest, ":" + Me->GetName() + " " + numeric + " " + dest + " " + buf); } void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override { - UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf; + IRCMessage message(source, "FMODE", dest->name, dest->creation_time); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "UID " << u->GetUID() << " " << u->timestamp << " " << u->nick << " " << u->host << " " << u->host << " " << u->GetIdent() << " 0.0.0.0 " << u->timestamp << " " << modes << " :" << u->realname; + Uplink::Send(Me, "UID", u->GetUID(), u->timestamp, u->nick, u->host, u->host, u->GetIdent(), "0.0.0.0", u->timestamp, modes, u->realname); if (modes.find('o') != Anope::string::npos) - UplinkSocket::Message(u) << "OPERTYPE :services"; + Uplink::Send(u, "OPERTYPE", "services"); } /* SERVER services-dev.chatspike.net password 0 :Description here */ @@ -240,7 +242,7 @@ class InspIRCd20Proto : public IRCDProto { /* if rsquit is set then we are waiting on a squit */ if (rsquit_id.empty() && rsquit_server.empty()) - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << Config->Uplinks[Anope::CurrentUplink].password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), Config->Uplinks[Anope::CurrentUplink].password, server->GetHops(), server->GetSID(), server->GetDescription()); } void SendSquit(Server *s, const Anope::string &message) override @@ -249,16 +251,20 @@ class InspIRCd20Proto : public IRCDProto { rsquit_id = s->GetSID(); rsquit_server = s->GetName(); - UplinkSocket::Message() << "RSQUIT " << s->GetName() << " :" << message; + + Uplink::Send("RSQUIT", s->GetName(), message); } else - UplinkSocket::Message() << "SQUIT " << s->GetName() << " :" << message; + { + Uplink::Send("SQUIT", s->GetName(), message); + } } /* JOIN */ void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { - UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :," << user->GetUID(); + Uplink::Send(Me, "FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), "," + user->GetUID()); + /* Note that we can send this with the FJOIN but choose not to * because the mode stacker will handle this and probably will * merge these modes with +nrt and other mlocked modes @@ -310,13 +316,13 @@ class InspIRCd20Proto : public IRCDProto /* SVSHOLD - set */ void SendSVSHold(const Anope::string &nick, time_t t) override { - UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick << " " << t << " :Being held for registered user"; + Uplink::Send(Config->GetClient("NickServ"), "SVSHOLD", nick, t, "Being held for registered user"); } /* SVSHOLD - release */ void SendSVSHoldDel(const Anope::string &nick) override { - UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick; + Uplink::Send(Config->GetClient("NickServ"), "SVSHOLD", nick); } /* UNSZLINE */ @@ -337,42 +343,42 @@ class InspIRCd20Proto : public IRCDProto void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) override { - UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan; + Uplink::Send(source, "SVSJOIN", u->GetUID(), chan); } void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) override { if (!param.empty()) - UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan << " :" << param; + Uplink::Send(source, "SVSPART", u->GetUID(), chan, param); else - UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan; + Uplink::Send(source, "SVSPART", u->GetUID(), chan); } void SendSWhois(const MessageSource &, const Anope::string &who, const Anope::string &mask) override { User *u = User::Find(who); - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " swhois :" << mask; + Uplink::Send(Me, "METADATA", u->GetUID(), "swhois", mask); } void SendBOB() override { - UplinkSocket::Message(Me) << "BURST " << Anope::CurTime; + Uplink::Send(Me, "BURST", Anope::CurTime); Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); - UplinkSocket::Message(Me) << "VERSION :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << IRCD->GetProtocolName() << " - (" << (enc ? enc->name : "none") << ") -- " << Anope::VersionBuildString(); + Uplink::Send(Me, "VERSION", "Anope-" + Anope::Version() + " " + Me->GetName() + " :" + IRCD->GetProtocolName() + " - (" + (enc ? enc->name : "none") + ") -- " + Anope::VersionBuildString()); } void SendEOB() override { - UplinkSocket::Message(Me) << "ENDBURST"; + Uplink::Send(Me, "ENDBURST"); } void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override { if (Servers::Capab.count("GLOBOPS")) - UplinkSocket::Message(source) << "SNONOTICE g :" << buf; + Uplink::Send(source, "SNONOTICE", "g", buf); else - UplinkSocket::Message(source) << "SNONOTICE A :" << buf; + Uplink::Send(source, "SNONOTICE", "A", buf); } void SendLogin(User *u, NickServ::Nick *na) override @@ -381,27 +387,34 @@ class InspIRCd20Proto : public IRCDProto if (na->GetAccount()->HasFieldS("UNCONFIRMED")) return; - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->GetAccount()->GetDisplay(); + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", na->GetAccount()->GetDisplay()); } void SendLogout(User *u) override { - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :"; + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", ""); } void SendChannel(Channel *c) override { - UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :"; + Uplink::Send(Me, "FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), ""); } void SendSASLMessage(const SASL::Message &message) override { - UplinkSocket::Message(Me) << "ENCAP " << message.target.substr(0, 3) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext)); + if (!message.ext.empty()) + Uplink::Send(Me, "ENCAP", message.target.substr(0, 3), "SASL", + message.source, message.target, + message.type, message.data, message.ext); + else + Uplink::Send(Me, "ENCAP", message.target.substr(0, 3), "SASL", + message.source, message.target, + message.type, message.data); } void SendSVSLogin(const Anope::string &uid, const Anope::string &acc) override { - UplinkSocket::Message(Me) << "METADATA " << uid << " accountname :" << acc; + Uplink::Send(Me, "METADATA", uid, "accountname", acc); SASLUser su; su.uid = uid; @@ -618,7 +631,7 @@ struct IRCDMessageCapab : Message::Capab if (spanningtree_proto_ver < 1202) { - UplinkSocket::Message() << "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START"; + Uplink::Send("ERROR", "Protocol mismatch, no or invalid protocol version given in CAPAB START"); Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; Anope::Quitting = true; return; @@ -747,14 +760,14 @@ struct IRCDMessageCapab : Message::Capab { if (!Servers::Capab.count("SERVICES")) { - UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope"; + Uplink::Send("ERROR", "m_services_account.so is not loaded. This is required by Anope"); Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; Anope::Quitting = true; return; } if (!ModeManager::FindUserModeByName("PRIV")) { - UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope"; + Uplink::Send("ERROR", "m_hidechans.so is not loaded. This is required by Anope"); Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; Anope::Quitting = true; return; @@ -787,7 +800,7 @@ struct IRCDMessageEncap : IRCDMessage return; u->SetIdent(params[3]); - UplinkSocket::Message(u) << "FIDENT " << params[3]; + Uplink::Send(u, "FIDENT", params[3]); } else if (params[1] == "CHGHOST") { @@ -796,7 +809,7 @@ struct IRCDMessageEncap : IRCDMessage return; u->SetDisplayedHost(params[3]); - UplinkSocket::Message(u) << "FHOST " << params[3]; + Uplink::Send(u, "FHOST", params[3]); } else if (params[1] == "CHGNAME") { @@ -805,7 +818,7 @@ struct IRCDMessageEncap : IRCDMessage return; u->SetRealname(params[3]); - UplinkSocket::Message(u) << "FNAME " << params[3]; + Uplink::Send(u, "FNAME", params[3]); } } }; @@ -946,12 +959,14 @@ struct IRCDMessageIdle : IRCDMessage { ServiceBot *bi = ServiceBot::Find(params[0]); if (bi) - UplinkSocket::Message(bi) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " " << (Anope::CurTime - bi->lastmsg); + { + Uplink::Send(bi, "IDLE", source.GetSource(), Anope::StartTime, Anope::CurTime - bi->lastmsg); + } else { User *u = User::Find(params[0]); if (u && u->server == Me) - UplinkSocket::Message(u) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " 0"; + Uplink::Send(u, "IDLE", source.GetSource(), Anope::StartTime, 0); } } }; @@ -1022,14 +1037,14 @@ struct IRCDMessageMetadata : IRCDMessage // Mode lock string is not what we say it is? if (modes != params[2]) - UplinkSocket::Message(Me) << "METADATA " << c->name << " mlock :" << modes; + Uplink::Send(Me, "METADATA", c->name, "mlock", modes); } else if ((do_topiclock) && (params[1] == "topiclock")) { bool mystate = c->ci->GetExt<bool>("TOPICLOCK"); bool serverstate = (params[2] == "1"); if (mystate != serverstate) - UplinkSocket::Message(Me) << "METADATA " << c->name << " topiclock :" << (mystate ? "1" : ""); + Uplink::Send(Me, "METADATA", c->name, "topiclock", mystate ? "1" : ""); } } } @@ -1158,7 +1173,7 @@ struct IRCDMessageRSQuit : IRCDMessage if (!s) return; - UplinkSocket::Message(Me) << "SQUIT " << s->GetSID() << " :" << reason; + Uplink::Send(Me, "SQUIT", s->GetSID(), reason); s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); } }; @@ -1252,7 +1267,7 @@ struct IRCDMessageTime : IRCDMessage void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { - UplinkSocket::Message(Me) << "TIME " << source.GetSource() << " " << params[1] << " " << Anope::CurTime; + Uplink::Send(Me, "TIME", source.GetSource(), params[1], Anope::CurTime); } }; @@ -1359,7 +1374,7 @@ class ProtoInspIRCd20 : public Module void SendChannelMetadata(Channel *c, const Anope::string &metadataname, const Anope::string &value) { - UplinkSocket::Message(Me) << "METADATA " << c->name << " " << metadataname << " :" << value; + Uplink::Send(Me, "METADATA", c->name, metadataname, value); } public: diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index 05339f0e9..aa2c23a80 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -45,29 +45,29 @@ class ngIRCdProto : public IRCDProto time_t timeleft = x->GetExpires() - Anope::CurTime; if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message(Me) << "GLINE " << x->GetMask() << " " << timeleft << " :" << x->GetReason() << " (" << x->GetBy() << ")"; + Uplink::Send(Me, "GLINE", x->GetMask(), timeleft, x->GetReason() + " (" + x->GetBy() + ")"); } void SendAkillDel(XLine *x) override { - UplinkSocket::Message(Me) << "GLINE " << x->GetMask(); + Uplink::Send(Me, "GLINE", x->GetMask()); } void SendChannel(Channel *c) override { - UplinkSocket::Message(Me) << "CHANINFO " << c->name << " +" << c->GetModes(true, true); + Uplink::Send(Me, "CHANINFO", c->name, "+" + c->GetModes(true, true)); } // Received: :dev.anope.de NICK DukeP 1 ~DukePyro p57ABF9C9.dip.t-dialin.net 1 +i :DukePyrolator void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "NICK " << u->nick << " 1 " << u->GetIdent() << " " << u->host << " 1 " << modes << " :" << u->realname; + Uplink::Send(Me, "NICK", u->nick, 1, u->GetIdent(), u->host, 1, modes, u->realname); } void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " 0210-IRC+ Anope|" << Anope::VersionShort() << ":CLHMSo P"; + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "0210-IRC+", "Anope|" + Anope::VersionShort(), "CLHMSo P"); /* Make myself known to myself in the serverlist */ SendServer(Me); /* finish the enhanced server handshake and register the connection */ @@ -76,27 +76,27 @@ class ngIRCdProto : public IRCDProto void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override { - UplinkSocket::Message(Me) << "SVSNICK " << u->nick << " " << newnick; + Uplink::Send(Me, "SVSNICK", u->nick, newnick); } void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override { - UplinkSocket::Message(source) << "WALLOPS :" << buf; + Uplink::Send(source, "WALLOPS", buf); } void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { - UplinkSocket::Message(user) << "JOIN " << c->name; + Uplink::Send(user, "JOIN", c->name); if (status) { /* First save the channel status incase uc->Status == status */ @@ -120,51 +120,53 @@ class ngIRCdProto : public IRCDProto void SendKickInternal(const MessageSource &source, const Channel *chan, User *user, const Anope::string &buf) override { if (!buf.empty()) - UplinkSocket::Message(source) << "KICK " << chan->name << " " << user->nick << " :" << buf; + Uplink::Send(source, "KICK", chan->name, user->nick, buf); else - UplinkSocket::Message(source) << "KICK " << chan->name << " " << user->nick; + Uplink::Send(source, "KICK", chan->name, user->nick); } void SendLogin(User *u, NickServ::Nick *na) override { - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->GetAccount()->GetDisplay(); + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", na->GetAccount()->GetDisplay()); } void SendLogout(User *u) override { - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :"; + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", ""); } void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override { - UplinkSocket::Message(source) << "MODE " << dest->name << " " << buf; + IRCMessage message(source, "MODE", dest->name); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void SendPartInternal(User *u, const Channel *chan, const Anope::string &buf) override { if (!buf.empty()) - UplinkSocket::Message(u) << "PART " << chan->name << " :" << buf; + Uplink::Send(u, "PART", chan->name, buf); else - UplinkSocket::Message(u) << "PART " << chan->name; + Uplink::Send(u, "PART", chan->name); } /* SERVER name hop descript */ void SendServer(const Server *server) override { - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription()); } void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "TOPIC " << c->name << " :" << c->topic; + Uplink::Send(source, "TOPIC", c->name, c->topic); } void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) override { if (!vIdent.empty()) - UplinkSocket::Message(Me) << "METADATA " << u->nick << " user :" << vIdent; + Uplink::Send(Me, "METADATA", u->nick, "user", vIdent); - UplinkSocket::Message(Me) << "METADATA " << u->nick << " cloakhost :" << vhost; + Uplink::Send(Me, "METADATA", u->nick, "cloakhost", vhost); if (!u->HasMode("CLOAK")) { u->SetMode(Config->GetClient("HostServ"), "CLOAK"); @@ -177,9 +179,11 @@ class ngIRCdProto : public IRCDProto this->SendVhost(u, u->GetIdent(), ""); } - Anope::string Format(const Anope::string &source, const Anope::string &message) override + Anope::string Format(IRCMessage &message) { - return IRCDProto::Format(source.empty() ? Me->GetSID() : source, message); + if (message.GetSource().GetSource().empty()) + message.SetSource(Me); + return IRCDProto::Format(message); } }; diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index 5a682f02a..df9853340 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -59,12 +59,12 @@ class PlexusProto : public IRCDProto void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override { - UplinkSocket::Message(source) << "OPERWALL :" << buf; + Uplink::Send(source, "OPERWALL", buf); } void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { - UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << user->GetUID(); + Uplink::Send(Me, "SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), user->GetUID()); if (status) { /* First save the channel status incase uc->Status == status */ @@ -87,14 +87,14 @@ class PlexusProto : public IRCDProto void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override { - UplinkSocket::Message(Me) << "ENCAP " << u->server->GetName() << " SVSNICK " << u->GetUID() << " " << u->timestamp << " " << newnick << " " << when; + Uplink::Send(Me, "ENCAP", u->server->GetName(), "SVSNICK", u->GetUID(), u->timestamp, newnick, when); } void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override { if (!ident.empty()) - UplinkSocket::Message(Me) << "ENCAP * CHGIDENT " << u->GetUID() << " " << ident; - UplinkSocket::Message(Me) << "ENCAP * CHGHOST " << u->GetUID() << " " << host; + Uplink::Send(Me, "ENCAP", "*", "CHGIDENT", u->GetUID(), ident); + Uplink::Send(Me, "ENCAP", "*", "CHGHOST", u->GetUID(), host); u->SetMode(Config->GetClient("HostServ"), "CLOAK"); } @@ -105,7 +105,8 @@ class PlexusProto : public IRCDProto void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID(); + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID()); + /* CAPAB * QS - Can handle quit storm removal * EX - Can do channel +e exemptions @@ -126,9 +127,11 @@ class PlexusProto : public IRCDProto * ENCAP - Supports encapsulization of protocol messages * SVS - Supports services protocol extensions */ - UplinkSocket::Message() << "CAPAB :QS EX CHW IE EOB KLN UNKLN GLN HUB KNOCK TBURST PARA ENCAP SVS"; + Uplink::Send("CAPAB", "QS EX CHW IE EOB KLN UNKLN GLN HUB KNOCK TBURST PARA ENCAP SVS"); + /* Make myself known to myself in the serverlist */ SendServer(Me); + /* * SVINFO * parv[0] = sender prefix @@ -137,43 +140,43 @@ class PlexusProto : public IRCDProto * parv[3] = server is standalone or connected to non-TS only * parv[4] = server's idea of UTC time */ - UplinkSocket::Message() << "SVINFO 6 5 0 :" << Anope::CurTime; + Uplink::Send("SVINFO", 6, 6, 0, Anope::CurTime); } void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 255.255.255.255 " << u->GetUID() << " 0 " << u->host << " :" << u->realname; + Uplink::Send(Me, "UID", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, "255.255.255.255", u->GetUID(), 0, u->host, u->realname); } void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { - UplinkSocket::Message(source) << "ENCAP * SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf; + Uplink::Send(source, "ENCAP", "*", "SVSMODE", u->GetUID(), u->timestamp, buf); } void SendLogin(User *u, NickServ::Nick *na) override { - UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << na->GetAccount()->GetDisplay(); + Uplink::Send(Me, "ENCAP", "*", "SU", u->GetUID(), na->GetAccount()->GetDisplay()); } void SendLogout(User *u) override { - UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID(); + Uplink::Send(Me, "ENCAP", "*", "SU", u->GetUID(), ""); } void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "ENCAP * TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic; + Uplink::Send(source, "ENCAP", "*", "TOPIC", c->name, c->topic_setter, c->topic_ts, c->topic); } void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) override { - UplinkSocket::Message(source) << "ENCAP " << user->server->GetName() << " SVSJOIN " << user->GetUID() << " " << chan; + Uplink::Send(source, "ENCAP", user->server->GetName(), "SVSJOIN", user->GetUID(), chan); } void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) override { - UplinkSocket::Message(source) << "ENCAP " << user->server->GetName() << " SVSPART " << user->GetUID() << " " << chan; + Uplink::Send(source, "ENCAP", user->server->GetName(), "SVSPART", user->GetUID(), chan); } }; @@ -375,6 +378,7 @@ class ProtoPlexus : public Module m_hybrid = ModuleManager::FindModule("hybrid"); if (!m_hybrid) throw ModuleException("Unable to find hybrid"); +#warning "" // if (!hybrid) // throw ModuleException("No protocol interface for hybrid"); } diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 8aea359f5..f1a7c85da 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -53,12 +53,13 @@ class RatboxProto : public IRCDProto void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override { - UplinkSocket::Message(source) << "OPERWALL :" << buf; + Uplink::Send(source, "OPERWALL", buf); } void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID(); + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID()); + /* QS - Can handle quit storm removal EX - Can do channel +e exemptions @@ -69,9 +70,11 @@ class RatboxProto : public IRCDProto TB - supports topic burst ENCAP - supports ENCAP */ - UplinkSocket::Message() << "CAPAB :QS EX CHW IE GLN TB ENCAP"; + Uplink::Send("CAPAB", "QS EX CHW IE GLN TB ENCAP"); + /* Make myself known to myself in the serverlist */ SendServer(Me); + /* * SVINFO * parv[0] = sender prefix @@ -80,13 +83,13 @@ class RatboxProto : public IRCDProto * parv[3] = server is standalone or connected to non-TS only * parv[4] = server's idea of UTC time */ - UplinkSocket::Message() << "SVINFO 6 3 0 :" << Anope::CurTime; + Uplink::Send("SVINFO", 6, 6, 0, Anope::CurTime); } void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " :" << u->realname; + Uplink::Send(Me, "UID", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, 0, u->GetUID(), u->realname); } void SendLogin(User *u, NickServ::Nick *na) override @@ -94,12 +97,12 @@ class RatboxProto : public IRCDProto if (na->GetAccount()->HasFieldS("UNCONFIRMED")) return; - UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << na->GetAccount()->GetDisplay(); + Uplink::Send(Me, "ENCAP", "*", "SU", u->GetUID(), na->GetAccount()->GetDisplay()); } void SendLogout(User *u) override { - UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID(); + Uplink::Send(Me, "ENCAP", "*", "SU", u->GetUID()); } void SendTopic(const MessageSource &source, Channel *c) override @@ -290,6 +293,7 @@ class ProtoRatbox : public Module m_hybrid = ModuleManager::FindModule("hybrid"); if (!m_hybrid) throw ModuleException("Unable to find hybrid"); +#warning "" // if (!hybrid) // throw ModuleException("No protocol interface for hybrid"); } diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index e455287ee..a4a0850e7 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -44,7 +44,7 @@ class UnrealIRCdProto : public IRCDProto /* SVSNOOP */ void SendSVSNOOP(const Server *server, bool set) override { - UplinkSocket::Message() << "SVSNOOP " << server->GetName() << " " << (set ? "+" : "-"); + Uplink::Send("SVSNOOP", server->GetName(), set ? "+" : "-"); } void SendAkillDel(XLine *x) override @@ -63,22 +63,22 @@ class UnrealIRCdProto : public IRCDProto } } - UplinkSocket::Message() << "TKL - G " << x->GetUser() << " " << x->GetHost() << " " << x->GetBy(); + Uplink::Send("TKL", "-", "G", x->GetUser(), x->GetHost(), x->GetBy()); } void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic; + Uplink::Send(source, "TOPIC", c->name, c->topic_setter, c->topic_ts, c->topic); } void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } void SendVhostDel(User *u) override @@ -137,24 +137,26 @@ class UnrealIRCdProto : public IRCDProto time_t timeleft = x->GetExpires() - Anope::CurTime; if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message() << "TKL + G " << x->GetUser() << " " << x->GetHost() << " " << x->GetBy() << " " << Anope::CurTime + timeleft << " " << x->GetCreated() << " :" << x->GetReason(); + Uplink::Send("TKL", "+", "G", x->GetUser(), x->GetHost(), x->GetBy(), Anope::CurTime + timeleft, x->GetCreated(), x->GetReason()); } void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override { - UplinkSocket::Message(source) << "SVSKILL " << user->nick << " :" << buf; + Uplink::Send(source, "SVSKILL", user->nick, buf); user->KillInternal(source, buf); } void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { - UplinkSocket::Message(source) << "SVS2MODE " << u->nick <<" " << buf; + IRCMessage message(source, "SVS2MODE", u->nick); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message() << "NICK " << u->nick << " 1 " << u->timestamp << " " << u->GetIdent() << " " << u->host << " " << u->server->GetName() << " 0 " << modes << " " << u->host << " * :" << u->realname; + Uplink::Send("NICK", u->nick, "1", u->timestamp, u->GetIdent(), u->host, u->server->GetName(), "0", modes, u->host, u->realname); } /* SERVER name hop descript */ @@ -162,15 +164,15 @@ class UnrealIRCdProto : public IRCDProto void SendServer(const Server *server) override { if (!server->GetSID().empty() && server == Me) - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :U0-*-" << server->GetSID() << " " << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), server->GetHops(), "U0-*-" + server->GetSID() + " " + server->GetDescription()); else - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription()); } /* JOIN */ void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { - UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " :" << user->nick; + Uplink::Send(Me, "SJOIN", c->creation_time, c->name, user->nick); if (status) { /* First save the channel status incase uc->Status == status */ @@ -195,7 +197,7 @@ class UnrealIRCdProto : public IRCDProto */ void SendSQLineDel(XLine *x) override { - UplinkSocket::Message() << "UNSQLINE " << x->GetMask(); + Uplink::Send("UNSQLINE", x->GetMask()); } /* SQLINE */ @@ -205,7 +207,7 @@ class UnrealIRCdProto : public IRCDProto */ void SendSQLine(User *, XLine *x) override { - UplinkSocket::Message() << "SQLINE " << x->GetMask() << " :" << x->GetReason(); + Uplink::Send("SQLINE", x->GetMask(), x->GetReason()); } /* @@ -216,7 +218,7 @@ class UnrealIRCdProto : public IRCDProto */ void SendSVSO(ServiceBot *source, const Anope::string &nick, const Anope::string &flag) override { - UplinkSocket::Message(source) << "SVSO " << nick << " " << flag; + Uplink::Send(source, "SVSO", nick, flag); } /* Functions that use serval cmd functions */ @@ -224,9 +226,9 @@ class UnrealIRCdProto : public IRCDProto void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) override { if (!vIdent.empty()) - UplinkSocket::Message(Me) << "CHGIDENT " << u->nick << " " << vIdent; + Uplink::Send(Me, "CHGIDENT", u->nick, vIdent); if (!vhost.empty()) - UplinkSocket::Message(Me) << "CHGHOST " << u->nick << " " << vhost; + Uplink::Send(Me, "CHGHOST", u->nick, vhost); } void SendConnect() override @@ -244,26 +246,23 @@ class UnrealIRCdProto : public IRCDProto ESVID = Allows storing account names as services stamp MLOCK = Supports the MLOCK server command VL = Version Info - NS = Config->Numeric Server + NS = Numeric Server */ - Anope::string protoctl = "NICKv2 VHP UMODE2 NICKIP SJOIN SJOIN2 SJ3 NOQUIT TKLEXT ESVID MLOCK VL"; - if (!Me->GetSID().empty()) - protoctl += " VL"; - UplinkSocket::Message() << "PROTOCTL " << protoctl; - UplinkSocket::Message() << "PASS :" << Config->Uplinks[Anope::CurrentUplink].password; + Uplink::Send("PROTOCTL", "NICKv2", "VHP", "UMODE2", "NICKIP", "SJOIN", "SJOIN2", "SJ3", "NOQUIT", "TKLEXT", "ESVID", "MLOCK", "VL"); + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password); SendServer(Me); } /* SVSHOLD - set */ void SendSVSHold(const Anope::string &nick, time_t t) override { - UplinkSocket::Message() << "TKL + Q H " << nick << " " << Me->GetName() << " " << Anope::CurTime + t << " " << Anope::CurTime << " :Being held for registered user"; + Uplink::Send("TKL", "+", "Q", "H", nick, Me->GetName(), Anope::CurTime + t, Anope::CurTime, "Being held for registered user"); } /* SVSHOLD - release */ void SendSVSHoldDel(const Anope::string &nick) override { - UplinkSocket::Message() << "TKL - Q * " << nick << " " << Me->GetName(); + Uplink::Send("TKL", "-", "Q", "*", nick, Me->GetName()); } /* UNSGLINE */ @@ -272,13 +271,13 @@ class UnrealIRCdProto : public IRCDProto */ void SendSGLineDel(XLine *x) override { - UplinkSocket::Message() << "SVSNLINE - :" << x->GetMask(); + Uplink::Send("SVSNLINE", "-", x->GetMask()); } /* UNSZLINE */ void SendSZLineDel(XLine *x) override { - UplinkSocket::Message() << "TKL - Z * " << x->GetHost() << " " << x->GetBy(); + Uplink::Send("TKL", "-", "Z", "*", x->GetHost(), x->GetBy()); } /* SZLINE */ @@ -288,7 +287,7 @@ class UnrealIRCdProto : public IRCDProto time_t timeleft = x->GetExpires() - Anope::CurTime; if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message() << "TKL + Z * " << x->GetHost() << " " << x->GetBy() << " " << Anope::CurTime + timeleft << " " << x->GetCreated() << " :" << x->GetReason(); + Uplink::Send("TKL", "+", "Z", "*", x->GetHost(), x->GetBy(), Anope::CurTime + timeleft, x->GetCreated(), x->GetReason()); } /* SGLINE */ @@ -299,7 +298,7 @@ class UnrealIRCdProto : public IRCDProto { Anope::string edited_reason = x->GetReason(); edited_reason = edited_reason.replace_all_cs(" ", "_"); - UplinkSocket::Message() << "SVSNLINE + " << edited_reason << " :" << x->GetMask(); + Uplink::Send("SVSNLINE", "+", edited_reason, x->GetMask()); } /* svsjoin @@ -314,27 +313,27 @@ class UnrealIRCdProto : public IRCDProto void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) override { if (!param.empty()) - UplinkSocket::Message(source) << "SVSJOIN " << user->GetUID() << " " << chan << " :" << param; + Uplink::Send(source, "SVSJOIN", user->GetUID(), chan, param); else - UplinkSocket::Message(source) << "SVSJOIN " << user->GetUID() << " " << chan; + Uplink::Send(source, "SVSJOIN", user->GetUID(), chan); } void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) override { if (!param.empty()) - UplinkSocket::Message(source) << "SVSPART " << user->GetUID() << " " << chan << " :" << param; + Uplink::Send(source, "SVSPART", user->GetUID(), chan, param); else - UplinkSocket::Message(source) << "SVSPART " << user->GetUID() << " " << chan; + Uplink::Send(source, "SVSPART", user->GetUID(), chan); } void SendSWhois(const MessageSource &source, const Anope::string &who, const Anope::string &mask) override { - UplinkSocket::Message(source) << "SWHOIS " << who << " :" << mask; + Uplink::Send(source, "SWHOIS", who, mask); } void SendEOB() override { - UplinkSocket::Message(Me) << "EOS"; + Uplink::Send(Me, "EOS"); } bool IsNickValid(const Anope::string &nick) override @@ -398,7 +397,10 @@ class UnrealIRCdProto : public IRCDProto if (p == Anope::string::npos) return; - UplinkSocket::Message(ServiceBot::Find(message.source)) << "SASL " << message.target.substr(0, p) << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : " " + message.ext); + if (!message.ext.empty()) + Uplink::Send(ServiceBot::Find(message.source), "SASL", message.target.substr(0, p), message.target, message.type, message.data, message.ext); + else + Uplink::Send(ServiceBot::Find(message.source), "SASL", message.target.substr(0, p), message.target, message.type, message.data); } void SendSVSLogin(const Anope::string &uid, const Anope::string &acc) override @@ -406,7 +408,7 @@ class UnrealIRCdProto : public IRCDProto size_t p = uid.find('!'); if (p == Anope::string::npos) return; - UplinkSocket::Message(Me) << "SVSLOGIN " << uid.substr(0, p) << " " << uid << " " << acc; + Uplink::Send(Me, "SVSLOGIN", uid.substr(0, p), uid, acc); } bool IsIdentValid(const Anope::string &ident) override @@ -709,7 +711,7 @@ struct IRCDMessageNetInfo : IRCDMessage void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { Stats *stats = Serialize::GetObject<Stats *>(); - UplinkSocket::Message() << "NETINFO " << (stats ? stats->GetMaxUserCount() : 0) << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7]; + Uplink::Send("NETINFO", stats ? stats->GetMaxUserCount() : 0, Anope::CurTime, params[2], params[3], "0", "0", "0", params[7]); } }; @@ -1165,7 +1167,7 @@ class ProtoUnreal : public Module if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0 && mlocks) { Anope::string modes = mlocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->GetName() << " " << modes; + Uplink::Send(Me, "MLOCK", c->creation_time, c->ci->GetName(), modes); } } @@ -1174,14 +1176,14 @@ class ProtoUnreal : public Module if (!ci->c || !use_server_side_mlock || !mlocks || !Servers::Capab.count("MLOCK")) return; Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->GetName() << " " << modes; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } void OnDelChan(ChanServ::Channel *ci) override { if (!ci->c || !use_server_side_mlock || !Servers::Capab.count("MLOCK")) return; - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->GetName() << " :"; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), ""); } EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) override @@ -1190,7 +1192,7 @@ class ProtoUnreal : public Module if (use_server_side_mlock && cm && mlocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->GetName() << " " << modes; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; @@ -1202,7 +1204,7 @@ class ProtoUnreal : public Module if (use_server_side_mlock && cm && mlocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->GetName() << " " << modes; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; diff --git a/src/process.cpp b/src/process.cpp index c110394fc..356a3b695 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -105,11 +105,26 @@ void IRCDProto::Parse(const Anope::string &buffer, Anope::string &source, Anope: } } -Anope::string IRCDProto::Format(const Anope::string &source, const Anope::string &message) +Anope::string IRCDProto::Format(IRCMessage &message) { + std::stringstream buffer; + + const Anope::string &source = message.GetSource().GetUID(); if (!source.empty()) - return ":" + source + " " + message; - else - return message; + buffer << ":" << source << " "; + + buffer << message.GetCommand(); + + for (unsigned int i = 0; i < message.GetParameters().size(); ++i) + { + buffer << " "; + + if (i + 1 == message.GetParameters().size()) + buffer << ":"; + + buffer << message.GetParameters()[i]; + } + + return buffer.str(); } diff --git a/src/protocol.cpp b/src/protocol.cpp index 057651d3b..c5b555cad 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -104,61 +104,65 @@ Anope::string IRCDProto::SID_Retrieve() void IRCDProto::SendKill(const MessageSource &source, const Anope::string &target, const Anope::string &reason) { - UplinkSocket::Message(source) << "KILL " << target << " :" << reason; + Uplink::Send(source, "KILL", target, reason); } void IRCDProto::SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) { - UplinkSocket::Message(source) << "KILL " << user->GetUID() << " :" << buf; + Uplink::Send(source, "KILL", user->GetUID(), buf); } void IRCDProto::SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) { - UplinkSocket::Message(source) << "MODE " << dest->name << " " << buf; + IRCMessage message(source, "MODE", dest->name); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void IRCDProto::SendModeInternal(const MessageSource &source, User *dest, const Anope::string &buf) { - UplinkSocket::Message(source) << "MODE " << dest->GetUID() << " " << buf; + IRCMessage message(source, "MODE", dest->GetUID()); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void IRCDProto::SendKickInternal(const MessageSource &source, const Channel *c, User *u, const Anope::string &r) { if (!r.empty()) - UplinkSocket::Message(source) << "KICK " << c->name << " " << u->GetUID() << " :" << r; + Uplink::Send(source, "KICK", c->name, u->GetUID(), r); else - UplinkSocket::Message(source) << "KICK " << c->name << " " << u->GetUID(); + Uplink::Send(source, "KICK", c->name, u->GetUID()); } void IRCDProto::SendNoticeInternal(const MessageSource &source, const Anope::string &dest, const Anope::string &msg) { - UplinkSocket::Message(source) << "NOTICE " << dest << " :" << msg; + Uplink::Send(source, "NOTICE", dest, msg); } void IRCDProto::SendPrivmsgInternal(const MessageSource &source, const Anope::string &dest, const Anope::string &buf) { - UplinkSocket::Message(source) << "PRIVMSG " << dest << " :" << buf; + Uplink::Send(source, "PRIVMSG", dest, buf); } void IRCDProto::SendQuitInternal(User *u, const Anope::string &buf) { if (!buf.empty()) - UplinkSocket::Message(u) << "QUIT :" << buf; + Uplink::Send(u, "QUIT", buf); else - UplinkSocket::Message(u) << "QUIT"; + Uplink::Send(u, "QUIT"); } void IRCDProto::SendPartInternal(User *u, const Channel *chan, const Anope::string &buf) { if (!buf.empty()) - UplinkSocket::Message(u) << "PART " << chan->name << " :" << buf; + Uplink::Send(u, "PART", chan->name, buf); else - UplinkSocket::Message(u) << "PART " << chan->name; + Uplink::Send(u, "PART", chan->name); } void IRCDProto::SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) { - UplinkSocket::Message(source) << "GLOBOPS :" << buf; + Uplink::Send(source, "GLOBOPS", buf); } void IRCDProto::SendCTCPInternal(const MessageSource &source, const Anope::string &dest, const Anope::string &buf) @@ -174,12 +178,15 @@ void IRCDProto::SendNumericInternal(int numeric, const Anope::string &dest, cons n = "0" + n; if (numeric < 100) n = "0" + n; - UplinkSocket::Message(Me) << n << " " << dest << " " << buf; + + IRCMessage message(Me, n, dest); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } void IRCDProto::SendTopic(const MessageSource &source, Channel *c) { - UplinkSocket::Message(source) << "TOPIC " << c->name << " :" << c->topic; + Uplink::Send(source, "TOPIC", c->name, c->topic); } void IRCDProto::SendSVSKill(const MessageSource &source, User *user, const char *fmt, ...) @@ -272,28 +279,22 @@ void IRCDProto::SendQuit(User *u, const char *fmt, ...) void IRCDProto::SendPing(const Anope::string &servname, const Anope::string &who) { if (servname.empty()) - UplinkSocket::Message(Me) << "PING " << who; + Uplink::Send(Me, "PING", who); else - UplinkSocket::Message(Me) << "PING " << servname << " " << who; + Uplink::Send(Me, "PING", servname, who); } -/** - * Send a PONG reply to a received PING. - * servname should be left NULL to send a one param reply. - * @param servname Daemon or client that is responding to the PING. - * @param who Origin of the PING and destination of the PONG message. - **/ void IRCDProto::SendPong(const Anope::string &servname, const Anope::string &who) { if (servname.empty()) - UplinkSocket::Message(Me) << "PONG " << who; + Uplink::Send(Me, "PONG", who); else - UplinkSocket::Message(Me) << "PONG " << servname << " " << who; + Uplink::Send(Me, "PONG", servname, who); } void IRCDProto::SendInvite(const MessageSource &source, const Channel *c, User *u) { - UplinkSocket::Message(source) << "INVITE " << u->GetUID() << " " << c->name; + Uplink::Send(source, "INVITE", u->GetUID(), c->name); } void IRCDProto::SendPart(User *user, const Channel *chan, const char *fmt, ...) @@ -323,17 +324,17 @@ void IRCDProto::SendGlobops(const MessageSource &source, const char *fmt, ...) void IRCDProto::SendSquit(Server *s, const Anope::string &message) { - UplinkSocket::Message() << "SQUIT " << s->GetSID() << " :" << message; + Uplink::Send("SQUIT", s->GetSID(), message); } void IRCDProto::SendNickChange(User *u, const Anope::string &newnick) { - UplinkSocket::Message(u) << "NICK " << newnick << " " << Anope::CurTime; + Uplink::Send(u, "NICK", newnick, Anope::CurTime); } void IRCDProto::SendForceNickChange(User *u, const Anope::string &newnick, time_t when) { - UplinkSocket::Message() << "SVSNICK " << u->GetUID() << " " << newnick << " " << when; + Uplink::Send(u, "SVSNICK", u->GetUID(), newnick, when); } void IRCDProto::SendCTCP(const MessageSource &source, const Anope::string &dest, const char *fmt, ...) @@ -482,6 +483,15 @@ const Anope::string &MessageSource::GetName() const return this->source; } +const Anope::string &MessageSource::GetUID() const +{ + if (this->s) + return this->s->GetSID(); + if (this->u) + return this->u->GetUID(); + return this->source; +} + const Anope::string &MessageSource::GetSource() const { return this->source; diff --git a/src/uplink.cpp b/src/uplink.cpp index ac262543f..c2b7579c5 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -166,60 +166,45 @@ void UplinkSocket::OnError(const Anope::string &err) error |= !err.empty(); } -UplinkSocket::Message::Message() : source(Me) +void Uplink::SendMessage(IRCMessage &message) { -} + const MessageSource &source = message.GetSource(); + Anope::string buffer = IRCD->Format(message); -UplinkSocket::Message::Message(const MessageSource &src) : source(src) -{ -} - -UplinkSocket::Message::~Message() -{ - Anope::string message_source; - - if (this->source.GetServer() != NULL) + if (source.GetServer() != NULL) { - const Server *s = this->source.GetServer(); + const Server *s = source.GetServer(); if (s != Me && !s->IsJuped()) { - Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << s->GetName() << " who is not from me?"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << s->GetName() << " who is not from me?"; return; } - - message_source = s->GetSID(); } - else if (this->source.GetUser() != NULL) + else if (source.GetUser() != NULL) { - const User *u = this->source.GetUser(); + const User *u = 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?"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << u->nick << " who is not from me?"; return; } - const ServiceBot *bi = this->source.GetBot(); + const ServiceBot *bi = source.GetBot(); if (bi != NULL && bi->introduced == false) { - Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << bi->nick << " when not introduced"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" 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"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" with UplinkSock NULL"; return; } - Anope::string sent = IRCD->Format(message_source, this->buffer.str()); - UplinkSock->Write(sent); - Log(LOG_RAWIO) << "Sent: " << sent; + UplinkSock->Write(buffer); + Log(LOG_RAWIO) << "Sent: " << buffer; } |