X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_cap.cpp;h=ee9c96936c23122ac1cac055f945b92a3d51d58e;hb=e9e75e50bc25e67af22dd88b39b12217a553d5cb;hp=160c7a9c92105903a119f7f054be018cbdf088ad;hpb=6d57bbe05c31c79eaad02fe81cfb9c1ed6b79c58;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp index 160c7a9c9..ee9c96936 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-2009 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" +#include "modules/cap.h" /* $ModDesc: Provides the CAP negotiation mechanism seen in ratbox-derived ircds */ @@ -36,9 +43,10 @@ class CommandCAP : public Command { public: LocalIntExt reghold; - CommandCAP (InspIRCd* Instance, Module* mod) : Command(Instance, mod, "CAP", 0, 1, true), + CommandCAP (Module* mod) : Command(mod, "CAP", 1), reghold("CAP_REGHOLD", mod) { + works_before_reg = true; } CmdResult Handle (const std::vector ¶meters, User *user) @@ -47,19 +55,14 @@ class CommandCAP : public Command if (subcommand == "REQ") { - CapData Data; - - 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_)) { @@ -67,19 +70,18 @@ class CommandCAP : public Command } reghold.set(user, 1); - Event event((char*) &Data, this->creator, "cap_req"); - event.Send(this->ServerInstance); + Data.Send(); 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()); + 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 * NAK :%s", NakResult.c_str()); + user->WriteServ("CAP %s NAK :%s", user->nick.c_str(), NakResult.c_str()); } } else if (subcommand == "END") @@ -88,45 +90,36 @@ class CommandCAP : public Command } else if ((subcommand == "LS") || (subcommand == "LIST")) { - CapData Data; - - 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); - Event event((char*) &Data, this->creator, subcommand == "LS" ? "cap_ls" : "cap_list"); - event.Send(this->ServerInstance); + 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()); + 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; + CapEvent Data(creator, user, CapEvent::CAPEVENT_CLEAR); reghold.set(user, 1); - Event event((char*) &Data, this->creator, "cap_clear"); - event.Send(this->ServerInstance); + 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; + 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->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "* %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; } }; @@ -134,17 +127,21 @@ class ModuleCAP : public Module { CommandCAP cmd; public: - ModuleCAP(InspIRCd* Me) - : Module(Me), cmd(Me, this) + ModuleCAP() + : cmd(this) + { + } + + void init() { - ServerInstance->AddCommand(&cmd); - Extensible::Register(&cmd.reghold); + ServerInstance->Modules->AddService(cmd); + ServerInstance->Modules->AddService(cmd.reghold); Implementation eventlist[] = { I_OnCheckReady }; - ServerInstance->Modules->Attach(eventlist, this, 1); + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } - ModResult OnCheckReady(User* user) + ModResult OnCheckReady(LocalUser* user) { /* Users in CAP state get held until CAP END */ if (cmd.reghold.get(user)) @@ -153,10 +150,6 @@ class ModuleCAP : public Module return MOD_RES_PASSTHRU; } - ~ModuleCAP() - { - } - Version GetVersion() { return Version("Client CAP extension support", VF_VENDOR); @@ -164,4 +157,3 @@ class ModuleCAP : public Module }; MODULE_INIT(ModuleCAP) -