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