diff options
Diffstat (limited to 'src/modules/m_cap.cpp')
-rw-r--r-- | src/modules/m_cap.cpp | 49 |
1 files changed, 15 insertions, 34 deletions
diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp index e9f4dae90..bc79e59ec 100644 --- a/src/modules/m_cap.cpp +++ b/src/modules/m_cap.cpp @@ -19,9 +19,7 @@ #include "inspircd.h" -#include "m_cap.h" - -/* $ModDesc: Provides the CAP negotiation mechanism seen in ratbox-derived ircds */ +#include "modules/cap.h" /* CAP LS @@ -51,7 +49,8 @@ class CommandCAP : public Command CmdResult Handle (const std::vector<std::string> ¶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") { @@ -66,6 +65,7 @@ class CommandCAP : public Command while (cap_stream.GetToken(cap_)) { + std::transform(cap_.begin(), cap_.end(), cap_.begin(), ::tolower); Data.wanted.push_back(cap_); } @@ -74,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 %s ACK :%s", user->nick.c_str(), 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 %s NAK :%s", user->nick.c_str(), NakResult.c_str()); + std::string NakResult = irc::stringjoiner(Data.wanted); + user->WriteCommand("CAP", "NAK :" + NakResult); } } else if (subcommand == "END") @@ -95,11 +95,8 @@ class CommandCAP : public Command 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(); - - user->WriteServ("CAP %s %s :%s", user->nick.c_str(), subcommand.c_str(), Result.c_str()); + std::string Result = irc::stringjoiner(Data.wanted); + user->WriteCommand("CAP", subcommand + " :" + Result); } else if (subcommand == "CLEAR") { @@ -108,14 +105,12 @@ class CommandCAP : public Command reghold.set(user, 1); Data.Send(); - 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()); + std::string Result = irc::stringjoiner(Data.ack); + user->WriteCommand("CAP", "ACK :" + Result); } else { - user->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "%s %s :Invalid CAP subcommand", user->nick.c_str(), subcommand.c_str()); + user->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "%s :Invalid CAP subcommand", subcommand.c_str()); return CMD_FAILURE; } @@ -132,16 +127,7 @@ class ModuleCAP : public Module { } - void init() - { - ServerInstance->Modules->AddService(cmd); - ServerInstance->Modules->AddService(cmd.reghold); - - Implementation eventlist[] = { I_OnCheckReady }; - ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); - } - - ModResult OnCheckReady(LocalUser* user) + ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE { /* Users in CAP state get held until CAP END */ if (cmd.reghold.get(user)) @@ -150,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) - |