2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
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.
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
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/>.
22 #include "servercommand.h"
23 #include "commandbuilder.h"
24 #include "remoteuser.h"
26 namespace SpanningTree
35 using SpanningTree::CommandAway;
36 using SpanningTree::CommandNick;
37 using SpanningTree::CommandPing;
38 using SpanningTree::CommandPong;
39 using SpanningTree::CommandServer;
43 class CommandRConnect : public Command
46 CommandRConnect(Module* Creator);
47 CmdResult Handle(const std::vector<std::string>& parameters, User* user);
48 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
51 class CommandRSQuit : public Command
54 CommandRSQuit(Module* Creator);
55 CmdResult Handle(const std::vector<std::string>& parameters, User* user);
56 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
59 class CommandMap : public Command
62 CommandMap(Module* Creator);
63 CmdResult Handle(const std::vector<std::string>& parameters, User* user);
64 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
67 class CommandSVSJoin : public ServerCommand
70 CommandSVSJoin(Module* Creator) : ServerCommand(Creator, "SVSJOIN", 2) { }
71 CmdResult Handle(User* user, std::vector<std::string>& params);
72 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
75 class CommandSVSPart : public ServerCommand
78 CommandSVSPart(Module* Creator) : ServerCommand(Creator, "SVSPART", 2) { }
79 CmdResult Handle(User* user, std::vector<std::string>& params);
80 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
83 class CommandSVSNick : public ServerCommand
86 CommandSVSNick(Module* Creator) : ServerCommand(Creator, "SVSNICK", 3) { }
87 CmdResult Handle(User* user, std::vector<std::string>& params);
88 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
91 class CommandMetadata : public ServerCommand
94 CommandMetadata(Module* Creator) : ServerCommand(Creator, "METADATA", 2) { }
95 CmdResult Handle(User* user, std::vector<std::string>& params);
97 class Builder : public CmdBuilder
100 Builder(User* user, const std::string& key, const std::string& val);
101 Builder(Channel* chan, const std::string& key, const std::string& val);
102 Builder(const std::string& key, const std::string& val);
106 class CommandUID : public ServerOnlyServerCommand<CommandUID>
109 CommandUID(Module* Creator) : ServerOnlyServerCommand<CommandUID>(Creator, "UID", 10) { }
110 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& params);
112 class Builder : public CmdBuilder
119 class CommandOpertype : public UserOnlyServerCommand<CommandOpertype>
122 CommandOpertype(Module* Creator) : UserOnlyServerCommand<CommandOpertype>(Creator, "OPERTYPE", 1) { }
123 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
125 class Builder : public CmdBuilder
133 class FwdFJoinBuilder;
134 class CommandFJoin : public ServerCommand
136 /** Remove all modes from a channel, including statusmodes (+qaovh etc), simplemodes, parameter modes.
137 * This does not update the timestamp of the target channel, this must be done seperately.
139 static void RemoveStatus(Channel* c);
142 * Lowers the TS on the given channel: removes all modes, unsets all extensions,
143 * clears the topic and removes all pending invites.
144 * @param chan The target channel whose TS to lower
145 * @param TS The new TS to set
146 * @param newname The new name of the channel; must be the same or a case change of the current name
148 static void LowerTS(Channel* chan, time_t TS, const std::string& newname);
149 void ProcessModeUUIDPair(const std::string& item, TreeServer* sourceserver, Channel* chan, Modes::ChangeList* modechangelist, FwdFJoinBuilder& fwdfjoin);
151 CommandFJoin(Module* Creator) : ServerCommand(Creator, "FJOIN", 3) { }
152 CmdResult Handle(User* user, std::vector<std::string>& params);
153 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_LOCALONLY; }
155 class Builder : public CmdBuilder
157 /** Maximum possible Membership::Id length in decimal digits, used for determining whether a user will fit into
160 static const size_t membid_max_digits = 20;
161 static const size_t maxline = 510;
162 std::string::size_type pos;
165 void add(Membership* memb, std::string::const_iterator mbegin, std::string::const_iterator mend);
166 bool has_room(std::string::size_type nummodes) const;
169 Builder(Channel* chan, TreeServer* source = Utils->TreeRoot);
170 void add(Membership* memb)
172 add(memb, memb->modes.begin(), memb->modes.end());
175 bool has_room(Membership* memb) const
177 return has_room(memb->modes.size());
181 const std::string& finalize();
185 class CommandFMode : public ServerCommand
188 CommandFMode(Module* Creator) : ServerCommand(Creator, "FMODE", 3) { }
189 CmdResult Handle(User* user, std::vector<std::string>& params);
192 class CommandFTopic : public ServerCommand
195 CommandFTopic(Module* Creator) : ServerCommand(Creator, "FTOPIC", 4, 5) { }
196 CmdResult Handle(User* user, std::vector<std::string>& params);
198 class Builder : public CmdBuilder
201 Builder(Channel* chan);
202 Builder(User* user, Channel* chan);
206 class CommandFHost : public UserOnlyServerCommand<CommandFHost>
209 CommandFHost(Module* Creator) : UserOnlyServerCommand<CommandFHost>(Creator, "FHOST", 1) { }
210 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
213 class CommandFIdent : public UserOnlyServerCommand<CommandFIdent>
216 CommandFIdent(Module* Creator) : UserOnlyServerCommand<CommandFIdent>(Creator, "FIDENT", 1) { }
217 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
220 class CommandFName : public UserOnlyServerCommand<CommandFName>
223 CommandFName(Module* Creator) : UserOnlyServerCommand<CommandFName>(Creator, "FNAME", 1) { }
224 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
227 class CommandIJoin : public UserOnlyServerCommand<CommandIJoin>
230 CommandIJoin(Module* Creator) : UserOnlyServerCommand<CommandIJoin>(Creator, "IJOIN", 2) { }
231 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
234 class CommandResync : public ServerOnlyServerCommand<CommandResync>
237 CommandResync(Module* Creator) : ServerOnlyServerCommand<CommandResync>(Creator, "RESYNC", 1) { }
238 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
239 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_LOCALONLY; }
242 class SpanningTree::CommandAway : public UserOnlyServerCommand<SpanningTree::CommandAway>
245 CommandAway(Module* Creator) : UserOnlyServerCommand<SpanningTree::CommandAway>(Creator, "AWAY", 0, 2) { }
246 CmdResult HandleRemote(::RemoteUser* user, std::vector<std::string>& parameters);
248 class Builder : public CmdBuilder
252 Builder(User* user, const std::string& msg);
257 class CommandAddLine : public ServerCommand
260 CommandAddLine(Module* Creator) : ServerCommand(Creator, "ADDLINE", 6, 6) { }
261 CmdResult Handle(User* user, std::vector<std::string>& parameters);
263 class Builder : public CmdBuilder
266 Builder(XLine* xline, User* user = ServerInstance->FakeClient);
270 class CommandDelLine : public ServerCommand
273 CommandDelLine(Module* Creator) : ServerCommand(Creator, "DELLINE", 2, 2) { }
274 CmdResult Handle(User* user, std::vector<std::string>& parameters);
277 class CommandEncap : public ServerCommand
280 CommandEncap(Module* Creator) : ServerCommand(Creator, "ENCAP", 2) { }
281 CmdResult Handle(User* user, std::vector<std::string>& parameters);
282 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
285 class CommandIdle : public UserOnlyServerCommand<CommandIdle>
288 CommandIdle(Module* Creator) : UserOnlyServerCommand<CommandIdle>(Creator, "IDLE", 1) { }
289 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
290 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
293 class SpanningTree::CommandNick : public UserOnlyServerCommand<SpanningTree::CommandNick>
296 CommandNick(Module* Creator) : UserOnlyServerCommand<SpanningTree::CommandNick>(Creator, "NICK", 2) { }
297 CmdResult HandleRemote(::RemoteUser* user, std::vector<std::string>& parameters);
300 class SpanningTree::CommandPing : public ServerCommand
303 CommandPing(Module* Creator) : ServerCommand(Creator, "PING", 1) { }
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]); }
308 class SpanningTree::CommandPong : public ServerOnlyServerCommand<SpanningTree::CommandPong>
311 CommandPong(Module* Creator) : ServerOnlyServerCommand<SpanningTree::CommandPong>(Creator, "PONG", 1) { }
312 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
313 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
316 class CommandSave : public ServerCommand
319 /** Timestamp of the uuid nick of all users who collided and got their nick changed to uuid
321 static const time_t SavedTimestamp = 100;
323 CommandSave(Module* Creator) : ServerCommand(Creator, "SAVE", 2) { }
324 CmdResult Handle(User* user, std::vector<std::string>& parameters);
327 class SpanningTree::CommandServer : public ServerOnlyServerCommand<SpanningTree::CommandServer>
329 static void HandleExtra(TreeServer* newserver, const std::vector<std::string>& params);
332 CommandServer(Module* Creator) : ServerOnlyServerCommand<SpanningTree::CommandServer>(Creator, "SERVER", 3) { }
333 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
335 class Builder : public CmdBuilder
337 void push_property(const char* key, const std::string& val)
339 push(key).push_raw('=').push_raw(val);
342 Builder(TreeServer* server);
346 class CommandSQuit : public ServerOnlyServerCommand<CommandSQuit>
349 CommandSQuit(Module* Creator) : ServerOnlyServerCommand<CommandSQuit>(Creator, "SQUIT", 2) { }
350 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
353 class CommandSNONotice : public ServerCommand
356 CommandSNONotice(Module* Creator) : ServerCommand(Creator, "SNONOTICE", 2) { }
357 CmdResult Handle(User* user, std::vector<std::string>& parameters);
360 class CommandEndBurst : public ServerOnlyServerCommand<CommandEndBurst>
363 CommandEndBurst(Module* Creator) : ServerOnlyServerCommand<CommandEndBurst>(Creator, "ENDBURST") { }
364 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
367 class CommandSInfo : public ServerOnlyServerCommand<CommandSInfo>
370 CommandSInfo(Module* Creator) : ServerOnlyServerCommand<CommandSInfo>(Creator, "SINFO", 2) { }
371 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
373 class Builder : public CmdBuilder
376 Builder(TreeServer* server, const char* type, const std::string& value);
380 class CommandNum : public ServerOnlyServerCommand<CommandNum>
383 CommandNum(Module* Creator) : ServerOnlyServerCommand<CommandNum>(Creator, "NUM", 3) { }
384 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
385 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
387 class Builder : public CmdBuilder
390 Builder(SpanningTree::RemoteUser* target, const Numeric::Numeric& numeric);
394 class SpanningTreeCommands
397 CommandSVSJoin svsjoin;
398 CommandSVSPart svspart;
399 CommandSVSNick svsnick;
400 CommandMetadata metadata;
402 CommandOpertype opertype;
405 CommandResync resync;
407 CommandFTopic ftopic;
409 CommandFIdent fident;
411 SpanningTree::CommandAway away;
412 CommandAddLine addline;
413 CommandDelLine delline;
416 SpanningTree::CommandNick nick;
417 SpanningTree::CommandPing ping;
418 SpanningTree::CommandPong pong;
420 SpanningTree::CommandServer server;
422 CommandSNONotice snonotice;
423 CommandEndBurst endburst;
426 SpanningTreeCommands(ModuleSpanningTree* module);