X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_cap.cpp;h=1d165f9355e427db5cfff61310c1b4d872eab87e;hb=5c9427cde0a949a17a476311db0a2a275345337b;hp=df11f1d32636559261ffe62fe9bcf08e48ffa6eb;hpb=90c5531101dedb1825bd8192d3b5ea4c810eee06;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp index df11f1d32..1d165f935 100644 --- a/src/modules/m_cap.cpp +++ b/src/modules/m_cap.cpp @@ -1,18 +1,25 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2008 Craig Edwards * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. * - * This program is free but copyrighted software; see - * the file COPYING for details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. * - * --------------------------------------------------- + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + #include "inspircd.h" -#include "m_cap.h" +#include "modules/cap.h" /* $ModDesc: Provides the CAP negotiation mechanism seen in ratbox-derived ircds */ @@ -20,11 +27,11 @@ CAP LS :alfred.staticbox.net CAP * LS :multi-prefix sasl CAP REQ :multi-prefix -:alfred.staticbox.net CAP * ACK :multi-prefix +:alfred.staticbox.net CAP * ACK :multi-prefix CAP CLEAR :alfred.staticbox.net CAP * ACK :-multi-prefix CAP REQ :multi-prefix -:alfred.staticbox.net CAP * ACK :multi-prefix +:alfred.staticbox.net CAP * ACK :multi-prefix CAP LIST :alfred.staticbox.net CAP * LIST :multi-prefix CAP END @@ -34,107 +41,119 @@ CAP END */ class CommandCAP : public Command { - Module* Creator; public: - CommandCAP (InspIRCd* Instance, Module* mod) : Command(Instance,"CAP", 0, 1, true), Creator(mod) + LocalIntExt reghold; + CommandCAP (Module* mod) : Command(mod, "CAP", 1), + reghold("CAP_REGHOLD", mod) { - this->source = "m_cap.so"; + works_before_reg = true; } - CmdResult Handle (const char* const* parameters, int pcnt, User *user) + CmdResult Handle (const std::vector ¶meters, User *user) { - irc::string subcommand = parameters[0]; + irc::string subcommand = parameters[0].c_str(); if (subcommand == "REQ") { - CapData Data; - Data.type = parameters[1]; - Data.user = user; - Data.creator = this->Creator; - Data.parameter = (pcnt > 1 ? parameters[1] : ""); - - user->Extend("CAP_REGHOLD"); - Event event((char*) &Data, (Module*)this->Creator, "cap_req"); - event.Send(this->ServerInstance); - - user->WriteServ("CAP * ACK :%s", Data.parameter.c_str()); + if (parameters.size() < 2) + return CMD_FAILURE; + + CapEvent Data(creator, user, CapEvent::CAPEVENT_REQ); + + // tokenize the input into a nice list of requested caps + std::string cap_; + irc::spacesepstream cap_stream(parameters[1]); + + while (cap_stream.GetToken(cap_)) + { + Data.wanted.push_back(cap_); + } + + reghold.set(user, 1); + Data.Send(); + + if (Data.ack.size() > 0) + { + std::string AckResult = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined(); + user->WriteServ("CAP %s ACK :%s", user->nick.c_str(), AckResult.c_str()); + } + + if (Data.wanted.size() > 0) + { + std::string NakResult = irc::stringjoiner(" ", Data.wanted, 0, Data.wanted.size() - 1).GetJoined(); + user->WriteServ("CAP %s NAK :%s", user->nick.c_str(), NakResult.c_str()); + } } else if (subcommand == "END") { - user->Shrink("CAP_REGHOLD"); + reghold.set(user, 0); } else if ((subcommand == "LS") || (subcommand == "LIST")) { - CapData Data; + CapEvent Data(creator, user, subcommand == "LS" ? CapEvent::CAPEVENT_LS : CapEvent::CAPEVENT_LIST); - Data.type = subcommand; - Data.user = user; - Data.creator = this->Creator; - Data.parameter.clear(); + reghold.set(user, 1); + Data.Send(); - user->Extend("CAP_REGHOLD"); - Event event((char*) &Data, (Module*)this->Creator, subcommand == "LS" ? "cap_ls" : "cap_list"); - event.Send(this->ServerInstance); + std::string Result; + if (Data.wanted.size() > 0) + Result = irc::stringjoiner(" ", Data.wanted, 0, Data.wanted.size() - 1).GetJoined(); - user->WriteServ("CAP * LS :%s", Data.parameter.c_str()); + user->WriteServ("CAP %s %s :%s", user->nick.c_str(), subcommand.c_str(), Result.c_str()); } else if (subcommand == "CLEAR") { - CapData Data; - - Data.type = subcommand; - Data.user = user; - Data.creator = this->Creator; - Data.parameter.clear(); + CapEvent Data(creator, user, CapEvent::CAPEVENT_CLEAR); - user->Extend("CAP_REGHOLD"); - Event event((char*) &Data, (Module*)this->Creator, "cap_clear"); - event.Send(this->ServerInstance); + reghold.set(user, 1); + Data.Send(); - user->WriteServ("CAP * ACK :%s", Data.parameter.c_str()); + std::string Result; + if (!Data.ack.empty()) + Result = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined(); + user->WriteServ("CAP %s ACK :%s", user->nick.c_str(), Result.c_str()); } else { - user->WriteServ("410 * %s :Invalid CAP subcommand", subcommand.c_str()); + user->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "%s %s :Invalid CAP subcommand", user->nick.c_str(), subcommand.c_str()); + return CMD_FAILURE; } - return CMD_FAILURE; + return CMD_SUCCESS; } }; class ModuleCAP : public Module { - CommandCAP* newcommand; + CommandCAP cmd; public: - ModuleCAP(InspIRCd* Me) - : Module(Me) + ModuleCAP() + : cmd(this) { - // Create a new command - newcommand = new CommandCAP(ServerInstance, this); - ServerInstance->AddCommand(newcommand); - - Implementation eventlist[] = { I_OnCheckReady, I_OnCleanup, I_OnUserDisconnect, I_OnRequest }; - ServerInstance->Modules->Attach(eventlist, this, 5); } - virtual bool OnCheckReady(User* user) + void init() CXX11_OVERRIDE { - /* Users in CAP state get held until CAP END */ - if (user->GetExt("CAP_REGHOLD")) - return true; + ServerInstance->Modules->AddService(cmd); + ServerInstance->Modules->AddService(cmd.reghold); - return false; + Implementation eventlist[] = { I_OnCheckReady }; + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } - virtual ~ModuleCAP() + ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE { + /* Users in CAP state get held until CAP END */ + if (cmd.reghold.get(user)) + return MOD_RES_DENY; + + return MOD_RES_PASSTHRU; } - virtual Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { - return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION); + return Version("Client CAP extension support", VF_VENDOR); } }; MODULE_INIT(ModuleCAP) -