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 
27 enum CmdResult
28 {
30  CMD_FAILURE = 0,
31 
33  CMD_SUCCESS = 1,
34 
35  /* The command does not exist. */
36  CMD_INVALID = 2
37 };
38 
40 const char FLAG_SERVERONLY = 7; // technically anything nonzero below 'A' works
41 
47 enum TranslateType
48 {
49  TR_TEXT, /* Raw text, leave as-is */
50  TR_NICK, /* Nickname, translate to UUID for server->server */
51  TR_CUSTOM /* Custom translation handled by EncodeParameter/DecodeParameter */
52 };
53 
59 enum RouteType
60 {
61  ROUTE_TYPE_LOCALONLY,
62  ROUTE_TYPE_BROADCAST,
63  ROUTE_TYPE_UNICAST,
64  ROUTE_TYPE_MESSAGE,
65  ROUTE_TYPE_OPT_BCAST,
66  ROUTE_TYPE_OPT_UCAST
67 };
68 
73 {
76  RouteType type;
79  std::string serverdest;
80 
84 
87  RouteDescriptor(RouteType t, const std::string &d)
88  : type(t), serverdest(d), server(NULL) { }
89 
90  RouteDescriptor(RouteType t, Server* srv)
91  : type(t), server(srv) { }
92 };
93 
95 #define ROUTE_LOCALONLY (RouteDescriptor(ROUTE_TYPE_LOCALONLY, ""))
96 
97 #define ROUTE_BROADCAST (RouteDescriptor(ROUTE_TYPE_BROADCAST, ""))
98 
99 #define ROUTE_UNICAST(x) (RouteDescriptor(ROUTE_TYPE_UNICAST, x))
100 
101 #define ROUTE_MESSAGE(x) (RouteDescriptor(ROUTE_TYPE_MESSAGE, x))
102 
103 #define ROUTE_OPT_BCAST (RouteDescriptor(ROUTE_TYPE_OPT_BCAST, ""))
104 
105 #define ROUTE_OPT_UCAST(x) (RouteDescriptor(ROUTE_TYPE_OPT_UCAST, x))
106 
110 class CoreExport CommandBase : public ServiceProvider
111 {
112  public:
115  unsigned char flags_needed;
116 
119  const unsigned int min_params;
120 
125  const unsigned int max_params;
126 
129  unsigned long use_count;
130 
133  bool disabled;
134 
138 
147 
151  std::string syntax;
152 
156  std::vector<TranslateType> translation;
157 
160  unsigned int Penalty;
161 
169  CommandBase(Module* me, const std::string& cmd, unsigned int minpara = 0, unsigned int maxpara = 0);
170 
171  virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
172 
178  virtual void EncodeParameter(std::string& parameter, unsigned int index);
179 
183  void Disable(bool setting)
184  {
185  disabled = setting;
186  }
187 
192  bool IsDisabled()
193  {
194  return disabled;
195  }
196 
200  {
201  return works_before_reg;
202  }
203 
204  virtual ~CommandBase();
205 };
206 
207 class CoreExport Command : public CommandBase
208 {
209  public:
214 
215  Command(Module* me, const std::string& cmd, unsigned int minpara = 0, unsigned int maxpara = 0);
216 
222  virtual CmdResult Handle(const std::vector<std::string>& parameters, User* user) = 0;
223 
226  void RegisterService() CXX11_OVERRIDE;
227 
231  ~Command();
232 };
233 
234 class CoreExport SplitCommand : public Command
235 {
236  public:
237  SplitCommand(Module* me, const std::string &cmd, unsigned int minpara = 0, unsigned int maxpara = 0)
238  : Command(me, cmd, minpara, maxpara) {}
239  CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
240  virtual CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user);
241  virtual CmdResult HandleRemote(const std::vector<std::string>& parameters, RemoteUser* user);
242  virtual CmdResult HandleServer(const std::vector<std::string>& parameters, FakeUser* user);
243 };
244 
247 #define TRANSLATE1(x1) translation.push_back(x1);
248 #define TRANSLATE2(x1,x2) translation.push_back(x1);translation.push_back(x2);
249 #define TRANSLATE3(x1,x2,x3) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);
250 #define TRANSLATE4(x1,x2,x3,x4) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);
251 #define TRANSLATE5(x1,x2,x3,x4,x5) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
252  translation.push_back(x5);
253 #define TRANSLATE6(x1,x2,x3,x4,x5,x6) 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);
255 #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);\
256  translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);
257 #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);\
258  translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);translation.push_back(x8);
std::vector< TranslateType > translation
Definition: ctables.h:156
Definition: server.h:22
bool force_manual_route
Definition: ctables.h:213
bool allow_empty_last_param
Definition: ctables.h:146
RouteType type
Definition: ctables.h:76
void Disable(bool setting)
Definition: ctables.h:183
Definition: users.h:224
Definition: ctables.h:207
Definition: users.h:751
unsigned int Penalty
Definition: ctables.h:160
Definition: ctables.h:72
Definition: ctables.h:234
Definition: users.h:895
const unsigned int min_params
Definition: ctables.h:119
bool WorksBeforeReg()
Definition: ctables.h:199
virtual void RegisterService()
Definition: base.cpp:98
Definition: ctables.h:110
Definition: modules.h:239
unsigned long use_count
Definition: ctables.h:129
Definition: users.h:903
Server * server
Definition: ctables.h:83
const unsigned int max_params
Definition: ctables.h:125
bool IsDisabled()
Definition: ctables.h:192
std::string syntax
Definition: ctables.h:151
Definition: base.h:244
unsigned char flags_needed
Definition: ctables.h:115
RouteDescriptor(RouteType t, const std::string &d)
Definition: ctables.h:87
bool disabled
Definition: ctables.h:133
std::string serverdest
Definition: ctables.h:79
bool works_before_reg
Definition: ctables.h:137