ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/releases/8.0.0beta2/modules/m_names.c
Revision: 1178
Committed: Mon Aug 15 08:11:31 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_names.c
File size: 4926 byte(s)
Log Message:
- Cleanup and restore older parts of the irc-command parser.
  Gives back ability to specify maximum amount of parameters
  that are processed within a command.

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 michael 1011 #include "list.h"
27 adx 30 #include "handlers.h"
28     #include "channel.h"
29     #include "channel_mode.h"
30     #include "client.h"
31     #include "common.h" /* bleah */
32     #include "hash.h"
33     #include "irc_string.h"
34     #include "sprintf_irc.h"
35     #include "ircd.h"
36     #include "numeric.h"
37     #include "send.h"
38     #include "s_serv.h"
39     #include "s_conf.h"
40     #include "msg.h"
41     #include "parse.h"
42     #include "modules.h"
43    
44    
45     static void names_all_visible_channels(struct Client *);
46     static void names_non_public_non_secret(struct Client *);
47     static void m_names(struct Client *, struct Client *, int, char *[]);
48    
49     struct Message names_msgtab = {
50 michael 1178 "NAMES", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
51 michael 885 {m_unregistered, m_names, m_ignore, m_ignore, m_names, m_ignore}
52 adx 30 };
53    
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
68     /************************************************************************
69     * m_names() - Added by Jto 27 Apr 1989
70     ************************************************************************/
71    
72     /*
73     ** m_names
74     ** parv[0] = sender prefix
75     ** parv[1] = channel
76     */
77     static void
78     m_names(struct Client *client_p, struct Client *source_p,
79     int parc, char *parv[])
80     {
81     struct Channel *chptr = NULL;
82     char *s;
83     char *para = parc > 1 ? parv[1] : NULL;
84    
85     if (!EmptyString(para))
86     {
87     while (*para == ',')
88 michael 632 ++para;
89 adx 30
90     if ((s = strchr(para, ',')) != NULL)
91     *s = '\0';
92    
93     if (*para == '\0')
94     return;
95    
96     if ((chptr = hash_find_channel(para)) != NULL)
97     channel_member_names(source_p, chptr, 1);
98     else
99     sendto_one(source_p, form_str(RPL_ENDOFNAMES),
100     me.name, source_p->name, para);
101     }
102     else
103     {
104     names_all_visible_channels(source_p);
105     names_non_public_non_secret(source_p);
106     sendto_one(source_p, form_str(RPL_ENDOFNAMES),
107     me.name, source_p->name, "*");
108     }
109     }
110    
111     /* names_all_visible_channels()
112     *
113     * inputs - pointer to client struct requesting names
114     * output - none
115     * side effects - lists all visible channels whee!
116     */
117     static void
118     names_all_visible_channels(struct Client *source_p)
119     {
120 michael 885 dlink_node *ptr = NULL;
121 adx 30
122     /*
123     * First, do all visible channels (public and the one user self is)
124     */
125     DLINK_FOREACH(ptr, global_channel_list.head)
126     {
127     /* Find users on same channel (defined by chptr) */
128 michael 885 channel_member_names(source_p, ptr->data, 0);
129 adx 30 }
130     }
131    
132     /* names_non_public_non_secret()
133     *
134     * inputs - pointer to client struct requesting names
135     * output - none
136     * side effects - lists all non public non secret channels
137     */
138     static void
139     names_non_public_non_secret(struct Client *source_p)
140     {
141     int mlen, tlen, cur_len;
142     int reply_to_send = NO;
143     int shown_already;
144     dlink_node *gc2ptr, *lp;
145     struct Client *c2ptr;
146     struct Channel *ch3ptr = NULL;
147     char buf[IRCD_BUFSIZE];
148     char *t;
149    
150 michael 1011 mlen = ircsprintf(buf, form_str(RPL_NAMREPLY), me.name,
151     source_p->name, "*", "*");
152 adx 30 cur_len = mlen;
153     t = buf + mlen;
154    
155     /* Second, do all non-public, non-secret channels in one big sweep */
156     DLINK_FOREACH(gc2ptr, global_client_list.head)
157     {
158     c2ptr = gc2ptr->data;
159    
160     if (!IsClient(c2ptr) || IsInvisible(c2ptr))
161     continue;
162    
163     shown_already = NO;
164    
165     /* We already know the user is not +i. If they are on no common
166     * channels with source_p, they have not been shown yet. */
167     DLINK_FOREACH(lp, c2ptr->channel.head)
168     {
169     ch3ptr = ((struct Membership *) lp->data)->chptr;
170    
171     if (IsMember(source_p, ch3ptr))
172     {
173     shown_already = YES;
174     break;
175     }
176     }
177    
178     if (shown_already)
179     continue;
180    
181     tlen = strlen(c2ptr->name);
182     if (cur_len + tlen + 1 > IRCD_BUFSIZE - 2)
183     {
184     sendto_one(source_p, "%s", buf);
185     cur_len = mlen;
186     t = buf + mlen;
187     }
188    
189     strcpy(t, c2ptr->name);
190     t += tlen;
191    
192     *t++ = ' ';
193     *t = 0;
194    
195     cur_len += tlen + 1;
196    
197     reply_to_send = YES;
198     }
199    
200     if (reply_to_send)
201     sendto_one(source_p, "%s", buf);
202     }

Properties

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