]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/ctables.h
Add counter system for umodes to get rid of some O(n)
[user/henk/code/inspircd.git] / include / ctables.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13  
14 #ifndef __CTABLES_H__
15 #define __CTABLES_H__
16
17
18 #include "inspircd_config.h"
19 #include "hash_map.h"
20 #include "base.h"
21
22 class userrec;
23 class InspIRCd;
24
25 /** Used to indicate command success codes
26  */
27 enum CmdResult
28 {
29         CMD_FAILURE = 0,        /* Command exists, but failed */
30         CMD_SUCCESS = 1,        /* Command exists, and succeeded */
31         CMD_INVALID = 2,        /* Command doesnt exist at all! */
32         CMD_USER_DELETED = 3,   /* User was deleted! */
33 };
34
35 /* For commands which should not be replicated to other
36  * servers, we usually return CMD_FAILURE. this isnt readable,
37  * so we define this alias for CMD_FAILURE called
38  * CMD_LOCALONLY, which of course does the same thing but is
39  * much more readable.
40  */
41 #define CMD_LOCALONLY CMD_FAILURE
42
43
44 /** A structure that defines a command
45  */
46 class command_t : public Extensible
47 {
48  protected:
49         InspIRCd* ServerInstance;
50  public:
51         /** Command name
52         */
53          std::string command;
54         /** User flags needed to execute the command or 0
55          */
56         char flags_needed;
57         /** Minimum number of parameters command takes
58         */
59         int min_params;
60         /** used by /stats m
61          */
62         long use_count;
63         /** used by /stats m
64          */
65         long total_bytes;
66         /** used for resource tracking between modules
67          */
68         std::string source;
69         /** True if the command is disabled to non-opers
70          */
71         bool disabled;
72         /** True if the command can be issued before registering
73          */
74         bool works_before_reg;
75         /** Syntax string for the command, displayed if non-empty string.
76          * This takes place of the text in the 'not enough parameters' numeric.
77          */
78         std::string syntax;
79
80         command_t(InspIRCd* Instance, const std::string &cmd, char flags, int minpara, int before_reg = false) : ServerInstance(Instance), command(cmd), flags_needed(flags), min_params(minpara), disabled(false), works_before_reg(before_reg)
81         {
82                 use_count = total_bytes = 0;
83                 source = "<core>";
84                 syntax = "";
85         }
86
87         virtual CmdResult Handle(const char** parameters, int pcnt, userrec* user) = 0;
88
89         virtual CmdResult HandleServer(const char** parameters, int pcnt, const std::string &servername)
90         {
91                 return CMD_INVALID;
92         }
93
94         void Disable(bool setting)
95         {
96                 disabled = setting;
97         }
98
99         bool IsDisabled()
100         {
101                 return disabled;
102         }
103
104         bool WorksBeforeReg()
105         {
106                 return works_before_reg;
107         }
108
109         virtual ~command_t() {}
110 };
111
112 typedef nspace::hash_map<std::string,command_t*> command_table;
113
114 #endif