]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/commands.h
m_spanningtree Remove PUSH handler
[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 CommandSave : public ServerCommand
302 {
303  public:
304         /** Timestamp of the uuid nick of all users who collided and got their nick changed to uuid
305          */
306         static const time_t SavedTimestamp = 100;
307
308         CommandSave(Module* Creator) : ServerCommand(Creator, "SAVE", 2) { }
309         CmdResult Handle(User* user, std::vector<std::string>& parameters);
310 };
311
312 class CommandServer : public ServerOnlyServerCommand<CommandServer>
313 {
314         static void HandleExtra(TreeServer* newserver, const std::vector<std::string>& params);
315
316  public:
317         CommandServer(Module* Creator) : ServerOnlyServerCommand<CommandServer>(Creator, "SERVER", 3) { }
318         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
319
320         class Builder : public CmdBuilder
321         {
322                 void push_property(const char* key, const std::string& val)
323                 {
324                         push(key).push_raw('=').push_raw(val);
325                 }
326          public:
327                 Builder(TreeServer* server);
328         };
329 };
330
331 class CommandSQuit : public ServerOnlyServerCommand<CommandSQuit>
332 {
333  public:
334         CommandSQuit(Module* Creator) : ServerOnlyServerCommand<CommandSQuit>(Creator, "SQUIT", 2) { }
335         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
336 };
337
338 class CommandSNONotice : public ServerCommand
339 {
340  public:
341         CommandSNONotice(Module* Creator) : ServerCommand(Creator, "SNONOTICE", 2) { }
342         CmdResult Handle(User* user, std::vector<std::string>& parameters);
343 };
344
345 class CommandEndBurst : public ServerOnlyServerCommand<CommandEndBurst>
346 {
347  public:
348         CommandEndBurst(Module* Creator) : ServerOnlyServerCommand<CommandEndBurst>(Creator, "ENDBURST") { }
349         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
350 };
351
352 class CommandSInfo : public ServerOnlyServerCommand<CommandSInfo>
353 {
354  public:
355         CommandSInfo(Module* Creator) : ServerOnlyServerCommand<CommandSInfo>(Creator, "SINFO", 2) { }
356         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
357
358         class Builder : public CmdBuilder
359         {
360          public:
361                 Builder(TreeServer* server, const char* type, const std::string& value);
362         };
363 };
364
365 class CommandNum : public ServerOnlyServerCommand<CommandNum>
366 {
367  public:
368         CommandNum(Module* Creator) : ServerOnlyServerCommand<CommandNum>(Creator, "NUM", 3) { }
369         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
370         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
371
372         class Builder : public CmdBuilder
373         {
374          public:
375                 Builder(SpanningTree::RemoteUser* target, const Numeric::Numeric& numeric);
376         };
377 };
378
379 class SpanningTreeCommands
380 {
381  public:
382         CommandSVSJoin svsjoin;
383         CommandSVSPart svspart;
384         CommandSVSNick svsnick;
385         CommandMetadata metadata;
386         CommandUID uid;
387         CommandOpertype opertype;
388         CommandFJoin fjoin;
389         CommandIJoin ijoin;
390         CommandResync resync;
391         CommandFMode fmode;
392         CommandFTopic ftopic;
393         CommandFHost fhost;
394         CommandFIdent fident;
395         CommandFName fname;
396         CommandAway away;
397         CommandAddLine addline;
398         CommandDelLine delline;
399         CommandEncap encap;
400         CommandIdle idle;
401         CommandNick nick;
402         CommandPing ping;
403         CommandPong pong;
404         CommandSave save;
405         CommandServer server;
406         CommandSQuit squit;
407         CommandSNONotice snonotice;
408         CommandEndBurst endburst;
409         CommandSInfo sinfo;
410         CommandNum num;
411         SpanningTreeCommands(ModuleSpanningTree* module);
412 };