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