2 * ircd-ratbox: A slightly useful ircd.
3 * m_message.c: Sends a (PRIVMSG|NOTICE) message to a user or channel.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: m_message.c 3173 2007-01-31 23:57:18Z jilles $
44 #include "s_newconf.h"
47 #include "inline/stringops.h"
48 #include "irc_dictionary.h"
50 static int m_message(int, const char *, struct Client
*, struct Client
*, int, const char **);
51 static int m_privmsg(struct Client
*, struct Client
*, int, const char **);
52 static int m_notice(struct Client
*, struct Client
*, int, const char **);
54 static void expire_tgchange(void *unused
);
55 static struct ev_entry
*expire_tgchange_event
;
60 expire_tgchange_event
= rb_event_addish("expire_tgchange", expire_tgchange
, NULL
, 300);
61 expire_tgchange(NULL
);
68 rb_event_delete(expire_tgchange_event
);
71 struct Message privmsg_msgtab
= {
72 "PRIVMSG", 0, 0, 0, MFLG_SLOW
| MFLG_UNREG
,
73 {mg_unreg
, {m_privmsg
, 0}, {m_privmsg
, 0}, mg_ignore
, mg_ignore
, {m_privmsg
, 0}}
75 struct Message notice_msgtab
= {
76 "NOTICE", 0, 0, 0, MFLG_SLOW
,
77 {mg_unreg
, {m_notice
, 0}, {m_notice
, 0}, {m_notice
, 0}, mg_ignore
, {m_notice
, 0}}
80 mapi_clist_av1 message_clist
[] = { &privmsg_msgtab
, ¬ice_msgtab
, NULL
};
82 DECLARE_MODULE_AV1(message
, modinit
, moddeinit
, message_clist
, NULL
, NULL
, "$Revision: 3173 $");
91 static int build_target_list(int p_or_n
, const char *command
,
92 struct Client
*client_p
,
93 struct Client
*source_p
, const char *nicks_channels
, const char *text
);
95 static int flood_attack_client(int p_or_n
, struct Client
*source_p
, struct Client
*target_p
);
96 static int flood_attack_channel(int p_or_n
, struct Client
*source_p
,
97 struct Channel
*chptr
, char *chname
);
99 /* Fifteen seconds should be plenty for a client to reply a ctcp */
100 #define LARGE_CTCP_TIME 15
102 #define ENTITY_NONE 0
103 #define ENTITY_CHANNEL 1
104 #define ENTITY_CHANNEL_OPMOD 2
105 #define ENTITY_CHANOPS_ON_CHANNEL 3
106 #define ENTITY_CLIENT 4
108 static struct entity targets
[512];
109 static int ntargets
= 0;
111 static int duplicate_ptr(void *);
113 static void msg_channel(int p_or_n
, const char *command
,
114 struct Client
*client_p
,
115 struct Client
*source_p
, struct Channel
*chptr
, const char *text
);
117 static void msg_channel_opmod(int p_or_n
, const char *command
,
118 struct Client
*client_p
,
119 struct Client
*source_p
, struct Channel
*chptr
,
122 static void msg_channel_flags(int p_or_n
, const char *command
,
123 struct Client
*client_p
,
124 struct Client
*source_p
,
125 struct Channel
*chptr
, int flags
, const char *text
);
127 static void msg_client(int p_or_n
, const char *command
,
128 struct Client
*source_p
, struct Client
*target_p
, const char *text
);
130 static void handle_special(int p_or_n
, const char *command
,
131 struct Client
*client_p
, struct Client
*source_p
, const char *nick
,
140 ** Another massive cleanup Nov, 2000
141 ** (I don't think there is a single line left from 6/91. Maybe.)
142 ** m_privmsg and m_notice do basically the same thing.
143 ** in the original 2.8.2 code base, they were the same function
144 ** "m_message.c." When we did the great cleanup in conjuncton with bleep
145 ** of ircu fame, we split m_privmsg.c and m_notice.c.
146 ** I don't see the point of that now. Its harder to maintain, its
147 ** easier to introduce bugs into one version and not the other etc.
148 ** Really, the penalty of an extra function call isn't that big a deal folks.
157 m_privmsg(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
159 return m_message(PRIVMSG
, "PRIVMSG", client_p
, source_p
, parc
, parv
);
163 m_notice(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
165 return m_message(NOTICE
, "NOTICE", client_p
, source_p
, parc
, parv
);
169 * inputs - flag privmsg or notice
170 * - pointer to command "PRIVMSG" or "NOTICE"
171 * - pointer to client_p
172 * - pointer to source_p
173 * - pointer to channel
176 m_message(int p_or_n
,
178 struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
182 if(parc
< 2 || EmptyString(parv
[1]))
185 sendto_one(source_p
, form_str(ERR_NORECIPIENT
), me
.name
,
186 source_p
->name
, command
);
190 if(parc
< 3 || EmptyString(parv
[2]))
193 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
197 /* Finish the flood grace period if theyre not messaging themselves
198 * as some clients (ircN) do this as a "lag check"
200 if(MyClient(source_p
) && !IsFloodDone(source_p
) && irccmp(source_p
->name
, parv
[1]))
201 flood_endgrace(source_p
);
203 if(build_target_list(p_or_n
, command
, client_p
, source_p
, parv
[1], parv
[2]) < 0)
208 for(i
= 0; i
< ntargets
; i
++)
210 switch (targets
[i
].type
)
213 msg_channel(p_or_n
, command
, client_p
, source_p
,
214 (struct Channel
*) targets
[i
].ptr
, parv
[2]);
217 case ENTITY_CHANNEL_OPMOD
:
218 msg_channel_opmod(p_or_n
, command
, client_p
, source_p
,
219 (struct Channel
*) targets
[i
].ptr
, parv
[2]);
222 case ENTITY_CHANOPS_ON_CHANNEL
:
223 msg_channel_flags(p_or_n
, command
, client_p
, source_p
,
224 (struct Channel
*) targets
[i
].ptr
,
225 targets
[i
].flags
, parv
[2]);
229 msg_client(p_or_n
, command
, source_p
,
230 (struct Client
*) targets
[i
].ptr
, parv
[2]);
241 * inputs - pointer to given client_p (server)
242 * - pointer to given source (oper/client etc.)
243 * - pointer to list of nicks/channels
244 * - pointer to table to place results
245 * - pointer to text (only used if source_p is an oper)
246 * output - number of valid entities
247 * side effects - target_table is modified to contain a list of
248 * pointers to channels or clients
249 * if source client is an oper
250 * all the classic old bizzare oper privmsg tricks
251 * are parsed and sent as is, if prefixed with $
257 build_target_list(int p_or_n
, const char *command
, struct Client
*client_p
,
258 struct Client
*source_p
, const char *nicks_channels
, const char *text
)
261 char *p
, *nick
, *target_list
;
262 struct Channel
*chptr
= NULL
;
263 struct Client
*target_p
;
265 target_list
= LOCAL_COPY(nicks_channels
); /* skip strcpy for non-lazyleafs */
269 for(nick
= rb_strtok_r(target_list
, ",", &p
); nick
; nick
= rb_strtok_r(NULL
, ",", &p
))
273 * channels are privmsg'd a lot more than other clients, moved up
274 * here plain old channel msg?
277 if(IsChanPrefix(*nick
))
279 /* ignore send of local channel to a server (should not happen) */
280 if(IsServer(client_p
) && *nick
== '&')
283 if((chptr
= find_channel(nick
)) != NULL
)
285 if(!duplicate_ptr(chptr
))
287 if(ntargets
>= ConfigFileEntry
.max_targets
)
289 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
290 me
.name
, source_p
->name
, nick
);
293 targets
[ntargets
].ptr
= (void *) chptr
;
294 targets
[ntargets
++].type
= ENTITY_CHANNEL
;
298 /* non existant channel */
299 else if(p_or_n
!= NOTICE
)
300 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
301 form_str(ERR_NOSUCHNICK
), nick
);
306 if(MyClient(source_p
))
307 target_p
= find_named_person(nick
);
309 target_p
= find_person(nick
);
311 /* look for a privmsg to another client */
314 if(!duplicate_ptr(target_p
))
316 if(ntargets
>= ConfigFileEntry
.max_targets
)
318 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
319 me
.name
, source_p
->name
, nick
);
322 targets
[ntargets
].ptr
= (void *) target_p
;
323 targets
[ntargets
].type
= ENTITY_CLIENT
;
324 targets
[ntargets
++].flags
= 0;
329 /* @#channel or +#channel message ? */
333 /* allow %+@ if someone wants to do that */
338 else if(*nick
== '+')
339 type
|= CHFL_CHANOP
| CHFL_VOICE
;
348 if(EmptyString(nick
))
350 sendto_one(source_p
, form_str(ERR_NORECIPIENT
),
351 me
.name
, source_p
->name
, command
);
355 /* At this point, nick+1 should be a channel name i.e. #foo or &foo
356 * if the channel is found, fine, if not report an error
359 if((chptr
= find_channel(nick
)) != NULL
)
361 struct membership
*msptr
;
363 msptr
= find_channel_membership(chptr
, source_p
);
365 if(!IsServer(source_p
) && !IsService(source_p
) && !is_chanop_voiced(msptr
))
367 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
368 get_id(&me
, source_p
),
369 get_id(source_p
, source_p
),
374 if(!duplicate_ptr(chptr
))
376 if(ntargets
>= ConfigFileEntry
.max_targets
)
378 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
379 me
.name
, source_p
->name
, nick
);
382 targets
[ntargets
].ptr
= (void *) chptr
;
383 targets
[ntargets
].type
= ENTITY_CHANOPS_ON_CHANNEL
;
384 targets
[ntargets
++].flags
= type
;
387 else if(p_or_n
!= NOTICE
)
389 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
390 form_str(ERR_NOSUCHNICK
), nick
);
396 if(IsServer(client_p
) && *nick
== '=' && nick
[1] == '#')
399 if((chptr
= find_channel(nick
)) != NULL
)
401 if(!duplicate_ptr(chptr
))
403 if(ntargets
>= ConfigFileEntry
.max_targets
)
405 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
406 me
.name
, source_p
->name
, nick
);
409 targets
[ntargets
].ptr
= (void *) chptr
;
410 targets
[ntargets
++].type
= ENTITY_CHANNEL_OPMOD
;
414 /* non existant channel */
415 else if(p_or_n
!= NOTICE
)
416 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
417 form_str(ERR_NOSUCHNICK
), nick
);
422 if(strchr(nick
, '@') || (IsOper(source_p
) && (*nick
== '$')))
424 handle_special(p_or_n
, command
, client_p
, source_p
, nick
, text
);
428 /* no matching anything found - error if not NOTICE */
431 /* dont give this numeric when source is local,
432 * because its misleading --anfl
434 if(!MyClient(source_p
) && IsDigit(*nick
))
435 sendto_one(source_p
, ":%s %d %s * :Target left IRC. "
436 "Failed to deliver: [%.20s]",
437 get_id(&me
, source_p
), ERR_NOSUCHNICK
,
438 get_id(source_p
, source_p
), text
);
440 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
441 form_str(ERR_NOSUCHNICK
), nick
);
451 * inputs - pointer to check
452 * - pointer to table of entities
453 * - number of valid entities so far
454 * output - YES if duplicate pointer in table, NO if not.
455 * note, this does the canonize using pointers
456 * side effects - NONE
459 duplicate_ptr(void *ptr
)
462 for(i
= 0; i
< ntargets
; i
++)
463 if(targets
[i
].ptr
== ptr
)
471 * inputs - flag privmsg or notice
472 * - pointer to command "PRIVMSG" or "NOTICE"
473 * - pointer to client_p
474 * - pointer to source_p
475 * - pointer to channel
477 * side effects - message given channel
479 * XXX - We need to rework this a bit, it's a tad ugly. --nenolod
482 msg_channel(int p_or_n
, const char *command
,
483 struct Client
*client_p
, struct Client
*source_p
, struct Channel
*chptr
,
491 struct membership
*msptr
= find_channel_membership(chptr
, source_p
);
494 if(MyClient(source_p
))
496 /* idle time shouldnt be reset by notices --fl */
498 source_p
->localClient
->last
= rb_current_time();
501 if(chptr
->mode
.mode
& MODE_NOREPEAT
)
503 rb_strlcpy(text2
, text
, BUFSIZE
);
504 strip_unprintable(text2
);
505 md
= channel_metadata_find(chptr
, "NOREPEAT");
506 if(md
&& (!ConfigChannel
.exempt_cmode_K
|| !is_any_op(msptr
)))
508 if(!(strcmp(md
->value
, text2
)))
511 sendto_one_numeric(source_p
, 404, "%s :Cannot send to channel - Message blocked due to repeating (+K set)", chptr
->chname
);
515 channel_metadata_delete(chptr
, "NOREPEAT", 0);
516 channel_metadata_add(chptr
, "NOREPEAT", text2
, 0);
519 if(chptr
->mode
.mode
& MODE_NOCOLOR
&& (!ConfigChannel
.exempt_cmode_c
|| !is_any_op(msptr
)))
521 rb_strlcpy(text2
, text
, BUFSIZE
);
524 if (EmptyString(text
))
526 /* could be empty after colour stripping and
527 * that would cause problems later */
529 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
534 /* chanops and voiced can flood their own channel with impunity */
535 if((result
= can_send(chptr
, source_p
, NULL
)))
537 if(result
== CAN_SEND_OPV
||
538 !flood_attack_channel(p_or_n
, source_p
, chptr
, chptr
->chname
))
540 if (strlen(text
) > 10 && chptr
->mode
.mode
& MODE_NOCAPS
&& (!ConfigChannel
.exempt_cmode_G
|| !is_any_op(msptr
)))
542 rb_strlcpy(text2
, text
, BUFSIZE
);
543 strip_unprintable(text2
);
544 for(contor
=0; contor
< strlen(text2
); contor
++)
546 if(IsUpper(text2
[contor
]) && !isdigit(text2
[contor
]))
550 if(((caps
*100)/(len
)) >= 50)
552 sendto_one_numeric(source_p
, 404, "%s :Cannot send to channel - Your message contains mostly capital letters (+G set)", chptr
->chname
);
556 if (p_or_n
!= PRIVMSG
&& chptr
->mode
.mode
& MODE_NONOTICE
&& (!ConfigChannel
.exempt_cmode_T
|| !is_any_op(msptr
)))
558 sendto_one_numeric(source_p
, 404, "%s :Cannot send to channel - Notices are disallowed (+T set)", chptr
->chname
);
561 if (p_or_n
!= NOTICE
&& chptr
->mode
.mode
& MODE_NOACTION
&&
562 !strncasecmp(text
+ 1, "ACTION", 6) &&
563 (!ConfigChannel
.exempt_cmode_D
|| !is_any_op(msptr
)))
565 sendto_one_numeric(source_p
, 404, "%s :Cannot send to channel - ACTIONs are disallowed (+D set)", chptr
->chname
);
568 if (p_or_n
!= NOTICE
&& *text
== '\001' &&
569 strncasecmp(text
+ 1, "ACTION", 6))
571 if (chptr
->mode
.mode
& MODE_NOCTCP
&& (!ConfigChannel
.exempt_cmode_C
|| !is_any_op(msptr
)))
573 sendto_one_numeric(source_p
, 404, "%s :Cannot send to channel - CTCPs to this channel are disallowed (+C set)", chptr
->chname
);
576 else if (rb_dlink_list_length(&chptr
->locmembers
) > (unsigned)(GlobalSetOptions
.floodcount
/ 2))
577 source_p
->large_ctcp_sent
= rb_current_time();
579 sendto_channel_flags(client_p
, ALL_MEMBERS
, source_p
, chptr
,
580 "%s %s :%s", command
, chptr
->chname
, text
);
583 else if(chptr
->mode
.mode
& MODE_OPMODERATE
&&
584 (!(chptr
->mode
.mode
& MODE_NOPRIVMSGS
) ||
585 IsMember(source_p
, chptr
)))
587 if(!flood_attack_channel(p_or_n
, source_p
, chptr
, chptr
->chname
))
589 sendto_channel_opmod(client_p
, source_p
, chptr
,
596 sendto_one_numeric(source_p
, ERR_CANNOTSENDTOCHAN
,
597 form_str(ERR_CANNOTSENDTOCHAN
), chptr
->chname
);
603 * inputs - flag privmsg or notice
604 * - pointer to command "PRIVMSG" or "NOTICE"
605 * - pointer to client_p
606 * - pointer to source_p
607 * - pointer to channel
609 * side effects - message given channel ops
611 * XXX - We need to rework this a bit, it's a tad ugly. --nenolod
614 msg_channel_opmod(int p_or_n
, const char *command
,
615 struct Client
*client_p
, struct Client
*source_p
,
616 struct Channel
*chptr
, const char *text
)
620 if(chptr
->mode
.mode
& MODE_NOCOLOR
)
622 rb_strlcpy(text2
, text
, BUFSIZE
);
625 if (EmptyString(text
))
627 /* could be empty after colour stripping and
628 * that would cause problems later */
630 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
635 if(chptr
->mode
.mode
& MODE_OPMODERATE
&&
636 (!(chptr
->mode
.mode
& MODE_NOPRIVMSGS
) ||
637 IsMember(source_p
, chptr
)))
639 if(!flood_attack_channel(p_or_n
, source_p
, chptr
, chptr
->chname
))
641 sendto_channel_opmod(client_p
, source_p
, chptr
,
648 sendto_one_numeric(source_p
, ERR_CANNOTSENDTOCHAN
,
649 form_str(ERR_CANNOTSENDTOCHAN
), chptr
->chname
);
656 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
657 * say NOTICE must not auto reply
658 * - pointer to command, "PRIVMSG" or "NOTICE"
659 * - pointer to client_p
660 * - pointer to source_p
661 * - pointer to channel
663 * - pointer to text to send
665 * side effects - message given channel either chanop or voice
668 msg_channel_flags(int p_or_n
, const char *command
, struct Client
*client_p
,
669 struct Client
*source_p
, struct Channel
*chptr
, int flags
, const char *text
)
674 if(flags
& CHFL_VOICE
)
676 type
= ONLY_CHANOPSVOICED
;
685 if(MyClient(source_p
))
687 /* idletime shouldnt be reset by notice --fl */
689 source_p
->localClient
->last
= rb_current_time();
692 sendto_channel_flags(client_p
, type
, source_p
, chptr
, "%s %c%s :%s",
693 command
, c
, chptr
->chname
, text
);
697 expire_tgchange(void *unused
)
700 rb_dlink_node
*ptr
, *next_ptr
;
702 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, tgchange_list
.head
)
706 if(target
->expiry
< rb_current_time())
708 rb_dlinkDelete(ptr
, &tgchange_list
);
709 rb_patricia_remove(tgchange_tree
, target
->pnode
);
719 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
720 * say NOTICE must not auto reply
721 * - pointer to command, "PRIVMSG" or "NOTICE"
722 * - pointer to source_p source (struct Client *)
723 * - pointer to target_p target (struct Client *)
726 * side effects - message given channel either chanop or voice
729 msg_client(int p_or_n
, const char *command
,
730 struct Client
*source_p
, struct Client
*target_p
, const char *text
)
732 int do_floodcount
= 0;
734 struct DictionaryIter iter
;
738 if(MyClient(source_p
))
740 /* reset idle time for message only if its not to self
741 * and its not a notice */
743 source_p
->localClient
->last
= rb_current_time();
745 /* auto cprivmsg/cnotice */
746 do_floodcount
= !IsOper(source_p
) &&
747 !find_allowing_channel(source_p
, target_p
);
749 /* target change stuff, dont limit ctcp replies as that
750 * would allow people to start filling up random users
751 * targets just by ctcping them
753 if((p_or_n
!= NOTICE
|| *text
!= '\001') &&
754 ConfigFileEntry
.target_change
&& do_floodcount
)
756 if(!add_target(source_p
, target_p
))
758 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
759 me
.name
, source_p
->name
, target_p
->name
);
764 if (do_floodcount
&& p_or_n
== NOTICE
&& *text
== '\001' &&
765 target_p
->large_ctcp_sent
+ LARGE_CTCP_TIME
>= rb_current_time())
769 flood_attack_client(p_or_n
, source_p
, target_p
))
772 else if(source_p
->from
== target_p
->from
)
774 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
775 "Send message to %s[%s] dropped from %s(Fake Dir)",
776 target_p
->name
, target_p
->from
->name
, source_p
->name
);
780 if(MyConnect(source_p
) && (p_or_n
!= NOTICE
) && target_p
->user
&& target_p
->user
->away
)
781 sendto_one_numeric(source_p
, RPL_AWAY
, form_str(RPL_AWAY
),
782 target_p
->name
, target_p
->user
->away
);
784 if(MyClient(target_p
))
786 if (IsSetNoCTCP(target_p
) && p_or_n
!= NOTICE
&& *text
== '\001' && strncasecmp(text
+ 1, "ACTION", 6))
788 sendto_one_numeric(source_p
, ERR_NOCTCP
,
789 form_str(ERR_NOCTCP
),
792 /* If opers want to go through +g, they should load oaccept.*/
793 else if(!IsServer(source_p
) && !IsService(source_p
) && (IsSetCallerId(target_p
) ||
794 (IsSetSCallerId(target_p
) && !has_common_channel(source_p
, target_p
)) ||
795 (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])))
797 if (IsOper(source_p
))
799 rb_snprintf(text3
, sizeof(text3
), "O%s", source_p
->id
);
800 DICTIONARY_FOREACH(md
, &iter
, target_p
->user
->metadata
)
802 if(!strcmp(md
->value
, "OACCEPT") && !strcmp(md
->name
, text3
))
809 /* Here is the anti-flood bot/spambot code -db */
810 if(accept_message(source_p
, target_p
) || oaccept
)
812 add_reply_target(target_p
, source_p
);
813 sendto_one(target_p
, ":%s!%s@%s %s %s :%s",
816 source_p
->host
, command
, target_p
->name
, text
);
818 else if (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])
820 if (p_or_n
!= NOTICE
)
821 sendto_one_numeric(source_p
, ERR_NONONREG
,
822 form_str(ERR_NONONREG
),
825 else if (IsSetSCallerId(target_p
) && !has_common_channel(source_p
, target_p
))
827 if (p_or_n
!= NOTICE
)
828 sendto_one_numeric(source_p
, ERR_NOCOMMONCHAN
,
829 form_str(ERR_NOCOMMONCHAN
),
834 /* check for accept, flag recipient incoming message */
837 sendto_one_numeric(source_p
, ERR_TARGUMODEG
,
838 form_str(ERR_TARGUMODEG
),
842 if((target_p
->localClient
->last_caller_id_time
+
843 ConfigFileEntry
.caller_id_wait
) < rb_current_time())
846 sendto_one_numeric(source_p
, RPL_TARGNOTIFY
,
847 form_str(RPL_TARGNOTIFY
),
850 add_reply_target(target_p
, source_p
);
851 sendto_one(target_p
, form_str(RPL_UMODEGMSG
),
852 me
.name
, target_p
->name
, source_p
->name
,
853 source_p
->username
, source_p
->host
);
855 target_p
->localClient
->last_caller_id_time
= rb_current_time();
861 add_reply_target(target_p
, source_p
);
862 sendto_anywhere(target_p
, source_p
, command
, ":%s", text
);
866 sendto_anywhere(target_p
, source_p
, command
, ":%s", text
);
872 * flood_attack_client
873 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
874 * say NOTICE must not auto reply
875 * - pointer to source Client
876 * - pointer to target Client
877 * output - 1 if target is under flood attack
878 * side effects - check for flood attack on target target_p
881 flood_attack_client(int p_or_n
, struct Client
*source_p
, struct Client
*target_p
)
885 /* Services could get many messages legitimately and
886 * can be messaged without rate limiting via aliases
887 * and msg user@server.
890 if(GlobalSetOptions
.floodcount
&& IsClient(source_p
) && source_p
!= target_p
&& !IsService(target_p
) && (!IsOper(source_p
) || !ConfigFileEntry
.true_no_oper_flood
))
892 if((target_p
->first_received_message_time
+ 1) < rb_current_time())
894 delta
= rb_current_time() - target_p
->first_received_message_time
;
895 target_p
->received_number_of_privmsgs
-= delta
;
896 target_p
->first_received_message_time
= rb_current_time();
897 if(target_p
->received_number_of_privmsgs
<= 0)
899 target_p
->received_number_of_privmsgs
= 0;
900 target_p
->flood_noticed
= 0;
904 if((target_p
->received_number_of_privmsgs
>=
905 GlobalSetOptions
.floodcount
) || target_p
->flood_noticed
)
907 if(target_p
->flood_noticed
== 0)
909 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
910 "Possible Flooder %s[%s@%s] on %s target: %s",
911 source_p
->name
, source_p
->username
,
913 source_p
->servptr
->name
, target_p
->name
);
914 target_p
->flood_noticed
= 1;
915 /* add a bit of penalty */
916 target_p
->received_number_of_privmsgs
+= 2;
918 if(MyClient(source_p
) && (p_or_n
!= NOTICE
))
920 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
921 me
.name
, source_p
->name
, target_p
->name
);
925 target_p
->received_number_of_privmsgs
++;
932 * flood_attack_channel
933 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
934 * says NOTICE must not auto reply
935 * - pointer to source Client
936 * - pointer to target channel
937 * output - 1 if target is under flood attack
938 * side effects - check for flood attack on target chptr
941 flood_attack_channel(int p_or_n
, struct Client
*source_p
, struct Channel
*chptr
, char *chname
)
945 if(GlobalSetOptions
.floodcount
&& MyClient(source_p
) && (!IsOper(source_p
) || !ConfigFileEntry
.true_no_oper_flood
))
947 if((chptr
->first_received_message_time
+ 1) < rb_current_time())
949 delta
= rb_current_time() - chptr
->first_received_message_time
;
950 chptr
->received_number_of_privmsgs
-= delta
;
951 chptr
->first_received_message_time
= rb_current_time();
952 if(chptr
->received_number_of_privmsgs
<= 0)
954 chptr
->received_number_of_privmsgs
= 0;
955 chptr
->flood_noticed
= 0;
959 if((chptr
->received_number_of_privmsgs
>= GlobalSetOptions
.floodcount
)
960 || chptr
->flood_noticed
)
962 if(chptr
->flood_noticed
== 0)
964 sendto_realops_snomask(SNO_BOTS
, *chptr
->chname
== '&' ? L_ALL
: L_NETWIDE
,
965 "Possible Flooder %s[%s@%s] on %s target: %s",
966 source_p
->name
, source_p
->username
,
968 source_p
->servptr
->name
, chptr
->chname
);
969 chptr
->flood_noticed
= 1;
971 /* Add a bit of penalty */
972 chptr
->received_number_of_privmsgs
+= 2;
974 if(MyClient(source_p
) && (p_or_n
!= NOTICE
))
976 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
977 me
.name
, source_p
->name
, chptr
->chname
);
981 chptr
->received_number_of_privmsgs
++;
991 * inputs - server pointer
993 * - nick stuff to grok for opers
994 * - text to send if grok
996 * side effects - all the traditional oper type messages are parsed here.
997 * i.e. "/msg #some.host."
998 * However, syntax has been changed.
999 * previous syntax "/msg #some.host.mask"
1000 * now becomes "/msg $#some.host.mask"
1001 * previous syntax of: "/msg $some.server.mask" remains
1002 * This disambiguates the syntax.
1005 handle_special(int p_or_n
, const char *command
, struct Client
*client_p
,
1006 struct Client
*source_p
, const char *nick
, const char *text
)
1008 struct Client
*target_p
;
1012 /* user[%host]@server addressed?
1013 * NOTE: users can send to user@server, but not user%host@server
1016 if((server
= strchr(nick
, '@')) != NULL
)
1018 if((target_p
= find_server(source_p
, server
+ 1)) == NULL
)
1020 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1021 form_str(ERR_NOSUCHSERVER
), server
+ 1);
1025 if(!IsOper(source_p
))
1027 if(strchr(nick
, '%') || (strncmp(nick
, "opers", 5) == 0))
1029 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
1030 form_str(ERR_NOSUCHNICK
), nick
);
1035 /* somewhere else.. */
1038 sendto_one(target_p
, ":%s %s %s :%s",
1039 get_id(source_p
, target_p
), command
, nick
, text
);
1043 /* Check if someones msg'ing opers@our.server */
1044 if(strncmp(nick
, "opers@", 6) == 0)
1046 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "To opers: From: %s: %s",
1047 source_p
->name
, text
);
1051 /* This was not very useful except for bypassing certain
1052 * restrictions. Note that we still allow sending to
1053 * remote servers this way, for messaging pseudoservers
1054 * securely whether they have a service{} block or not.
1057 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
1058 form_str(ERR_NOSUCHNICK
), nick
);
1063 * the following two cases allow masks in NOTICEs
1066 * Armin, 8Jun90 (gruner@informatik.tu-muenchen.de)
1068 if(IsOper(source_p
) && *nick
== '$')
1070 if((*(nick
+ 1) == '$' || *(nick
+ 1) == '#'))
1072 else if(MyOper(source_p
))
1074 sendto_one(source_p
,
1075 ":%s NOTICE %s :The command %s %s is no longer supported, please use $%s",
1076 me
.name
, source_p
->name
, command
, nick
, nick
);
1080 if(MyClient(source_p
) && !IsOperMassNotice(source_p
))
1082 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
1083 me
.name
, source_p
->name
, "mass_notice");
1087 if((s
= strrchr(nick
, '.')) == NULL
)
1089 sendto_one_numeric(source_p
, ERR_NOTOPLEVEL
,
1090 form_str(ERR_NOTOPLEVEL
), nick
);
1094 if(*s
== '.' || *s
== '*' || *s
== '?')
1096 if(*s
== '*' || *s
== '?')
1098 sendto_one_numeric(source_p
, ERR_WILDTOPLEVEL
,
1099 form_str(ERR_WILDTOPLEVEL
), nick
);
1103 sendto_match_butone(IsServer(client_p
) ? client_p
: NULL
, source_p
,
1105 (*nick
== '#') ? MATCH_HOST
: MATCH_SERVER
,
1106 "%s $%s :%s", command
, nick
, text
);
1107 if (p_or_n
!= NOTICE
&& *text
== '\001')
1108 source_p
->large_ctcp_sent
= rb_current_time();