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"
27 class CommandRConnect : public Command
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);
35 class CommandRSQuit : public Command
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);
43 class CommandMap : public Command
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);
51 class CommandSVSJoin : public ServerCommand
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);
59 class CommandSVSPart : public ServerCommand
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);
67 class CommandSVSNick : public ServerCommand
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);
75 class CommandMetadata : public ServerCommand
78 CommandMetadata(Module* Creator) : ServerCommand(Creator, "METADATA", 2) { }
79 CmdResult Handle(User* user, std::vector<std::string>& params);
81 class Builder : public CmdBuilder
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);
90 class CommandUID : public ServerOnlyServerCommand<CommandUID>
93 CommandUID(Module* Creator) : ServerOnlyServerCommand<CommandUID>(Creator, "UID", 10) { }
94 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& params);
96 class Builder : public CmdBuilder
103 class CommandOpertype : public UserOnlyServerCommand<CommandOpertype>
106 CommandOpertype(Module* Creator) : UserOnlyServerCommand<CommandOpertype>(Creator, "OPERTYPE", 1) { }
107 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
109 class Builder : public CmdBuilder
117 class FwdFJoinBuilder;
118 class CommandFJoin : public ServerCommand
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.
123 static void RemoveStatus(Channel* c);
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
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);
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; }
139 class Builder : public CmdBuilder
141 /** Maximum possible Membership::Id length in decimal digits, used for determining whether a user will fit into
144 static const size_t membid_max_digits = 20;
145 static const size_t maxline = 510;
146 std::string::size_type pos;
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;
153 Builder(Channel* chan, TreeServer* source = Utils->TreeRoot);
154 void add(Membership* memb)
156 add(memb, memb->modes.begin(), memb->modes.end());
159 bool has_room(Membership* memb) const
161 return has_room(memb->modes.size());
165 const std::string& finalize();
169 class CommandFMode : public ServerCommand
172 CommandFMode(Module* Creator) : ServerCommand(Creator, "FMODE", 3) { }
173 CmdResult Handle(User* user, std::vector<std::string>& params);
176 class CommandFTopic : public ServerCommand
179 CommandFTopic(Module* Creator) : ServerCommand(Creator, "FTOPIC", 4, 5) { }
180 CmdResult Handle(User* user, std::vector<std::string>& params);
182 class Builder : public CmdBuilder
185 Builder(Channel* chan);
186 Builder(User* user, Channel* chan);
190 class CommandFHost : public UserOnlyServerCommand<CommandFHost>
193 CommandFHost(Module* Creator) : UserOnlyServerCommand<CommandFHost>(Creator, "FHOST", 1) { }
194 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
197 class CommandFIdent : public UserOnlyServerCommand<CommandFIdent>
200 CommandFIdent(Module* Creator) : UserOnlyServerCommand<CommandFIdent>(Creator, "FIDENT", 1) { }
201 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
204 class CommandFName : public UserOnlyServerCommand<CommandFName>
207 CommandFName(Module* Creator) : UserOnlyServerCommand<CommandFName>(Creator, "FNAME", 1) { }
208 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
211 class CommandIJoin : public UserOnlyServerCommand<CommandIJoin>
214 CommandIJoin(Module* Creator) : UserOnlyServerCommand<CommandIJoin>(Creator, "IJOIN", 2) { }
215 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
218 class CommandResync : public ServerOnlyServerCommand<CommandResync>
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; }
226 class CommandAway : public UserOnlyServerCommand<CommandAway>
229 CommandAway(Module* Creator) : UserOnlyServerCommand<CommandAway>(Creator, "AWAY", 0, 2) { }
230 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
232 class Builder : public CmdBuilder
236 Builder(User* user, const std::string& msg);
241 class CommandAddLine : public ServerCommand
244 CommandAddLine(Module* Creator) : ServerCommand(Creator, "ADDLINE", 6, 6) { }
245 CmdResult Handle(User* user, std::vector<std::string>& parameters);
247 class Builder : public CmdBuilder
250 Builder(XLine* xline, User* user = ServerInstance->FakeClient);
254 class CommandDelLine : public ServerCommand
257 CommandDelLine(Module* Creator) : ServerCommand(Creator, "DELLINE", 2, 2) { }
258 CmdResult Handle(User* user, std::vector<std::string>& parameters);
261 class CommandEncap : public ServerCommand
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);
269 class CommandIdle : public UserOnlyServerCommand<CommandIdle>
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]); }
277 class CommandNick : public UserOnlyServerCommand<CommandNick>
280 CommandNick(Module* Creator) : UserOnlyServerCommand<CommandNick>(Creator, "NICK", 2) { }
281 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
284 class CommandPing : public ServerCommand
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]); }
292 class CommandPong : public ServerOnlyServerCommand<CommandPong>
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]); }
300 class CommandPush : public ServerCommand
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]); }
308 class CommandSave : public ServerCommand
311 /** Timestamp of the uuid nick of all users who collided and got their nick changed to uuid
313 static const time_t SavedTimestamp = 100;
315 CommandSave(Module* Creator) : ServerCommand(Creator, "SAVE", 2) { }
316 CmdResult Handle(User* user, std::vector<std::string>& parameters);
319 class CommandServer : public ServerOnlyServerCommand<CommandServer>
321 static void HandleExtra(TreeServer* newserver, const std::vector<std::string>& params);
324 CommandServer(Module* Creator) : ServerOnlyServerCommand<CommandServer>(Creator, "SERVER", 3) { }
325 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
327 class Builder : public CmdBuilder
329 void push_property(const char* key, const std::string& val)
331 push(key).push_raw('=').push_raw(val);
334 Builder(TreeServer* server);
338 class CommandSQuit : public ServerOnlyServerCommand<CommandSQuit>
341 CommandSQuit(Module* Creator) : ServerOnlyServerCommand<CommandSQuit>(Creator, "SQUIT", 2) { }
342 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
345 class CommandSNONotice : public ServerCommand
348 CommandSNONotice(Module* Creator) : ServerCommand(Creator, "SNONOTICE", 2) { }
349 CmdResult Handle(User* user, std::vector<std::string>& parameters);
352 class CommandEndBurst : public ServerOnlyServerCommand<CommandEndBurst>
355 CommandEndBurst(Module* Creator) : ServerOnlyServerCommand<CommandEndBurst>(Creator, "ENDBURST") { }
356 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
359 class CommandSInfo : public ServerOnlyServerCommand<CommandSInfo>
362 CommandSInfo(Module* Creator) : ServerOnlyServerCommand<CommandSInfo>(Creator, "SINFO", 2) { }
363 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
365 class Builder : public CmdBuilder
368 Builder(TreeServer* server, const char* type, const std::string& value);
372 class SpanningTreeCommands
375 CommandSVSJoin svsjoin;
376 CommandSVSPart svspart;
377 CommandSVSNick svsnick;
378 CommandMetadata metadata;
380 CommandOpertype opertype;
383 CommandResync resync;
385 CommandFTopic ftopic;
387 CommandFIdent fident;
390 CommandAddLine addline;
391 CommandDelLine delline;
399 CommandServer server;
401 CommandSNONotice snonotice;
402 CommandEndBurst endburst;
404 SpanningTreeCommands(ModuleSpanningTree* module);