Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / m_join.c
index 657bc4e7398c54abb4df031f022b3a532725da29..437a52f2bbb58be6ee6009f3049427898c268d38 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#if !defined(XXX_BOGUS_TEMP_HACK)
-#include "handlers.h"      /* m_names */
-#endif
-
 /*
  * Helper function to find last 0 in a comma-separated list of
  * channel names.
@@ -159,7 +155,7 @@ join0(struct JoinBuf *join, struct Client *cptr, struct Client *sptr,
   joinbuf_init(&part, sptr, cptr, JOINBUF_TYPE_PARTALL,
               "Left all channels", 0);
 
-  while ((member = sptr->user->channel))
+  while ((member = cli_user(sptr)->channel))
     joinbuf_join(&part, member->channel,
                 IsZombie(member) ? CHFL_ZOMBIE : 0);
 
@@ -176,9 +172,7 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   struct Channel *chptr;
   struct JoinBuf join;
   struct JoinBuf create;
-#ifdef BADCHAN
   struct Gline *gline;
-#endif
   unsigned int flags = 0;
   int i;
   char *p = 0;
@@ -196,8 +190,6 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 
   keys = parv[2]; /* remember where keys are */
 
-  parv[2] = 0; /* for call to m_names below */
-
   for (name = ircd_strtok(&p, chanlist, ","); name;
        name = ircd_strtok(&p, 0, ",")) {
     clean_channelname(name);
@@ -210,14 +202,12 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
       continue;
     }
 
-#ifdef BADCHAN
     /* BADCHANed channel */
     if ((gline = gline_find(name, GLINE_BADCHAN | GLINE_EXACT)) &&
        GlineIsActive(gline) && !IsAnOper(sptr)) {
       send_reply(sptr, ERR_BANNEDFROMCHAN, name);
       continue;
     }
-#endif
 
     if ((chptr = FindChannel(name))) {
       if (find_member_link(chptr, sptr))
@@ -227,12 +217,8 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     } else
       flags = IsModelessChannel(name) ? CHFL_DEOPPED : CHFL_CHANOP;
 
-    if (sptr->user->joined >= MAXCHANNELSPERUSER
-#ifdef OPER_NO_CHAN_LIMIT
-       /* Opers are allowed to join any number of channels */
-       && !IsAnOper(sptr)
-#endif
-       ) {
+    if (cli_user(sptr)->joined >= MAXCHANNELSPERUSER &&
+       !HasPriv(sptr, PRIV_CHAN_LIMIT)) {
       send_reply(sptr, ERR_TOOMANYCHANNELS, chptr ? chptr->chname : name);
       break; /* no point processing the other channels */
     }
@@ -241,7 +227,6 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
       if (check_target_limit(sptr, chptr, chptr->chname, 0))
        continue; /* exceeded target limit */
       else if ((i = can_join(sptr, chptr, keys))) {
-#ifdef OPER_WALK_THROUGH_LMODES
        if (i > MAGIC_OPER_OVERRIDE) { /* oper overrode mode */
          switch (i - MAGIC_OPER_OVERRIDE) {
          case ERR_CHANNELISFULL: /* figure out which mode */
@@ -268,10 +253,6 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
          send_reply(sptr, i, chptr->chname);
          continue;
        }
-#else
-       send_reply(sptr, i, chptr->chname);
-       continue;
-#endif
       } /* else if ((i = can_join(sptr, chptr, keys))) { */
 
       joinbuf_join(&join, chptr, flags);
@@ -292,7 +273,7 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
                 chptr->topic_time);
     }
 
-    do_names(sptr, chptr, NAMES_ALL); /* send /names list */
+    do_names(sptr, chptr, NAMES_ALL|NAMES_EON); /* send /names list */
   }
 
   joinbuf_flush(&join); /* must be first, if there's a JOIN 0 */
@@ -316,8 +297,7 @@ int ms_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   char *name;
 
   if (IsServer(sptr)) {
-    Debug((DEBUG_ERROR, "%s tried to JOIN a channel", sptr->name));
-    return 0;
+    return protocol_violation(sptr,"%s tried to JOIN a channel, duh!", cli_name(sptr));
   }
 
   if (parc < 2 || *parv[1] == '\0')
@@ -337,10 +317,24 @@ int ms_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     if (join0(&join, cptr, sptr, name)) /* did client do a JOIN 0? */
       continue;
 
-    if (IsLocalChannel(name) || !IsChannelName(name))
+    if (IsLocalChannel(name) || !IsChannelName(name)) {
+      protocol_violation(sptr,"%s tried to join %s",cli_name(cptr),name);
       continue;
+    }
 
-    if ((chptr = FindChannel(name))) {
+    if (!(chptr = FindChannel(name))) {
+      /* No channel exists, so create one */
+      if (!(chptr = get_channel(sptr, name, CGT_CREATE))) {
+        protocol_violation(sptr,"couldn't get channel %s for %s",
+                          name,cli_name(sptr));
+       continue;
+      }
+      flags = CHFL_DEOPPED | ((cli_flags(sptr) & FLAGS_TS8) ? CHFL_SERVOPOK : 0);
+
+      /* when the network is 2.10.11+ then remove MAGIC_REMOTE_JOIN_TS */ 
+      chptr->creationtime = creation ? creation : MAGIC_REMOTE_JOIN_TS;
+    }
+    else { /* We have a valid channel? */
       if ((member = find_member_link(chptr, sptr))) {
        if (!IsZombie(member)) /* already on channel */
          continue;
@@ -349,15 +343,8 @@ int ms_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
        remove_user_from_channel(sptr, chptr);
        chptr = FindChannel(name);
       } else
-       flags = CHFL_DEOPPED | ((sptr->flags & FLAGS_TS8) ? CHFL_SERVOPOK : 0);
-    } else {
-      flags = CHFL_DEOPPED | ((sptr->flags & FLAGS_TS8) ? CHFL_SERVOPOK : 0);
-
-      if ((chptr = get_channel(sptr, name, CGT_CREATE)))
-       chptr->creationtime = creation ? creation : MAGIC_REMOTE_JOIN_TS;
-      else
-       continue; /* couldn't get channel */
-    }
+       flags = CHFL_DEOPPED | ((cli_flags(sptr) & FLAGS_TS8) ? CHFL_SERVOPOK : 0);
+    } 
 
     joinbuf_join(&join, chptr, flags);
   }