]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
97c617e0ada9bff406f889c02f836fd76de624ad
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.h
1 #ifndef __ST__UTIL__
2 #define __ST__UTIL__
3
4 #include "configreader.h"
5 #include "users.h"
6 #include "channels.h"
7 #include "modules.h"
8 #include "inspircd.h"
9
10 /* Foward declarations */
11 class TreeServer;
12 class TreeSocket;
13 class Link;
14 class ModuleSpanningTree;
15
16 /* This hash_map holds the hash equivalent of the server
17  * tree, used for rapid linear lookups.
18  */
19 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<string>, irc::StrHashComp> server_hash;
20
21 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
22
23 /** A group of modules that implement InspSocketHook
24  * that we can use to hook our server to server connections.
25  */
26 typedef std::map<irc::string, Module*> hookmodules;
27
28 /** Contains helper functions and variables for this module,
29  * and keeps them out of the global namespace
30  */
31 class SpanningTreeUtilities
32 {
33  private:
34         /** Creator server
35          */
36         InspIRCd* ServerInstance;
37  public:
38         /** Creator module
39          */
40         ModuleSpanningTree* Creator;
41         /** Flatten links and /MAP for non-opers
42          */
43         bool FlatLinks;
44         /** Hide U-Lined servers in /MAP and /LINKS
45          */
46         bool HideULines;
47         /** Announce TS changes to channels on merge
48          */
49         bool AnnounceTSChange;
50         /** Synchronize timestamps between servers
51          */
52         bool EnableTimeSync;
53         /** Socket bindings for listening sockets
54          */
55         std::vector<TreeSocket*> Bindings;
56         /** This variable represents the root of the server tree
57          */
58         TreeServer *TreeRoot;
59         /** IPs allowed to link to us
60          */
61         std::vector<std::string> ValidIPs;
62         /** Hash of currently connected servers by name
63          */
64         server_hash serverlist;
65         /** Holds the data from the <link> tags in the conf
66          */
67         std::vector<Link> LinkBlocks;
68         /** Holds a bitmask of queued xline types waiting to be applied.
69          * Will be a mask containing values APPLY_GLINES, APPLY_KLINES,
70          * APPLY_QLINES and APPLY_ZLINES.
71          */
72         int lines_to_apply;
73
74         /** List of module pointers which can provide I/O abstraction
75          */
76         hookmodules hooks;
77
78         /** List of module names which can provide I/O abstraction
79          */
80         std::vector<std::string> hooknames;
81
82         /** Initialise utility class
83          */
84         SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* Creator);
85         /** Destroy class and free listeners etc
86          */
87         ~SpanningTreeUtilities();
88         /** Send a message from this server to one other local or remote
89          */
90         bool DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target);
91         /** Send a message from this server to all but one other, local or remote
92          */
93         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit);
94         /** Send a message from this server to all but one other, local or remote
95          */
96         bool DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit);
97         /** Send a message from this server to all others
98          */
99         bool DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params);
100         /** Send a message from this server to all others
101          */
102         bool DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params);
103         /** 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)
104          */
105         bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params);
106         /** Read the spanningtree module's tags from the config file
107          */
108         void ReadConfiguration(bool rebind);
109         /** Add a server to the server list for GetListOfServersForChannel
110          */
111         void AddThisServer(TreeServer* server, TreeServerList &list);
112         /** Compile a list of servers which contain members of channel c
113          */
114         void GetListOfServersForChannel(chanrec* c, TreeServerList &list, char status, const CUList &exempt_list);
115         /** Find a server by name
116          */
117         TreeServer* FindServer(const std::string &ServerName);
118         /** Find a route to a server by name
119          */
120         TreeServer* BestRouteTo(const std::string &ServerName);
121         /** Find a server by glob mask
122          */
123         TreeServer* FindServerMask(const std::string &ServerName);
124         /** Returns true if this is a server name we recognise
125          */
126         bool IsServer(const std::string &ServerName);
127         /** Attempt to connect to the failover link of link x
128          */
129         void DoFailOver(Link* x);
130         /** Find a link tag from a server name
131          */
132         Link* FindLink(const std::string& name);
133 };
134
135 #endif