]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
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. | |
5 | * | |
6 | * Copyright (C) 2005 Lee Hardy <lee -at- leeh.co.uk> | |
7 | * Copyright (C) 2005 ircd-ratbox development team | |
8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions are | |
11 | * met: | |
12 | * | |
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. | |
20 | * | |
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. | |
212380e3 AC |
32 | */ |
33 | #include "stdinc.h" | |
34 | #include "client.h" | |
35 | #include "channel.h" | |
36 | #include "numeric.h" | |
37 | #include "msg.h" | |
38 | #include "modules.h" | |
39 | #include "hash.h" | |
40 | #include "send.h" | |
41 | #include "s_conf.h" | |
42 | #include "packet.h" | |
0b904d91 | 43 | #include "supported.h" |
212380e3 | 44 | |
eeabf33a EM |
45 | static const char cmessage_desc[] = |
46 | "Provides the CPRIVMSG and CNOTICE facilities for bypassing anti-spam measures"; | |
47 | ||
3c7d6fcc EM |
48 | static void m_cmessage(int, const char *, struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
49 | static void m_cprivmsg(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
50 | static void m_cnotice(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 | 51 | |
0b904d91 AC |
52 | static int |
53 | _modinit(void) | |
54 | { | |
55 | add_isupport("CPRIVMSG", isupport_string, ""); | |
56 | add_isupport("CNOTICE", isupport_string, ""); | |
57 | ||
58 | return 0; | |
59 | } | |
60 | ||
61 | static void | |
62 | _moddeinit(void) | |
63 | { | |
64 | delete_isupport("CPRIVMSG"); | |
65 | delete_isupport("CNOTICE"); | |
66 | } | |
67 | ||
212380e3 | 68 | struct Message cprivmsg_msgtab = { |
7baa37a9 | 69 | "CPRIVMSG", 0, 0, 0, 0, |
212380e3 AC |
70 | {mg_ignore, {m_cprivmsg, 4}, mg_ignore, mg_ignore, mg_ignore, {m_cprivmsg, 4}} |
71 | }; | |
72 | struct Message cnotice_msgtab = { | |
7baa37a9 | 73 | "CNOTICE", 0, 0, 0, 0, |
212380e3 AC |
74 | {mg_ignore, {m_cnotice, 4}, mg_ignore, mg_ignore, mg_ignore, {m_cnotice, 4}} |
75 | }; | |
76 | ||
77 | mapi_clist_av1 cmessage_clist[] = { &cprivmsg_msgtab, &cnotice_msgtab, NULL }; | |
5544da98 | 78 | |
5544da98 | 79 | DECLARE_MODULE_AV2(cmessage, _modinit, _moddeinit, cmessage_clist, NULL, NULL, NULL, NULL, cmessage_desc); |
212380e3 AC |
80 | |
81 | #define PRIVMSG 0 | |
82 | #define NOTICE 1 | |
83 | ||
3c7d6fcc | 84 | static void |
428ca87b | 85 | m_cprivmsg(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 86 | { |
3c7d6fcc | 87 | m_cmessage(PRIVMSG, "PRIVMSG", msgbuf_p, client_p, source_p, parc, parv); |
212380e3 AC |
88 | } |
89 | ||
3c7d6fcc | 90 | static void |
428ca87b | 91 | m_cnotice(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 | 92 | { |
3c7d6fcc | 93 | m_cmessage(NOTICE, "NOTICE", msgbuf_p, client_p, source_p, parc, parv); |
212380e3 AC |
94 | } |
95 | ||
3c7d6fcc | 96 | static void |
428ca87b | 97 | m_cmessage(int p_or_n, const char *command, struct MsgBuf *msgbuf_p, |
212380e3 AC |
98 | struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
99 | { | |
100 | struct Client *target_p; | |
101 | struct Channel *chptr; | |
102 | struct membership *msptr; | |
103 | ||
104 | if(!IsFloodDone(source_p)) | |
105 | flood_endgrace(source_p); | |
106 | ||
107 | if((target_p = find_named_person(parv[1])) == NULL) | |
108 | { | |
109 | if(p_or_n != NOTICE) | |
110 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
111 | form_str(ERR_NOSUCHNICK), parv[1]); | |
3c7d6fcc | 112 | return; |
212380e3 AC |
113 | } |
114 | ||
115 | if((chptr = find_channel(parv[2])) == NULL) | |
116 | { | |
117 | if(p_or_n != NOTICE) | |
118 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
119 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
3c7d6fcc | 120 | return; |
212380e3 AC |
121 | } |
122 | ||
123 | if((msptr = find_channel_membership(chptr, source_p)) == NULL) | |
124 | { | |
125 | if(p_or_n != NOTICE) | |
126 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
55abcbb2 | 127 | form_str(ERR_NOTONCHANNEL), |
212380e3 | 128 | chptr->chname); |
3c7d6fcc | 129 | return; |
212380e3 AC |
130 | } |
131 | ||
132 | if(!is_chanop_voiced(msptr)) | |
133 | { | |
134 | if(p_or_n != NOTICE) | |
135 | sendto_one(source_p, form_str(ERR_VOICENEEDED), | |
136 | me.name, source_p->name, chptr->chname); | |
3c7d6fcc | 137 | return; |
212380e3 AC |
138 | } |
139 | ||
140 | if(!IsMember(target_p, chptr)) | |
141 | { | |
142 | if(p_or_n != NOTICE) | |
143 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
144 | form_str(ERR_USERNOTINCHANNEL), | |
145 | target_p->name, chptr->chname); | |
3c7d6fcc | 146 | return; |
212380e3 AC |
147 | } |
148 | ||
149 | if(MyClient(target_p) && (IsSetCallerId(target_p) || (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])) && | |
150 | !accept_message(source_p, target_p) && !IsOper(source_p)) | |
151 | { | |
152 | if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]) | |
153 | { | |
154 | if (p_or_n != NOTICE) | |
155 | sendto_one_numeric(source_p, ERR_NONONREG, | |
156 | form_str(ERR_NONONREG), | |
157 | target_p->name); | |
3c7d6fcc | 158 | return; |
212380e3 AC |
159 | } |
160 | if(p_or_n != NOTICE) | |
161 | sendto_one_numeric(source_p, ERR_TARGUMODEG, | |
162 | form_str(ERR_TARGUMODEG), target_p->name); | |
163 | ||
164 | if((target_p->localClient->last_caller_id_time + | |
e3354945 | 165 | ConfigFileEntry.caller_id_wait) < rb_current_time()) |
212380e3 AC |
166 | { |
167 | if(p_or_n != NOTICE) | |
168 | sendto_one_numeric(source_p, RPL_TARGNOTIFY, | |
169 | form_str(RPL_TARGNOTIFY), | |
170 | target_p->name); | |
171 | ||
172 | sendto_one(target_p, form_str(RPL_UMODEGMSG), | |
173 | me.name, target_p->name, source_p->name, | |
174 | source_p->username, source_p->host); | |
175 | ||
e3354945 | 176 | target_p->localClient->last_caller_id_time = rb_current_time(); |
212380e3 AC |
177 | } |
178 | ||
3c7d6fcc | 179 | return; |
212380e3 AC |
180 | } |
181 | ||
182 | if(p_or_n != NOTICE) | |
e3354945 | 183 | source_p->localClient->last = rb_current_time(); |
212380e3 AC |
184 | |
185 | sendto_anywhere(target_p, source_p, command, ":%s", parv[3]); | |
212380e3 | 186 | } |