diff options
author | Attila Molnar <attilamolnar@hush.com> | 2016-02-25 17:02:03 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2016-02-25 17:02:03 +0100 |
commit | 304b6dbbf56710b1310fce8c5cf71b73334c060a (patch) | |
tree | 002d219057b5b4fda5c49595eada3eb7e1e8d525 /include | |
parent | dbe5a1fc6f9e18765863f332a3e79d7c918d3e65 (diff) |
Introduce Stats::Context, pass it to the OnStats hook and switch all code to it
Diffstat (limited to 'include')
-rw-r--r-- | include/inspircd.h | 1 | ||||
-rw-r--r-- | include/modules.h | 8 | ||||
-rw-r--r-- | include/modules/stats.h | 172 | ||||
-rw-r--r-- | include/typedefs.h | 5 | ||||
-rw-r--r-- | include/xline.h | 5 |
5 files changed, 182 insertions, 9 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index 931148884..ee09070f8 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -587,3 +587,4 @@ inline void stdalgo::culldeleter::operator()(classbase* item) #include "numericbuilder.h" #include "modules/whois.h" +#include "modules/stats.h" diff --git a/include/modules.h b/include/modules.h index 86ee7f4f3..d97f02046 100644 --- a/include/modules.h +++ b/include/modules.h @@ -873,14 +873,10 @@ class CoreExport Module : public classbase, public usecountbase /** Called on all /STATS commands * This method is triggered for all /STATS use, including stats symbols handled by the core. - * @param symbol the symbol provided to /STATS - * @param user the user issuing the /STATS command - * @param results A string_list to append results into. You should put all your results - * into this string_list, rather than displaying them directly, so that your handler will - * work when remote STATS queries are received. + * @param stats Context of the /STATS request, contains requesting user, list of answer rows etc. * @return 1 to block the /STATS from being processed by the core, 0 to allow it */ - virtual ModResult OnStats(char symbol, User* user, string_list &results); + virtual ModResult OnStats(Stats::Context& stats); /** Called whenever a change of a local users displayed host is attempted. * Return 1 to deny the host change, or 0 to allow it. diff --git a/include/modules/stats.h b/include/modules/stats.h new file mode 100644 index 000000000..b1e27b4e7 --- /dev/null +++ b/include/modules/stats.h @@ -0,0 +1,172 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com> + * + * 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 + +namespace Stats +{ + class Context; + class Row; +} + +class Stats::Row : public Numeric::Numeric +{ + public: + Row(unsigned int num) + : Numeric(num) + { + } +}; + +class Stats::Context +{ + /** Source user of the STATS request + */ + User* const source; + + /** List of reply rows + */ + std::vector<Row> rows; + + /** Symbol indicating the type of this STATS request (usually a letter) + */ + const char symbol; + + public: + /** Constructor + * @param src Source user of the STATS request, can be a local or remote user + * @param sym Symbol (letter) indicating the type of the request + */ + Context(User* src, char sym) + : source(src) + , symbol(sym) + { + } + + /** Get the source user of the STATS request + * @return Source user of the STATS request + */ + User* GetSource() const { return source; } + + /** Get the list of reply rows + * @return List of rows generated as reply for the request + */ + const std::vector<Row>& GetRows() const { return rows; } + + /** Get the symbol (letter) indicating what type of STATS was requested + * @return Symbol specified by the requesting user + */ + char GetSymbol() const { return symbol; } + + /** Add a row to the reply list + * @param row Reply to add + */ + void AddRow(const Row& row) { rows.push_back(row); } + + template <typename T1> + void AddRow(unsigned int numeric, T1 p1) + { + Row n(numeric); + n.push(p1); + AddRow(n); + } + + template <typename T1, typename T2> + void AddRow(unsigned int numeric, T1 p1, T2 p2) + { + Row n(numeric); + n.push(p1); + n.push(p2); + AddRow(n); + } + + template <typename T1, typename T2, typename T3> + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + AddRow(n); + } + + template <typename T1, typename T2, typename T3, typename T4> + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + AddRow(n); + } + + template <typename T1, typename T2, typename T3, typename T4, typename T5> + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + n.push(p5); + AddRow(n); + } + + template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + n.push(p5); + n.push(p6); + AddRow(n); + } + + template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + n.push(p5); + n.push(p6); + n.push(p7); + AddRow(n); + } + + template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> + void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8) + { + Row n(numeric); + n.push(p1); + n.push(p2); + n.push(p3); + n.push(p4); + n.push(p5); + n.push(p6); + n.push(p7); + AddRow(n); + } +}; diff --git a/include/typedefs.h b/include/typedefs.h index dfecb0483..17c05d704 100644 --- a/include/typedefs.h +++ b/include/typedefs.h @@ -111,3 +111,8 @@ typedef XLineContainer::iterator ContainerIter; /** An interator in an XLineLookup */ typedef XLineLookup::iterator LookupIter; + +namespace Stats +{ + class Context; +} diff --git a/include/xline.h b/include/xline.h index fe044d0f2..c2ede29df 100644 --- a/include/xline.h +++ b/include/xline.h @@ -520,8 +520,7 @@ class CoreExport XLineManager * will be expired and removed before the list is displayed. * @param type The type of stats to show * @param numeric The numeric to give to each result line - * @param user The username making the query - * @param results The string_list to receive the results + * @param stats Stats context */ - void InvokeStats(const std::string &type, int numeric, User* user, string_list &results); + void InvokeStats(const std::string& type, unsigned int numeric, Stats::Context& stats); }; |