]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_topic.c
Update TODO
[irc/rqf/shadowircd.git] / modules / m_topic.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_topic.c: Sets a channel topic.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
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 2 of the License, or
12 * (at your option) any later version.
13 *
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.
18 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
24 * $Id: m_topic.c 254 2005-09-21 23:35:12Z nenolod $
25 */
26
27#include "stdinc.h"
212380e3 28#include "channel.h"
29#include "client.h"
30#include "hash.h"
13ae2f4b 31#include "match.h"
212380e3 32#include "ircd.h"
33#include "numeric.h"
34#include "send.h"
73788f79 35#include "s_newconf.h"
212380e3 36#include "s_conf.h"
37#include "s_serv.h"
38#include "msg.h"
39#include "parse.h"
40#include "modules.h"
41#include "packet.h"
42
43static int m_topic(struct Client *, struct Client *, int, const char **);
44static int ms_topic(struct Client *, struct Client *, int, const char **);
45
46struct Message topic_msgtab = {
47 "TOPIC", 0, 0, 0, MFLG_SLOW,
48 {mg_unreg, {m_topic, 2}, {m_topic, 2}, {ms_topic, 5}, mg_ignore, {m_topic, 2}}
49};
50
51mapi_clist_av1 topic_clist[] = { &topic_msgtab, NULL };
52DECLARE_MODULE_AV1(topic, NULL, NULL, topic_clist, NULL, NULL, "$Revision: 254 $");
53
54/*
55 * m_topic
212380e3 56 * parv[1] = channel name
57 * parv[2] = new topic, if setting topic
58 */
59static int
60m_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
61{
62 struct Channel *chptr = NULL;
63 struct membership *msptr;
64 char *p = NULL;
73788f79
JT
65 const char *name;
66 int operspy = 0;
212380e3 67
68 if((p = strchr(parv[1], ',')))
69 *p = '\0';
70
73788f79
JT
71 name = parv[1];
72
73 if(IsOperSpy(source_p) && parv[1][0] == '!')
74 {
75 name++;
76 operspy = 1;
77
78 if(EmptyString(name))
79 {
80 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
81 me.name, source_p->name, "TOPIC");
82 return 0;
83 }
84 }
85
212380e3 86 if(MyClient(source_p) && !IsFloodDone(source_p))
87 flood_endgrace(source_p);
88
73788f79 89 if(!IsChannelName(name))
212380e3 90 {
91 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
73788f79 92 form_str(ERR_NOSUCHCHANNEL), name);
212380e3 93 return 0;
94 }
95
73788f79 96 chptr = find_channel(name);
212380e3 97
98 if(chptr == NULL)
99 {
100 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
73788f79 101 form_str(ERR_NOSUCHCHANNEL), name);
212380e3 102 return 0;
103 }
104
105 /* setting topic */
106 if(parc > 2)
107 {
c6fa5506
JH
108 char topic_info[USERHOST_REPLYLEN];
109
212380e3 110 msptr = find_channel_membership(chptr, source_p);
111
112 if(msptr == NULL)
113 {
114 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
73788f79 115 form_str(ERR_NOTONCHANNEL), name);
212380e3 116 return 0;
117 }
118
c6fa5506 119 if(MyClient(source_p) && (chptr->mode.mode & MODE_TOPICLIMIT) && !is_chanop(msptr))
212380e3 120 {
c6fa5506 121 if(IsOverride(source_p))
34d8ef4d
JH
122 {
123 sendto_wallops_flags(UMODE_WALLOP, &me,
c6fa5506
JH
124 "%s is overriding TOPIC on [%s]",
125 get_oper_name(source_p), chptr->chname);
34d8ef4d
JH
126 sendto_server(NULL, chptr, NOCAPS, NOCAPS,
127 ":%s WALLOPS :%s is overriding TOPIC on [%s]",
71ea6069 128 me.name, get_oper_name(source_p), chptr->chname);
34d8ef4d 129 }
c6fa5506
JH
130 else
131 {
132 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
133 me.name, source_p->name, parv[1]);
134 return 0;
135 }
136
137 }
45b9f1cb
JH
138
139 if(ConfigChannel.host_in_topic)
140 rb_sprintf(topic_info, "%s!%s@%s",
141 source_p->name, source_p->username, source_p->host);
142 else
143 rb_strlcpy(topic_info, source_p->name, sizeof(topic_info));
144
9f6bbe3c 145 set_channel_topic(chptr, parv[2], topic_info, rb_current_time());
212380e3 146
147 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
148 ":%s TOPIC %s :%s",
149 use_id(source_p), chptr->chname,
150 chptr->topic == NULL ? "" : chptr->topic);
212380e3 151 sendto_channel_local(ALL_MEMBERS,
152 chptr, ":%s!%s@%s TOPIC %s :%s",
153 source_p->name, source_p->username,
154 source_p->host, chptr->chname,
155 chptr->topic == NULL ? "" : chptr->topic);
c6fa5506 156
212380e3 157 }
158 else if(MyClient(source_p))
159 {
73788f79
JT
160 if(operspy)
161 report_operspy(source_p, "TOPIC", chptr->chname);
162 if(!IsMember(source_p, chptr) && SecretChannel(chptr) &&
163 !operspy)
212380e3 164 {
165 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
73788f79 166 form_str(ERR_NOTONCHANNEL), name);
212380e3 167 return 0;
168 }
169 if(chptr->topic == NULL)
170 sendto_one(source_p, form_str(RPL_NOTOPIC),
73788f79 171 me.name, source_p->name, name);
212380e3 172 else
173 {
174 sendto_one(source_p, form_str(RPL_TOPIC),
175 me.name, source_p->name, chptr->chname, chptr->topic);
176
177 sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
178 me.name, source_p->name, chptr->chname,
179 chptr->topic_info, chptr->topic_time);
180 }
181 }
182
183 return 0;
184}
185
186/*
187 * ms_topic
212380e3 188 * parv[1] = channel name
189 * parv[2] = topic_info
190 * parv[3] = topic_info time
191 * parv[4] = new channel topic
192 *
193 * Let servers always set a topic
194 */
195static int
196ms_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
197{
198 struct Channel *chptr = NULL;
199
200 if(IsChannelName(parv[1]))
201 {
202 if((chptr = find_channel(parv[1])) == NULL)
203 return 0;
204
205 set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3]));
206
207 sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s",
208 source_p->name, parv[1],
209 chptr->topic == NULL ? "" : chptr->topic);
210 }
211
212 return 0;
213}