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