]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/message.cpp
EXPERIMENTAL new socket engine code
[user/henk/code/inspircd.git] / src / message.cpp
index ba1590f8e8b1f3ec46563fae78adce220098c41c..2f527c983e6ba9b0812af1ead2b8a91333e0b50d 100644 (file)
  * ---------------------------------------------------
  */
 
+using namespace std;
+
+#include "inspircd_config.h"
 #include "inspircd.h"
 #include "inspircd_io.h"
 #include "inspircd_util.h"
-#include "inspircd_config.h"
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/errno.h>
-#include <sys/ioctl.h>
 #include <sys/utsname.h>
-#include <cstdio>
 #include <time.h>
 #include <string>
 #ifdef GCC3
 #include <map>
 #include <sstream>
 #include <vector>
-#include <errno.h>
 #include <deque>
-#include <errno.h>
-#include <unistd.h>
-#include <sched.h>
-#include "connection.h"
 #include "users.h"
-#include "servers.h"
 #include "ctables.h"
 #include "globals.h"
 #include "modules.h"
 #include "dynamic.h"
 #include "wildcard.h"
+#include "commands.h"
 #include "message.h"
 #include "inspstring.h"
 #include "dns.h"
-
-using namespace std;
+#include "helperfuncs.h"
 
 extern int MODCOUNT;
 extern std::vector<Module*> modules;
@@ -69,9 +63,6 @@ extern char DNSServer[MAXBUF];
 
 int common_channels(userrec *u, userrec *u2)
 {
-       int i = 0;
-       int z = 0;
-
        if ((!u) || (!u2))
        {
                log(DEFAULT,"*** BUG *** common_channels was given an invalid parameter");
@@ -79,7 +70,7 @@ int common_channels(userrec *u, userrec *u2)
        }
        for (int i = 0; i != MAXCHANS; i++)
        {
-               for (z = 0; z != MAXCHANS; z++)
+               for (int z = 0; z != MAXCHANS; z++)
                {
                        if ((u->chans[i].channel != NULL) && (u2->chans[z].channel != NULL))
                        {
@@ -97,36 +88,6 @@ int common_channels(userrec *u, userrec *u2)
 }
 
 
-void safedelete(userrec *p)
-{
-       if (p)
-       {
-               log(DEBUG,"deleting %s %s %s %s",p->nick,p->ident,p->dhost,p->fullname);
-               log(DEBUG,"safedelete(userrec*): pointer is safe to delete");
-               delete p;
-               p = NULL;
-       }
-       else
-       {
-               log(DEBUG,"safedelete(userrec*): unsafe pointer operation squished");
-       }
-}
-
-void safedelete(chanrec *p)
-{
-       if (p)
-       {
-               delete p;
-               p = NULL;
-               log(DEBUG,"safedelete(chanrec*): pointer is safe to delete");
-       }
-       else
-       {
-               log(DEBUG,"safedelete(chanrec*): unsafe pointer operation squished");
-       }
-}
-
-
 void tidystring(char* str)
 {
        // strips out double spaces before a : parameter
@@ -147,7 +108,7 @@ void tidystring(char* str)
        while (go_again)
        {
                bool noparse = false;
-               int t = 0, a = 0;
+               unsigned int t = 0, a = 0;
                go_again = false;
                while (a < strlen(str))
                {
@@ -190,11 +151,12 @@ void chop(char* str)
        FOREACH_MOD OnServerRaw(temp,false,NULL);
        const char* str2 = temp.c_str();
        snprintf(str,MAXBUF,"%s",str2);
-       if (strlen(str) >= 512)
+       if (strlen(str) >= 511)
        {
-               str[509] = '\r';
-               str[510] = '\n';
-               str[511] = '\0';
+               str[510] = '\r';
+               str[511] = '\n';
+               str[512] = '\0';
+               log(DEBUG,"Excess line chopped.");
        }
 }
 
@@ -256,11 +218,9 @@ void ChangeName(userrec* user, const char* gecos)
                FOREACH_RESULT(OnChangeLocalUserGECOS(user,gecos));
                if (MOD_RESULT)
                        return;
+               FOREACH_MOD OnChangeName(user,gecos);
        }
        strlcpy(user->fullname,gecos,MAXBUF);
-       char buffer[MAXBUF];
-       snprintf(buffer,MAXBUF,"a %s :%s",user->nick,gecos);
-       NetSendToAll(buffer);
 }
 
 void ChangeDisplayedHost(userrec* user, const char* host)
@@ -271,18 +231,15 @@ void ChangeDisplayedHost(userrec* user, const char* host)
                 FOREACH_RESULT(OnChangeLocalUserHost(user,host));
                 if (MOD_RESULT)
                         return;
+               FOREACH_MOD OnChangeHost(user,host);
         }
        strlcpy(user->dhost,host,160);
-       char buffer[MAXBUF];
-       snprintf(buffer,MAXBUF,"b %s %s",user->nick,host);
-       NetSendToAll(buffer);
 }
 
 /* verify that a user's ident and nickname is valid */
 
 int isident(const char* n)
 {
-        char v[MAXBUF];
         if (!n)
 
         {
@@ -292,14 +249,14 @@ int isident(const char* n)
         {
                 return 0;
         }
-        for (int i = 0; i != strlen(n); i++)
+        for (unsigned int i = 0; i < strlen(n); i++)
         {
                 if ((n[i] < 33) || (n[i] > 125))
                 {
                         return 0;
                 }
                 /* can't occur ANYWHERE in an Ident! */
-                if (strchr("<>,./?:;@'~#=+()*&%$£ \"!",n[i]))
+                if (strchr("<>,/?:;@'~#=+()*&%$£ \"!",n[i]))
                 {
                         return 0;
                 }
@@ -310,8 +267,6 @@ int isident(const char* n)
 
 int isnick(const char* n)
 {
-       int i = 0;
-       char v[MAXBUF];
        if (!n)
        {
                return 0;
@@ -320,11 +275,11 @@ int isnick(const char* n)
        {
                return 0;
        }
-       if (strlen(n) > NICKMAX-1)
+       if (strlen(n) > NICKMAX)
        {
                return 0;
        }
-       for (int i = 0; i != strlen(n); i++)
+       for (unsigned int i = 0; i != strlen(n); i++)
        {
                if ((n[i] < 33) || (n[i] > 125))
                {
@@ -356,7 +311,6 @@ char* cmode(userrec *user, chanrec *chan)
                return "";
        }
 
-       int i;
        for (int i = 0; i != MAXCHANS; i++)
        {
                if (user->chans[i].channel)
@@ -394,6 +348,9 @@ int cstatus(userrec *user, chanrec *chan)
                return 0;
        }
 
+       if (is_uline(user->server))
+               return STATUS_OP;
+
        for (int i = 0; i != MAXCHANS; i++)
        {
                if (user->chans[i].channel)
@@ -470,11 +427,9 @@ void TidyBan(char *ban)
 
 char lst[MAXBUF];
 
-char* chlist(userrec *user)
+char* chlist(userrec *user,userrec* source)
 {
-       int i = 0;
        char cmp[MAXBUF];
-
         log(DEBUG,"chlist: %s",user->nick);
        strcpy(lst,"");
        if (!user)
@@ -491,7 +446,8 @@ char* chlist(userrec *user)
                                strlcat(cmp," ",MAXBUF);
                                if (!strstr(lst,cmp))
                                {
-                                       if ((!user->chans[i].channel->c_private) && (!user->chans[i].channel->secret))
+                                       // if the channel is NOT private/secret, OR the source user is on the channel
+                                       if (((!(user->chans[i].channel->binarymodes & CM_PRIVATE)) && (!(user->chans[i].channel->binarymodes & CM_SECRET))) || (has_channel(source,user->chans[i].channel)))
                                        {
                                                strlcat(lst,cmode(user,user->chans[i].channel),MAXBUF);
                                                strlcat(lst,user->chans[i].channel->name,MAXBUF);
@@ -509,11 +465,4 @@ char* chlist(userrec *user)
 }
 
 
-void send_network_quit(const char* nick, const char* reason)
-{
-       char buffer[MAXBUF];
-       snprintf(buffer,MAXBUF,"Q %s :%s",nick,reason);
-       NetSendToAll(buffer);
-}
-