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 SplitCommand
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)
39 : SplitCommand(parent, "ISON", 1)
41 syntax = "<nick> {nick}";
44 * @param parameters The parameters to the command
45 * @param user The user issuing the command
46 * @return A value from CmdResult to indicate command success or failure.
48 CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user);
51 bool CommandIson::AddNick(User* user, User* toadd, std::string& reply, const std::string::size_type pos)
53 if ((toadd) && (toadd->registered == REG_ALL))
55 reply.append(toadd->nick).push_back(' ');
56 if (reply.length() > 450)
58 user->WriteServ(reply);
68 CmdResult CommandIson::HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
70 std::string reply = "303 " + user->nick + " :";
71 const std::string::size_type pos = reply.size();
73 for (std::vector<std::string>::const_iterator i = parameters.begin(); i != parameters.end()-1; ++i)
75 const std::string& targetstr = *i;
77 User* const u = ServerInstance->FindNickOnly(targetstr);
78 AddNick(user, u, reply, pos);
81 // Last parameter can be a space separated list
82 irc::spacesepstream ss(parameters.back());
83 for (std::string token; ss.GetToken(token); )
84 AddNick(user, ServerInstance->FindNickOnly(token), reply, pos);
86 user->WriteServ(reply);
91 COMMAND_INIT(CommandIson)