]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/ctables.h
Command result codes. This isnt finished yet, still got to do most of the modules...
[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 };
36
37 /** A structure that defines a command
38  */
39 class command_t : public Extensible
40 {
41  protected:
42         InspIRCd* ServerInstance;
43  public:
44         /** Command name
45         */
46          std::string command;
47         /** User flags needed to execute the command or 0
48          */
49         char flags_needed;
50         /** Minimum number of parameters command takes
51         */
52         int min_params;
53         /** used by /stats m
54          */
55         long use_count;
56         /** used by /stats m
57          */
58         long total_bytes;
59         /** used for resource tracking between modules
60          */
61         std::string source;
62         /** True if the command is disabled to non-opers
63          */
64         bool disabled;
65         /** True if the command can be issued before registering
66          */
67         bool works_before_reg;
68         /** Syntax string for the command, displayed if non-empty string.
69          * This takes place of the text in the 'not enough parameters' numeric.
70          */
71         std::string syntax;
72
73         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)
74         {
75                 use_count = total_bytes = 0;
76                 source = "<core>";
77                 syntax = "";
78         }
79
80         virtual CmdResult Handle(const char** parameters, int pcnt, userrec* user) = 0;
81
82         void Disable(bool setting)
83         {
84                 disabled = setting;
85         }
86
87         bool IsDisabled()
88         {
89                 return disabled;
90         }
91
92         bool WorksBeforeReg()
93         {
94                 return works_before_reg;
95         }
96
97         virtual ~command_t() {}
98 };
99
100 typedef nspace::hash_map<std::string,command_t*> command_table;
101
102 #endif