]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/main.cpp
Send HALFOP= line in CAPAB CAPABILITIES for 1201 compat (anope relies on this)
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / main.cpp
index fc4e319062a727e46966803bf1ffa9f307104382..68367cee0142eb8cb4eebba65a3271c90f9cd240 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
  * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
 ModuleSpanningTree::ModuleSpanningTree()
 {
        Utils = new SpanningTreeUtilities(this);
-       command_rconnect = new CommandRConnect(this, Utils);
-       command_rsquit = new CommandRSQuit(this, Utils);
-       command_svsjoin = new CommandSVSJoin(this);
-       command_svspart = new CommandSVSPart(this);
-       command_svsnick = new CommandSVSNick(this);
+       commands = new SpanningTreeCommands(this);
+       RefreshTimer = NULL;
+}
+
+SpanningTreeCommands::SpanningTreeCommands(ModuleSpanningTree* module)
+       : rconnect(module, module->Utils), rsquit(module, module->Utils),
+       svsjoin(module), svspart(module), svsnick(module), metadata(module),
+       uid(module), opertype(module), fjoin(module), fmode(module), ftopic(module),
+       fhost(module), fident(module), fname(module)
+{
+}
+
+void ModuleSpanningTree::init()
+{
+       ServerInstance->Modules->AddService(commands->rconnect);
+       ServerInstance->Modules->AddService(commands->rsquit);
+       ServerInstance->Modules->AddService(commands->svsjoin);
+       ServerInstance->Modules->AddService(commands->svspart);
+       ServerInstance->Modules->AddService(commands->svsnick);
+       ServerInstance->Modules->AddService(commands->metadata);
+       ServerInstance->Modules->AddService(commands->uid);
+       ServerInstance->Modules->AddService(commands->opertype);
+       ServerInstance->Modules->AddService(commands->fjoin);
+       ServerInstance->Modules->AddService(commands->fmode);
+       ServerInstance->Modules->AddService(commands->ftopic);
+       ServerInstance->Modules->AddService(commands->fhost);
+       ServerInstance->Modules->AddService(commands->fident);
+       ServerInstance->Modules->AddService(commands->fname);
        RefreshTimer = new CacheRefreshTimer(Utils);
-       ServerInstance->AddCommand(command_rconnect);
-       ServerInstance->AddCommand(command_rsquit);
-       ServerInstance->AddCommand(command_svsjoin);
-       ServerInstance->AddCommand(command_svspart);
-       ServerInstance->AddCommand(command_svsnick);
        ServerInstance->Timers->AddTimer(RefreshTimer);
 
        Implementation eventlist[] =
@@ -128,13 +146,18 @@ void ModuleSpanningTree::DoPingChecks(time_t curtime)
         * Cancel remote burst mode on any servers which still have it enabled due to latency/lack of data.
         * This prevents lost REMOTECONNECT notices
         */
-       timeval t;
-       gettimeofday(&t, NULL);
-       long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
+       long ts = ServerInstance->Time() * 1000 + (ServerInstance->Time_ns() / 1000000);
 
+restart:
        for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
        {
                TreeServer *s = i->second;
+               
+               if (s->GetSocket() && s->GetSocket()->GetLinkState() == DYING)
+               {
+                       s->GetSocket()->Close();
+                       goto restart;
+               }
 
                // Fix for bug #792, do not ping servers that are not connected yet!
                // Remote servers have Socket == NULL and local connected servers have
@@ -172,10 +195,8 @@ void ModuleSpanningTree::DoPingChecks(time_t curtime)
                                        if (sock)
                                        {
                                                sock->SendError("Ping timeout");
-                                               sock->Squit(s,"Ping timeout");
-                                               ServerInstance->SE->DelFd(sock);
                                                sock->Close();
-                                               return;
+                                               goto restart;
                                        }
                                }
                        }
@@ -257,8 +278,7 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
        if (ipvalid)
        {
                /* Gave a hook, but it wasnt one we know */
-               TreeSocket* newsocket = new TreeSocket(Utils, x->IPAddr, x->Port, x->Timeout ? x->Timeout : 10,
-                       x->Name.c_str(), x->Bind, y, x->Hook);
+               TreeSocket* newsocket = new TreeSocket(Utils, x, y, x->IPAddr);
                if (newsocket->GetFd() > -1)
                {
                        /* Handled automatically on success */
@@ -308,12 +328,16 @@ void ModuleSpanningTree::DoConnectTimeout(time_t curtime)
                std::pair<std::string, int> p = i->second;
                std::map<TreeSocket*, std::pair<std::string, int> >::iterator me = i;
                i++;
-               if (curtime > s->age + p.second)
+               if (s->GetLinkState() == DYING)
+               {
+                       Utils->timeoutlist.erase(me);
+                       s->Close();
+               }
+               else if (curtime > s->age + p.second)
                {
                        ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002 (timeout of %d seconds)",p.first.c_str(),p.second);
                        Utils->timeoutlist.erase(me);
                        s->Close();
-                       ServerInstance->GlobalCulls.AddItem(s);
                }
        }
 }
@@ -558,6 +582,13 @@ void ModuleSpanningTree::OnUserConnect(LocalUser* user)
        params.push_back(":"+std::string(user->fullname));
        Utils->DoOneToMany(ServerInstance->Config->GetSID(), "UID", params);
 
+       if (IS_OPER(user))
+       {
+               params.clear();
+               params.push_back(user->oper->name);
+               Utils->DoOneToMany(user->uuid,"OPERTYPE",params);
+       }
+
        for(Extensible::ExtensibleStore::const_iterator i = user->GetExtList().begin(); i != user->GetExtList().end(); i++)
        {
                ExtensionItem* item = i->first;
@@ -729,12 +760,33 @@ void ModuleSpanningTree::OnRehash(User* user)
 
 void ModuleSpanningTree::OnLoadModule(Module* mod)
 {
-       // TODO notify other servers?
+       std::string data;
+       data.push_back('+');
+       data.append(mod->ModuleSourceFile);
+       Version v = mod->GetVersion();
+       if (!v.link_data.empty())
+       {
+               data.push_back('=');
+               data.append(v.link_data);
+       }
+       ServerInstance->PI->SendMetaData(NULL, "modules", data);
 }
 
 void ModuleSpanningTree::OnUnloadModule(Module* mod)
 {
-       // TODO notify other servers?
+       ServerInstance->PI->SendMetaData(NULL, "modules", "-" + mod->ModuleSourceFile);
+
+       unsigned int items = Utils->TreeRoot->ChildCount();
+       for(unsigned int x = 0; x < items; x++)
+       {
+               TreeServer* srv = Utils->TreeRoot->GetChild(x);
+               TreeSocket* sock = srv->GetSocket();
+               if (sock && sock->GetIOHook() == mod)
+               {
+                       sock->SendError("SSL module unloaded");
+                       sock->Close();
+               }
+       }
 }
 
 void ModuleSpanningTree::RedoConfig(Module* mod)
@@ -746,12 +798,11 @@ void ModuleSpanningTree::RedoConfig(Module* mod)
 // locally.
 void ModuleSpanningTree::OnOper(User* user, const std::string &opertype)
 {
-       if (IS_LOCAL(user))
-       {
-               parameterlist params;
-               params.push_back(opertype);
-               Utils->DoOneToMany(user->uuid,"OPERTYPE",params);
-       }
+       if (user->registered != REG_ALL || !IS_LOCAL(user))
+               return;
+       parameterlist params;
+       params.push_back(opertype);
+       Utils->DoOneToMany(user->uuid,"OPERTYPE",params);
 }
 
 void ModuleSpanningTree::OnAddLine(User* user, XLine *x)
@@ -900,11 +951,7 @@ ModuleSpanningTree::~ModuleSpanningTree()
        /* This will also free the listeners */
        delete Utils;
 
-       delete command_rconnect;
-       delete command_rsquit;
-       delete command_svsjoin;
-       delete command_svspart;
-       delete command_svsnick;
+       delete commands;
 }
 
 Version ModuleSpanningTree::GetVersion()