Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_join.c
index b5a675cb20cb7d3093caf3b9c36ed8a65fb7372f..cec63571b75a29dc5267787dff552f0917f36f5c 100644 (file)
@@ -167,7 +167,7 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
         continue;
 
       /* Try to add the new channel as a recent target for the user. */
-      if (check_target_limit(sptr, chptr, chptr->chname, 1)) {
+      if (check_target_limit(sptr, chptr, chptr->chname, 0)) {
         chptr->members = 0;
         destruct_channel(chptr);
         continue;
@@ -340,8 +340,7 @@ int ms_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
       }
       flags |= HasFlag(sptr, FLAG_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;
+      chptr->creationtime = creation;
     }
     else { /* We have a valid channel? */
       if ((member = find_member_link(chptr, sptr)))
@@ -363,9 +362,39 @@ int ms_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
          by one when someone joins an existing, but empty, channel.
          However, this is only necessary when the channel is still
          empty (also here) and when this channel doesn't have +A set.
+
+         To prevent this from allowing net-rides on the channel, we
+         clear all ops from the channel.
+
+         (Scenario for a net ride: c1 - s1 - s2 - c2, with c1 the only
+         user in the channel; c1 parts and rejoins, gaining ops.
+         Before s2 sees c1's part, c2 joins the channel and parts
+         immediately.  s1 sees c1 part, c1 create, c2 join, c2 part;
+         c2's join resets the timestamp.  s2 sees c2 join, c2 part, c1
+         part, c1 create; but since s2 sees the channel as a zannel or
+         non-existent, it does not bounce the create with the newer
+         timestamp.)
       */
-      if (creation && creation - ((!chptr->mode.apass[0] && chptr->users == 0) ? 1 : 0) <= chptr->creationtime)
+      if (creation && (creation < chptr->creationtime ||
+                      (!chptr->mode.apass[0] && chptr->users == 0))) {
+        struct Membership *member;
+        struct ModeBuf mbuf;
+
        chptr->creationtime = creation;
+        /* Deop the current ops.  (This will go in both directions on
+         * the network, and revise the channel timestamp as it goes,
+         * avoiding further traffic due to the JOIN.)
+         */
+        modebuf_init(&mbuf, sptr, cptr, chptr, MODEBUF_DEST_CHANNEL | MODEBUF_DEST_HACK3 | MODEBUF_DEST_SERVER);
+        for (member = chptr->members; member; member = member->next_member)
+        {
+          if (IsChanOp(member)) {
+            modebuf_mode_client(&mbuf, MODE_DEL | MODE_CHANOP, member->user, OpLevel(member));
+           member->status &= ~CHFL_CHANOP;
+         }
+        }
+        modebuf_flush(&mbuf);
+      }
     }
 
     joinbuf_join(&join, chptr, flags);