]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/main.cpp
MetaData rework
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / main.cpp
index 7f2164f622426a6f48eb0f9bd6fae26b4dc9ca40..2ecbd8a88709f261bdec25cab12a75976d56011a 100644 (file)
@@ -52,7 +52,7 @@ ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me)
                I_OnChangeLocalUserHost, I_OnChangeName, I_OnUserPart, I_OnUnloadModule, I_OnUserQuit,
                I_OnUserPostNick, I_OnUserKick, I_OnRemoteKill, I_OnRehash, I_OnPreRehash, I_OnOper,
                I_OnAddLine, I_OnDelLine, I_OnMode, I_OnLoadModule, I_OnStats, I_OnEvent, I_OnSetAway,
-               I_OnPostCommand
+               I_OnPostCommand, I_OnUserConnect
        };
        ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
 
@@ -60,10 +60,8 @@ ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me)
        ServerInstance->PI = new SpanningTreeProtocolInterface(this, Utils, ServerInstance);
        loopCall = false;
 
-       for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
-       {
-               ServerInstance->PI->Introduce(*i);
-       }
+       // update our local user count
+       Utils->TreeRoot->SetUserCount(ServerInstance->Users->local_users.size());
 }
 
 void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
@@ -579,6 +577,27 @@ void ModuleSpanningTree::OnBackgroundTimer(time_t curtime)
        DoConnectTimeout(curtime);
 }
 
+void ModuleSpanningTree::OnUserConnect(User* user)
+{
+       if (user->quitting)
+               return;
+
+       parameterlist params;
+       params.push_back(user->uuid);
+       params.push_back(ConvToStr(user->age));
+       params.push_back(user->nick);
+       params.push_back(user->host);
+       params.push_back(user->dhost);
+       params.push_back(user->ident);
+       params.push_back(user->GetIPString());
+       params.push_back(ConvToStr(user->signon));
+       params.push_back("+"+std::string(user->FormatModes(true)));
+       params.push_back(":"+std::string(user->fullname));
+       Utils->DoOneToMany(ServerInstance->Config->GetSID(), "UID", params);
+
+       Utils->TreeRoot->SetUserCount(1); // increment by 1
+}
+
 void ModuleSpanningTree::OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created)
 {
        // Only do this for local users
@@ -880,26 +899,28 @@ void ModuleSpanningTree::ProtoSendMode(void* opaque, TargetTypeFlags target_type
        }
 }
 
-void ModuleSpanningTree::ProtoSendMetaData(void* opaque, TargetTypeFlags target_type, void* target, const std::string &extname, const std::string &extdata)
+void ModuleSpanningTree::ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata)
 {
-       TreeSocket* s = (TreeSocket*)opaque;
-       if (target)
-       {
-               if (target_type == TYPE_USER)
-               {
-                       User* u = (User*)target;
-                       s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata);
-               }
-               else if (target_type == TYPE_CHANNEL)
-               {
-                       Channel* c = (Channel*)target;
-                       s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+extname+" :"+extdata);
-               }
-       }
-       if (target_type == TYPE_OTHER)
-       {
+       TreeSocket* s = static_cast<TreeSocket*>(opaque);
+       User* u = dynamic_cast<User*>(target);
+       Channel* c = dynamic_cast<Channel*>(target);
+       if (u)
+               s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata);
+       else if (c)
+               s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+extname+" :"+extdata);
+       else if (!target)
                s->WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" METADATA * "+extname+" :"+extdata);
-       }
+}
+
+std::string ModuleSpanningTree::ProtoTranslate(Extensible* item)
+{
+       User* u = dynamic_cast<User*>(item);
+       Channel* c = dynamic_cast<Channel*>(item);
+       if (u)
+               return u->uuid;
+       if (c)
+               return c->name;
+       return "*";
 }
 
 void ModuleSpanningTree::OnEvent(Event* event)