]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
Replace some voodoo with a define
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 "configreader.h"
18 #include "users.h"
19 #include "channels.h"
20 #include "modules.h"
21 #include "inspircd.h"
22
23 /* Foward declarations */
24 class TreeServer;
25 class TreeSocket;
26 class Link;
27 class ModuleSpanningTree;
28
29 /* This hash_map holds the hash equivalent of the server
30  * tree, used for rapid linear lookups.
31  */
32 #ifdef WINDOWS
33 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash_compare<string, less<string> > > server_hash;
34 #else
35 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<string>, irc::StrHashComp> server_hash;
36 #endif
37
38 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
39
40 /** A group of modules that implement InspSocketHook
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
49 {
50  private:
51         /** Creator server
52          */
53         InspIRCd* ServerInstance;
54  public:
55         /** Creator module
56          */
57         ModuleSpanningTree* Creator;
58         /** Remote servers that are currently bursting
59          */
60         server_hash RemoteServersBursting;
61         /** Flatten links and /MAP for non-opers
62          */
63         bool FlatLinks;
64         /** Hide U-Lined servers in /MAP and /LINKS
65          */
66         bool HideULines;
67         /** Announce TS changes to channels on merge
68          */
69         bool AnnounceTSChange;
70         /** Synchronize timestamps between servers
71          */
72         bool EnableTimeSync;
73         /** Make snomasks +CQ quiet during bursts and splits
74          */
75         bool quiet_bursts;
76         /** Socket bindings for listening sockets
77          */
78         std::vector<TreeSocket*> Bindings;
79         /* Number of seconds that a server can go without ping
80          * before opers are warned of high latency.
81          */
82         int PingWarnTime;
83         /** This variable represents the root of the server tree
84          */
85         TreeServer *TreeRoot;
86         /** IPs allowed to link to us
87          */
88         std::vector<std::string> ValidIPs;
89         /** Hash of currently connected servers by name
90          */
91         server_hash serverlist;
92         /** Hash of servers currently bursting but not initialized as connected
93          */
94         std::map<irc::string,TreeSocket*> burstingserverlist;
95         /** Holds the data from the <link> tags in the conf
96          */
97         std::vector<Link> LinkBlocks;
98         /** Holds a bitmask of queued xline types waiting to be applied.
99          * Will be a mask containing values APPLY_GLINES, APPLY_KLINES,
100          * APPLY_QLINES and APPLY_ZLINES.
101          */
102         int lines_to_apply;
103
104         /** If this is true, this server is the master sync server for time
105          * synching - e.g. it is the server with its clock correct. It will
106          * send out the correct time at intervals.
107          */
108         bool MasterTime;
109
110         /** List of module pointers which can provide I/O abstraction
111          */
112         hookmodules hooks;
113
114         /** List of module names which can provide I/O abstraction
115          */
116         std::vector<std::string> hooknames;
117
118         /** True (default) if we are to use challenge-response HMAC
119          * to authenticate passwords.
120          *
121          * NOTE: This defaults to on, but should be turned off if
122          * you are linking to an older version of inspircd.
123          */
124         bool ChallengeResponse;
125
126         /** Initialise utility class
127          */
128         SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* Creator);
129         /** Destroy class and free listeners etc
130          */
131         ~SpanningTreeUtilities();
132         /** Send a message from this server to one other local or remote
133          */
134         bool DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target);
135         /** Send a message from this server to all but one other, local or remote
136          */
137         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit);
138         /** Send a message from this server to all but one other, local or remote
139          */
140         bool DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit);
141         /** Send a message from this server to all others
142          */
143         bool DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params);
144         /** Send a message from this server to all others
145          */
146         bool DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params);
147         /** 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)
148          */
149         bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params);
150         /** Read the spanningtree module's tags from the config file
151          */
152         void ReadConfiguration(bool rebind);
153         /** Add a server to the server list for GetListOfServersForChannel
154          */
155         void AddThisServer(TreeServer* server, TreeServerList &list);
156         /** Compile a list of servers which contain members of channel c
157          */
158         void GetListOfServersForChannel(chanrec* c, TreeServerList &list, char status, const CUList &exempt_list);
159         /** Find a server by name
160          */
161         TreeServer* FindServer(const std::string &ServerName);
162         /** Find a remote bursting server by name
163          */
164         TreeServer* FindRemoteBurstServer(TreeServer* Server);
165         /** Set a remote server to bursting or not bursting
166          */
167         void SetRemoteBursting(TreeServer* Server, bool bursting);
168         /** Find a route to a server by name
169          */
170         TreeServer* BestRouteTo(const std::string &ServerName);
171         /** Find a server by glob mask
172          */
173         TreeServer* FindServerMask(const std::string &ServerName);
174         /** Returns true if this is a server name we recognise
175          */
176         bool IsServer(const std::string &ServerName);
177         /** Attempt to connect to the failover link of link x
178          */
179         void DoFailOver(Link* x);
180         /** Find a link tag from a server name
181          */
182         Link* FindLink(const std::string& name);
183         /** Refresh the IP cache used for allowing inbound connections
184          */
185         void RefreshIPCache();
186
187         TreeSocket* FindBurstingServer(const std::string &ServerName);
188
189         void AddBurstingServer(const std::string &ServerName, TreeSocket* s);
190
191         void DelBurstingServer(TreeSocket* s);
192 };
193
194 #endif