X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcoremods%2Fcore_ison.cpp;h=ebb43bdf9c88fe392dba6a4b034b6fb12494a284;hb=19cc9292ab5889fa09962820f3179e8078bec956;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..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,63 +46,49 @@ 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) { - std::map ison_already; - 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 (ison_already.find(u) != ison_already.end()) - continue; + const std::string& targetstr = *i; - if ((u) && (u->registered == REG_ALL)) + User* const u = ServerInstance->FindNickOnly(targetstr); + if (!AddNick(user, u, reply, pos)) { - 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)) + 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 (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; - } - } + AddNick(user, ServerInstance->FindNickOnly(item), reply, pos); } } } - if (!reply.empty()) - user->WriteServ(reply); - + user->WriteServ(reply); return CMD_SUCCESS; }