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