]> jfr.im git - irc/quakenet/newserv.git/blobdiff - channel/channelhandlers.c
fix bug in G stats
[irc/quakenet/newserv.git] / channel / channelhandlers.c
index fe45face3b60192b3cbea5c3a3bb1ae517342303..d3c6c8affdb3061d759ecc9004ae4ed8ff55376a 100644 (file)
@@ -212,7 +212,7 @@ int handleburstmsg(void *source, int cargc, char **cargv) {
 int handlejoinmsg(void *source, int cargc, char **cargv) {
   char *pos,*nextchan;
   nick *np;
-  void *harg[2];
+  void *harg[3];
   channel *cp,**ch;
   long timestamp=0;
   int i;
@@ -230,7 +230,7 @@ int handlejoinmsg(void *source, int cargc, char **cargv) {
   /* Find out who we are talking about here */
   np=getnickbynumericstr(source);
   if (np==NULL) {
-    Error("channel",ERR_WARNING,"Channel join from non existent user %s",source);
+    Error("channel",ERR_WARNING,"Channel join from non existent user %s",(char *)source);
     return CMD_OK;  
   }
   
@@ -257,6 +257,7 @@ int handlejoinmsg(void *source, int cargc, char **cargv) {
         /* Send hook */
         harg[0]=ch[i];
         harg[1]=np;
+        harg[2]=NULL;
         triggerhook(HOOK_CHANNEL_PART,harg);
         delnickfromchannel(ch[i],np->numeric,0);
       }
@@ -283,16 +284,23 @@ int handlejoinmsg(void *source, int cargc, char **cargv) {
         if (newchan) {
           delchannel(cp);
         } 
-      } else { 
+      } else {
+        chanindex *cip=cp->index;
+         
         /* If we just created a channel, flag it */
         if (newchan) {
           triggerhook(HOOK_CHANNEL_NEWCHANNEL,cp);
         }
-
-        /* send hook */
-        harg[0]=cp;
-        harg[1]=np;
-        triggerhook(HOOK_CHANNEL_JOIN,harg);
+        
+        /* Don't send HOOK_CHANNEL_JOIN if the channel doesn't exist any
+         * more (can happen if something destroys it in response to
+         * HOOK_CHANNEL_NEWCHANNEL) */
+        if (cp == cip->channel) {
+          /* send hook */
+          harg[0]=cp;
+          harg[1]=np;
+          triggerhook(HOOK_CHANNEL_JOIN,harg);
+        }
       }
     }
     nextchan=pos;
@@ -317,7 +325,7 @@ int handlecreatemsg(void *source, int cargc, char **cargv) {
   /* Find out who we are talking about here */
   np=getnickbynumericstr(source);
   if (np==NULL) {
-    Error("channel",ERR_WARNING,"Channel create from non existent user %s",source);
+    Error("channel",ERR_WARNING,"Channel create from non existent user %s",(char *)source);
     return CMD_OK;  
   }
   
@@ -354,16 +362,22 @@ int handlecreatemsg(void *source, int cargc, char **cargv) {
       if (newchan) {
         delchannel(cp);
       }
-    } else {  
+    } else {
+      chanindex *cip = cp->index;
+        
       /* Flag the channel as new if necessary */
       if (newchan) {
         triggerhook(HOOK_CHANNEL_NEWCHANNEL,cp);
       }
     
-      /* Trigger hook */
-      harg[0]=cp;
-      harg[1]=np;
-      triggerhook(HOOK_CHANNEL_CREATE,harg);
+      /* If HOOK_CHANNEL_NEWCHANNEL has caused the channel to be deleted,
+       * don't trigger the CREATE hook. */
+      if (cip->channel == cp) {
+        /* Trigger hook */
+        harg[0]=cp;
+        harg[1]=np;
+        triggerhook(HOOK_CHANNEL_CREATE,harg);
+      }
     }
     nextchan=pos;
   }
@@ -394,7 +408,7 @@ int handlepartmsg(void *source, int cargc, char **cargv) {
   /* Find out who we are talking about here */
   np=getnickbynumericstr(source);
   if (np==NULL) {
-    Error("channel",ERR_WARNING,"PART from non existent numeric %s",source);
+    Error("channel",ERR_WARNING,"PART from non existent numeric %s",(char *)source);
     return CMD_OK;  
   }
   
@@ -441,7 +455,7 @@ int handlekickmsg(void *source, int cargc, char **cargv) {
   
   /* Find out who we are talking about here */
   if ((np=getnickbynumericstr(cargv[1]))==NULL) {
-    Error("channel",ERR_DEBUG,"Non-existant numeric %s kicked from channel %s",source,cargv[0]);
+    Error("channel",ERR_DEBUG,"Non-existant numeric %s kicked from channel %s",(char *)source,cargv[0]);
     return CMD_OK;  
   }
 
@@ -494,10 +508,15 @@ int handletopicmsg(void *source, int cargc, char **cargv) {
   if (cargc>3)
     timestamp=strtol(cargv[cargc-3], NULL, 10);
   
-  if ((np=getnickbynumericstr((char *)source))==NULL) {
+  np=getnickbynumericstr((char *)source);
+
+  /* The following check removed because servers can set topics.. */
+#if 0
+  if (np==NULL) {
     /* We should check the sender exists, but we still change the topic even if it doesn't */
     Error("channel",ERR_WARNING,"Topic change by non-existent user %s",(char *)source);
   }
+#endif
   
   /* Grab channel pointer */
   if ((cp=findchannel(cargv[0]))==NULL) {