Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / m_join.c
index 036139da22155bccff34220026d3c676762e6277..91d04d34489f06ed94fc68b669514c5eac5a8606 100644 (file)
@@ -130,12 +130,6 @@ int m_join(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   char*           p = NULL;
   char*           bufptr;
 
-  /*
-   * Doesn't make sense having a server join a channel, and besides
-   * the server cores.
-   */
-  if (IsServer(sptr))
-    return 0;
 
   if (parc < 2 || *parv[1] == '\0')
     return need_more_params(sptr, "JOIN");
@@ -429,27 +423,6 @@ int ms_join(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   if (parc < 2 || *parv[1] == '\0')
     return need_more_params(sptr, "JOIN");
 
-  for (p = parv[1]; *p; p++)    /* find the last "JOIN 0" in the line -Kev */
-    if (*p == '0'
-        && (*(p + 1) == ',' || *(p + 1) == '\0' || !IsChannelChar(*(p + 1))))
-    {
-      /* If it's a single "0", remember the place; we will start parsing
-         the channels after the last 0 in the line -Kev */
-      parv[1] = p;
-      if (!*(p + 1))
-        break;
-      p++;
-    }
-    else
-    {                           /* Step through to the next comma or until the
-                                   end of the line, in an attempt to save CPU
-                                   -Kev */
-      while (*p != ',' && *p != '\0')
-        p++;
-      if (!*p)
-        break;
-    }
-
   keysOrTS = parv[2];           /* Remember where our keys are or the TS is;
                                    parv[2] needs to be NULL for the call to
                                    m_names below -Kev */
@@ -463,162 +436,59 @@ int ms_join(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   for (name = ircd_strtok(&p, parv[1], ","); name; name = ircd_strtok(&p, NULL, ","))
   {
     size_t len;
-    if (MyConnect(sptr))
-      clean_channelname(name);
-    else if (IsLocalChannel(name))
+    if (IsLocalChannel(name))
       continue;
-    if (*name == '0' && *(name + 1) == '\0')
+
+    if (!IsChannelName(name))
     {
-      /* Remove the user from all his channels -Kev */
-      while ((member = sptr->user->channel))
-      {
-        chptr = member->channel;
-        if (!IsZombie(member))
-          sendto_channel_butserv(chptr, sptr, PartFmt2,
-              parv[0], chptr->chname, "Left all channels");
-        remove_user_from_channel(sptr, chptr);
-      }
-      /* Just in case */
-      *mbuf = *jbuf = '\0';
-      mlen = jlen = 0;
+      sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], name);
+      continue;
     }
-    else
-    {                           /* not a /join 0, so treat it as
-                                   a /join #channel -Kev */
-      if (!IsChannelName(name))
-      {
-        if (MyUser(sptr))
-          sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], name);
-        continue;
-      }
-
-      if (MyConnect(sptr))
-      {
-#ifdef BADCHAN
-        if (bad_channel(name) && !IsAnOper(sptr))
-        {
-          sendto_one(sptr, err_str(ERR_BADCHANNAME), me.name, parv[0], name);
-          continue;
-        }
-#endif
-        /*
-         * Local client is first to enter previously nonexistant
-         * channel so make them (rightfully) the Channel Operator.
-         * This looks kind of ugly because we try to avoid calling the strlen()
-         */
-        if (ChannelExists(name))
-        {
-          flags = CHFL_DEOPPED;
-          sendcreate = 0;
-        }
-        else if (strlen(name) > CHANNELLEN)
-        {
-          *(name + CHANNELLEN) = '\0';
-          if (ChannelExists(name))
-          {
-            flags = CHFL_DEOPPED;
-            sendcreate = 0;
-          }
-          else
-          {
-            flags = IsModelessChannel(name) ? CHFL_DEOPPED : CHFL_CHANOP;
-            sendcreate = 1;
-          }
-        }
-        else
-        {
-          flags = IsModelessChannel(name) ? CHFL_DEOPPED : CHFL_CHANOP;
-          sendcreate = 1;
-        }
 
-#ifdef OPER_NO_CHAN_LIMIT
-        /*
-         * Opers are allowed to join any number of channels
-         */
-        if (sptr->user->joined >= MAXCHANNELSPERUSER && !IsAnOper(sptr))
-#else
-        if (sptr->user->joined >= MAXCHANNELSPERUSER)
-#endif
-        {
-          chptr = get_channel(sptr, name, CGT_NO_CREATE);
-          sendto_one(sptr, err_str(ERR_TOOMANYCHANNELS),
-                     me.name, parv[0], chptr ? chptr->chname : name);
-          /*
-           * Can't return, else he won't get on ANY channels!
-           * Break out of the for loop instead.  -Kev
-           */
-          break;
-        }
-      }
+    chptr = get_channel(sptr, name, CGT_CREATE);
+    if (chptr && (member = find_member_link(chptr, sptr)))
+    {
+      if (!IsZombie(member))
+       continue;
+
+      /* If they are a zombie, make them really part
+       * and rejoin
+       */              
+      zombie = 1;
+      flags = member->status & (CHFL_DEOPPED | CHFL_SERVOPOK);
+      remove_user_from_channel(sptr, chptr);
       chptr = get_channel(sptr, name, CGT_CREATE);
-      if (chptr && (member = find_member_link(chptr, sptr)))
-      {
-        if (IsZombie(member))
-        {
-          zombie = 1;
-          flags = member->status & (CHFL_DEOPPED | CHFL_SERVOPOK);
-          remove_user_from_channel(sptr, chptr);
-          chptr = get_channel(sptr, name, CGT_CREATE);
-        }
-        else
-          continue;
-      }
-      name = chptr->chname;
-      if (!chptr->creationtime) /* A remote JOIN created this channel ? */
-        chptr->creationtime = MAGIC_REMOTE_JOIN_TS;
-      if (parc > 2)
-      {
-        if (chptr->creationtime == MAGIC_REMOTE_JOIN_TS)
-          chptr->creationtime = atoi(keysOrTS);
-        else
-          parc = 2;             /* Don't pass it on */
-      }
-      if (!zombie)
-      {
-        if (!MyConnect(sptr))
-          flags = CHFL_DEOPPED;
-        if (sptr->flags & FLAGS_TS8)
-          flags |= CHFL_SERVOPOK;
-      }
-      if (MyConnect(sptr))
-      {
-        int created = chptr->users == 0;
-        if (check_target_limit(sptr, chptr, chptr->chname, created))
-        {
-          if (created)          /* Did we create the channel? */
-            sub1_from_channel(chptr);   /* Remove it again! */
-          continue;
-        }
-        if ((i = can_join(sptr, chptr, keysOrTS)))
-        {
-          sendto_one(sptr, err_str(i), me.name, parv[0], chptr->chname);
-          continue;
-        }
-      }
-      /*
-       * Complete user entry to the new channel (if any)
-       */
-      add_user_to_channel(chptr, sptr, flags);
-
-      /*
-       * Notify all other users on the new channel
-       */
-      sendto_channel_butserv(chptr, sptr, ":%s JOIN :%s", parv[0], name);
-
-      if (MyUser(sptr))
-      {
-        del_invite(sptr, chptr);
-        if (chptr->topic[0] != '\0')
-        {
-          sendto_one(sptr, rpl_str(RPL_TOPIC), me.name,
-              parv[0], name, chptr->topic);
-          sendto_one(sptr, rpl_str(RPL_TOPICWHOTIME), me.name, parv[0], name,
-              chptr->topic_nick, chptr->topic_time);
-        }
-        parv[1] = name;
-        m_names(cptr, sptr, 2, parv);
-      }
+      
+    }
+    
+    name = chptr->chname;
+    
+    if (!chptr->creationtime) /* A remote JOIN created this channel ? */
+      chptr->creationtime = MAGIC_REMOTE_JOIN_TS;
+      
+    if (parc > 2)
+    {
+      if (chptr->creationtime == MAGIC_REMOTE_JOIN_TS)
+        chptr->creationtime = atoi(keysOrTS);
+      else
+        parc = 2;             /* Don't pass it on */
+    }
+    
+    if (!zombie)
+    {
+      if (sptr->flags & FLAGS_TS8)
+        flags |= CHFL_SERVOPOK;
     }
+    
+    /*
+     * Complete user entry to the new channel (if any)
+     */
+    add_user_to_channel(chptr, sptr, flags);
+
+    /*
+     * Notify all other users on the new channel
+     */
+    sendto_channel_butserv(chptr, sptr, ":%s JOIN :%s", parv[0], name);
 
     /* Select proper buffer; mbuf for creation, jbuf otherwise */
 
@@ -628,6 +498,7 @@ int ms_join(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     bufptr = (sendcreate == 0) ? jbuf : mbuf;
     buflen = (sendcreate == 0) ? &jlen : &mlen;
     len = strlen(name);
+    
     if (*buflen < BUFSIZE - len - 2)
     {
       if (*bufptr)
@@ -648,23 +519,6 @@ int ms_join(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     sendto_serv_butone(cptr, "%s%s " TOK_CREATE " %s " TIME_T_FMT,
         NumNick(sptr), mbuf, TStime());
 
-  if (MyUser(sptr))
-  {                             /* shouldn't ever set TS for remote JOIN's */
-    if (*jbuf)
-    {                           /* check for channels that need TS's */
-      p = NULL;
-      for (name = ircd_strtok(&p, jbuf, ","); name; name = ircd_strtok(&p, NULL, ","))
-      {
-        chptr = get_channel(sptr, name, CGT_NO_CREATE);
-        if (chptr && chptr->mode.mode & MODE_SENDTS)
-        {                       /* send a TS? */
-          sendto_serv_butone(cptr, "%s " TOK_MODE " %s + " TIME_T_FMT, NumServ(&me),
-              chptr->chname, chptr->creationtime);      /* ok, send TS */
-          chptr->mode.mode &= ~MODE_SENDTS;     /* reset flag */
-        }
-      }
-    }
-  }
   return 0;
 }