]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
Left figure from output
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index d6df39dbbab8ad49f184543c36a1b611fb983b78..897f9f890e0b1144cdd075375629a0807a8bbd49 100644 (file)
@@ -36,7 +36,6 @@ using namespace std;
 #include <stdarg.h>
 #include "connection.h"
 #include "users.h"
-#include "servers.h"
 #include "ctables.h"
 #include "globals.h"
 #include "modules.h"
@@ -66,7 +65,7 @@ extern int LogLevel;
 
 extern std::stringstream config_f;
 
-extern serverrec* me[32];
+
 
 extern FILE *log_file;
 extern userrec* fd_ref_table[65536];
@@ -378,20 +377,16 @@ void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
 
 std::string GetServerDescription(char* servername)
 {
-        for (int j = 0; j < 32; j++)
-        {
-                if (me[j] != NULL)
-                {
-                        for (unsigned int k = 0; k < me[j]->connectors.size(); k++)
-                        {
-                                if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),servername))
-                                {
-                                        return me[j]->connectors[k].GetDescription();
-                                }
-                        }
-                }
-        }
-       return ServerDesc; // not a remote server that can be found, it must be me.
+       std::string description = "";
+       FOREACH_MOD OnGetServerDescription(servername,description);
+       if (description != "")
+       {
+               return description;
+       }
+       else
+       {
+               return ServerDesc; // not a remote server that can be found, it must be me.
+       }
 }
 
 /* write a formatted string to all users who share at least one common
@@ -421,7 +416,7 @@ void WriteCommon(userrec *u, char* text, ...)
 
         bool sent_to_at_least_one = false;
 
-        for (int i = 0; i < MAXCHANS; i++)
+        for (unsigned int i = 0; i < u->chans.size(); i++)
         {
                 if (u->chans[i].channel)
                 {
@@ -471,7 +466,7 @@ void WriteCommonExcept(userrec *u, char* text, ...)
 
         memset(&already_sent,0,65536);
 
-        for (int i = 0; i < MAXCHANS; i++)
+        for (unsigned int i = 0; i < u->chans.size(); i++)
         {
                 if (u->chans[i].channel)
                 {
@@ -521,6 +516,46 @@ void WriteOpers(char* text, ...)
         }
 }
 
+void ServerNoticeAll(char* text, ...)
+{
+       if (!text)
+               return;
+
+       char textbuffer[MAXBUF];
+       va_list argsPtr;
+       va_start (argsPtr, text);
+       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+       va_end(argsPtr);
+
+       for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+       {
+               if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
+               {
+                       WriteServ(i->second->fd,"NOTICE $%s :%s",ServerName,textbuffer);
+               }
+       }
+}
+
+void ServerPrivmsgAll(char* text, ...)
+{
+       if (!text)
+               return;
+
+       char textbuffer[MAXBUF];
+       va_list argsPtr;
+       va_start (argsPtr, text);
+       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+       va_end(argsPtr);
+
+       for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+       {
+               if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
+               {
+                       WriteServ(i->second->fd,"PRIVMSG $%s :%s",ServerName,textbuffer);
+               }
+       }
+}
+
 void NoticeAllOpers(userrec *source, bool local_only, char* text, ...)
 {
         if ((!text) || (!source))
@@ -572,7 +607,7 @@ bool CommonOnThisServer(userrec* u,const char* servername)
 {
         log(DEBUG,"ChanAnyOnThisServer");
 
-        for (int i = 0; i < MAXCHANS; i++)
+        for (unsigned int i = 0; i < u->chans.size(); i++)
         {
                 if (u->chans[i].channel)
                 {
@@ -768,7 +803,7 @@ void purge_empty_chans(userrec* u)
         int go_again = 1, purge = 0;
 
         // firstly decrement the count on each channel
-        for (int f = 0; f < MAXCHANS; f++)
+        for (unsigned int f = 0; f < u->chans.size(); f++)
         {
                 if (u->chans[f].channel)
                 {
@@ -776,7 +811,7 @@ void purge_empty_chans(userrec* u)
                 }
         }
 
-        for (int i = 0; i < MAXCHANS; i++)
+        for (unsigned int i = 0; i < u->chans.size(); i++)
         {
                 if (u->chans[i].channel)
                 {
@@ -1051,7 +1086,7 @@ int registered_usercount(void)
         int c = 0;
         for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
         {
-                if ((i->second->fd) && (isnick(i->second->nick))) c++;
+                if (i->second->registered == 7) c++;
         }
         return c;
 }
@@ -1059,10 +1094,9 @@ int registered_usercount(void)
 int usercount_invisible(void)
 {
         int c = 0;
-
         for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
         {
-                if ((i->second->fd) && (isnick(i->second->nick)) && (strchr(i->second->modes,'i'))) c++;
+                if ((isnick(i->second->nick)) && (strchr(i->second->modes,'i'))) c++;
         }
         return c;
 }
@@ -1070,10 +1104,9 @@ int usercount_invisible(void)
 int usercount_opers(void)
 {
         int c = 0;
-
         for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
         {
-                if ((i->second->fd) && (isnick(i->second->nick)) && (strchr(i->second->modes,'o'))) c++;
+                if ((isnick(i->second->nick)) && (strchr(i->second->modes,'o'))) c++;
         }
         return c;
 }
@@ -1095,30 +1128,6 @@ long chancount(void)
         return chanlist.size();
 }
 
-long count_servs(void)
-{
-        int c = 0;
-        for (int i = 0; i < 32; i++)
-        {
-                if (me[i] != NULL)
-                {
-                        for (vector<ircd_connector>::iterator j = me[i]->connectors.begin(); j != me[i]->connectors.end(); j++)
-                        {
-                                if (strcasecmp(j->GetServerName().c_str(),ServerName))
-                                {
-                                        c++;
-                                }
-                        }
-                }
-        }
-        return c;
-}
-
-long servercount(void)
-{
-        return count_servs()+1;
-}
-
 long local_count()
 {
         int c = 0;
@@ -1181,39 +1190,6 @@ bool AllModulesReportReady(userrec* user)
         return true;
 }
 
-char islast(const char* s)
-{
-        char c = '`';
-        for (int j = 0; j < 32; j++)
-        {
-                if (me[j] != NULL)
-                {
-                        for (unsigned int k = 0; k < me[j]->connectors.size(); k++)
-                        {
-                                if (strcasecmp(me[j]->connectors[k].GetServerName().c_str(),s))
-                                {
-                                        c = '|';
-                                }
-                                if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),s))
-                                {
-                                        c = '`';
-                                }
-                        }
-                }
-        }
-        return c;
-}
-
-long map_count(const char* s)
-{
-        int c = 0;
-        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
-        {
-                if ((i->second->fd) && (isnick(i->second->nick)) && (!strcasecmp(i->second->server,s))) c++;
-        }
-        return c;
-}
-
 void createcommand(char* cmd, handlerfunc f, char flags, int minparams,char* source)
 {
         command_t comm;