1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
5346 |
* Copyright (c) 1997-2015 ircd-hybrid development team |
5 |
adx |
30 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
michael |
4564 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2820 |
/*! \file m_message.c |
23 |
|
|
* \brief Includes required functions for processing the PRIVMSG/NOTICE command. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
adx |
30 |
#include "client.h" |
30 |
|
|
#include "ircd.h" |
31 |
|
|
#include "numeric.h" |
32 |
michael |
1309 |
#include "conf.h" |
33 |
michael |
3347 |
#include "server.h" |
34 |
adx |
30 |
#include "send.h" |
35 |
|
|
#include "parse.h" |
36 |
|
|
#include "modules.h" |
37 |
|
|
#include "channel.h" |
38 |
|
|
#include "channel_mode.h" |
39 |
|
|
#include "irc_string.h" |
40 |
|
|
#include "hash.h" |
41 |
|
|
#include "packet.h" |
42 |
|
|
|
43 |
michael |
1243 |
|
44 |
michael |
3774 |
enum |
45 |
|
|
{ |
46 |
|
|
PRIVMSG = 0, |
47 |
|
|
NOTICE = 1 |
48 |
|
|
}; |
49 |
michael |
2796 |
|
50 |
michael |
3774 |
enum |
51 |
|
|
{ |
52 |
|
|
ENTITY_NONE = 0, |
53 |
|
|
ENTITY_CHANNEL = 1, |
54 |
michael |
5455 |
ENTITY_CLIENT = 2 |
55 |
michael |
3774 |
}; |
56 |
michael |
2796 |
|
57 |
michael |
4084 |
static struct |
58 |
adx |
30 |
{ |
59 |
|
|
void *ptr; |
60 |
michael |
5455 |
unsigned int type; |
61 |
|
|
unsigned int flags; |
62 |
michael |
2786 |
} targets[IRCD_BUFSIZE]; |
63 |
adx |
30 |
|
64 |
michael |
3283 |
static int unsigned ntargets = 0; |
65 |
michael |
2786 |
|
66 |
|
|
|
67 |
adx |
30 |
/* |
68 |
|
|
** m_privmsg |
69 |
|
|
** |
70 |
|
|
** massive cleanup |
71 |
|
|
** rev argv 6/91 |
72 |
|
|
** |
73 |
|
|
** Another massive cleanup Nov, 2000 |
74 |
|
|
** (I don't think there is a single line left from 6/91. Maybe.) |
75 |
|
|
** m_privmsg and m_notice do basically the same thing. |
76 |
|
|
** in the original 2.8.2 code base, they were the same function |
77 |
|
|
** "m_message.c." When we did the great cleanup in conjuncton with bleep |
78 |
|
|
** of ircu fame, we split m_privmsg.c and m_notice.c. |
79 |
michael |
4299 |
** I don't see the point of that now. It's harder to maintain, it's |
80 |
adx |
30 |
** easier to introduce bugs into one version and not the other etc. |
81 |
|
|
** Really, the penalty of an extra function call isn't that big a deal folks. |
82 |
|
|
** -db Nov 13, 2000 |
83 |
|
|
** |
84 |
|
|
*/ |
85 |
|
|
|
86 |
michael |
2796 |
/* duplicate_ptr() |
87 |
|
|
* |
88 |
|
|
* inputs - pointer to check |
89 |
|
|
* - pointer to table of entities |
90 |
|
|
* - number of valid entities so far |
91 |
|
|
* output - YES if duplicate pointer in table, NO if not. |
92 |
|
|
* note, this does the canonize using pointers |
93 |
|
|
* side effects - NONE |
94 |
|
|
*/ |
95 |
|
|
static int |
96 |
michael |
4084 |
duplicate_ptr(const void *const ptr) |
97 |
adx |
30 |
{ |
98 |
michael |
3283 |
for (unsigned int i = 0; i < ntargets; ++i) |
99 |
michael |
2796 |
if (targets[i].ptr == ptr) |
100 |
|
|
return 1; |
101 |
adx |
30 |
|
102 |
michael |
2796 |
return 0; |
103 |
adx |
30 |
} |
104 |
|
|
|
105 |
michael |
2796 |
/* flood_attack_client() |
106 |
adx |
30 |
* |
107 |
michael |
2796 |
* inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC |
108 |
|
|
* say NOTICE must not auto reply |
109 |
michael |
2820 |
* - pointer to source Client |
110 |
michael |
2796 |
* - pointer to target Client |
111 |
|
|
* output - 1 if target is under flood attack |
112 |
|
|
* side effects - check for flood attack on target target_p |
113 |
adx |
30 |
*/ |
114 |
|
|
static int |
115 |
michael |
4002 |
flood_attack_client(int p_or_n, struct Client *source_p, struct Client *target_p) |
116 |
adx |
30 |
{ |
117 |
michael |
5452 |
assert(MyClient(target_p)); |
118 |
|
|
assert(IsClient(source_p)); |
119 |
adx |
30 |
|
120 |
michael |
5452 |
if (HasUMode(source_p, UMODE_OPER) || HasFlag(source_p, FLAGS_SERVICE)) |
121 |
|
|
return 0; |
122 |
|
|
|
123 |
|
|
if (GlobalSetOptions.floodcount && !IsCanFlood(source_p)) |
124 |
adx |
30 |
{ |
125 |
michael |
4589 |
if ((target_p->connection->first_received_message_time + 1) |
126 |
michael |
2796 |
< CurrentTime) |
127 |
|
|
{ |
128 |
michael |
5452 |
const int delta = |
129 |
michael |
4589 |
CurrentTime - target_p->connection->first_received_message_time; |
130 |
|
|
target_p->connection->received_number_of_privmsgs -= delta; |
131 |
|
|
target_p->connection->first_received_message_time = CurrentTime; |
132 |
adx |
30 |
|
133 |
michael |
4589 |
if (target_p->connection->received_number_of_privmsgs <= 0) |
134 |
adx |
30 |
{ |
135 |
michael |
4589 |
target_p->connection->received_number_of_privmsgs = 0; |
136 |
michael |
2796 |
DelFlag(target_p, FLAGS_FLOOD_NOTICED); |
137 |
adx |
30 |
} |
138 |
|
|
} |
139 |
|
|
|
140 |
michael |
4589 |
if ((target_p->connection->received_number_of_privmsgs >= |
141 |
michael |
2796 |
GlobalSetOptions.floodcount) || HasFlag(target_p, FLAGS_FLOOD_NOTICED)) |
142 |
adx |
30 |
{ |
143 |
michael |
2796 |
if (!HasFlag(target_p, FLAGS_FLOOD_NOTICED)) |
144 |
adx |
30 |
{ |
145 |
michael |
2796 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
146 |
|
|
"Possible Flooder %s on %s target: %s", |
147 |
|
|
get_client_name(source_p, HIDE_IP), |
148 |
|
|
source_p->servptr->name, target_p->name); |
149 |
michael |
3774 |
|
150 |
michael |
2796 |
AddFlag(target_p, FLAGS_FLOOD_NOTICED); |
151 |
michael |
4589 |
target_p->connection->received_number_of_privmsgs += 2; /* Add a bit of penalty */ |
152 |
adx |
30 |
} |
153 |
|
|
|
154 |
michael |
3774 |
if (MyClient(source_p) && p_or_n != NOTICE) |
155 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":*** Message to %s throttled due to flooding", |
156 |
|
|
target_p->name); |
157 |
michael |
2796 |
return 1; |
158 |
adx |
30 |
} |
159 |
michael |
2796 |
else |
160 |
michael |
4589 |
target_p->connection->received_number_of_privmsgs++; |
161 |
michael |
2796 |
} |
162 |
adx |
30 |
|
163 |
michael |
2796 |
return 0; |
164 |
|
|
} |
165 |
adx |
30 |
|
166 |
michael |
2796 |
/* flood_attack_channel() |
167 |
|
|
* |
168 |
|
|
* inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC |
169 |
|
|
* says NOTICE must not auto reply |
170 |
michael |
2820 |
* - pointer to source Client |
171 |
michael |
2796 |
* - pointer to target channel |
172 |
|
|
* output - 1 if target is under flood attack |
173 |
|
|
* side effects - check for flood attack on target chptr |
174 |
|
|
*/ |
175 |
|
|
static int |
176 |
michael |
4002 |
flood_attack_channel(int p_or_n, struct Client *source_p, struct Channel *chptr) |
177 |
michael |
2796 |
{ |
178 |
|
|
if (GlobalSetOptions.floodcount && !IsCanFlood(source_p)) |
179 |
|
|
{ |
180 |
|
|
if ((chptr->first_received_message_time + 1) < CurrentTime) |
181 |
|
|
{ |
182 |
michael |
5455 |
const int delta = CurrentTime - chptr->first_received_message_time; |
183 |
michael |
2796 |
chptr->received_number_of_privmsgs -= delta; |
184 |
|
|
chptr->first_received_message_time = CurrentTime; |
185 |
adx |
30 |
|
186 |
michael |
2796 |
if (chptr->received_number_of_privmsgs <= 0) |
187 |
adx |
30 |
{ |
188 |
michael |
2796 |
chptr->received_number_of_privmsgs = 0; |
189 |
|
|
ClearFloodNoticed(chptr); |
190 |
adx |
30 |
} |
191 |
|
|
} |
192 |
|
|
|
193 |
michael |
2796 |
if ((chptr->received_number_of_privmsgs >= GlobalSetOptions.floodcount) || |
194 |
|
|
IsSetFloodNoticed(chptr)) |
195 |
adx |
30 |
{ |
196 |
michael |
2796 |
if (!IsSetFloodNoticed(chptr)) |
197 |
adx |
30 |
{ |
198 |
michael |
2796 |
sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE, |
199 |
|
|
"Possible Flooder %s on %s target: %s", |
200 |
|
|
get_client_name(source_p, HIDE_IP), |
201 |
michael |
4617 |
source_p->servptr->name, chptr->name); |
202 |
michael |
3774 |
|
203 |
michael |
2796 |
SetFloodNoticed(chptr); |
204 |
michael |
3774 |
chptr->received_number_of_privmsgs += 2; /* Add a bit of penalty */ |
205 |
adx |
30 |
} |
206 |
michael |
2796 |
|
207 |
michael |
3774 |
if (MyClient(source_p) && p_or_n != NOTICE) |
208 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":*** Message to %s throttled due to flooding", |
209 |
michael |
4617 |
chptr->name); |
210 |
michael |
2796 |
return 1; |
211 |
adx |
30 |
} |
212 |
michael |
2796 |
else |
213 |
|
|
chptr->received_number_of_privmsgs++; |
214 |
adx |
30 |
} |
215 |
|
|
|
216 |
michael |
2786 |
return 0; |
217 |
adx |
30 |
} |
218 |
|
|
|
219 |
|
|
/* msg_channel_flags() |
220 |
|
|
* |
221 |
michael |
2820 |
* inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC |
222 |
adx |
30 |
* say NOTICE must not auto reply |
223 |
|
|
* - pointer to command, "PRIVMSG" or "NOTICE" |
224 |
|
|
* - pointer to source_p |
225 |
|
|
* - pointer to channel |
226 |
|
|
* - flags |
227 |
|
|
* - pointer to text to send |
228 |
|
|
* output - NONE |
229 |
|
|
* side effects - message given channel either chanop or voice |
230 |
|
|
*/ |
231 |
|
|
static void |
232 |
michael |
5455 |
msg_channel(int p_or_n, const char *command, struct Client *source_p, |
233 |
|
|
struct Channel *chptr, unsigned int flags, const char *text) |
234 |
adx |
30 |
{ |
235 |
michael |
5455 |
int result = 0; |
236 |
michael |
4084 |
unsigned int type = 0; |
237 |
michael |
5455 |
const char *prefix = ""; |
238 |
adx |
30 |
|
239 |
|
|
if (flags & CHFL_VOICE) |
240 |
|
|
{ |
241 |
|
|
type = CHFL_VOICE|CHFL_HALFOP|CHFL_CHANOP; |
242 |
michael |
5455 |
prefix = "+"; |
243 |
adx |
30 |
} |
244 |
|
|
else if (flags & CHFL_HALFOP) |
245 |
|
|
{ |
246 |
|
|
type = CHFL_HALFOP|CHFL_CHANOP; |
247 |
michael |
5455 |
prefix = "%"; |
248 |
|
|
} |
249 |
|
|
else if (flags & CHFL_CHANOP) |
250 |
adx |
30 |
{ |
251 |
|
|
type = CHFL_CHANOP; |
252 |
michael |
5455 |
prefix = "@"; |
253 |
adx |
30 |
} |
254 |
|
|
|
255 |
michael |
4527 |
/* Chanops and voiced can flood their own channel with impunity */ |
256 |
|
|
if ((result = can_send(chptr, source_p, NULL, text)) < 0) |
257 |
|
|
{ |
258 |
|
|
if (result == CAN_SEND_OPV || |
259 |
|
|
!flood_attack_channel(p_or_n, source_p, chptr)) |
260 |
michael |
5455 |
sendto_channel_butone(source_p, source_p, chptr, type, "%s %s%s :%s", |
261 |
|
|
command, prefix, chptr->name, text); |
262 |
michael |
4527 |
} |
263 |
|
|
else |
264 |
|
|
{ |
265 |
|
|
if (p_or_n != NOTICE) |
266 |
|
|
{ |
267 |
|
|
if (result == ERR_NOCTRLSONCHAN) |
268 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOCTRLSONCHAN, |
269 |
michael |
4617 |
chptr->name, text); |
270 |
michael |
4527 |
else if (result == ERR_NEEDREGGEDNICK) |
271 |
|
|
sendto_one_numeric(source_p, &me, ERR_NEEDREGGEDNICK, |
272 |
michael |
4617 |
chptr->name); |
273 |
michael |
4527 |
else |
274 |
|
|
sendto_one_numeric(source_p, &me, ERR_CANNOTSENDTOCHAN, |
275 |
michael |
4617 |
chptr->name); |
276 |
michael |
4527 |
} |
277 |
|
|
} |
278 |
adx |
30 |
} |
279 |
|
|
|
280 |
|
|
/* msg_client() |
281 |
|
|
* |
282 |
michael |
2820 |
* inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC |
283 |
adx |
30 |
* say NOTICE must not auto reply |
284 |
|
|
* - pointer to command, "PRIVMSG" or "NOTICE" |
285 |
|
|
* - pointer to source_p source (struct Client *) |
286 |
|
|
* - pointer to target_p target (struct Client *) |
287 |
|
|
* - pointer to text |
288 |
|
|
* output - NONE |
289 |
|
|
* side effects - message given channel either chanop or voice |
290 |
|
|
*/ |
291 |
|
|
static void |
292 |
|
|
msg_client(int p_or_n, const char *command, struct Client *source_p, |
293 |
michael |
4002 |
struct Client *target_p, const char *text) |
294 |
adx |
30 |
{ |
295 |
michael |
3974 |
if (MyClient(source_p)) |
296 |
adx |
30 |
{ |
297 |
michael |
3978 |
if (target_p->away[0] && p_or_n != NOTICE) |
298 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_AWAY, target_p->name, target_p->away); |
299 |
michael |
1175 |
|
300 |
|
|
if (HasUMode(target_p, UMODE_REGONLY) && target_p != source_p) |
301 |
michael |
1173 |
{ |
302 |
michael |
1175 |
if (!HasUMode(source_p, UMODE_REGISTERED|UMODE_OPER)) |
303 |
|
|
{ |
304 |
|
|
if (p_or_n != NOTICE) |
305 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NONONREG, target_p->name); |
306 |
michael |
1175 |
return; |
307 |
|
|
} |
308 |
michael |
1173 |
} |
309 |
adx |
30 |
} |
310 |
|
|
|
311 |
michael |
5452 |
if (MyClient(target_p) && IsClient(source_p)) |
312 |
adx |
30 |
{ |
313 |
michael |
5452 |
if (HasUMode(target_p, UMODE_CALLERID|UMODE_SOFTCALLERID) && |
314 |
|
|
!accept_message(source_p, target_p)) |
315 |
adx |
30 |
{ |
316 |
michael |
5452 |
const int callerid = !!HasUMode(target_p, UMODE_CALLERID); |
317 |
|
|
|
318 |
|
|
/* check for accept, flag recipient incoming message */ |
319 |
|
|
if (p_or_n != NOTICE) |
320 |
|
|
sendto_one_numeric(source_p, &me, RPL_TARGUMODEG, |
321 |
|
|
target_p->name, |
322 |
|
|
callerid ? "+g" : "+G", |
323 |
|
|
callerid ? "server side ignore" : |
324 |
|
|
"server side ignore with the exception of common channels"); |
325 |
|
|
|
326 |
|
|
if ((target_p->connection->last_caller_id_time + |
327 |
|
|
ConfigGeneral.caller_id_wait) < CurrentTime) |
328 |
adx |
30 |
{ |
329 |
|
|
if (p_or_n != NOTICE) |
330 |
michael |
5452 |
sendto_one_numeric(source_p, &me, RPL_TARGNOTIFY, target_p->name); |
331 |
adx |
30 |
|
332 |
michael |
5452 |
sendto_one_numeric(target_p, &me, RPL_UMODEGMSG, |
333 |
|
|
get_client_name(source_p, HIDE_IP), |
334 |
|
|
callerid ? "+g" : "+G"); |
335 |
|
|
target_p->connection->last_caller_id_time = CurrentTime; |
336 |
|
|
} |
337 |
adx |
30 |
|
338 |
michael |
5452 |
/* Only so opers can watch for floods */ |
339 |
michael |
5453 |
flood_attack_client(NOTICE, source_p, target_p); |
340 |
michael |
5452 |
return; |
341 |
|
|
} |
342 |
adx |
30 |
|
343 |
michael |
5452 |
if (flood_attack_client(p_or_n, source_p, target_p)) |
344 |
|
|
return; |
345 |
|
|
} |
346 |
adx |
30 |
|
347 |
michael |
5452 |
sendto_anywhere(target_p, source_p, command, ":%s", text); |
348 |
adx |
30 |
} |
349 |
|
|
|
350 |
|
|
/* handle_special() |
351 |
|
|
* |
352 |
michael |
3159 |
* inputs - client pointer |
353 |
adx |
30 |
* - nick stuff to grok for opers |
354 |
|
|
* - text to send if grok |
355 |
|
|
* output - none |
356 |
|
|
* side effects - old style username@server is handled here for non opers |
357 |
|
|
* opers are allowed username%hostname@server |
358 |
|
|
* all the traditional oper type messages are also parsed here. |
359 |
|
|
* i.e. "/msg #some.host." |
360 |
|
|
* However, syntax has been changed. |
361 |
|
|
* previous syntax "/msg #some.host.mask" |
362 |
|
|
* now becomes "/msg $#some.host.mask" |
363 |
|
|
* previous syntax of: "/msg $some.server.mask" remains |
364 |
|
|
* This disambiguates the syntax. |
365 |
|
|
* |
366 |
|
|
* XXX N.B. dalnet changed it to nick@server as have other servers. |
367 |
|
|
* we will stick with tradition for now. |
368 |
|
|
* - Dianora |
369 |
|
|
*/ |
370 |
|
|
static void |
371 |
michael |
3159 |
handle_special(int p_or_n, const char *command, struct Client *source_p, |
372 |
michael |
3950 |
const char *nick, const char *text) |
373 |
adx |
30 |
{ |
374 |
michael |
3948 |
struct Client *target_p = NULL; |
375 |
|
|
const char *server = NULL, *s = NULL; |
376 |
adx |
30 |
|
377 |
|
|
/* |
378 |
|
|
* user[%host]@server addressed? |
379 |
|
|
*/ |
380 |
michael |
2796 |
if ((server = strchr(nick, '@'))) |
381 |
adx |
30 |
{ |
382 |
michael |
3969 |
if ((target_p = hash_find_server(server + 1)) == NULL) |
383 |
adx |
30 |
{ |
384 |
michael |
3948 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, server + 1); |
385 |
adx |
30 |
return; |
386 |
|
|
} |
387 |
|
|
|
388 |
michael |
3948 |
if (!HasUMode(source_p, UMODE_OPER) && strchr(nick, '%')) |
389 |
adx |
30 |
{ |
390 |
michael |
3948 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, nick); |
391 |
|
|
return; |
392 |
|
|
} |
393 |
michael |
3774 |
|
394 |
michael |
3948 |
if (!IsMe(target_p)) |
395 |
|
|
{ |
396 |
|
|
sendto_one(target_p, ":%s %s %s :%s", source_p->id, command, nick, text); |
397 |
|
|
return; |
398 |
|
|
} |
399 |
adx |
30 |
|
400 |
michael |
3948 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, nick); |
401 |
adx |
30 |
return; |
402 |
|
|
} |
403 |
|
|
|
404 |
michael |
1219 |
if (!HasUMode(source_p, UMODE_OPER)) |
405 |
adx |
30 |
{ |
406 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
407 |
adx |
30 |
return; |
408 |
|
|
} |
409 |
|
|
|
410 |
|
|
/* |
411 |
michael |
2796 |
* The following two cases allow masks in NOTICEs |
412 |
adx |
30 |
* (for OPERs only) |
413 |
|
|
* |
414 |
|
|
* Armin, 8Jun90 (gruner@informatik.tu-muenchen.de) |
415 |
|
|
*/ |
416 |
|
|
if (*nick == '$') |
417 |
|
|
{ |
418 |
michael |
3482 |
if (*(nick + 1) == '$' || *(nick + 1) == '#') |
419 |
michael |
2796 |
++nick; |
420 |
michael |
3964 |
else if (MyClient(source_p)) |
421 |
adx |
30 |
{ |
422 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":The command %s %s is no longer supported, please use $%s", |
423 |
|
|
command, nick, nick); |
424 |
adx |
30 |
return; |
425 |
|
|
} |
426 |
|
|
|
427 |
|
|
if ((s = strrchr(nick, '.')) == NULL) |
428 |
|
|
{ |
429 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOTOPLEVEL, nick); |
430 |
adx |
30 |
return; |
431 |
|
|
} |
432 |
|
|
|
433 |
|
|
while (*++s) |
434 |
|
|
if (*s == '.' || *s == '*' || *s == '?') |
435 |
|
|
break; |
436 |
|
|
|
437 |
|
|
if (*s == '*' || *s == '?') |
438 |
|
|
{ |
439 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_WILDTOPLEVEL, nick); |
440 |
adx |
30 |
return; |
441 |
|
|
} |
442 |
michael |
2820 |
|
443 |
michael |
3156 |
sendto_match_butone(IsServer(source_p->from) ? source_p->from : NULL, source_p, |
444 |
adx |
30 |
nick + 1, (*nick == '#') ? MATCH_HOST : MATCH_SERVER, |
445 |
|
|
"%s $%s :%s", command, nick, text); |
446 |
|
|
} |
447 |
|
|
} |
448 |
|
|
|
449 |
michael |
2796 |
/* build_target_list() |
450 |
adx |
30 |
* |
451 |
michael |
3159 |
* inputs - pointer to given source (oper/client etc.) |
452 |
michael |
2796 |
* - pointer to list of nicks/channels |
453 |
|
|
* - pointer to table to place results |
454 |
|
|
* - pointer to text (only used if source_p is an oper) |
455 |
|
|
* output - number of valid entities |
456 |
|
|
* side effects - target_table is modified to contain a list of |
457 |
|
|
* pointers to channels or clients |
458 |
|
|
* if source client is an oper |
459 |
|
|
* all the classic old bizzare oper privmsg tricks |
460 |
|
|
* are parsed and sent as is, if prefixed with $ |
461 |
|
|
* to disambiguate. |
462 |
|
|
* |
463 |
adx |
30 |
*/ |
464 |
michael |
2796 |
static int |
465 |
michael |
3159 |
build_target_list(int p_or_n, const char *command, struct Client *source_p, |
466 |
michael |
5455 |
char *list, const char *text) |
467 |
adx |
30 |
{ |
468 |
michael |
5455 |
unsigned int type = 0; |
469 |
|
|
char *p = NULL; |
470 |
|
|
void *target = NULL; |
471 |
adx |
30 |
|
472 |
michael |
2796 |
ntargets = 0; |
473 |
|
|
|
474 |
michael |
5455 |
for (const char *name = strtoken(&p, list, ","); name; |
475 |
|
|
name = strtoken(&p, NULL, ",")) |
476 |
adx |
30 |
{ |
477 |
michael |
3982 |
const char *with_prefix = NULL; |
478 |
michael |
2796 |
|
479 |
|
|
/* |
480 |
|
|
* Channels are privmsg'd a lot more than other clients, moved up |
481 |
|
|
* here plain old channel msg? |
482 |
|
|
*/ |
483 |
michael |
5455 |
if (IsChanPrefix(*name)) |
484 |
adx |
30 |
{ |
485 |
michael |
5455 |
if ((target = hash_find_channel(name))) |
486 |
michael |
2796 |
{ |
487 |
michael |
5455 |
if (!duplicate_ptr(target)) |
488 |
michael |
2796 |
{ |
489 |
michael |
4341 |
if (ntargets >= ConfigGeneral.max_targets) |
490 |
michael |
2796 |
{ |
491 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_TOOMANYTARGETS, |
492 |
michael |
5455 |
name, ConfigGeneral.max_targets); |
493 |
michael |
2796 |
return 1; |
494 |
|
|
} |
495 |
adx |
30 |
|
496 |
michael |
5455 |
targets[ntargets].ptr = target; |
497 |
|
|
targets[ntargets].type = ENTITY_CHANNEL; |
498 |
|
|
targets[ntargets++].flags = 0; |
499 |
michael |
2796 |
} |
500 |
|
|
} |
501 |
michael |
5455 |
else if (p_or_n != NOTICE) |
502 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name); |
503 |
michael |
2796 |
|
504 |
|
|
continue; |
505 |
|
|
} |
506 |
|
|
|
507 |
michael |
3774 |
/* Look for a PRIVMSG/NOTICE to another client */ |
508 |
michael |
5455 |
if ((target = find_person(source_p, name))) |
509 |
michael |
2796 |
{ |
510 |
michael |
5455 |
if (!duplicate_ptr(target)) |
511 |
michael |
2796 |
{ |
512 |
michael |
4341 |
if (ntargets >= ConfigGeneral.max_targets) |
513 |
michael |
2796 |
{ |
514 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_TOOMANYTARGETS, |
515 |
michael |
5455 |
name, ConfigGeneral.max_targets); |
516 |
michael |
2796 |
return 1; |
517 |
|
|
} |
518 |
|
|
|
519 |
michael |
5455 |
targets[ntargets].ptr = target; |
520 |
michael |
2796 |
targets[ntargets].type = ENTITY_CLIENT; |
521 |
|
|
targets[ntargets++].flags = 0; |
522 |
|
|
} |
523 |
|
|
|
524 |
|
|
continue; |
525 |
|
|
} |
526 |
michael |
2820 |
|
527 |
michael |
2796 |
/* @#channel or +#channel message ? */ |
528 |
|
|
type = 0; |
529 |
michael |
5455 |
with_prefix = name; |
530 |
michael |
2796 |
|
531 |
|
|
/* Allow %+@ if someone wants to do that */ |
532 |
michael |
3482 |
while (1) |
533 |
michael |
2796 |
{ |
534 |
michael |
5455 |
if (*name == '@') |
535 |
michael |
2796 |
type |= CHFL_CHANOP; |
536 |
michael |
5455 |
else if (*name == '%') |
537 |
michael |
2796 |
type |= CHFL_CHANOP | CHFL_HALFOP; |
538 |
michael |
5455 |
else if (*name == '+') |
539 |
michael |
2796 |
type |= CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE; |
540 |
|
|
else |
541 |
|
|
break; |
542 |
michael |
5455 |
++name; |
543 |
michael |
2796 |
} |
544 |
|
|
|
545 |
michael |
3246 |
if (type) |
546 |
michael |
2796 |
{ |
547 |
michael |
5455 |
if (EmptyString(name)) /* If it's a '\0' dump it, there is no recipient */ |
548 |
michael |
2796 |
{ |
549 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NORECIPIENT, command); |
550 |
adx |
30 |
continue; |
551 |
michael |
2796 |
} |
552 |
adx |
30 |
|
553 |
michael |
2796 |
/* |
554 |
michael |
5455 |
* At this point, name+1 should be a channel name i.e. #foo or &foo |
555 |
michael |
2796 |
* if the channel is found, fine, if not report an error |
556 |
|
|
*/ |
557 |
michael |
5455 |
if ((target = hash_find_channel(name))) |
558 |
adx |
30 |
{ |
559 |
michael |
2796 |
if (IsClient(source_p) && !HasFlag(source_p, FLAGS_SERVICE)) |
560 |
|
|
{ |
561 |
michael |
5455 |
if (!has_member_flags(find_channel_link(source_p, target), |
562 |
michael |
2796 |
CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE)) |
563 |
|
|
{ |
564 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, with_prefix); |
565 |
michael |
5458 |
continue; |
566 |
michael |
2796 |
} |
567 |
|
|
} |
568 |
|
|
|
569 |
michael |
5455 |
if (!duplicate_ptr(target)) |
570 |
michael |
2796 |
{ |
571 |
michael |
4341 |
if (ntargets >= ConfigGeneral.max_targets) |
572 |
michael |
2796 |
{ |
573 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_TOOMANYTARGETS, |
574 |
michael |
5455 |
name, ConfigGeneral.max_targets); |
575 |
michael |
2820 |
return 1; |
576 |
michael |
2796 |
} |
577 |
|
|
|
578 |
michael |
5455 |
targets[ntargets].ptr = target; |
579 |
|
|
targets[ntargets].type = ENTITY_CHANNEL; |
580 |
michael |
2796 |
targets[ntargets++].flags = type; |
581 |
|
|
} |
582 |
adx |
30 |
} |
583 |
michael |
5455 |
else if (p_or_n != NOTICE) |
584 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name); |
585 |
michael |
2796 |
|
586 |
|
|
continue; |
587 |
adx |
30 |
} |
588 |
michael |
2796 |
|
589 |
michael |
5455 |
if (*name == '$' || strchr(name, '@')) |
590 |
|
|
handle_special(p_or_n, command, source_p, name, text); |
591 |
michael |
2796 |
else |
592 |
|
|
{ |
593 |
|
|
if (p_or_n != NOTICE) |
594 |
|
|
{ |
595 |
michael |
5455 |
if (!IsDigit(*name) || MyClient(source_p)) |
596 |
|
|
sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name); |
597 |
michael |
2796 |
} |
598 |
|
|
} |
599 |
adx |
30 |
} |
600 |
|
|
|
601 |
michael |
2796 |
return 1; |
602 |
adx |
30 |
} |
603 |
michael |
1230 |
|
604 |
michael |
2796 |
/* |
605 |
|
|
* inputs - flag privmsg or notice |
606 |
|
|
* - pointer to command "PRIVMSG" or "NOTICE" |
607 |
|
|
* - pointer to source_p |
608 |
|
|
* - pointer to channel |
609 |
|
|
*/ |
610 |
|
|
static void |
611 |
michael |
4002 |
m_message(int p_or_n, const char *command, struct Client *source_p, int parc, char *parv[]) |
612 |
michael |
2796 |
{ |
613 |
|
|
if (parc < 2 || EmptyString(parv[1])) |
614 |
|
|
{ |
615 |
|
|
if (p_or_n != NOTICE) |
616 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NORECIPIENT, command); |
617 |
michael |
2796 |
return; |
618 |
|
|
} |
619 |
|
|
|
620 |
|
|
if (parc < 3 || EmptyString(parv[2])) |
621 |
|
|
{ |
622 |
|
|
if (p_or_n != NOTICE) |
623 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOTEXTTOSEND); |
624 |
michael |
2796 |
return; |
625 |
|
|
} |
626 |
|
|
|
627 |
|
|
/* Finish the flood grace period... */ |
628 |
|
|
if (MyClient(source_p) && !IsFloodDone(source_p)) |
629 |
|
|
flood_endgrace(source_p); |
630 |
|
|
|
631 |
michael |
3156 |
if (build_target_list(p_or_n, command, source_p, parv[1], parv[2]) < 0) |
632 |
michael |
2796 |
return; |
633 |
|
|
|
634 |
michael |
3283 |
for (unsigned int i = 0; i < ntargets; ++i) |
635 |
michael |
2796 |
{ |
636 |
|
|
switch (targets[i].type) |
637 |
|
|
{ |
638 |
michael |
3774 |
case ENTITY_CLIENT: |
639 |
|
|
msg_client(p_or_n, command, source_p, targets[i].ptr, parv[2]); |
640 |
|
|
break; |
641 |
|
|
|
642 |
michael |
2796 |
case ENTITY_CHANNEL: |
643 |
michael |
5455 |
msg_channel(p_or_n, command, source_p, targets[i].ptr, |
644 |
|
|
targets[i].flags, parv[2]); |
645 |
michael |
2796 |
break; |
646 |
|
|
} |
647 |
|
|
} |
648 |
|
|
} |
649 |
|
|
|
650 |
michael |
2820 |
static int |
651 |
michael |
3156 |
m_privmsg(struct Client *source_p, int parc, char *parv[]) |
652 |
michael |
2796 |
{ |
653 |
|
|
/* |
654 |
|
|
* Servers have no reason to send privmsgs, yet sometimes there is cause |
655 |
|
|
* for a notice.. (for example remote kline replies) --fl_ |
656 |
|
|
*/ |
657 |
|
|
if (!IsClient(source_p)) |
658 |
michael |
2820 |
return 0; |
659 |
michael |
2796 |
|
660 |
michael |
3973 |
if (MyConnect(source_p)) |
661 |
michael |
4589 |
source_p->connection->last_privmsg = CurrentTime; |
662 |
michael |
3973 |
|
663 |
michael |
3156 |
m_message(PRIVMSG, "PRIVMSG", source_p, parc, parv); |
664 |
michael |
2820 |
return 0; |
665 |
michael |
2796 |
} |
666 |
|
|
|
667 |
michael |
2820 |
static int |
668 |
michael |
3156 |
m_notice(struct Client *source_p, int parc, char *parv[]) |
669 |
michael |
2796 |
{ |
670 |
michael |
3156 |
m_message(NOTICE, "NOTICE", source_p, parc, parv); |
671 |
michael |
2820 |
return 0; |
672 |
michael |
2796 |
} |
673 |
|
|
|
674 |
|
|
static struct Message privmsg_msgtab = |
675 |
|
|
{ |
676 |
michael |
4546 |
"PRIVMSG", NULL, 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
677 |
michael |
2820 |
{ m_unregistered, m_privmsg, m_privmsg, m_ignore, m_privmsg, m_ignore } |
678 |
michael |
1230 |
}; |
679 |
|
|
|
680 |
michael |
2796 |
static struct Message notice_msgtab = |
681 |
|
|
{ |
682 |
michael |
4546 |
"NOTICE", NULL, 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
683 |
michael |
2820 |
{ m_unregistered, m_notice, m_notice, m_ignore, m_notice, m_ignore } |
684 |
michael |
1230 |
}; |
685 |
|
|
|
686 |
|
|
static void |
687 |
|
|
module_init(void) |
688 |
|
|
{ |
689 |
|
|
mod_add_cmd(&privmsg_msgtab); |
690 |
|
|
mod_add_cmd(¬ice_msgtab); |
691 |
|
|
} |
692 |
|
|
|
693 |
|
|
static void |
694 |
|
|
module_exit(void) |
695 |
|
|
{ |
696 |
|
|
mod_del_cmd(&privmsg_msgtab); |
697 |
|
|
mod_del_cmd(¬ice_msgtab); |
698 |
|
|
} |
699 |
|
|
|
700 |
michael |
2796 |
struct module module_entry = |
701 |
|
|
{ |
702 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
703 |
|
|
.name = NULL, |
704 |
|
|
.version = "$Revision$", |
705 |
|
|
.handle = NULL, |
706 |
|
|
.modinit = module_init, |
707 |
|
|
.modexit = module_exit, |
708 |
|
|
.flags = MODULE_FLAG_CORE |
709 |
|
|
}; |