X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcoremods%2Fcore_ison.cpp;h=f1733ba88a7755f79ffe9c6a1699903f839b7997;hb=b200104cf2c61465acecaca111e3ec727fc3b954;hp=8c1c3d2f54459de34a514e6aad6817a2e9ddc60f;hpb=8670d8c51f1debd8afb6732e782fc61d2e479349;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/coremods/core_ison.cpp b/src/coremods/core_ison.cpp index 8c1c3d2f5..f1733ba88 100644 --- a/src/coremods/core_ison.cpp +++ b/src/coremods/core_ison.cpp @@ -22,20 +22,14 @@ /** Handle /ISON. */ -class CommandIson : public Command +class CommandIson : public SplitCommand { - /** Helper function to append a nick to an ISON reply - * @param user User doing the /ISON - * @param toadd User to append to the ISON reply - * @param reply Reply string to append the nick to - * @param pos If the reply gets too long it is sent to the user and truncated from this position - */ - static bool AddNick(User* user, User* toadd, std::string& reply, const std::string::size_type pos); - public: /** Constructor for ison. */ - CommandIson ( Module* parent) : Command(parent,"ISON", 1) { + CommandIson(Module* parent) + : SplitCommand(parent, "ISON", 1) + { syntax = " {nick}"; } /** Handle command. @@ -43,51 +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); }; -bool CommandIson::AddNick(User* user, User* toadd, std::string& reply, const std::string::size_type pos) +class IsonReplyBuilder : public Numeric::Builder<' ', true> { - if ((toadd) && (toadd->registered == REG_ALL)) + public: + IsonReplyBuilder(LocalUser* user) + : Numeric::Builder<' ', true>(user, RPL_ISON) { - reply.append(toadd->nick).push_back(' '); - if (reply.length() > 450) - { - user->WriteServ(reply); - reply.erase(pos); - } - return true; } - return false; -} + + 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 + " :"; - const std::string::size_type pos = reply.size(); + 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 (!AddNick(user, u, reply, pos)) - { - 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)) - AddNick(user, ServerInstance->FindNickOnly(item), reply, pos); - } - } + 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; }