ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/core/m_message.c
Revision: 3164
Committed: Sat Mar 15 20:19:15 2014 UTC (10 years, 1 month ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/core/m_message.c
File size: 24110 byte(s)
Log Message:
- More client_p removal cleanups
- parse.c:handle_command: now no longer drop servers if the right
  amount of parameters isn't given

File Contents

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

Properties

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