]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/xline.h
Fix (?) stats chars
[user/henk/code/inspircd.git] / include / xline.h
index b8b045fd57318ac1fa5bc9c43b5faac1c50c7a72..e395c8fbae399bf43a6106de5ee4843f22af017f 100644 (file)
@@ -343,14 +343,39 @@ class CoreExport QLine : public XLine
        char* nick;
 };
 
+/** Contains an ident and host split into two strings
+ */
+typedef std::pair<std::string, std::string> IdentHostPair;
+
+
+class CoreExport XLineFactory
+{
+ protected:
+
+       InspIRCd* ServerInstance;
+       const char type;
+
+ public:
+
+       XLineFactory(InspIRCd* Instance, const char t) : ServerInstance(Instance), type(t) { }
+       
+       virtual const char GetType() { return type; }
+
+       virtual XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask) = 0;
+
+       virtual ~XLineFactory() { }
+};
+
 /* Required forward declarations
  */
 class ServerConfig;
 class InspIRCd;
 
-/** Contains an ident and host split into two strings
- */
-typedef std::pair<std::string, std::string> IdentHostPair;
+class GLineFactory;
+class ELineFactory;
+class QLineFactory;
+class ZLineFactory;
+class KLineFactory;
 
 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
  */
@@ -371,6 +396,16 @@ class CoreExport XLineManager
 
        std::vector<XLine *> active_lines;
 
+       std::map<char, XLineFactory*> line_factory;
+
+       GLineFactory* GFact;
+       ELineFactory* EFact;
+       KLineFactory* KFact;
+       QLineFactory* QFact;
+       ZLineFactory* ZFact;
+
+       unsigned int PermLines;
+
  public:
 
        std::map<char, std::map<std::string, XLine *> > lookup_lines;
@@ -380,6 +415,8 @@ class CoreExport XLineManager
         */
        XLineManager(InspIRCd* Instance);
 
+       ~XLineManager();
+
        /** Split an ident and host into two seperate strings.
         * This allows for faster matching.
         */
@@ -391,21 +428,40 @@ class CoreExport XLineManager
        void CheckELines(std::map<std::string, XLine *> &ELines);
 
        /** Add a new GLine
-        * @param duration The duration of the line
-        * @param source The source of the line
-        * @param reason The reason for the line
-        * @param hostmask The hostmask
+        * @param line The line to be added
+        * @param user The user adding the line or NULL for the local server
         * @return True if the line was added successfully
         */
-       bool AddLine(XLine* line);
+       bool AddLine(XLine* line, User* user);
 
        /** Delete a GLine
-        * @param hostmask The host to remove
-        * @param type Type of line to remove
+        * @param hostmask The xline-specific string identifying the line, e.g. "*@foo"
+        * @param type The type of xline
+        * @param user The user removing the line or NULL if its the local server
         * @param simulate If this is true, don't actually remove the line, just return
         * @return True if the line was deleted successfully
         */
-       bool DelLine(const char* hostmask, char type, bool simulate = false);
+       bool DelLine(const char* hostmask, char type, User* user, bool simulate = false);
+
+       /** Registers an xline factory.
+        * An xline factory is a class which when given a particular xline type,
+        * will generate a new XLine specialized to that type. For example if you
+        * pass the XLineFactory that handles glines some data it will return a
+        * pointer to a GLine, polymorphically represented as XLine. This is used where
+        * you do not know the full details of the item you wish to create, e.g. in a 
+        * server protocol module like m_spanningtree, when you receive xlines from other
+        * servers.
+        */
+       bool RegisterFactory(XLineFactory* xlf);
+
+       /** Unregisters an xline factory
+        */
+       bool UnregisterFactory(XLineFactory* xlf);
+
+       /** Get the XLineFactory for a specific type.
+        * Returns NULL if there is no known handler for this xline type
+        */
+       XLineFactory* GetFactory(const char type);
 
        /** Check if a nickname matches a QLine
         * @return nick The nick to check against
@@ -445,29 +501,12 @@ class CoreExport XLineManager
         */
        void ApplyLines();
 
-       /** Handle /STATS K
+       /** Handle /STATS for a given type.
+        * @param numeric The numeric to give to each result line
         * @param user The username making the query
         * @param results The string_list to receive the results
         */
-       void stats_k(User* user, string_list &results);
-
-       /** Handle /STATS G
-        * @param user The username making the query
-        * @param results The string_list to receive the results
-        */
-       void stats_g(User* user, string_list &results);
-
-       /** Handle /STATS Q
-        * @param user The username making the query
-        * @param results The string_list to receive the results
-        */
-       void stats_q(User* user, string_list &results);
-
-       /** Handle /STATS Z
-        * @param user The username making the query
-        * @param results The string_list to receive the results
-        */
-       void stats_z(User* user, string_list &results);
+       void InvokeStats(const char type, int numeric, User* user, string_list &results);
 
        /** Handle /STATS E
         * @param user The username making the query
@@ -500,5 +539,62 @@ class CoreExport XLineManager
        void eline_set_creation_time(const char* host, time_t create_time);
 };
 
-#endif
+class CoreExport GLineFactory : public XLineFactory
+{
+ public:
+       GLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'G') { }
+
+       XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+       {
+               IdentHostPair ih = ServerInstance->XLines->IdentSplit(xline_specific_mask);
+               return new GLine(ServerInstance, set_time, duration, source, reason, ih.first.c_str(), ih.second.c_str());
+       }
+};
+
+class CoreExport ELineFactory : public XLineFactory
+{
+ public:
+       ELineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'E') { }
+
+       XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+       {
+               IdentHostPair ih = ServerInstance->XLines->IdentSplit(xline_specific_mask);
+               return new ELine(ServerInstance, set_time, duration, source, reason, ih.first.c_str(), ih.second.c_str());
+       }
+};
+
+class CoreExport KLineFactory : public XLineFactory
+{
+ public:
+        KLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'K') { }
+
+        XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+        {
+                IdentHostPair ih = ServerInstance->XLines->IdentSplit(xline_specific_mask);
+                return new KLine(ServerInstance, set_time, duration, source, reason, ih.first.c_str(), ih.second.c_str());
+        }
+};
+
+class CoreExport QLineFactory : public XLineFactory
+{
+ public:
+        QLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'Q') { }
+
+        XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+        {
+                return new QLine(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
+        }
+};
 
+class CoreExport ZLineFactory : public XLineFactory
+{
+ public:
+        ZLineFactory(InspIRCd* Instance) : XLineFactory(Instance, 'Z') { }
+
+        XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+        {
+                return new ZLine(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
+        }
+};
+
+#endif