]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/commands.h
Merge insp20
[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 FwdFJoinBuilder;
118 class CommandFJoin : public ServerCommand
119 {
120         /** Remove all modes from a channel, including statusmodes (+qaovh etc), simplemodes, parameter modes.
121          * This does not update the timestamp of the target channel, this must be done seperately.
122          */
123         static void RemoveStatus(Channel* c);
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, Modes::ChangeList* modechangelist, FwdFJoinBuilder& fwdfjoin);
134  public:
135         CommandFJoin(Module* Creator) : ServerCommand(Creator, "FJOIN", 3) { }
136         CmdResult Handle(User* user, std::vector<std::string>& params);
137         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_LOCALONLY; }
138
139         class Builder : public CmdBuilder
140         {
141                 /** Maximum possible Membership::Id length in decimal digits, used for determining whether a user will fit into
142                  * a message or not
143                  */
144                 static const size_t membid_max_digits = 20;
145                 static const size_t maxline = 510;
146                 std::string::size_type pos;
147
148         protected:
149                 void add(Membership* memb, std::string::const_iterator mbegin, std::string::const_iterator mend);
150                 bool has_room(std::string::size_type nummodes) const;
151
152          public:
153                 Builder(Channel* chan, TreeServer* source = Utils->TreeRoot);
154                 void add(Membership* memb)
155                 {
156                         add(memb, memb->modes.begin(), memb->modes.end());
157                 }
158
159                 bool has_room(Membership* memb) const
160                 {
161                         return has_room(memb->modes.size());
162                 }
163
164                 void clear();
165                 const std::string& finalize();
166         };
167 };
168
169 class CommandFMode : public ServerCommand
170 {
171  public:
172         CommandFMode(Module* Creator) : ServerCommand(Creator, "FMODE", 3) { }
173         CmdResult Handle(User* user, std::vector<std::string>& params);
174 };
175
176 class CommandFTopic : public ServerCommand
177 {
178  public:
179         CommandFTopic(Module* Creator) : ServerCommand(Creator, "FTOPIC", 4, 5) { }
180         CmdResult Handle(User* user, std::vector<std::string>& params);
181
182         class Builder : public CmdBuilder
183         {
184          public:
185                 Builder(Channel* chan);
186                 Builder(User* user, Channel* chan);
187         };
188 };
189
190 class CommandFHost : public UserOnlyServerCommand<CommandFHost>
191 {
192  public:
193         CommandFHost(Module* Creator) : UserOnlyServerCommand<CommandFHost>(Creator, "FHOST", 1) { }
194         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
195 };
196
197 class CommandFIdent : public UserOnlyServerCommand<CommandFIdent>
198 {
199  public:
200         CommandFIdent(Module* Creator) : UserOnlyServerCommand<CommandFIdent>(Creator, "FIDENT", 1) { }
201         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
202 };
203
204 class CommandFName : public UserOnlyServerCommand<CommandFName>
205 {
206  public:
207         CommandFName(Module* Creator) : UserOnlyServerCommand<CommandFName>(Creator, "FNAME", 1) { }
208         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
209 };
210
211 class CommandIJoin : public UserOnlyServerCommand<CommandIJoin>
212 {
213  public:
214         CommandIJoin(Module* Creator) : UserOnlyServerCommand<CommandIJoin>(Creator, "IJOIN", 2) { }
215         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
216 };
217
218 class CommandResync : public ServerOnlyServerCommand<CommandResync>
219 {
220  public:
221         CommandResync(Module* Creator) : ServerOnlyServerCommand<CommandResync>(Creator, "RESYNC", 1) { }
222         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
223         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_LOCALONLY; }
224 };
225
226 class CommandAway : public UserOnlyServerCommand<CommandAway>
227 {
228  public:
229         CommandAway(Module* Creator) : UserOnlyServerCommand<CommandAway>(Creator, "AWAY", 0, 2) { }
230         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
231
232         class Builder : public CmdBuilder
233         {
234          public:
235                 Builder(User* user);
236                 Builder(User* user, const std::string& msg);
237         };
238 };
239
240 class XLine;
241 class CommandAddLine : public ServerCommand
242 {
243  public:
244         CommandAddLine(Module* Creator) : ServerCommand(Creator, "ADDLINE", 6, 6) { }
245         CmdResult Handle(User* user, std::vector<std::string>& parameters);
246
247         class Builder : public CmdBuilder
248         {
249          public:
250                 Builder(XLine* xline, User* user = ServerInstance->FakeClient);
251         };
252 };
253
254 class CommandDelLine : public ServerCommand
255 {
256  public:
257         CommandDelLine(Module* Creator) : ServerCommand(Creator, "DELLINE", 2, 2) { }
258         CmdResult Handle(User* user, std::vector<std::string>& parameters);
259 };
260
261 class CommandEncap : public ServerCommand
262 {
263  public:
264         CommandEncap(Module* Creator) : ServerCommand(Creator, "ENCAP", 2) { }
265         CmdResult Handle(User* user, std::vector<std::string>& parameters);
266         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
267 };
268
269 class CommandIdle : public UserOnlyServerCommand<CommandIdle>
270 {
271  public:
272         CommandIdle(Module* Creator) : UserOnlyServerCommand<CommandIdle>(Creator, "IDLE", 1) { }
273         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
274         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
275 };
276
277 class CommandNick : public UserOnlyServerCommand<CommandNick>
278 {
279  public:
280         CommandNick(Module* Creator) : UserOnlyServerCommand<CommandNick>(Creator, "NICK", 2) { }
281         CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
282 };
283
284 class CommandPing : public ServerCommand
285 {
286  public:
287         CommandPing(Module* Creator) : ServerCommand(Creator, "PING", 1) { }
288         CmdResult Handle(User* user, std::vector<std::string>& parameters);
289         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
290 };
291
292 class CommandPong : public ServerOnlyServerCommand<CommandPong>
293 {
294  public:
295         CommandPong(Module* Creator) : ServerOnlyServerCommand<CommandPong>(Creator, "PONG", 1) { }
296         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
297         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
298 };
299
300 class CommandPush : public ServerCommand
301 {
302  public:
303         CommandPush(Module* Creator) : ServerCommand(Creator, "PUSH", 2) { }
304         CmdResult Handle(User* user, std::vector<std::string>& parameters);
305         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
306 };
307
308 class CommandSave : public ServerCommand
309 {
310  public:
311         /** Timestamp of the uuid nick of all users who collided and got their nick changed to uuid
312          */
313         static const time_t SavedTimestamp = 100;
314
315         CommandSave(Module* Creator) : ServerCommand(Creator, "SAVE", 2) { }
316         CmdResult Handle(User* user, std::vector<std::string>& parameters);
317 };
318
319 class CommandServer : public ServerOnlyServerCommand<CommandServer>
320 {
321         static void HandleExtra(TreeServer* newserver, const std::vector<std::string>& params);
322
323  public:
324         CommandServer(Module* Creator) : ServerOnlyServerCommand<CommandServer>(Creator, "SERVER", 3) { }
325         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
326
327         class Builder : public CmdBuilder
328         {
329                 void push_property(const char* key, const std::string& val)
330                 {
331                         push(key).push_raw('=').push_raw(val);
332                 }
333          public:
334                 Builder(TreeServer* server);
335         };
336 };
337
338 class CommandSQuit : public ServerOnlyServerCommand<CommandSQuit>
339 {
340  public:
341         CommandSQuit(Module* Creator) : ServerOnlyServerCommand<CommandSQuit>(Creator, "SQUIT", 2) { }
342         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
343 };
344
345 class CommandSNONotice : public ServerCommand
346 {
347  public:
348         CommandSNONotice(Module* Creator) : ServerCommand(Creator, "SNONOTICE", 2) { }
349         CmdResult Handle(User* user, std::vector<std::string>& parameters);
350 };
351
352 class CommandEndBurst : public ServerOnlyServerCommand<CommandEndBurst>
353 {
354  public:
355         CommandEndBurst(Module* Creator) : ServerOnlyServerCommand<CommandEndBurst>(Creator, "ENDBURST") { }
356         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
357 };
358
359 class CommandSInfo : public ServerOnlyServerCommand<CommandSInfo>
360 {
361  public:
362         CommandSInfo(Module* Creator) : ServerOnlyServerCommand<CommandSInfo>(Creator, "SINFO", 2) { }
363         CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
364
365         class Builder : public CmdBuilder
366         {
367          public:
368                 Builder(TreeServer* server, const char* type, const std::string& value);
369         };
370 };
371
372 class SpanningTreeCommands
373 {
374  public:
375         CommandSVSJoin svsjoin;
376         CommandSVSPart svspart;
377         CommandSVSNick svsnick;
378         CommandMetadata metadata;
379         CommandUID uid;
380         CommandOpertype opertype;
381         CommandFJoin fjoin;
382         CommandIJoin ijoin;
383         CommandResync resync;
384         CommandFMode fmode;
385         CommandFTopic ftopic;
386         CommandFHost fhost;
387         CommandFIdent fident;
388         CommandFName fname;
389         CommandAway away;
390         CommandAddLine addline;
391         CommandDelLine delline;
392         CommandEncap encap;
393         CommandIdle idle;
394         CommandNick nick;
395         CommandPing ping;
396         CommandPong pong;
397         CommandPush push;
398         CommandSave save;
399         CommandServer server;
400         CommandSQuit squit;
401         CommandSNONotice snonotice;
402         CommandEndBurst endburst;
403         CommandSInfo sinfo;
404         SpanningTreeCommands(ModuleSpanningTree* module);
405 };