]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/stats.h
Remove the Kiwi links from the readme.
[user/henk/code/inspircd.git] / include / modules / stats.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com>
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 Stats
26 {
27         class Context;
28         class EventListener;
29         class Row;
30 }
31
32 class Stats::EventListener : public Events::ModuleEventListener
33 {
34  public:
35         EventListener(Module* mod)
36                 : ModuleEventListener(mod, "event/stats")
37         {
38         }
39
40         /** Called when the STATS command is executed.
41          * @param stats Context of the /STATS request, contains requesting user, list of answer rows etc.
42          * @return MOD_RES_DENY if the stats request has been fulfilled. Otherwise, MOD_RES_PASSTHRU.
43          */
44         virtual ModResult OnStats(Stats::Context& stats) = 0;
45 };
46
47 class Stats::Row : public Numeric::Numeric
48 {
49  public:
50         Row(unsigned int num)
51                 : Numeric(num)
52         {
53         }
54 };
55
56 class Stats::Context
57 {
58         /** Source user of the STATS request
59          */
60         User* const source;
61
62         /** List of reply rows
63          */
64         std::vector<Row> rows;
65
66         /** Symbol indicating the type of this STATS request (usually a letter)
67          */
68         const char symbol;
69
70  public:
71         /** Constructor
72          * @param src Source user of the STATS request, can be a local or remote user
73          * @param sym Symbol (letter) indicating the type of the request
74          */
75         Context(User* src, char sym)
76                 : source(src)
77                 , symbol(sym)
78         {
79         }
80
81         /** Get the source user of the STATS request
82          * @return Source user of the STATS request
83          */
84         User* GetSource() const { return source; }
85
86         /** Get the list of reply rows
87          * @return List of rows generated as reply for the request
88          */
89         const std::vector<Row>& GetRows() const { return rows; }
90
91         /** Get the symbol (letter) indicating what type of STATS was requested
92          * @return Symbol specified by the requesting user
93          */
94         char GetSymbol() const { return symbol; }
95
96         /** Add a row to the reply list
97          * @param row Reply to add
98          */
99         void AddRow(const Row& row) { rows.push_back(row); }
100
101         template <typename T1>
102         void AddRow(unsigned int numeric, T1 p1)
103         {
104                 Row n(numeric);
105                 n.push(p1);
106                 AddRow(n);
107         }
108
109         template <typename T1, typename T2>
110         void AddRow(unsigned int numeric, T1 p1, T2 p2)
111         {
112                 Row n(numeric);
113                 n.push(p1);
114                 n.push(p2);
115                 AddRow(n);
116         }
117
118         template <typename T1, typename T2, typename T3>
119         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3)
120         {
121                 Row n(numeric);
122                 n.push(p1);
123                 n.push(p2);
124                 n.push(p3);
125                 AddRow(n);
126         }
127
128         template <typename T1, typename T2, typename T3, typename T4>
129         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
130         {
131                 Row n(numeric);
132                 n.push(p1);
133                 n.push(p2);
134                 n.push(p3);
135                 n.push(p4);
136                 AddRow(n);
137         }
138
139         template <typename T1, typename T2, typename T3, typename T4, typename T5>
140         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5)
141         {
142                 Row n(numeric);
143                 n.push(p1);
144                 n.push(p2);
145                 n.push(p3);
146                 n.push(p4);
147                 n.push(p5);
148                 AddRow(n);
149         }
150
151         template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
152         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6)
153         {
154                 Row n(numeric);
155                 n.push(p1);
156                 n.push(p2);
157                 n.push(p3);
158                 n.push(p4);
159                 n.push(p5);
160                 n.push(p6);
161                 AddRow(n);
162         }
163
164         template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
165         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7)
166         {
167                 Row n(numeric);
168                 n.push(p1);
169                 n.push(p2);
170                 n.push(p3);
171                 n.push(p4);
172                 n.push(p5);
173                 n.push(p6);
174                 n.push(p7);
175                 AddRow(n);
176         }
177
178         template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
179         void AddRow(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4, T5 p5, T6 p6, T7 p7, T8 p8)
180         {
181                 Row n(numeric);
182                 n.push(p1);
183                 n.push(p2);
184                 n.push(p3);
185                 n.push(p4);
186                 n.push(p5);
187                 n.push(p6);
188                 n.push(p7);
189                 n.push(p8);
190                 AddRow(n);
191         }
192 };