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.
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
84 * No need to include handlers.h here the signatures must match
85 * and we don't need to force a rebuild of all the handlers everytime
86 * we add a new one to the list. --Bleep
94 #include "ircd_reply.h"
95 #include "ircd_string.h"
104 * m_topic - generic message handler
106 * parv[0] = sender prefix
108 * parv[parc - 1] = topic (if parc > 2)
110 int m_topic(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
112 struct Channel *chptr;
113 char *topic = 0, *name, *p = 0;
116 return need_more_params(sptr, "TOPIC");
119 topic = parv[parc - 1];
121 for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
124 if (!IsChannelName(name) || !(chptr = FindChannel(name)) ||
125 ((topic || SecretChannel(chptr)) && !find_channel_member(sptr, chptr)))
127 sendto_one(sptr, err_str(chptr ? ERR_NOTONCHANNEL : ERR_NOSUCHCHANNEL),
128 me.name, parv[0], chptr ? chptr->chname : name);
131 if (IsModelessChannel(name))
133 sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED), me.name, parv[0],
137 if (IsLocalChannel(name) && !MyUser(sptr))
140 if (!topic) /* only asking for topic */
142 if (chptr->topic[0] == '\0')
143 sendto_one(sptr, rpl_str(RPL_NOTOPIC), me.name, parv[0], chptr->chname);
146 sendto_one(sptr, rpl_str(RPL_TOPIC),
147 me.name, parv[0], chptr->chname, chptr->topic);
148 sendto_one(sptr, rpl_str(RPL_TOPICWHOTIME),
149 me.name, parv[0], chptr->chname,
150 chptr->topic_nick, chptr->topic_time);
153 else if (((chptr->mode.mode & MODE_TOPICLIMIT) == 0 ||
154 is_chan_op(sptr, chptr)) && topic)
156 /* setting a topic */
157 ircd_strncpy(chptr->topic, topic, TOPICLEN);
158 ircd_strncpy(chptr->topic_nick, sptr->name, NICKLEN);
159 chptr->topic_time = CurrentTime;
160 sendto_serv_butone(cptr, "%s%s " TOK_TOPIC " %s :%s",
161 NumNick(sptr), chptr->chname, chptr->topic);
162 sendto_channel_butserv(chptr, sptr, ":%s TOPIC %s :%s",
163 parv[0], chptr->chname, chptr->topic);
166 sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED),
167 me.name, parv[0], chptr->chname);
173 * ms_topic - server message handler
175 * parv[0] = sender prefix
177 * parv[parc - 1] = topic (if parc > 2)
179 int ms_topic(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
181 struct Channel *chptr;
182 char *topic = 0, *name, *p = 0;
185 return need_more_params(sptr, "TOPIC");
188 topic = parv[parc - 1];
190 for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
193 if (!IsChannelName(name) || !(chptr = FindChannel(name)) ||
194 ((topic || SecretChannel(chptr)) && !find_channel_member(sptr, chptr)))
196 sendto_one(sptr, err_str(chptr ? ERR_NOTONCHANNEL : ERR_NOSUCHCHANNEL),
197 me.name, parv[0], chptr ? chptr->chname : name);
200 if (IsModelessChannel(name))
202 sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED), me.name, parv[0],
206 if (IsLocalChannel(name) && !MyUser(sptr))
209 if (!topic) /* only asking for topic */
211 if (chptr->topic[0] == '\0')
212 sendto_one(sptr, rpl_str(RPL_NOTOPIC), me.name, parv[0], chptr->chname);
215 sendto_one(sptr, rpl_str(RPL_TOPIC),
216 me.name, parv[0], chptr->chname, chptr->topic);
217 sendto_one(sptr, rpl_str(RPL_TOPICWHOTIME),
218 me.name, parv[0], chptr->chname,
219 chptr->topic_nick, chptr->topic_time);
222 else if (((chptr->mode.mode & MODE_TOPICLIMIT) == 0 ||
223 is_chan_op(sptr, chptr)) && topic)
225 /* setting a topic */
226 ircd_strncpy(chptr->topic, topic, TOPICLEN);
227 ircd_strncpy(chptr->topic_nick, sptr->name, NICKLEN);
228 chptr->topic_time = CurrentTime;
229 sendto_serv_butone(cptr, "%s%s " TOK_TOPIC " %s :%s",
230 NumNick(sptr), chptr->chname, chptr->topic);
231 sendto_channel_butserv(chptr, sptr, ":%s TOPIC %s :%s",
232 parv[0], chptr->chname, chptr->topic);
235 sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED),
236 me.name, parv[0], chptr->chname);
246 * parv[0] = sender prefix
248 * parv[parc - 1] = topic (if parc > 2)
250 int m_topic(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
252 struct Channel *chptr;
253 char *topic = 0, *name, *p = 0;
256 return need_more_params(sptr, "TOPIC");
259 topic = parv[parc - 1];
261 for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0)
264 if (!IsChannelName(name) || !(chptr = FindChannel(name)) ||
265 ((topic || SecretChannel(chptr)) && !find_channel_member(sptr, chptr)))
267 sendto_one(sptr, err_str(chptr ? ERR_NOTONCHANNEL : ERR_NOSUCHCHANNEL),
268 me.name, parv[0], chptr ? chptr->chname : name);
271 if (IsModelessChannel(name))
273 sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED), me.name, parv[0],
277 if (IsLocalChannel(name) && !MyUser(sptr))
280 if (!topic) /* only asking for topic */
282 if (chptr->topic[0] == '\0')
283 sendto_one(sptr, rpl_str(RPL_NOTOPIC), me.name, parv[0], chptr->chname);
286 sendto_one(sptr, rpl_str(RPL_TOPIC),
287 me.name, parv[0], chptr->chname, chptr->topic);
288 sendto_one(sptr, rpl_str(RPL_TOPICWHOTIME),
289 me.name, parv[0], chptr->chname,
290 chptr->topic_nick, chptr->topic_time);
293 else if (((chptr->mode.mode & MODE_TOPICLIMIT) == 0 ||
294 is_chan_op(sptr, chptr)) && topic)
296 /* setting a topic */
297 ircd_strncpy(chptr->topic, topic, TOPICLEN);
298 ircd_strncpy(chptr->topic_nick, sptr->name, NICKLEN);
299 chptr->topic_time = CurrentTime;
300 sendto_serv_butone(cptr, "%s%s " TOK_TOPIC " %s :%s",
301 NumNick(sptr), chptr->chname, chptr->topic);
302 sendto_channel_butserv(chptr, sptr, ":%s TOPIC %s :%s",
303 parv[0], chptr->chname, chptr->topic);
306 sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED),
307 me.name, parv[0], chptr->chname);