summaryrefslogtreecommitdiff
path: root/include/protocol.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/protocol.h')
-rw-r--r--include/protocol.h133
1 files changed, 104 insertions, 29 deletions
diff --git a/include/protocol.h b/include/protocol.h
index d8029d53d..4fdc97f0c 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -1,21 +1,30 @@
/*
+ * Anope IRC Services
*
- * (C) 2003-2016 Anope Team
- * Contact us at team@anope.org
+ * Copyright (C) 2012-2016 Anope Team <team@anope.org>
*
- * Please read COPYING and README for further details.
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
*
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
-#ifndef PROTOCOL_H
-#define PROTOCOL_H
+#pragma once
#include "services.h"
#include "anope.h"
#include "service.h"
+class IRCMessage;
+
/* Encapsultes the IRCd protocol we are speaking. */
class CoreExport IRCDProto : public Service
{
@@ -24,6 +33,8 @@ class CoreExport IRCDProto : public Service
protected:
IRCDProto(Module *creator, const Anope::string &proto_name);
public:
+ static constexpr const char *NAME = "ircdproto";
+
virtual ~IRCDProto();
virtual void SendSVSKillInternal(const MessageSource &, User *, const Anope::string &);
@@ -40,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;
@@ -104,20 +115,20 @@ class CoreExport IRCDProto : public Service
* @param u The user affected by the akill, if known
* @param x The akill
*/
- virtual void SendAkill(User *, XLine *) = 0;
- virtual void SendAkillDel(const XLine *) = 0;
+ virtual void SendAkill(User *, XLine *) anope_abstract;
+ virtual void SendAkillDel(XLine *) anope_abstract;
/* Realname ban */
- virtual void SendSGLine(User *, const XLine *) { }
- virtual void SendSGLineDel(const XLine *) { }
+ virtual void SendSGLine(User *, XLine *) { }
+ virtual void SendSGLineDel(XLine *) { }
/* IP ban */
- virtual void SendSZLine(User *u, const XLine *) { }
- virtual void SendSZLineDel(const XLine *) { }
+ virtual void SendSZLine(User *u, XLine *) { }
+ virtual void SendSZLineDel(XLine *) { }
/* Nick ban (and sometimes channel) */
- virtual void SendSQLine(User *, const XLine *x) { }
- virtual void SendSQLineDel(const XLine *x) { }
+ virtual void SendSQLine(User *, XLine *x) { }
+ virtual void SendSQLineDel(XLine *x) { }
virtual void SendKill(const MessageSource &source, const Anope::string &target, const Anope::string &reason);
@@ -134,7 +145,7 @@ class CoreExport IRCDProto : public Service
/** Introduces a client to the rest of the network
* @param u The client to introduce
*/
- virtual void SendClientIntroduction(User *u) = 0;
+ virtual void SendClientIntroduction(User *u) anope_abstract;
virtual void SendKick(const MessageSource &source, const Channel *chan, User *user, const char *fmt, ...);
@@ -143,11 +154,18 @@ class CoreExport IRCDProto : public Service
virtual void SendAction(const MessageSource &source, const Anope::string &dest, const char *fmt, ...);
virtual void SendCTCP(const MessageSource &source, const Anope::string &dest, const char *fmt, ...);
- virtual void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) = 0;
- virtual void SendGlobalPrivmsg(BotInfo *bi, const Server *desc, const Anope::string &msg) = 0;
+ virtual void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) anope_abstract;
+ virtual void SendGlobalPrivmsg(ServiceBot *bi, const Server *desc, const Anope::string &msg) anope_abstract;
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.
@@ -157,7 +175,7 @@ class CoreExport IRCDProto : public Service
* be set on the user. This may include the modes in the join, but will usually place them on the mode
* stacker to be set "soon".
*/
- virtual void SendJoin(User *u, Channel *c, const ChannelStatus *status) = 0;
+ virtual void SendJoin(User *u, Channel *c, const ChannelStatus *status) anope_abstract;
virtual void SendPart(User *u, const Channel *chan, const char *fmt, ...);
/** Force joins a user that isn't ours to a channel.
@@ -181,7 +199,7 @@ class CoreExport IRCDProto : public Service
/** Sets oper flags on a user, currently only supported by Unreal
*/
- virtual void SendSVSO(BotInfo *, const Anope::string &, const Anope::string &) { }
+ virtual void SendSVSO(ServiceBot *, const Anope::string &, const Anope::string &) { }
/** Sends a nick change of one of our clients.
*/
@@ -194,8 +212,8 @@ class CoreExport IRCDProto : public Service
/** Used to introduce ourselves to our uplink. Usually will SendServer(Me) and any other
* initial handshake requirements.
*/
- virtual void SendConnect() = 0;
-
+ virtual void SendConnect() anope_abstract;
+
/** Called right before we begin our burst, after we have handshaked successfully with the uplink/
* At this point none of our servesr, users, or channels exist on the uplink
*/
@@ -209,13 +227,13 @@ class CoreExport IRCDProto : public Service
/** Introduces a server to the uplink
*/
- virtual void SendServer(const Server *) = 0;
+ virtual void SendServer(const Server *) anope_abstract;
virtual void SendSquit(Server *, const Anope::string &message);
virtual void SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...);
- virtual void SendLogin(User *u, NickAlias *na) = 0;
- virtual void SendLogout(User *u) = 0;
+ virtual void SendLogin(User *u, NickServ::Nick *na) anope_abstract;
+ virtual void SendLogout(User *u) anope_abstract;
/** Send a channel creation message to the uplink.
* On most TS6 IRCds this is a SJOIN with no nick
@@ -256,9 +274,10 @@ 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;
- BotInfo *GetBot() const;
+ ServiceBot *GetBot() const;
Server *GetServer() const;
};
@@ -275,9 +294,11 @@ class CoreExport IRCDMessage : public Service
unsigned param_count;
std::set<IRCDMessageFlag> flags;
public:
+ static constexpr const char *NAME = "IRCDMessage";
+
IRCDMessage(Module *owner, const Anope::string &n, unsigned p = 0);
unsigned GetParamCount() const;
- virtual void Run(MessageSource &, const std::vector<Anope::string> &params) = 0;
+ virtual void Run(MessageSource &, const std::vector<Anope::string> &params) anope_abstract;
void SetFlag(IRCDMessageFlag f) { flags.insert(f); }
bool HasFlag(IRCDMessageFlag f) const { return flags.count(f); }
@@ -285,4 +306,58 @@ class CoreExport IRCDMessage : public Service
extern CoreExport IRCDProto *IRCD;
-#endif // PROTOCOL_H
+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;
+ }
+};