]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/m_accept.c
Add umode +R to doc/services.txt.
[irc/rqf/shadowircd.git] / modules / m_accept.c
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 "modules.h"
38
39 static int m_accept(struct Client *, struct Client *, int, const char **);
40 static void build_nicklist(struct Client *, char *, char *, const char *);
41
42 static void add_accept(struct Client *, struct Client *);
43 static void list_accepts(struct Client *);
44
45 struct Message accept_msgtab = {
46 "ACCEPT", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
47 {mg_unreg, {m_accept, 2}, mg_ignore, mg_ignore, mg_ignore, {m_accept, 2}}
48 };
49
50 mapi_clist_av1 accept_clist[] = {
51 &accept_msgtab, NULL
52 };
53 DECLARE_MODULE_AV1(accept, NULL, NULL, accept_clist, NULL, NULL, "$Revision: 254 $");
54
55 /*
56 * m_accept - ACCEPT command handler
57 * parv[1] = servername
58 */
59 static int
60 m_accept(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
61 {
62 char *nick;
63 char *p = NULL;
64 static char addbuf[BUFSIZE];
65 static char delbuf[BUFSIZE];
66 struct Client *target_p;
67 int accept_num;
68
69 if(*parv[1] == '*')
70 {
71 list_accepts(source_p);
72 return 0;
73 }
74
75 build_nicklist(source_p, addbuf, delbuf, parv[1]);
76
77 /* parse the delete list */
78 for (nick = rb_strtok_r(delbuf, ",", &p); nick != NULL; nick = rb_strtok_r(NULL, ",", &p))
79 {
80 /* shouldnt happen, but lets be paranoid */
81 if((target_p = find_named_person(nick)) == NULL)
82 {
83 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
84 form_str(ERR_NOSUCHNICK), nick);
85 continue;
86 }
87
88 /* user isnt on clients accept list */
89 if(!accept_message(target_p, source_p))
90 {
91 sendto_one(source_p, form_str(ERR_ACCEPTNOT),
92 me.name, source_p->name, target_p->name);
93 continue;
94 }
95
96 rb_dlinkFindDestroy(target_p, &source_p->localClient->allow_list);
97 rb_dlinkFindDestroy(source_p, &target_p->on_allow_list);
98 }
99
100 /* get the number of accepts they have */
101 accept_num = rb_dlink_list_length(&source_p->localClient->allow_list);
102
103 /* parse the add list */
104 for (nick = rb_strtok_r(addbuf, ",", &p); nick; nick = rb_strtok_r(NULL, ",", &p), accept_num++)
105 {
106 /* shouldnt happen, but lets be paranoid */
107 if((target_p = find_named_person(nick)) == NULL)
108 {
109 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
110 form_str(ERR_NOSUCHNICK), nick);
111 continue;
112 }
113
114 /* user is already on clients accept list */
115 if(accept_message(target_p, source_p))
116 {
117 sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
118 me.name, source_p->name, target_p->name);
119 continue;
120 }
121
122 if(accept_num >= ConfigFileEntry.max_accept)
123 {
124 sendto_one(source_p, form_str(ERR_ACCEPTFULL), me.name, source_p->name);
125 return 0;
126 }
127
128 /* why is this here? */
129 /* del_from accept(target_p, source_p); */
130 add_accept(source_p, target_p);
131 }
132
133 return 0;
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
143 * output -
144 * side effects - addbuf/delbuf are modified to give valid nicks
145 */
146 static void
147 build_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;
154 struct Client *target_p;
155 char *n = LOCAL_COPY(nicks);
156
157 *addbuf = *delbuf = '\0';
158 del = lenadd = lendel = 0;
159
160 /* build list of clients to add into addbuf, clients to remove in delbuf */
161 for (name = rb_strtok_r(n, ",", &p); name; name = rb_strtok_r(NULL, ",", &p), del = 0)
162 {
163 if(*name == '-')
164 {
165 del = 1;
166 name++;
167 }
168
169 if((target_p = find_named_person(name)) == NULL)
170 {
171 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
172 form_str(ERR_NOSUCHNICK), name);
173 continue;
174 }
175
176 /* we're deleting a client */
177 if(del)
178 {
179 if(*delbuf)
180 (void) strcat(delbuf, ",");
181
182 (void) strncat(delbuf, name, BUFSIZE - lendel - 1);
183 lendel += strlen(name) + 1;
184 }
185 /* adding a client */
186 else
187 {
188 if(*addbuf)
189 (void) strcat(addbuf, ",");
190
191 (void) strncat(addbuf, name, BUFSIZE - lenadd - 1);
192 lenadd += strlen(name) + 1;
193 }
194 }
195 }
196
197 /*
198 * add_accept()
199 *
200 * input - pointer to clients accept list to add to
201 * - pointer to client to add
202 * output - none
203 * side effects - target is added to clients list
204 */
205 static void
206 add_accept(struct Client *source_p, struct Client *target_p)
207 {
208 rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list);
209 rb_dlinkAddAlloc(source_p, &target_p->on_allow_list);
210 }
211
212
213 /*
214 * list_accepts()
215 *
216 * input - pointer to client
217 * output - none
218 * side effects - print accept list to client
219 */
220 static void
221 list_accepts(struct Client *source_p)
222 {
223 rb_dlink_node *ptr;
224 struct Client *target_p;
225 char nicks[BUFSIZE];
226 int len = 0;
227 int len2 = 0;
228 int count = 0;
229
230 *nicks = '\0';
231 len2 = strlen(source_p->name) + 10;
232
233 RB_DLINK_FOREACH(ptr, source_p->localClient->allow_list.head)
234 {
235 target_p = ptr->data;
236
237 if(target_p)
238 {
239
240 if((len + strlen(target_p->name) + len2 > BUFSIZE) || count > 14)
241 {
242 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
243 me.name, source_p->name, nicks);
244
245 len = count = 0;
246 *nicks = '\0';
247 }
248
249 len += rb_snprintf(nicks + len, sizeof(nicks) - len, "%s ", target_p->name);
250 count++;
251 }
252 }
253
254 if(*nicks)
255 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
256 me.name, source_p->name, nicks);
257
258 sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
259 me.name, source_p->name);
260
261 }