ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/core/m_message.c
Revision: 1435
Committed: Fri Jun 15 18:35:37 2012 UTC (14 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 28611 byte(s)
Log Message:
- Backed-out -r1429. Unregistered clients may again speak in +R channels

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_message.c: Sends a (PRIVMSG|NOTICE) message to a user or channel.
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 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "client.h"
28 #include "ircd.h"
29 #include "numeric.h"
30 #include "conf.h"
31 #include "s_serv.h"
32 #include "send.h"
33 #include "parse.h"
34 #include "modules.h"
35 #include "channel.h"
36 #include "channel_mode.h"
37 #include "irc_string.h"
38 #include "hash.h"
39 #include "packet.h"
40
41
42 struct entity
43 {
44 void *ptr;
45 int type;
46 int flags;
47 };
48
49 static int build_target_list(int p_or_n, const char *command,
50 struct Client *client_p,
51 struct Client *source_p,
52 char *nicks_channels, char *text);
53
54 static int flood_attack_client(int p_or_n, struct Client *source_p,
55 struct Client *target_p);
56 static int flood_attack_channel(int p_or_n, struct Client *source_p,
57 struct Channel *chptr, char *chname);
58 static struct Client* find_userhost (char *, char *, int *);
59
60 #define ENTITY_NONE 0
61 #define ENTITY_CHANNEL 1
62 #define ENTITY_CHANOPS_ON_CHANNEL 2
63 #define ENTITY_CLIENT 3
64
65 static struct entity targets[512];
66 static int ntargets = 0;
67
68 static int duplicate_ptr(void *);
69
70 static void m_message(int, const char *, struct Client *,
71 struct Client *, int, char **);
72
73 static void msg_channel(int p_or_n, const char *command,
74 struct Client *client_p,
75 struct Client *source_p,
76 struct Channel *chptr, char *text);
77
78 static void msg_channel_flags(int p_or_n, const char *command,
79 struct Client *client_p,
80 struct Client *source_p,
81 struct Channel *chptr, int flags, char *text);
82
83 static void msg_client(int p_or_n, const char *command,
84 struct Client *source_p, struct Client *target_p,
85 char *text);
86
87 static void handle_special(int p_or_n, const char *command,
88 struct Client *client_p,
89 struct Client *source_p, char *nick, char *text);
90
91 /*
92 ** m_privmsg
93 **
94 ** massive cleanup
95 ** rev argv 6/91
96 **
97 ** Another massive cleanup Nov, 2000
98 ** (I don't think there is a single line left from 6/91. Maybe.)
99 ** m_privmsg and m_notice do basically the same thing.
100 ** in the original 2.8.2 code base, they were the same function
101 ** "m_message.c." When we did the great cleanup in conjuncton with bleep
102 ** of ircu fame, we split m_privmsg.c and m_notice.c.
103 ** I don't see the point of that now. Its harder to maintain, its
104 ** easier to introduce bugs into one version and not the other etc.
105 ** Really, the penalty of an extra function call isn't that big a deal folks.
106 ** -db Nov 13, 2000
107 **
108 */
109
110 #define PRIVMSG 0
111 #define NOTICE 1
112
113 static void
114 m_privmsg(struct Client *client_p, struct Client *source_p,
115 int parc, char *parv[])
116 {
117 /* servers have no reason to send privmsgs, yet sometimes there is cause
118 * for a notice.. (for example remote kline replies) --fl_
119 */
120 if (!IsClient(source_p))
121 return;
122
123 m_message(PRIVMSG, "PRIVMSG", client_p, source_p, parc, parv);
124 }
125
126 static void
127 m_notice(struct Client *client_p, struct Client *source_p,
128 int parc, char *parv[])
129 {
130 m_message(NOTICE, "NOTICE", client_p, source_p, parc, parv);
131 }
132
133 /*
134 * inputs - flag privmsg or notice
135 * - pointer to command "PRIVMSG" or "NOTICE"
136 * - pointer to client_p
137 * - pointer to source_p
138 * - pointer to channel
139 */
140 static void
141 m_message(int p_or_n, const char *command, struct Client *client_p,
142 struct Client *source_p, int parc, char *parv[])
143 {
144 int i;
145
146 if (parc < 2 || EmptyString(parv[1]))
147 {
148 if (p_or_n != NOTICE)
149 sendto_one(source_p, form_str(ERR_NORECIPIENT),
150 ID_or_name(&me, client_p),
151 ID_or_name(source_p, client_p), command);
152 return;
153 }
154
155 if (parc < 3 || EmptyString(parv[2]))
156 {
157 if (p_or_n != NOTICE)
158 sendto_one(source_p, form_str(ERR_NOTEXTTOSEND),
159 ID_or_name(&me, client_p),
160 ID_or_name(source_p, client_p));
161 return;
162 }
163
164 /* Finish the flood grace period... */
165 if (MyClient(source_p) && !IsFloodDone(source_p))
166 flood_endgrace(source_p);
167
168 if (build_target_list(p_or_n, command, client_p, source_p, parv[1],
169 parv[2]) < 0)
170 return;
171
172 for (i = 0; i < ntargets; i++)
173 {
174 switch (targets[i].type)
175 {
176 case ENTITY_CHANNEL:
177 msg_channel(p_or_n, command, client_p, source_p,
178 (struct Channel *)targets[i].ptr, parv[2]);
179 break;
180
181 case ENTITY_CHANOPS_ON_CHANNEL:
182 msg_channel_flags(p_or_n, command, client_p, source_p,
183 (struct Channel *)targets[i].ptr,
184 targets[i].flags, parv[2]);
185 break;
186
187 case ENTITY_CLIENT:
188 msg_client(p_or_n, command, source_p,
189 (struct Client *)targets[i].ptr, parv[2]);
190 break;
191 }
192 }
193 }
194
195 /* build_target_list()
196 *
197 * inputs - pointer to given client_p (server)
198 * - pointer to given source (oper/client etc.)
199 * - pointer to list of nicks/channels
200 * - pointer to table to place results
201 * - pointer to text (only used if source_p is an oper)
202 * output - number of valid entities
203 * side effects - target_table is modified to contain a list of
204 * pointers to channels or clients
205 * if source client is an oper
206 * all the classic old bizzare oper privmsg tricks
207 * are parsed and sent as is, if prefixed with $
208 * to disambiguate.
209 *
210 */
211 static int
212 build_target_list(int p_or_n, const char *command, struct Client *client_p,
213 struct Client *source_p, char *nicks_channels, char *text)
214 {
215 int type;
216 char *p = NULL, *nick, *target_list;
217 struct Channel *chptr = NULL;
218 struct Client *target_p = NULL;
219
220 target_list = nicks_channels;
221
222 ntargets = 0;
223
224 for (nick = strtoken(&p, target_list, ","); nick;
225 nick = strtoken(&p, NULL, ","))
226 {
227 char *with_prefix;
228 /*
229 * channels are privmsg'd a lot more than other clients, moved up
230 * here plain old channel msg?
231 */
232
233 if (IsChanPrefix(*nick))
234 {
235 /* ignore send of local channel to a server (should not happen) */
236 if (*nick == '&' && IsServer(client_p))
237 continue;
238
239 if ((chptr = hash_find_channel(nick)) != NULL)
240 {
241 if (!duplicate_ptr(chptr))
242 {
243 if (ntargets >= ConfigFileEntry.max_targets)
244 {
245 sendto_one(source_p, form_str(ERR_TOOMANYTARGETS),
246 ID_or_name(&me, client_p),
247 ID_or_name(source_p, client_p), nick,
248 ConfigFileEntry.max_targets);
249 return (1);
250 }
251 targets[ntargets].ptr = (void *)chptr;
252 targets[ntargets++].type = ENTITY_CHANNEL;
253 }
254 }
255 else
256 {
257 if (p_or_n != NOTICE)
258 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
259 ID_or_name(&me, client_p),
260 ID_or_name(source_p, client_p), nick);
261 }
262 continue;
263 }
264
265 /* look for a privmsg to another client */
266 if ((target_p = find_person(client_p, nick)) != NULL)
267 {
268 if (!duplicate_ptr(target_p))
269 {
270 if (ntargets >= ConfigFileEntry.max_targets)
271 {
272 sendto_one(source_p, form_str(ERR_TOOMANYTARGETS),
273 ID_or_name(&me, client_p),
274 ID_or_name(source_p, client_p), nick,
275 ConfigFileEntry.max_targets);
276 return (1);
277 }
278 targets[ntargets].ptr = (void *)target_p;
279 targets[ntargets].type = ENTITY_CLIENT;
280 targets[ntargets++].flags = 0;
281 }
282 continue;
283 }
284
285 /* @#channel or +#channel message ? */
286
287 type = 0;
288 with_prefix = nick;
289 /* allow %+@ if someone wants to do that */
290 for (; ;)
291 {
292 if (*nick == '@')
293 type |= CHFL_CHANOP;
294 #ifdef HALFOPS
295 else if (*nick == '%')
296 type |= CHFL_CHANOP | CHFL_HALFOP;
297 #endif
298 else if (*nick == '+')
299 type |= CHFL_CHANOP | CHFL_HALFOP | CHFL_VOICE;
300 else
301 break;
302 nick++;
303 }
304
305 if (type != 0)
306 {
307 /* suggested by Mortiis */
308 if (*nick == '\0') /* if its a '\0' dump it, there is no recipient */
309 {
310 sendto_one(source_p, form_str(ERR_NORECIPIENT),
311 ID_or_name(&me, client_p),
312 ID_or_name(source_p, client_p), command);
313 continue;
314 }
315
316 /* At this point, nick+1 should be a channel name i.e. #foo or &foo
317 * if the channel is found, fine, if not report an error
318 */
319
320 if ((chptr = hash_find_channel(nick)) != NULL)
321 {
322 if (!has_member_flags(find_channel_link(source_p, chptr),
323 CHFL_CHANOP|CHFL_HALFOP|CHFL_VOICE))
324 {
325 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
326 ID_or_name(&me, client_p),
327 ID_or_name(source_p, client_p), with_prefix);
328 return(-1);
329 }
330
331 if (!duplicate_ptr(chptr))
332 {
333 if (ntargets >= ConfigFileEntry.max_targets)
334 {
335 sendto_one(source_p, form_str(ERR_TOOMANYTARGETS),
336 ID_or_name(&me, client_p),
337 ID_or_name(source_p, client_p), nick,
338 ConfigFileEntry.max_targets);
339 return(1);
340 }
341 targets[ntargets].ptr = (void *)chptr;
342 targets[ntargets].type = ENTITY_CHANOPS_ON_CHANNEL;
343 targets[ntargets++].flags = type;
344 }
345 }
346 else
347 {
348 if (p_or_n != NOTICE)
349 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
350 ID_or_name(&me, client_p),
351 ID_or_name(source_p, client_p), nick);
352 }
353 continue;
354 }
355
356 if ((*nick == '$') || strchr(nick, '@') != NULL)
357 {
358 handle_special(p_or_n, command, client_p, source_p, nick, text);
359 }
360 else
361 {
362 if (p_or_n != NOTICE)
363 {
364 if (!IsDigit(*nick) || MyClient(source_p))
365 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
366 ID_or_name(&me, client_p),
367 ID_or_name(source_p, client_p), nick);
368 }
369 }
370 /* continue; */
371 }
372
373 return(1);
374 }
375
376 /* duplicate_ptr()
377 *
378 * inputs - pointer to check
379 * - pointer to table of entities
380 * - number of valid entities so far
381 * output - YES if duplicate pointer in table, NO if not.
382 * note, this does the canonize using pointers
383 * side effects - NONE
384 */
385 static int
386 duplicate_ptr(void *ptr)
387 {
388 int i;
389
390 for (i = 0; i < ntargets; i++)
391 {
392 if (targets[i].ptr == ptr)
393 return(1);
394 }
395
396 return(0);
397 }
398
399 /* msg_channel()
400 *
401 * inputs - flag privmsg or notice
402 * - pointer to command "PRIVMSG" or "NOTICE"
403 * - pointer to client_p
404 * - pointer to source_p
405 * - pointer to channel
406 * output - NONE
407 * side effects - message given channel
408 */
409 static void
410 msg_channel(int p_or_n, const char *command, struct Client *client_p,
411 struct Client *source_p, struct Channel *chptr, char *text)
412 {
413 int result;
414
415 if (MyClient(source_p))
416 {
417 /* idle time shouldnt be reset by notices --fl */
418 if (p_or_n != NOTICE)
419 source_p->localClient->last_privmsg = CurrentTime;
420 }
421
422 /* chanops and voiced can flood their own channel with impunity */
423 if ((result = can_send(chptr, source_p, NULL)) < 0)
424 {
425 if (result == CAN_SEND_OPV ||
426 !flood_attack_channel(p_or_n, source_p, chptr, chptr->chname))
427 sendto_channel_butone(client_p, source_p, chptr, command, ":%s", text);
428 }
429 else
430 {
431 if (p_or_n != NOTICE)
432 sendto_one(source_p, form_str(ERR_CANNOTSENDTOCHAN),
433 ID_or_name(&me, client_p),
434 ID_or_name(source_p, client_p), chptr->chname);
435 }
436 }
437
438 /* msg_channel_flags()
439 *
440 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
441 * say NOTICE must not auto reply
442 * - pointer to command, "PRIVMSG" or "NOTICE"
443 * - pointer to client_p
444 * - pointer to source_p
445 * - pointer to channel
446 * - flags
447 * - pointer to text to send
448 * output - NONE
449 * side effects - message given channel either chanop or voice
450 */
451 static void
452 msg_channel_flags(int p_or_n, const char *command, struct Client *client_p,
453 struct Client *source_p, struct Channel *chptr,
454 int flags, char *text)
455 {
456 int type;
457 char c;
458
459 if (flags & CHFL_VOICE)
460 {
461 type = CHFL_VOICE|CHFL_HALFOP|CHFL_CHANOP;
462 c = '+';
463 }
464 #ifdef HALFOPS
465 else if (flags & CHFL_HALFOP)
466 {
467 type = CHFL_HALFOP|CHFL_CHANOP;
468 c = '%';
469 }
470 #endif
471 else
472 {
473 type = CHFL_CHANOP;
474 c = '@';
475 }
476
477 if (MyClient(source_p))
478 {
479 /* idletime shouldnt be reset by notice --fl */
480 if (p_or_n != NOTICE)
481 source_p->localClient->last_privmsg = CurrentTime;
482
483 sendto_channel_local_butone(source_p, type, chptr, ":%s!%s@%s %s %c%s :%s",
484 source_p->name, source_p->username,
485 source_p->host, command, c, chptr->chname, text);
486 }
487 else
488 {
489 /*
490 * another good catch, lee. we never would echo to remote clients anyway,
491 * so use slightly less intensive sendto_channel_local()
492 */
493 sendto_channel_local(type, 1, chptr, ":%s!%s@%s %s %c%s :%s",
494 source_p->name, source_p->username,
495 source_p->host, command, c, chptr->chname, text);
496 }
497
498 if (chptr->chname[0] != '#')
499 return;
500
501 sendto_channel_remote(source_p, client_p, type, CAP_CHW, CAP_TS6, chptr,
502 ":%s %s %c%s :%s", source_p->name, command, c, chptr->chname, text);
503 sendto_channel_remote(source_p, client_p, type, CAP_CHW|CAP_TS6, NOCAPS, chptr,
504 ":%s %s %c%s :%s", ID(source_p), command, c, chptr->chname, text);
505 /* non CAP_CHW servers? */
506 }
507
508 /* msg_client()
509 *
510 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
511 * say NOTICE must not auto reply
512 * - pointer to command, "PRIVMSG" or "NOTICE"
513 * - pointer to source_p source (struct Client *)
514 * - pointer to target_p target (struct Client *)
515 * - pointer to text
516 * output - NONE
517 * side effects - message given channel either chanop or voice
518 */
519 static void
520 msg_client(int p_or_n, const char *command, struct Client *source_p,
521 struct Client *target_p, char *text)
522 {
523 if (MyConnect(source_p))
524 {
525 /*
526 * reset idle time for message only if it's not a notice
527 */
528 if ((p_or_n != NOTICE))
529 source_p->localClient->last_privmsg = CurrentTime;
530
531 if ((p_or_n != NOTICE) && target_p->away)
532 sendto_one(source_p, form_str(RPL_AWAY), me.name,
533 source_p->name, target_p->name, target_p->away);
534
535 if (HasUMode(target_p, UMODE_REGONLY) && target_p != source_p)
536 {
537 if (!HasUMode(source_p, UMODE_REGISTERED|UMODE_OPER))
538 {
539 if (p_or_n != NOTICE)
540 sendto_one(source_p, form_str(ERR_NONONREG), me.name, source_p->name,
541 target_p->name);
542 return;
543 }
544 }
545 }
546
547 if (MyClient(target_p))
548 {
549 if (!IsServer(source_p) && HasUMode(target_p, UMODE_CALLERID|UMODE_SOFTCALLERID))
550 {
551 /* Here is the anti-flood bot/spambot code -db */
552 if (accept_message(source_p, target_p) || HasFlag(source_p, FLAGS_SERVICE) ||
553 (HasUMode(source_p, UMODE_OPER) && (ConfigFileEntry.opers_bypass_callerid == 1)))
554 {
555 sendto_one(target_p, ":%s!%s@%s %s %s :%s",
556 source_p->name, source_p->username,
557 source_p->host, command, target_p->name, text);
558 }
559 else
560 {
561 /* check for accept, flag recipient incoming message */
562 if (p_or_n != NOTICE)
563 sendto_one(source_p, form_str(RPL_TARGUMODEG),
564 ID_or_name(&me, source_p->from),
565 ID_or_name(source_p, source_p->from), target_p->name);
566
567 if ((target_p->localClient->last_caller_id_time +
568 ConfigFileEntry.caller_id_wait) < CurrentTime)
569 {
570 if (p_or_n != NOTICE)
571 sendto_one(source_p, form_str(RPL_TARGNOTIFY),
572 ID_or_name(&me, source_p->from),
573 ID_or_name(source_p, source_p->from), target_p->name);
574
575 sendto_one(target_p, form_str(RPL_UMODEGMSG),
576 me.name, target_p->name,
577 get_client_name(source_p, HIDE_IP));
578
579 target_p->localClient->last_caller_id_time = CurrentTime;
580
581 }
582 /* Only so opers can watch for floods */
583 flood_attack_client(p_or_n, source_p, target_p);
584 }
585 }
586 else
587 {
588 /* If the client is remote, we dont perform a special check for
589 * flooding.. as we wouldnt block their message anyway.. this means
590 * we dont give warnings.. we then check if theyre opered
591 * (to avoid flood warnings), lastly if theyre our client
592 * and flooding -- fl */
593 if (!MyClient(source_p) || HasUMode(source_p, UMODE_OPER) ||
594 (MyClient(source_p) &&
595 !flood_attack_client(p_or_n, source_p, target_p)))
596 sendto_anywhere(target_p, source_p, "%s %s :%s",
597 command, target_p->name, text);
598 }
599 }
600 else
601 /* The target is a remote user.. same things apply -- fl */
602 if (!MyClient(source_p) || HasUMode(source_p, UMODE_OPER) ||
603 (MyClient(source_p)
604 && !flood_attack_client(p_or_n, source_p, target_p)))
605 sendto_anywhere(target_p, source_p, "%s %s :%s", command, target_p->name,
606 text);
607 }
608
609 /* flood_attack_client()
610 *
611 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
612 * say NOTICE must not auto reply
613 * - pointer to source Client
614 * - pointer to target Client
615 * output - 1 if target is under flood attack
616 * side effects - check for flood attack on target target_p
617 */
618 static int
619 flood_attack_client(int p_or_n, struct Client *source_p,
620 struct Client *target_p)
621 {
622 int delta;
623
624 if (GlobalSetOptions.floodcount && MyConnect(target_p)
625 && IsClient(source_p) && !IsConfCanFlood(source_p))
626 {
627 if ((target_p->localClient->first_received_message_time + 1)
628 < CurrentTime)
629 {
630 delta =
631 CurrentTime - target_p->localClient->first_received_message_time;
632 target_p->localClient->received_number_of_privmsgs -= delta;
633 target_p->localClient->first_received_message_time = CurrentTime;
634
635 if (target_p->localClient->received_number_of_privmsgs <= 0)
636 {
637 target_p->localClient->received_number_of_privmsgs = 0;
638 DelFlag(target_p, FLAGS_FLOOD_NOTICED);
639 }
640 }
641
642 if ((target_p->localClient->received_number_of_privmsgs >=
643 GlobalSetOptions.floodcount) || HasFlag(target_p, FLAGS_FLOOD_NOTICED))
644 {
645 if (!HasFlag(target_p, FLAGS_FLOOD_NOTICED))
646 {
647 sendto_realops_flags(UMODE_BOTS, L_ALL,
648 "Possible Flooder %s on %s target: %s",
649 get_client_name(source_p, HIDE_IP),
650 source_p->servptr->name, target_p->name);
651 AddFlag(target_p, FLAGS_FLOOD_NOTICED);
652 /* add a bit of penalty */
653 target_p->localClient->received_number_of_privmsgs += 2;
654 }
655
656 if (MyClient(source_p) && (p_or_n != NOTICE))
657 sendto_one(source_p,
658 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
659 me.name, source_p->name, target_p->name);
660 return(1);
661 }
662 else
663 target_p->localClient->received_number_of_privmsgs++;
664 }
665
666 return(0);
667 }
668
669 /* flood_attack_channel()
670 *
671 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
672 * says NOTICE must not auto reply
673 * - pointer to source Client
674 * - pointer to target channel
675 * output - 1 if target is under flood attack
676 * side effects - check for flood attack on target chptr
677 */
678 static int
679 flood_attack_channel(int p_or_n, struct Client *source_p,
680 struct Channel *chptr, char *chname)
681 {
682 int delta;
683
684 if (GlobalSetOptions.floodcount && !IsConfCanFlood(source_p))
685 {
686 if ((chptr->first_received_message_time + 1) < CurrentTime)
687 {
688 delta = CurrentTime - chptr->first_received_message_time;
689 chptr->received_number_of_privmsgs -= delta;
690 chptr->first_received_message_time = CurrentTime;
691 if (chptr->received_number_of_privmsgs <= 0)
692 {
693 chptr->received_number_of_privmsgs = 0;
694 ClearFloodNoticed(chptr);
695 }
696 }
697
698 if ((chptr->received_number_of_privmsgs >= GlobalSetOptions.floodcount)
699 || IsSetFloodNoticed(chptr))
700 {
701 if (!IsSetFloodNoticed(chptr))
702 {
703 sendto_realops_flags(UMODE_BOTS, L_ALL,
704 "Possible Flooder %s on %s target: %s",
705 get_client_name(source_p, HIDE_IP),
706 source_p->servptr->name, chptr->chname);
707 SetFloodNoticed(chptr);
708
709 /* Add a bit of penalty */
710 chptr->received_number_of_privmsgs += 2;
711 }
712 if (MyClient(source_p) && (p_or_n != NOTICE))
713 sendto_one(source_p,
714 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
715 me.name, source_p->name, chname);
716 return(1);
717 }
718 else
719 chptr->received_number_of_privmsgs++;
720 }
721
722 return(0);
723 }
724
725 /* handle_special()
726 *
727 * inputs - server pointer
728 * - client pointer
729 * - nick stuff to grok for opers
730 * - text to send if grok
731 * output - none
732 * side effects - old style username@server is handled here for non opers
733 * opers are allowed username%hostname@server
734 * all the traditional oper type messages are also parsed here.
735 * i.e. "/msg #some.host."
736 * However, syntax has been changed.
737 * previous syntax "/msg #some.host.mask"
738 * now becomes "/msg $#some.host.mask"
739 * previous syntax of: "/msg $some.server.mask" remains
740 * This disambiguates the syntax.
741 *
742 * XXX N.B. dalnet changed it to nick@server as have other servers.
743 * we will stick with tradition for now.
744 * - Dianora
745 */
746 static void
747 handle_special(int p_or_n, const char *command, struct Client *client_p,
748 struct Client *source_p, char *nick, char *text)
749 {
750 struct Client *target_p;
751 char *host;
752 char *server;
753 char *s;
754 int count;
755
756 /*
757 * user[%host]@server addressed?
758 */
759 if ((server = strchr(nick, '@')) != NULL)
760 {
761 count = 0;
762
763 if ((host = strchr(nick, '%')) && !HasUMode(source_p, UMODE_OPER))
764 {
765 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
766 ID_or_name(&me, client_p),
767 ID_or_name(source_p, client_p));
768 return;
769 }
770
771 if ((target_p = hash_find_server(server + 1)) != NULL)
772 {
773 if (!IsMe(target_p))
774 {
775 /*
776 * Not destined for a user on me :-(
777 */
778 sendto_one(target_p, ":%s %s %s :%s",
779 ID_or_name(source_p, target_p->from),
780 command, nick, text);
781 if ((p_or_n != NOTICE) && MyClient(source_p))
782 source_p->localClient->last_privmsg = CurrentTime;
783 return;
784 }
785
786 *server = '\0';
787
788 if (host != NULL)
789 *host++ = '\0';
790
791 /* Check if someones msg'ing opers@our.server */
792 if (strcmp(nick, "opers") == 0)
793 {
794 if (!HasUMode(source_p, UMODE_OPER))
795 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
796 ID_or_name(&me, client_p),
797 ID_or_name(source_p, client_p));
798 else
799 sendto_realops_flags(UMODE_ALL, L_ALL, "To opers: From: %s: %s",
800 source_p->name, text);
801 return;
802 }
803
804 /*
805 * Look for users which match the destination host
806 * (no host == wildcard) and if one and one only is
807 * found connected to me, deliver message!
808 */
809 target_p = find_userhost(nick, host, &count);
810
811 if (target_p != NULL)
812 {
813 if (server != NULL)
814 *server = '@';
815 if (host != NULL)
816 *--host = '%';
817
818 if (count == 1)
819 {
820 sendto_one(target_p, ":%s!%s@%s %s %s :%s",
821 source_p->name, source_p->username, source_p->host,
822 command, nick, text);
823 if ((p_or_n != NOTICE) && MyClient(source_p))
824 source_p->localClient->last_privmsg = CurrentTime;
825 }
826 else
827 sendto_one(source_p, form_str(ERR_TOOMANYTARGETS),
828 ID_or_name(&me, client_p),
829 ID_or_name(source_p, client_p), nick,
830 ConfigFileEntry.max_targets);
831 }
832 }
833 else if (server && *(server+1) && (target_p == NULL))
834 sendto_one(source_p, form_str(ERR_NOSUCHSERVER),
835 ID_or_name(&me, client_p),
836 ID_or_name(source_p, client_p), server+1);
837 else if (server && (target_p == NULL))
838 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
839 ID_or_name(&me, client_p),
840 ID_or_name(source_p, client_p), nick);
841 return;
842 }
843
844 if (!HasUMode(source_p, UMODE_OPER))
845 {
846 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
847 ID_or_name(&me, client_p),
848 ID_or_name(source_p, client_p));
849 return;
850 }
851
852 /*
853 * the following two cases allow masks in NOTICEs
854 * (for OPERs only)
855 *
856 * Armin, 8Jun90 (gruner@informatik.tu-muenchen.de)
857 */
858 if (*nick == '$')
859 {
860 if ((*(nick+1) == '$' || *(nick+1) == '#'))
861 nick++;
862 else if (MyClient(source_p) && HasUMode(source_p, UMODE_OPER))
863 {
864 sendto_one(source_p,
865 ":%s NOTICE %s :The command %s %s is no longer supported, please use $%s",
866 me.name, source_p->name, command, nick, nick);
867 return;
868 }
869
870 if ((s = strrchr(nick, '.')) == NULL)
871 {
872 sendto_one(source_p, form_str(ERR_NOTOPLEVEL),
873 me.name, source_p->name, nick);
874 return;
875 }
876
877 while (*++s)
878 if (*s == '.' || *s == '*' || *s == '?')
879 break;
880
881 if (*s == '*' || *s == '?')
882 {
883 sendto_one(source_p, form_str(ERR_WILDTOPLEVEL),
884 ID_or_name(&me, client_p),
885 ID_or_name(source_p, client_p), nick);
886 return;
887 }
888
889 sendto_match_butone(IsServer(client_p) ? client_p : NULL, source_p,
890 nick + 1, (*nick == '#') ? MATCH_HOST : MATCH_SERVER,
891 "%s $%s :%s", command, nick, text);
892
893 if ((p_or_n != NOTICE) && MyClient(source_p))
894 source_p->localClient->last_privmsg = CurrentTime;
895
896 return;
897 }
898 }
899
900 /*
901 * find_userhost - find a user@host (server or user).
902 * inputs - user name to look for
903 * - host name to look for
904 * - pointer to count of number of matches found
905 * outputs - pointer to client if found
906 * - count is updated
907 * side effects - none
908 *
909 */
910 static struct Client *
911 find_userhost(char *user, char *host, int *count)
912 {
913 struct Client *c2ptr;
914 struct Client *res = NULL;
915 dlink_node *lc2ptr;
916
917 *count = 0;
918
919 if (collapse(user) != NULL)
920 {
921 DLINK_FOREACH(lc2ptr, local_client_list.head)
922 {
923 c2ptr = lc2ptr->data;
924
925 if (!IsClient(c2ptr)) /* something other than a client */
926 continue;
927
928 if ((!host || match(host, c2ptr->host)) &&
929 irccmp(user, c2ptr->username) == 0)
930 {
931 (*count)++;
932 res = c2ptr;
933 }
934 }
935 }
936
937 return(res);
938 }
939
940 static struct Message privmsg_msgtab = {
941 "PRIVMSG", 0, 0, 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
942 {m_unregistered, m_privmsg, m_privmsg, m_ignore, m_privmsg, m_ignore}
943 };
944
945 static struct Message notice_msgtab = {
946 "NOTICE", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
947 {m_unregistered, m_notice, m_notice, m_ignore, m_notice, m_ignore}
948 };
949
950 static void
951 module_init(void)
952 {
953 mod_add_cmd(&privmsg_msgtab);
954 mod_add_cmd(&notice_msgtab);
955 }
956
957 static void
958 module_exit(void)
959 {
960 mod_del_cmd(&privmsg_msgtab);
961 mod_del_cmd(&notice_msgtab);
962 }
963
964 struct module module_entry = {
965 .node = { NULL, NULL, NULL },
966 .name = NULL,
967 .version = "$Revision$",
968 .handle = NULL,
969 .modinit = module_init,
970 .modexit = module_exit,
971 .flags = MODULE_FLAG_CORE
972 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision