2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "modules/cap.h"
26 :alfred.staticbox.net CAP * LS :multi-prefix sasl
28 :alfred.staticbox.net CAP * ACK :multi-prefix
30 :alfred.staticbox.net CAP * ACK :-multi-prefix
32 :alfred.staticbox.net CAP * ACK :multi-prefix
34 :alfred.staticbox.net CAP * LIST :multi-prefix
40 class CommandCAP : public Command
44 CommandCAP (Module* mod) : Command(mod, "CAP", 1),
45 reghold("CAP_REGHOLD", mod)
47 works_before_reg = true;
50 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
52 irc::string subcommand = parameters[0].c_str();
54 if (subcommand == "REQ")
56 if (parameters.size() < 2)
59 CapEvent Data(creator, user, CapEvent::CAPEVENT_REQ);
61 // tokenize the input into a nice list of requested caps
63 irc::spacesepstream cap_stream(parameters[1]);
65 while (cap_stream.GetToken(cap_))
67 std::transform(cap_.begin(), cap_.end(), cap_.begin(), ::tolower);
68 Data.wanted.push_back(cap_);
74 if (Data.ack.size() > 0)
76 std::string AckResult = irc::stringjoiner(Data.ack).GetJoined();
77 user->WriteServ("CAP %s ACK :%s", user->nick.c_str(), AckResult.c_str());
80 if (Data.wanted.size() > 0)
82 std::string NakResult = irc::stringjoiner(Data.wanted).GetJoined();
83 user->WriteServ("CAP %s NAK :%s", user->nick.c_str(), NakResult.c_str());
86 else if (subcommand == "END")
90 else if ((subcommand == "LS") || (subcommand == "LIST"))
92 CapEvent Data(creator, user, subcommand == "LS" ? CapEvent::CAPEVENT_LS : CapEvent::CAPEVENT_LIST);
97 std::string Result = irc::stringjoiner(Data.wanted).GetJoined();
98 user->WriteServ("CAP %s %s :%s", user->nick.c_str(), subcommand.c_str(), Result.c_str());
100 else if (subcommand == "CLEAR")
102 CapEvent Data(creator, user, CapEvent::CAPEVENT_CLEAR);
104 reghold.set(user, 1);
107 std::string Result = irc::stringjoiner(Data.ack).GetJoined();
108 user->WriteServ("CAP %s ACK :%s", user->nick.c_str(), Result.c_str());
112 user->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "%s :Invalid CAP subcommand", subcommand.c_str());
120 class ModuleCAP : public Module
129 ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
131 /* Users in CAP state get held until CAP END */
132 if (cmd.reghold.get(user))
135 return MOD_RES_PASSTHRU;
138 Version GetVersion() CXX11_OVERRIDE
140 return Version("Client CAP extension support", VF_VENDOR);
144 MODULE_INIT(ModuleCAP)