]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_ison.cpp
core_privmsg: respect the exemption list when sending $* messages.
[user/henk/code/inspircd.git] / src / coremods / core_ison.cpp
index 3edef82753379ab6debeaa0462dba7ba9745f1bc..3f6b1ac74c2af68bcbfd866083f5ce34378f983e 100644 (file)
 
 /** 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> {nick}";
        }
        /** Handle command.
@@ -35,58 +37,61 @@ 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<std::string>& parameters, User *user);
+       CmdResult HandleLocal(LocalUser* user, const Params& parameters) 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<std::string>& parameters, User *user)
+CmdResult CommandIson::HandleLocal(LocalUser* user, const Params& parameters)
 {
-       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<std::string>::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.erase(pos);
-                       }
-               }
-               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.erase(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;
 }
 
+class CoreModIson : public Module
+{
+ private:
+       CommandIson cmd;
+
+ public:
+       CoreModIson()
+               : cmd(this)
+       {
+       }
+
+       Version GetVersion() CXX11_OVERRIDE
+       {
+               return Version("Provides the ISON command", VF_CORE | VF_VENDOR);
+       }
+};
 
-COMMAND_INIT(CommandIson)
+MODULE_INIT(CoreModIson)