]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_accept.c
Clean these modules up.
[irc/rqf/shadowircd.git] / modules / m_accept.c
CommitLineData
212380e3 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
23 *
24 * $Id: m_accept.c 254 2005-09-21 23:35:12Z nenolod $
25 */
26
27#include "stdinc.h"
28#include "client.h"
29#include "hash.h"
30#include "ircd.h"
31#include "numeric.h"
32#include "s_conf.h"
33#include "s_serv.h"
34#include "send.h"
35#include "msg.h"
36#include "parse.h"
37#include "sprintf_irc.h"
38#include "modules.h"
39
40static int m_accept(struct Client *, struct Client *, int, const char **);
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 = {
47 "ACCEPT", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
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};
54DECLARE_MODULE_AV1(accept, NULL, NULL, accept_clist, NULL, NULL, "$Revision: 254 $");
55
56/*
57 * m_accept - ACCEPT command handler
58 * parv[0] = sender prefix
59 * parv[1] = servername
60 */
61static int
62m_accept(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
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);
74 return 0;
75 }
76
77 build_nicklist(source_p, addbuf, delbuf, parv[1]);
78
79 /* parse the delete list */
80 for (nick = strtoken(&p, delbuf, ","); nick != NULL; nick = strtoken(&p, NULL, ","))
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
9f6c3353
JT
98 rb_dlinkFindDestroy(target_p, &source_p->localClient->allow_list);
99 rb_dlinkFindDestroy(source_p, &target_p->on_allow_list);
212380e3 100 }
101
102 /* get the number of accepts they have */
08d11e34 103 accept_num = rb_dlink_list_length(&source_p->localClient->allow_list);
212380e3 104
105 /* parse the add list */
106 for (nick = strtoken(&p, addbuf, ","); nick; nick = strtoken(&p, NULL, ","))
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);
127 return 0;
128 }
129
130 /* why is this here? */
131 /* del_from accept(target_p, source_p); */
132 add_accept(source_p, target_p);
133 accept_num++;
134 }
135
136 return 0;
137}
138
139/*
140 * build_nicklist()
141 *
142 * input - pointer to client
143 * - pointer to addbuffer
144 * - pointer to remove buffer
145 * - pointer to list of nicks
146 * output -
147 * side effects - addbuf/delbuf are modified to give valid nicks
148 */
149static void
150build_nicklist(struct Client *source_p, char *addbuf, char *delbuf, const char *nicks)
151{
152 char *name;
153 char *p;
154 int lenadd;
155 int lendel;
156 int del;
157 struct Client *target_p;
158 char *n = LOCAL_COPY(nicks);
159
160 *addbuf = *delbuf = '\0';
161 del = lenadd = lendel = 0;
162
163 /* build list of clients to add into addbuf, clients to remove in delbuf */
164 for (name = strtoken(&p, n, ","); name; name = strtoken(&p, NULL, ","), del = 0)
165 {
166 if(*name == '-')
167 {
168 del = 1;
169 name++;
170 }
171
172 if((target_p = find_named_person(name)) == NULL)
173 {
174 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
175 form_str(ERR_NOSUCHNICK), name);
176 continue;
177 }
178
179 /* we're deleting a client */
180 if(del)
181 {
182 if(*delbuf)
183 (void) strcat(delbuf, ",");
184
185 (void) strncat(delbuf, name, BUFSIZE - lendel - 1);
186 lendel += strlen(name) + 1;
187 }
188 /* adding a client */
189 else
190 {
191 if(*addbuf)
192 (void) strcat(addbuf, ",");
193
194 (void) strncat(addbuf, name, BUFSIZE - lenadd - 1);
195 lenadd += strlen(name) + 1;
196 }
197 }
198}
199
200/*
201 * add_accept()
202 *
203 * input - pointer to clients accept list to add to
204 * - pointer to client to add
205 * output - none
206 * side effects - target is added to clients list
207 */
208static void
209add_accept(struct Client *source_p, struct Client *target_p)
210{
211 dlinkAddAlloc(target_p, &source_p->localClient->allow_list);
212 dlinkAddAlloc(source_p, &target_p->on_allow_list);
213}
214
215
216/*
217 * list_accepts()
218 *
219 * input - pointer to client
220 * output - none
221 * side effects - print accept list to client
222 */
223static void
224list_accepts(struct Client *source_p)
225{
08d11e34 226 rb_dlink_node *ptr;
212380e3 227 struct Client *target_p;
228 char nicks[BUFSIZE];
229 int len = 0;
230 int len2 = 0;
231 int count = 0;
232
233 *nicks = '\0';
234 len2 = strlen(source_p->name) + 10;
235
08d11e34 236 RB_DLINK_FOREACH(ptr, source_p->localClient->allow_list.head)
212380e3 237 {
238 target_p = ptr->data;
239
240 if(target_p)
241 {
242
243 if((len + strlen(target_p->name) + len2 > BUFSIZE) || count > 14)
244 {
245 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
246 me.name, source_p->name, nicks);
247
248 len = count = 0;
249 *nicks = '\0';
250 }
251
581fa5c4 252 len += rb_snprintf(nicks + len, sizeof(nicks) - len, "%s ", target_p->name);
212380e3 253 count++;
254 }
255 }
256
257 if(*nicks)
258 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
259 me.name, source_p->name, nicks);
260
261 sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
262 me.name, source_p->name);
263
264}