]> jfr.im git - solanum.git/blame - modules/m_accept.c
Replace RPL_WHOISTEXT(337) with RPL_WHOISSPECIAL(320) (#419)
[solanum.git] / modules / m_accept.c
CommitLineData
212380e3
AC
1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_accept.c: Allows a user to talk to a +g user.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
212380e3
AC
23 */
24
25#include "stdinc.h"
26#include "client.h"
27#include "hash.h"
28#include "ircd.h"
29#include "numeric.h"
30#include "s_conf.h"
31#include "s_serv.h"
32#include "send.h"
33#include "msg.h"
34#include "parse.h"
212380e3
AC
35#include "modules.h"
36
eeabf33a
EM
37static const char accept_desc[] =
38 "Provides the ACCEPT command for use with Caller ID/user mode +g";
39
3c7d6fcc 40static void m_accept(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
41static void build_nicklist(struct Client *, char *, char *, const char *);
42
43static void add_accept(struct Client *, struct Client *);
44static void list_accepts(struct Client *);
45
46struct Message accept_msgtab = {
7baa37a9 47 "ACCEPT", 0, 0, 0, 0,
212380e3
AC
48 {mg_unreg, {m_accept, 2}, mg_ignore, mg_ignore, mg_ignore, {m_accept, 2}}
49};
50
51mapi_clist_av1 accept_clist[] = {
52 &accept_msgtab, NULL
53};
3c88406e
EM
54
55DECLARE_MODULE_AV2(accept, NULL, NULL, accept_clist, NULL, NULL, NULL, NULL, accept_desc);
212380e3
AC
56
57/*
58 * m_accept - ACCEPT command handler
212380e3
AC
59 * parv[1] = servername
60 */
3c7d6fcc 61static void
428ca87b 62m_accept(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
63{
64 char *nick;
65 char *p = NULL;
66 static char addbuf[BUFSIZE];
67 static char delbuf[BUFSIZE];
68 struct Client *target_p;
69 int accept_num;
70
71 if(*parv[1] == '*')
72 {
73 list_accepts(source_p);
3c7d6fcc 74 return;
212380e3
AC
75 }
76
77 build_nicklist(source_p, addbuf, delbuf, parv[1]);
78
79 /* parse the delete list */
4a2651e5 80 for (nick = rb_strtok_r(delbuf, ",", &p); nick != NULL; nick = rb_strtok_r(NULL, ",", &p))
212380e3
AC
81 {
82 /* shouldnt happen, but lets be paranoid */
83 if((target_p = find_named_person(nick)) == NULL)
84 {
85 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
86 form_str(ERR_NOSUCHNICK), nick);
87 continue;
88 }
89
90 /* user isnt on clients accept list */
91 if(!accept_message(target_p, source_p))
92 {
93 sendto_one(source_p, form_str(ERR_ACCEPTNOT),
94 me.name, source_p->name, target_p->name);
95 continue;
96 }
97
555ac41f
JT
98 rb_dlinkFindDestroy(target_p, &source_p->localClient->allow_list);
99 rb_dlinkFindDestroy(source_p, &target_p->on_allow_list);
212380e3
AC
100 }
101
102 /* get the number of accepts they have */
5b96d9a6 103 accept_num = rb_dlink_list_length(&source_p->localClient->allow_list);
212380e3
AC
104
105 /* parse the add list */
4a2651e5 106 for (nick = rb_strtok_r(addbuf, ",", &p); nick; nick = rb_strtok_r(NULL, ",", &p), accept_num++)
212380e3
AC
107 {
108 /* shouldnt happen, but lets be paranoid */
109 if((target_p = find_named_person(nick)) == NULL)
110 {
111 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
112 form_str(ERR_NOSUCHNICK), nick);
113 continue;
114 }
115
116 /* user is already on clients accept list */
117 if(accept_message(target_p, source_p))
118 {
119 sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
120 me.name, source_p->name, target_p->name);
121 continue;
122 }
123
124 if(accept_num >= ConfigFileEntry.max_accept)
125 {
126 sendto_one(source_p, form_str(ERR_ACCEPTFULL), me.name, source_p->name);
3c7d6fcc 127 return;
212380e3
AC
128 }
129
130 /* why is this here? */
131 /* del_from accept(target_p, source_p); */
132 add_accept(source_p, target_p);
212380e3 133 }
212380e3
AC
134}
135
136/*
137 * build_nicklist()
138 *
139 * input - pointer to client
140 * - pointer to addbuffer
141 * - pointer to remove buffer
142 * - pointer to list of nicks
55abcbb2 143 * output -
212380e3
AC
144 * side effects - addbuf/delbuf are modified to give valid nicks
145 */
146static void
147build_nicklist(struct Client *source_p, char *addbuf, char *delbuf, const char *nicks)
148{
149 char *name;
150 char *p;
151 int lenadd;
152 int lendel;
153 int del;
212380e3
AC
154 char *n = LOCAL_COPY(nicks);
155
156 *addbuf = *delbuf = '\0';
157 del = lenadd = lendel = 0;
158
159 /* build list of clients to add into addbuf, clients to remove in delbuf */
4a2651e5 160 for (name = rb_strtok_r(n, ",", &p); name; name = rb_strtok_r(NULL, ",", &p), del = 0)
212380e3
AC
161 {
162 if(*name == '-')
163 {
164 del = 1;
165 name++;
166 }
167
f93bc397 168 if(find_named_person(name) == NULL)
212380e3 169 {
55abcbb2 170 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
212380e3
AC
171 form_str(ERR_NOSUCHNICK), name);
172 continue;
173 }
174
175 /* we're deleting a client */
176 if(del)
177 {
178 if(*delbuf)
179 (void) strcat(delbuf, ",");
180
181 (void) strncat(delbuf, name, BUFSIZE - lendel - 1);
182 lendel += strlen(name) + 1;
183 }
184 /* adding a client */
185 else
186 {
187 if(*addbuf)
188 (void) strcat(addbuf, ",");
189
190 (void) strncat(addbuf, name, BUFSIZE - lenadd - 1);
191 lenadd += strlen(name) + 1;
192 }
193 }
194}
195
196/*
197 * add_accept()
198 *
199 * input - pointer to clients accept list to add to
200 * - pointer to client to add
201 * output - none
202 * side effects - target is added to clients list
203 */
204static void
205add_accept(struct Client *source_p, struct Client *target_p)
206{
7018b86a
JT
207 rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list);
208 rb_dlinkAddAlloc(source_p, &target_p->on_allow_list);
212380e3
AC
209}
210
211
212/*
213 * list_accepts()
214 *
215 * input - pointer to client
216 * output - none
217 * side effects - print accept list to client
218 */
219static void
220list_accepts(struct Client *source_p)
221{
5b96d9a6 222 rb_dlink_node *ptr;
212380e3
AC
223 struct Client *target_p;
224 char nicks[BUFSIZE];
225 int len = 0;
226 int len2 = 0;
227 int count = 0;
228
229 *nicks = '\0';
230 len2 = strlen(source_p->name) + 10;
231
5b96d9a6 232 RB_DLINK_FOREACH(ptr, source_p->localClient->allow_list.head)
212380e3
AC
233 {
234 target_p = ptr->data;
235
236 if(target_p)
237 {
238
239 if((len + strlen(target_p->name) + len2 > BUFSIZE) || count > 14)
240 {
241 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
242 me.name, source_p->name, nicks);
243
244 len = count = 0;
245 *nicks = '\0';
246 }
247
5203cba5 248 len += snprintf(nicks + len, sizeof(nicks) - len, "%s ", target_p->name);
212380e3
AC
249 count++;
250 }
251 }
252
253 if(*nicks)
55abcbb2 254 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
212380e3
AC
255 me.name, source_p->name, nicks);
256
55abcbb2 257 sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
212380e3
AC
258 me.name, source_p->name);
259
260}