X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcoremods%2Fcore_ison.cpp;h=642e36b43984046a53c8d8b58522cc4e1980c701;hb=b7716ed57704b2b2bcc665a590aecc8f02de631d;hp=d127ed3443b9795391327df0a4c6b98ae9848ff3;hpb=b0eca1dbccdbe5ac22b96375011a5cf51a487c47;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/coremods/core_ison.cpp b/src/coremods/core_ison.cpp index d127ed344..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,55 +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; +}; + +class IsonReplyBuilder : public Numeric::Builder<' ', true> +{ + public: + IsonReplyBuilder(LocalUser* user) + : Numeric::Builder<' ', true>(user, RPL_ISON) + { + } + + void AddNick(const std::string& nickname) + { + User* const user = ServerInstance->FindNickOnly(nickname); + if ((user) && (user->registered == REG_ALL)) + Add(user->nick); + } }; /** Handle /ISON */ -CmdResult CommandIson::Handle (const std::vector& parameters, User *user) +CmdResult CommandIson::HandleLocal(const std::vector& parameters, LocalUser* user) { - User *u; - std::string reply = "303 " + user->nick + " :"; + IsonReplyBuilder reply(user); - for (unsigned int i = 0; i < parameters.size(); i++) + for (std::vector::const_iterator i = parameters.begin(); i != parameters.end()-1; ++i) { - u = ServerInstance->FindNickOnly(parameters[i]); - if ((u) && (u->registered == REG_ALL)) - { - reply.append(u->nick).append(" "); - if (reply.length() > 450) - { - user->WriteServ(reply); - reply = "303 " + user->nick + " :"; - } - } - 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; - - while (list.GetToken(item)) - { - u = ServerInstance->FindNickOnly(item); - if ((u) && (u->registered == REG_ALL)) - { - reply.append(u->nick).append(" "); - if (reply.length() > 450) - { - user->WriteServ(reply); - reply = "303 " + user->nick + " :"; - } - } - } - } - } + const std::string& targetstr = *i; + reply.AddNick(targetstr); } - 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; }