]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/commands.h
4810e9d4bcde2621a23130968e271874cc499920
[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 #include "remoteuser.h"
25
26 /** Handle /RCONNECT
27  */
28 class CommandRConnect : public Command
29 {
30  public:
31         CommandRConnect(Module* Creator);
32         CmdResult Handle(const std::vector<std::string>& parameters, User* user);
33         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
34 };
35
36 class CommandRSQuit : public Command
37 {
38  public:
39         CommandRSQuit(Module* Creator);
40         CmdResult Handle(const std::vector<std::string>& parameters, User* user);
41         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
42 };
43
44 class CommandMap : public Command
45 {
46  public:
47         CommandMap(Module* Creator);
48         CmdResult Handle(const std::vector<std::string>& parameters, User* user);
49         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
50 };
51
52 class CommandSVSJoin : public ServerCommand
53 {
54  public:
55         CommandSVSJoin(Module* Creator) : ServerCommand(Creator, "SVSJOIN", 2) { }
56         CmdResult Handle(User* user, std::vector<std::string>& params);
57         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
58 };
59
60 class CommandSVSPart : public ServerCommand
61 {
62  public:
63         CommandSVSPart(Module* Creator) : ServerCommand(Creator, "SVSPART", 2) { }
64         CmdResult Handle(User* user, std::vector<std::string>& params);
65         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
66 };
67
68 class CommandSVSNick : public ServerCommand
69 {
70  public:
71         CommandSVSNick(Module* Creator) : ServerCommand(Creator, "SVSNICK", 3) { }
72         CmdResult Handle(User* user, std::vector<std::string>& params);
73         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
74 };
75
76 class CommandMetadata : public ServerCommand
77 {
78  public:
79         CommandMetadata(Module* Creator) : ServerCommand(Creator, "METADATA", 2) { }
80         CmdResult Handle(User* user, std::vector<std::string>& params);
81
82         class Builder : public CmdBuilder
83         {
84          public:
85                 Builder(User* user, const std::string& key, const std::string& val);
86                 Builder(Channel* chan, const std::string& key, const std::string& val);
87                 Builder(const std::string& key, const std::string& val);
88         };
89 };
90
91 class CommandUID : public ServerOnlyServerCommand<CommandUID>
92 {
93  public:
94         CommandUID(Module* Creator) : ServerOnlyServerCommand<CommandUID>(Creator, "UID", 10) { }
95         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& params);
96
97         class Builder : public CmdBuilder
98         {
99          public:
100                 Builder(User* user);
101         };
102 };
103
104 class CommandOpertype : public UserOnlyServerCommand<CommandOpertype>
105 {
106  public:
107         CommandOpertype(Module* Creator) : UserOnlyServerCommand<CommandOpertype>(Creator, "OPERTYPE", 1) { }
108         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
109
110         class Builder : public CmdBuilder
111         {
112          public:
113                 Builder(User* user);
114         };
115 };
116
117 class TreeSocket;
118 class FwdFJoinBuilder;
119 class CommandFJoin : public ServerCommand
120 {
121         /** Remove all modes from a channel, including statusmodes (+qaovh etc), simplemodes, parameter modes.
122          * This does not update the timestamp of the target channel, this must be done seperately.
123          */
124         static void RemoveStatus(Channel* c);
125
126         /**
127          * Lowers the TS on the given channel: removes all modes, unsets all extensions,
128          * clears the topic and removes all pending invites.
129          * @param chan The target channel whose TS to lower
130          * @param TS The new TS to set
131          * @param newname The new name of the channel; must be the same or a case change of the current name
132          */
133         static void LowerTS(Channel* chan, time_t TS, const std::string& newname);
134         void ProcessModeUUIDPair(const std::string& item, TreeServer* sourceserver, Channel* chan, Modes::ChangeList* modechangelist, FwdFJoinBuilder& fwdfjoin);
135  public:
136         CommandFJoin(Module* Creator) : ServerCommand(Creator, "FJOIN", 3) { }
137         CmdResult Handle(User* user, std::vector<std::string>& params);
138         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_LOCALONLY; }
139
140         class Builder : public CmdBuilder
141         {
142                 /** Maximum possible Membership::Id length in decimal digits, used for determining whether a user will fit into
143                  * a message or not
144                  */
145                 static const size_t membid_max_digits = 20;
146                 static const size_t maxline = 510;
147                 std::string::size_type pos;
148
149         protected:
150                 void add(Membership* memb, std::string::const_iterator mbegin, std::string::const_iterator mend);
151                 bool has_room(std::string::size_type nummodes) const;
152
153          public:
154                 Builder(Channel* chan, TreeServer* source = Utils->TreeRoot);
155                 void add(Membership* memb)
156                 {
157                         add(memb, memb->modes.begin(), memb->modes.end());
158                 }
159
160                 bool has_room(Membership* memb) const
161                 {
162                         return has_room(memb->modes.size());
163                 }
164
165                 void clear();
166                 const std::string& finalize();
167         };
168 };
169
170 class CommandFMode : public ServerCommand
171 {
172  public:
173         CommandFMode(Module* Creator) : ServerCommand(Creator, "FMODE", 3) { }
174         CmdResult Handle(User* user, std::vector<std::string>& params);
175 };
176
177 class CommandFTopic : public ServerCommand
178 {
179  public:
180         CommandFTopic(Module* Creator) : ServerCommand(Creator, "FTOPIC", 4, 5) { }
181         CmdResult Handle(User* user, std::vector<std::string>& params);
182
183         class Builder : public CmdBuilder
184         {
185          public:
186                 Builder(Channel* chan);
187                 Builder(User* user, Channel* chan);
188         };
189 };
190
191 class CommandFHost : public UserOnlyServerCommand<CommandFHost>
192 {
193  public:
194         CommandFHost(Module* Creator) : UserOnlyServerCommand<CommandFHost>(Creator, "FHOST", 1) { }
195         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
196 };
197
198 class CommandFIdent : public UserOnlyServerCommand<CommandFIdent>
199 {
200  public:
201         CommandFIdent(Module* Creator) : UserOnlyServerCommand<CommandFIdent>(Creator, "FIDENT", 1) { }
202         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
203 };
204
205 class CommandFName : public UserOnlyServerCommand<CommandFName>
206 {
207  public:
208         CommandFName(Module* Creator) : UserOnlyServerCommand<CommandFName>(Creator, "FNAME", 1) { }
209         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
210 };
211
212 class CommandIJoin : public UserOnlyServerCommand<CommandIJoin>
213 {
214  public:
215         CommandIJoin(Module* Creator) : UserOnlyServerCommand<CommandIJoin>(Creator, "IJOIN", 2) { }
216         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
217 };
218
219 class CommandResync : public ServerOnlyServerCommand<CommandResync>
220 {
221  public:
222         CommandResync(Module* Creator) : ServerOnlyServerCommand<CommandResync>(Creator, "RESYNC", 1) { }
223         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
224         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_LOCALONLY; }
225 };
226
227 class CommandAway : public UserOnlyServerCommand<CommandAway>
228 {
229  public:
230         CommandAway(Module* Creator) : UserOnlyServerCommand<CommandAway>(Creator, "AWAY", 0, 2) { }
231         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
232
233         class Builder : public CmdBuilder
234         {
235          public:
236                 Builder(User* user);
237                 Builder(User* user, const std::string& msg);
238         };
239 };
240
241 class XLine;
242 class CommandAddLine : public ServerCommand
243 {
244  public:
245         CommandAddLine(Module* Creator) : ServerCommand(Creator, "ADDLINE", 6, 6) { }
246         CmdResult Handle(User* user, std::vector<std::string>& parameters);
247
248         class Builder : public CmdBuilder
249         {
250          public:
251                 Builder(XLine* xline, User* user = ServerInstance->FakeClient);
252         };
253 };
254
255 class CommandDelLine : public ServerCommand
256 {
257  public:
258         CommandDelLine(Module* Creator) : ServerCommand(Creator, "DELLINE", 2, 2) { }
259         CmdResult Handle(User* user, std::vector<std::string>& parameters);
260 };
261
262 class CommandEncap : public ServerCommand
263 {
264  public:
265         CommandEncap(Module* Creator) : ServerCommand(Creator, "ENCAP", 2) { }
266         CmdResult Handle(User* user, std::vector<std::string>& parameters);
267         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
268 };
269
270 class CommandIdle : public UserOnlyServerCommand<CommandIdle>
271 {
272  public:
273         CommandIdle(Module* Creator) : UserOnlyServerCommand<CommandIdle>(Creator, "IDLE", 1) { }
274         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
275         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
276 };
277
278 class CommandNick : public UserOnlyServerCommand<CommandNick>
279 {
280  public:
281         CommandNick(Module* Creator) : UserOnlyServerCommand<CommandNick>(Creator, "NICK", 2) { }
282         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
283 };
284
285 class CommandPing : public ServerCommand
286 {
287  public:
288         CommandPing(Module* Creator) : ServerCommand(Creator, "PING", 1) { }
289         CmdResult Handle(User* user, std::vector<std::string>& parameters);
290         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
291 };
292
293 class CommandPong : public ServerOnlyServerCommand<CommandPong>
294 {
295  public:
296         CommandPong(Module* Creator) : ServerOnlyServerCommand<CommandPong>(Creator, "PONG", 1) { }
297         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
298         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
299 };
300
301 class CommandPush : public ServerCommand
302 {
303  public:
304         CommandPush(Module* Creator) : ServerCommand(Creator, "PUSH", 2) { }
305         CmdResult Handle(User* user, std::vector<std::string>& parameters);
306         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
307 };
308
309 class CommandSave : public ServerCommand
310 {
311  public:
312         /** Timestamp of the uuid nick of all users who collided and got their nick changed to uuid
313          */
314         static const time_t SavedTimestamp = 100;
315
316         CommandSave(Module* Creator) : ServerCommand(Creator, "SAVE", 2) { }
317         CmdResult Handle(User* user, std::vector<std::string>& parameters);
318 };
319
320 class CommandServer : public ServerOnlyServerCommand<CommandServer>
321 {
322         static void HandleExtra(TreeServer* newserver, const std::vector<std::string>& params);
323
324  public:
325         CommandServer(Module* Creator) : ServerOnlyServerCommand<CommandServer>(Creator, "SERVER", 3) { }
326         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
327
328         class Builder : public CmdBuilder
329         {
330                 void push_property(const char* key, const std::string& val)
331                 {
332                         push(key).push_raw('=').push_raw(val);
333                 }
334          public:
335                 Builder(TreeServer* server);
336         };
337 };
338
339 class CommandSQuit : public ServerOnlyServerCommand<CommandSQuit>
340 {
341  public:
342         CommandSQuit(Module* Creator) : ServerOnlyServerCommand<CommandSQuit>(Creator, "SQUIT", 2) { }
343         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
344 };
345
346 class CommandSNONotice : public ServerCommand
347 {
348  public:
349         CommandSNONotice(Module* Creator) : ServerCommand(Creator, "SNONOTICE", 2) { }
350         CmdResult Handle(User* user, std::vector<std::string>& parameters);
351 };
352
353 class CommandEndBurst : public ServerOnlyServerCommand<CommandEndBurst>
354 {
355  public:
356         CommandEndBurst(Module* Creator) : ServerOnlyServerCommand<CommandEndBurst>(Creator, "ENDBURST") { }
357         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
358 };
359
360 class CommandSInfo : public ServerOnlyServerCommand<CommandSInfo>
361 {
362  public:
363         CommandSInfo(Module* Creator) : ServerOnlyServerCommand<CommandSInfo>(Creator, "SINFO", 2) { }
364         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
365
366         class Builder : public CmdBuilder
367         {
368          public:
369                 Builder(TreeServer* server, const char* type, const std::string& value);
370         };
371 };
372
373 class CommandNum : public ServerOnlyServerCommand<CommandNum>
374 {
375  public:
376         CommandNum(Module* Creator) : ServerOnlyServerCommand<CommandNum>(Creator, "NUM", 3) { }
377         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
378         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
379
380         class Builder : public CmdBuilder
381         {
382          public:
383                 Builder(SpanningTree::RemoteUser* target, const Numeric::Numeric& numeric);
384         };
385 };
386
387 class SpanningTreeCommands
388 {
389  public:
390         CommandSVSJoin svsjoin;
391         CommandSVSPart svspart;
392         CommandSVSNick svsnick;
393         CommandMetadata metadata;
394         CommandUID uid;
395         CommandOpertype opertype;
396         CommandFJoin fjoin;
397         CommandIJoin ijoin;
398         CommandResync resync;
399         CommandFMode fmode;
400         CommandFTopic ftopic;
401         CommandFHost fhost;
402         CommandFIdent fident;
403         CommandFName fname;
404         CommandAway away;
405         CommandAddLine addline;
406         CommandDelLine delline;
407         CommandEncap encap;
408         CommandIdle idle;
409         CommandNick nick;
410         CommandPing ping;
411         CommandPong pong;
412         CommandPush push;
413         CommandSave save;
414         CommandServer server;
415         CommandSQuit squit;
416         CommandSNONotice snonotice;
417         CommandEndBurst endburst;
418         CommandSInfo sinfo;
419         CommandNum num;
420         SpanningTreeCommands(ModuleSpanningTree* module);
421 };