diff options
Diffstat (limited to 'include/xline.h')
-rw-r--r-- | include/xline.h | 144 |
1 files changed, 93 insertions, 51 deletions
diff --git a/include/xline.h b/include/xline.h index 4d7885eff..208bc0145 100644 --- a/include/xline.h +++ b/include/xline.h @@ -1,64 +1,118 @@ /* + * Anope IRC Services * - * (C) 2008-2017 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2012-2017 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. + * + * 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 XLINE_H -#define XLINE_H + +#pragma once #include "serialize.h" #include "service.h" #include "sockets.h" -/* An Xline, eg, anything added with operserv/akill, or any of the operserv/sxline commands */ -class CoreExport XLine : public Serializable +/* An XLine, eg, anything added with operserv/akill, or any of the operserv/sxline commands */ +class CoreExport XLine : public Serialize::Object { - void Init(); + void Recache(); Anope::string nick, user, host, real; + + friend class XLineType; + + Serialize::Storage<Anope::string> type, mask, by, reason, id; + Serialize::Storage<time_t> created, expires; + public: - cidr *c; - Anope::string mask; - Regex *regex; - Anope::string by; - time_t created; - time_t expires; - Anope::string reason; - XLineManager *manager; - Anope::string id; - - 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 = ""); + static constexpr const char *const NAME = "xline"; + + cidr *c = nullptr; + std::regex *regex = nullptr; + + using Serialize::Object::Object; + ~XLine(); + void SetType(const Anope::string &); + Anope::string GetType(); + + void SetMask(const Anope::string &); + Anope::string GetMask(); + + void SetBy(const Anope::string &); + Anope::string GetBy(); + + void SetReason(const Anope::string &); + Anope::string GetReason(); + + void SetID(const Anope::string &); + Anope::string GetID(); + + void SetCreated(const time_t &); + time_t GetCreated(); + + void SetExpires(const time_t &); + time_t GetExpires(); + const Anope::string &GetNick() const; const Anope::string &GetUser() const; const Anope::string &GetHost() const; const Anope::string &GetReal() const; - Anope::string GetReason() const; + Anope::string GetReasonWithID(); bool HasNickOrReal() const; - bool IsRegex() const; + bool IsRegex(); - void Serialize(Serialize::Data &data) const anope_override; - static Serializable* Unserialize(Serializable *obj, Serialize::Data &data); + XLineManager *GetManager(); +}; + +class XLineType : public Serialize::Type<XLine> +{ + public: + Serialize::Field<XLine, Anope::string> type; + struct Mask : Serialize::Field<XLine, Anope::string> + { + using Serialize::Field<XLine, Anope::string>::Field; + + void OnSet(XLine *s, const Anope::string &value) override; + } mask; + Serialize::Field<XLine, Anope::string> by, reason, id; + Serialize::Field<XLine, time_t> created, expires; + + XLineType(Module *m) : Serialize::Type<XLine>(m) + , type(this, "type", &XLine::type) + , mask(this, "mask", &XLine::mask) + , by(this, "by", &XLine::by) + , reason(this, "reason", &XLine::reason) + , id(this, "id", &XLine::id) + , created(this, "created", &XLine::created) + , expires(this, "expires", &XLine::expires) + { + } }; /* Managers XLines. There is one XLineManager per type of XLine. */ class CoreExport XLineManager : public Service { char type; - /* List of XLines in this XLineManager */ - Serialize::Checker<std::vector<XLine *> > xlines; - /* Akills can have the same IDs, sometimes */ - static Serialize::Checker<std::multimap<Anope::string, XLine *, ci::less> > XLinesByUID; public: + static constexpr const char *NAME = "xlinemanager"; + /* List of XLine managers we check users against in XLineManager::CheckAll */ - static std::list<XLineManager *> XLineManagers; + static std::vector<XLineManager *> XLineManagers; /** Register a XLineManager, places it in XLineManagers for use in XLineManager::CheckAll * It is important XLineManagers are registered in the proper order. Eg, if you had one akilling @@ -95,31 +149,20 @@ class CoreExport XLineManager : public Service /** The type of xline provided by this service * @return The type */ - const char &Type(); - - /** Get the number of XLines in this XLineManager - * @return The number of XLines - */ - size_t GetCount() const; + char Type(); /** Get the XLine vector * @return The vector */ - const std::vector<XLine *> &GetList() const; + std::vector<XLine *> GetXLines() const; + + inline unsigned int GetCount() const { return GetXLines().size(); } /** Add an entry to this XLineManager * @param x The entry */ void AddXLine(XLine *x); - void RemoveXLine(XLine *); - - /** Delete an entry from this XLineManager - * @param x The entry - * @return true if the entry was found and deleted, else false - */ - bool DelXLine(XLine *x); - /** Gets an entry by index * @param index The index * @return The XLine, or NULL if the index is out of bounds @@ -156,29 +199,28 @@ class CoreExport XLineManager : public Service * @param u The user * @param x The xline */ - virtual bool Check(User *u, const XLine *x) = 0; + virtual bool Check(User *u, XLine *x) anope_abstract; /** 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) = 0; + virtual void OnMatch(User *u, XLine *x) anope_abstract; /** Called when an XLine expires * @param x The xline */ - virtual void OnExpire(const XLine *x); + virtual void OnExpire(XLine *x); /** Called to send an XLine to the IRCd * @param u The user, if we know it * @param x The xline */ - virtual void Send(User *u, XLine *x) = 0; + virtual void Send(User *u, XLine *x) anope_abstract; /** Called to remove an XLine from the IRCd * @param x The XLine */ - virtual void SendDel(XLine *x) = 0; + virtual void SendDel(XLine *x) anope_abstract; }; -#endif // XLINE_H |