]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/main.h
1aeffbc728bd834729125792f80641c59c45a5d5
[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 "servercommand.h"
33 #include "commands.h"
34 #include "protocolinterface.h"
35
36 /** An enumeration of all known protocol versions.
37  *
38  * If you introduce new protocol versions please document them here:
39  * https://docs.inspircd.org/spanningtree/changes
40  */
41 enum ProtocolVersion
42 {
43         /** The linking protocol version introduced in InspIRCd v2.0. */
44         PROTO_INSPIRCD_20 = 1202,
45
46         /** The linking protocol version introduced in InspIRCd v2.1 alpha 0. */
47         PROTO_INSPIRCD_21_A0 = 1203,
48
49         /** The linking protocol version introduced in InspIRCd v2.1 beta 2. */
50         PROTO_INSPIRCD_21_B2 = 1204,
51
52         /** The linking protocol version introduced in InspIRCd v3.0. */
53         PROTO_INSPIRCD_30 = 1205,
54
55         /** The oldest version of the protocol that we support. */
56         PROTO_OLDEST = PROTO_INSPIRCD_20,
57
58         /** The newest version of the protocol that we support. */
59         PROTO_NEWEST = PROTO_INSPIRCD_30
60 };
61
62 /** Forward declarations
63  */
64 class SpanningTreeUtilities;
65 class CacheRefreshTimer;
66 class TreeServer;
67 class Link;
68 class Autoconnect;
69
70 /** This is the main class for the spanningtree module
71  */
72 class ModuleSpanningTree
73         : public Module
74         , public Away::EventListener
75         , public Stats::EventListener
76         , public CTCTags::EventListener
77 {
78         /** Client to server commands, registered in the core
79          */
80         CommandRConnect rconnect;
81         CommandRSQuit rsquit;
82         CommandMap map;
83
84         /** Server to server only commands, not registered in the core
85          */
86         SpanningTreeCommands commands;
87
88         /** Next membership id assigned when a local user joins a channel
89          */
90         Membership::Id currmembid;
91
92         /** The specialized ProtocolInterface that is assigned to ServerInstance->PI on load
93          */
94         SpanningTreeProtocolInterface protocolinterface;
95
96         /** Event provider for our broadcast events. */
97         Events::ModuleEventProvider broadcasteventprov;
98
99         /** Event provider for our link events. */
100         Events::ModuleEventProvider linkeventprov;
101
102         /** Event provider for our sync events. */
103         Events::ModuleEventProvider synceventprov;
104
105         /** API for accessing user SSL certificates. */
106         UserCertificateAPI sslapi;
107
108  public:
109         dynamic_reference<DNS::Manager> DNS;
110
111         /** Event provider for message tags. */
112         Events::ModuleEventProvider tagevprov;
113
114         ServerCommandManager CmdManager;
115
116         /** Set to true if inside a spanningtree call, to prevent sending
117          * xlines and other things back to their source
118          */
119         bool loopCall;
120
121         /** Constructor
122          */
123         ModuleSpanningTree();
124         void init() CXX11_OVERRIDE;
125
126         /** Shows /LINKS
127          */
128         void ShowLinks(TreeServer* Current, User* user, int hops);
129
130         /** Handle LINKS command
131          */
132         void HandleLinks(const CommandBase::Params& parameters, User* user);
133
134         /** Handle SQUIT
135          */
136         ModResult HandleSquit(const CommandBase::Params& parameters, User* user);
137
138         /** Handle remote WHOIS
139          */
140         ModResult HandleRemoteWhois(const CommandBase::Params& parameters, User* user);
141
142         /** Connect a server locally
143          */
144         void ConnectServer(Link* x, Autoconnect* y = NULL);
145
146         /** Connect the next autoconnect server
147          */
148         void ConnectServer(Autoconnect* y, bool on_timer);
149
150         /** Check if any servers are due to be autoconnected
151          */
152         void AutoConnectServers(time_t curtime);
153
154         /** Check if any connecting servers should timeout
155          */
156         void DoConnectTimeout(time_t curtime);
157
158         /** Handle remote VERSON
159          */
160         ModResult HandleVersion(const CommandBase::Params& parameters, User* user);
161
162         /** Handle CONNECT
163          */
164         ModResult HandleConnect(const CommandBase::Params& parameters, User* user);
165
166         /** Retrieves the event provider for broadcast events. */
167         const Events::ModuleEventProvider& GetBroadcastEventProvider() const { return broadcasteventprov; }
168
169         /** Retrieves the event provider for link events. */
170         const Events::ModuleEventProvider& GetLinkEventProvider() const { return linkeventprov; }
171
172         /** Retrieves the event provider for sync events. */
173         const Events::ModuleEventProvider& GetSyncEventProvider() const { return synceventprov; }
174
175         /**
176          ** *** MODULE EVENTS ***
177          **/
178
179         ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE;
180         void OnPostCommand(Command*, const CommandBase::Params& parameters, LocalUser* user, CmdResult result, bool loop) CXX11_OVERRIDE;
181         void OnUserConnect(LocalUser* source) CXX11_OVERRIDE;
182         void OnUserInvite(User* source, User* dest, Channel* channel, time_t timeout, unsigned int notifyrank, CUList& notifyexcepts) CXX11_OVERRIDE;
183         ModResult OnPreTopicChange(User* user, Channel* chan, const std::string& topic) CXX11_OVERRIDE;
184         void OnPostTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE;
185         void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE;
186         void OnUserPostTagMessage(User* user, const MessageTarget& target, const CTCTags::TagMessageDetails& details) CXX11_OVERRIDE;
187         void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE;
188         void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE;
189         void OnChangeHost(User* user, const std::string &newhost) CXX11_OVERRIDE;
190         void OnChangeRealName(User* user, const std::string& real) CXX11_OVERRIDE;
191         void OnChangeIdent(User* user, const std::string &ident) CXX11_OVERRIDE;
192         void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE;
193         void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) CXX11_OVERRIDE;
194         void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE;
195         void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE;
196         void OnPreRehash(User* user, const std::string &parameter) CXX11_OVERRIDE;
197         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE;
198         void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE;
199         void OnAddLine(User *u, XLine *x) CXX11_OVERRIDE;
200         void OnDelLine(User *u, XLine *x) CXX11_OVERRIDE;
201         ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE;
202         void OnUserAway(User* user) CXX11_OVERRIDE;
203         void OnUserBack(User* user) CXX11_OVERRIDE;
204         void OnLoadModule(Module* mod) CXX11_OVERRIDE;
205         void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
206         ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE;
207         void OnMode(User* source, User* u, Channel* c, const Modes::ChangeList& modes, ModeParser::ModeProcessFlag processflags) CXX11_OVERRIDE;
208         CullResult cull() CXX11_OVERRIDE;
209         ~ModuleSpanningTree();
210         Version GetVersion() CXX11_OVERRIDE;
211         void Prioritize() CXX11_OVERRIDE;
212 };