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