summaryrefslogtreecommitdiff
path: root/include/modules
diff options
context:
space:
mode:
Diffstat (limited to 'include/modules')
-rw-r--r--include/modules/stats.h172
-rw-r--r--include/modules/whois.h54
2 files changed, 214 insertions, 12 deletions
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/modules/whois.h b/include/modules/whois.h
index b64d46410..4f09d268b 100644
--- a/include/modules/whois.h
+++ b/include/modules/whois.h
@@ -55,12 +55,11 @@ class Whois::LineEventListener : public Events::ModuleEventListener
* the values numeric and text, but you cannot change the user the
* numeric is sent to.
* @param whois Whois context, can be used to send numerics
- * @param numeric The numeric of the line being sent
- * @param text The text of the numeric, including any parameters
+ * @param numeric Numeric being sent
* @return MOD_RES_DENY to drop the line completely so that the user does not
* receive it, or MOD_RES_PASSTHRU to allow the line to be sent.
*/
- virtual ModResult OnWhoisLine(Context& whois, unsigned int& numeric, std::string& text) = 0;
+ virtual ModResult OnWhoisLine(Context& whois, Numeric::Numeric& numeric) = 0;
};
class Whois::Context
@@ -97,20 +96,51 @@ class Whois::Context
User* GetTarget() const { return target; }
/** Send a line of WHOIS data to the source of the WHOIS
- * @param numeric Numeric to send
- * @param format Format string for the numeric
- * @param ... Parameters for the format string
*/
- void SendLine(unsigned int numeric, const char* format, ...) CUSTOM_PRINTF(3, 4)
+ template <typename T1>
+ void SendLine(unsigned int numeric, T1 p1)
+ {
+ Numeric::Numeric n(numeric);
+ n.push(target->nick);
+ n.push(p1);
+ SendLine(n);
+ }
+
+ template <typename T1, typename T2>
+ void SendLine(unsigned int numeric, T1 p1, T2 p2)
+ {
+ Numeric::Numeric n(numeric);
+ n.push(target->nick);
+ n.push(p1);
+ n.push(p2);
+ SendLine(n);
+ }
+
+ template <typename T1, typename T2, typename T3>
+ void SendLine(unsigned int numeric, T1 p1, T2 p2, T3 p3)
+ {
+ Numeric::Numeric n(numeric);
+ n.push(target->nick);
+ n.push(p1);
+ n.push(p2);
+ n.push(p3);
+ SendLine(n);
+ }
+
+ template <typename T1, typename T2, typename T3, typename T4>
+ void SendLine(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
{
- std::string textbuffer;
- VAFORMAT(textbuffer, format, format)
- SendLine(numeric, textbuffer);
+ Numeric::Numeric n(numeric);
+ n.push(target->nick);
+ n.push(p1);
+ n.push(p2);
+ n.push(p3);
+ n.push(p4);
+ SendLine(n);
}
/** Send a line of WHOIS data to the source of the WHOIS
* @param numeric Numeric to send
- * @param text Text of the numeric
*/
- virtual void SendLine(unsigned int numeric, const std::string& text) = 0;
+ virtual void SendLine(Numeric::Numeric& numeric) = 0;
};