2 * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
3 * m_cmessage.c: Handles CPRIVMSG/CNOTICE, target change limitation free
4 * PRIVMSG/NOTICE implementations.
6 * Copyright (C) 2005 Lee Hardy <lee -at- leeh.co.uk>
7 * Copyright (C) 2005 ircd-ratbox development team
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are
13 * 1.Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2.Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3.The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
33 * $Id: m_cmessage.c 26 2006-09-20 18:02:06Z spb $
46 static int m_cmessage(int, const char *, struct Client
*, struct Client
*, int, const char **);
47 static int m_cprivmsg(struct Client
*, struct Client
*, int, const char **);
48 static int m_cnotice(struct Client
*, struct Client
*, int, const char **);
50 struct Message cprivmsg_msgtab
= {
51 "CPRIVMSG", 0, 0, 0, MFLG_SLOW
,
52 {mg_ignore
, {m_cprivmsg
, 4}, mg_ignore
, mg_ignore
, mg_ignore
, {m_cprivmsg
, 4}}
54 struct Message cnotice_msgtab
= {
55 "CNOTICE", 0, 0, 0, MFLG_SLOW
,
56 {mg_ignore
, {m_cnotice
, 4}, mg_ignore
, mg_ignore
, mg_ignore
, {m_cnotice
, 4}}
59 mapi_clist_av1 cmessage_clist
[] = { &cprivmsg_msgtab
, &cnotice_msgtab
, NULL
};
60 DECLARE_MODULE_AV1(cmessage
, NULL
, NULL
, cmessage_clist
, NULL
, NULL
, "$Revision: 26 $");
66 m_cprivmsg(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
68 return m_cmessage(PRIVMSG
, "PRIVMSG", client_p
, source_p
, parc
, parv
);
72 m_cnotice(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
74 return m_cmessage(NOTICE
, "NOTICE", client_p
, source_p
, parc
, parv
);
78 m_cmessage(int p_or_n
, const char *command
,
79 struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
81 struct Client
*target_p
;
82 struct Channel
*chptr
;
83 struct membership
*msptr
;
85 if(!IsFloodDone(source_p
))
86 flood_endgrace(source_p
);
88 if((target_p
= find_named_person(parv
[1])) == NULL
)
91 sendto_one_numeric(source_p
, ERR_NOSUCHNICK
,
92 form_str(ERR_NOSUCHNICK
), parv
[1]);
96 if((chptr
= find_channel(parv
[2])) == NULL
)
99 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
100 form_str(ERR_NOSUCHCHANNEL
), parv
[2]);
104 if((msptr
= find_channel_membership(chptr
, source_p
)) == NULL
)
107 sendto_one_numeric(source_p
, ERR_NOTONCHANNEL
,
108 form_str(ERR_NOTONCHANNEL
),
113 if(!is_chanop_voiced(msptr
))
116 sendto_one(source_p
, form_str(ERR_VOICENEEDED
),
117 me
.name
, source_p
->name
, chptr
->chname
);
121 if(!IsMember(target_p
, chptr
))
124 sendto_one_numeric(source_p
, ERR_USERNOTINCHANNEL
,
125 form_str(ERR_USERNOTINCHANNEL
),
126 target_p
->name
, chptr
->chname
);
130 if(MyClient(target_p
) && (IsSetCallerId(target_p
) || (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])) &&
131 !accept_message(source_p
, target_p
) && !IsOper(source_p
))
133 if (IsSetRegOnlyMsg(target_p
) && !source_p
->user
->suser
[0])
135 if (p_or_n
!= NOTICE
)
136 sendto_one_numeric(source_p
, ERR_NONONREG
,
137 form_str(ERR_NONONREG
),
142 sendto_one_numeric(source_p
, ERR_TARGUMODEG
,
143 form_str(ERR_TARGUMODEG
), target_p
->name
);
145 if((target_p
->localClient
->last_caller_id_time
+
146 ConfigFileEntry
.caller_id_wait
) < CurrentTime
)
149 sendto_one_numeric(source_p
, RPL_TARGNOTIFY
,
150 form_str(RPL_TARGNOTIFY
),
153 sendto_one(target_p
, form_str(RPL_UMODEGMSG
),
154 me
.name
, target_p
->name
, source_p
->name
,
155 source_p
->username
, source_p
->host
);
157 target_p
->localClient
->last_caller_id_time
= CurrentTime
;
164 source_p
->localClient
->last
= CurrentTime
;
166 sendto_anywhere(target_p
, source_p
, command
, ":%s", parv
[3]);