From 07c58b6fb8da655a45d4d4d17dd6d518f60b00dd Mon Sep 17 00:00:00 2001 From: brain Date: Mon, 27 Aug 2007 21:09:46 +0000 Subject: This may need tidying up to make SetID internal and do this in the constructor, but for now it works. AWOOGA AWOOGA WARNING: SetID can throw a CoreException if the id already exists! git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7919 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_spanningtree/treeserver.cpp | 9 +++++++++ src/modules/m_spanningtree/utils.cpp | 9 +++++++++ src/modules/m_spanningtree/utils.h | 6 ++++++ 3 files changed, 24 insertions(+) (limited to 'src/modules/m_spanningtree') diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index d252f2386..5f91e43b5 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -132,6 +132,11 @@ std::string& TreeServer::GetID() void TreeServer::SetID(const std::string &id) { sid = id; + server_hash::iterator iter = Utils->sidlist.find(sid); + if (iter == Utils->sidlist.end()) + Utils->sidlist[sid] = this; + else + throw CoreException("Server ID '"+id+"' already exists!"); } int TreeServer::QuitUsers(const std::string &reason) @@ -330,6 +335,10 @@ TreeServer::~TreeServer() { /* We'd better tidy up after ourselves, eh? */ this->DelHashEntry(); + + server_hash::iterator iter = Utils->sidlist.find(GetID()); + if (iter != Utils->sidlist.end()) + Utils->sidlist.erase(iter); } diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index b8a634797..3f5a910c9 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -149,6 +149,15 @@ TreeServer* SpanningTreeUtilities::FindServerMask(const std::string &ServerName) return NULL; } +TreeServer* SpanningTreeUtilities::FindServerID(const std::string &id) +{ + server_hash::iterator iter = sidlist.find(id); + if (iter != sidlist.end()) + return iter->second; + else + return NULL; +} + /* A convenient wrapper that returns true if a server exists */ bool SpanningTreeUtilities::IsServer(const std::string &ServerName) { diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 3a36a2e20..101714186 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -89,6 +89,9 @@ class SpanningTreeUtilities /** Hash of currently connected servers by name */ server_hash serverlist; + /** Hash of currently known server ids + */ + server_hash sidlist; /** Hash of servers currently bursting but not initialized as connected */ std::map burstingserverlist; @@ -163,6 +166,9 @@ class SpanningTreeUtilities /** Find a server by name */ TreeServer* FindServer(const std::string &ServerName); + /** Find server by SID + */ + TreeServer* FindServerID(const std::string &id); /** Find a remote bursting server by name */ TreeServer* FindRemoteBurstServer(TreeServer* Server); -- cgit v1.2.3