]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/message.cpp
fixes to /STATS P
[user/henk/code/inspircd.git] / src / message.cpp
index 63fdae1358181f1955dbe0ca5c8c57f58c0924bd..f7576fe4789fe2ba7a0bcbcfd9ba13bfa6c3cc3d 100644 (file)
 #include "wildcard.h"
 #include "message.h"
 
+using namespace std;
+
+extern int MODCOUNT;
+extern vector<Module*> modules;
+extern vector<ircd_module*> factory;
 
 /* return 0 or 1 depending if users u and u2 share one or more common channels
  * (used by QUIT, NICK etc which arent channel specific notices) */
@@ -53,7 +58,7 @@ int common_channels(userrec *u, userrec *u2)
                {
                        if ((u->chans[i].channel != NULL) && (u2->chans[z].channel != NULL))
                        {
-                               if ((u->chans[i].channel == u2->chans[z].channel) && (u->chans[i].channel) && (u2->chans[z].channel) && (u->registered == 7) && (u2->registered == 7))
+                               if ((!strcasecmp(u->chans[i].channel->name,u2->chans[z].channel->name)) && (u->chans[i].channel) && (u2->chans[z].channel) && (u->registered == 7) && (u2->registered == 7))
                                {
                                        if ((c_count(u)) && (c_count(u2)))
                                        {
@@ -157,7 +162,7 @@ void chop(char* str)
        return;
   }
   string temp = str;
-  FOREACH_MOD OnServerRaw(temp,false);
+  FOREACH_MOD OnServerRaw(temp,false,NULL);
   const char* str2 = temp.c_str();
   sprintf(str,"%s",str2);
   
@@ -229,14 +234,6 @@ bool hasumode(userrec* user, char mode)
 void ChangeName(userrec* user, const char* gecos)
 {
        strncpy(user->fullname,gecos,MAXBUF);
-
-       // TODO: replace these with functions:
-       // NetSendToAll - to all
-       // NetSendToCommon - to all that hold users sharing a common channel with another user
-       // NetSendToOne - to one server
-       // NetSendToAllExcept - send to all but one
-       // all by servername
-
        char buffer[MAXBUF];
        snprintf(buffer,MAXBUF,"a %s :%s",user->nick,gecos);
        NetSendToAll(buffer);
@@ -331,21 +328,24 @@ char* cmode(userrec *user, chanrec *chan)
        int i;
        for (int i = 0; i != MAXCHANS; i++)
        {
-               if ((user->chans[i].channel == chan) && (chan != NULL))
+               if (user->chans[i].channel)
                {
-                       if ((user->chans[i].uc_modes & UCMODE_OP) > 0)
-                       {
-                               return "@";
-                       }
-                       if ((user->chans[i].uc_modes & UCMODE_HOP) > 0)
-                       {
-                               return "%";
-                       }
-                       if ((user->chans[i].uc_modes & UCMODE_VOICE) > 0)
+                       if ((!strcasecmp(user->chans[i].channel->name,chan->name)) && (chan != NULL))
                        {
-                               return "+";
+                               if ((user->chans[i].uc_modes & UCMODE_OP) > 0)
+                               {
+                                       return "@";
+                               }
+                               if ((user->chans[i].uc_modes & UCMODE_HOP) > 0)
+                               {
+                                       return "%";
+                               }
+                               if ((user->chans[i].uc_modes & UCMODE_VOICE) > 0)
+                               {
+                                       return "+";
+                               }
+                               return "";
                        }
-                       return "";
                }
        }
 }
@@ -364,21 +364,24 @@ int cstatus(userrec *user, chanrec *chan)
 
        for (int i = 0; i != MAXCHANS; i++)
        {
-               if ((user->chans[i].channel == chan) && (chan != NULL))
+               if (user->chans[i].channel)
                {
-                       if ((user->chans[i].uc_modes & UCMODE_OP) > 0)
-                       {
-                               return STATUS_OP;
-                       }
-                       if ((user->chans[i].uc_modes & UCMODE_HOP) > 0)
-                       {
-                               return STATUS_HOP;
-                       }
-                       if ((user->chans[i].uc_modes & UCMODE_VOICE) > 0)
+                       if ((!strcasecmp(user->chans[i].channel->name,chan->name)) && (chan != NULL))
                        {
-                               return STATUS_VOICE;
+                               if ((user->chans[i].uc_modes & UCMODE_OP) > 0)
+                               {
+                                       return STATUS_OP;
+                               }
+                               if ((user->chans[i].uc_modes & UCMODE_HOP) > 0)
+                               {
+                                       return STATUS_HOP;
+                               }
+                               if ((user->chans[i].uc_modes & UCMODE_VOICE) > 0)
+                               {
+                                       return STATUS_VOICE;
+                               }
+                               return STATUS_NORMAL;
                        }
-                       return STATUS_NORMAL;
                }
        }
 }
@@ -394,13 +397,90 @@ int has_channel(userrec *u, chanrec *c)
        }
        for (int i =0; i != MAXCHANS; i++)
        {
-               if (u->chans[i].channel == c)
+               if (u->chans[i].channel)
                {
-                       return 1;
+                       if (!strcasecmp(u->chans[i].channel->name,c->name))
+                       {
+                               return 1;
+                       }
                }
        }
        return 0;
 }
 
 
+void TidyBan(char *ban)
+{
+       if (!ban) {
+               log(DEFAULT,"*** BUG *** TidyBan was given an invalid parameter");
+               return;
+       }
+       
+       char temp[MAXBUF],NICK[MAXBUF],IDENT[MAXBUF],HOST[MAXBUF];
+
+       strcpy(temp,ban);
+
+       char* pos_of_pling = strchr(temp,'!');
+       char* pos_of_at = strchr(temp,'@');
+
+       pos_of_pling[0] = '\0';
+       pos_of_at[0] = '\0';
+       pos_of_pling++;
+       pos_of_at++;
+
+       strncpy(NICK,temp,NICKMAX);
+       strncpy(IDENT,pos_of_pling,IDENTMAX+1);
+       strncpy(HOST,pos_of_at,160);
+
+       sprintf(ban,"%s!%s@%s",NICK,IDENT,HOST);
+}
+
+char lst[MAXBUF];
+
+char* chlist(userrec *user)
+{
+       int i = 0;
+       char cmp[MAXBUF];
+
+        log(DEBUG,"chlist: %s",user->nick);
+       strcpy(lst,"");
+       if (!user)
+       {
+               return lst;
+       }
+       for (int i = 0; i != MAXCHANS; i++)
+       {
+               if (user->chans[i].channel != NULL)
+               {
+                       if (user->chans[i].channel->name)
+                       {
+                               strcpy(cmp,user->chans[i].channel->name);
+                               strcat(cmp," ");
+                               if (!strstr(lst,cmp))
+                               {
+                                       if ((!user->chans[i].channel->c_private) && (!user->chans[i].channel->secret))
+                                       {
+                                               strcat(lst,cmode(user,user->chans[i].channel));
+                                               strcat(lst,user->chans[i].channel->name);
+                                               strcat(lst," ");
+                                       }
+                               }
+                       }
+               }
+       }
+       if (strlen(lst))
+       {
+               lst[strlen(lst)-1] = '\0'; // chop trailing space
+       }
+       return lst;
+}
+
+
+void send_network_quit(const char* nick, const char* reason)
+{
+       char buffer[MAXBUF];
+       snprintf(buffer,MAXBUF,"Q %s :%s",nick,reason);
+       NetSendToAll(buffer);
+}
+