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