]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/numeric.h
Merge pull request #677 from Robby-/master-dnsblzline
[user/henk/code/inspircd.git] / include / numeric.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 "numerics.h"
23
24 namespace Numeric
25 {
26         class Numeric;
27 }
28
29 class Numeric::Numeric
30 {
31         /** Numeric number
32          */
33         unsigned int numeric;
34
35         /** Parameters of the numeric
36          */
37         std::vector<std::string> params;
38
39         /** Source server of the numeric, if NULL (the default) then it is the local server
40          */
41         Server* sourceserver;
42
43  public:
44         /** Constructor
45          * @param num Numeric number (RPL_*, ERR_*)
46          */
47         Numeric(unsigned int num)
48                 : numeric(num)
49                 , sourceserver(NULL)
50         {
51         }
52
53         /** Add a parameter to the numeric. The parameter will be converted to a string first with ConvToStr().
54          * @param x Parameter to add
55          */
56         template <typename T>
57         Numeric& push(const T& x)
58         {
59                 params.push_back(ConvToStr(x));
60                 return *this;
61         }
62
63         /** Set the source server of the numeric. The source server defaults to the local server.
64          * @param server Server to set as source
65          */
66         void SetServer(Server* server) { sourceserver = server; }
67
68         /** Get the source server of the numeric
69          * @return Source server or NULL if the source is the local server
70          */
71         Server* GetServer() const { return sourceserver; }
72
73         /** Get the number of the numeric as an unsigned integer
74          * @return Numeric number as an unsigned integer
75          */
76         unsigned int GetNumeric() const { return numeric; }
77
78         /** Get the parameters of the numeric
79          * @return Parameters of the numeric as a const vector of strings
80          */
81         const std::vector<std::string>& GetParams() const { return params; }
82
83         /** Get the parameters of the numeric
84          * @return Parameters of the numeric as a vector of strings
85          */
86         std::vector<std::string>& GetParams() { return params; }
87 };
88
89 namespace Numerics
90 {
91         /** ERR_NOSUCHNICK numeric
92          */
93         class NoSuchNick : public Numeric::Numeric
94         {
95          public:
96                 NoSuchNick(const std::string& nick)
97                         : Numeric(ERR_NOSUCHNICK)
98                 {
99                         push(nick);
100                         push("No such nick/channel");
101                 }
102         };
103 }