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 /include | |
| parent | a6b14a9fb6afc5e16874ed7e4c0a135a4f5bfa53 (diff) | |
Remove rfc1459 message framing everywhere
Diffstat (limited to 'include')
| -rw-r--r-- | include/protocol.h | 67 | ||||
| -rw-r--r-- | include/uplink.h | 33 |
2 files changed, 82 insertions, 18 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; |
