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