]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_topic.c
Add operspy /topic.
[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
56 * parv[0] = sender prefix
57 * parv[1] = channel name
58 * parv[2] = new topic, if setting topic
59 */
60static int
61m_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
62{
63 struct Channel *chptr = NULL;
64 struct membership *msptr;
65 char *p = NULL;
73788f79
JT
66 const char *name;
67 int operspy = 0;
212380e3 68
69 if((p = strchr(parv[1], ',')))
70 *p = '\0';
71
73788f79
JT
72 name = parv[1];
73
74 if(IsOperSpy(source_p) && parv[1][0] == '!')
75 {
76 name++;
77 operspy = 1;
78
79 if(EmptyString(name))
80 {
81 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
82 me.name, source_p->name, "TOPIC");
83 return 0;
84 }
85 }
86
212380e3 87 if(MyClient(source_p) && !IsFloodDone(source_p))
88 flood_endgrace(source_p);
89
73788f79 90 if(!IsChannelName(name))
212380e3 91 {
92 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
73788f79 93 form_str(ERR_NOSUCHCHANNEL), name);
212380e3 94 return 0;
95 }
96
73788f79 97 chptr = find_channel(name);
212380e3 98
99 if(chptr == NULL)
100 {
101 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
73788f79 102 form_str(ERR_NOSUCHCHANNEL), name);
212380e3 103 return 0;
104 }
105
106 /* setting topic */
107 if(parc > 2)
108 {
109 msptr = find_channel_membership(chptr, source_p);
110
111 if(msptr == NULL)
112 {
113 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
73788f79 114 form_str(ERR_NOTONCHANNEL), name);
212380e3 115 return 0;
116 }
117
118 if((chptr->mode.mode & MODE_TOPICLIMIT) == 0 || is_chanop(msptr))
119 {
120 char topic_info[USERHOST_REPLYLEN];
581fa5c4 121 rb_sprintf(topic_info, "%s!%s@%s",
212380e3 122 source_p->name, source_p->username, source_p->host);
9f6bbe3c 123 set_channel_topic(chptr, parv[2], topic_info, rb_current_time());
212380e3 124
125 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
126 ":%s TOPIC %s :%s",
127 use_id(source_p), chptr->chname,
128 chptr->topic == NULL ? "" : chptr->topic);
212380e3 129 sendto_channel_local(ALL_MEMBERS,
130 chptr, ":%s!%s@%s TOPIC %s :%s",
131 source_p->name, source_p->username,
132 source_p->host, chptr->chname,
133 chptr->topic == NULL ? "" : chptr->topic);
134 }
135 else
136 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
73788f79 137 me.name, source_p->name, name);
212380e3 138 }
139 else if(MyClient(source_p))
140 {
73788f79
JT
141 if(operspy)
142 report_operspy(source_p, "TOPIC", chptr->chname);
143 if(!IsMember(source_p, chptr) && SecretChannel(chptr) &&
144 !operspy)
212380e3 145 {
146 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
73788f79 147 form_str(ERR_NOTONCHANNEL), name);
212380e3 148 return 0;
149 }
150 if(chptr->topic == NULL)
151 sendto_one(source_p, form_str(RPL_NOTOPIC),
73788f79 152 me.name, source_p->name, name);
212380e3 153 else
154 {
155 sendto_one(source_p, form_str(RPL_TOPIC),
156 me.name, source_p->name, chptr->chname, chptr->topic);
157
158 sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
159 me.name, source_p->name, chptr->chname,
160 chptr->topic_info, chptr->topic_time);
161 }
162 }
163
164 return 0;
165}
166
167/*
168 * ms_topic
169 * parv[0] = sender prefix
170 * parv[1] = channel name
171 * parv[2] = topic_info
172 * parv[3] = topic_info time
173 * parv[4] = new channel topic
174 *
175 * Let servers always set a topic
176 */
177static int
178ms_topic(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
179{
180 struct Channel *chptr = NULL;
181
182 if(IsChannelName(parv[1]))
183 {
184 if((chptr = find_channel(parv[1])) == NULL)
185 return 0;
186
187 set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3]));
188
189 sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s",
190 source_p->name, parv[1],
191 chptr->topic == NULL ? "" : chptr->topic);
192 }
193
194 return 0;
195}