From d67225f7e15127841f98a54748c73bff4da9f783 Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 11 Jul 2006 19:20:18 +0000 Subject: [PATCH] Channel user count stuff git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4341 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_httpd_stats.cpp | 98 ++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index 7c43d19d8..93908a746 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -19,13 +19,27 @@ using namespace std; #include #include "users.h" #include "channels.h" +#include "configreader.h" #include "modules.h" #include "inspsocket.h" #include "helperfuncs.h" #include "httpd.h" +#include "inspircd.h" /* $ModDesc: Provides statistics over HTTP via m_httpd.so */ +extern user_hash clientlist; +extern chan_hash chanlist; +extern std::vector all_opers; +extern InspIRCd* ServerInstance; +extern ServerConfig* Config; + +extern int MODCOUNT; + +typedef std::map StatsHash; +typedef StatsHash::iterator StatsIter; +static StatsHash* sh = new StatsHash(); + class ModuleHttpStats : public Module { Server* Srv; @@ -61,10 +75,44 @@ class ModuleHttpStats : public Module data << "InspIRCd server statisitics for " << Srv->GetServerName() << " (" << Srv->GetServerDescription() << ")"; data << ""; data << "

InspIRCd server statisitics for " << Srv->GetServerName() << " (" << Srv->GetServerDescription() << ")

"; + + data << "
"; + data << "

Totals

"; + data << ""; + data << ""; + data << ""; + data << ""; + data << ""; + data << "
Users" << clientlist.size() << "
Channels" << chanlist.size() << "
Opers" << all_opers.size() << "
Sockets" << (ServerInstance->SE->GetMaxFds() - ServerInstance->SE->GetRemainingFds()) << " (Max: " << ServerInstance->SE->GetMaxFds() << " via socket engine '" << ServerInstance->SE->GetName() << "')
"; + data << "
"; + + data << "
"; + data << "

Modules

"; + data << ""; + for (int i = 0; i <= MODCOUNT; i++) + { + if (Config->module_names[i] != "") + data << ""; + } + data << "
" << Config->module_names[i] << "
"; + data << "
"; + + data << "
"; + data << "

Channels

"; + data << ""; + data << ""; + for (StatsIter a = sh->begin(); a != sh->end(); a++) + { + data << ""; + } + data << "
UsersCount
" << a->second << "" << a->first << "
"; + data << "
"; + data << ""; data << ""; + /* Send the document back to m_httpd */ HTTPDocument response(http->sock, &data, 200, "X-Powered-By: m_http_stats.so\r\nContent-Type: text/html\r\n"); Request req((char*)&response, (Module*)this, event->GetSource()); req.Send(); @@ -74,6 +122,53 @@ class ModuleHttpStats : public Module } } + void OnChannelDelete(chanrec* chan) + { + StatsIter a = sh->find(chan->name); + if (a != sh->end()) + { + sh->erase(a); + } + } + + void OnUserJoin(userrec* user, chanrec* channel) + { + StatsIter a = sh->find(channel->name); + if (a != sh->end()) + { + a->second++; + } + else + { + a[channel->name] = 1; + } + } + + void OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage) + { + StatsIter a = sh->find(channel->name); + if (a != sh->end()) + { + a->second--; + } + } + + void OnUserQuit(userrec* user, const std::string &message) + { + for (std::vector::const_iterator v = user->chans.begin(); v != user->chans.end(); v++) + { + if (((ucrec*)(*v))->channel) + { + chanrec* c = ((ucrec*)(*v))->channel; + StatsIter a = sh->find(c->name); + if (a != sh->end()) + { + a->second--; + } + } + } + } + char* OnRequest(Request* request) { return NULL; @@ -81,11 +176,12 @@ class ModuleHttpStats : public Module void Implements(char* List) { - List[I_OnEvent] = List[I_OnRequest] = 1; + List[I_OnEvent] = List[I_OnRequest] = List[I_OnChannelDelete] = List[I_OnUserJoin] = List[I_OnUserPart] = List[I_OnUserQuit] = 1; } virtual ~ModuleHttpStats() { + delete sh; } virtual Version GetVersion() -- 2.39.5