]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/commands.h
3047e7e60960ca99089af45a2d6949af416c5e63
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / commands.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #pragma once
21
22 #include "servercommand.h"
23 #include "commandbuilder.h"
24
25 /** Handle /RCONNECT
26  */
27 class CommandRConnect : public Command
28 {
29  public:
30         CommandRConnect(Module* Creator);
31         CmdResult Handle(const std::vector<std::string>& parameters, User* user);
32         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
33 };
34
35 class CommandRSQuit : public Command
36 {
37  public:
38         CommandRSQuit(Module* Creator);
39         CmdResult Handle(const std::vector<std::string>& parameters, User* user);
40         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
41 };
42
43 class CommandMap : public Command
44 {
45  public:
46         CommandMap(Module* Creator);
47         CmdResult Handle(const std::vector<std::string>& parameters, User* user);
48         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
49 };
50
51 class CommandSVSJoin : public ServerCommand
52 {
53  public:
54         CommandSVSJoin(Module* Creator) : ServerCommand(Creator, "SVSJOIN", 2) { }
55         CmdResult Handle(User* user, std::vector<std::string>& params);
56         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
57 };
58
59 class CommandSVSPart : public ServerCommand
60 {
61  public:
62         CommandSVSPart(Module* Creator) : ServerCommand(Creator, "SVSPART", 2) { }
63         CmdResult Handle(User* user, std::vector<std::string>& params);
64         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
65 };
66
67 class CommandSVSNick : public ServerCommand
68 {
69  public:
70         CommandSVSNick(Module* Creator) : ServerCommand(Creator, "SVSNICK", 3) { }
71         CmdResult Handle(User* user, std::vector<std::string>& params);
72         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
73 };
74
75 class CommandMetadata : public ServerCommand
76 {
77  public:
78         CommandMetadata(Module* Creator) : ServerCommand(Creator, "METADATA", 2) { }
79         CmdResult Handle(User* user, std::vector<std::string>& params);
80
81         class Builder : public CmdBuilder
82         {
83          public:
84                 Builder(User* user, const std::string& key, const std::string& val);
85                 Builder(Channel* chan, const std::string& key, const std::string& val);
86                 Builder(const std::string& key, const std::string& val);
87         };
88 };
89
90 class CommandUID : public ServerOnlyServerCommand<CommandUID>
91 {
92  public:
93         CommandUID(Module* Creator) : ServerOnlyServerCommand<CommandUID>(Creator, "UID", 10) { }
94         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& params);
95
96         class Builder : public CmdBuilder
97         {
98          public:
99                 Builder(User* user);
100         };
101 };
102
103 class CommandOpertype : public UserOnlyServerCommand<CommandOpertype>
104 {
105  public:
106         CommandOpertype(Module* Creator) : UserOnlyServerCommand<CommandOpertype>(Creator, "OPERTYPE", 1) { }
107         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
108
109         class Builder : public CmdBuilder
110         {
111          public:
112                 Builder(User* user);
113         };
114 };
115
116 class TreeSocket;
117 class CommandFJoin : public ServerCommand
118 {
119         /** Remove all modes from a channel, including statusmodes (+qaovh etc), simplemodes, parameter modes.
120          * This does not update the timestamp of the target channel, this must be done seperately.
121          */
122         static void RemoveStatus(Channel* c);
123         static void ApplyModeStack(User* srcuser, Channel* c, irc::modestacker& stack);
124
125         /**
126          * Lowers the TS on the given channel: removes all modes, unsets all extensions,
127          * clears the topic and removes all pending invites.
128          * @param chan The target channel whose TS to lower
129          * @param TS The new TS to set
130          * @param newname The new name of the channel; must be the same or a case change of the current name
131          */
132         static void LowerTS(Channel* chan, time_t TS, const std::string& newname);
133         void ProcessModeUUIDPair(const std::string& item, TreeServer* sourceserver, Channel* chan, irc::modestacker* modestack);
134  public:
135         CommandFJoin(Module* Creator) : ServerCommand(Creator, "FJOIN", 3) { }
136         CmdResult Handle(User* user, std::vector<std::string>& params);
137
138         class Builder : public CmdBuilder
139         {
140                 /** Maximum possible Membership::Id length in decimal digits, used for determining whether a user will fit into
141                  * a message or not
142                  */
143                 static const size_t membid_max_digits = 20;
144                 static const size_t maxline = 480;
145                 std::string::size_type pos;
146
147          public:
148                 Builder(Channel* chan);
149                 void add(Membership* memb);
150                 bool has_room(Membership* memb) const;
151                 void clear();
152                 const std::string& finalize();
153         };
154 };
155
156 class CommandFMode : public ServerCommand
157 {
158  public:
159         CommandFMode(Module* Creator) : ServerCommand(Creator, "FMODE", 3) { }
160         CmdResult Handle(User* user, std::vector<std::string>& params);
161 };
162
163 class CommandFTopic : public ServerCommand
164 {
165  public:
166         CommandFTopic(Module* Creator) : ServerCommand(Creator, "FTOPIC", 4, 5) { }
167         CmdResult Handle(User* user, std::vector<std::string>& params);
168
169         class Builder : public CmdBuilder
170         {
171          public:
172                 Builder(Channel* chan);
173                 Builder(User* user, Channel* chan);
174         };
175 };
176
177 class CommandFHost : public UserOnlyServerCommand<CommandFHost>
178 {
179  public:
180         CommandFHost(Module* Creator) : UserOnlyServerCommand<CommandFHost>(Creator, "FHOST", 1) { }
181         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
182 };
183
184 class CommandFIdent : public UserOnlyServerCommand<CommandFIdent>
185 {
186  public:
187         CommandFIdent(Module* Creator) : UserOnlyServerCommand<CommandFIdent>(Creator, "FIDENT", 1) { }
188         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
189 };
190
191 class CommandFName : public UserOnlyServerCommand<CommandFName>
192 {
193  public:
194         CommandFName(Module* Creator) : UserOnlyServerCommand<CommandFName>(Creator, "FNAME", 1) { }
195         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
196 };
197
198 class CommandIJoin : public UserOnlyServerCommand<CommandIJoin>
199 {
200  public:
201         CommandIJoin(Module* Creator) : UserOnlyServerCommand<CommandIJoin>(Creator, "IJOIN", 2) { }
202         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
203 };
204
205 class CommandResync : public ServerOnlyServerCommand<CommandResync>
206 {
207  public:
208         CommandResync(Module* Creator) : ServerOnlyServerCommand<CommandResync>(Creator, "RESYNC", 1) { }
209         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
210         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_LOCALONLY; }
211 };
212
213 class CommandAway : public UserOnlyServerCommand<CommandAway>
214 {
215  public:
216         CommandAway(Module* Creator) : UserOnlyServerCommand<CommandAway>(Creator, "AWAY", 0, 2) { }
217         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
218
219         class Builder : public CmdBuilder
220         {
221          public:
222                 Builder(User* user);
223                 Builder(User* user, const std::string& msg);
224         };
225 };
226
227 class XLine;
228 class CommandAddLine : public ServerCommand
229 {
230  public:
231         CommandAddLine(Module* Creator) : ServerCommand(Creator, "ADDLINE", 6, 6) { }
232         CmdResult Handle(User* user, std::vector<std::string>& parameters);
233
234         class Builder : public CmdBuilder
235         {
236          public:
237                 Builder(XLine* xline, User* user = ServerInstance->FakeClient);
238         };
239 };
240
241 class CommandDelLine : public ServerCommand
242 {
243  public:
244         CommandDelLine(Module* Creator) : ServerCommand(Creator, "DELLINE", 2, 2) { }
245         CmdResult Handle(User* user, std::vector<std::string>& parameters);
246 };
247
248 class CommandEncap : public ServerCommand
249 {
250  public:
251         CommandEncap(Module* Creator) : ServerCommand(Creator, "ENCAP", 2) { }
252         CmdResult Handle(User* user, std::vector<std::string>& parameters);
253         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
254 };
255
256 class CommandIdle : public UserOnlyServerCommand<CommandIdle>
257 {
258  public:
259         CommandIdle(Module* Creator) : UserOnlyServerCommand<CommandIdle>(Creator, "IDLE", 1) { }
260         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
261         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
262 };
263
264 class CommandNick : public UserOnlyServerCommand<CommandNick>
265 {
266  public:
267         CommandNick(Module* Creator) : UserOnlyServerCommand<CommandNick>(Creator, "NICK", 2) { }
268         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
269 };
270
271 class CommandPing : public ServerCommand
272 {
273  public:
274         CommandPing(Module* Creator) : ServerCommand(Creator, "PING", 1) { }
275         CmdResult Handle(User* user, std::vector<std::string>& parameters);
276         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
277 };
278
279 class CommandPong : public ServerOnlyServerCommand<CommandPong>
280 {
281  public:
282         CommandPong(Module* Creator) : ServerOnlyServerCommand<CommandPong>(Creator, "PONG", 1) { }
283         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
284         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
285 };
286
287 class CommandPush : public ServerCommand
288 {
289  public:
290         CommandPush(Module* Creator) : ServerCommand(Creator, "PUSH", 2) { }
291         CmdResult Handle(User* user, std::vector<std::string>& parameters);
292         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
293 };
294
295 class CommandSave : public ServerCommand
296 {
297  public:
298         CommandSave(Module* Creator) : ServerCommand(Creator, "SAVE", 2) { }
299         CmdResult Handle(User* user, std::vector<std::string>& parameters);
300 };
301
302 class CommandServer : public ServerOnlyServerCommand<CommandServer>
303 {
304  public:
305         CommandServer(Module* Creator) : ServerOnlyServerCommand<CommandServer>(Creator, "SERVER", 5) { }
306         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
307
308         class Builder : public CmdBuilder
309         {
310          public:
311                 Builder(TreeServer* server);
312         };
313 };
314
315 class CommandSQuit : public ServerOnlyServerCommand<CommandSQuit>
316 {
317  public:
318         CommandSQuit(Module* Creator) : ServerOnlyServerCommand<CommandSQuit>(Creator, "SQUIT", 2) { }
319         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
320 };
321
322 class CommandSNONotice : public ServerCommand
323 {
324  public:
325         CommandSNONotice(Module* Creator) : ServerCommand(Creator, "SNONOTICE", 2) { }
326         CmdResult Handle(User* user, std::vector<std::string>& parameters);
327 };
328
329 class CommandBurst : public ServerOnlyServerCommand<CommandBurst>
330 {
331  public:
332         CommandBurst(Module* Creator) : ServerOnlyServerCommand<CommandBurst>(Creator, "BURST") { }
333         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
334 };
335
336 class CommandEndBurst : public ServerOnlyServerCommand<CommandEndBurst>
337 {
338  public:
339         CommandEndBurst(Module* Creator) : ServerOnlyServerCommand<CommandEndBurst>(Creator, "ENDBURST") { }
340         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
341 };
342
343 class CommandSInfo : public ServerOnlyServerCommand<CommandSInfo>
344 {
345  public:
346         CommandSInfo(Module* Creator) : ServerOnlyServerCommand<CommandSInfo>(Creator, "SINFO", 2) { }
347         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
348
349         class Builder : public CmdBuilder
350         {
351          public:
352                 Builder(TreeServer* server, const char* type, const std::string& value);
353         };
354 };
355
356 class SpanningTreeCommands
357 {
358  public:
359         CommandSVSJoin svsjoin;
360         CommandSVSPart svspart;
361         CommandSVSNick svsnick;
362         CommandMetadata metadata;
363         CommandUID uid;
364         CommandOpertype opertype;
365         CommandFJoin fjoin;
366         CommandIJoin ijoin;
367         CommandResync resync;
368         CommandFMode fmode;
369         CommandFTopic ftopic;
370         CommandFHost fhost;
371         CommandFIdent fident;
372         CommandFName fname;
373         CommandAway away;
374         CommandAddLine addline;
375         CommandDelLine delline;
376         CommandEncap encap;
377         CommandIdle idle;
378         CommandNick nick;
379         CommandPing ping;
380         CommandPong pong;
381         CommandPush push;
382         CommandSave save;
383         CommandServer server;
384         CommandSQuit squit;
385         CommandSNONotice snonotice;
386         CommandBurst burst;
387         CommandEndBurst endburst;
388         CommandSInfo sinfo;
389         SpanningTreeCommands(ModuleSpanningTree* module);
390 };