2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2013-2016, 2018 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2013, 2017-2020 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2013 Adam <Adam@anope.org>
8 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
9 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
10 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
11 * Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
12 * Copyright (C) 2007, 2009-2010 Craig Edwards <brain@inspircd.org>
13 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
15 * This file is part of InspIRCd. InspIRCd is free software: you can
16 * redistribute it and/or modify it under the terms of the GNU General Public
17 * License as published by the Free Software Foundation, version 2.
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 #include "modules/dns.h"
34 #include "modules/ssl.h"
35 #include "modules/stats.h"
36 #include "modules/ctctags.h"
37 #include "modules/server.h"
38 #include "servercommand.h"
40 #include "protocolinterface.h"
43 /** An enumeration of all known protocol versions.
45 * If you introduce new protocol versions please document them here:
46 * https://docs.inspircd.org/spanningtree/changes
50 /** The linking protocol version introduced in InspIRCd v2.0. */
51 PROTO_INSPIRCD_20 = 1202,
53 /** The linking protocol version introduced in InspIRCd v2.1 alpha 0. */
54 PROTO_INSPIRCD_21_A0 = 1203,
56 /** The linking protocol version introduced in InspIRCd v2.1 beta 2. */
57 PROTO_INSPIRCD_21_B2 = 1204,
59 /** The linking protocol version introduced in InspIRCd v3.0. */
60 PROTO_INSPIRCD_30 = 1205,
62 /** The oldest version of the protocol that we support. */
63 PROTO_OLDEST = PROTO_INSPIRCD_20,
65 /** The newest version of the protocol that we support. */
66 PROTO_NEWEST = PROTO_INSPIRCD_30
69 /** Forward declarations
71 class SpanningTreeUtilities;
72 class CacheRefreshTimer;
77 /** This is the main class for the spanningtree module
79 class ModuleSpanningTree
81 , public Away::EventListener
82 , public Stats::EventListener
83 , public CTCTags::EventListener
85 /** Client to server commands, registered in the core
87 CommandRConnect rconnect;
91 /** Server to server only commands, not registered in the core
93 SpanningTreeCommands commands;
95 /** Next membership id assigned when a local user joins a channel
97 Membership::Id currmembid;
99 /** The specialized ProtocolInterface that is assigned to ServerInstance->PI on load
101 SpanningTreeProtocolInterface protocolinterface;
103 /** Event provider for our broadcast events. */
104 Events::ModuleEventProvider broadcasteventprov;
106 /** Event provider for our link events. */
107 Events::ModuleEventProvider linkeventprov;
109 /** Event provider for our message events. */
110 Events::ModuleEventProvider messageeventprov;
112 /** Event provider for our sync events. */
113 Events::ModuleEventProvider synceventprov;
115 /** API for accessing user SSL certificates. */
116 UserCertificateAPI sslapi;
118 /** Tag for marking services pseudoclients. */
119 ServiceTag servicetag;
122 dynamic_reference<DNS::Manager> DNS;
124 /** Event provider for message tags. */
125 ClientProtocol::MessageTagEvent tagevprov;
127 ServerCommandManager CmdManager;
129 /** Set to true if inside a spanningtree call, to prevent sending
130 * xlines and other things back to their source
136 ModuleSpanningTree();
137 void init() CXX11_OVERRIDE;
141 void ShowLinks(TreeServer* Current, User* user, int hops);
143 /** Handle LINKS command
145 void HandleLinks(const CommandBase::Params& parameters, User* user);
149 ModResult HandleSquit(const CommandBase::Params& parameters, User* user);
151 /** Handle remote WHOIS
153 ModResult HandleRemoteWhois(const CommandBase::Params& parameters, User* user);
155 /** Connect a server locally
157 void ConnectServer(Link* x, Autoconnect* y = NULL);
159 /** Connect the next autoconnect server
161 void ConnectServer(Autoconnect* y, bool on_timer);
163 /** Check if any servers are due to be autoconnected
165 void AutoConnectServers(time_t curtime);
167 /** Check if any connecting servers should timeout
169 void DoConnectTimeout(time_t curtime);
171 /** Handle remote VERSION
173 ModResult HandleVersion(const CommandBase::Params& parameters, User* user);
177 ModResult HandleConnect(const CommandBase::Params& parameters, User* user);
179 /** Retrieves the event provider for broadcast events. */
180 const Events::ModuleEventProvider& GetBroadcastEventProvider() const { return broadcasteventprov; }
182 /** Retrieves the event provider for link events. */
183 const Events::ModuleEventProvider& GetLinkEventProvider() const { return linkeventprov; }
185 /** Retrieves the event provider for message events. */
186 const Events::ModuleEventProvider& GetMessageEventProvider() const { return messageeventprov; }
188 /** Retrieves the event provider for sync events. */
189 const Events::ModuleEventProvider& GetSyncEventProvider() const { return synceventprov; }
192 ** *** MODULE EVENTS ***
195 ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE;
196 void OnPostCommand(Command*, const CommandBase::Params& parameters, LocalUser* user, CmdResult result, bool loop) CXX11_OVERRIDE;
197 void OnUserConnect(LocalUser* source) CXX11_OVERRIDE;
198 void OnUserInvite(User* source, User* dest, Channel* channel, time_t timeout, unsigned int notifyrank, CUList& notifyexcepts) CXX11_OVERRIDE;
199 ModResult OnPreTopicChange(User* user, Channel* chan, const std::string& topic) CXX11_OVERRIDE;
200 void OnPostTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE;
201 void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE;
202 void OnUserPostTagMessage(User* user, const MessageTarget& target, const CTCTags::TagMessageDetails& details) CXX11_OVERRIDE;
203 void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE;
204 void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE;
205 void OnChangeHost(User* user, const std::string &newhost) CXX11_OVERRIDE;
206 void OnChangeRealName(User* user, const std::string& real) CXX11_OVERRIDE;
207 void OnChangeIdent(User* user, const std::string &ident) CXX11_OVERRIDE;
208 void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts) CXX11_OVERRIDE;
209 void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message) CXX11_OVERRIDE;
210 void OnUserPostNick(User* user, const std::string &oldnick) CXX11_OVERRIDE;
211 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE;
212 void OnPreRehash(User* user, const std::string ¶meter) CXX11_OVERRIDE;
213 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE;
214 void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE;
215 void OnAddLine(User *u, XLine *x) CXX11_OVERRIDE;
216 void OnDelLine(User *u, XLine *x) CXX11_OVERRIDE;
217 ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE;
218 void OnUserAway(User* user) CXX11_OVERRIDE;
219 void OnUserBack(User* user) CXX11_OVERRIDE;
220 void OnLoadModule(Module* mod) CXX11_OVERRIDE;
221 void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
222 ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE;
223 void OnMode(User* source, User* u, Channel* c, const Modes::ChangeList& modes, ModeParser::ModeProcessFlag processflags) CXX11_OVERRIDE;
224 void OnShutdown(const std::string& reason) CXX11_OVERRIDE;
225 CullResult cull() CXX11_OVERRIDE;
226 ~ModuleSpanningTree();
227 Version GetVersion() CXX11_OVERRIDE;
228 void Prioritize() CXX11_OVERRIDE;