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