]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/who.h
d5fcba9777ab848a482190f26a93d771ee61d7f5
[user/henk/code/inspircd.git] / include / modules / who.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5  *   Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
6  *
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.
10  *
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
14  * details.
15  *
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/>.
18  */
19
20
21 #pragma once
22
23 #include "event.h"
24
25 namespace Who
26 {
27         class EventListener;
28         class Request;
29 }
30
31 class Who::EventListener : public Events::ModuleEventListener
32 {
33  public:
34         EventListener(Module* mod)
35                 : ModuleEventListener(mod, "event/who")
36         {
37         }
38
39         /** Called when a result from WHO is about to be queued.
40          * @param request Details about the WHO request which caused this response.
41          * @param source The user who initiated this WHO request.
42          * @param user The user that this line of the WHO request is about.
43          * @param memb The channel membership of the user or NULL if not targeted at a channel.
44          * @param numeric The numeric which will be sent in response to the request.
45          * @return MOD_RES_ALLOW to explicitly allow the response, MOD_RES_DENY to explicitly deny the
46          *         response, or MOD_RES_PASSTHRU to let another module handle the event.
47          */
48         virtual ModResult OnWhoLine(const Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) = 0;
49 };
50
51 class Who::Request
52 {
53  public:
54         typedef std::bitset<UCHAR_MAX + 1> CharState;
55
56         /** The flags for matching users to include. */
57         CharState flags;
58
59         /** Whether we are matching using a wildcard or a flag. */
60         bool fuzzy_match;
61
62         /** The text to match against. */
63         std::string matchtext;
64
65         /** The WHO/WHOX responses we will send to the source. */
66         std::vector<Numeric::Numeric> results;
67
68         /** Whether the source requested a WHOX response. */
69         bool whox;
70
71         /** The fields to include in the WHOX response. */
72         CharState whox_fields;
73
74         /** A user specified label for the WHOX response. */
75         std::string whox_querytype;
76
77         /** Get the index in the response parameters for the different data fields
78          *
79          * The fields 'r' (realname) and 'd' (hops) will always be missing in a non-WHOX
80          * query, because WHOX splits them to 2 fields, where old WHO has them as one.
81          *
82          * @param flag The field name to look for
83          * @param out The index will be stored in this value
84          * @return True if the field is available, false otherwise
85          */
86         virtual bool GetFieldIndex(char flag, size_t& out) const = 0;
87
88  protected:
89         Request()
90                 : fuzzy_match(false)
91                 , whox(false)
92         {
93         }
94 };