From 0ba58d7d0eea4e2a0e0d18a66880f84af6fea60e Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 18 Feb 2012 18:07:34 -0500 Subject: Fixed some events --- include/modules.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'include') diff --git a/include/modules.h b/include/modules.h index 1cb496a54..ce6bbba51 100644 --- a/include/modules.h +++ b/include/modules.h @@ -516,7 +516,7 @@ class CoreExport Module : public Extensible /** Called before a XLine is deleted * @param u The user deleting the XLine - * @param x The XLine, can be NULL for all XLines + * @param x The XLine * @param xlm The xline manager it was deleted from */ virtual void OnDelXLine(User *u, XLine *x, XLineManager *xlm) { } @@ -835,7 +835,6 @@ class CoreExport Module : public Extensible * @param nc The nickcore of the memo being deleted * @param mi The memo info * @param m The memo - * @param number What memo number is being deleted, can be 0 for all memos */ virtual void OnMemoDel(const NickCore *nc, MemoInfo *mi, Memo *m) { } @@ -843,7 +842,6 @@ class CoreExport Module : public Extensible * @param ci The channel of the memo being deleted * @param mi The memo info * @param m The memo - * @param number What memo number is being deleted, can be 0 for all memos */ virtual void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, Memo *m) { } -- cgit From b84e0804636d3868684c6ec2670207e7ae1cadeb Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 19 Feb 2012 20:54:55 -0500 Subject: Made our message sources actual clients/servers, and put in a few more default messages for very standard things (KICK etc) --- include/protocol.h | 22 +++++++++++----------- include/uplink.h | 8 ++++++-- 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/protocol.h b/include/protocol.h index f1bb9dbbe..40ddb75b3 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -48,11 +48,11 @@ struct IRCDVar class CoreExport IRCDProto { - private: - virtual void SendSVSKillInternal(const BotInfo *, const User *, const Anope::string &) = 0; - virtual void SendModeInternal(const BotInfo *, const Channel *, const Anope::string &) = 0; + protected: + virtual void SendSVSKillInternal(const BotInfo *, const User *, const Anope::string &); + virtual void SendModeInternal(const BotInfo *, const Channel *, const Anope::string &); virtual void SendModeInternal(const BotInfo *, const User *, const Anope::string &) = 0; - virtual void SendKickInternal(const BotInfo *, const Channel *, const User *, const Anope::string &) = 0; + virtual void SendKickInternal(const BotInfo *, const Channel *, const User *, const Anope::string &); virtual void SendMessageInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf); virtual void SendNoticeInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &msg); virtual void SendPrivmsgInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf); @@ -60,12 +60,12 @@ class CoreExport IRCDProto virtual void SendPartInternal(const BotInfo *bi, const Channel *chan, const Anope::string &buf); virtual void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf); virtual void SendCTCPInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf); - virtual void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf); + virtual void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf); public: virtual ~IRCDProto() { } virtual void SendSVSNOOP(const Server *, bool) { } - virtual void SendTopic(BotInfo *, Channel *) = 0; + virtual void SendTopic(BotInfo *, Channel *); virtual void SendVhostDel(User *) { } virtual void SendAkill(User *, const XLine *) = 0; virtual void SendAkillDel(const XLine *) = 0; @@ -86,12 +86,12 @@ class CoreExport IRCDProto virtual void SendPong(const Anope::string &servname, const Anope::string &who); virtual void SendJoin(User *, Channel *, const ChannelStatus *) = 0; virtual void SendSQLineDel(const XLine *x) { } - virtual void SendInvite(const BotInfo *bi, const Anope::string &chan, const Anope::string &nick); + virtual void SendInvite(const BotInfo *bi, const Channel *c, const User *u); virtual void SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...); virtual void SendGlobops(const BotInfo *source, const char *fmt, ...); virtual void SendSQLine(User *, const XLine *x) { } virtual void SendSquit(Server *, const Anope::string &message); - virtual void SendSVSO(const Anope::string &, const Anope::string &, const Anope::string &) { } + virtual void SendSVSO(const BotInfo *, const Anope::string &, const Anope::string &) { } virtual void SendChangeBotNick(const BotInfo *bi, const Anope::string &newnick); virtual void SendForceNickChange(const User *u, const Anope::string &newnick, time_t when); virtual void SendVhost(User *, const Anope::string &, const Anope::string &) { } @@ -103,14 +103,14 @@ class CoreExport IRCDProto virtual void SendSZLine(User *u, const XLine *) { } virtual void SendSGLine(User *, const XLine *) { } virtual void SendCTCP(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); - virtual void SendSVSJoin(const Anope::string &, const Anope::string &, const Anope::string &, const Anope::string &) { } - virtual void SendSWhois(const Anope::string &, const Anope::string &, const Anope::string &) { } + virtual void SendSVSJoin(const BotInfo *bi, const Anope::string &, const Anope::string &, const Anope::string &) { } + virtual void SendSWhois(const BotInfo *bi, const Anope::string &, const Anope::string &) { } virtual void SendBOB() { } virtual void SendEOB() { } virtual void SendServer(const Server *) = 0; virtual bool IsNickValid(const Anope::string &) { return true; } virtual bool IsChannelValid(const Anope::string &); - virtual void SendNumeric(const Anope::string &source, int numeric, const Anope::string &dest, const char *fmt, ...); + virtual void SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...); virtual void SendLogin(User *u) = 0; virtual void SendLogout(User *u) = 0; diff --git a/include/uplink.h b/include/uplink.h index 7f200d426..70b20a28b 100644 --- a/include/uplink.h +++ b/include/uplink.h @@ -25,11 +25,15 @@ class UplinkSocket : public ConnectionSocket, public BufferedSocket class CoreExport Message { - Anope::string source; + private: + const Server *server; + const User *user; std::stringstream buffer; + public: Message(); - Message(const Anope::string &); + explicit Message(const Server *); + explicit Message(const User *); ~Message(); template Message &operator<<(const T &val) { -- cgit From 3850b073ddf610415de54dced9ff134397779676 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 22 Feb 2012 18:12:02 -0500 Subject: Added regex support for many commands, such as akill, sqline, snline, all of the */list commands, etc. Also extended the ability of akill to match a full nick!user@host and real name of users. --- include/anope.h | 3 ++- include/config.h | 2 ++ include/defs.h | 1 + include/module.h | 1 + include/oper.h | 38 ++++++++++++++++++++++++++------------ include/protocol.h | 2 +- include/regexpr.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 include/regexpr.h (limited to 'include') diff --git a/include/anope.h b/include/anope.h index 421d735a3..b286d0fb6 100644 --- a/include/anope.h +++ b/include/anope.h @@ -346,8 +346,9 @@ namespace Anope * @param str The string to check against the pattern (e.g. foobar) * @param mask The pattern to check (e.g. foo*bar) * @param case_sensitive Whether or not the match is case sensitive, default false. + * @param use_regex Whether or not to try regex. case_sensitive is not used in regex. */ - extern CoreExport bool Match(const string &str, const string &mask, bool case_sensitive = false); + extern CoreExport bool Match(const string &str, const string &mask, bool case_sensitive = false, bool use_regex = false); /** Find a message in the message table * @param name The name of the message were looking for diff --git a/include/config.h b/include/config.h index d53b7f41c..1ec67984a 100644 --- a/include/config.h +++ b/include/config.h @@ -456,6 +456,8 @@ class CoreExport ServerConfig bool HidePrivilegedCommands; /* If set, nicks cant be owned/everything is entirely account based */ bool NoNicknameOwnership; + /* Regex engine to use */ + Anope::string RegexEngine; /* A vector of our logfile options */ std::vector LogInfos; diff --git a/include/defs.h b/include/defs.h index 0a248daf7..098f48edd 100644 --- a/include/defs.h +++ b/include/defs.h @@ -35,6 +35,7 @@ class Module; class NickAlias; class NickCore; class OperType; +class Regex; class Server; class ServerConfig; class Socket; diff --git a/include/module.h b/include/module.h index 94f565a3a..6865a2c17 100644 --- a/include/module.h +++ b/include/module.h @@ -36,6 +36,7 @@ #include "oper.h" #include "opertype.h" #include "protocol.h" +#include "regexpr.h" #include "regchannel.h" #include "serialize.h" #include "servers.h" diff --git a/include/oper.h b/include/oper.h index ced1d38dc..b3034b7c5 100644 --- a/include/oper.h +++ b/include/oper.h @@ -14,8 +14,10 @@ class CoreExport XLine : public Serializable { + void InitRegex(); public: Anope::string Mask; + Regex *regex; Anope::string By; time_t Created; time_t Expires; @@ -25,11 +27,18 @@ class CoreExport XLine : public Serializable XLine(const Anope::string &mask, const Anope::string &reason = "", const Anope::string &uid = ""); - XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid); + XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid = ""); + ~XLine(); Anope::string GetNick() const; Anope::string GetUser() const; Anope::string GetHost() const; + Anope::string GetReal() const; + + Anope::string GetReason() const; + + bool HasNickOrReal() const; + bool IsRegex() const; Anope::string serialize_name() const; serialized_data serialize(); @@ -41,7 +50,8 @@ class CoreExport XLineManager : public Service char type; /* List of XLines in this XLineManager */ std::vector XLines; - static std::map XLinesByUID; + /* Akills can have the same IDs, sometimes */ + static std::multimap XLinesByUID; public: /* List of XLine managers we check users against in XLineManager::CheckAll */ static std::list XLineManagers; @@ -63,7 +73,7 @@ class CoreExport XLineManager : public Service * Wparam u The user * @return A pair of the XLineManager the user was found in and the XLine they matched, both may be NULL for no match */ - static std::pair CheckAll(User *u); + static void CheckAll(User *u); /** Generate a unique ID for this XLine * @return A unique ID @@ -116,15 +126,13 @@ class CoreExport XLineManager : public Service void Clear(); /** Checks if a mask can/should be added to the XLineManager + * @param source The source adding the mask. * @param mask The mask * @param expires When the mask would expire - * @return A pair of int and XLine*. - * 1 - Mask already exists - * 2 - Mask already exists, but the expiry time was changed - * 3 - Mask is already covered by another mask - * In each case the XLine it matches/is covered by is returned in XLine* + * @param reason the reason + * @return true if the mask can be added */ - std::pair CanAdd(const Anope::string &mask, time_t expires); + bool CanAdd(CommandSource &source, const Anope::string &mask, time_t expires, const Anope::string &reason); /** Checks if this list has an entry * @param mask The mask @@ -134,15 +142,21 @@ class CoreExport XLineManager : public Service /** Check a user against all of the xlines in this XLineManager * @param u The user - * @return The xline the user marches, if any. Also calls OnMatch() + * @return The xline the user marches, if any. + */ + XLine *CheckAllXLines(User *u); + + /** Check a user against an xline + * @param u The user + * @param x The xline */ - virtual XLine *Check(User *u); + virtual bool Check(User *u, XLine *x) = 0; /** Called when a user matches a xline in this XLineManager * @param u The user * @param x The XLine they match */ - virtual void OnMatch(User *u, XLine *x); + virtual void OnMatch(User *u, XLine *x) = 0; /** Called when an XLine expires * @param x The xline diff --git a/include/protocol.h b/include/protocol.h index 40ddb75b3..edfc5bd53 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -67,7 +67,7 @@ class CoreExport IRCDProto virtual void SendSVSNOOP(const Server *, bool) { } virtual void SendTopic(BotInfo *, Channel *); virtual void SendVhostDel(User *) { } - virtual void SendAkill(User *, const XLine *) = 0; + virtual void SendAkill(User *, XLine *) = 0; virtual void SendAkillDel(const XLine *) = 0; virtual void SendSVSKill(const BotInfo *source, const User *user, const char *fmt, ...); virtual void SendMode(const BotInfo *bi, const Channel *dest, const char *fmt, ...); diff --git a/include/regexpr.h b/include/regexpr.h new file mode 100644 index 000000000..a333c7e1b --- /dev/null +++ b/include/regexpr.h @@ -0,0 +1,47 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + */ + +#ifndef REGEXPR_H +#define REGEXPR_H + +#include "services.h" +#include "anope.h" +#include "service.h" + +class RegexException : public CoreException +{ + public: + RegexException(const Anope::string &reason = "") : CoreException(reason) { } + + virtual ~RegexException() throw() { } +}; + +class CoreExport Regex +{ + Anope::string expression; + protected: + Regex(const Anope::string &expr) : expression(expr) { } + public: + virtual ~Regex() { } + const Anope::string &GetExpression() { return expression; } + virtual bool Matches(const Anope::string &str) = 0; +}; + +class CoreExport RegexProvider : public Service +{ + public: + RegexProvider(Module *o, const Anope::string &n) : Service(o, "Regex", n) { } + virtual Regex *Compile(const Anope::string &) = 0; +}; + +#endif // REGEXPR_H + -- cgit