X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_cap.cpp;h=bc79e59ecae6e832b096013a1e17fac190fd3f5e;hb=b9006ce3cba742ca2a22d601ba1a63a47b0402c9;hp=a0730efa713a82e78ce39f8859d02475aa25438c;hpb=cd712c40e1b352c05e7ae0f72e0a5e84cdf64323;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp index a0730efa7..bc79e59ec 100644 --- a/src/modules/m_cap.cpp +++ b/src/modules/m_cap.cpp @@ -1,20 +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-2010 InspIRCd Development Team - * See: http://wiki.inspircd.org/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" -/* $ModDesc: Provides the CAP negotiation mechanism seen in ratbox-derived ircds */ +#include "inspircd.h" +#include "modules/cap.h" /* CAP LS @@ -44,26 +49,23 @@ class CommandCAP : public Command CmdResult Handle (const std::vector ¶meters, User *user) { - irc::string subcommand = parameters[0].c_str(); + std::string subcommand(parameters[0].length(), ' '); + std::transform(parameters[0].begin(), parameters[0].end(), subcommand.begin(), ::toupper); if (subcommand == "REQ") { - CapEvent Data(creator, "cap_req"); - - Data.type = subcommand; - Data.user = user; - Data.creator = this->creator; - 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 param = parameters[1]; std::string cap_; - irc::spacesepstream cap_stream(param); + irc::spacesepstream cap_stream(parameters[1]); while (cap_stream.GetToken(cap_)) { + std::transform(cap_.begin(), cap_.end(), cap_.begin(), ::tolower); Data.wanted.push_back(cap_); } @@ -72,14 +74,14 @@ class CommandCAP : public Command if (Data.ack.size() > 0) { - std::string AckResult = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined(); - user->WriteServ("CAP * ACK :%s", AckResult.c_str()); + std::string AckResult = irc::stringjoiner(Data.ack); + user->WriteCommand("CAP", "ACK :" + AckResult); } if (Data.wanted.size() > 0) { - std::string NakResult = irc::stringjoiner(" ", Data.wanted, 0, Data.wanted.size() - 1).GetJoined(); - user->WriteServ("CAP * NAK :%s", NakResult.c_str()); + std::string NakResult = irc::stringjoiner(Data.wanted); + user->WriteCommand("CAP", "NAK :" + NakResult); } } else if (subcommand == "END") @@ -88,43 +90,31 @@ class CommandCAP : public Command } else if ((subcommand == "LS") || (subcommand == "LIST")) { - CapEvent Data(creator, subcommand == "LS" ? "cap_ls" : "cap_list"); - - Data.type = subcommand; - Data.user = user; - Data.creator = this->creator; + CapEvent Data(creator, user, subcommand == "LS" ? CapEvent::CAPEVENT_LS : CapEvent::CAPEVENT_LIST); reghold.set(user, 1); Data.Send(); - std::string Result; - if (Data.wanted.size() > 0) - Result = irc::stringjoiner(" ", Data.wanted, 0, Data.wanted.size() - 1).GetJoined(); - else - Result = ""; - - user->WriteServ("CAP * %s :%s", subcommand.c_str(), Result.c_str()); + std::string Result = irc::stringjoiner(Data.wanted); + user->WriteCommand("CAP", subcommand + " :" + Result); } else if (subcommand == "CLEAR") { - CapEvent Data(creator, "cap_clear"); - - Data.type = subcommand; - Data.user = user; - Data.creator = this->creator; + CapEvent Data(creator, user, CapEvent::CAPEVENT_CLEAR); reghold.set(user, 1); Data.Send(); - std::string Result = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined(); - user->WriteServ("CAP * ACK :%s", Result.c_str()); + std::string Result = irc::stringjoiner(Data.ack); + user->WriteCommand("CAP", "ACK :" + Result); } else { - user->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "* %s :Invalid CAP subcommand", subcommand.c_str()); + user->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "%s :Invalid CAP subcommand", subcommand.c_str()); + return CMD_FAILURE; } - return CMD_FAILURE; + return CMD_SUCCESS; } }; @@ -135,14 +125,9 @@ class ModuleCAP : public Module ModuleCAP() : cmd(this) { - ServerInstance->AddCommand(&cmd); - ServerInstance->Extensions.Register(&cmd.reghold); - - Implementation eventlist[] = { I_OnCheckReady }; - ServerInstance->Modules->Attach(eventlist, this, 1); } - ModResult OnCheckReady(LocalUser* user) + ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE { /* Users in CAP state get held until CAP END */ if (cmd.reghold.get(user)) @@ -151,15 +136,10 @@ class ModuleCAP : public Module return MOD_RES_PASSTHRU; } - ~ModuleCAP() - { - } - - Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { return Version("Client CAP extension support", VF_VENDOR); } }; MODULE_INIT(ModuleCAP) -