/[svn]/ircd-hybrid-7.2/modules/m_accept.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/modules/m_accept.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (show annotations)
Sun Oct 2 21:05:51 2005 UTC (14 years ago) by lusky
File MIME type: text/x-chdr
File size: 6403 byte(s)
create 7.2 branch, we can move/rename it as needed.


1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_accept.c: Allows a user to talk to a +g user.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "handlers.h"
27 #include "client.h"
28 #include "irc_string.h"
29 #include "sprintf_irc.h"
30 #include "hash.h" /* for find_client() */
31 #include "ircd.h"
32 #include "list.h"
33 #include "numeric.h"
34 #include "s_conf.h"
35 #include "s_serv.h"
36 #include "send.h"
37 #include "msg.h"
38 #include "parse.h"
39 #include "s_user.h"
40 #include "modules.h"
41
42 static void m_accept(struct Client *, struct Client *, int, char *[]);
43 static void build_nicklist(struct Client *, char *, char *, char *);
44 static void add_accept(struct Client *, struct Client *);
45 static void list_accepts(struct Client *);
46
47 struct Message accept_msgtab = {
48 "ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0,
49 {m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore}
50 };
51
52 #ifndef STATIC_MODULES
53 void
54 _modinit(void)
55 {
56 mod_add_cmd(&accept_msgtab);
57 }
58
59 void
60 _moddeinit(void)
61 {
62 mod_del_cmd(&accept_msgtab);
63 }
64
65 const char *_version = "$Revision$";
66 #endif
67
68 /*
69 * m_accept - ACCEPT command handler
70 * parv[0] = sender prefix
71 * parv[1] = servername
72 */
73 static void
74 m_accept(struct Client *client_p, struct Client *source_p,
75 int parc, char *parv[])
76 {
77 char *nick;
78 char *p = NULL;
79 char addbuf[IRCD_BUFSIZE] = { '\0' };
80 char delbuf[IRCD_BUFSIZE] = { '\0' };
81 struct Client *target_p = NULL;
82 int accept_num;
83
84 if ((parc < 2) || (*parv[1] == '*'))
85 {
86 list_accepts(source_p);
87 return;
88 }
89
90 build_nicklist(source_p, addbuf, delbuf, parv[1]);
91
92 /* parse the delete list */
93 for (nick = strtoken(&p, delbuf, ","); nick != NULL;
94 nick = strtoken(&p, NULL, ","))
95 {
96 /* shouldnt happen, but lets be paranoid */
97 if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p))
98 {
99 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
100 me.name, source_p->name, nick);
101 continue;
102 }
103
104 /* user isnt on clients accept list */
105 if (!accept_message(target_p, source_p))
106 {
107 sendto_one(source_p, form_str(ERR_ACCEPTNOT),
108 me.name, source_p->name, target_p->name);
109 continue;
110 }
111
112 del_from_accept(target_p, source_p);
113 }
114
115 /* get the number of accepts they have */
116 accept_num = dlink_list_length(&source_p->allow_list);
117
118 /* parse the add list */
119 for (nick = strtoken(&p, addbuf, ","); nick;
120 nick = strtoken(&p, NULL, ","), accept_num++)
121 {
122 /* shouldnt happen, but lets be paranoid */
123 if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p))
124 {
125 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
126 me.name, source_p->name, nick);
127 continue;
128 }
129
130 /* user is already on clients accept list */
131 if (accept_message(target_p, source_p))
132 {
133 sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
134 me.name, source_p->name, target_p->name);
135 continue;
136 }
137
138 if (accept_num >= ConfigFileEntry.max_accept)
139 {
140 sendto_one(source_p, form_str(ERR_ACCEPTFULL),
141 me.name, source_p->name);
142 return;
143 }
144
145 /* why is this here? */
146 /* del_from accept(target_p, source_p); */
147 add_accept(source_p, target_p);
148 }
149 }
150
151 /* build_nicklist()
152 *
153 * input - pointer to client
154 * - pointer to addbuffer
155 * - pointer to remove buffer
156 * - pointer to list of nicks
157 * output -
158 * side effects - addbuf/delbuf are modified to give valid nicks
159 */
160 static void
161 build_nicklist(struct Client *source_p, char *addbuf,
162 char *delbuf, char *nicks)
163 {
164 char *name = NULL;
165 char *p = NULL;
166 char *buf_p = NULL;
167 struct Client *target_p = NULL;
168
169 /* build list of clients to add into addbuf, clients to remove in delbuf */
170 for (name = strtoken(&p, nicks, ","); name;
171 name = strtoken(&p, NULL, ","))
172 {
173 if (*name == '-')
174 buf_p = delbuf, ++name;
175 else
176 buf_p = addbuf;
177
178 if (((target_p = find_client(name)) == NULL) || !IsClient(target_p))
179 {
180 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
181 me.name, source_p->name, name);
182 continue;
183 }
184
185 if (*buf_p)
186 strlcat(buf_p, ",", IRCD_BUFSIZE);
187 strlcat(buf_p, name, IRCD_BUFSIZE);
188 }
189 }
190
191 /* add_accept()
192 *
193 * input - pointer to clients accept list to add to
194 * - pointer to client to add
195 * output - none
196 * side effects - target is added to clients list
197 */
198 static void
199 add_accept(struct Client *source_p, struct Client *target_p)
200 {
201 dlinkAdd(target_p, make_dlink_node(), &source_p->allow_list);
202 dlinkAdd(source_p, make_dlink_node(), &target_p->on_allow_list);
203 list_accepts(source_p);
204 }
205
206 /* list_accepts()
207 *
208 * input - pointer to client
209 * output - none
210 * side effects - print accept list to client
211 */
212 static void
213 list_accepts(struct Client *source_p)
214 {
215 int len = 0;
216 char nicks[IRCD_BUFSIZE] = { '\0' };
217 char *t = nicks;
218 const dlink_node *ptr = NULL;
219
220 len = strlen(me.name) + strlen(source_p->name) + 12;
221
222 DLINK_FOREACH(ptr, source_p->allow_list.head)
223 {
224 const struct Client *target_p = ptr->data;
225
226 if ((t - nicks) + strlen(target_p->name) + len > IRCD_BUFSIZE)
227 {
228 *(t - 1) = '\0';
229 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
230 me.name, source_p->name, nicks);
231 t = nicks;
232 }
233
234 t += ircsprintf(t, "%s ", target_p->name);
235 }
236
237 if (nicks[0] != '\0')
238 {
239 *(t - 1) = '\0';
240 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
241 me.name, source_p->name, nicks);
242 }
243
244 sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
245 me.name, source_p->name);
246 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.26