]> jfr.im git - solanum.git/blame - modules/m_topic.c
modules: Add AV2 descriptions to all m_s* modules
[solanum.git] / modules / m_topic.c
CommitLineData
212380e3
AC
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
212380e3
AC
23 */
24
25#include "stdinc.h"
212380e3
AC
26#include "channel.h"
27#include "client.h"
28#include "hash.h"
4562c604 29#include "match.h"
212380e3
AC
30#include "ircd.h"
31#include "numeric.h"
32#include "send.h"
41615da9 33#include "s_newconf.h"
212380e3
AC
34#include "s_conf.h"
35#include "s_serv.h"
36#include "msg.h"
37#include "parse.h"
38#include "modules.h"
39#include "packet.h"
717238d2 40#include "tgchange.h"
77d3d2db 41#include "logger.h"
633531a4 42#include "inline/stringops.h"
212380e3 43
428ca87b
AC
44static int m_topic(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
45static int ms_topic(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
46
47struct Message topic_msgtab = {
7baa37a9 48 "TOPIC", 0, 0, 0, 0,
212380e3
AC
49 {mg_unreg, {m_topic, 2}, {m_topic, 2}, {ms_topic, 5}, mg_ignore, {m_topic, 2}}
50};
51
52mapi_clist_av1 topic_clist[] = { &topic_msgtab, NULL };
105a4985 53DECLARE_MODULE_AV2(topic, NULL, NULL, topic_clist, NULL, NULL, NULL, NULL, NULL);
212380e3
AC
54
55/*
56 * m_topic
212380e3
AC
57 * parv[1] = channel name
58 * parv[2] = new topic, if setting topic
59 */
60static int
428ca87b 61m_topic(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
62{
63 struct Channel *chptr = NULL;
64 struct membership *msptr;
65 char *p = NULL;
41615da9
JT
66 const char *name;
67 int operspy = 0;
212380e3
AC
68
69 if((p = strchr(parv[1], ',')))
70 *p = '\0';
71
41615da9
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
AC
87 if(MyClient(source_p) && !IsFloodDone(source_p))
88 flood_endgrace(source_p);
89
41615da9 90 chptr = find_channel(name);
212380e3
AC
91
92 if(chptr == NULL)
93 {
94 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
41615da9 95 form_str(ERR_NOSUCHCHANNEL), name);
212380e3
AC
96 return 0;
97 }
98
99 /* setting topic */
100 if(parc > 2)
101 {
102 msptr = find_channel_membership(chptr, source_p);
103
104 if(msptr == NULL)
105 {
106 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
41615da9 107 form_str(ERR_NOTONCHANNEL), name);
212380e3
AC
108 return 0;
109 }
110
717238d2
JT
111 if(MyClient(source_p) && !is_chanop_voiced(msptr) &&
112 !IsOper(source_p) &&
113 !add_channel_target(source_p, chptr))
114 {
115 sendto_one(source_p, form_str(ERR_TARGCHANGE),
116 me.name, source_p->name, chptr->chname);
117 return 0;
118 }
119
406478d2 120 if(((chptr->mode.mode & MODE_TOPICLIMIT) == 0 ||
3ee43bcf 121 get_channel_access(source_p, chptr, msptr, MODE_ADD, NULL) >= CHFL_CHANOP) &&
406478d2
JT
122 (!MyClient(source_p) ||
123 can_send(chptr, source_p, msptr)))
212380e3 124 {
633531a4 125 char topic[TOPICLEN + 1];
212380e3 126 char topic_info[USERHOST_REPLYLEN];
633531a4 127 rb_strlcpy(topic, parv[2], sizeof(topic));
5203cba5 128 sprintf(topic_info, "%s!%s@%s",
212380e3 129 source_p->name, source_p->username, source_p->host);
633531a4
AC
130
131 if (ConfigChannel.strip_topic_colors)
132 strip_colour(topic);
133
134 set_channel_topic(chptr, topic, topic_info, rb_current_time());
212380e3
AC
135
136 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
137 ":%s TOPIC %s :%s",
138 use_id(source_p), chptr->chname,
139 chptr->topic == NULL ? "" : chptr->topic);
212380e3
AC
140 sendto_channel_local(ALL_MEMBERS,
141 chptr, ":%s!%s@%s TOPIC %s :%s",
142 source_p->name, source_p->username,
143 source_p->host, chptr->chname,
144 chptr->topic == NULL ? "" : chptr->topic);
145 }
146 else
147 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
631b4a54
JT
148 get_id(&me, source_p),
149 get_id(source_p, source_p), name);
212380e3
AC
150 }
151 else if(MyClient(source_p))
152 {
41615da9
JT
153 if(operspy)
154 report_operspy(source_p, "TOPIC", chptr->chname);
155 if(!IsMember(source_p, chptr) && SecretChannel(chptr) &&
156 !operspy)
212380e3
AC
157 {
158 sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
41615da9 159 form_str(ERR_NOTONCHANNEL), name);
212380e3
AC
160 return 0;
161 }
162 if(chptr->topic == NULL)
163 sendto_one(source_p, form_str(RPL_NOTOPIC),
41615da9 164 me.name, source_p->name, name);
212380e3
AC
165 else
166 {
167 sendto_one(source_p, form_str(RPL_TOPIC),
168 me.name, source_p->name, chptr->chname, chptr->topic);
169
170 sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
171 me.name, source_p->name, chptr->chname,
0cce01d3
JT
172 chptr->topic_info,
173 (unsigned long)chptr->topic_time);
212380e3
AC
174 }
175 }
176
177 return 0;
178}
179
180/*
181 * ms_topic
212380e3
AC
182 * parv[1] = channel name
183 * parv[2] = topic_info
184 * parv[3] = topic_info time
185 * parv[4] = new channel topic
186 *
187 * Let servers always set a topic
188 */
189static int
428ca87b 190ms_topic(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
191{
192 struct Channel *chptr = NULL;
193
0941f28e
JT
194 if((chptr = find_channel(parv[1])) == NULL)
195 return 0;
212380e3 196
0941f28e 197 set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3]));
212380e3 198
0941f28e 199 sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s",
55abcbb2 200 source_p->name, parv[1],
0941f28e 201 chptr->topic == NULL ? "" : chptr->topic);
212380e3
AC
202
203 return 0;
204}