ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_accept.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 6336 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "hash.h" /* for find_client() */
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 "s_user.h"
37     #include "modules.h"
38    
39     static void m_accept(struct Client *, struct Client *, int, char *[]);
40     static void build_nicklist(struct Client *, char *, char *, char *);
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, 0, MFLG_SLOW, 0,
46     {m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore}
47     };
48    
49     #ifndef STATIC_MODULES
50     void
51     _modinit(void)
52     {
53     mod_add_cmd(&accept_msgtab);
54     }
55    
56     void
57     _moddeinit(void)
58     {
59     mod_del_cmd(&accept_msgtab);
60     }
61    
62 knight 31 const char *_version = "$Revision$";
63 adx 30 #endif
64    
65     /*
66     * m_accept - ACCEPT command handler
67     * parv[0] = sender prefix
68     * parv[1] = servername
69     */
70     static void
71     m_accept(struct Client *client_p, struct Client *source_p,
72     int parc, char *parv[])
73     {
74     char *nick;
75     char *p = NULL;
76     char addbuf[IRCD_BUFSIZE] = { '\0' };
77     char delbuf[IRCD_BUFSIZE] = { '\0' };
78     struct Client *target_p = NULL;
79     int accept_num;
80    
81     if ((parc < 2) || (*parv[1] == '*'))
82     {
83     list_accepts(source_p);
84     return;
85     }
86    
87     build_nicklist(source_p, addbuf, delbuf, parv[1]);
88    
89     /* parse the delete list */
90     for (nick = strtoken(&p, delbuf, ","); nick != NULL;
91     nick = strtoken(&p, NULL, ","))
92     {
93     /* shouldnt happen, but lets be paranoid */
94     if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p))
95     {
96     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
97     me.name, source_p->name, nick);
98     continue;
99     }
100    
101     /* user isnt on clients accept list */
102     if (!accept_message(target_p, source_p))
103     {
104     sendto_one(source_p, form_str(ERR_ACCEPTNOT),
105     me.name, source_p->name, target_p->name);
106     continue;
107     }
108    
109     del_from_accept(target_p, source_p);
110     }
111    
112     /* get the number of accepts they have */
113     accept_num = dlink_list_length(&source_p->allow_list);
114    
115     /* parse the add list */
116     for (nick = strtoken(&p, addbuf, ","); nick;
117     nick = strtoken(&p, NULL, ","), accept_num++)
118     {
119     /* shouldnt happen, but lets be paranoid */
120     if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p))
121     {
122     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
123     me.name, source_p->name, nick);
124     continue;
125     }
126    
127     /* user is already on clients accept list */
128     if (accept_message(target_p, source_p))
129     {
130     sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
131     me.name, source_p->name, target_p->name);
132     continue;
133     }
134    
135     if (accept_num >= ConfigFileEntry.max_accept)
136     {
137     sendto_one(source_p, form_str(ERR_ACCEPTFULL),
138     me.name, source_p->name);
139     return;
140     }
141    
142     /* why is this here? */
143     /* del_from accept(target_p, source_p); */
144     add_accept(source_p, target_p);
145     }
146     }
147    
148     /* build_nicklist()
149     *
150     * input - pointer to client
151     * - pointer to addbuffer
152     * - pointer to remove buffer
153     * - pointer to list of nicks
154     * output -
155     * side effects - addbuf/delbuf are modified to give valid nicks
156     */
157     static void
158     build_nicklist(struct Client *source_p, char *addbuf,
159     char *delbuf, char *nicks)
160     {
161     char *name = NULL;
162     char *p = NULL;
163     char *buf_p = NULL;
164     struct Client *target_p = NULL;
165    
166     /* build list of clients to add into addbuf, clients to remove in delbuf */
167     for (name = strtoken(&p, nicks, ","); name;
168     name = strtoken(&p, NULL, ","))
169     {
170     if (*name == '-')
171     buf_p = delbuf, ++name;
172     else
173     buf_p = addbuf;
174    
175     if (((target_p = find_client(name)) == NULL) || !IsClient(target_p))
176     {
177     sendto_one(source_p, form_str(ERR_NOSUCHNICK),
178     me.name, source_p->name, name);
179     continue;
180     }
181    
182     if (*buf_p)
183     strlcat(buf_p, ",", IRCD_BUFSIZE);
184     strlcat(buf_p, name, IRCD_BUFSIZE);
185     }
186     }
187    
188     /* add_accept()
189     *
190     * input - pointer to clients accept list to add to
191     * - pointer to client to add
192     * output - none
193     * side effects - target is added to clients list
194     */
195     static void
196     add_accept(struct Client *source_p, struct Client *target_p)
197     {
198     dlinkAdd(target_p, make_dlink_node(), &source_p->allow_list);
199     dlinkAdd(source_p, make_dlink_node(), &target_p->on_allow_list);
200     list_accepts(source_p);
201     }
202    
203     /* list_accepts()
204     *
205     * input - pointer to client
206     * output - none
207     * side effects - print accept list to client
208     */
209     static void
210     list_accepts(struct Client *source_p)
211     {
212     int len = 0;
213     char nicks[IRCD_BUFSIZE] = { '\0' };
214     char *t = nicks;
215     const dlink_node *ptr = NULL;
216    
217     len = strlen(me.name) + strlen(source_p->name) + 12;
218    
219     DLINK_FOREACH(ptr, source_p->allow_list.head)
220     {
221     const struct Client *target_p = ptr->data;
222    
223     if ((t - nicks) + strlen(target_p->name) + len > IRCD_BUFSIZE)
224     {
225     *(t - 1) = '\0';
226     sendto_one(source_p, form_str(RPL_ACCEPTLIST),
227     me.name, source_p->name, nicks);
228     t = nicks;
229     }
230    
231     t += ircsprintf(t, "%s ", target_p->name);
232     }
233    
234     if (nicks[0] != '\0')
235     {
236     *(t - 1) = '\0';
237     sendto_one(source_p, form_str(RPL_ACCEPTLIST),
238     me.name, source_p->name, nicks);
239     }
240    
241     sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
242     me.name, source_p->name);
243     }

Properties

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