]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
Always deny invite to users below halfop status, move OnUserPreInvite up to above...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __ST__UTIL__
15 #define __ST__UTIL__
16
17 #include "inspircd.h"
18
19 /* Foward declarations */
20 class TreeServer;
21 class TreeSocket;
22 class Link;
23 class ModuleSpanningTree;
24
25 /* This hash_map holds the hash equivalent of the server
26  * tree, used for rapid linear lookups.
27  */
28 #ifdef WINDOWS
29         typedef nspace::hash_map<std::string, TreeServer*, nspace::hash_compare<std::string, std::less<std::string> > > server_hash;
30 #else
31         #ifdef HASHCOMP_DEPRECATED
32                 typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
33         #else
34                 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
35         #endif
36 #endif
37
38 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
39
40 /** A group of modules that implement BufferedSocketHook
41  * that we can use to hook our server to server connections.
42  */
43 typedef std::map<irc::string, Module*> hookmodules;
44
45 /** Contains helper functions and variables for this module,
46  * and keeps them out of the global namespace
47  */
48 class SpanningTreeUtilities : public classbase
49 {
50  private:
51         /** Creator server
52          */
53         InspIRCd* ServerInstance;
54  public:
55         /** Creator module
56          */
57         ModuleSpanningTree* Creator;
58
59         /** Flatten links and /MAP for non-opers
60          */
61         bool FlatLinks;
62         /** Hide U-Lined servers in /MAP and /LINKS
63          */
64         bool HideULines;
65         /** Announce TS changes to channels on merge
66          */
67         bool AnnounceTSChange;
68
69         /** Make snomasks +CQ quiet during bursts and splits
70          */
71         bool quiet_bursts;
72         /** Socket bindings for listening sockets
73          */
74         std::vector<TreeSocket*> Bindings;
75         /* Number of seconds that a server can go without ping
76          * before opers are warned of high latency.
77          */
78         int PingWarnTime;
79         /** This variable represents the root of the server tree
80          */
81         TreeServer *TreeRoot;
82         /** IPs allowed to link to us
83          */
84         std::vector<std::string> ValidIPs;
85         /** Hash of currently connected servers by name
86          */
87         server_hash serverlist;
88         /** Hash of currently known server ids
89          */
90         server_hash sidlist;
91         /** Hash of servers currently bursting but not initialized as connected
92          */
93         std::map<irc::string,TreeSocket*> burstingserverlist;
94         /** Holds the data from the <link> tags in the conf
95          */
96         std::vector<Link> LinkBlocks;
97
98         /** List of module pointers which can provide I/O abstraction
99          */
100         hookmodules hooks;
101
102         /** List of module names which can provide I/O abstraction
103          */
104         std::vector<std::string> hooknames;
105
106         /** True (default) if we are to use challenge-response HMAC
107          * to authenticate passwords.
108          *
109          * NOTE: This defaults to on, but should be turned off if
110          * you are linking to an older version of inspircd.
111          */
112         bool ChallengeResponse;
113
114         /** Ping frequency of server to server links
115          */
116         int PingFreq;
117
118         /** Initialise utility class
119          */
120         SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* Creator);
121
122         /** Destroy class and free listeners etc
123          */
124         ~SpanningTreeUtilities();
125
126         /** Send a message from this server to one other local or remote
127          */
128         bool DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target);
129
130         /** Send a message from this server to all but one other, local or remote
131          */
132         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit);
133
134         /** Send a message from this server to all but one other, local or remote
135          */
136         bool DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit);
137
138         /** Send a message from this server to all others
139          */
140         bool DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params);
141
142         /** Send a message from this server to all others
143          */
144         bool DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params);
145
146         /** Send a message from this server to all others, without doing any processing on the command (e.g. send it as-is with colons and all)
147          */
148         bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params);
149
150         /** Read the spanningtree module's tags from the config file
151          */
152         void ReadConfiguration(bool rebind);
153
154         /** Add a server to the server list for GetListOfServersForChannel
155          */
156         void AddThisServer(TreeServer* server, TreeServerList &list);
157
158         /** Compile a list of servers which contain members of channel c
159          */
160         void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
161
162         /** Find a server by name
163          */
164         TreeServer* FindServer(const std::string &ServerName);
165
166         /** Find server by SID
167          */
168         TreeServer* FindServerID(const std::string &id);
169
170         /** Find a route to a server by name
171          */
172         TreeServer* BestRouteTo(const std::string &ServerName);
173
174         /** Find a server by glob mask
175          */
176         TreeServer* FindServerMask(const std::string &ServerName);
177
178         /** Returns true if this is a server name we recognise
179          */
180         bool IsServer(const std::string &ServerName);
181
182         /** Attempt to connect to the failover link of link x
183          */
184         void DoFailOver(Link* x);
185
186         /** Find a link tag from a server name
187          */
188         Link* FindLink(const std::string& name);
189
190         /** Refresh the IP cache used for allowing inbound connections
191          */
192         void RefreshIPCache();
193 };
194
195 #endif