ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_names.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: 5570 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_names.c: Shows the users who are online.
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 "channel.h"
28     #include "channel_mode.h"
29     #include "client.h"
30     #include "common.h" /* bleah */
31     #include "hash.h"
32     #include "ircd.h"
33     #include "numeric.h"
34     #include "send.h"
35     #include "s_serv.h"
36     #include "s_conf.h"
37     #include "msg.h"
38     #include "parse.h"
39     #include "modules.h"
40    
41    
42     static void names_all_visible_channels(struct Client *);
43     static void names_non_public_non_secret(struct Client *);
44    
45     static void m_names(struct Client *, struct Client *, int, char *[]);
46     static void ms_names(struct Client *, struct Client *, int, char *[]);
47    
48     struct Message names_msgtab = {
49     "NAMES", 0, 0, 0, 0, MFLG_SLOW, 0,
50     {m_unregistered, m_names, ms_names, m_ignore, m_names, m_ignore}
51     };
52    
53     #ifndef STATIC_MODULES
54     void
55     _modinit(void)
56     {
57     mod_add_cmd(&names_msgtab);
58     }
59    
60     void
61     _moddeinit(void)
62     {
63     mod_del_cmd(&names_msgtab);
64     }
65    
66 knight 31 const char *_version = "$Revision$";
67 adx 30 #endif
68    
69     /************************************************************************
70     * m_names() - Added by Jto 27 Apr 1989
71     ************************************************************************/
72    
73     /*
74     ** m_names
75     ** parv[0] = sender prefix
76     ** parv[1] = channel
77     */
78     static void
79     m_names(struct Client *client_p, struct Client *source_p,
80     int parc, char *parv[])
81     {
82     struct Channel *chptr = NULL;
83     char *s;
84     char *para = parc > 1 ? parv[1] : NULL;
85    
86     if (!EmptyString(para))
87     {
88     while (*para == ',')
89     para++;
90    
91     if ((s = strchr(para, ',')) != NULL)
92     *s = '\0';
93    
94     if (*para == '\0')
95     return;
96    
97     if (!check_channel_name(para))
98     {
99     sendto_one(source_p, form_str(ERR_BADCHANNAME),
100     me.name, source_p->name, para);
101     return;
102     }
103    
104     if ((chptr = hash_find_channel(para)) != NULL)
105     channel_member_names(source_p, chptr, 1);
106     else
107     sendto_one(source_p, form_str(RPL_ENDOFNAMES),
108     me.name, source_p->name, para);
109     }
110     else
111     {
112     names_all_visible_channels(source_p);
113     names_non_public_non_secret(source_p);
114     sendto_one(source_p, form_str(RPL_ENDOFNAMES),
115     me.name, source_p->name, "*");
116     }
117     }
118    
119     /* names_all_visible_channels()
120     *
121     * inputs - pointer to client struct requesting names
122     * output - none
123     * side effects - lists all visible channels whee!
124     */
125     static void
126     names_all_visible_channels(struct Client *source_p)
127     {
128     dlink_node *ptr;
129     struct Channel *chptr;
130    
131     /*
132     * First, do all visible channels (public and the one user self is)
133     */
134     DLINK_FOREACH(ptr, global_channel_list.head)
135     {
136     chptr = ptr->data;
137    
138     /* Find users on same channel (defined by chptr) */
139     channel_member_names(source_p, chptr, 0);
140     }
141     }
142    
143     /* names_non_public_non_secret()
144     *
145     * inputs - pointer to client struct requesting names
146     * output - none
147     * side effects - lists all non public non secret channels
148     */
149     static void
150     names_non_public_non_secret(struct Client *source_p)
151     {
152     int mlen, tlen, cur_len;
153     int reply_to_send = NO;
154     int shown_already;
155     dlink_node *gc2ptr, *lp;
156     struct Client *c2ptr;
157     struct Channel *ch3ptr = NULL;
158     char buf[IRCD_BUFSIZE];
159     char *t;
160    
161     mlen = ircsprintf(buf,form_str(RPL_NAMREPLY),
162     me.name, source_p->name, "*", "*");
163     cur_len = mlen;
164     t = buf + mlen;
165    
166     /* Second, do all non-public, non-secret channels in one big sweep */
167     DLINK_FOREACH(gc2ptr, global_client_list.head)
168     {
169     c2ptr = gc2ptr->data;
170    
171     if (!IsClient(c2ptr) || IsInvisible(c2ptr))
172     continue;
173    
174     shown_already = NO;
175    
176     /* We already know the user is not +i. If they are on no common
177     * channels with source_p, they have not been shown yet. */
178     DLINK_FOREACH(lp, c2ptr->channel.head)
179     {
180     ch3ptr = ((struct Membership *) lp->data)->chptr;
181    
182     if (IsMember(source_p, ch3ptr))
183     {
184     shown_already = YES;
185     break;
186     }
187     }
188    
189     if (shown_already)
190     continue;
191    
192     tlen = strlen(c2ptr->name);
193     if (cur_len + tlen + 1 > IRCD_BUFSIZE - 2)
194     {
195     sendto_one(source_p, "%s", buf);
196     cur_len = mlen;
197     t = buf + mlen;
198     }
199    
200     strcpy(t, c2ptr->name);
201     t += tlen;
202    
203     *t++ = ' ';
204     *t = 0;
205    
206     cur_len += tlen + 1;
207    
208     reply_to_send = YES;
209     }
210    
211     if (reply_to_send)
212     sendto_one(source_p, "%s", buf);
213     }
214    
215     static void
216     ms_names(struct Client *client_p, struct Client *source_p,
217     int parc, char *parv[])
218     {
219     /* If its running as a hub, and linked with lazy links
220     * then allow leaf to use normal client m_names()
221     * other wise, ignore it.
222     */
223     if (ServerInfo.hub)
224     {
225     if (!IsCapable(client_p->from, CAP_LL))
226     return;
227     }
228    
229     if (IsClient(source_p))
230     m_names(client_p, source_p, parc, parv);
231     }

Properties

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