-/** Handle /RCONNECT
- */
-class cmd_rconnect : public command_t
-{
- Module* Creator;
- SpanningTreeUtilities* Utils;
- public:
- cmd_rconnect (InspIRCd* Instance, Module* Callback, SpanningTreeUtilities* Util) : command_t(Instance, "RCONNECT", 'o', 2), Creator(Callback), Utils(Util)
- {
- this->source = "m_spanningtree.so";
- syntax = "<remote-server-mask> <target-server-mask>";
- }
-
- CmdResult Handle (const char** parameters, int pcnt, userrec *user)
- {
- if (IS_LOCAL(user))
- {
- if (!Utils->FindServer(parameters[0]))
- {
- user->WriteServ("NOTICE %s :*** RCONNECT: Server \002%s\002 isn't connected to the network!", user->nick, parameters[0]);
- return CMD_FAILURE;
- }
-
- user->WriteServ("NOTICE %s :*** RCONNECT: Sending remote connect to \002%s\002 to connect server \002%s\002.",user->nick,parameters[0],parameters[1]);
- }
-
- /* Is this aimed at our server? */
- if (ServerInstance->MatchText(ServerInstance->Config->ServerName,parameters[0]))
- {
- /* Yes, initiate the given connect */
- ServerInstance->SNO->WriteToSnoMask('l',"Remote CONNECT from %s matching \002%s\002, connecting server \002%s\002",user->nick,parameters[0],parameters[1]);
- const char* para[1];
- para[0] = parameters[1];
- std::string original_command = std::string("CONNECT ") + parameters[1];
- Creator->OnPreCommand("CONNECT", para, 1, user, true, original_command);
- }
-
- return CMD_SUCCESS;
- }
-};
-
-/** This class is used to resolve server hostnames during /connect and autoconnect.
- * As of 1.1, the resolver system is seperated out from InspSocket, so we must do this
- * resolver step first ourselves if we need it. This is totally nonblocking, and will
- * callback to OnLookupComplete or OnError when completed. Once it has completed we
- * will have an IP address which we can then use to continue our connection.
- */
-class ServernameResolver : public Resolver
-{
- private:
- /** A copy of the Link tag info for what we're connecting to.
- * We take a copy, rather than using a pointer, just in case the
- * admin takes the tag away and rehashes while the domain is resolving.
- */
- Link MyLink;
- SpanningTreeUtilities* Utils;
- public:
- ServernameResolver(Module* me, SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &hostname, Link x, bool &cached) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), MyLink(x), Utils(Util)
- {
- /* Nothing in here, folks */
- }
-
- void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
- {
- /* Initiate the connection, now that we have an IP to use.
- * Passing a hostname directly to InspSocket causes it to
- * just bail and set its FD to -1.
- */
- TreeServer* CheckDupe = Utils->FindServer(MyLink.Name.c_str());
- if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
- {
-
- if ((!MyLink.Hook.empty()) && (Utils->hooks.find(MyLink.Hook.c_str()) == Utils->hooks.end()))
- return;
-
- TreeSocket* newsocket = new TreeSocket(this->Utils, ServerInstance, result,MyLink.Port,false,MyLink.Timeout ? MyLink.Timeout : 10,MyLink.Name.c_str(),
- MyLink.Hook.empty() ? NULL : Utils->hooks[MyLink.Hook.c_str()]);
- if (newsocket->GetFd() > -1)
- {
- /* We're all OK */
- }
- else
- {
- /* Something barfed, show the opers */
- ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: %s.",MyLink.Name.c_str(),strerror(errno));
- delete newsocket;
- Utils->DoFailOver(&MyLink);
- }
- }
- }
-
- void OnError(ResolverError e, const std::string &errormessage)
- {
- /* Ooops! */
- ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s",MyLink.Name.c_str(),errormessage.c_str());
- Utils->DoFailOver(&MyLink);
- }
-};
-
-/** Create a timer which recurs every second, we inherit from InspTimer.
- * InspTimer is only one-shot however, so at the end of each Tick() we simply
- * insert another of ourselves into the pending queue :)
- */
-class TimeSyncTimer : public InspTimer
-{
- private:
- InspIRCd *Instance;
- ModuleSpanningTree *Module;
- public:
- TimeSyncTimer(InspIRCd *Instance, ModuleSpanningTree *Mod);
- virtual void Tick(time_t TIME);
-};
-