]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
Merge tag 'v2.0.27' into master.
[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 class TreeServer;
29 class TreeSocket;
30 class Link;
31 class Autoconnect;
32 class ModuleSpanningTree;
33 class SpanningTreeUtilities;
34 class CmdBuilder;
35
36 extern SpanningTreeUtilities* Utils;
37
38 /** Associative container type, mapping server names/ids to TreeServers
39  */
40 typedef TR1NS::unordered_map<std::string, TreeServer*, irc::insensitive, irc::StrHashComp> server_hash;
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         CacheRefreshTimer RefreshTimer;
48
49  public:
50         typedef std::set<TreeSocket*> TreeSocketSet;
51         typedef std::map<TreeSocket*, std::pair<std::string, unsigned int> > TimeoutList;
52
53         /** Creator module
54          */
55         ModuleSpanningTree* Creator;
56
57         /** Flatten links and /MAP for non-opers
58          */
59         bool FlatLinks;
60
61         /** True if we're going to hide netsplits as *.net *.split for non-opers
62          */
63         bool HideSplits;
64
65         /** Hide U-Lined servers in /MAP and /LINKS
66          */
67         bool HideULines;
68         /** Announce TS changes to channels on merge
69          */
70         bool AnnounceTSChange;
71
72         /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
73          */
74         bool AllowOptCommon;
75
76         /** Make snomasks +CQ quiet during bursts and splits
77          */
78         bool quiet_bursts;
79
80         /* Number of seconds that a server can go without ping
81          * before opers are warned of high latency.
82          */
83         unsigned int PingWarnTime;
84         /** This variable represents the root of the server tree
85          */
86         TreeServer *TreeRoot;
87         /** IPs allowed to link to us
88          */
89         std::vector<std::string> ValidIPs;
90         /** Hash of currently connected servers by name
91          */
92         server_hash serverlist;
93         /** Hash of currently known server ids
94          */
95         server_hash sidlist;
96         /** List of all outgoing sockets and their timeouts
97          */
98         TimeoutList timeoutlist;
99         /** Holds the data from the <link> tags in the conf
100          */
101         std::vector<reference<Link> > LinkBlocks;
102         /** Holds the data from the <autoconnect> tags in the conf
103          */
104         std::vector<reference<Autoconnect> > AutoconnectBlocks;
105
106         /** Ping frequency of server to server links
107          */
108         unsigned int PingFreq;
109
110         /** Initialise utility class
111          */
112         SpanningTreeUtilities(ModuleSpanningTree* Creator);
113
114         /** Prepare for class destruction
115          */
116         CullResult cull() CXX11_OVERRIDE;
117
118         /** Destroy class and free listeners etc
119          */
120         ~SpanningTreeUtilities();
121
122         void RouteCommand(TreeServer* origin, CommandBase* cmd, const CommandBase::Params& parameters, User* user);
123
124         /** Send a message from this server to one other local or remote
125          */
126         void DoOneToOne(const CmdBuilder& params, Server* target);
127
128         /** Send a message from this server to all but one other, local or remote
129          */
130         void DoOneToAllButSender(const CmdBuilder& params, TreeServer* omit);
131
132         /** Send a message from this server to all others
133          */
134         void DoOneToMany(const CmdBuilder& params);
135
136         /** Read the spanningtree module's tags from the config file
137          */
138         void ReadConfiguration();
139
140         /** Handle nick collision
141          */
142         bool DoCollision(User* u, TreeServer* server, time_t remotets, const std::string& remoteident, const std::string& remoteip, const std::string& remoteuid, const char* collidecmd);
143
144         /** Compile a list of servers which contain members of channel c
145          */
146         void GetListOfServersForChannel(Channel* c, TreeSocketSet& list, char status, const CUList& exempt_list);
147
148         /** Find a server by name or SID
149          */
150         TreeServer* FindServer(const std::string &ServerName);
151
152         /** Find server by SID
153          */
154         TreeServer* FindServerID(const std::string &id);
155
156         /** Find a server based on a target string.
157          * @param target Target string where a command should be routed to. May be a server name, a sid, a nickname or a uuid.
158          */
159         TreeServer* FindRouteTarget(const std::string& target);
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
173         /** Sends a PRIVMSG or a NOTICE to a channel obeying an exempt list and an optional prefix
174          */
175         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);
176 };
177
178 inline void SpanningTreeUtilities::DoOneToMany(const CmdBuilder& params)
179 {
180         DoOneToAllButSender(params, NULL);
181 }