]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_info/cmd_servlist.cpp
Fix a few issues with SERVLIST.
[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> [<type>]]";
36 }
37
38 CmdResult CommandServList::HandleLocal(LocalUser* user, const Params& parameters)
39 {
40         const std::string& mask = parameters.empty() ? "*" : parameters[0];
41         const bool has_type = parameters.size() > 1;
42         for (UserManager::ULineList::const_iterator iter = ServerInstance->Users.all_ulines.begin(); iter != ServerInstance->Users.all_ulines.end(); ++iter)
43         {
44                 User* uline = *iter;
45                 if (uline->IsModeSet(invisiblemode) || !InspIRCd::Match(uline->nick, mask))
46                         continue;
47
48                 if (has_type && (!user->IsOper() || !InspIRCd::Match(user->oper->name, parameters[2     ])))
49                         continue;
50
51                 Numeric::Numeric numeric(RPL_SERVLIST);
52                 numeric
53                         .push(uline->nick)
54                         .push(uline->server->GetName())
55                         .push("*")
56                         .push(user->IsOper() ? user->oper->name : "*")
57                         .push(0)
58                         .push(uline->GetRealName());
59                 user->WriteNumeric(numeric);
60         }
61         user->WriteNumeric(RPL_SERVLISTEND, mask, has_type ? parameters[1] : "*", "End of service listing");
62         return CMD_SUCCESS;
63 }