keep in sync with OGN upstream (SVN-317)
[ircu2.10.12-pk.git] / ircd / m_join.c
index 6a93769cc55de697d612fd52ba7f92a0c1b18575..66c4379650c267d1f448eb66f9d49e1c835db6c5 100644 (file)
@@ -157,7 +157,9 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
       send_reply(sptr, ERR_TOOMANYCHANNELS, name);
       break; /* no point processing the other channels */
     }
-
+    
+       int flags = 0;
+       
     /* BADCHANed channel */
     if ((gline = gline_find(name, GLINE_BADCHAN)) &&
        GlineIsActive(gline) && !IsAnOper(sptr)) {
@@ -192,7 +194,7 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     } else if (check_target_limit(sptr, chptr, chptr->chname, 0)) {
       continue;
     } else {
-      int flags = CHFL_DEOPPED;
+      flags = CHFL_DEOPPED;
       int err = 0;
       int override = 0;
 
@@ -285,6 +287,8 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
                    do_names(sptr, chptrb, NAMES_ALL|NAMES_EON);
                  }
                } else {
+          if(find_member_link(chptrb, sptr))
+            continue; //we have already joined this channel
                  //first of all check if we may even join this channel
                  int err2 = 0;
                  if (chptrb->users == 0 && !chptrb->mode.apass[0] && !(chptrb->mode.mode & MODE_PERSIST)) {
@@ -310,23 +314,30 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
               send_reply(sptr, RPL_TOPIC, chptrb->chname, chptrb->topic);
               send_reply(sptr, RPL_TOPICWHOTIME, chptrb->chname, chptrb->topic_nick, chptrb->topic_time);
             }
-            do_names(sptr, chptrb, NAMES_ALL|NAMES_EON); /* send /names list */
+            do_names(sptr, chptrb, NAMES_ALL|NAMES_EON|(((chptrb->mode.mode & MODE_AUDITORIUM) && !(flags & CHFL_CHANOP)) ? NAMES_OPS : 0)); /* send /names list */
                  }
            }
          }
          
       if (err) {
-        switch(err) {
-          case ERR_NEEDREGGEDNICK:
-            send_reply(sptr, 
-                       ERR_NEEDREGGEDNICK, 
-                       chptr->chname, 
-                       feature_str(FEAT_URLREG));            
-            break;
-          default:
+        const char *error = NULL;
+        if (err == ERR_CHANNELISFULL)
+            error = feature_str(FEAT_ERR_CHANNELISFULL);
+        else if (err == ERR_INVITEONLYCHAN)
+            error = feature_str(FEAT_ERR_INVITEONLYCHAN);
+        else if (err == ERR_BANNEDFROMCHAN)
+            error = feature_str(FEAT_ERR_BANNEDFROMCHAN);
+        else if (err == ERR_BADCHANNELKEY)
+            error = feature_str(FEAT_ERR_BADCHANNELKEY);
+        else if (err == ERR_NEEDREGGEDNICK)
+            error = feature_str(FEAT_ERR_NEEDREGGEDNICK);
+        else if (err == ERR_JOINACCESS)
+            error = feature_str(FEAT_ERR_JOINACCESS);
+        
+        if (error)
+            send_reply(sptr, err, chptr->chname, error);
+        else
             send_reply(sptr, err, chptr->chname);
-            break;
-        }
         continue;
       }
          
@@ -354,7 +365,7 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
                 chptr->topic_time);
     }
 
-    do_names(sptr, chptr, NAMES_ALL|NAMES_EON); /* send /names list */
+    do_names(sptr, chptr, NAMES_ALL|NAMES_EON|(((chptr->mode.mode & MODE_AUDITORIUM) && !(flags & CHFL_CHANOP)) ? NAMES_OPS : 0)); /* send /names list */
   }
 
   joinbuf_flush(&join); /* must be first, if there's a JOIN 0 */