]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/cmd_ison.cpp
Fix some confusing logic in sanick.
[user/henk/code/inspircd.git] / src / coremods / core_user / cmd_ison.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2014-2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2007, 2010 Craig Edwards <brain@inspircd.org>
9  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10  *
11  * This file is part of InspIRCd.  InspIRCd is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation, version 2.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  */
23
24
25 #include "inspircd.h"
26 #include "core_user.h"
27
28 class IsonReplyBuilder : public Numeric::Builder<' ', true>
29 {
30  public:
31         IsonReplyBuilder(LocalUser* user)
32                 : Numeric::Builder<' ', true>(user, RPL_ISON)
33         {
34         }
35
36         void AddNick(const std::string& nickname)
37         {
38                 User* const user = ServerInstance->FindNickOnly(nickname);
39                 if ((user) && (user->registered == REG_ALL))
40                         Add(user->nick);
41         }
42 };
43
44 /** Handle /ISON
45  */
46 CmdResult CommandIson::HandleLocal(LocalUser* user, const Params& parameters)
47 {
48         IsonReplyBuilder reply(user);
49
50         for (std::vector<std::string>::const_iterator i = parameters.begin(); i != parameters.end()-1; ++i)
51         {
52                 const std::string& targetstr = *i;
53                 reply.AddNick(targetstr);
54         }
55
56         // Last parameter can be a space separated list
57         irc::spacesepstream ss(parameters.back());
58         for (std::string token; ss.GetToken(token); )
59                 reply.AddNick(token);
60
61         reply.Flush();
62         return CMD_SUCCESS;
63 }