]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/main.cpp
Add a shun option to only apply when users are fully connected.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / main.cpp
index 484d72e6d0a364c54a97fb6ff584186af4f2ea5a..01387c753c85ca7b68e476ac9bc771574ce7ef28 100644 (file)
@@ -1,11 +1,16 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
+ *   Copyright (C) 2020 Matt Schatz <genius3000@g3k.solutions>
+ *   Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
+ *   Copyright (C) 2013, 2017-2020 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2013, 2016 Adam <Adam@anope.org>
+ *   Copyright (C) 2012-2016, 2018 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2007-2009 Craig Edwards <craigedwards@brainbox.cc>
- *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
- *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2007-2009 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007-2009 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2005, 2007-2010 Craig Edwards <brain@inspircd.org>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
@@ -49,8 +54,9 @@ ModuleSpanningTree::ModuleSpanningTree()
        , messageeventprov(this, "event/server-message")
        , synceventprov(this, "event/server-sync")
        , sslapi(this)
+       , servicetag(this)
        , DNS(this, "DNS")
-       , tagevprov(this, "event/messagetag")
+       , tagevprov(this)
        , loopCall(false)
 {
 }
@@ -130,7 +136,7 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
                        ShowLinks(server, user, hops+1);
                }
        }
-       /* Don't display the line if its a uline, hide ulines is on, and the user isnt an oper */
+       /* Don't display the line if its a uline, hide ulines is on, and the user isn't an oper */
        if ((Utils->HideULines) && (Current->IsULine()) && (!user->IsOper()))
                return;
        /* Or if the server is hidden and they're not an oper */
@@ -138,7 +144,7 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
                return;
 
        user->WriteNumeric(RPL_LINKS, Current->GetName(),
-                       (((Utils->FlatLinks) && (!user->IsOper())) ? ServerInstance->Config->ServerName : Parent),
+                       (((Utils->FlatLinks) && (!user->IsOper())) ? ServerInstance->Config->GetServerName() : Parent),
                        InspIRCd::Format("%d %s", (((Utils->FlatLinks) && (!user->IsOper())) ? 0 : hops), Current->GetDesc().c_str()));
 }
 
@@ -210,17 +216,13 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
                // If this fails then the IP sa will be AF_UNSPEC.
                irc::sockets::aptosa(x->IPAddr, x->Port, sa);
        }
-       
+
        /* Do we already have an IP? If so, no need to resolve it. */
        if (sa.family() != AF_UNSPEC)
        {
                // Create a TreeServer object that will start connecting immediately in the background
                TreeSocket* newsocket = new TreeSocket(x, y, sa);
-               if (newsocket->GetFd() > -1)
-               {
-                       /* Handled automatically on success */
-               }
-               else
+               if (!newsocket->HasFd())
                {
                        ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",
                                x->Name.c_str(), newsocket->getError().c_str());
@@ -419,7 +421,7 @@ void ModuleSpanningTree::OnUserPostMessage(User* user, const MessageTarget& targ
                        const std::string* serverglob = target.Get<std::string>();
                        CmdBuilder par(user, message_type);
                        par.push_tags(details.tags_out);
-                       par.push(*serverglob);
+                       par.push(std::string("$") + *serverglob);
                        par.push_last(details.text);
                        par.Broadcast();
                        break;
@@ -456,7 +458,7 @@ void ModuleSpanningTree::OnUserPostTagMessage(User* user, const MessageTarget& t
                        const std::string* serverglob = target.Get<std::string>();
                        CmdBuilder par(user, "TAGMSG");
                        par.push_tags(details.tags_out);
-                       par.push(*serverglob);
+                       par.push(std::string("$") + *serverglob);
                        par.Broadcast();
                        break;
                }
@@ -486,7 +488,7 @@ void ModuleSpanningTree::OnUserConnect(LocalUser* user)
        for(Extensible::ExtensibleStore::const_iterator i = user->GetExtList().begin(); i != user->GetExtList().end(); i++)
        {
                ExtensionItem* item = i->first;
-               std::string value = item->serialize(FORMAT_NETWORK, user, i->second);
+               std::string value = item->ToNetwork(user, i->second);
                if (!value.empty())
                        ServerInstance->PI->SendMetaData(user, item->name, value);
        }
@@ -689,7 +691,7 @@ void ModuleSpanningTree::OnUnloadModule(Module* mod)
                {
                        TreeServer* server = i->second;
                        if (!server->IsRoot())
-                               FOREACH_MOD_CUSTOM(GetLinkEventProvider(), ServerProtocol::LinkEventListener, OnServerSplit, (server));
+                               FOREACH_MOD_CUSTOM(GetLinkEventProvider(), ServerProtocol::LinkEventListener, OnServerSplit, (server, false));
                }
                return;
        }
@@ -793,6 +795,13 @@ void ModuleSpanningTree::OnMode(User* source, User* u, Channel* c, const Modes::
        }
 }
 
+void ModuleSpanningTree::OnShutdown(const std::string& reason)
+{
+       const TreeServer::ChildServers& children = Utils->TreeRoot->GetChildren();
+       while (!children.empty())
+               children.front()->SQuit(reason, true);
+}
+
 CullResult ModuleSpanningTree::cull()
 {
        if (Utils)
@@ -804,7 +813,7 @@ ModuleSpanningTree::~ModuleSpanningTree()
 {
        ServerInstance->PI = &ServerInstance->DefaultProtocolInterface;
 
-       Server* newsrv = new Server(ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc);
+       Server* newsrv = new Server(ServerInstance->Config->GetSID(), ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc);
        SetLocalUsersServer(newsrv);
 
        delete Utils;
@@ -812,7 +821,7 @@ ModuleSpanningTree::~ModuleSpanningTree()
 
 Version ModuleSpanningTree::GetVersion()
 {
-       return Version("Allows servers to be linked", VF_VENDOR);
+       return Version("Allows linking multiple servers together as part of one network.", VF_VENDOR);
 }
 
 /* It is IMPORTANT that m_spanningtree is the last module in the chain