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