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: 1121
Committed: Sun Jan 9 11:03:03 2011 UTC (13 years, 2 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.3/modules/core/m_message.c
File size: 28287 byte(s)
Log Message:
- removed all instances of STATIC_MODULES since we don't have
  static modules anymore
- removed m_mkpasswd module from contrib

File Contents

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

Properties

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