Fix desync when an oplevel deop is bounced (#1298140).
[ircu2.10.12-pk.git] / ircd / m_burst.c
index 42b39cd7ba501850b2d53ea10ade226ff727b7a2..1746fda68601edae3755f6ff43e5309c4eabc455 100644 (file)
@@ -249,7 +249,7 @@ int ms_burst(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
               && (!(check_modes & MODE_REGONLY) || IsAccount(member->user)))
             continue;
           sendcmdto_serv_butone(&me, CMD_KICK, NULL, "%H %C :Net Rider", chptr, member->user);
-          sendcmdto_channel_butserv_butone(&me, CMD_KICK, chptr, NULL, 0, "%H %C :Net Rider", chptr, member->user);
+          sendcmdto_channel_butserv_butone(&his, CMD_KICK, chptr, NULL, 0, "%H %C :Net Rider", chptr, member->user);
           make_zombie(member, member->user, &me, &me, chptr);
         }
       }
@@ -277,6 +277,24 @@ int ms_burst(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     modebuf_mode(mbuf, MODE_DEL | chptr->mode.mode); /* wipeout modes */
     chptr->mode.mode &= MODE_BURSTADDED | MODE_WASDELJOINS;
 
+    /* wipe out modes not represented in chptr->mode.mode */
+    if (chptr->mode.limit) {
+      modebuf_mode_uint(mbuf, MODE_DEL | MODE_LIMIT, chptr->mode.limit);
+      chptr->mode.limit = 0;
+    }
+    if (chptr->mode.key[0]) {
+      modebuf_mode_string(mbuf, MODE_DEL | MODE_KEY, chptr->mode.key, 0);
+      chptr->mode.key[0] = '\0';
+    }
+    if (chptr->mode.upass[0]) {
+      modebuf_mode_string(mbuf, MODE_DEL | MODE_UPASS, chptr->mode.upass, 0);
+      chptr->mode.upass[0] = '\0';
+    }
+    if (chptr->mode.apass[0]) {
+      modebuf_mode_string(mbuf, MODE_DEL | MODE_APASS, chptr->mode.apass, 0);
+      chptr->mode.apass[0] = '\0';
+    }
+
     parse_flags |= (MODE_PARSE_SET | MODE_PARSE_WIPEOUT); /* wipeout keys */
 
     /* mark bans for wipeout */
@@ -288,7 +306,7 @@ int ms_burst(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
       *chptr->topic = '\0';
       *chptr->topic_nick = '\0';
       chptr->topic_time = 0;
-      sendcmdto_channel_butserv_butone(&me, CMD_TOPIC, chptr, NULL, 0,
+      sendcmdto_channel_butserv_butone(&his, CMD_TOPIC, chptr, NULL, 0,
                                        "%H :%s", chptr, chptr->topic);
     }
   } else if (chptr->creationtime == timestamp) {
@@ -351,15 +369,9 @@ int ms_burst(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
              banstr[banpos++] = *ptr;
 
            newban = make_ban(ban); /* create new ban */
-
-            DupString(newban->who, 
-                      cli_name(feature_bool(FEAT_HIS_BANWHO) ? &me : sptr));
+            strcpy(newban->who, "*");
            newban->when = TStime();
-
-           newban->flags = BAN_BURSTED; /* set flags */
-           if ((ptr = strrchr(ban, '@')) && check_if_ipmask(ptr + 1))
-             newban->flags |= BAN_IPMASK;
-
+           newban->flags |= BAN_BURSTED;
            newban->next = 0;
            if (lp)
              lp->next = newban; /* link it in */
@@ -454,7 +466,12 @@ int ms_burst(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
            if (current_mode & CHFL_VOICE)
              nickstr[nickpos++] = 'v';
            if (current_mode & CHFL_CHANOP)
-             nickpos += ircd_snprintf(0, nickstr + nickpos, sizeof(nickstr) - nickpos, "%u", oplevel);
+            {
+              if (chptr->mode.apass[0])
+               nickpos += ircd_snprintf(0, nickstr + nickpos, sizeof(nickstr) - nickpos, "%u", oplevel);
+              else
+                nickstr[nickpos++] = 'o';
+            }
          } else if (current_mode & CHFL_CHANOP && oplevel != last_oplevel) { /* if just op level changed... */
            nickstr[nickpos++] = ':'; /* add a specifier */
            nickpos += ircd_snprintf(0, nickstr + nickpos, sizeof(nickstr) - nickpos, "%u", oplevel - last_oplevel);
@@ -477,7 +494,7 @@ int ms_burst(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
              member->status |= CHFL_BURST_ALREADY_VOICED;
            /* Synchronize with the burst. */
            member->status |= CHFL_BURST_JOINED | (current_mode & (CHFL_CHANOP|CHFL_VOICE));
-           member->oplevel = oplevel;
+           SetOpLevel(member, oplevel);
          }
        }
       }
@@ -506,16 +523,17 @@ int ms_burst(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     for (member = chptr->members; member; member = member->next_member) {
       if (member->status & CHFL_BURST_JOINED) { /* joined during burst */
        if ((member->status & CHFL_CHANOP) && !(member->status & CHFL_BURST_ALREADY_OPPED))
-         modebuf_mode_client(mbuf, MODE_ADD | CHFL_CHANOP, member->user);
+         modebuf_mode_client(mbuf, MODE_ADD | CHFL_CHANOP, member->user, OpLevel(member));
        if ((member->status & CHFL_VOICE) && !(member->status & CHFL_BURST_ALREADY_VOICED))
-         modebuf_mode_client(mbuf, MODE_ADD | CHFL_VOICE, member->user);
+         modebuf_mode_client(mbuf, MODE_ADD | CHFL_VOICE, member->user, OpLevel(member));
       } else if (parse_flags & MODE_PARSE_WIPEOUT) { /* wipeout old ops */
        if (member->status & CHFL_CHANOP)
-         modebuf_mode_client(mbuf, MODE_DEL | CHFL_CHANOP, member->user);
+         modebuf_mode_client(mbuf, MODE_DEL | CHFL_CHANOP, member->user, OpLevel(member));
        if (member->status & CHFL_VOICE)
-         modebuf_mode_client(mbuf, MODE_DEL | CHFL_VOICE, member->user);
-       member->status = ((member->status & ~(CHFL_CHANOP | CHFL_VOICE)) |
-                         CHFL_DEOPPED);
+         modebuf_mode_client(mbuf, MODE_DEL | CHFL_VOICE, member->user, OpLevel(member));
+       member->status = (member->status
+                          & ~(CHFL_CHANNEL_MANAGER | CHFL_CHANOP | CHFL_VOICE))
+                        | CHFL_DEOPPED;
       }
     }
 
@@ -526,9 +544,10 @@ int ms_burst(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 
       /* remove ban from channel */
       if (lp->flags & (BAN_OVERLAPPED | BAN_BURST_WIPEOUT)) {
+        char *bandup;
+        DupString(bandup, lp->banstr);
        modebuf_mode_string(mbuf, MODE_DEL | MODE_BAN,
-                           lp->banstr, 1); /* let it free banstr */
-        lp->banstr = NULL; /* do not free this string */
+                           bandup, 1);
        *lp_p = lp->next; /* clip out of list */
         free_ban(lp);
        continue;