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
43 #include "s_newconf.h"
46 #include "inline/stringops.h"
47 #include "irc_dictionary.h"
49 static int m_message(int, const char *, struct Client
*, struct Client
*, int, const char **);
50 static int m_privmsg(struct Client
*, struct Client
*, int, const char **);
51 static int m_notice(struct Client
*, struct Client
*, int, const char **);
53 static void expire_tgchange(void *unused
);
54 static struct ev_entry
*expire_tgchange_event
;
59 expire_tgchange_event
= rb_event_addish("expire_tgchange", expire_tgchange
, NULL
, 300);
60 expire_tgchange(NULL
);
67 rb_event_delete(expire_tgchange_event
);
70 struct Message privmsg_msgtab
= {
71 "PRIVMSG", 0, 0, 0, MFLG_SLOW
| MFLG_UNREG
,
72 {mg_unreg
, {m_privmsg
, 0}, {m_privmsg
, 0}, mg_ignore
, mg_ignore
, {m_privmsg
, 0}}
74 struct Message notice_msgtab
= {
75 "NOTICE", 0, 0, 0, MFLG_SLOW
,
76 {mg_unreg
, {m_notice
, 0}, {m_notice
, 0}, {m_notice
, 0}, mg_ignore
, {m_notice
, 0}}
79 mapi_clist_av1 message_clist
[] = { &privmsg_msgtab
, ¬ice_msgtab
, NULL
};
81 DECLARE_MODULE_AV1(message
, modinit
, moddeinit
, message_clist
, NULL
, NULL
, "$Revision: 3173 $");
90 static int build_target_list(int p_or_n
, const char *command
,
91 struct Client
*client_p
,
92 struct Client
*source_p
, const char *nicks_channels
, const char *text
);
94 static int flood_attack_client(int p_or_n
, struct Client
*source_p
, struct Client
*target_p
);
95 static int flood_attack_channel(int p_or_n
, struct Client
*source_p
,
96 struct Channel
*chptr
, char *chname
);
98 /* Fifteen seconds should be plenty for a client to reply a ctcp */
99 #define LARGE_CTCP_TIME 15
101 #define ENTITY_NONE 0
102 #define ENTITY_CHANNEL 1
103 #define ENTITY_CHANNEL_OPMOD 2
104 #define ENTITY_CHANOPS_ON_CHANNEL 3
105 #define ENTITY_CLIENT 4
107 static struct entity targets
[512];
108 static int ntargets
= 0;
110 static int duplicate_ptr(void *);
112 static void msg_channel(int p_or_n
, const char *command
,
113 struct Client
*client_p
,
114 struct Client
*source_p
, struct Channel
*chptr
, const char *text
);
116 static void msg_channel_opmod(int p_or_n
, const char *command
,
117 struct Client
*client_p
,
118 struct Client
*source_p
, struct Channel
*chptr
,
121 static void msg_channel_flags(int p_or_n
, const char *command
,
122 struct Client
*client_p
,
123 struct Client
*source_p
,
124 struct Channel
*chptr
, int flags
, const char *text
);
126 static void msg_client(int p_or_n
, const char *command
,
127 struct Client
*source_p
, struct Client
*target_p
, const char *text
);
129 static void handle_special(int p_or_n
, const char *command
,
130 struct Client
*client_p
, struct Client
*source_p
, const char *nick
,
139 ** Another massive cleanup Nov, 2000
140 ** (I don't think there is a single line left from 6/91. Maybe.)
141 ** m_privmsg and m_notice do basically the same thing.
142 ** in the original 2.8.2 code base, they were the same function
143 ** "m_message.c." When we did the great cleanup in conjuncton with bleep
144 ** of ircu fame, we split m_privmsg.c and m_notice.c.
145 ** I don't see the point of that now. Its harder to maintain, its
146 ** easier to introduce bugs into one version and not the other etc.
147 ** Really, the penalty of an extra function call isn't that big a deal folks.
156 m_privmsg(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
158 return m_message(PRIVMSG
, "PRIVMSG", client_p
, source_p
, parc
, parv
);
162 m_notice(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
164 return m_message(NOTICE
, "NOTICE", client_p
, source_p
, parc
, parv
);
168 * inputs - flag privmsg or notice
169 * - pointer to command "PRIVMSG" or "NOTICE"
170 * - pointer to client_p
171 * - pointer to source_p
172 * - pointer to channel
175 m_message(int p_or_n
,
177 struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
181 if(parc
< 2 || EmptyString(parv
[1]))
184 sendto_one(source_p
, form_str(ERR_NORECIPIENT
), me
.name
,
185 source_p
->name
, command
);
189 if(parc
< 3 || EmptyString(parv
[2]))
192 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
196 /* Finish the flood grace period if theyre not messaging themselves
197 * as some clients (ircN) do this as a "lag check"
199 if(MyClient(source_p
) && !IsFloodDone(source_p
) && irccmp(source_p
->name
, parv
[1]))
200 flood_endgrace(source_p
);
202 if(build_target_list(p_or_n
, command
, client_p
, source_p
, parv
[1], parv
[2]) < 0)
207 for(i
= 0; i
< ntargets
; i
++)
209 switch (targets
[i
].type
)
212 msg_channel(p_or_n
, command
, client_p
, source_p
,
213 (struct Channel
*) targets
[i
].ptr
, parv
[2]);
216 case ENTITY_CHANNEL_OPMOD
:
217 msg_channel_opmod(p_or_n
, command
, client_p
, source_p
,
218 (struct Channel
*) targets
[i
].ptr
, parv
[2]);
221 case ENTITY_CHANOPS_ON_CHANNEL
:
222 msg_channel_flags(p_or_n
, command
, client_p
, source_p
,
223 (struct Channel
*) targets
[i
].ptr
,
224 targets
[i
].flags
, parv
[2]);
228 msg_client(p_or_n
, command
, source_p
,
229 (struct Client
*) targets
[i
].ptr
, parv
[2]);
240 * inputs - pointer to given client_p (server)
241 * - pointer to given source (oper/client etc.)
242 * - pointer to list of nicks/channels
243 * - pointer to table to place results
244 * - pointer to text (only used if source_p is an oper)
245 * output - number of valid entities
246 * side effects - target_table is modified to contain a list of
247 * pointers to channels or clients
248 * if source client is an oper
249 * all the classic old bizzare oper privmsg tricks
250 * are parsed and sent as is, if prefixed with $
256 build_target_list(int p_or_n
, const char *command
, struct Client
*client_p
,
257 struct Client
*source_p
, const char *nicks_channels
, const char *text
)
260 char *p
, *nick
, *target_list
;
261 struct Channel
*chptr
= NULL
;
262 struct Client
*target_p
;
264 target_list
= LOCAL_COPY(nicks_channels
); /* skip strcpy for non-lazyleafs */
268 for(nick
= rb_strtok_r(target_list
, ",", &p
); nick
; nick
= rb_strtok_r(NULL
, ",", &p
))
272 * channels are privmsg'd a lot more than other clients, moved up
273 * here plain old channel msg?
276 if(IsChanPrefix(*nick
))
278 /* ignore send of local channel to a server (should not happen) */
279 if(IsServer(client_p
) && *nick
== '&')
282 if((chptr
= find_channel(nick
)) != NULL
)
284 if(!duplicate_ptr(chptr
))
286 if(ntargets
>= ConfigFileEntry
.max_targets
)
288 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
289 me
.name
, source_p
->name
, nick
);
292 targets
[ntargets
].ptr
= (void *) chptr
;
293 targets
[ntargets
++].type
= ENTITY_CHANNEL
;
297 /* non existant channel */
298 else if(p_or_n
!= NOTICE
)
299 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
300 form_str(ERR_NOSUCHNICK
), nick
);
305 if(MyClient(source_p
))
306 target_p
= find_named_person(nick
);
308 target_p
= find_person(nick
);
310 /* look for a privmsg to another client */
313 if(!duplicate_ptr(target_p
))
315 if(ntargets
>= ConfigFileEntry
.max_targets
)
317 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
318 me
.name
, source_p
->name
, nick
);
321 targets
[ntargets
].ptr
= (void *) target_p
;
322 targets
[ntargets
].type
= ENTITY_CLIENT
;
323 targets
[ntargets
++].flags
= 0;
328 /* @#channel or +#channel message ? */
332 /* allow %+@ if someone wants to do that */
337 else if(*nick
== '+')
338 type
|= CHFL_CHANOP
| CHFL_VOICE
;
347 if(EmptyString(nick
))
349 sendto_one(source_p
, form_str(ERR_NORECIPIENT
),
350 me
.name
, source_p
->name
, command
);
354 /* At this point, nick+1 should be a channel name i.e. #foo or &foo
355 * if the channel is found, fine, if not report an error
358 if((chptr
= find_channel(nick
)) != NULL
)
360 struct membership
*msptr
;
362 msptr
= find_channel_membership(chptr
, source_p
);
364 if(!IsServer(source_p
) && !IsService(source_p
) && !is_chanop_voiced(msptr
))
366 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
367 get_id(&me
, source_p
),
368 get_id(source_p
, source_p
),
373 if(!duplicate_ptr(chptr
))
375 if(ntargets
>= ConfigFileEntry
.max_targets
)
377 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
378 me
.name
, source_p
->name
, nick
);
381 targets
[ntargets
].ptr
= (void *) chptr
;
382 targets
[ntargets
].type
= ENTITY_CHANOPS_ON_CHANNEL
;
383 targets
[ntargets
++].flags
= type
;
386 else if(p_or_n
!= NOTICE
)
388 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
389 form_str(ERR_NOSUCHNICK
), nick
);
395 if(IsServer(client_p
) && *nick
== '=' && nick
[1] == '#')
398 if((chptr
= find_channel(nick
)) != NULL
)
400 if(!duplicate_ptr(chptr
))
402 if(ntargets
>= ConfigFileEntry
.max_targets
)
404 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
405 me
.name
, source_p
->name
, nick
);
408 targets
[ntargets
].ptr
= (void *) chptr
;
409 targets
[ntargets
++].type
= ENTITY_CHANNEL_OPMOD
;
413 /* non existant channel */
414 else if(p_or_n
!= NOTICE
)
415 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
416 form_str(ERR_NOSUCHNICK
), nick
);
421 if(strchr(nick
, '@') || (IsOper(source_p
) && (*nick
== '$')))
423 handle_special(p_or_n
, command
, client_p
, source_p
, nick
, text
);
427 /* no matching anything found - error if not NOTICE */
430 /* dont give this numeric when source is local,
431 * because its misleading --anfl
433 if(!MyClient(source_p
) && IsDigit(*nick
))
434 sendto_one(source_p
, ":%s %d %s * :Target left IRC. "
435 "Failed to deliver: [%.20s]",
436 get_id(&me
, source_p
), ERR_NOSUCHNICK
,
437 get_id(source_p
, source_p
), text
);
439 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
440 form_str(ERR_NOSUCHNICK
), nick
);
450 * inputs - pointer to check
451 * - pointer to table of entities
452 * - number of valid entities so far
453 * output - YES if duplicate pointer in table, NO if not.
454 * note, this does the canonize using pointers
455 * side effects - NONE
458 duplicate_ptr(void *ptr
)
461 for(i
= 0; i
< ntargets
; i
++)
462 if(targets
[i
].ptr
== ptr
)
470 * inputs - flag privmsg or notice
471 * - pointer to command "PRIVMSG" or "NOTICE"
472 * - pointer to client_p
473 * - pointer to source_p
474 * - pointer to channel
476 * side effects - message given channel
478 * XXX - We need to rework this a bit, it's a tad ugly. --nenolod
481 msg_channel(int p_or_n
, const char *command
,
482 struct Client
*client_p
, struct Client
*source_p
, struct Channel
*chptr
,
490 struct membership
*msptr
= find_channel_membership(chptr
, source_p
);
493 if(MyClient(source_p
))
495 /* idle time shouldnt be reset by notices --fl */
497 source_p
->localClient
->last
= rb_current_time();
500 if(chptr
->mode
.mode
& MODE_NOREPEAT
)
502 rb_strlcpy(text2
, text
, BUFSIZE
);
503 strip_unprintable(text2
);
504 md
= channel_metadata_find(chptr
, "NOREPEAT");
505 if(md
&& (!ConfigChannel
.exempt_cmode_K
|| !is_any_op(msptr
)))
507 if(!(strcmp(md
->value
, text2
)))
510 sendto_one_numeric(source_p
, 404, "%s :Cannot send to channel - Message blocked due to repeating (+K set)", chptr
->chname
);
514 channel_metadata_delete(chptr
, "NOREPEAT", 0);
515 channel_metadata_add(chptr
, "NOREPEAT", text2
, 0);
518 if(chptr
->mode
.mode
& MODE_NOCOLOR
&& (!ConfigChannel
.exempt_cmode_c
|| !is_any_op(msptr
)))
520 rb_strlcpy(text2
, text
, BUFSIZE
);
523 if (EmptyString(text
))
525 /* could be empty after colour stripping and
526 * that would cause problems later */
528 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
533 /* chanops and voiced can flood their own channel with impunity */
534 if((result
= can_send(chptr
, source_p
, NULL
)))
536 if(result
!= CAN_SEND_OPV
&& MyClient(source_p
) &&
538 !add_channel_target(source_p
, chptr
))
540 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
541 me
.name
, source_p
->name
, chptr
->chname
);
544 if(result
== CAN_SEND_OPV
||
545 !flood_attack_channel(p_or_n
, source_p
, chptr
, chptr
->chname
))
547 if (strlen(text
) > 10 && chptr
->mode
.mode
& MODE_NOCAPS
&& (!ConfigChannel
.exempt_cmode_G
|| !is_any_op(msptr
)))
549 rb_strlcpy(text2
, text
, BUFSIZE
);
550 strip_unprintable(text2
);
551 for(contor
=0; contor
< strlen(text2
); contor
++)
553 if(IsUpper(text2
[contor
]) && !isdigit(text2
[contor
]))
557 if(((caps
*100)/(len
)) >= 50)
559 sendto_one_numeric(source_p
, 404, "%s :Cannot send to channel - Your message contains mostly capital letters (+G set)", chptr
->chname
);
563 if (p_or_n
!= PRIVMSG
&& chptr
->mode
.mode
& MODE_NONOTICE
&& (!ConfigChannel
.exempt_cmode_T
|| !is_any_op(msptr
)))
565 sendto_one_numeric(source_p
, 404, "%s :Cannot send to channel - Notices are disallowed (+T set)", chptr
->chname
);
568 if (p_or_n
!= NOTICE
&& chptr
->mode
.mode
& MODE_NOACTION
&&
569 !strncasecmp(text
+ 1, "ACTION", 6) &&
570 (!ConfigChannel
.exempt_cmode_D
|| !is_any_op(msptr
)))
572 sendto_one_numeric(source_p
, 404, "%s :Cannot send to channel - ACTIONs are disallowed (+D set)", chptr
->chname
);
575 if (p_or_n
!= NOTICE
&& *text
== '\001' &&
576 strncasecmp(text
+ 1, "ACTION", 6))
578 if (chptr
->mode
.mode
& MODE_NOCTCP
&& (!ConfigChannel
.exempt_cmode_C
|| !is_any_op(msptr
)))
580 sendto_one_numeric(source_p
, 404, "%s :Cannot send to channel - CTCPs to this channel are disallowed (+C set)", chptr
->chname
);
583 else if (rb_dlink_list_length(&chptr
->locmembers
) > (unsigned)(GlobalSetOptions
.floodcount
/ 2))
584 source_p
->large_ctcp_sent
= rb_current_time();
586 sendto_channel_flags(client_p
, ALL_MEMBERS
, source_p
, chptr
,
587 "%s %s :%s", command
, chptr
->chname
, text
);
590 else if(chptr
->mode
.mode
& MODE_OPMODERATE
&&
591 (!(chptr
->mode
.mode
& MODE_NOPRIVMSGS
) ||
592 IsMember(source_p
, chptr
)))
594 if(MyClient(source_p
) && !IsOper(source_p
) &&
595 !add_channel_target(source_p
, chptr
))
597 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
598 me
.name
, source_p
->name
, chptr
->chname
);
601 if(!flood_attack_channel(p_or_n
, source_p
, chptr
, chptr
->chname
))
603 sendto_channel_opmod(client_p
, source_p
, chptr
,
610 sendto_one_numeric(source_p
, ERR_CANNOTSENDTOCHAN
,
611 form_str(ERR_CANNOTSENDTOCHAN
), chptr
->chname
);
617 * inputs - flag privmsg or notice
618 * - pointer to command "PRIVMSG" or "NOTICE"
619 * - pointer to client_p
620 * - pointer to source_p
621 * - pointer to channel
623 * side effects - message given channel ops
625 * XXX - We need to rework this a bit, it's a tad ugly. --nenolod
628 msg_channel_opmod(int p_or_n
, const char *command
,
629 struct Client
*client_p
, struct Client
*source_p
,
630 struct Channel
*chptr
, const char *text
)
634 if(chptr
->mode
.mode
& MODE_NOCOLOR
)
636 rb_strlcpy(text2
, text
, BUFSIZE
);
639 if (EmptyString(text
))
641 /* could be empty after colour stripping and
642 * that would cause problems later */
644 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
649 if(chptr
->mode
.mode
& MODE_OPMODERATE
&&
650 (!(chptr
->mode
.mode
& MODE_NOPRIVMSGS
) ||
651 IsMember(source_p
, chptr
)))
653 if(!flood_attack_channel(p_or_n
, source_p
, chptr
, chptr
->chname
))
655 sendto_channel_opmod(client_p
, source_p
, chptr
,
662 sendto_one_numeric(source_p
, ERR_CANNOTSENDTOCHAN
,
663 form_str(ERR_CANNOTSENDTOCHAN
), chptr
->chname
);
670 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
671 * say NOTICE must not auto reply
672 * - pointer to command, "PRIVMSG" or "NOTICE"
673 * - pointer to client_p
674 * - pointer to source_p
675 * - pointer to channel
677 * - pointer to text to send
679 * side effects - message given channel either chanop or voice
682 msg_channel_flags(int p_or_n
, const char *command
, struct Client
*client_p
,
683 struct Client
*source_p
, struct Channel
*chptr
, int flags
, const char *text
)
688 if(flags
& CHFL_VOICE
)
690 type
= ONLY_CHANOPSVOICED
;
699 if(MyClient(source_p
))
701 /* idletime shouldnt be reset by notice --fl */
703 source_p
->localClient
->last
= rb_current_time();
706 sendto_channel_flags(client_p
, type
, source_p
, chptr
, "%s %c%s :%s",
707 command
, c
, chptr
->chname
, text
);
711 expire_tgchange(void *unused
)
714 rb_dlink_node
*ptr
, *next_ptr
;
716 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, tgchange_list
.head
)
720 if(target
->expiry
< rb_current_time())
722 rb_dlinkDelete(ptr
, &tgchange_list
);
723 rb_patricia_remove(tgchange_tree
, target
->pnode
);
733 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
734 * say NOTICE must not auto reply
735 * - pointer to command, "PRIVMSG" or "NOTICE"
736 * - pointer to source_p source (struct Client *)
737 * - pointer to target_p target (struct Client *)
740 * side effects - message given channel either chanop or voice
743 msg_client(int p_or_n
, const char *command
,
744 struct Client
*source_p
, struct Client
*target_p
, const char *text
)
746 int do_floodcount
= 0;
748 struct DictionaryIter iter
;
752 if(MyClient(source_p
))
755 * XXX: Controversial? Allow target users to send replies
756 * through a +g. Rationale is that people can presently use +g
757 * as a way to taunt users, e.g. harass them and hide behind +g
758 * as a way of griefing. --nenolod
760 if(p_or_n
!= NOTICE
&& MyClient(source_p
) &&
761 IsSetCallerId(source_p
) &&
762 IsSetSCallerId(source_p
) &&
763 !accept_message(target_p
, source_p
))
765 if(rb_dlink_list_length(&source_p
->localClient
->allow_list
) <
766 ConfigFileEntry
.max_accept
)
768 rb_dlinkAddAlloc(target_p
, &source_p
->localClient
->allow_list
);
769 rb_dlinkAddAlloc(source_p
, &target_p
->on_allow_list
);
773 sendto_one_numeric(source_p
, ERR_OWNMODE
,
774 form_str(ERR_OWNMODE
),
775 target_p
->name
, "+g");
780 /* reset idle time for message only if its not to self
781 * and its not a notice */
783 source_p
->localClient
->last
= rb_current_time();
785 /* auto cprivmsg/cnotice */
786 do_floodcount
= !IsOper(source_p
) &&
787 !find_allowing_channel(source_p
, target_p
);
789 /* target change stuff, dont limit ctcp replies as that
790 * would allow people to start filling up random users
791 * targets just by ctcping them
793 if((p_or_n
!= NOTICE
|| *text
!= '\001') &&
794 ConfigFileEntry
.target_change
&& do_floodcount
)
796 if(!add_target(source_p
, target_p
))
798 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
799 me
.name
, source_p
->name
, target_p
->name
);
804 if (do_floodcount
&& p_or_n
== NOTICE
&& *text
== '\001' &&
805 target_p
->large_ctcp_sent
+ LARGE_CTCP_TIME
>= rb_current_time())
809 flood_attack_client(p_or_n
, source_p
, target_p
))
812 else if(source_p
->from
== target_p
->from
)
814 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
815 "Send message to %s[%s] dropped from %s(Fake Dir)",
816 target_p
->name
, target_p
->from
->name
, source_p
->name
);
820 if(MyConnect(source_p
) && (p_or_n
!= NOTICE
) && target_p
->user
&& target_p
->user
->away
)
821 sendto_one_numeric(source_p
, RPL_AWAY
, form_str(RPL_AWAY
),
822 target_p
->name
, target_p
->user
->away
);
824 if(MyClient(target_p
))
826 if (IsSetNoCTCP(target_p
) && p_or_n
!= NOTICE
&& *text
== '\001' && strncasecmp(text
+ 1, "ACTION", 6))
828 sendto_one_numeric(source_p
, ERR_NOCTCP
,
829 form_str(ERR_NOCTCP
),
832 /* If opers want to go through +g, they should load oaccept.*/
833 else if(!IsServer(source_p
) && !IsService(source_p
) && (IsSetCallerId(target_p
) ||
834 (IsSetSCallerId(target_p
) && !has_common_channel(source_p
, target_p
)) ||
835 (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])))
837 if (IsOper(source_p
))
839 rb_snprintf(text3
, sizeof(text3
), "O%s", source_p
->id
);
840 DICTIONARY_FOREACH(md
, &iter
, target_p
->user
->metadata
)
842 if(!strcmp(md
->value
, "OACCEPT") && !strcmp(md
->name
, text3
))
849 /* Here is the anti-flood bot/spambot code -db */
850 if(accept_message(source_p
, target_p
) || oaccept
)
852 add_reply_target(target_p
, source_p
);
853 sendto_one(target_p
, ":%s!%s@%s %s %s :%s",
856 source_p
->host
, command
, target_p
->name
, text
);
858 else if (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])
860 if (p_or_n
!= NOTICE
)
861 sendto_one_numeric(source_p
, ERR_NONONREG
,
862 form_str(ERR_NONONREG
),
865 else if (IsSetSCallerId(target_p
) && !has_common_channel(source_p
, target_p
))
867 if (p_or_n
!= NOTICE
)
868 sendto_one_numeric(source_p
, ERR_NOCOMMONCHAN
,
869 form_str(ERR_NOCOMMONCHAN
),
874 /* check for accept, flag recipient incoming message */
877 sendto_one_numeric(source_p
, ERR_TARGUMODEG
,
878 form_str(ERR_TARGUMODEG
),
882 if((target_p
->localClient
->last_caller_id_time
+
883 ConfigFileEntry
.caller_id_wait
) < rb_current_time())
886 sendto_one_numeric(source_p
, RPL_TARGNOTIFY
,
887 form_str(RPL_TARGNOTIFY
),
890 add_reply_target(target_p
, source_p
);
891 sendto_one(target_p
, form_str(RPL_UMODEGMSG
),
892 me
.name
, target_p
->name
, source_p
->name
,
893 source_p
->username
, source_p
->host
);
895 target_p
->localClient
->last_caller_id_time
= rb_current_time();
901 add_reply_target(target_p
, source_p
);
902 sendto_anywhere(target_p
, source_p
, command
, ":%s", text
);
906 sendto_anywhere(target_p
, source_p
, command
, ":%s", text
);
912 * flood_attack_client
913 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
914 * say NOTICE must not auto reply
915 * - pointer to source Client
916 * - pointer to target Client
917 * output - 1 if target is under flood attack
918 * side effects - check for flood attack on target target_p
921 flood_attack_client(int p_or_n
, struct Client
*source_p
, struct Client
*target_p
)
925 /* Services could get many messages legitimately and
926 * can be messaged without rate limiting via aliases
927 * and msg user@server.
930 if(GlobalSetOptions
.floodcount
&& IsClient(source_p
) && source_p
!= target_p
&& !IsService(target_p
) && (!IsOper(source_p
) || !ConfigFileEntry
.true_no_oper_flood
))
932 if((target_p
->first_received_message_time
+ 1) < rb_current_time())
934 delta
= rb_current_time() - target_p
->first_received_message_time
;
935 target_p
->received_number_of_privmsgs
-= delta
;
936 target_p
->first_received_message_time
= rb_current_time();
937 if(target_p
->received_number_of_privmsgs
<= 0)
939 target_p
->received_number_of_privmsgs
= 0;
940 target_p
->flood_noticed
= 0;
944 if((target_p
->received_number_of_privmsgs
>=
945 GlobalSetOptions
.floodcount
) || target_p
->flood_noticed
)
947 if(target_p
->flood_noticed
== 0)
949 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
950 "Possible Flooder %s[%s@%s] on %s target: %s",
951 source_p
->name
, source_p
->username
,
953 source_p
->servptr
->name
, target_p
->name
);
954 target_p
->flood_noticed
= 1;
955 /* add a bit of penalty */
956 target_p
->received_number_of_privmsgs
+= 2;
958 if(MyClient(source_p
) && (p_or_n
!= NOTICE
))
960 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
961 me
.name
, source_p
->name
, target_p
->name
);
965 target_p
->received_number_of_privmsgs
++;
972 * flood_attack_channel
973 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
974 * says NOTICE must not auto reply
975 * - pointer to source Client
976 * - pointer to target channel
977 * output - 1 if target is under flood attack
978 * side effects - check for flood attack on target chptr
981 flood_attack_channel(int p_or_n
, struct Client
*source_p
, struct Channel
*chptr
, char *chname
)
985 if(GlobalSetOptions
.floodcount
&& MyClient(source_p
) && (!IsOper(source_p
) || !ConfigFileEntry
.true_no_oper_flood
))
987 if((chptr
->first_received_message_time
+ 1) < rb_current_time())
989 delta
= rb_current_time() - chptr
->first_received_message_time
;
990 chptr
->received_number_of_privmsgs
-= delta
;
991 chptr
->first_received_message_time
= rb_current_time();
992 if(chptr
->received_number_of_privmsgs
<= 0)
994 chptr
->received_number_of_privmsgs
= 0;
995 chptr
->flood_noticed
= 0;
999 if((chptr
->received_number_of_privmsgs
>= GlobalSetOptions
.floodcount
)
1000 || chptr
->flood_noticed
)
1002 if(chptr
->flood_noticed
== 0)
1004 sendto_realops_snomask(SNO_BOTS
, *chptr
->chname
== '&' ? L_ALL
: L_NETWIDE
,
1005 "Possible Flooder %s[%s@%s] on %s target: %s",
1006 source_p
->name
, source_p
->username
,
1008 source_p
->servptr
->name
, chptr
->chname
);
1009 chptr
->flood_noticed
= 1;
1011 /* Add a bit of penalty */
1012 chptr
->received_number_of_privmsgs
+= 2;
1014 if(MyClient(source_p
) && (p_or_n
!= NOTICE
))
1015 sendto_one(source_p
,
1016 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
1017 me
.name
, source_p
->name
, chptr
->chname
);
1021 chptr
->received_number_of_privmsgs
++;
1031 * inputs - server pointer
1033 * - nick stuff to grok for opers
1034 * - text to send if grok
1036 * side effects - all the traditional oper type messages are parsed here.
1037 * i.e. "/msg #some.host."
1038 * However, syntax has been changed.
1039 * previous syntax "/msg #some.host.mask"
1040 * now becomes "/msg $#some.host.mask"
1041 * previous syntax of: "/msg $some.server.mask" remains
1042 * This disambiguates the syntax.
1045 handle_special(int p_or_n
, const char *command
, struct Client
*client_p
,
1046 struct Client
*source_p
, const char *nick
, const char *text
)
1048 struct Client
*target_p
;
1052 /* user[%host]@server addressed?
1053 * NOTE: users can send to user@server, but not user%host@server
1056 if((server
= strchr(nick
, '@')) != NULL
)
1058 if((target_p
= find_server(source_p
, server
+ 1)) == NULL
)
1060 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1061 form_str(ERR_NOSUCHSERVER
), server
+ 1);
1065 if(!IsOper(source_p
))
1067 if(strchr(nick
, '%') || (strncmp(nick
, "opers", 5) == 0))
1069 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
1070 form_str(ERR_NOSUCHNICK
), nick
);
1075 /* somewhere else.. */
1078 sendto_one(target_p
, ":%s %s %s :%s",
1079 get_id(source_p
, target_p
), command
, nick
, text
);
1083 /* Check if someones msg'ing opers@our.server */
1084 if(strncmp(nick
, "opers@", 6) == 0)
1086 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "To opers: From: %s: %s",
1087 source_p
->name
, text
);
1091 /* This was not very useful except for bypassing certain
1092 * restrictions. Note that we still allow sending to
1093 * remote servers this way, for messaging pseudoservers
1094 * securely whether they have a service{} block or not.
1097 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
1098 form_str(ERR_NOSUCHNICK
), nick
);
1103 * the following two cases allow masks in NOTICEs
1106 * Armin, 8Jun90 (gruner@informatik.tu-muenchen.de)
1108 if(IsOper(source_p
) && *nick
== '$')
1110 if((*(nick
+ 1) == '$' || *(nick
+ 1) == '#'))
1112 else if(MyOper(source_p
))
1114 sendto_one(source_p
,
1115 ":%s NOTICE %s :The command %s %s is no longer supported, please use $%s",
1116 me
.name
, source_p
->name
, command
, nick
, nick
);
1120 if(MyClient(source_p
) && !IsOperMassNotice(source_p
))
1122 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
1123 me
.name
, source_p
->name
, "mass_notice");
1127 if((s
= strrchr(nick
, '.')) == NULL
)
1129 sendto_one_numeric(source_p
, ERR_NOTOPLEVEL
,
1130 form_str(ERR_NOTOPLEVEL
), nick
);
1134 if(*s
== '.' || *s
== '*' || *s
== '?')
1136 if(*s
== '*' || *s
== '?')
1138 sendto_one_numeric(source_p
, ERR_WILDTOPLEVEL
,
1139 form_str(ERR_WILDTOPLEVEL
), nick
);
1143 sendto_match_butone(IsServer(client_p
) ? client_p
: NULL
, source_p
,
1145 (*nick
== '#') ? MATCH_HOST
: MATCH_SERVER
,
1146 "%s $%s :%s", command
, nick
, text
);
1147 if (p_or_n
!= NOTICE
&& *text
== '\001')
1148 source_p
->large_ctcp_sent
= rb_current_time();