Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_accept.c
blobe6db626b8a35e5250ba545cb87f114656f197fbd
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_accept.c: Allows a user to talk to a +g user.
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
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.
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.
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
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"
35 #include "sprintf_irc.h"
36 #include "modules.h"
38 static int m_accept(struct Client *, struct Client *, int, const char **);
39 static void build_nicklist(struct Client *, char *, char *, const char *);
41 static void add_accept(struct Client *, struct Client *);
42 static void list_accepts(struct Client *);
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}}
49 mapi_clist_av1 accept_clist[] = {
50 &accept_msgtab, NULL
52 DECLARE_MODULE_AV1(accept, NULL, NULL, accept_clist, NULL, NULL, "$Revision: 26 $");
55 * m_accept - ACCEPT command handler
56 * parv[0] = sender prefix
57 * parv[1] = servername
59 static int
60 m_accept(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
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;
69 if(*parv[1] == '*')
71 list_accepts(source_p);
72 return 0;
75 build_nicklist(source_p, addbuf, delbuf, parv[1]);
77 /* parse the delete list */
78 for (nick = strtoken(&p, delbuf, ","); nick != NULL; nick = strtoken(&p, NULL, ","))
80 /* shouldnt happen, but lets be paranoid */
81 if((target_p = find_named_person(nick)) == NULL)
83 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
84 form_str(ERR_NOSUCHNICK), nick);
85 continue;
88 /* user isnt on clients accept list */
89 if(!accept_message(target_p, source_p))
91 sendto_one(source_p, form_str(ERR_ACCEPTNOT),
92 me.name, source_p->name, target_p->name);
93 continue;
96 dlinkFindDestroy(target_p, &source_p->localClient->allow_list);
97 dlinkFindDestroy(source_p, &target_p->on_allow_list);
100 /* get the number of accepts they have */
101 accept_num = dlink_list_length(&source_p->localClient->allow_list);
103 /* parse the add list */
104 for (nick = strtoken(&p, addbuf, ","); nick; nick = strtoken(&p, NULL, ","))
106 /* shouldnt happen, but lets be paranoid */
107 if((target_p = find_named_person(nick)) == NULL)
109 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
110 form_str(ERR_NOSUCHNICK), nick);
111 continue;
114 /* user is already on clients accept list */
115 if(accept_message(target_p, source_p))
117 sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
118 me.name, source_p->name, target_p->name);
119 continue;
122 if(accept_num >= ConfigFileEntry.max_accept)
124 sendto_one(source_p, form_str(ERR_ACCEPTFULL), me.name, source_p->name);
125 return 0;
128 /* why is this here? */
129 /* del_from accept(target_p, source_p); */
130 add_accept(source_p, target_p);
131 accept_num++;
134 return 0;
138 * build_nicklist()
140 * input - pointer to client
141 * - pointer to addbuffer
142 * - pointer to remove buffer
143 * - pointer to list of nicks
144 * output -
145 * side effects - addbuf/delbuf are modified to give valid nicks
147 static void
148 build_nicklist(struct Client *source_p, char *addbuf, char *delbuf, const char *nicks)
150 char *name;
151 char *p;
152 int lenadd;
153 int lendel;
154 int del;
155 struct Client *target_p;
156 char *n = LOCAL_COPY(nicks);
158 *addbuf = *delbuf = '\0';
159 del = lenadd = lendel = 0;
161 /* build list of clients to add into addbuf, clients to remove in delbuf */
162 for (name = strtoken(&p, n, ","); name; name = strtoken(&p, NULL, ","), del = 0)
164 if(*name == '-')
166 del = 1;
167 name++;
170 if((target_p = find_named_person(name)) == NULL)
172 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
173 form_str(ERR_NOSUCHNICK), name);
174 continue;
177 /* we're deleting a client */
178 if(del)
180 if(*delbuf)
181 (void) strcat(delbuf, ",");
183 (void) strncat(delbuf, name, BUFSIZE - lendel - 1);
184 lendel += strlen(name) + 1;
186 /* adding a client */
187 else
189 if(*addbuf)
190 (void) strcat(addbuf, ",");
192 (void) strncat(addbuf, name, BUFSIZE - lenadd - 1);
193 lenadd += strlen(name) + 1;
199 * add_accept()
201 * input - pointer to clients accept list to add to
202 * - pointer to client to add
203 * output - none
204 * side effects - target is added to clients list
206 static void
207 add_accept(struct Client *source_p, struct Client *target_p)
209 dlinkAddAlloc(target_p, &source_p->localClient->allow_list);
210 dlinkAddAlloc(source_p, &target_p->on_allow_list);
215 * list_accepts()
217 * input - pointer to client
218 * output - none
219 * side effects - print accept list to client
221 static void
222 list_accepts(struct Client *source_p)
224 dlink_node *ptr;
225 struct Client *target_p;
226 char nicks[BUFSIZE];
227 int len = 0;
228 int len2 = 0;
229 int count = 0;
231 *nicks = '\0';
232 len2 = strlen(source_p->name) + 10;
234 DLINK_FOREACH(ptr, source_p->localClient->allow_list.head)
236 target_p = ptr->data;
238 if(target_p)
241 if((len + strlen(target_p->name) + len2 > BUFSIZE) || count > 14)
243 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
244 me.name, source_p->name, nicks);
246 len = count = 0;
247 *nicks = '\0';
250 len += ircsnprintf(nicks + len, sizeof(nicks) - len, "%s ", target_p->name);
251 count++;
255 if(*nicks)
256 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
257 me.name, source_p->name, nicks);
259 sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
260 me.name, source_p->name);