ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/core/m_message.c
Revision: 3972
Committed: Wed Jun 18 11:40:12 2014 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 21513 byte(s)
Log Message:
- m_message.c: update client->localClient->last_privmsg in m_privmsg()

File Contents

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

Properties

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