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
41 #include "s_newconf.h"
44 #include "inline/stringops.h"
46 static const char message_desc
[] =
47 "Provides the PRIVMSG and NOTICE commands to send messages to users and channels";
49 static void m_message(enum message_type
, struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
50 static void m_privmsg(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
51 static void m_notice(struct MsgBuf
*, 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, 0,
72 {mg_unreg
, {m_privmsg
, 0}, {m_privmsg
, 0}, mg_ignore
, mg_ignore
, {m_privmsg
, 0}}
74 struct Message notice_msgtab
= {
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_AV2(message
, modinit
, moddeinit
, message_clist
, NULL
, NULL
, NULL
, NULL
, message_desc
);
90 static int build_target_list(enum message_type msgtype
,
91 struct Client
*client_p
,
92 struct Client
*source_p
, const char *nicks_channels
, const char *text
);
94 static bool flood_attack_client(enum message_type msgtype
, struct Client
*source_p
, struct Client
*target_p
);
96 /* Fifteen seconds should be plenty for a client to reply a ctcp */
97 #define LARGE_CTCP_TIME 15
100 #define ENTITY_CHANNEL 1
101 #define ENTITY_CHANNEL_OPMOD 2
102 #define ENTITY_CHANOPS_ON_CHANNEL 3
103 #define ENTITY_CLIENT 4
105 static struct entity targets
[512];
106 static int ntargets
= 0;
108 static bool duplicate_ptr(void *);
110 static void msg_channel(enum message_type msgtype
,
111 struct Client
*client_p
,
112 struct Client
*source_p
, struct Channel
*chptr
, const char *text
);
114 static void msg_channel_opmod(enum message_type msgtype
,
115 struct Client
*client_p
,
116 struct Client
*source_p
, struct Channel
*chptr
,
119 static void msg_channel_flags(enum message_type msgtype
,
120 struct Client
*client_p
,
121 struct Client
*source_p
,
122 struct Channel
*chptr
, int flags
, const char *text
);
124 static void msg_client(enum message_type msgtype
,
125 struct Client
*source_p
, struct Client
*target_p
, const char *text
);
127 static void handle_special(enum message_type msgtype
,
128 struct Client
*client_p
, struct Client
*source_p
, const char *nick
,
137 ** Another massive cleanup Nov, 2000
138 ** (I don't think there is a single line left from 6/91. Maybe.)
139 ** m_privmsg and m_notice do basically the same thing.
140 ** in the original 2.8.2 code base, they were the same function
141 ** "m_message.c." When we did the great cleanup in conjuncton with bleep
142 ** of ircu fame, we split m_privmsg.c and m_notice.c.
143 ** I don't see the point of that now. Its harder to maintain, its
144 ** easier to introduce bugs into one version and not the other etc.
145 ** Really, the penalty of an extra function call isn't that big a deal folks.
149 const char *cmdname
[MESSAGE_TYPE_COUNT
] = {
150 [MESSAGE_TYPE_PRIVMSG
] = "PRIVMSG",
151 [MESSAGE_TYPE_NOTICE
] = "NOTICE",
155 m_privmsg(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
157 m_message(MESSAGE_TYPE_PRIVMSG
, msgbuf_p
, client_p
, source_p
, parc
, parv
);
161 m_notice(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
163 m_message(MESSAGE_TYPE_NOTICE
, msgbuf_p
, client_p
, source_p
, parc
, parv
);
167 * inputs - flag privmsg or notice
168 * - pointer to client_p
169 * - pointer to source_p
170 * - pointer to channel
173 m_message(enum message_type msgtype
, struct MsgBuf
*msgbuf_p
,
174 struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
178 if(parc
< 2 || EmptyString(parv
[1]))
180 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
181 sendto_one(source_p
, form_str(ERR_NORECIPIENT
), me
.name
,
182 source_p
->name
, cmdname
[msgtype
]);
186 if(parc
< 3 || EmptyString(parv
[2]))
188 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
189 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
193 /* Finish the flood grace period if theyre not messaging themselves
194 * as some clients (ircN) do this as a "lag check"
196 if(MyClient(source_p
) && !IsFloodDone(source_p
) && irccmp(source_p
->name
, parv
[1]))
197 flood_endgrace(source_p
);
199 if(build_target_list(msgtype
, client_p
, source_p
, parv
[1], parv
[2]) < 0)
204 for(i
= 0; i
< ntargets
; i
++)
206 switch (targets
[i
].type
)
209 msg_channel(msgtype
, client_p
, source_p
,
210 (struct Channel
*) targets
[i
].ptr
, parv
[2]);
213 case ENTITY_CHANNEL_OPMOD
:
214 msg_channel_opmod(msgtype
, client_p
, source_p
,
215 (struct Channel
*) targets
[i
].ptr
, parv
[2]);
218 case ENTITY_CHANOPS_ON_CHANNEL
:
219 msg_channel_flags(msgtype
, client_p
, source_p
,
220 (struct Channel
*) targets
[i
].ptr
,
221 targets
[i
].flags
, parv
[2]);
225 msg_client(msgtype
, source_p
,
226 (struct Client
*) targets
[i
].ptr
, parv
[2]);
235 * inputs - pointer to given client_p (server)
236 * - pointer to given source (oper/client etc.)
237 * - pointer to list of nicks/channels
238 * - pointer to table to place results
239 * - pointer to text (only used if source_p is an oper)
240 * output - number of valid entities
241 * side effects - target_table is modified to contain a list of
242 * pointers to channels or clients
243 * if source client is an oper
244 * all the classic old bizzare oper privmsg tricks
245 * are parsed and sent as is, if prefixed with $
250 build_target_list(enum message_type msgtype
, struct Client
*client_p
,
251 struct Client
*source_p
, const char *nicks_channels
, const char *text
)
254 char *p
, *nick
, *target_list
;
255 struct Channel
*chptr
= NULL
;
256 struct Client
*target_p
;
258 target_list
= LOCAL_COPY(nicks_channels
); /* skip strcpy for non-lazyleafs */
262 for(nick
= rb_strtok_r(target_list
, ",", &p
); nick
; nick
= rb_strtok_r(NULL
, ",", &p
))
266 * channels are privmsg'd a lot more than other clients, moved up
267 * here plain old channel msg?
270 if(IsChanPrefix(*nick
))
272 /* ignore send of local channel to a server (should not happen) */
273 if(IsServer(client_p
) && *nick
== '&')
276 if((chptr
= find_channel(nick
)) != NULL
)
278 if(!duplicate_ptr(chptr
))
280 if(ntargets
>= ConfigFileEntry
.max_targets
)
282 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
283 me
.name
, source_p
->name
, nick
);
286 targets
[ntargets
].ptr
= (void *) chptr
;
287 targets
[ntargets
++].type
= ENTITY_CHANNEL
;
291 /* non existant channel */
292 else if(msgtype
!= MESSAGE_TYPE_NOTICE
)
293 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
294 form_str(ERR_NOSUCHNICK
), nick
);
299 if(MyClient(source_p
))
300 target_p
= find_named_person(nick
);
302 target_p
= find_person(nick
);
304 /* look for a privmsg to another client */
307 if(!duplicate_ptr(target_p
))
309 if(ntargets
>= ConfigFileEntry
.max_targets
)
311 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
312 me
.name
, source_p
->name
, nick
);
315 targets
[ntargets
].ptr
= (void *) target_p
;
316 targets
[ntargets
].type
= ENTITY_CLIENT
;
317 targets
[ntargets
++].flags
= 0;
322 /* @#channel or +#channel message ? */
326 /* allow %+@ if someone wants to do that */
331 else if(*nick
== '+')
332 type
|= CHFL_CHANOP
| CHFL_VOICE
;
341 if(EmptyString(nick
))
343 sendto_one(source_p
, form_str(ERR_NORECIPIENT
),
344 me
.name
, source_p
->name
, cmdname
[msgtype
]);
348 /* At this point, nick+1 should be a channel name i.e. #foo or &foo
349 * if the channel is found, fine, if not report an error
352 if((chptr
= find_channel(nick
)) != NULL
)
354 struct membership
*msptr
;
356 msptr
= find_channel_membership(chptr
, source_p
);
358 if(!IsServer(source_p
) && !IsService(source_p
) && !is_chanop_voiced(msptr
))
360 sendto_one(source_p
, form_str(ERR_CHANOPRIVSNEEDED
),
361 get_id(&me
, source_p
),
362 get_id(source_p
, source_p
),
367 if(!duplicate_ptr(chptr
))
369 if(ntargets
>= ConfigFileEntry
.max_targets
)
371 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
372 me
.name
, source_p
->name
, nick
);
375 targets
[ntargets
].ptr
= (void *) chptr
;
376 targets
[ntargets
].type
= ENTITY_CHANOPS_ON_CHANNEL
;
377 targets
[ntargets
++].flags
= type
;
380 else if(msgtype
!= MESSAGE_TYPE_NOTICE
)
382 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
383 form_str(ERR_NOSUCHNICK
), nick
);
389 if(IsServer(client_p
) && *nick
== '=' && nick
[1] == '#')
392 if((chptr
= find_channel(nick
)) != NULL
)
394 if(!duplicate_ptr(chptr
))
396 if(ntargets
>= ConfigFileEntry
.max_targets
)
398 sendto_one(source_p
, form_str(ERR_TOOMANYTARGETS
),
399 me
.name
, source_p
->name
, nick
);
402 targets
[ntargets
].ptr
= (void *) chptr
;
403 targets
[ntargets
++].type
= ENTITY_CHANNEL_OPMOD
;
407 /* non existant channel */
408 else if(msgtype
!= MESSAGE_TYPE_NOTICE
)
409 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
410 form_str(ERR_NOSUCHNICK
), nick
);
415 if(strchr(nick
, '@') || (IsOper(source_p
) && (*nick
== '$')))
417 handle_special(msgtype
, client_p
, source_p
, nick
, text
);
421 /* no matching anything found - error if not NOTICE */
422 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
424 /* dont give this numeric when source is local,
425 * because its misleading --anfl
427 if(!MyClient(source_p
) && IsDigit(*nick
))
428 sendto_one(source_p
, ":%s %d %s * :Target left IRC. "
429 "Failed to deliver: [%.20s]",
430 get_id(&me
, source_p
), ERR_NOSUCHNICK
,
431 get_id(source_p
, source_p
), text
);
433 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
434 form_str(ERR_NOSUCHNICK
), nick
);
444 * inputs - pointer to check
445 * - pointer to table of entities
446 * - number of valid entities so far
447 * output - true if duplicate pointer in table, false if not.
448 * note, this does the canonize using pointers
449 * side effects - NONE
452 duplicate_ptr(void *ptr
)
455 for(i
= 0; i
< ntargets
; i
++)
456 if(targets
[i
].ptr
== ptr
)
464 * inputs - flag privmsg or notice
465 * - pointer to client_p
466 * - pointer to source_p
467 * - pointer to channel
469 * side effects - message given channel
471 * XXX - We need to rework this a bit, it's a tad ugly. --nenolod
474 msg_channel(enum message_type msgtype
,
475 struct Client
*client_p
, struct Client
*source_p
, struct Channel
*chptr
,
479 hook_data_privmsg_channel hdata
;
481 if(MyClient(source_p
))
483 /* idle time shouldnt be reset by notices --fl */
484 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
485 source_p
->localClient
->last
= rb_current_time();
488 hdata
.msgtype
= msgtype
;
489 hdata
.source_p
= source_p
;
494 call_hook(h_privmsg_channel
, &hdata
);
496 /* memory buffer address may have changed, update pointer */
499 if (hdata
.approved
!= 0)
502 /* hook may have reduced the string to nothing. */
503 if (EmptyString(text
))
505 /* could be empty after colour stripping and
506 * that would cause problems later */
507 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
508 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
512 /* chanops and voiced can flood their own channel with impunity */
513 if((result
= can_send(chptr
, source_p
, NULL
)))
515 if(result
!= CAN_SEND_OPV
&& MyClient(source_p
) &&
517 !add_channel_target(source_p
, chptr
))
519 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
520 me
.name
, source_p
->name
, chptr
->chname
);
523 if(result
== CAN_SEND_OPV
||
524 !flood_attack_channel(msgtype
, source_p
, chptr
, chptr
->chname
))
526 sendto_channel_flags(client_p
, ALL_MEMBERS
, source_p
, chptr
,
527 "%s %s :%s", cmdname
[msgtype
], chptr
->chname
, text
);
530 else if(chptr
->mode
.mode
& MODE_OPMODERATE
&&
531 (!(chptr
->mode
.mode
& MODE_NOPRIVMSGS
) ||
532 IsMember(source_p
, chptr
)))
534 if(MyClient(source_p
) && !IsOper(source_p
) &&
535 !add_channel_target(source_p
, chptr
))
537 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
538 me
.name
, source_p
->name
, chptr
->chname
);
541 if(!flood_attack_channel(msgtype
, source_p
, chptr
, chptr
->chname
))
543 sendto_channel_opmod(client_p
, source_p
, chptr
,
544 cmdname
[msgtype
], text
);
549 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
550 sendto_one_numeric(source_p
, ERR_CANNOTSENDTOCHAN
,
551 form_str(ERR_CANNOTSENDTOCHAN
), chptr
->chname
);
557 * inputs - flag privmsg or notice
558 * - pointer to client_p
559 * - pointer to source_p
560 * - pointer to channel
562 * side effects - message given channel ops
564 * XXX - We need to rework this a bit, it's a tad ugly. --nenolod
567 msg_channel_opmod(enum message_type msgtype
,
568 struct Client
*client_p
, struct Client
*source_p
,
569 struct Channel
*chptr
, const char *text
)
571 hook_data_privmsg_channel hdata
;
573 hdata
.msgtype
= msgtype
;
574 hdata
.source_p
= source_p
;
579 call_hook(h_privmsg_channel
, &hdata
);
581 /* memory buffer address may have changed, update pointer */
584 if (hdata
.approved
!= 0)
587 /* hook may have reduced the string to nothing. */
588 if (EmptyString(text
))
590 /* could be empty after colour stripping and
591 * that would cause problems later */
592 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
593 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
597 if(chptr
->mode
.mode
& MODE_OPMODERATE
&&
598 (!(chptr
->mode
.mode
& MODE_NOPRIVMSGS
) ||
599 IsMember(source_p
, chptr
)))
601 if(!flood_attack_channel(msgtype
, source_p
, chptr
, chptr
->chname
))
603 sendto_channel_opmod(client_p
, source_p
, chptr
,
604 cmdname
[msgtype
], text
);
609 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
610 sendto_one_numeric(source_p
, ERR_CANNOTSENDTOCHAN
,
611 form_str(ERR_CANNOTSENDTOCHAN
), chptr
->chname
);
618 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
619 * say NOTICE must not auto reply
620 * - pointer to client_p
621 * - pointer to source_p
622 * - pointer to channel
624 * - pointer to text to send
626 * side effects - message given channel either chanop or voice
629 msg_channel_flags(enum message_type msgtype
, struct Client
*client_p
,
630 struct Client
*source_p
, struct Channel
*chptr
, int flags
, const char *text
)
634 hook_data_privmsg_channel hdata
;
636 if(flags
& CHFL_VOICE
)
638 type
= ONLY_CHANOPSVOICED
;
647 if(MyClient(source_p
))
649 /* idletime shouldnt be reset by notice --fl */
650 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
651 source_p
->localClient
->last
= rb_current_time();
654 hdata
.msgtype
= msgtype
;
655 hdata
.source_p
= source_p
;
660 call_hook(h_privmsg_channel
, &hdata
);
662 /* memory buffer address may have changed, update pointer */
665 if (hdata
.approved
!= 0)
668 if (EmptyString(text
))
670 /* could be empty after colour stripping and
671 * that would cause problems later */
672 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
673 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
677 sendto_channel_flags(client_p
, type
, source_p
, chptr
, "%s %c%s :%s",
678 cmdname
[msgtype
], c
, chptr
->chname
, text
);
682 expire_tgchange(void *unused
)
685 rb_dlink_node
*ptr
, *next_ptr
;
687 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, tgchange_list
.head
)
691 if(target
->expiry
< rb_current_time())
693 rb_dlinkDelete(ptr
, &tgchange_list
);
694 rb_patricia_remove(tgchange_tree
, target
->pnode
);
704 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
705 * say NOTICE must not auto reply
706 * - pointer to source_p source (struct Client *)
707 * - pointer to target_p target (struct Client *)
710 * side effects - message given channel either chanop or voice
713 msg_client(enum message_type msgtype
,
714 struct Client
*source_p
, struct Client
*target_p
, const char *text
)
716 int do_floodcount
= 0;
717 hook_data_privmsg_user hdata
;
719 if(MyClient(source_p
))
722 * XXX: Controversial? Allow target users to send replies
723 * through a +g. Rationale is that people can presently use +g
724 * as a way to taunt users, e.g. harass them and hide behind +g
725 * as a way of griefing. --nenolod
727 if(msgtype
!= MESSAGE_TYPE_NOTICE
&&
728 (IsSetCallerId(source_p
) ||
729 (IsSetRegOnlyMsg(source_p
) && !target_p
->user
->suser
[0])) &&
730 !accept_message(target_p
, source_p
) &&
733 if(rb_dlink_list_length(&source_p
->localClient
->allow_list
) <
734 (unsigned long)ConfigFileEntry
.max_accept
)
736 rb_dlinkAddAlloc(target_p
, &source_p
->localClient
->allow_list
);
737 rb_dlinkAddAlloc(source_p
, &target_p
->on_allow_list
);
741 sendto_one_numeric(source_p
, ERR_OWNMODE
,
742 form_str(ERR_OWNMODE
),
743 target_p
->name
, "+g");
748 /* reset idle time for message only if its not to self
749 * and its not a notice */
750 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
751 source_p
->localClient
->last
= rb_current_time();
753 /* auto cprivmsg/cnotice */
754 do_floodcount
= !IsOper(source_p
) &&
755 !find_allowing_channel(source_p
, target_p
);
757 /* target change stuff, dont limit ctcp replies as that
758 * would allow people to start filling up random users
759 * targets just by ctcping them
761 if((msgtype
!= MESSAGE_TYPE_NOTICE
|| *text
!= '\001') &&
762 ConfigFileEntry
.target_change
&& do_floodcount
)
764 if(!add_target(source_p
, target_p
))
766 sendto_one(source_p
, form_str(ERR_TARGCHANGE
),
767 me
.name
, source_p
->name
, target_p
->name
);
772 if (do_floodcount
&& msgtype
== MESSAGE_TYPE_NOTICE
&& *text
== '\001' &&
773 target_p
->large_ctcp_sent
+ LARGE_CTCP_TIME
>= rb_current_time())
777 flood_attack_client(msgtype
, source_p
, target_p
))
780 else if(source_p
->from
== target_p
->from
)
782 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
783 "Send message to %s[%s] dropped from %s(Fake Dir)",
784 target_p
->name
, target_p
->from
->name
, source_p
->name
);
788 if(MyConnect(source_p
) && (msgtype
!= MESSAGE_TYPE_NOTICE
) && target_p
->user
&& target_p
->user
->away
)
789 sendto_one_numeric(source_p
, RPL_AWAY
, form_str(RPL_AWAY
),
790 target_p
->name
, target_p
->user
->away
);
792 if(MyClient(target_p
))
794 hdata
.msgtype
= msgtype
;
795 hdata
.source_p
= source_p
;
796 hdata
.target_p
= target_p
;
800 call_hook(h_privmsg_user
, &hdata
);
802 /* buffer location may have changed. */
805 if (hdata
.approved
!= 0)
808 if (EmptyString(text
))
810 /* could be empty after colour stripping and
811 * that would cause problems later */
812 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
813 sendto_one(source_p
, form_str(ERR_NOTEXTTOSEND
), me
.name
, source_p
->name
);
817 /* XXX Controversial? allow opers always to send through a +g */
818 if(!IsServer(source_p
) && (IsSetCallerId(target_p
) ||
819 (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])))
821 /* Here is the anti-flood bot/spambot code -db */
822 if(accept_message(source_p
, target_p
) || IsOper(source_p
))
824 add_reply_target(target_p
, source_p
);
825 sendto_one(target_p
, ":%s!%s@%s %s %s :%s",
828 source_p
->host
, cmdname
[msgtype
], target_p
->name
, text
);
830 else if (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])
832 if (msgtype
!= MESSAGE_TYPE_NOTICE
)
833 sendto_one_numeric(source_p
, ERR_NONONREG
,
834 form_str(ERR_NONONREG
),
839 /* check for accept, flag recipient incoming message */
840 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
842 sendto_one_numeric(source_p
, ERR_TARGUMODEG
,
843 form_str(ERR_TARGUMODEG
),
847 if((target_p
->localClient
->last_caller_id_time
+
848 ConfigFileEntry
.caller_id_wait
) < rb_current_time())
850 if(msgtype
!= MESSAGE_TYPE_NOTICE
)
851 sendto_one_numeric(source_p
, RPL_TARGNOTIFY
,
852 form_str(RPL_TARGNOTIFY
),
855 add_reply_target(target_p
, source_p
);
856 sendto_one(target_p
, form_str(RPL_UMODEGMSG
),
857 me
.name
, target_p
->name
, source_p
->name
,
858 source_p
->username
, source_p
->host
);
860 target_p
->localClient
->last_caller_id_time
= rb_current_time();
866 add_reply_target(target_p
, source_p
);
867 sendto_anywhere(target_p
, source_p
, cmdname
[msgtype
], ":%s", text
);
871 sendto_anywhere(target_p
, source_p
, cmdname
[msgtype
], ":%s", text
);
877 * flood_attack_client
878 * inputs - flag 0 if PRIVMSG 1 if NOTICE. RFC
879 * says NOTICE must not auto reply
880 * - pointer to source Client
881 * - pointer to target Client
882 * output - true if target is under flood attack
883 * side effects - check for flood attack on target target_p
886 flood_attack_client(enum message_type msgtype
, struct Client
*source_p
, struct Client
*target_p
)
890 /* Services could get many messages legitimately and
891 * can be messaged without rate limiting via aliases
892 * and msg user@server.
895 if(GlobalSetOptions
.floodcount
&& IsClient(source_p
) && source_p
!= target_p
&& !IsService(target_p
))
897 if((target_p
->first_received_message_time
+ 1) < rb_current_time())
899 delta
= rb_current_time() - target_p
->first_received_message_time
;
900 target_p
->received_number_of_privmsgs
-= delta
;
901 target_p
->first_received_message_time
= rb_current_time();
902 if(target_p
->received_number_of_privmsgs
<= 0)
904 target_p
->received_number_of_privmsgs
= 0;
905 target_p
->flood_noticed
= 0;
909 if((target_p
->received_number_of_privmsgs
>=
910 GlobalSetOptions
.floodcount
) || target_p
->flood_noticed
)
912 if(target_p
->flood_noticed
== 0)
914 sendto_realops_snomask(SNO_BOTS
, L_NETWIDE
,
915 "Possible Flooder %s[%s@%s] on %s target: %s",
916 source_p
->name
, source_p
->username
,
918 source_p
->servptr
->name
, target_p
->name
);
919 target_p
->flood_noticed
= 1;
920 /* add a bit of penalty */
921 target_p
->received_number_of_privmsgs
+= 2;
923 if(MyClient(source_p
) && (msgtype
!= MESSAGE_TYPE_NOTICE
))
925 ":%s NOTICE %s :*** Message to %s throttled due to flooding",
926 me
.name
, source_p
->name
, target_p
->name
);
930 target_p
->received_number_of_privmsgs
++;
939 * inputs - server pointer
941 * - nick stuff to grok for opers
942 * - text to send if grok
944 * side effects - all the traditional oper type messages are parsed here.
945 * i.e. "/msg #some.host."
946 * However, syntax has been changed.
947 * previous syntax "/msg #some.host.mask"
948 * now becomes "/msg $#some.host.mask"
949 * previous syntax of: "/msg $some.server.mask" remains
950 * This disambiguates the syntax.
953 handle_special(enum message_type msgtype
, struct Client
*client_p
,
954 struct Client
*source_p
, const char *nick
, const char *text
)
956 struct Client
*target_p
;
960 /* user[%host]@server addressed?
961 * NOTE: users can send to user@server, but not user%host@server
964 if((server
= strchr(nick
, '@')) != NULL
)
966 if((target_p
= find_server(source_p
, server
+ 1)) == NULL
)
968 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
969 form_str(ERR_NOSUCHSERVER
), server
+ 1);
973 if(!IsOper(source_p
))
975 if(strchr(nick
, '%') || (strncmp(nick
, "opers", 5) == 0))
977 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
978 form_str(ERR_NOSUCHNICK
), nick
);
983 /* somewhere else.. */
986 sendto_one(target_p
, ":%s %s %s :%s",
987 get_id(source_p
, target_p
), cmdname
[msgtype
], nick
, text
);
991 /* Check if someones msg'ing opers@our.server */
992 if(strncmp(nick
, "opers@", 6) == 0)
994 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "To opers: From: %s: %s",
995 source_p
->name
, text
);
999 /* This was not very useful except for bypassing certain
1000 * restrictions. Note that we still allow sending to
1001 * remote servers this way, for messaging pseudoservers
1002 * securely whether they have a service{} block or not.
1005 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
1006 form_str(ERR_NOSUCHNICK
), nick
);
1011 * the following two cases allow masks in NOTICEs
1014 * Armin, 8Jun90 (gruner@informatik.tu-muenchen.de)
1016 if(IsOper(source_p
) && *nick
== '$')
1018 if((*(nick
+ 1) == '$' || *(nick
+ 1) == '#'))
1020 else if(MyOper(source_p
))
1022 sendto_one(source_p
,
1023 ":%s NOTICE %s :The command %s %s is no longer supported, please use $%s",
1024 me
.name
, source_p
->name
, cmdname
[msgtype
], nick
, nick
);
1028 if(MyClient(source_p
) && !IsOperMassNotice(source_p
))
1030 sendto_one(source_p
, form_str(ERR_NOPRIVS
),
1031 me
.name
, source_p
->name
, "mass_notice");
1035 if((s
= strrchr(nick
, '.')) == NULL
)
1037 sendto_one_numeric(source_p
, ERR_NOTOPLEVEL
,
1038 form_str(ERR_NOTOPLEVEL
), nick
);
1042 if(*s
== '.' || *s
== '*' || *s
== '?')
1044 if(*s
== '*' || *s
== '?')
1046 sendto_one_numeric(source_p
, ERR_WILDTOPLEVEL
,
1047 form_str(ERR_WILDTOPLEVEL
), nick
);
1051 sendto_match_butone(IsServer(client_p
) ? client_p
: NULL
, source_p
,
1053 (*nick
== '#') ? MATCH_HOST
: MATCH_SERVER
,
1054 "%s $%s :%s", cmdname
[msgtype
], nick
, text
);
1055 if (msgtype
!= MESSAGE_TYPE_NOTICE
&& *text
== '\001')
1056 source_p
->large_ctcp_sent
= rb_current_time();