anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
xline.h (5050B)
1 /* 2 * 3 * (C) 2008-2022 Anope Team 4 * Contact us at team@anope.org 5 * 6 * Please read COPYING and README for further details. 7 */ 8 9 #ifndef XLINE_H 10 #define XLINE_H 11 12 #include "serialize.h" 13 #include "service.h" 14 #include "sockets.h" 15 16 /* An Xline, eg, anything added with operserv/akill, or any of the operserv/sxline commands */ 17 class CoreExport XLine : public Serializable 18 { 19 void Init(); 20 Anope::string nick, user, host, real; 21 public: 22 cidr *c; 23 Anope::string mask; 24 Regex *regex; 25 Anope::string by; 26 time_t created; 27 time_t expires; 28 Anope::string reason; 29 XLineManager *manager; 30 Anope::string id; 31 32 XLine(const Anope::string &mask, const Anope::string &reason = "", const Anope::string &uid = ""); 33 34 XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason, const Anope::string &uid = ""); 35 ~XLine(); 36 37 const Anope::string &GetNick() const; 38 const Anope::string &GetUser() const; 39 const Anope::string &GetHost() const; 40 const Anope::string &GetReal() const; 41 42 Anope::string GetReason() const; 43 44 bool HasNickOrReal() const; 45 bool IsRegex() const; 46 47 void Serialize(Serialize::Data &data) const anope_override; 48 static Serializable* Unserialize(Serializable *obj, Serialize::Data &data); 49 }; 50 51 /* Managers XLines. There is one XLineManager per type of XLine. */ 52 class CoreExport XLineManager : public Service 53 { 54 char type; 55 /* List of XLines in this XLineManager */ 56 Serialize::Checker<std::vector<XLine *> > xlines; 57 /* Akills can have the same IDs, sometimes */ 58 static Serialize::Checker<std::multimap<Anope::string, XLine *, ci::less> > XLinesByUID; 59 public: 60 /* List of XLine managers we check users against in XLineManager::CheckAll */ 61 static std::list<XLineManager *> XLineManagers; 62 63 /** Register a XLineManager, places it in XLineManagers for use in XLineManager::CheckAll 64 * It is important XLineManagers are registered in the proper order. Eg, if you had one akilling 65 * clients and one handing them free olines, you would want the akilling one first. This way if a client 66 * matches an entry on both of the XLineManagers, they would be akilled. 67 * @param xlm THe XLineManager 68 */ 69 static void RegisterXLineManager(XLineManager *xlm); 70 71 /** Unregister a XLineManager 72 * @param xlm The XLineManager 73 */ 74 static void UnregisterXLineManager(XLineManager *xlm); 75 76 /** Check a user against all known XLineManagers 77 * Wparam u The user 78 * @return A pair of the XLineManager the user was found in and the XLine they matched, both may be NULL for no match 79 */ 80 static void CheckAll(User *u); 81 82 /** Generate a unique ID for this XLine 83 * @return A unique ID 84 */ 85 static Anope::string GenerateUID(); 86 87 /** Constructor 88 */ 89 XLineManager(Module *creator, const Anope::string &name, char t); 90 91 /** Destructor 92 */ 93 virtual ~XLineManager(); 94 95 /** The type of xline provided by this service 96 * @return The type 97 */ 98 const char &Type(); 99 100 /** Get the number of XLines in this XLineManager 101 * @return The number of XLines 102 */ 103 size_t GetCount() const; 104 105 /** Get the XLine vector 106 * @return The vector 107 */ 108 const std::vector<XLine *> &GetList() const; 109 110 /** Add an entry to this XLineManager 111 * @param x The entry 112 */ 113 void AddXLine(XLine *x); 114 115 void RemoveXLine(XLine *); 116 117 /** Delete an entry from this XLineManager 118 * @param x The entry 119 * @return true if the entry was found and deleted, else false 120 */ 121 bool DelXLine(XLine *x); 122 123 /** Gets an entry by index 124 * @param index The index 125 * @return The XLine, or NULL if the index is out of bounds 126 */ 127 XLine* GetEntry(unsigned index); 128 129 /** Clear the XLine vector 130 * Note: This does not remove the XLines from the IRCd 131 */ 132 void Clear(); 133 134 /** Checks if a mask can/should be added to the XLineManager 135 * @param source The source adding the mask. 136 * @param mask The mask 137 * @param expires When the mask would expire 138 * @param reason the reason 139 * @return true if the mask can be added 140 */ 141 bool CanAdd(CommandSource &source, const Anope::string &mask, time_t expires, const Anope::string &reason); 142 143 /** Checks if this list has an entry 144 * @param mask The mask 145 * @return The XLine the user matches, or NULL 146 */ 147 XLine* HasEntry(const Anope::string &mask); 148 149 /** Check a user against all of the xlines in this XLineManager 150 * @param u The user 151 * @return The xline the user marches, if any. 152 */ 153 XLine *CheckAllXLines(User *u); 154 155 /** Check a user against an xline 156 * @param u The user 157 * @param x The xline 158 */ 159 virtual bool Check(User *u, const XLine *x) = 0; 160 161 /** Called when a user matches a xline in this XLineManager 162 * @param u The user 163 * @param x The XLine they match 164 */ 165 virtual void OnMatch(User *u, XLine *x) = 0; 166 167 /** Called when an XLine expires 168 * @param x The xline 169 */ 170 virtual void OnExpire(const XLine *x); 171 172 /** Called to send an XLine to the IRCd 173 * @param u The user, if we know it 174 * @param x The xline 175 */ 176 virtual void Send(User *u, XLine *x) = 0; 177 178 /** Called to remove an XLine from the IRCd 179 * @param x The XLine 180 */ 181 virtual void SendDel(XLine *x) = 0; 182 }; 183 184 #endif // XLINE_H