]>
Commit | Line | Data |
---|---|---|
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. | |
32 | * | |
33 | * $Id: m_cmessage.c 1543 2006-06-01 18:18:28Z jilles $ | |
34 | */ | |
35 | #include "stdinc.h" | |
36 | #include "client.h" | |
37 | #include "channel.h" | |
38 | #include "numeric.h" | |
39 | #include "msg.h" | |
40 | #include "modules.h" | |
41 | #include "hash.h" | |
42 | #include "send.h" | |
43 | #include "s_conf.h" | |
44 | #include "packet.h" | |
45 | #include "supported.h" | |
46 | ||
47 | static int m_cmessage(int, const char *, struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
48 | static int m_cprivmsg(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
49 | static int m_cnotice(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
50 | ||
51 | static int | |
52 | _modinit(void) | |
53 | { | |
54 | add_isupport("CPRIVMSG", isupport_string, ""); | |
55 | add_isupport("CNOTICE", isupport_string, ""); | |
56 | ||
57 | return 0; | |
58 | } | |
59 | ||
60 | static void | |
61 | _moddeinit(void) | |
62 | { | |
63 | delete_isupport("CPRIVMSG"); | |
64 | delete_isupport("CNOTICE"); | |
65 | } | |
66 | ||
67 | struct Message cprivmsg_msgtab = { | |
68 | "CPRIVMSG", 0, 0, 0, 0, | |
69 | {mg_ignore, {m_cprivmsg, 4}, mg_ignore, mg_ignore, mg_ignore, {m_cprivmsg, 4}} | |
70 | }; | |
71 | struct Message cnotice_msgtab = { | |
72 | "CNOTICE", 0, 0, 0, 0, | |
73 | {mg_ignore, {m_cnotice, 4}, mg_ignore, mg_ignore, mg_ignore, {m_cnotice, 4}} | |
74 | }; | |
75 | ||
76 | mapi_clist_av1 cmessage_clist[] = { &cprivmsg_msgtab, &cnotice_msgtab, NULL }; | |
77 | DECLARE_MODULE_AV1(cmessage, _modinit, _moddeinit, cmessage_clist, NULL, NULL, "$Revision: 1543 $"); | |
78 | ||
79 | #define PRIVMSG 0 | |
80 | #define NOTICE 1 | |
81 | ||
82 | static int | |
83 | m_cprivmsg(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
84 | { | |
85 | return m_cmessage(PRIVMSG, "PRIVMSG", msgbuf_p, client_p, source_p, parc, parv); | |
86 | } | |
87 | ||
88 | static int | |
89 | m_cnotice(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
90 | { | |
91 | return m_cmessage(NOTICE, "NOTICE", msgbuf_p, client_p, source_p, parc, parv); | |
92 | } | |
93 | ||
94 | static int | |
95 | m_cmessage(int p_or_n, const char *command, struct MsgBuf *msgbuf_p, | |
96 | struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
97 | { | |
98 | struct Client *target_p; | |
99 | struct Channel *chptr; | |
100 | struct membership *msptr; | |
101 | ||
102 | if(!IsFloodDone(source_p)) | |
103 | flood_endgrace(source_p); | |
104 | ||
105 | if((target_p = find_named_person(parv[1])) == NULL) | |
106 | { | |
107 | if(p_or_n != NOTICE) | |
108 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, | |
109 | form_str(ERR_NOSUCHNICK), parv[1]); | |
110 | return 0; | |
111 | } | |
112 | ||
113 | if((chptr = find_channel(parv[2])) == NULL) | |
114 | { | |
115 | if(p_or_n != NOTICE) | |
116 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
117 | form_str(ERR_NOSUCHCHANNEL), parv[2]); | |
118 | return 0; | |
119 | } | |
120 | ||
121 | if((msptr = find_channel_membership(chptr, source_p)) == NULL) | |
122 | { | |
123 | if(p_or_n != NOTICE) | |
124 | sendto_one_numeric(source_p, ERR_NOTONCHANNEL, | |
125 | form_str(ERR_NOTONCHANNEL), | |
126 | chptr->chname); | |
127 | return 0; | |
128 | } | |
129 | ||
130 | if(!is_chanop_voiced(msptr)) | |
131 | { | |
132 | if(p_or_n != NOTICE) | |
133 | sendto_one(source_p, form_str(ERR_VOICENEEDED), | |
134 | me.name, source_p->name, chptr->chname); | |
135 | return 0; | |
136 | } | |
137 | ||
138 | if(!IsMember(target_p, chptr)) | |
139 | { | |
140 | if(p_or_n != NOTICE) | |
141 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
142 | form_str(ERR_USERNOTINCHANNEL), | |
143 | target_p->name, chptr->chname); | |
144 | return 0; | |
145 | } | |
146 | ||
147 | if(MyClient(target_p) && (IsSetCallerId(target_p) || (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0])) && | |
148 | !accept_message(source_p, target_p) && !IsOper(source_p)) | |
149 | { | |
150 | if (IsSetRegOnlyMsg(target_p) && !source_p->user->suser[0]) | |
151 | { | |
152 | if (p_or_n != NOTICE) | |
153 | sendto_one_numeric(source_p, ERR_NONONREG, | |
154 | form_str(ERR_NONONREG), | |
155 | target_p->name); | |
156 | return 0; | |
157 | } | |
158 | if(p_or_n != NOTICE) | |
159 | sendto_one_numeric(source_p, ERR_TARGUMODEG, | |
160 | form_str(ERR_TARGUMODEG), target_p->name); | |
161 | ||
162 | if((target_p->localClient->last_caller_id_time + | |
163 | ConfigFileEntry.caller_id_wait) < rb_current_time()) | |
164 | { | |
165 | if(p_or_n != NOTICE) | |
166 | sendto_one_numeric(source_p, RPL_TARGNOTIFY, | |
167 | form_str(RPL_TARGNOTIFY), | |
168 | target_p->name); | |
169 | ||
170 | sendto_one(target_p, form_str(RPL_UMODEGMSG), | |
171 | me.name, target_p->name, source_p->name, | |
172 | source_p->username, source_p->host); | |
173 | ||
174 | target_p->localClient->last_caller_id_time = rb_current_time(); | |
175 | } | |
176 | ||
177 | return 0; | |
178 | } | |
179 | ||
180 | if(p_or_n != NOTICE) | |
181 | source_p->localClient->last = rb_current_time(); | |
182 | ||
183 | sendto_anywhere(target_p, source_p, command, ":%s", parv[3]); | |
184 | return 0; | |
185 | } |