2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class CommandIson : public Command
27 /** Helper function to append a nick to an ISON reply
28 * @param user User doing the /ISON
29 * @param toadd User to append to the ISON reply
30 * @param reply Reply string to append the nick to
31 * @param pos If the reply gets too long it is sent to the user and truncated from this position
33 static bool AddNick(User* user, User* toadd, std::string& reply, const std::string::size_type pos);
36 /** Constructor for ison.
38 CommandIson ( Module* parent) : Command(parent,"ISON", 1) {
39 syntax = "<nick> {nick}";
42 * @param parameters The parameters to the command
43 * @param user The user issuing the command
44 * @return A value from CmdResult to indicate command success or failure.
46 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
49 bool CommandIson::AddNick(User* user, User* toadd, std::string& reply, const std::string::size_type pos)
51 if ((toadd) && (toadd->registered == REG_ALL))
53 reply.append(toadd->nick).push_back(' ');
54 if (reply.length() > 450)
56 user->WriteServ(reply);
66 CmdResult CommandIson::Handle (const std::vector<std::string>& parameters, User *user)
68 std::string reply = "303 " + user->nick + " :";
69 const std::string::size_type pos = reply.size();
71 for (std::vector<std::string>::const_iterator i = parameters.begin(); i != parameters.end(); ++i)
73 const std::string& targetstr = *i;
75 User* const u = ServerInstance->FindNickOnly(targetstr);
76 if (!AddNick(user, u, reply, pos))
78 if ((i == parameters.end() - 1) && (targetstr.find(' ') != std::string::npos))
80 /* Its a space seperated list of nicks (RFC1459 says to support this)
82 irc::spacesepstream list(targetstr);
85 while (list.GetToken(item))
86 AddNick(user, ServerInstance->FindNickOnly(item), reply, pos);
91 user->WriteServ(reply);
96 COMMAND_INIT(CommandIson)