- struct Channel *chptr;
- char *topic = 0, *name, *p = 0;
-
- if (parc < 2)
- return need_more_params(sptr, "TOPIC");
-
- if (parc > 2)
- topic = parv[parc - 1];
-
- for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
- {
- chptr = 0;
- if (!IsChannelName(name) || !(chptr = FindChannel(name)) ||
- ((topic || SecretChannel(chptr)) && !find_channel_member(sptr, chptr)))
- {
- sendto_one(sptr, err_str(chptr ? ERR_NOTONCHANNEL : ERR_NOSUCHCHANNEL),
- me.name, parv[0], chptr ? chptr->chname : name);
- continue;
- }
- if (IsModelessChannel(name))
- {
- sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED), me.name, parv[0],
- chptr->chname);
- continue;
- }
- if (IsLocalChannel(name) && !MyUser(sptr))
- continue;
-
- if (!topic) /* only asking for topic */
- {
- if (chptr->topic[0] == '\0')
- sendto_one(sptr, rpl_str(RPL_NOTOPIC), me.name, parv[0], chptr->chname);
- else
- {
- sendto_one(sptr, rpl_str(RPL_TOPIC),
- me.name, parv[0], chptr->chname, chptr->topic);
- sendto_one(sptr, rpl_str(RPL_TOPICWHOTIME),
- me.name, parv[0], chptr->chname,
- chptr->topic_nick, chptr->topic_time);
- }
- }
- else if (((chptr->mode.mode & MODE_TOPICLIMIT) == 0 ||
- is_chan_op(sptr, chptr)) && topic)
- {
- /* setting a topic */
- ircd_strncpy(chptr->topic, topic, TOPICLEN);
- ircd_strncpy(chptr->topic_nick, sptr->name, NICKLEN);
- chptr->topic_time = CurrentTime;
- sendto_serv_butone(cptr, "%s%s " TOK_TOPIC " %s :%s",
- NumNick(sptr), chptr->chname, chptr->topic);
- sendto_channel_butserv(chptr, sptr, ":%s TOPIC %s :%s",
- parv[0], chptr->chname, chptr->topic);
- }
- else
- sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED),
- me.name, parv[0], chptr->chname);
- }
- return 0;
+ struct Client *from;
+ int newtopic;
+
+ if (feature_bool(FEAT_HIS_BANWHO) && IsServer(sptr))
+ from = &his;
+ else
+ from = sptr;
+ /* Note if this is just a refresh of an old topic, and don't
+ * send it to all the clients to save bandwidth. We still send
+ * it to other servers as they may have split and lost the topic.
+ */
+ newtopic=ircd_strncmp(chptr->topic,topic,TOPICLEN)!=0;
+ /* setting a topic */
+ ircd_strncpy(chptr->topic, topic, TOPICLEN);
+ ircd_strncpy(chptr->topic_nick, cli_name(from), NICKLEN);
+ chptr->topic_time = ts ? ts : TStime();
+ /* Fixed in 2.10.11: Don't propagate local topics */
+ if (!IsLocalChannel(chptr->chname))
+ sendcmdto_serv_butone(sptr, CMD_TOPIC, cptr, "%H %Tu %Tu :%s", chptr,
+ chptr->creationtime, chptr->topic_time, chptr->topic);
+ if (newtopic)
+ {
+ struct Membership *member;
+
+ /* If the member is delayed-join, show them. */
+ member = find_channel_member(sptr, chptr);
+ if (member && IsDelayedJoin(member))
+ RevealDelayedJoin(member);
+
+ sendcmdto_channel_butserv_butone(from, CMD_TOPIC, chptr, NULL, 0,
+ "%H :%s", chptr, chptr->topic);
+ }
+ /* if this is the same topic as before we send it to the person that
+ * set it (so they knew it went through ok), but don't bother sending
+ * it to everyone else on the channel to save bandwidth
+ */
+ else if (MyUser(sptr))
+ sendcmdto_one(sptr, CMD_TOPIC, sptr, "%H :%s", chptr, chptr->topic);