X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Fmain.cpp;h=029f5e88867eca24aa0715bc715924bf1affb9c6;hb=1638ee61936bc91758be39c3463c6e46d0d655e7;hp=9aee4a4ced621041396eaf47f9b155f58a4adcff;hpb=645f7e18c64a6628ede880dc69bf8825ba93b375;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 9aee4a4ce..029f5e888 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -47,8 +47,8 @@ ModuleSpanningTree::ModuleSpanningTree() 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) + uid(module), opertype(module), fjoin(module), ijoin(module), resync(module), + fmode(module), ftopic(module), fhost(module), fident(module), fname(module) { } @@ -63,12 +63,14 @@ void ModuleSpanningTree::init() ServerInstance->Modules->AddService(commands->uid); ServerInstance->Modules->AddService(commands->opertype); ServerInstance->Modules->AddService(commands->fjoin); + ServerInstance->Modules->AddService(commands->ijoin); + ServerInstance->Modules->AddService(commands->resync); 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); + RefreshTimer = new CacheRefreshTimer(this, Utils); ServerInstance->Timers->AddTimer(RefreshTimer); Implementation eventlist[] = @@ -87,7 +89,7 @@ void ModuleSpanningTree::init() loopCall = false; // update our local user count - Utils->TreeRoot->SetUserCount(ServerInstance->Users->local_users.size()); + Utils->TreeRoot->UserCount = ServerInstance->Users->local_users.size(); } void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops) @@ -194,8 +196,7 @@ restart: // ... if we can find a proper route to them if (tsock) { - tsock->WriteLine(":" + ServerInstance->Config->GetSID() + " PING " + - ServerInstance->Config->GetSID() + " " + s->GetID()); + tsock->WriteLine(":" + ServerInstance->Config->GetSID() + " PING " + s->GetID()); s->LastPingMsec = ts; } } @@ -467,108 +468,45 @@ void ModuleSpanningTree::OnWallops(User* user, const std::string &text) } } -void ModuleSpanningTree::OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) +void ModuleSpanningTree::LocalMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list, const char* message_type) { - /* Server origin */ - if (user == NULL) + /* Server or remote origin, dest should always be non-null */ + if ((!user) || (!IS_LOCAL(user)) || (!dest)) return; if (target_type == TYPE_USER) { - User* d = (User*)dest; - if (!IS_LOCAL(d) && IS_LOCAL(user)) + User* d = (User*) dest; + if (!IS_LOCAL(d)) { parameterlist params; params.push_back(d->uuid); params.push_back(":"+text); - Utils->DoOneToOne(user->uuid,"NOTICE",params,d->server); + Utils->DoOneToOne(user->uuid, message_type, params, d->server); } } else if (target_type == TYPE_CHANNEL) { - if (IS_LOCAL(user)) - { - Channel *c = (Channel*)dest; - if (c) - { - std::string cname = c->name; - if (status) - cname = status + cname; - TreeServerList list; - Utils->GetListOfServersForChannel(c,list,status,exempt_list); - for (TreeServerList::iterator i = list.begin(); i != list.end(); i++) - { - TreeSocket* Sock = i->second->GetSocket(); - if (Sock) - Sock->WriteLine(":"+std::string(user->uuid)+" NOTICE "+cname+" :"+text); - } - } - } + Utils->SendChannelMessage(user->uuid, (Channel*)dest, text, status, exempt_list, message_type); } else if (target_type == TYPE_SERVER) { - if (IS_LOCAL(user)) - { - char* target = (char*)dest; - parameterlist par; - par.push_back(target); - par.push_back(":"+text); - Utils->DoOneToMany(user->uuid,"NOTICE",par); - } + char* target = (char*) dest; + parameterlist par; + par.push_back(target); + par.push_back(":"+text); + Utils->DoOneToMany(user->uuid, message_type, par); } } -void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) +void ModuleSpanningTree::OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) { - /* Server origin */ - if (user == NULL) - return; + LocalMessage(user, dest, target_type, text, status, exempt_list, "NOTICE"); +} - if (target_type == TYPE_USER) - { - // route private messages which are targetted at clients only to the server - // which needs to receive them - User* d = (User*)dest; - if (!IS_LOCAL(d) && (IS_LOCAL(user))) - { - parameterlist params; - params.push_back(d->uuid); - params.push_back(":"+text); - Utils->DoOneToOne(user->uuid,"PRIVMSG",params,d->server); - } - } - else if (target_type == TYPE_CHANNEL) - { - if (IS_LOCAL(user)) - { - Channel *c = (Channel*)dest; - if (c) - { - std::string cname = c->name; - if (status) - cname = status + cname; - TreeServerList list; - Utils->GetListOfServersForChannel(c,list,status,exempt_list); - for (TreeServerList::iterator i = list.begin(); i != list.end(); i++) - { - TreeSocket* Sock = i->second->GetSocket(); - if (Sock) - Sock->WriteLine(":"+std::string(user->uuid)+" PRIVMSG "+cname+" :"+text); - } - } - } - } - else if (target_type == TYPE_SERVER) - { - if (IS_LOCAL(user)) - { - char* target = (char*)dest; - parameterlist par; - par.push_back(target); - par.push_back(":"+text); - Utils->DoOneToMany(user->uuid,"PRIVMSG",par); - } - } +void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list) +{ + LocalMessage(user, dest, target_type, text, status, exempt_list, "PRIVMSG"); } void ModuleSpanningTree::OnBackgroundTimer(time_t curtime) @@ -611,23 +549,32 @@ void ModuleSpanningTree::OnUserConnect(LocalUser* user) ServerInstance->PI->SendMetaData(user, item->name, value); } - Utils->TreeRoot->SetUserCount(1); // increment by 1 + Utils->TreeRoot->UserCount++; } -void ModuleSpanningTree::OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) +void ModuleSpanningTree::OnUserJoin(Membership* memb, bool sync, bool created_by_local, CUList& excepts) { // Only do this for local users if (IS_LOCAL(memb->user)) { parameterlist params; - // set up their permissions and the channel TS with FJOIN. - // All users are FJOINed now, because a module may specify - // new joining permissions for the user. params.push_back(memb->chan->name); - params.push_back(ConvToStr(memb->chan->age)); - params.push_back(std::string("+") + memb->chan->ChanModes(true)); - params.push_back(memb->modes+","+memb->user->uuid); - Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FJOIN",params); + if (created_by_local) + { + params.push_back(ConvToStr(memb->chan->age)); + params.push_back(std::string("+") + memb->chan->ChanModes(true)); + params.push_back(memb->modes+","+memb->user->uuid); + Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FJOIN",params); + } + else + { + if (!memb->modes.empty()) + { + params.push_back(ConvToStr(memb->chan->age)); + params.push_back(memb->modes); + } + Utils->DoOneToMany(memb->user->uuid, "IJOIN", params); + } } } @@ -694,7 +641,7 @@ void ModuleSpanningTree::OnUserQuit(User* user, const std::string &reason, const TreeServer* SourceServer = Utils->FindServer(user->server); if (SourceServer) { - SourceServer->SetUserCount(-1); // decrement by 1 + SourceServer->UserCount--; } } @@ -951,7 +898,7 @@ void ModuleSpanningTree::ProtoSendMetaData(void* opaque, Extensible* target, con if (u) s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata); else if (c) - s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+extname+" :"+extdata); + s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+ConvToStr(c->age)+" "+extname+" :"+extdata); else if (!target) s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA * "+extname+" :"+extdata); } @@ -960,6 +907,7 @@ CullResult ModuleSpanningTree::cull() { Utils->cull(); ServerInstance->Timers->DelTimer(RefreshTimer); + delete RefreshTimer; return this->Module::cull(); }