/** 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.
* @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(const std::vector<std::string>& parameters, LocalUser* user);
};
-/** Handle /ISON
- */
-CmdResult CommandIson::Handle (const std::vector<std::string>& parameters, User *user)
+class IsonReplyBuilder : public Numeric::Builder<' ', true>
{
- std::map<User*,User*> ison_already;
- User *u;
- std::string reply = "303 " + user->nick + " :";
-
- for (unsigned int i = 0; i < parameters.size(); i++)
+ public:
+ IsonReplyBuilder(LocalUser* user)
+ : Numeric::Builder<' ', true>(user, RPL_ISON)
{
- u = ServerInstance->FindNickOnly(parameters[i]);
- 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;
- }
- 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;
+ void AddNick(const std::string& nickname)
+ {
+ User* const user = ServerInstance->FindNickOnly(nickname);
+ if ((user) && (user->registered == REG_ALL))
+ Add(user->nick);
+ }
+};
- while (list.GetToken(item))
- {
- u = ServerInstance->FindNickOnly(item);
- if (ison_already.find(u) != ison_already.end())
- continue;
+/** Handle /ISON
+ */
+CmdResult CommandIson::HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
+{
+ IsonReplyBuilder reply(user);
- 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;
- }
- }
- }
- }
+ for (std::vector<std::string>::const_iterator i = parameters.begin(); i != parameters.end()-1; ++i)
+ {
+ const std::string& targetstr = *i;
+ reply.AddNick(targetstr);
}
- if (!reply.empty())
- 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;
}