]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_ison.cpp
Move typedef ClassVector to ServerConfig::ClassVector
[user/henk/code/inspircd.git] / src / coremods / core_ison.cpp
index d127ed3443b9795391327df0a4c6b98ae9848ff3..ebb43bdf9c88fe392dba6a4b034b6fb12494a284 100644 (file)
  */
 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<std::string>& 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<std::string>& 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<std::string>::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);
                        }
                }
        }