2 * IRC - Internet Relay Chat, ircd/m_topic.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include "ircd_features.h"
34 #include "ircd_reply.h"
35 #include "ircd_string.h"
41 /* #include <assert.h> -- Now using assert in ircd_log.h */
42 #include <stdlib.h> /* for atoi() */
44 /** Set a channel topic or report an error.
45 * @param[in] sptr Original topic setter.
46 * @param[in] cptr Neighbor that sent the topic message.
47 * @param[in] chptr Channel to set topic on.
48 * @param[in] topic New topic.
49 * @param[in] ts Timestamp that topic was set (0 for current time).
51 static void do_settopic(struct Client *sptr, struct Client *cptr,
52 struct Channel *chptr, char *topic, time_t ts)
57 if (feature_bool(FEAT_HIS_BANWHO) && IsServer(sptr))
61 /* Note if this is just a refresh of an old topic, and don't
62 * send it to all the clients to save bandwidth. We still send
63 * it to other servers as they may have split and lost the topic.
65 newtopic=ircd_strncmp(chptr->topic,topic,TOPICLEN)!=0;
67 ircd_strncpy(chptr->topic, topic, TOPICLEN);
68 ircd_strncpy(chptr->topic_nick, cli_name(from), NICKLEN);
69 chptr->topic_time = ts ? ts : TStime();
70 /* Fixed in 2.10.11: Don't propagate local topics */
71 if (!IsLocalChannel(chptr->chname))
72 sendcmdto_serv_butone(sptr, CMD_TOPIC, cptr, "%H %Tu %Tu :%s", chptr,
73 chptr->creationtime, chptr->topic_time, chptr->topic);
76 struct Membership *member;
78 /* If the member is delayed-join, show them. */
79 member = find_channel_member(sptr, chptr);
80 if (member && IsDelayedJoin(member))
81 RevealDelayedJoin(member);
83 sendcmdto_channel_butserv_butone(from, CMD_TOPIC, chptr, NULL, 0,
84 "%H :%s", chptr, chptr->topic);
86 /* if this is the same topic as before we send it to the person that
87 * set it (so they knew it went through ok), but don't bother sending
88 * it to everyone else on the channel to save bandwidth
90 else if (MyUser(sptr))
91 sendcmdto_one(sptr, CMD_TOPIC, sptr, "%H :%s", chptr, chptr->topic);
94 /** Handle a local user's attempt to get or set a channel topic.
96 * \a parv has the following elements:
97 * \li \a parv[1] is the channel name
98 * \li \a parv[\a parc - 1] is the topic (if \a parc > 2)
100 * See @ref m_functions for discussion of the arguments.
101 * @param[in] cptr Client that sent us the message.
102 * @param[in] sptr Original source of message.
103 * @param[in] parc Number of arguments.
104 * @param[in] parv Argument vector.
106 int m_topic(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
108 struct Channel *chptr;
109 char *topic = 0, *name, *p = 0;
112 return need_more_params(sptr, "TOPIC");
115 topic = parv[parc - 1];
117 for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
120 /* Does the channel exist */
121 if (!IsChannelName(name) || !(chptr = FindChannel(name)))
123 send_reply(sptr,ERR_NOSUCHCHANNEL,name);
126 /* Trying to check a topic outside a secret channel */
127 if ((topic || SecretChannel(chptr)) && !find_channel_member(sptr, chptr))
129 send_reply(sptr, ERR_NOTONCHANNEL, chptr->chname);
133 /* only asking for topic */
136 if (chptr->topic[0] == '\0')
137 send_reply(sptr, RPL_NOTOPIC, chptr->chname);
140 send_reply(sptr, RPL_TOPIC, chptr->chname, chptr->topic);
141 send_reply(sptr, RPL_TOPICWHOTIME, chptr->chname, chptr->topic_nick,
145 else if ((chptr->mode.mode & MODE_TOPICLIMIT) && !is_chan_op(sptr, chptr))
146 send_reply(sptr, ERR_CHANOPRIVSNEEDED, chptr->chname);
147 else if (!client_can_send_to_channel(sptr, chptr, 1))
148 send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
150 do_settopic(sptr,cptr,chptr,topic,0);
155 /** Handle a remote user's attempt to set a channel topic.
156 * \a parv has the following elements:
157 * \li \a parv[1] is the channel name
158 * \li \a parv[2] is the channel creation timestamp (optional)
159 * \li \a parv[2] is the topic's timestamp (optional)
160 * \li \a parv[\a parc - 1] is the topic
162 * See @ref m_functions for discussion of the arguments.
163 * @param[in] cptr Client that sent us the message.
164 * @param[in] sptr Original source of message.
165 * @param[in] parc Number of arguments.
166 * @param[in] parv Argument vector.
168 int ms_topic(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
170 struct Channel *chptr;
171 char *topic = 0, *name, *p = 0;
175 return need_more_params(sptr, "TOPIC");
177 topic = parv[parc - 1];
179 for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
182 /* Does the channel exist */
183 if (!IsChannelName(name) || !(chptr = FindChannel(name)))
185 send_reply(sptr,ERR_NOSUCHCHANNEL,name);
189 /* Ignore requests for topics from remote servers */
190 if (IsLocalChannel(name) && !MyUser(sptr))
192 protocol_violation(sptr,"Topic request");
196 /* If existing channel is older or has newer topic, ignore */
197 if (parc > 3 && (ts = atoi(parv[2])) && chptr->creationtime < ts)
200 ts = 0; /* Default to the current time if no topic_time is passed. */
201 if (parc > 4 && (ts = atoi(parv[3])) && chptr->topic_time > ts)
204 do_settopic(sptr,cptr,chptr,topic, ts);