From 6b929c6dbb3d36c3873ab9911ad4d8a46ddbdc99 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Wed, 4 Jul 2012 20:26:24 +0200 Subject: m_spanningtree Use iterators in CAPAB handler and when generating reply to spanningtree related /stats, use std::find() in TreeServer::DelChild() --- src/modules/m_spanningtree/capab.cpp | 8 ++++---- src/modules/m_spanningtree/override_stats.cpp | 7 ++++--- src/modules/m_spanningtree/treeserver.cpp | 10 ++++------ 3 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp index 378695091..40769df3d 100644 --- a/src/modules/m_spanningtree/capab.cpp +++ b/src/modules/m_spanningtree/capab.cpp @@ -37,12 +37,12 @@ std::string TreeSocket::MyModules(int filter) std::string capabilities; sort(modlist.begin(),modlist.end()); - for (unsigned int i = 0; i < modlist.size(); i++) + for (std::vector::const_iterator i = modlist.begin(); i != modlist.end(); ++i) { - if (i) + if (i != modlist.begin()) capabilities.push_back(proto_version > 1201 ? ' ' : ','); - capabilities.append(modlist[i]); - Module* m = ServerInstance->Modules->Find(modlist[i]); + capabilities.append(*i); + Module* m = ServerInstance->Modules->Find(*i); if (m && proto_version > 1201) { Version v = m->GetVersion(); diff --git a/src/modules/m_spanningtree/override_stats.cpp b/src/modules/m_spanningtree/override_stats.cpp index 83691c151..688661b80 100644 --- a/src/modules/m_spanningtree/override_stats.cpp +++ b/src/modules/m_spanningtree/override_stats.cpp @@ -33,11 +33,12 @@ ModResult ModuleSpanningTree::OnStats(char statschar, User* user, string_list &r { if ((statschar == 'c') || (statschar == 'n')) { - for (unsigned int i = 0; i < Utils->LinkBlocks.size(); i++) + for (std::vector >::iterator i = Utils->LinkBlocks.begin(); i != Utils->LinkBlocks.end(); ++i) { - results.push_back(std::string(ServerInstance->Config->ServerName)+" 213 "+user->nick+" "+statschar+" *@"+(Utils->LinkBlocks[i]->HiddenFromStats ? "" : Utils->LinkBlocks[i]->IPAddr)+" * "+Utils->LinkBlocks[i]->Name.c_str()+" "+ConvToStr(Utils->LinkBlocks[i]->Port)+" "+(Utils->LinkBlocks[i]->Hook.empty() ? "plaintext" : Utils->LinkBlocks[i]->Hook)); + Link* L = *i; + results.push_back(std::string(ServerInstance->Config->ServerName)+" 213 "+user->nick+" "+statschar+" *@"+(L->HiddenFromStats ? "" : L->IPAddr)+" * "+(*i)->Name.c_str()+" "+ConvToStr(L->Port)+" "+(L->Hook.empty() ? "plaintext" : L->Hook)); if (statschar == 'c') - results.push_back(std::string(ServerInstance->Config->ServerName)+" 244 "+user->nick+" H * * "+Utils->LinkBlocks[i]->Name.c_str()); + results.push_back(std::string(ServerInstance->Config->ServerName)+" 244 "+user->nick+" H * * "+L->Name.c_str()); } return MOD_RES_DENY; } diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index 65e119149..493b05ebf 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -321,13 +321,11 @@ void TreeServer::AddChild(TreeServer* Child) bool TreeServer::DelChild(TreeServer* Child) { - for (std::vector::iterator a = Children.begin(); a != Children.end(); a++) + std::vector::iterator it = std::find(Children.begin(), Children.end(), Child); + if (it != Children.end()) { - if (*a == Child) - { - Children.erase(a); - return true; - } + Children.erase(it); + return true; } return false; } -- cgit v1.2.3