2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
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/>.
26 /** Base class for server-to-server commands that may have a (remote) user source or server source.
28 class ServerCommand : public CommandBase
31 ServerCommand(Module* Creator, const std::string& Name, unsigned int MinPara = 0, unsigned int MaxPara = 0);
33 virtual CmdResult Handle(User* user, std::vector<std::string>& parameters) = 0;
34 virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
37 /** Base class for server-to-server command handlers which are only valid if their source is a user.
38 * When a server sends a command of this type and the source is a server (sid), the link is aborted.
41 class UserOnlyServerCommand : public ServerCommand
44 UserOnlyServerCommand(Module* Creator, const std::string& Name, unsigned int MinPara = 0, unsigned int MaxPara = 0)
45 : ServerCommand(Creator, Name, MinPara, MaxPara) { }
47 CmdResult Handle(User* user, std::vector<std::string>& parameters)
49 RemoteUser* remoteuser = IS_REMOTE(user);
52 return static_cast<T*>(this)->HandleRemote(remoteuser, parameters);
56 /** Base class for server-to-server command handlers which are only valid if their source is a server.
57 * When a server sends a command of this type and the source is a user (uuid), the link is aborted.
60 class ServerOnlyServerCommand : public ServerCommand
63 ServerOnlyServerCommand(Module* Creator, const std::string& Name, unsigned int MinPara = 0, unsigned int MaxPara = 0)
64 : ServerCommand(Creator, Name, MinPara, MaxPara) { }
66 CmdResult Handle(User* user, std::vector<std::string>& parameters)
70 TreeServer* server = Utils->FindServer(user->server);
71 return static_cast<T*>(this)->HandleServer(server, parameters);
75 class ServerCommandManager
77 typedef TR1NS::unordered_map<std::string, ServerCommand*> ServerCommandMap;
78 ServerCommandMap commands;
81 ServerCommand* GetHandler(const std::string& command) const;
82 bool AddCommand(ServerCommand* cmd);