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/>.
23 #include "treeserver.h"
25 /** Base class for server-to-server commands that may have a (remote) user source or server source.
27 class ServerCommand : public CommandBase
30 ServerCommand(Module* Creator, const std::string& Name, unsigned int MinPara = 0, unsigned int MaxPara = 0);
32 virtual CmdResult Handle(User* user, std::vector<std::string>& parameters) = 0;
33 virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
36 /** Base class for server-to-server command handlers which are only valid if their source is a user.
37 * When a server sends a command of this type and the source is a server (sid), the link is aborted.
40 class UserOnlyServerCommand : public ServerCommand
43 UserOnlyServerCommand(Module* Creator, const std::string& Name, unsigned int MinPara = 0, unsigned int MaxPara = 0)
44 : ServerCommand(Creator, Name, MinPara, MaxPara) { }
46 CmdResult Handle(User* user, std::vector<std::string>& parameters)
48 RemoteUser* remoteuser = IS_REMOTE(user);
51 return static_cast<T*>(this)->HandleRemote(remoteuser, parameters);
55 /** Base class for server-to-server command handlers which are only valid if their source is a server.
56 * When a server sends a command of this type and the source is a user (uuid), the link is aborted.
59 class ServerOnlyServerCommand : public ServerCommand
62 ServerOnlyServerCommand(Module* Creator, const std::string& Name, unsigned int MinPara = 0, unsigned int MaxPara = 0)
63 : ServerCommand(Creator, Name, MinPara, MaxPara) { }
65 CmdResult Handle(User* user, std::vector<std::string>& parameters)
69 TreeServer* server = TreeServer::Get(user);
70 return static_cast<T*>(this)->HandleServer(server, parameters);
74 class ServerCommandManager
76 typedef TR1NS::unordered_map<std::string, ServerCommand*> ServerCommandMap;
77 ServerCommandMap commands;
80 ServerCommand* GetHandler(const std::string& command) const;
81 bool AddCommand(ServerCommand* cmd);