]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
Gah, im forgetting to SetMode!
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index a60d83459c50117140b313c58811c8c7aa885315..77a74c32c111d6b2ceea501d2f2d15fff28b8158 100644 (file)
@@ -67,7 +67,7 @@ static time_t LAST = 0;
  *  Write a line of text `text' to the logfile (and stdout, if in nofork) if the level `level'
  *  is greater than the configured loglevel.
  */
-void log(int level, char *text, ...)
+void do_log(int level, const char *text, ...)
 {
        va_list argsPtr;
        char textbuffer[MAXBUF];
@@ -92,7 +92,10 @@ void log(int level, char *text, ...)
                va_end(argsPtr);
 
                if (Config->writelog)
+               {
                        fprintf(Config->log_file,"%s %s\n",TIMESTR,textbuffer);
+                       fflush(Config->log_file);
+               }
        }
        
        if (Config->nofork)
@@ -155,11 +158,11 @@ void Write_NoFormat(int sock, const char *text)
        if ((sock < 0) || (!text) || (sock > MAX_DESCRIPTORS))
                return;
 
-       bytes = snprintf(tb,MAXBUF,"%s\r\n",text);
-       chop(tb);
-
        if (fd_ref_table[sock])
        {
+               bytes = snprintf(tb,MAXBUF,"%s\r\n",text);
+               chop(tb);
+
                if (Config->GetIOHook(fd_ref_table[sock]->port))
                {
                        try
@@ -200,14 +203,15 @@ void Write(int sock, char *text, ...)
                return;
        }
 
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-       bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
-       chop(tb);
-
        if (fd_ref_table[sock])
        {
+
+               va_start(argsPtr, text);
+               vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+               va_end(argsPtr);
+               bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
+               chop(tb);
+
                if (Config->GetIOHook(fd_ref_table[sock]->port))
                {
                        try
@@ -240,11 +244,11 @@ void WriteServ_NoFormat(int sock, const char* text)
        if ((sock < 0) || (!text) || (sock > MAX_DESCRIPTORS))
                return;
 
-       bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,text);
-       chop(tb);
-
        if (fd_ref_table[sock])
        {
+               bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,text);
+               chop(tb);
+
                if (Config->GetIOHook(fd_ref_table[sock]->port))
                {
                        try
@@ -283,6 +287,9 @@ void WriteServ(int sock, char* text, ...)
                return;
        }
 
+       if (!fd_ref_table[sock])
+               return;
+
        va_start(argsPtr, text);
        vsnprintf(textbuffer, MAXBUF, text, argsPtr);
        va_end(argsPtr);
@@ -302,11 +309,11 @@ void WriteFrom_NoFormat(int sock, userrec *user, const char* text)
        if ((sock < 0) || (!text) || (!user) || (sock > MAX_DESCRIPTORS))
                return;
 
-       bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),text);
-       chop(tb);
-
        if (fd_ref_table[sock])
        {
+               bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),text);
+               chop(tb);
+
                if (Config->GetIOHook(fd_ref_table[sock]->port))
                {
                        try
@@ -346,14 +353,15 @@ void WriteFrom(int sock, userrec *user,char* text, ...)
                return;
        }
 
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
-       bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),textbuffer);
-       chop(tb);
-
        if (fd_ref_table[sock])
        {
+
+               va_start(argsPtr, text);
+               vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+               va_end(argsPtr);
+               bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),textbuffer);
+               chop(tb);
+
                if (Config->GetIOHook(fd_ref_table[sock]->port))
                {
                        try
@@ -539,7 +547,7 @@ void WriteChannelLocal_NoFormat(chanrec* Ptr, userrec* user, const char* text)
 
 
 
-void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
+void WriteChannelWithServ(const char* ServName, chanrec* Ptr, const char* text, ...)
 {
        char textbuffer[MAXBUF];
        va_list argsPtr;
@@ -564,7 +572,7 @@ void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
        }
 }
 
-void WriteChannelWithServ_NoFormat(char* ServName, chanrec* Ptr, const char* text)
+void WriteChannelWithServ_NoFormat(const char* ServName, chanrec* Ptr, const char* text)
 {
        CUList *ulist;
 
@@ -662,7 +670,7 @@ void ChanExceptSender_NoFormat(chanrec* Ptr, userrec* user, char status, const c
        }
 }
 
-std::string GetServerDescription(char* servername)
+std::string GetServerDescription(const char* servername)
 {
        std::string description = "";
 
@@ -958,7 +966,7 @@ void WriteOpers_NoFormat(const char* text)
 
                if (IS_LOCAL(a))
                {
-                       if (a->modebits & UM_SERVERNOTICE)
+                       if (a->modes[UM_SERVERNOTICE])
                        {
                                // send server notices to all with +s
                                WriteServ(a->fd,"NOTICE %s :%s",a->nick,text);
@@ -1037,7 +1045,7 @@ void WriteMode(const char* modes, int flags, const char* text, ...)
 
                        for (int n = 0; n < modelen; n++)
                        {
-                               if (!hasumode(t,modes[n]))
+                               if (!t->modes[modes[n]-65])
                                {
                                        send_to_user = false;
                                        break;
@@ -1050,7 +1058,7 @@ void WriteMode(const char* modes, int flags, const char* text, ...)
 
                        for (int n = 0; n < modelen; n++)
                        {
-                               if (hasumode(t,modes[n]))
+                               if (t->modes[modes[n]-65])
                                {
                                        send_to_user = true;
                                        break;
@@ -1113,7 +1121,7 @@ void WriteWallOps(userrec *source, bool local_only, char* text, ...)
        {
                userrec* t = (userrec*)(*i);
 
-               if ((IS_LOCAL(t)) && (t->modebits & UM_WALLOPS))
+               if ((IS_LOCAL(t)) && (t->modes[UM_WALLOPS]))
                {
                        WriteTo_NoFormat(source,t,formatbuffer);
                }
@@ -1326,7 +1334,7 @@ void userlist(userrec *user,chanrec *c)
 
        for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
        {
-               if ((!has_user) && (i->second->modebits & UM_INVISIBLE))
+               if ((!has_user) && (i->second->modes[UM_INVISIBLE]))
                {
                        /*
                         * user is +i, and source not on the channel, does not show
@@ -1377,7 +1385,7 @@ int usercount_i(chanrec *c)
        CUList *ulist= c->GetUsers();
        for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
        {
-               if (!(i->second->modebits & UM_INVISIBLE))
+               if (!(i->second->modes[UM_INVISIBLE]))
                        count++;
        }
 
@@ -1390,12 +1398,16 @@ int usercount(chanrec *c)
 }
 
 
-/* looks up a users password for their connection class (<ALLOW>/<DENY> tags) */
+/* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
+ * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
+ * then their ip will be taken as 'priority' anyway, so for example,
+ * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
+ */
 ConnectClass GetClass(userrec *user)
 {
        for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
        {
-               if (match(user->host,i->host.c_str()))
+               if ((match(inet_ntoa(user->ip4),i->host.c_str())) || (match(user->host,i->host.c_str())))
                {
                        return *i;
                }
@@ -1487,7 +1499,7 @@ int usercount_invisible(void)
 
        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
        {
-               if ((i->second->registered == 7) && (i->second->modebits & UM_INVISIBLE))
+               if ((i->second->registered == 7) && (i->second->modes[UM_INVISIBLE]))
                        c++;
        }