]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/main.h
Add the server id to the Server class.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / main.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
6  *   Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
7  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
9  *
10  * This file is part of InspIRCd.  InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23
24 #pragma once
25
26 #include "inspircd.h"
27 #include "event.h"
28 #include "modules/dns.h"
29 #include "modules/ssl.h"
30 #include "modules/stats.h"
31 #include "modules/ctctags.h"
32 #include "modules/server.h"
33 #include "servercommand.h"
34 #include "commands.h"
35 #include "protocolinterface.h"
36
37 /** An enumeration of all known protocol versions.
38  *
39  * If you introduce new protocol versions please document them here:
40  * https://docs.inspircd.org/spanningtree/changes
41  */
42 enum ProtocolVersion
43 {
44         /** The linking protocol version introduced in InspIRCd v2.0. */
45         PROTO_INSPIRCD_20 = 1202,
46
47         /** The linking protocol version introduced in InspIRCd v2.1 alpha 0. */
48         PROTO_INSPIRCD_21_A0 = 1203,
49
50         /** The linking protocol version introduced in InspIRCd v2.1 beta 2. */
51         PROTO_INSPIRCD_21_B2 = 1204,
52
53         /** The linking protocol version introduced in InspIRCd v3.0. */
54         PROTO_INSPIRCD_30 = 1205,
55
56         /** The oldest version of the protocol that we support. */
57         PROTO_OLDEST = PROTO_INSPIRCD_20,
58
59         /** The newest version of the protocol that we support. */
60         PROTO_NEWEST = PROTO_INSPIRCD_30
61 };
62
63 /** Forward declarations
64  */
65 class SpanningTreeUtilities;
66 class CacheRefreshTimer;
67 class TreeServer;
68 class Link;
69 class Autoconnect;
70
71 /** This is the main class for the spanningtree module
72  */
73 class ModuleSpanningTree
74         : public Module
75         , public Away::EventListener
76         , public Stats::EventListener
77         , public CTCTags::EventListener
78 {
79         /** Client to server commands, registered in the core
80          */
81         CommandRConnect rconnect;
82         CommandRSQuit rsquit;
83         CommandMap map;
84
85         /** Server to server only commands, not registered in the core
86          */
87         SpanningTreeCommands commands;
88
89         /** Next membership id assigned when a local user joins a channel
90          */
91         Membership::Id currmembid;
92
93         /** The specialized ProtocolInterface that is assigned to ServerInstance->PI on load
94          */
95         SpanningTreeProtocolInterface protocolinterface;
96
97         /** Event provider for our broadcast events. */
98         Events::ModuleEventProvider broadcasteventprov;
99
100         /** Event provider for our link events. */
101         Events::ModuleEventProvider linkeventprov;
102
103         /** Event provider for our message events. */
104         Events::ModuleEventProvider messageeventprov;
105
106         /** Event provider for our sync events. */
107         Events::ModuleEventProvider synceventprov;
108
109         /** API for accessing user SSL certificates. */
110         UserCertificateAPI sslapi;
111
112  public:
113         dynamic_reference<DNS::Manager> DNS;
114
115         /** Event provider for message tags. */
116         Events::ModuleEventProvider tagevprov;
117
118         ServerCommandManager CmdManager;
119
120         /** Set to true if inside a spanningtree call, to prevent sending
121          * xlines and other things back to their source
122          */
123         bool loopCall;
124
125         /** Constructor
126          */
127         ModuleSpanningTree();
128         void init() CXX11_OVERRIDE;
129
130         /** Shows /LINKS
131          */
132         void ShowLinks(TreeServer* Current, User* user, int hops);
133
134         /** Handle LINKS command
135          */
136         void HandleLinks(const CommandBase::Params& parameters, User* user);
137
138         /** Handle SQUIT
139          */
140         ModResult HandleSquit(const CommandBase::Params& parameters, User* user);
141
142         /** Handle remote WHOIS
143          */
144         ModResult HandleRemoteWhois(const CommandBase::Params& parameters, User* user);
145
146         /** Connect a server locally
147          */
148         void ConnectServer(Link* x, Autoconnect* y = NULL);
149
150         /** Connect the next autoconnect server
151          */
152         void ConnectServer(Autoconnect* y, bool on_timer);
153
154         /** Check if any servers are due to be autoconnected
155          */
156         void AutoConnectServers(time_t curtime);
157
158         /** Check if any connecting servers should timeout
159          */
160         void DoConnectTimeout(time_t curtime);
161
162         /** Handle remote VERSON
163          */
164         ModResult HandleVersion(const CommandBase::Params& parameters, User* user);
165
166         /** Handle CONNECT
167          */
168         ModResult HandleConnect(const CommandBase::Params& parameters, User* user);
169
170         /** Retrieves the event provider for broadcast events. */
171         const Events::ModuleEventProvider& GetBroadcastEventProvider() const { return broadcasteventprov; }
172
173         /** Retrieves the event provider for link events. */
174         const Events::ModuleEventProvider& GetLinkEventProvider() const { return linkeventprov; }
175
176         /** Retrieves the event provider for message events. */
177         const Events::ModuleEventProvider& GetMessageEventProvider() const { return messageeventprov; }
178
179         /** Retrieves the event provider for sync events. */
180         const Events::ModuleEventProvider& GetSyncEventProvider() const { return synceventprov; }
181
182         /**
183          ** *** MODULE EVENTS ***
184          **/
185
186         ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE;
187         void OnPostCommand(Command*, const CommandBase::Params& parameters, LocalUser* user, CmdResult result, bool loop) CXX11_OVERRIDE;
188         void OnUserConnect(LocalUser* source) CXX11_OVERRIDE;
189         void OnUserInvite(User* source, User* dest, Channel* channel, time_t timeout, unsigned int notifyrank, CUList& notifyexcepts) CXX11_OVERRIDE;
190         ModResult OnPreTopicChange(User* user, Channel* chan, const std::string& topic) CXX11_OVERRIDE;
191         void OnPostTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE;
192         void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE;
193         void OnUserPostTagMessage(User* user, const MessageTarget& target, const CTCTags::TagMessageDetails& details) CXX11_OVERRIDE;
194         void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE;
195         void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE;
196         void OnChangeHost(User* user, const std::string &newhost) CXX11_OVERRIDE;
197         void OnChangeRealName(User* user, const std::string& real) CXX11_OVERRIDE;
198         void OnChangeIdent(User* user, const std::string &ident) CXX11_OVERRIDE;
199         void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE;
200         void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) CXX11_OVERRIDE;
201         void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE;
202         void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE;
203         void OnPreRehash(User* user, const std::string &parameter) CXX11_OVERRIDE;
204         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE;
205         void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE;
206         void OnAddLine(User *u, XLine *x) CXX11_OVERRIDE;
207         void OnDelLine(User *u, XLine *x) CXX11_OVERRIDE;
208         ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE;
209         void OnUserAway(User* user) CXX11_OVERRIDE;
210         void OnUserBack(User* user) CXX11_OVERRIDE;
211         void OnLoadModule(Module* mod) CXX11_OVERRIDE;
212         void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
213         ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE;
214         void OnMode(User* source, User* u, Channel* c, const Modes::ChangeList& modes, ModeParser::ModeProcessFlag processflags) CXX11_OVERRIDE;
215         CullResult cull() CXX11_OVERRIDE;
216         ~ModuleSpanningTree();
217         Version GetVersion() CXX11_OVERRIDE;
218         void Prioritize() CXX11_OVERRIDE;
219 };