]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/ctables.h
003d512e8d79ed2fa894af165e5ca9958890e7ec
[user/henk/code/inspircd.git] / include / ctables.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16  
17 #ifndef __CTABLES_H__
18 #define __CTABLES_H__
19
20
21 #include "inspircd_config.h"
22 #include "hash_map.h"
23 #include "base.h"
24
25 class userrec;
26 class InspIRCd;
27
28 /** Used to indicate command success codes
29  */
30 enum CmdResult
31 {
32         CMD_FAILURE = 0,        /* Command exists, but failed */
33         CMD_SUCCESS = 1,        /* Command exists, and succeeded */
34         CMD_INVALID = 2,        /* Command doesnt exist at all! */
35         CMD_USER_DELETED = 3,   /* User was deleted! */
36 };
37
38 /** A structure that defines a command
39  */
40 class command_t : public Extensible
41 {
42  protected:
43         InspIRCd* ServerInstance;
44  public:
45         /** Command name
46         */
47          std::string command;
48         /** User flags needed to execute the command or 0
49          */
50         char flags_needed;
51         /** Minimum number of parameters command takes
52         */
53         int min_params;
54         /** used by /stats m
55          */
56         long use_count;
57         /** used by /stats m
58          */
59         long total_bytes;
60         /** used for resource tracking between modules
61          */
62         std::string source;
63         /** True if the command is disabled to non-opers
64          */
65         bool disabled;
66         /** True if the command can be issued before registering
67          */
68         bool works_before_reg;
69         /** Syntax string for the command, displayed if non-empty string.
70          * This takes place of the text in the 'not enough parameters' numeric.
71          */
72         std::string syntax;
73
74         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)
75         {
76                 use_count = total_bytes = 0;
77                 source = "<core>";
78                 syntax = "";
79         }
80
81         virtual CmdResult Handle(const char** parameters, int pcnt, userrec* user) = 0;
82
83         virtual CmdResult HandleServer(const char** parameters, int pcnt, const std::string &servername)
84         {
85                 return CMD_INVALID;
86         }
87
88         void Disable(bool setting)
89         {
90                 disabled = setting;
91         }
92
93         bool IsDisabled()
94         {
95                 return disabled;
96         }
97
98         bool WorksBeforeReg()
99         {
100                 return works_before_reg;
101         }
102
103         virtual ~command_t() {}
104 };
105
106 typedef nspace::hash_map<std::string,command_t*> command_table;
107
108 #endif