]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_info/cmd_servlist.cpp
f400124d2b1e7c02e7ecccd14d7e729d681e127b
[user/henk/code/inspircd.git] / src / coremods / core_info / cmd_servlist.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2020 Sadie Powell <sadie@witchery.services>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21 #include "core_info.h"
22
23 enum
24 {
25         // From RFC 2812.
26         RPL_SERVLIST = 234,
27         RPL_SERVLISTEND = 235
28 };
29
30 CommandServList::CommandServList(Module* parent)
31         : SplitCommand(parent, "SERVLIST")
32         , invisiblemode(parent, "invisible")
33 {
34         allow_empty_last_param = false;
35         syntax = "[<mask>]";
36 }
37
38 CmdResult CommandServList::HandleLocal(LocalUser* user, const Params& parameters)
39 {
40         const std::string& mask = parameters.empty() ? "*" : parameters[0];
41         for (UserManager::ULineList::const_iterator iter = ServerInstance->Users.all_ulines.begin(); iter != ServerInstance->Users.all_ulines.end(); ++iter)
42         {
43                 User* uline = *iter;
44                 if (uline->IsModeSet(invisiblemode) || !InspIRCd::Match(uline->nick, mask))
45                         continue;
46
47                 Numeric::Numeric numeric(RPL_SERVLIST);
48                 numeric
49                         .push(uline->nick)
50                         .push(uline->server->GetName())
51                         .push(mask)
52                         .push(0)
53                         .push(0)
54                         .push(uline->GetRealName());
55                 user->WriteNumeric(numeric);
56         }
57         user->WriteNumeric(RPL_SERVLISTEND, mask, 0, "End of service listing");
58         return CMD_SUCCESS;
59 }