]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add call to protocol interface to get useful info on the server map. Return a std...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 8 May 2008 22:40:11 +0000 (22:40 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 8 May 2008 22:40:11 +0000 (22:40 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9673 e03df62e-2008-0410-955e-edbf42e46eb7

include/protocol.h
src/modules/m_httpd_stats.cpp
src/modules/m_spanningtree/protocolinterface.cpp
src/modules/m_spanningtree/protocolinterface.h

index 16e347ad2481e818c08bce8fcfb5e46826b22d12..44013a1cac271ca8d6f92163b5d8544c6df89996 100644 (file)
@@ -20,6 +20,18 @@ class InspIRCd;
 
 typedef std::deque<std::string> parameterlist;
 
+class ProtoServer
+{
+ public:
+       std::string servername;
+       std::string parentname;
+       unsigned int usercount;
+       unsigned int opercount;
+       unsigned int latencyms;
+};
+
+typedef std::list<ProtoServer> ProtoServerList;
+
 class ProtocolInterface : public Extensible
 {
  protected:
@@ -60,6 +72,8 @@ class ProtocolInterface : public Extensible
        virtual void SendUserPrivmsg(User* target, const std::string &text) { }
 
        virtual void SendUserNotice(User* target, const std::string &text) { }
+
+       virtual void GetServerList(ProtoServerList &sl) { }
 };
 
 #endif
index d95824c839a72a9eca0c18d08ecd22c87272dc5c..aa64dc3eabc63783a30a82f9cf38f91632bacae7 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "inspircd.h"
 #include "httpd.h"
+#include "protocol.h"
 
 /* $ModDesc: Provides statistics over HTTP via m_httpd.so */
 /* $ModDep: httpd.h */
@@ -26,8 +27,6 @@ typedef SortedList::iterator SortedIter;
 static StatsHash* sh = new StatsHash();
 static SortedList* so = new SortedList();
 
-static StatsHash* Servers = new StatsHash();
-
 class ModuleHttpStats : public Module
 {
        
@@ -73,18 +72,6 @@ class ModuleHttpStats : public Module
                so->clear();
                for (StatsIter a = sh->begin(); a != sh->end(); a++)
                        InsertOrder(a->first, a->second);
-               for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
-               {
-                       StatsHash::iterator n = Servers->find(u->second->server);
-                       if (n != Servers->end())
-                       {
-                               n->second++;
-                       }
-                       else
-                       {
-                               Servers->insert(std::make_pair<irc::string,int>(u->second->server,1));
-                       }
-               }
                this->changed = false;
        }
 
@@ -156,11 +143,17 @@ class ModuleHttpStats : public Module
 
                                data << "<serverlist>";
                                
-                               for (StatsHash::iterator b = Servers->begin(); b != Servers->end(); b++)
+                               ProtoServerList sl;
+                               ServerInstance->PI->GetServerList(sl);
+
+                               for (ProtoServerList::iterator b = sl.begin(); b != sl.end(); ++b)
                                {
                                        data << "<server>";
-                                       data << "<servername>" << b->first << "</servername>";
-                                       data << "<usercount>" << b->second << "</usercount>";
+                                       data << "<servername>" << b->servername << "</servername>";
+                                       data << "<parentname>" << b->parentname << "</parentname>";
+                                       data << "<usercount>" << b->usercount << "</usercount>";
+                                       data << "<opercount>" << b->opercount << "</opercount>";
+                                       data << "<lagmillisecs>" << b->latencyms << "</lagmillisecs>";
                                        data << "</server>";
                                }
                                data << "</serverlist>";
index 7aed1ddfa148f8bf66f91d709ddf47bc8bdad84e..e586c7017160c7d5761d6abdbad63f08f90f510e 100644 (file)
@@ -5,6 +5,22 @@
 #include "m_spanningtree/treesocket.h"
 #include "m_spanningtree/protocolinterface.h"
 
+void SpanningTreeProtocolInterface::GetServerList(ProtoServerList &sl)
+{
+       sl.clear();
+       for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
+       {
+               ProtoServer ps;
+               ps.servername = i->second->GetName();
+               TreeServer* s = i->second->GetParent();
+               ps.parentname = s ? s->GetName() : ServerInstance->Config->ServerName;
+               ps.usercount = i->second->GetUserCount();
+               ps.opercount = i->second->GetOperCount();
+               ps.latencyms = i->second->rtt;
+               sl.push_back(ps);
+       }
+}
+
 void SpanningTreeProtocolInterface::SendEncapsulatedData(parameterlist &encap)
 {
        Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", encap);
index 60f961a22bad7e69b4a92fd173ef2703bceb15e6..b43e88c67f19c5e5aaf49906068e9247ada7263d 100644 (file)
@@ -4,7 +4,6 @@
 class SpanningTreeUtilities;
 class ModuleSpanningTree;
 
-
 class SpanningTreeProtocolInterface : public ProtocolInterface
 {
        SpanningTreeUtilities* Utils;
@@ -25,6 +24,8 @@ class SpanningTreeProtocolInterface : public ProtocolInterface
        virtual void SendChannelNotice(Channel* target, char status, const std::string &text);
        virtual void SendUserPrivmsg(User* target, const std::string &text);
        virtual void SendUserNotice(User* target, const std::string &text);
+       virtual void GetServerList(ProtoServerList &sl);
 };
 
 #endif
+