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:
114  class Params : public std::vector<std::string>
115  {
116  private:
117  /* IRCv3 message tags. */
119 
120  public:
125  Params(const std::vector<std::string>& paramsref, const ClientProtocol::TagMap& tagsref)
126  : std::vector<std::string>(paramsref)
127  , tags(tagsref)
128  {
129  }
130 
135  template<typename Iterator>
136  Params(Iterator first, Iterator last)
137  : std::vector<std::string>(first, last)
138  {
139  }
140 
142  Params() { }
143 
145  const ClientProtocol::TagMap& GetTags() const { return tags; }
146  };
147 
150  unsigned char flags_needed;
151 
154  const unsigned int min_params;
155 
160  const unsigned int max_params;
161 
164  unsigned long use_count;
165 
169 
178 
182  std::string syntax;
183 
187  std::vector<TranslateType> translation;
188 
191  unsigned int Penalty;
192 
200  CommandBase(Module* me, const std::string& cmd, unsigned int minpara = 0, unsigned int maxpara = 0);
201 
202  virtual RouteDescriptor GetRouting(User* user, const CommandBase::Params& parameters);
203 
209  virtual void EncodeParameter(std::string& parameter, unsigned int index);
210 
214  {
215  return works_before_reg;
216  }
217 
218  virtual ~CommandBase();
219 };
220 
221 class CoreExport Command : public CommandBase
222 {
223  public:
228 
229  Command(Module* me, const std::string& cmd, unsigned int minpara = 0, unsigned int maxpara = 0);
230 
236  virtual CmdResult Handle(User* user, const Params& parameters) = 0;
237 
240  void RegisterService() CXX11_OVERRIDE;
241 
245  ~Command();
246 };
247 
248 class CoreExport SplitCommand : public Command
249 {
250  public:
251  SplitCommand(Module* me, const std::string &cmd, unsigned int minpara = 0, unsigned int maxpara = 0)
252  : Command(me, cmd, minpara, maxpara) {}
253  CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
254  virtual CmdResult HandleLocal(LocalUser* user, const Params& parameters);
255  virtual CmdResult HandleRemote(RemoteUser* user, const Params& parameters);
256  virtual CmdResult HandleServer(FakeUser* user, const Params& parameters);
257 };
258 
261 #define TRANSLATE1(x1) translation.push_back(x1);
262 #define TRANSLATE2(x1,x2) translation.push_back(x1);translation.push_back(x2);
263 #define TRANSLATE3(x1,x2,x3) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);
264 #define TRANSLATE4(x1,x2,x3,x4) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);
265 #define TRANSLATE5(x1,x2,x3,x4,x5) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
266  translation.push_back(x5);
267 #define TRANSLATE6(x1,x2,x3,x4,x5,x6) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
268  translation.push_back(x5);translation.push_back(x6);
269 #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);\
270  translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);
271 #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);\
272  translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);translation.push_back(x8);
std::vector< TranslateType > translation
Definition: ctables.h:187
Definition: server.h:22
bool force_manual_route
Definition: ctables.h:227
bool allow_empty_last_param
Definition: ctables.h:177
RouteType type
Definition: ctables.h:76
Definition: users.h:224
Definition: ctables.h:221
Definition: users.h:707
unsigned int Penalty
Definition: ctables.h:191
Definition: ctables.h:72
Definition: ctables.h:248
Definition: users.h:872
const unsigned int min_params
Definition: ctables.h:154
bool WorksBeforeReg()
Definition: ctables.h:213
virtual void RegisterService()
Definition: base.cpp:98
Params(Iterator first, Iterator last)
Definition: ctables.h:136
Params(const std::vector< std::string > &paramsref, const ClientProtocol::TagMap &tagsref)
Definition: ctables.h:125
Definition: ctables.h:110
Definition: modules.h:240
unsigned long use_count
Definition: ctables.h:164
Definition: users.h:880
Server * server
Definition: ctables.h:83
const unsigned int max_params
Definition: ctables.h:160
Definition: ctables.h:114
std::string syntax
Definition: ctables.h:182
const ClientProtocol::TagMap & GetTags() const
Definition: ctables.h:145
Definition: base.h:244
Params()
Definition: ctables.h:142
unsigned char flags_needed
Definition: ctables.h:150
RouteDescriptor(RouteType t, const std::string &d)
Definition: ctables.h:87
std::string serverdest
Definition: ctables.h:79
bool works_before_reg
Definition: ctables.h:168