]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
m_spanningtree atoi() to ConvToInt() conversion, add const where possible
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #pragma once
24
25 #include "inspircd.h"
26
27 /* Foward declarations */
28 class TreeServer;
29 class TreeSocket;
30 class Link;
31 class Autoconnect;
32 class ModuleSpanningTree;
33 class SpanningTreeUtilities;
34
35 /* This hash_map holds the hash equivalent of the server
36  * tree, used for rapid linear lookups.
37  */
38 typedef std::tr1::unordered_map<std::string, TreeServer*, std::tr1::insensitive, irc::StrHashComp> server_hash;
39
40 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
41
42 /** Contains helper functions and variables for this module,
43  * and keeps them out of the global namespace
44  */
45 class SpanningTreeUtilities : public classbase
46 {
47  public:
48         /** Creator module
49          */
50         ModuleSpanningTree* Creator;
51
52         /** Flatten links and /MAP for non-opers
53          */
54         bool FlatLinks;
55         /** Hide U-Lined servers in /MAP and /LINKS
56          */
57         bool HideULines;
58         /** Announce TS changes to channels on merge
59          */
60         bool AnnounceTSChange;
61
62         /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
63          */
64         bool AllowOptCommon;
65
66         /** Make snomasks +CQ quiet during bursts and splits
67          */
68         bool quiet_bursts;
69
70         /* Number of seconds that a server can go without ping
71          * before opers are warned of high latency.
72          */
73         int PingWarnTime;
74         /** This variable represents the root of the server tree
75          */
76         TreeServer *TreeRoot;
77         /** IPs allowed to link to us
78          */
79         std::vector<std::string> ValidIPs;
80         /** Hash of currently connected servers by name
81          */
82         server_hash serverlist;
83         /** Hash of currently known server ids
84          */
85         server_hash sidlist;
86         /** Hash of servers currently bursting but not initialized as connected
87          */
88         std::map<irc::string,TreeSocket*> burstingserverlist;
89         /** List of all outgoing sockets and their timeouts
90          */
91         std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
92         /** Holds the data from the <link> tags in the conf
93          */
94         std::vector<reference<Link> > LinkBlocks;
95         /** Holds the data from the <autoconnect> tags in the conf
96          */
97         std::vector<reference<Autoconnect> > AutoconnectBlocks;
98
99         /** True (default) if we are to use challenge-response HMAC
100          * to authenticate passwords.
101          *
102          * NOTE: This defaults to on, but should be turned off if
103          * you are linking to an older version of inspircd.
104          */
105         bool ChallengeResponse;
106
107         /** Ping frequency of server to server links
108          */
109         int PingFreq;
110
111         /** Initialise utility class
112          */
113         SpanningTreeUtilities(ModuleSpanningTree* Creator);
114
115         /** Prepare for class destruction
116          */
117         CullResult cull();
118
119         /** Destroy class and free listeners etc
120          */
121         ~SpanningTreeUtilities();
122
123         void RouteCommand(TreeServer*, const std::string&, const parameterlist&, User*);
124
125         /** Send a message from this server to one other local or remote
126          */
127         bool DoOneToOne(const std::string& prefix, const std::string& command, const parameterlist& params, const std::string& target);
128
129         /** Send a message from this server to all but one other, local or remote
130          */
131         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, const parameterlist& params, const std::string& omit);
132
133         /** Send a message from this server to all others
134          */
135         bool DoOneToMany(const std::string &prefix, const std::string &command, const parameterlist &params);
136
137         /** Read the spanningtree module's tags from the config file
138          */
139         void ReadConfiguration();
140
141         /** Add a server to the server list for GetListOfServersForChannel
142          */
143         void AddThisServer(TreeServer* server, TreeServerList &list);
144
145         /** Compile a list of servers which contain members of channel c
146          */
147         void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
148
149         /** Find a server by name
150          */
151         TreeServer* FindServer(const std::string &ServerName);
152
153         /** Find server by SID
154          */
155         TreeServer* FindServerID(const std::string &id);
156
157         /** Find a route to a server by name
158          */
159         TreeServer* BestRouteTo(const std::string &ServerName);
160
161         /** Find a server by glob mask
162          */
163         TreeServer* FindServerMask(const std::string &ServerName);
164
165         /** Find a link tag from a server name
166          */
167         Link* FindLink(const std::string& name);
168
169         /** Refresh the IP cache used for allowing inbound connections
170          */
171         void RefreshIPCache();
172 };