]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
9e6f41852f2d1c4ba631551d8c95c4859a14af85
[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 #include "cachetimer.h"
27
28 /* Foward declarations */
29 class TreeServer;
30 class TreeSocket;
31 class Link;
32 class Autoconnect;
33 class ModuleSpanningTree;
34 class SpanningTreeUtilities;
35 class CmdBuilder;
36
37 extern SpanningTreeUtilities* Utils;
38
39 /* This hash_map holds the hash equivalent of the server
40  * tree, used for rapid linear lookups.
41  */
42 typedef TR1NS::unordered_map<std::string, TreeServer*, irc::insensitive, irc::StrHashComp> server_hash;
43
44 /** Contains helper functions and variables for this module,
45  * and keeps them out of the global namespace
46  */
47 class SpanningTreeUtilities : public classbase
48 {
49         CacheRefreshTimer RefreshTimer;
50
51  public:
52         typedef std::set<TreeSocket*> TreeSocketSet;
53
54         /** Creator module
55          */
56         ModuleSpanningTree* Creator;
57
58         /** Flatten links and /MAP for non-opers
59          */
60         bool FlatLinks;
61         /** Hide U-Lined servers in /MAP and /LINKS
62          */
63         bool HideULines;
64         /** Announce TS changes to channels on merge
65          */
66         bool AnnounceTSChange;
67
68         /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
69          */
70         bool AllowOptCommon;
71
72         /** Make snomasks +CQ quiet during bursts and splits
73          */
74         bool quiet_bursts;
75
76         /* Number of seconds that a server can go without ping
77          * before opers are warned of high latency.
78          */
79         int PingWarnTime;
80         /** This variable represents the root of the server tree
81          */
82         TreeServer *TreeRoot;
83         /** IPs allowed to link to us
84          */
85         std::vector<std::string> ValidIPs;
86         /** Hash of currently connected servers by name
87          */
88         server_hash serverlist;
89         /** Hash of currently known server ids
90          */
91         server_hash sidlist;
92         /** List of all outgoing sockets and their timeouts
93          */
94         std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
95         /** Holds the data from the <link> tags in the conf
96          */
97         std::vector<reference<Link> > LinkBlocks;
98         /** Holds the data from the <autoconnect> tags in the conf
99          */
100         std::vector<reference<Autoconnect> > AutoconnectBlocks;
101
102         /** True (default) if we are to use challenge-response HMAC
103          * to authenticate passwords.
104          *
105          * NOTE: This defaults to on, but should be turned off if
106          * you are linking to an older version of inspircd.
107          */
108         bool ChallengeResponse;
109
110         /** Ping frequency of server to server links
111          */
112         int PingFreq;
113
114         /** Initialise utility class
115          */
116         SpanningTreeUtilities(ModuleSpanningTree* Creator);
117
118         /** Prepare for class destruction
119          */
120         CullResult cull();
121
122         /** Destroy class and free listeners etc
123          */
124         ~SpanningTreeUtilities();
125
126         void RouteCommand(TreeServer* origin, CommandBase* cmd, const parameterlist& parameters, User* user);
127
128         /** Send a message from this server to one other local or remote
129          */
130         bool DoOneToOne(const CmdBuilder& params, const std::string& target);
131
132         /** Send a message from this server to all but one other, local or remote
133          */
134         void DoOneToAllButSender(const CmdBuilder& params, TreeServer* omit);
135
136         /** Send a message from this server to all others
137          */
138         void DoOneToMany(const CmdBuilder& params);
139
140         /** Read the spanningtree module's tags from the config file
141          */
142         void ReadConfiguration();
143
144         /** Handle nick collision
145          */
146         int DoCollision(User* u, TreeServer* server, time_t remotets, const std::string& remoteident, const std::string& remoteip, const std::string& remoteuid);
147
148         /** Compile a list of servers which contain members of channel c
149          */
150         void GetListOfServersForChannel(Channel* c, TreeSocketSet& list, char status, const CUList& exempt_list);
151
152         /** Find a server by name
153          */
154         TreeServer* FindServer(const std::string &ServerName);
155
156         /** Find server by SID
157          */
158         TreeServer* FindServerID(const std::string &id);
159
160         /** Find a route to a server by name
161          */
162         TreeServer* BestRouteTo(const std::string &ServerName);
163
164         /** Find a server by glob mask
165          */
166         TreeServer* FindServerMask(const std::string &ServerName);
167
168         /** Find a link tag from a server name
169          */
170         Link* FindLink(const std::string& name);
171
172         /** Refresh the IP cache used for allowing inbound connections
173          */
174         void RefreshIPCache();
175
176         /** Sends a PRIVMSG or a NOTICE to a channel obeying an exempt list and an optional prefix
177          */
178         void SendChannelMessage(const std::string& prefix, Channel* target, const std::string& text, char status, const CUList& exempt_list, const char* message_type, TreeSocket* omit = NULL);
179 };
180
181 inline void SpanningTreeUtilities::DoOneToMany(const CmdBuilder& params)
182 {
183         DoOneToAllButSender(params, NULL);
184 }