InspIRCd  3.0
ctables.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  * Copyright (C) 2008 Robin Burchell <[email protected]>
6  * Copyright (C) 2008 Thomas Stagner <[email protected]>
7  * Copyright (C) 2007 Dennis Friis <[email protected]>
8  * Copyright (C) 2003, 2007 Craig Edwards <[email protected]>
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 #pragma once
25 
28 enum CmdResult
29 {
30  CMD_FAILURE = 0, /* Command exists, but failed */
31  CMD_SUCCESS = 1, /* Command exists, and succeeded */
32  CMD_INVALID = 2, /* Command doesnt exist at all! */
33  CMD_EPERM = 3 /* Command failed because of a permission check */
34 };
35 
37 const char FLAG_SERVERONLY = 7; // technically anything nonzero below 'A' works
38 
44 enum TranslateType
45 {
46  TR_TEXT, /* Raw text, leave as-is */
47  TR_NICK, /* Nickname, translate to UUID for server->server */
48  TR_CUSTOM /* Custom translation handled by EncodeParameter/DecodeParameter */
49 };
50 
56 enum RouteType
57 {
58  ROUTE_TYPE_LOCALONLY,
59  ROUTE_TYPE_BROADCAST,
60  ROUTE_TYPE_UNICAST,
61  ROUTE_TYPE_MESSAGE,
62  ROUTE_TYPE_OPT_BCAST,
63  ROUTE_TYPE_OPT_UCAST
64 };
65 
70 {
73  RouteType type;
76  std::string serverdest;
77 
81 
84  RouteDescriptor(RouteType t, const std::string &d)
85  : type(t), serverdest(d), server(NULL) { }
86 
87  RouteDescriptor(RouteType t, Server* srv)
88  : type(t), server(srv) { }
89 };
90 
92 #define ROUTE_LOCALONLY (RouteDescriptor(ROUTE_TYPE_LOCALONLY, ""))
93 
94 #define ROUTE_BROADCAST (RouteDescriptor(ROUTE_TYPE_BROADCAST, ""))
95 
96 #define ROUTE_UNICAST(x) (RouteDescriptor(ROUTE_TYPE_UNICAST, x))
97 
98 #define ROUTE_MESSAGE(x) (RouteDescriptor(ROUTE_TYPE_MESSAGE, x))
99 
100 #define ROUTE_OPT_BCAST (RouteDescriptor(ROUTE_TYPE_OPT_BCAST, ""))
101 
102 #define ROUTE_OPT_UCAST(x) (RouteDescriptor(ROUTE_TYPE_OPT_UCAST, x))
103 
107 class CoreExport CommandBase : public ServiceProvider
108 {
109  public:
113 
116  const unsigned int min_params;
117 
122  const unsigned int max_params;
123 
126  unsigned long use_count;
127 
130  bool disabled;
131 
135 
144 
148  std::string syntax;
149 
153  std::vector<TranslateType> translation;
154 
157  int Penalty;
158 
166  CommandBase(Module* me, const std::string& cmd, unsigned int minpara = 0, unsigned int maxpara = 0);
167 
168  virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
169 
175  virtual void EncodeParameter(std::string& parameter, int index);
176 
180  void Disable(bool setting)
181  {
182  disabled = setting;
183  }
184 
189  bool IsDisabled()
190  {
191  return disabled;
192  }
193 
197  {
198  return works_before_reg;
199  }
200 
201  virtual ~CommandBase();
202 };
203 
204 class CoreExport Command : public CommandBase
205 {
206  public:
211 
212  Command(Module* me, const std::string& cmd, unsigned int minpara = 0, unsigned int maxpara = 0);
213 
219  virtual CmdResult Handle(const std::vector<std::string>& parameters, User* user) = 0;
220 
223  void RegisterService() CXX11_OVERRIDE;
224 
228  ~Command();
229 };
230 
231 class CoreExport SplitCommand : public Command
232 {
233  public:
234  SplitCommand(Module* me, const std::string &cmd, int minpara = 0, int maxpara = 0)
235  : Command(me, cmd, minpara, maxpara) {}
236  virtual CmdResult Handle(const std::vector<std::string>& parameters, User* user);
237  virtual CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user);
238  virtual CmdResult HandleRemote(const std::vector<std::string>& parameters, RemoteUser* user);
239  virtual CmdResult HandleServer(const std::vector<std::string>& parameters, FakeUser* user);
240 };
241 
244 #define TRANSLATE1(x1) translation.push_back(x1);
245 #define TRANSLATE2(x1,x2) translation.push_back(x1);translation.push_back(x2);
246 #define TRANSLATE3(x1,x2,x3) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);
247 #define TRANSLATE4(x1,x2,x3,x4) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);
248 #define TRANSLATE5(x1,x2,x3,x4,x5) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
249  translation.push_back(x5);
250 #define TRANSLATE6(x1,x2,x3,x4,x5,x6) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
251  translation.push_back(x5);translation.push_back(x6);
252 #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);\
253  translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);
254 #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);\
255  translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);translation.push_back(x8);
std::vector< TranslateType > translation
Definition: ctables.h:153
Definition: server.h:22
bool force_manual_route
Definition: ctables.h:210
bool allow_empty_last_param
Definition: ctables.h:143
RouteType type
Definition: ctables.h:73
char flags_needed
Definition: ctables.h:112
void Disable(bool setting)
Definition: ctables.h:180
Definition: users.h:224
Definition: ctables.h:204
Definition: users.h:742
Definition: ctables.h:69
Definition: ctables.h:231
Definition: users.h:886
const unsigned int min_params
Definition: ctables.h:116
bool WorksBeforeReg()
Definition: ctables.h:196
Definition: ctables.h:107
int Penalty
Definition: ctables.h:157
Definition: modules.h:245
unsigned long use_count
Definition: ctables.h:126
Definition: users.h:894
Server * server
Definition: ctables.h:80
const unsigned int max_params
Definition: ctables.h:122
bool IsDisabled()
Definition: ctables.h:189
std::string syntax
Definition: ctables.h:148
Definition: base.h:244
RouteDescriptor(RouteType t, const std::string &d)
Definition: ctables.h:84
bool disabled
Definition: ctables.h:130
std::string serverdest
Definition: ctables.h:76
bool works_before_reg
Definition: ctables.h:134