2018-11-14 15:01:21 +00:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
|
|
|
*
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
|
2021-05-14 14:48:39 +01:00
|
|
|
* Copyright (C) 2018, 2021 Sadie Powell <sadie@witchery.services>
|
2018-11-14 15:01:21 +00:00
|
|
|
*
|
|
|
|
* This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
* redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "event.h"
|
|
|
|
|
|
|
|
namespace Who
|
|
|
|
{
|
|
|
|
class EventListener;
|
|
|
|
class Request;
|
|
|
|
}
|
|
|
|
|
2021-12-20 20:00:03 +00:00
|
|
|
class Who::EventListener
|
|
|
|
: public Events::ModuleEventListener
|
2018-11-14 15:01:21 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
EventListener(Module* mod)
|
|
|
|
: ModuleEventListener(mod, "event/who")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Called when a result from WHO is about to be queued.
|
|
|
|
* @param request Details about the WHO request which caused this response.
|
|
|
|
* @param source The user who initiated this WHO request.
|
|
|
|
* @param user The user that this line of the WHO request is about.
|
|
|
|
* @param memb The channel membership of the user or NULL if not targeted at a channel.
|
|
|
|
* @param numeric The numeric which will be sent in response to the request.
|
|
|
|
* @return MOD_RES_ALLOW to explicitly allow the response, MOD_RES_DENY to explicitly deny the
|
|
|
|
* response, or MOD_RES_PASSTHRU to let another module handle the event.
|
|
|
|
*/
|
|
|
|
virtual ModResult OnWhoLine(const Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Who::Request
|
|
|
|
{
|
|
|
|
public:
|
2021-05-14 14:26:46 +01:00
|
|
|
typedef std::bitset<UCHAR_MAX + 1> CharState;
|
|
|
|
|
2018-11-14 15:01:21 +00:00
|
|
|
/** The flags for matching users to include. */
|
2021-05-14 14:26:46 +01:00
|
|
|
CharState flags;
|
2018-11-14 15:01:21 +00:00
|
|
|
|
|
|
|
/** Whether we are matching using a wildcard or a flag. */
|
2020-02-06 11:25:42 +00:00
|
|
|
bool fuzzy_match = false;
|
2018-11-14 15:01:21 +00:00
|
|
|
|
|
|
|
/** The text to match against. */
|
|
|
|
std::string matchtext;
|
|
|
|
|
|
|
|
/** The WHO/WHOX responses we will send to the source. */
|
|
|
|
std::vector<Numeric::Numeric> results;
|
|
|
|
|
|
|
|
/** Whether the source requested a WHOX response. */
|
2020-02-06 11:25:42 +00:00
|
|
|
bool whox = false;
|
2018-11-14 15:01:21 +00:00
|
|
|
|
|
|
|
/** The fields to include in the WHOX response. */
|
2021-05-14 14:26:46 +01:00
|
|
|
CharState whox_fields;
|
2018-11-14 15:01:21 +00:00
|
|
|
|
|
|
|
/** A user specified label for the WHOX response. */
|
|
|
|
std::string whox_querytype;
|
|
|
|
|
2019-03-12 09:48:28 -05:00
|
|
|
/** Get the index in the response parameters for the different data fields
|
|
|
|
*
|
|
|
|
* The fields 'r' (realname) and 'd' (hops) will always be missing in a non-WHOX
|
|
|
|
* query, because WHOX splits them to 2 fields, where old WHO has them as one.
|
|
|
|
*
|
|
|
|
* @param flag The field name to look for
|
|
|
|
* @param out The index will be stored in this value
|
|
|
|
* @return True if the field is available, false otherwise
|
|
|
|
*/
|
2019-03-12 12:04:01 -05:00
|
|
|
virtual bool GetFieldIndex(char flag, size_t& out) const = 0;
|
2019-03-12 09:48:28 -05:00
|
|
|
|
2018-11-14 15:01:21 +00:00
|
|
|
protected:
|
2020-02-06 11:25:42 +00:00
|
|
|
Request() = default;
|
2018-11-14 15:01:21 +00:00
|
|
|
};
|