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"
46 #include "inline/stringops.h"
48 static int m_message(int, const char *, struct Client
*, struct Client
*, int, const char **);
49 static int m_privmsg(struct Client
*, struct Client
*, int, const char **);
50 static int m_notice(struct Client
*, struct Client
*, int, const char **);
52 static void expire_tgchange(void *unused
);
53 static struct ev_entry
*expire_tgchange_event
;
58 expire_tgchange_event
= rb_event_addish("expire_tgchange", expire_tgchange
, NULL
, 300);
59 expire_tgchange(NULL
);
66 rb_event_delete(expire_tgchange_event
);
69 struct Message privmsg_msgtab
= {
70 "PRIVMSG", 0, 0, 0, MFLG_SLOW
| MFLG_UNREG
,
71 {mg_unreg
, {m_privmsg
, 0}, {m_privmsg
, 0}, mg_ignore
, mg_ignore
, {m_privmsg
, 0}}
73 struct Message notice_msgtab
= {
74 "NOTICE", 0, 0, 0, MFLG_SLOW
,
75 {mg_unreg
, {m_notice
, 0}, {m_notice
, 0}, {m_notice
, 0}, mg_ignore
, {m_notice
, 0}}
78 mapi_clist_av1 message_clist
[] = { &privmsg_msgtab
, ¬ice_msgtab
, NULL
};
80 DECLARE_MODULE_AV1(message
, modinit
, moddeinit
, message_clist
, NULL
, NULL
, "$Revision: 3173 $");
89 static int build_target_list(int p_or_n
, const char *command
,
90 struct Client
*client_p
,
91 struct Client
*source_p
, const char *nicks_channels
, const char *text
);
93 static struct Channel
*find_allowing_channel(struct Client
*source_p
, struct Client
*target_p
);
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(strchr(nick
, '@') || (IsOper(source_p
) && (*nick
== '$')))
397 handle_special(p_or_n
, command
, client_p
, source_p
, nick
, text
);
401 if(IsServer(client_p
) && *nick
== '=' && nick
[1] == '#')
404 if((chptr
= find_channel(nick
)) != NULL
)
406 if(!duplicate_ptr(chptr
))
408 if(ntargets
>= ConfigFileEntry
.max_targets
)
410 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
411 me
.name
, source_p
->name
, nick
);
414 targets
[ntargets
].ptr
= (void *) chptr
;
415 targets
[ntargets
++].type
= ENTITY_CHANNEL_OPMOD
;
419 /* non existant channel */
420 else if(p_or_n
!= NOTICE
)
421 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
422 form_str(ERR_NOSUCHNICK
), nick
);
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
,
488 if(MyClient(source_p
))
490 /* idle time shouldnt be reset by notices --fl */
492 source_p
->localClient
->last
= rb_current_time();
495 if(chptr
->mode
.mode
& MODE_NOCOLOR
)
497 rb_strlcpy(text2
, text
, BUFSIZE
);
500 if (EmptyString(text
))
502 /* could be empty after colour stripping and
503 * that would cause problems later */
505 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
510 /* chanops and voiced can flood their own channel with impunity */
511 if((result
= can_send(chptr
, source_p
, NULL
)))
513 if(result
== CAN_SEND_OPV
||
514 !flood_attack_channel(p_or_n
, source_p
, chptr
, chptr
->chname
))
516 sendto_channel_flags(client_p
, ALL_MEMBERS
, source_p
, chptr
,
517 "%s %s :%s", command
, chptr
->chname
, text
);
518 if (p_or_n
!= NOTICE
&& *text
== '\001' &&
519 rb_dlink_list_length(&chptr
->locmembers
) > (unsigned)(GlobalSetOptions
.floodcount
/ 2))
520 source_p
->large_ctcp_sent
= rb_current_time();
523 else if(chptr
->mode
.mode
& MODE_OPMODERATE
&&
524 (!(chptr
->mode
.mode
& MODE_NOPRIVMSGS
) ||
525 IsMember(source_p
, chptr
)))
527 if(!flood_attack_channel(p_or_n
, source_p
, chptr
, chptr
->chname
))
529 sendto_channel_opmod(client_p
, source_p
, chptr
,
536 sendto_one_numeric(source_p
, ERR_CANNOTSENDTOCHAN
,
537 form_str(ERR_CANNOTSENDTOCHAN
), chptr
->chname
);
543 * inputs - flag privmsg or notice
544 * - pointer to command "PRIVMSG" or "NOTICE"
545 * - pointer to client_p
546 * - pointer to source_p
547 * - pointer to channel
549 * side effects - message given channel ops
551 * XXX - We need to rework this a bit, it's a tad ugly. --nenolod
554 msg_channel_opmod(int p_or_n
, const char *command
,
555 struct Client
*client_p
, struct Client
*source_p
,
556 struct Channel
*chptr
, const char *text
)
560 if(chptr
->mode
.mode
& MODE_NOCOLOR
)
562 rb_strlcpy(text2
, text
, BUFSIZE
);
565 if (EmptyString(text
))
567 /* could be empty after colour stripping and
568 * that would cause problems later */
570 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
575 if(chptr
->mode
.mode
& MODE_OPMODERATE
&&
576 (!(chptr
->mode
.mode
& MODE_NOPRIVMSGS
) ||
577 IsMember(source_p
, chptr
)))
579 if(!flood_attack_channel(p_or_n
, source_p
, chptr
, chptr
->chname
))
581 sendto_channel_opmod(client_p
, source_p
, chptr
,
588 sendto_one_numeric(source_p
, ERR_CANNOTSENDTOCHAN
,
589 form_str(ERR_CANNOTSENDTOCHAN
), chptr
->chname
);
596 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
597 * say NOTICE must not auto reply
598 * - pointer to command, "PRIVMSG" or "NOTICE"
599 * - pointer to client_p
600 * - pointer to source_p
601 * - pointer to channel
603 * - pointer to text to send
605 * side effects - message given channel either chanop or voice
608 msg_channel_flags(int p_or_n
, const char *command
, struct Client
*client_p
,
609 struct Client
*source_p
, struct Channel
*chptr
, int flags
, const char *text
)
614 if(flags
& CHFL_VOICE
)
616 type
= ONLY_CHANOPSVOICED
;
625 if(MyClient(source_p
))
627 /* idletime shouldnt be reset by notice --fl */
629 source_p
->localClient
->last
= rb_current_time();
632 sendto_channel_flags(client_p
, type
, source_p
, chptr
, "%s %c%s :%s",
633 command
, c
, chptr
->chname
, text
);
636 #define PREV_FREE_TARGET(x) ((FREE_TARGET(x) == 0) ? 9 : FREE_TARGET(x) - 1)
637 #define PREV_TARGET(i) ((i == 0) ? i = 9 : --i)
638 #define NEXT_TARGET(i) ((i == 9) ? i = 0 : ++i)
641 expire_tgchange(void *unused
)
644 rb_dlink_node
*ptr
, *next_ptr
;
646 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, tgchange_list
.head
)
650 if(target
->expiry
< rb_current_time())
652 rb_dlinkDelete(ptr
, &tgchange_list
);
653 rb_patricia_remove(tgchange_tree
, target
->pnode
);
661 add_target(struct Client
*source_p
, struct Client
*target_p
)
666 /* can msg themselves or services without using any target slots */
667 if(source_p
== target_p
|| IsService(target_p
))
670 /* special condition for those who have had PRIVMSG crippled to allow them
671 * to talk to IRCops still.
673 * XXX: is this controversial?
675 if(source_p
->localClient
->target_last
> rb_current_time() && IsOper(target_p
))
678 hashv
= fnv_hash_upper((const unsigned char *)use_id(target_p
), 32);
680 if(USED_TARGETS(source_p
))
682 /* hunt for an existing target */
683 for(i
= PREV_FREE_TARGET(source_p
), j
= USED_TARGETS(source_p
);
684 j
; --j
, PREV_TARGET(i
))
686 if(source_p
->localClient
->targets
[i
] == hashv
)
690 /* first message after connect, we may only start clearing
691 * slots after this message --anfl
693 if(!IsTGChange(source_p
))
695 SetTGChange(source_p
);
696 source_p
->localClient
->target_last
= rb_current_time();
698 /* clear as many targets as we can */
699 else if((i
= (rb_current_time() - source_p
->localClient
->target_last
) / 60))
701 if(i
> USED_TARGETS(source_p
))
702 USED_TARGETS(source_p
) = 0;
704 USED_TARGETS(source_p
) -= i
;
706 source_p
->localClient
->target_last
= rb_current_time();
708 /* cant clear any, full target list */
709 else if(USED_TARGETS(source_p
) == 10)
711 ServerStats
.is_tgch
++;
712 add_tgchange(source_p
->sockhost
);
716 /* no targets in use, reset their target_last so that they cant
717 * abuse a long idle to get targets back more quickly
721 source_p
->localClient
->target_last
= rb_current_time();
722 SetTGChange(source_p
);
725 source_p
->localClient
->targets
[FREE_TARGET(source_p
)] = hashv
;
726 NEXT_TARGET(FREE_TARGET(source_p
));
727 ++USED_TARGETS(source_p
);
734 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
735 * say NOTICE must not auto reply
736 * - pointer to command, "PRIVMSG" or "NOTICE"
737 * - pointer to source_p source (struct Client *)
738 * - pointer to target_p target (struct Client *)
741 * side effects - message given channel either chanop or voice
744 msg_client(int p_or_n
, const char *command
,
745 struct Client
*source_p
, struct Client
*target_p
, const char *text
)
748 int do_floodcount
= 0;
750 if(MyClient(source_p
))
752 /* reset idle time for message only if its not to self
753 * and its not a notice */
755 source_p
->localClient
->last
= rb_current_time();
757 /* auto cprivmsg/cnotice */
758 do_floodcount
= !IsOper(source_p
) &&
759 !find_allowing_channel(source_p
, target_p
);
761 /* target change stuff, dont limit ctcp replies as that
762 * would allow people to start filling up random users
763 * targets just by ctcping them
765 if((p_or_n
!= NOTICE
|| *text
!= '\001') &&
766 ConfigFileEntry
.target_change
&& do_floodcount
)
768 if(!add_target(source_p
, target_p
))
770 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
771 me
.name
, source_p
->name
, target_p
->name
);
776 if (do_floodcount
&& p_or_n
== NOTICE
&& *text
== '\001' &&
777 target_p
->large_ctcp_sent
+ LARGE_CTCP_TIME
>= rb_current_time())
781 flood_attack_client(p_or_n
, source_p
, target_p
))
784 else if(source_p
->from
== target_p
->from
)
786 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
787 "Send message to %s[%s] dropped from %s(Fake Dir)",
788 target_p
->name
, target_p
->from
->name
, source_p
->name
);
792 if(MyConnect(source_p
) && (p_or_n
!= NOTICE
) && target_p
->user
&& (awaymsg
= get_metadata(target_p
, "away")) != NULL
)
793 sendto_one_numeric(source_p
, RPL_AWAY
, form_str(RPL_AWAY
),
794 target_p
->name
, awaymsg
);
796 if(MyClient(target_p
))
798 /* XXX Controversial? allow opers always to send through a +g */
799 if(!IsServer(source_p
) && (IsSetCallerId(target_p
) ||
800 (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])))
802 /* Here is the anti-flood bot/spambot code -db */
803 if(accept_message(source_p
, target_p
) || IsOper(source_p
))
805 sendto_one(target_p
, ":%s!%s@%s %s %s :%s",
808 source_p
->host
, command
, target_p
->name
, text
);
810 else if (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])
812 if (p_or_n
!= NOTICE
)
813 sendto_one_numeric(source_p
, ERR_NONONREG
,
814 form_str(ERR_NONONREG
),
819 /* check for accept, flag recipient incoming message */
822 sendto_one_numeric(source_p
, ERR_TARGUMODEG
,
823 form_str(ERR_TARGUMODEG
),
827 if((target_p
->localClient
->last_caller_id_time
+
828 ConfigFileEntry
.caller_id_wait
) < rb_current_time())
831 sendto_one_numeric(source_p
, RPL_TARGNOTIFY
,
832 form_str(RPL_TARGNOTIFY
),
835 sendto_one(target_p
, form_str(RPL_UMODEGMSG
),
836 me
.name
, target_p
->name
, source_p
->name
,
837 source_p
->username
, source_p
->host
);
839 target_p
->localClient
->last_caller_id_time
= rb_current_time();
844 sendto_anywhere(target_p
, source_p
, command
, ":%s", text
);
847 sendto_anywhere(target_p
, source_p
, command
, ":%s", text
);
852 static struct Channel
*
853 find_allowing_channel(struct Client
*source_p
, struct Client
*target_p
)
856 struct membership
*msptr
;
858 RB_DLINK_FOREACH(ptr
, source_p
->user
->channel
.head
)
861 if (is_chanop_voiced(msptr
) && IsMember(target_p
, msptr
->chptr
))
868 * flood_attack_client
869 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
870 * say NOTICE must not auto reply
871 * - pointer to source Client
872 * - pointer to target Client
873 * output - 1 if target is under flood attack
874 * side effects - check for flood attack on target target_p
877 flood_attack_client(int p_or_n
, struct Client
*source_p
, struct Client
*target_p
)
881 /* Services could get many messages legitimately and
882 * can be messaged without rate limiting via aliases
883 * and msg user@server.
886 if(GlobalSetOptions
.floodcount
&& IsClient(source_p
) && source_p
!= target_p
&& !IsService(target_p
))
888 if((target_p
->first_received_message_time
+ 1) < rb_current_time())
890 delta
= rb_current_time() - target_p
->first_received_message_time
;
891 target_p
->received_number_of_privmsgs
-= delta
;
892 target_p
->first_received_message_time
= rb_current_time();
893 if(target_p
->received_number_of_privmsgs
<= 0)
895 target_p
->received_number_of_privmsgs
= 0;
896 target_p
->flood_noticed
= 0;
900 if((target_p
->received_number_of_privmsgs
>=
901 GlobalSetOptions
.floodcount
) || target_p
->flood_noticed
)
903 if(target_p
->flood_noticed
== 0)
905 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
906 "Possible Flooder %s[%s@%s] on %s target: %s",
907 source_p
->name
, source_p
->username
,
909 source_p
->servptr
->name
, target_p
->name
);
910 target_p
->flood_noticed
= 1;
911 /* add a bit of penalty */
912 target_p
->received_number_of_privmsgs
+= 2;
914 if(MyClient(source_p
) && (p_or_n
!= NOTICE
))
916 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
917 me
.name
, source_p
->name
, target_p
->name
);
921 target_p
->received_number_of_privmsgs
++;
928 * flood_attack_channel
929 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
930 * says NOTICE must not auto reply
931 * - pointer to source Client
932 * - pointer to target channel
933 * output - 1 if target is under flood attack
934 * side effects - check for flood attack on target chptr
937 flood_attack_channel(int p_or_n
, struct Client
*source_p
, struct Channel
*chptr
, char *chname
)
941 if(GlobalSetOptions
.floodcount
&& MyClient(source_p
))
943 if((chptr
->first_received_message_time
+ 1) < rb_current_time())
945 delta
= rb_current_time() - chptr
->first_received_message_time
;
946 chptr
->received_number_of_privmsgs
-= delta
;
947 chptr
->first_received_message_time
= rb_current_time();
948 if(chptr
->received_number_of_privmsgs
<= 0)
950 chptr
->received_number_of_privmsgs
= 0;
951 chptr
->flood_noticed
= 0;
955 if((chptr
->received_number_of_privmsgs
>= GlobalSetOptions
.floodcount
)
956 || chptr
->flood_noticed
)
958 if(chptr
->flood_noticed
== 0)
960 sendto_realops_snomask(SNO_BOTS
, *chptr
->chname
== '&' ? L_ALL
: L_NETWIDE
,
961 "Possible Flooder %s[%s@%s] on %s target: %s",
962 source_p
->name
, source_p
->username
,
964 source_p
->servptr
->name
, chptr
->chname
);
965 chptr
->flood_noticed
= 1;
967 /* Add a bit of penalty */
968 chptr
->received_number_of_privmsgs
+= 2;
970 if(MyClient(source_p
) && (p_or_n
!= NOTICE
))
972 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
973 me
.name
, source_p
->name
, chptr
->chname
);
977 chptr
->received_number_of_privmsgs
++;
987 * inputs - server pointer
989 * - nick stuff to grok for opers
990 * - text to send if grok
992 * side effects - all the traditional oper type messages are parsed here.
993 * i.e. "/msg #some.host."
994 * However, syntax has been changed.
995 * previous syntax "/msg #some.host.mask"
996 * now becomes "/msg $#some.host.mask"
997 * previous syntax of: "/msg $some.server.mask" remains
998 * This disambiguates the syntax.
1001 handle_special(int p_or_n
, const char *command
, struct Client
*client_p
,
1002 struct Client
*source_p
, const char *nick
, const char *text
)
1004 struct Client
*target_p
;
1008 /* user[%host]@server addressed?
1009 * NOTE: users can send to user@server, but not user%host@server
1012 if((server
= strchr(nick
, '@')) != NULL
)
1014 if((target_p
= find_server(source_p
, server
+ 1)) == NULL
)
1016 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
1017 form_str(ERR_NOSUCHSERVER
), server
+ 1);
1021 if(!IsOper(source_p
))
1023 if(strchr(nick
, '%') || (strncmp(nick
, "opers", 5) == 0))
1025 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
1026 form_str(ERR_NOSUCHNICK
), nick
);
1031 /* somewhere else.. */
1034 sendto_one(target_p
, ":%s %s %s :%s",
1035 get_id(source_p
, target_p
), command
, nick
, text
);
1039 /* Check if someones msg'ing opers@our.server */
1040 if(strncmp(nick
, "opers@", 6) == 0)
1042 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "To opers: From: %s: %s",
1043 source_p
->name
, text
);
1047 /* This was not very useful except for bypassing certain
1048 * restrictions. Note that we still allow sending to
1049 * remote servers this way, for messaging pseudoservers
1050 * securely whether they have a service{} block or not.
1053 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
1054 form_str(ERR_NOSUCHNICK
), nick
);
1059 * the following two cases allow masks in NOTICEs
1062 * Armin, 8Jun90 (gruner@informatik.tu-muenchen.de)
1064 if(IsOper(source_p
) && *nick
== '$')
1066 if((*(nick
+ 1) == '$' || *(nick
+ 1) == '#'))
1068 else if(MyOper(source_p
))
1070 sendto_one(source_p
,
1071 ":%s NOTICE %s :The command %s %s is no longer supported, please use $%s",
1072 me
.name
, source_p
->name
, command
, nick
, nick
);
1076 if(MyClient(source_p
) && !IsOperMassNotice(source_p
))
1078 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
1079 me
.name
, source_p
->name
, "mass_notice");
1083 if((s
= strrchr(nick
, '.')) == NULL
)
1085 sendto_one_numeric(source_p
, ERR_NOTOPLEVEL
,
1086 form_str(ERR_NOTOPLEVEL
), nick
);
1090 if(*s
== '.' || *s
== '*' || *s
== '?')
1092 if(*s
== '*' || *s
== '?')
1094 sendto_one_numeric(source_p
, ERR_WILDTOPLEVEL
,
1095 form_str(ERR_WILDTOPLEVEL
), nick
);
1099 sendto_match_butone(IsServer(client_p
) ? client_p
: NULL
, source_p
,
1101 (*nick
== '#') ? MATCH_HOST
: MATCH_SERVER
,
1102 "%s $%s :%s", command
, nick
, text
);
1103 if (p_or_n
!= NOTICE
&& *text
== '\001')
1104 source_p
->large_ctcp_sent
= rb_current_time();