]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree.cpp
Clean up ghosts on nick collision
[user/henk/code/inspircd.git] / src / modules / m_spanningtree.cpp
index bc1cc8770b0d9f61416ee8f6ed04d9f7a4dadafc..ca25fe4a689938d2b09bed10e10cfcbf55f66043 100644 (file)
@@ -635,12 +635,12 @@ class TreeSocket : public InspSocket
        {
                if (this->LinkState == CONNECTING)
                {
-                       Srv->SendOpers("*** Connection to "+myhost+"["+this->GetIP()+"] established.");
                        /* we do not need to change state here. */
                        for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
                        {
                                if (x->Name == this->myhost)
                                {
+                                       Srv->SendOpers("*** Connection to \2"+myhost+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] established.");
                                        this->SendCapabilities();
                                        if (x->EncryptionKey != "")
                                        {
@@ -665,6 +665,7 @@ class TreeSocket : public InspSocket
                 * If that happens the connection hangs here until it's closed. Unlikely
                 * and rather harmless.
                 */
+               Srv->SendOpers("*** Connection to \2"+myhost+"\2 lost link tag(!)");
                return true;
        }
        
@@ -1068,7 +1069,7 @@ class TreeSocket : public InspSocket
                clientlist[tempnick]->registered = 7;
                clientlist[tempnick]->signon = age;
                strlcpy(clientlist[tempnick]->modes, modes.c_str(),53);
-               strlcpy(clientlist[tempnick]->ip,ip.c_str(),16);
+               inet_aton(ip.c_str(),&clientlist[tempnick]->ip4);
 
                ucrec a;
                a.channel = NULL;
@@ -1078,7 +1079,7 @@ class TreeSocket : public InspSocket
 
                if (!this->bursting)
                {
-                       WriteOpers("*** Client connecting at %s: %s!%s@%s [%s]",clientlist[tempnick]->server,clientlist[tempnick]->nick,clientlist[tempnick]->ident,clientlist[tempnick]->host,clientlist[tempnick]->ip);
+                       WriteOpers("*** Client connecting at %s: %s!%s@%s [%s]",clientlist[tempnick]->server,clientlist[tempnick]->nick,clientlist[tempnick]->ident,clientlist[tempnick]->host,(char*)inet_ntoa(clientlist[tempnick]->ip4));
                }
                params[7] = ":" + params[7];
                DoOneToAllButSender(source,"NICK",params,source);
@@ -1178,7 +1179,7 @@ class TreeSocket : public InspSocket
                for (chan_hash::iterator c = chanlist.begin(); c != chanlist.end(); c++)
                {
                        SendFJoins(Current, c->second);
-                       snprintf(data,MAXBUF,":%s FMODE %s +%s",Srv->GetServerName().c_str(),c->second->name,chanmodes(c->second));
+                       snprintf(data,MAXBUF,":%s FMODE %s +%s",Srv->GetServerName().c_str(),c->second->name,chanmodes(c->second,true));
                        this->WriteLine(data);
                        if (*c->second->topic)
                        {
@@ -1209,7 +1210,7 @@ class TreeSocket : public InspSocket
                {
                        if (u->second->registered == 7)
                        {
-                               snprintf(data,MAXBUF,":%s NICK %lu %s %s %s %s +%s %s :%s",u->second->server,(unsigned long)u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->ip,u->second->fullname);
+                               snprintf(data,MAXBUF,":%s NICK %lu %s %s %s %s +%s %s :%s",u->second->server,(unsigned long)u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,(char*)inet_ntoa(u->second->ip4),u->second->fullname);
                                this->WriteLine(data);
                                if (strchr(u->second->modes,'o'))
                                {
@@ -1244,6 +1245,7 @@ class TreeSocket : public InspSocket
                /* Send everything else (channel modes, xlines etc) */
                this->SendChannelModes(s);
                this->SendXLines(s);
+               FOREACH_MOD(I_OnSyncOtherMetaData,OnSyncOtherMetaData((Module*)TreeProtocolModule,(void*)this));
                this->WriteLine("ENDBURST");
                Srv->SendOpers("*** Finished bursting to \2"+s->GetName()+"\2.");
        }
@@ -1472,7 +1474,11 @@ class TreeSocket : public InspSocket
                TreeServer* ServerSource = FindServer(prefix);
                if (ServerSource)
                {
-                       if (*(params[0].c_str()) == '#')
+                       if (params[0] == "*")
+                       {
+                               FOREACH_MOD(I_OnDecodeMetaData,OnDecodeMetaData(TYPE_OTHER,NULL,params[1],params[2]));
+                       }
+                       else if (*(params[0].c_str()) == '#')
                        {
                                chanrec* c = Srv->FindChannel(params[0]);
                                if (c)
@@ -1480,7 +1486,7 @@ class TreeSocket : public InspSocket
                                        FOREACH_MOD(I_OnDecodeMetaData,OnDecodeMetaData(TYPE_CHANNEL,c,params[1],params[2]));
                                }
                        }
-                       else
+                       else if (*(params[0].c_str()) != '#')
                        {
                                userrec* u = Srv->FindNick(params[0]);
                                if (u)
@@ -2120,6 +2126,32 @@ class TreeSocket : public InspSocket
                                        }
                                        if (who)
                                        {
+                                               if ((command == "NICK") && (params.size() > 0))
+                                               {
+                                                       /* On nick messages, check that the nick doesnt
+                                                        * already exist here. If it does, kill their copy,
+                                                        * and our copy.
+                                                        */
+                                                       userrec* x = Srv->FindNick(params[0]);
+                                                       if (x)
+                                                       {
+                                                               std::deque<std::string> p;
+                                                               p.push_back(params[0]);
+                                                               p.push_back("Nickname collision ("+prefix+" -> "+params[0]+")");
+                                                               DoOneToMany(Srv->GetServerName(),"KILL",p);
+                                                               p.clear();
+                                                               p.push_back(prefix);
+                                                               p.push_back("KILL "+prefix+" :Nickname collision");
+                                                               DoOneToMany(Srv->GetServerName(),"KILL",p);
+                                                               Srv->QuitUser(x,"Nickname collision ("+prefix+" -> "+params[0]+")");
+                                                               userrec* y = Srv->FindNick(prefix);
+                                                               if (y)
+                                                               {
+                                                                       Srv->QuitUser(y,"Nickname collision");
+                                                               }
+                                                               return DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
+                                                       }
+                                               }
                                                // its a user
                                                target = who->server;
                                                char* strparams[127];
@@ -2184,7 +2216,7 @@ class TreeSocket : public InspSocket
                {
                        Squit(s,"Remote host closed the connection");
                }
-               WriteOpers("Server '\2%s\2[%s]' closed the connection.",quitserver.c_str(),this->GetIP().c_str());
+               WriteOpers("Server '\2%s\2' closed the connection.",quitserver.c_str());
        }
 
        virtual int OnIncomingConnection(int newsock, char* ip)
@@ -3027,7 +3059,7 @@ class ModuleSpanningTree : public Module
                        params.push_back(user->dhost);
                        params.push_back(user->ident);
                        params.push_back("+"+std::string(user->modes));
-                       params.push_back(user->ip);
+                       params.push_back((char*)inet_ntoa(user->ip4));
                        params.push_back(":"+std::string(user->fullname));
                        DoOneToMany(Srv->GetServerName(),"NICK",params);
 
@@ -3233,7 +3265,11 @@ class ModuleSpanningTree : public Module
                                userrec* u = (userrec*)target;
                                s->WriteLine(":"+Srv->GetServerName()+" METADATA "+u->nick+" "+extname+" :"+extdata);
                        }
-                       else
+                       else if (target_type == TYPE_OTHER)
+                       {
+                               s->WriteLine(":"+Srv->GetServerName()+" METADATA * "+extname+" :"+extdata);
+                       }
+                       else if (target_type == TYPE_CHANNEL)
                        {
                                chanrec* c = (chanrec*)target;
                                s->WriteLine(":"+Srv->GetServerName()+" METADATA "+c->name+" "+extname+" :"+extdata);
@@ -3241,6 +3277,18 @@ class ModuleSpanningTree : public Module
                }
        }
 
+       virtual void OnEvent(Event* event)
+       {
+               if (event->GetEventID() == "send_metadata")
+               {
+                       std::deque<std::string>* params = (std::deque<std::string>*)event->GetData();
+                       if (params->size() < 3)
+                               return;
+                       (*params)[2] = ":" + (*params)[2];
+                       DoOneToMany(Srv->GetServerName(),"METADATA",*params);
+               }
+       }
+
        virtual ~ModuleSpanningTree()
        {
        }
@@ -3258,7 +3306,7 @@ class ModuleSpanningTree : public Module
                List[I_OnUserQuit] = List[I_OnUserPostNick] = List[I_OnUserKick] = List[I_OnRemoteKill] = List[I_OnRehash] = 1;
                List[I_OnOper] = List[I_OnAddGLine] = List[I_OnAddZLine] = List[I_OnAddQLine] = List[I_OnAddELine] = 1;
                List[I_OnDelGLine] = List[I_OnDelZLine] = List[I_OnDelQLine] = List[I_OnDelELine] = List[I_ProtoSendMode] = List[I_OnMode] = 1;
-               List[I_OnStats] = List[I_ProtoSendMetaData] = 1;
+               List[I_OnStats] = List[I_ProtoSendMetaData] = List[I_OnEvent] = 1;
        }
 
        /* It is IMPORTANT that m_spanningtree is the last module in the chain