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"
28 class CommandRConnect : public Command
31 CommandRConnect(Module* Creator);
32 CmdResult Handle(const std::vector<std::string>& parameters, User* user);
33 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
36 class CommandRSQuit : public Command
39 CommandRSQuit(Module* Creator);
40 CmdResult Handle(const std::vector<std::string>& parameters, User* user);
41 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
44 class CommandMap : public Command
47 CommandMap(Module* Creator);
48 CmdResult Handle(const std::vector<std::string>& parameters, User* user);
49 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
52 class CommandSVSJoin : public ServerCommand
55 CommandSVSJoin(Module* Creator) : ServerCommand(Creator, "SVSJOIN", 2) { }
56 CmdResult Handle(User* user, std::vector<std::string>& params);
57 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
60 class CommandSVSPart : public ServerCommand
63 CommandSVSPart(Module* Creator) : ServerCommand(Creator, "SVSPART", 2) { }
64 CmdResult Handle(User* user, std::vector<std::string>& params);
65 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
68 class CommandSVSNick : public ServerCommand
71 CommandSVSNick(Module* Creator) : ServerCommand(Creator, "SVSNICK", 3) { }
72 CmdResult Handle(User* user, std::vector<std::string>& params);
73 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
76 class CommandMetadata : public ServerCommand
79 CommandMetadata(Module* Creator) : ServerCommand(Creator, "METADATA", 2) { }
80 CmdResult Handle(User* user, std::vector<std::string>& params);
82 class Builder : public CmdBuilder
85 Builder(User* user, const std::string& key, const std::string& val);
86 Builder(Channel* chan, const std::string& key, const std::string& val);
87 Builder(const std::string& key, const std::string& val);
91 class CommandUID : public ServerOnlyServerCommand<CommandUID>
94 CommandUID(Module* Creator) : ServerOnlyServerCommand<CommandUID>(Creator, "UID", 10) { }
95 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& params);
97 class Builder : public CmdBuilder
104 class CommandOpertype : public UserOnlyServerCommand<CommandOpertype>
107 CommandOpertype(Module* Creator) : UserOnlyServerCommand<CommandOpertype>(Creator, "OPERTYPE", 1) { }
108 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
110 class Builder : public CmdBuilder
118 class FwdFJoinBuilder;
119 class CommandFJoin : public ServerCommand
121 /** Remove all modes from a channel, including statusmodes (+qaovh etc), simplemodes, parameter modes.
122 * This does not update the timestamp of the target channel, this must be done seperately.
124 static void RemoveStatus(Channel* c);
127 * Lowers the TS on the given channel: removes all modes, unsets all extensions,
128 * clears the topic and removes all pending invites.
129 * @param chan The target channel whose TS to lower
130 * @param TS The new TS to set
131 * @param newname The new name of the channel; must be the same or a case change of the current name
133 static void LowerTS(Channel* chan, time_t TS, const std::string& newname);
134 void ProcessModeUUIDPair(const std::string& item, TreeServer* sourceserver, Channel* chan, Modes::ChangeList* modechangelist, FwdFJoinBuilder& fwdfjoin);
136 CommandFJoin(Module* Creator) : ServerCommand(Creator, "FJOIN", 3) { }
137 CmdResult Handle(User* user, std::vector<std::string>& params);
138 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_LOCALONLY; }
140 class Builder : public CmdBuilder
142 /** Maximum possible Membership::Id length in decimal digits, used for determining whether a user will fit into
145 static const size_t membid_max_digits = 20;
146 static const size_t maxline = 510;
147 std::string::size_type pos;
150 void add(Membership* memb, std::string::const_iterator mbegin, std::string::const_iterator mend);
151 bool has_room(std::string::size_type nummodes) const;
154 Builder(Channel* chan, TreeServer* source = Utils->TreeRoot);
155 void add(Membership* memb)
157 add(memb, memb->modes.begin(), memb->modes.end());
160 bool has_room(Membership* memb) const
162 return has_room(memb->modes.size());
166 const std::string& finalize();
170 class CommandFMode : public ServerCommand
173 CommandFMode(Module* Creator) : ServerCommand(Creator, "FMODE", 3) { }
174 CmdResult Handle(User* user, std::vector<std::string>& params);
177 class CommandFTopic : public ServerCommand
180 CommandFTopic(Module* Creator) : ServerCommand(Creator, "FTOPIC", 4, 5) { }
181 CmdResult Handle(User* user, std::vector<std::string>& params);
183 class Builder : public CmdBuilder
186 Builder(Channel* chan);
187 Builder(User* user, Channel* chan);
191 class CommandFHost : public UserOnlyServerCommand<CommandFHost>
194 CommandFHost(Module* Creator) : UserOnlyServerCommand<CommandFHost>(Creator, "FHOST", 1) { }
195 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
198 class CommandFIdent : public UserOnlyServerCommand<CommandFIdent>
201 CommandFIdent(Module* Creator) : UserOnlyServerCommand<CommandFIdent>(Creator, "FIDENT", 1) { }
202 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
205 class CommandFName : public UserOnlyServerCommand<CommandFName>
208 CommandFName(Module* Creator) : UserOnlyServerCommand<CommandFName>(Creator, "FNAME", 1) { }
209 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
212 class CommandIJoin : public UserOnlyServerCommand<CommandIJoin>
215 CommandIJoin(Module* Creator) : UserOnlyServerCommand<CommandIJoin>(Creator, "IJOIN", 2) { }
216 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& params);
219 class CommandResync : public ServerOnlyServerCommand<CommandResync>
222 CommandResync(Module* Creator) : ServerOnlyServerCommand<CommandResync>(Creator, "RESYNC", 1) { }
223 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
224 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_LOCALONLY; }
227 class CommandAway : public UserOnlyServerCommand<CommandAway>
230 CommandAway(Module* Creator) : UserOnlyServerCommand<CommandAway>(Creator, "AWAY", 0, 2) { }
231 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
233 class Builder : public CmdBuilder
237 Builder(User* user, const std::string& msg);
242 class CommandAddLine : public ServerCommand
245 CommandAddLine(Module* Creator) : ServerCommand(Creator, "ADDLINE", 6, 6) { }
246 CmdResult Handle(User* user, std::vector<std::string>& parameters);
248 class Builder : public CmdBuilder
251 Builder(XLine* xline, User* user = ServerInstance->FakeClient);
255 class CommandDelLine : public ServerCommand
258 CommandDelLine(Module* Creator) : ServerCommand(Creator, "DELLINE", 2, 2) { }
259 CmdResult Handle(User* user, std::vector<std::string>& parameters);
262 class CommandEncap : public ServerCommand
265 CommandEncap(Module* Creator) : ServerCommand(Creator, "ENCAP", 2) { }
266 CmdResult Handle(User* user, std::vector<std::string>& parameters);
267 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
270 class CommandIdle : public UserOnlyServerCommand<CommandIdle>
273 CommandIdle(Module* Creator) : UserOnlyServerCommand<CommandIdle>(Creator, "IDLE", 1) { }
274 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
275 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
278 class CommandNick : public UserOnlyServerCommand<CommandNick>
281 CommandNick(Module* Creator) : UserOnlyServerCommand<CommandNick>(Creator, "NICK", 2) { }
282 CmdResult HandleRemote(RemoteUser* user, std::vector<std::string>& parameters);
285 class CommandPing : public ServerCommand
288 CommandPing(Module* Creator) : ServerCommand(Creator, "PING", 1) { }
289 CmdResult Handle(User* user, std::vector<std::string>& parameters);
290 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
293 class CommandPong : public ServerOnlyServerCommand<CommandPong>
296 CommandPong(Module* Creator) : ServerOnlyServerCommand<CommandPong>(Creator, "PONG", 1) { }
297 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
298 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) { return ROUTE_UNICAST(parameters[0]); }
301 class CommandSave : public ServerCommand
304 /** Timestamp of the uuid nick of all users who collided and got their nick changed to uuid
306 static const time_t SavedTimestamp = 100;
308 CommandSave(Module* Creator) : ServerCommand(Creator, "SAVE", 2) { }
309 CmdResult Handle(User* user, std::vector<std::string>& parameters);
312 class CommandServer : public ServerOnlyServerCommand<CommandServer>
314 static void HandleExtra(TreeServer* newserver, const std::vector<std::string>& params);
317 CommandServer(Module* Creator) : ServerOnlyServerCommand<CommandServer>(Creator, "SERVER", 3) { }
318 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
320 class Builder : public CmdBuilder
322 void push_property(const char* key, const std::string& val)
324 push(key).push_raw('=').push_raw(val);
327 Builder(TreeServer* server);
331 class CommandSQuit : public ServerOnlyServerCommand<CommandSQuit>
334 CommandSQuit(Module* Creator) : ServerOnlyServerCommand<CommandSQuit>(Creator, "SQUIT", 2) { }
335 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
338 class CommandSNONotice : public ServerCommand
341 CommandSNONotice(Module* Creator) : ServerCommand(Creator, "SNONOTICE", 2) { }
342 CmdResult Handle(User* user, std::vector<std::string>& parameters);
345 class CommandEndBurst : public ServerOnlyServerCommand<CommandEndBurst>
348 CommandEndBurst(Module* Creator) : ServerOnlyServerCommand<CommandEndBurst>(Creator, "ENDBURST") { }
349 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
352 class CommandSInfo : public ServerOnlyServerCommand<CommandSInfo>
355 CommandSInfo(Module* Creator) : ServerOnlyServerCommand<CommandSInfo>(Creator, "SINFO", 2) { }
356 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
358 class Builder : public CmdBuilder
361 Builder(TreeServer* server, const char* type, const std::string& value);
365 class CommandNum : public ServerOnlyServerCommand<CommandNum>
368 CommandNum(Module* Creator) : ServerOnlyServerCommand<CommandNum>(Creator, "NUM", 3) { }
369 CmdResult HandleServer(TreeServer* server, std::vector<std::string>& parameters);
370 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
372 class Builder : public CmdBuilder
375 Builder(SpanningTree::RemoteUser* target, const Numeric::Numeric& numeric);
379 class SpanningTreeCommands
382 CommandSVSJoin svsjoin;
383 CommandSVSPart svspart;
384 CommandSVSNick svsnick;
385 CommandMetadata metadata;
387 CommandOpertype opertype;
390 CommandResync resync;
392 CommandFTopic ftopic;
394 CommandFIdent fident;
397 CommandAddLine addline;
398 CommandDelLine delline;
405 CommandServer server;
407 CommandSNONotice snonotice;
408 CommandEndBurst endburst;
411 SpanningTreeCommands(ModuleSpanningTree* module);