X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcoremods%2Fcore_ison.cpp;h=ebb43bdf9c88fe392dba6a4b034b6fb12494a284;hb=30fc51c6ddca487a1b89da9ab0ab59da003aee36;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..ebb43bdf9 100644 --- a/src/coremods/core_ison.cpp +++ b/src/coremods/core_ison.cpp @@ -24,6 +24,14 @@ */ class CommandIson : public Command { + /** 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. */ @@ -38,47 +46,44 @@ class CommandIson : public Command CmdResult Handle(const std::vector& parameters, User *user); }; +bool CommandIson::AddNick(User* user, User* toadd, std::string& reply, const std::string::size_type pos) +{ + if ((toadd) && (toadd->registered == REG_ALL)) + { + reply.append(toadd->nick).push_back(' '); + if (reply.length() > 450) + { + user->WriteServ(reply); + reply.erase(pos); + } + return true; + } + return false; +} + /** Handle /ISON */ CmdResult CommandIson::Handle (const std::vector& parameters, User *user) { - User *u; std::string reply = "303 " + user->nick + " :"; + const std::string::size_type pos = reply.size(); - for (unsigned int i = 0; i < parameters.size(); i++) + for (std::vector::const_iterator i = parameters.begin(); i != parameters.end(); ++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 + const std::string& targetstr = *i; + + User* const u = ServerInstance->FindNickOnly(targetstr); + if (!AddNick(user, u, reply, pos)) { - if ((i == parameters.size() - 1) && (parameters[i].find(' ') != std::string::npos)) + if ((i == parameters.end() - 1) && (targetstr.find(' ') != std::string::npos)) { /* Its a space seperated list of nicks (RFC1459 says to support this) */ - irc::spacesepstream list(parameters[i]); + irc::spacesepstream list(targetstr); 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 + " :"; - } - } - } + AddNick(user, ServerInstance->FindNickOnly(item), reply, pos); } } }