1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_topic.c: Sets a channel topic. |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
|
|
* USA |
21 |
|
|
* |
22 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
|
|
#include "tools.h" |
27 |
|
|
#include "handlers.h" |
28 |
|
|
#include "channel.h" |
29 |
|
|
#include "channel_mode.h" |
30 |
|
|
#include "client.h" |
31 |
|
|
#include "hash.h" |
32 |
|
|
#include "irc_string.h" |
33 |
|
|
#include "sprintf_irc.h" |
34 |
|
|
#include "ircd.h" |
35 |
|
|
#include "numeric.h" |
36 |
|
|
#include "send.h" |
37 |
|
|
#include "s_conf.h" |
38 |
|
|
#include "s_serv.h" |
39 |
|
|
#include "msg.h" |
40 |
|
|
#include "parse.h" |
41 |
|
|
#include "modules.h" |
42 |
|
|
#include "packet.h" |
43 |
|
|
#include "common.h" |
44 |
|
|
|
45 |
|
|
static void m_topic(struct Client *, struct Client *, int, char **); |
46 |
|
|
static void ms_topic(struct Client *, struct Client *, int, char **); |
47 |
|
|
|
48 |
|
|
struct Message topic_msgtab = { |
49 |
|
|
"TOPIC", 0, 0, 2, 0, MFLG_SLOW, 0, |
50 |
|
|
{m_unregistered, m_topic, ms_topic, m_ignore, m_topic, m_ignore} |
51 |
|
|
}; |
52 |
|
|
|
53 |
|
|
#ifndef STATIC_MODULES |
54 |
|
|
void |
55 |
|
|
_modinit(void) |
56 |
|
|
{ |
57 |
|
|
mod_add_cmd(&topic_msgtab); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
void |
61 |
|
|
_moddeinit(void) |
62 |
|
|
{ |
63 |
|
|
mod_del_cmd(&topic_msgtab); |
64 |
|
|
} |
65 |
|
|
|
66 |
knight |
31 |
const char *_version = "$Revision$"; |
67 |
adx |
30 |
#endif |
68 |
|
|
|
69 |
|
|
/* m_topic() |
70 |
|
|
* parv[0] = sender prefix |
71 |
|
|
* parv[1] = channel name |
72 |
|
|
* parv[2] = new topic, if setting topic |
73 |
|
|
*/ |
74 |
|
|
static void |
75 |
|
|
m_topic(struct Client *client_p, struct Client *source_p, |
76 |
|
|
int parc, char *parv[]) |
77 |
|
|
{ |
78 |
|
|
struct Channel *chptr = NULL; |
79 |
|
|
char *p; |
80 |
|
|
struct Membership *ms; |
81 |
|
|
const char *from, *to; |
82 |
|
|
|
83 |
|
|
if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p)) |
84 |
|
|
{ |
85 |
|
|
from = me.id; |
86 |
|
|
to = source_p->id; |
87 |
|
|
} |
88 |
|
|
else |
89 |
|
|
{ |
90 |
|
|
from = me.name; |
91 |
|
|
to = source_p->name; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
if ((p = strchr(parv[1], ',')) != NULL) |
95 |
|
|
*p = '\0'; |
96 |
|
|
|
97 |
|
|
if (parv[1][0] == '\0') |
98 |
|
|
{ |
99 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
100 |
|
|
from, to, "TOPIC"); |
101 |
|
|
return; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
if (MyClient(source_p) && !IsFloodDone(source_p)) |
105 |
|
|
flood_endgrace(source_p); |
106 |
|
|
|
107 |
|
|
if (IsChanPrefix(*parv[1])) |
108 |
|
|
{ |
109 |
|
|
if ((chptr = hash_find_channel(parv[1])) == NULL) |
110 |
|
|
{ |
111 |
|
|
/* if chptr isn't found locally, it =could= exist |
112 |
|
|
* on the uplink. so forward reqeuest |
113 |
|
|
*/ |
114 |
|
|
if (!ServerInfo.hub && uplink && IsCapable(uplink, CAP_LL)) |
115 |
|
|
{ |
116 |
|
|
sendto_one(uplink, ":%s TOPIC %s %s", |
117 |
|
|
ID_or_name(source_p, uplink), chptr->chname, |
118 |
|
|
((parc > 2) ? parv[2] : "")); |
119 |
|
|
return; |
120 |
|
|
} |
121 |
|
|
else |
122 |
|
|
{ |
123 |
|
|
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
124 |
|
|
from, to, parv[1]); |
125 |
|
|
return; |
126 |
|
|
} |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
/* setting topic */ |
130 |
|
|
if (parc > 2) |
131 |
|
|
{ |
132 |
|
|
if ((ms = find_channel_link(source_p, chptr)) == NULL) |
133 |
|
|
{ |
134 |
|
|
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), from, |
135 |
|
|
to, parv[1]); |
136 |
|
|
return; |
137 |
|
|
} |
138 |
|
|
if ((chptr->mode.mode & MODE_TOPICLIMIT) == 0 || |
139 |
|
|
has_member_flags(ms, CHFL_CHANOP|CHFL_HALFOP)) |
140 |
|
|
{ |
141 |
|
|
char topic_info[USERHOST_REPLYLEN]; |
142 |
|
|
ircsprintf(topic_info, "%s!%s@%s", |
143 |
|
|
source_p->name, source_p->username, source_p->host); |
144 |
|
|
set_channel_topic(chptr, parv[2], topic_info, CurrentTime); |
145 |
|
|
|
146 |
|
|
sendto_server(client_p, NULL, chptr, CAP_TS6, NOCAPS, NOFLAGS, |
147 |
|
|
":%s TOPIC %s :%s", |
148 |
|
|
ID(source_p), chptr->chname, |
149 |
|
|
chptr->topic == NULL ? "" : chptr->topic); |
150 |
|
|
sendto_server(client_p, NULL, chptr, NOCAPS, CAP_TS6, NOFLAGS, |
151 |
|
|
":%s TOPIC %s :%s", |
152 |
|
|
source_p->name, chptr->chname, |
153 |
|
|
chptr->topic == NULL ? "" : chptr->topic); |
154 |
|
|
sendto_channel_local(ALL_MEMBERS, NO, |
155 |
|
|
chptr, ":%s!%s@%s TOPIC %s :%s", |
156 |
|
|
source_p->name, |
157 |
|
|
source_p->username, |
158 |
|
|
source_p->host, |
159 |
|
|
chptr->chname, chptr->topic == NULL ? |
160 |
|
|
"" : chptr->topic); |
161 |
|
|
} |
162 |
|
|
else |
163 |
|
|
sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), |
164 |
|
|
from, to, chptr->chname); |
165 |
|
|
} |
166 |
|
|
else /* only asking for topic */ |
167 |
|
|
{ |
168 |
|
|
if (!SecretChannel(chptr) || IsMember(source_p, chptr)) |
169 |
|
|
{ |
170 |
|
|
if (chptr->topic == NULL) |
171 |
|
|
sendto_one(source_p, form_str(RPL_NOTOPIC), |
172 |
|
|
from, to, chptr->chname); |
173 |
|
|
else |
174 |
|
|
{ |
175 |
|
|
sendto_one(source_p, form_str(RPL_TOPIC), |
176 |
|
|
from, to, |
177 |
|
|
chptr->chname, chptr->topic); |
178 |
|
|
|
179 |
|
|
/* client on LL needing the topic - if we have serverhide, say |
180 |
|
|
* its the actual LL server that set the topic, not us the |
181 |
|
|
* uplink -- fl_ |
182 |
|
|
*/ |
183 |
|
|
if (ConfigServerHide.hide_servers && !MyClient(source_p) |
184 |
|
|
&& IsCapable(client_p, CAP_LL) && ServerInfo.hub) |
185 |
|
|
{ |
186 |
|
|
sendto_one(source_p, form_str(RPL_TOPICWHOTIME), |
187 |
|
|
from, to, chptr->chname, |
188 |
|
|
client_p->name, chptr->topic_time); |
189 |
|
|
} |
190 |
|
|
else |
191 |
|
|
{ |
192 |
|
|
sendto_one(source_p, form_str(RPL_TOPICWHOTIME), |
193 |
|
|
from, to, chptr->chname, |
194 |
|
|
chptr->topic_info, |
195 |
|
|
chptr->topic_time); |
196 |
|
|
} |
197 |
|
|
} |
198 |
|
|
} |
199 |
|
|
else |
200 |
|
|
{ |
201 |
|
|
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
202 |
|
|
from, to, chptr->chname); |
203 |
|
|
return; |
204 |
|
|
} |
205 |
|
|
} |
206 |
|
|
} |
207 |
|
|
else |
208 |
|
|
{ |
209 |
|
|
sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL), |
210 |
|
|
from, to, parv[1]); |
211 |
|
|
} |
212 |
|
|
} |
213 |
|
|
|
214 |
|
|
/* |
215 |
|
|
* ms_topic |
216 |
|
|
* parv[0] = sender prefix |
217 |
|
|
* parv[1] = channel name |
218 |
|
|
* parv[2] = topic_info |
219 |
|
|
* parv[3] = topic_info time |
220 |
|
|
* parv[4] = new channel topic |
221 |
|
|
* |
222 |
|
|
* Let servers always set a topic |
223 |
|
|
*/ |
224 |
|
|
static void |
225 |
|
|
ms_topic(struct Client *client_p, struct Client *source_p, |
226 |
|
|
int parc, char *parv[]) |
227 |
|
|
{ |
228 |
|
|
struct Channel *chptr = NULL; |
229 |
|
|
|
230 |
|
|
if (!IsServer(source_p)) |
231 |
|
|
{ |
232 |
|
|
m_topic(client_p, source_p, parc, parv); |
233 |
|
|
return; |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
if (parc < 5) |
237 |
|
|
return; |
238 |
|
|
|
239 |
|
|
if (parv[1] && IsChanPrefix(*parv[1])) |
240 |
|
|
{ |
241 |
|
|
if ((chptr = hash_find_channel(parv[1])) == NULL) |
242 |
|
|
return; |
243 |
|
|
|
244 |
|
|
set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3])); |
245 |
|
|
|
246 |
|
|
if (ConfigServerHide.hide_servers) |
247 |
|
|
{ |
248 |
|
|
sendto_channel_local(ALL_MEMBERS, NO, |
249 |
|
|
chptr, ":%s TOPIC %s :%s", |
250 |
|
|
me.name, chptr->chname, |
251 |
|
|
chptr->topic == NULL ? "" : chptr->topic); |
252 |
|
|
|
253 |
|
|
} |
254 |
|
|
else |
255 |
|
|
{ |
256 |
|
|
sendto_channel_local(ALL_MEMBERS, NO, |
257 |
|
|
chptr, ":%s TOPIC %s :%s", |
258 |
|
|
source_p->name, |
259 |
|
|
chptr->chname, chptr->topic == NULL ? "" : chptr->topic); |
260 |
|
|
} |
261 |
|
|
} |
262 |
|
|
} |