X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcoremods%2Fcore_ison.cpp;h=642e36b43984046a53c8d8b58522cc4e1980c701;hb=5585654df265bc37d547fa7738e35cc7ae7dacbb;hp=53d2e1c49ef7c7eb5f1d4faa12839a5103b01c5e;hpb=f71e6bf9cb41811f18864f5d4eecb26e29d03f25;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/coremods/core_ison.cpp b/src/coremods/core_ison.cpp index 53d2e1c49..642e36b43 100644 --- a/src/coremods/core_ison.cpp +++ b/src/coremods/core_ison.cpp @@ -22,12 +22,14 @@ /** Handle /ISON. */ -class CommandIson : public Command +class CommandIson : public SplitCommand { public: /** Constructor for ison. */ - CommandIson ( Module* parent) : Command(parent,"ISON", 1) { + CommandIson(Module* parent) + : SplitCommand(parent, "ISON", 1) + { syntax = " {nick}"; } /** Handle command. @@ -35,66 +37,43 @@ class CommandIson : public Command * @param user The user issuing the command * @return A value from CmdResult to indicate command success or failure. */ - CmdResult Handle(const std::vector& parameters, User *user); + CmdResult HandleLocal(const std::vector& parameters, LocalUser* user) CXX11_OVERRIDE; }; -/** Handle /ISON - */ -CmdResult CommandIson::Handle (const std::vector& parameters, User *user) +class IsonReplyBuilder : public Numeric::Builder<' ', true> { - std::map ison_already; - User *u; - std::string reply = "303 " + user->nick + " :"; - - for (unsigned int i = 0; i < parameters.size(); i++) + public: + IsonReplyBuilder(LocalUser* user) + : Numeric::Builder<' ', true>(user, RPL_ISON) { - u = ServerInstance->FindNickOnly(parameters[i]); - if (ison_already.find(u) != ison_already.end()) - continue; + } - if ((u) && (u->registered == REG_ALL)) - { - reply.append(u->nick).append(" "); - if (reply.length() > 450) - { - user->WriteServ(reply); - reply = "303 " + user->nick + " :"; - } - ison_already[u] = u; - } - else - { - if ((i == parameters.size() - 1) && (parameters[i].find(' ') != std::string::npos)) - { - /* Its a space seperated list of nicks (RFC1459 says to support this) - */ - irc::spacesepstream list(parameters[i]); - std::string item; + void AddNick(const std::string& nickname) + { + User* const user = ServerInstance->FindNickOnly(nickname); + if ((user) && (user->registered == REG_ALL)) + Add(user->nick); + } +}; - while (list.GetToken(item)) - { - u = ServerInstance->FindNickOnly(item); - if (ison_already.find(u) != ison_already.end()) - continue; +/** Handle /ISON + */ +CmdResult CommandIson::HandleLocal(const std::vector& parameters, LocalUser* user) +{ + IsonReplyBuilder reply(user); - if ((u) && (u->registered == REG_ALL)) - { - reply.append(u->nick).append(" "); - if (reply.length() > 450) - { - user->WriteServ(reply); - reply = "303 " + user->nick + " :"; - } - ison_already[u] = u; - } - } - } - } + for (std::vector::const_iterator i = parameters.begin(); i != parameters.end()-1; ++i) + { + const std::string& targetstr = *i; + reply.AddNick(targetstr); } - if (!reply.empty()) - user->WriteServ(reply); + // Last parameter can be a space separated list + irc::spacesepstream ss(parameters.back()); + for (std::string token; ss.GetToken(token); ) + reply.AddNick(token); + reply.Flush(); return CMD_SUCCESS; }