InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
ctables.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6  * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
7  * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8  * Copyright (C) 2003, 2007 Craig Edwards <craigedwards@brainbox.cc>
9  *
10  * This file is part of InspIRCd. InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 
24 #ifndef CTABLES_H
25 #define CTABLES_H
26 
29 enum CmdResult
30 {
31  CMD_FAILURE = 0, /* Command exists, but failed */
32  CMD_SUCCESS = 1, /* Command exists, and succeeded */
33  CMD_INVALID = 2, /* Command doesnt exist at all! */
34  CMD_EPERM = 3 /* Command failed because of a permission check */
35 };
36 
38 const char FLAG_SERVERONLY = 7; // technically anything nonzero below 'A' works
39 
45 enum TranslateType
46 {
47  TR_END, /* End of known parameters, everything after this is TR_TEXT */
48  TR_TEXT, /* Raw text, leave as-is */
49  TR_NICK, /* Nickname, translate to UUID for server->server */
50  TR_CUSTOM /* Custom translation handled by EncodeParameter/DecodeParameter */
51 };
52 
58 enum RouteType
59 {
60  ROUTE_TYPE_LOCALONLY,
61  ROUTE_TYPE_BROADCAST,
62  ROUTE_TYPE_UNICAST,
63  ROUTE_TYPE_MESSAGE,
64  ROUTE_TYPE_OPT_BCAST,
65  ROUTE_TYPE_OPT_UCAST
66 };
67 
72 {
75  RouteType type;
78  std::string serverdest;
79 
82  RouteDescriptor(RouteType t, const std::string &d)
83  : type(t), serverdest(d) { }
84 };
85 
87 #define ROUTE_LOCALONLY (RouteDescriptor(ROUTE_TYPE_LOCALONLY, ""))
88 
89 #define ROUTE_BROADCAST (RouteDescriptor(ROUTE_TYPE_BROADCAST, ""))
90 
91 #define ROUTE_UNICAST(x) (RouteDescriptor(ROUTE_TYPE_UNICAST, x))
92 
93 #define ROUTE_MESSAGE(x) (RouteDescriptor(ROUTE_TYPE_MESSAGE, x))
94 
95 #define ROUTE_OPT_BCAST (RouteDescriptor(ROUTE_TYPE_OPT_BCAST, ""))
96 
97 #define ROUTE_OPT_UCAST(x) (RouteDescriptor(ROUTE_TYPE_OPT_UCAST, x))
98 
102 class CoreExport Command : public ServiceProvider
103 {
104  public:
108 
111  const unsigned int min_params;
112 
117  const unsigned int max_params;
118 
121  unsigned long use_count;
122 
125  unsigned long total_bytes;
126 
129  bool disabled;
130 
134 
143 
147  std::string syntax;
148 
152  std::vector<TranslateType> translation;
153 
156  int Penalty;
157 
165  Command(Module* me, const std::string &cmd, int minpara = 0, int maxpara = 0) :
166  ServiceProvider(me, cmd, SERVICE_COMMAND), flags_needed(0), min_params(minpara), max_params(maxpara),
167  use_count(0), total_bytes(0), disabled(false), works_before_reg(false), allow_empty_last_param(true),
168  Penalty(1)
169  {
170  }
171 
177  virtual CmdResult Handle(const std::vector<std::string>& parameters, User* user) = 0;
178 
179  virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
180  {
181  return ROUTE_LOCALONLY;
182  }
183 
189  virtual void EncodeParameter(std::string& parameter, int index)
190  {
191  }
192 
199  virtual void DecodeParameter(std::string& parameter, int index)
200  {
201  }
202 
206  void Disable(bool setting)
207  {
208  disabled = setting;
209  }
210 
215  bool IsDisabled()
216  {
217  return disabled;
218  }
219 
223  {
224  return works_before_reg;
225  }
226 
227  virtual ~Command();
228 };
229 
230 class CoreExport SplitCommand : public Command
231 {
232  public:
233  SplitCommand(Module* me, const std::string &cmd, int minpara = 0, int maxpara = 0)
234  : Command(me, cmd, minpara, maxpara) {}
235  virtual CmdResult Handle(const std::vector<std::string>& parameters, User* user);
236  virtual CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user);
237  virtual CmdResult HandleRemote(const std::vector<std::string>& parameters, RemoteUser* user);
238  virtual CmdResult HandleServer(const std::vector<std::string>& parameters, FakeUser* user);
239 };
240 
243 #define TRANSLATE1(x1) translation.push_back(x1);
244 #define TRANSLATE2(x1,x2) translation.push_back(x1);translation.push_back(x2);
245 #define TRANSLATE3(x1,x2,x3) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);
246 #define TRANSLATE4(x1,x2,x3,x4) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);
247 #define TRANSLATE5(x1,x2,x3,x4,x5) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
248  translation.push_back(x5);
249 #define TRANSLATE6(x1,x2,x3,x4,x5,x6) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
250  translation.push_back(x5);translation.push_back(x6);
251 #define TRANSLATE7(x1,x2,x3,x4,x5,x6,x7) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
252  translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);
253 #define TRANSLATE8(x1,x2,x3,x4,x5,x6,x7,x8) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
254  translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);translation.push_back(x8);
255 
256 #endif
std::vector< TranslateType > translation
Definition: ctables.h:152
bool allow_empty_last_param
Definition: ctables.h:142
RouteType type
Definition: ctables.h:75
unsigned long total_bytes
Definition: ctables.h:125
Command(Module *me, const std::string &cmd, int minpara=0, int maxpara=0)
Definition: ctables.h:165
Definition: users.h:230
Definition: ctables.h:102
bool IsDisabled()
Definition: ctables.h:215
Definition: users.h:742
virtual void DecodeParameter(std::string &parameter, int index)
Definition: ctables.h:199
const unsigned int max_params
Definition: ctables.h:117
Definition: ctables.h:71
int Penalty
Definition: ctables.h:156
Definition: ctables.h:230
Definition: users.h:890
void Disable(bool setting)
Definition: ctables.h:206
virtual void EncodeParameter(std::string &parameter, int index)
Definition: ctables.h:189
const unsigned int min_params
Definition: ctables.h:111
char flags_needed
Definition: ctables.h:107
Definition: modules.h:350
Definition: users.h:899
virtual CmdResult Handle(const std::vector< std::string > &parameters, User *user)=0
bool WorksBeforeReg()
Definition: ctables.h:222
Definition: base.h:244
RouteDescriptor(RouteType t, const std::string &d)
Definition: ctables.h:82
unsigned long use_count
Definition: ctables.h:121
bool disabled
Definition: ctables.h:129
std::string serverdest
Definition: ctables.h:78
std::string syntax
Definition: ctables.h:147
bool works_before_reg
Definition: ctables.h:133