ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_names.c
Revision: 632
Committed: Thu Jun 1 10:53:00 2006 UTC (17 years, 10 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_names.c
File size: 5490 byte(s)
Log Message:
- Added channel::disable_fake_channels which disallows creation of channels
  that have ascii 2, 3, 31 and 160 in their names.
- Minor improvements and cleanups to channel name validation routines
  backported from 7.3

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

Properties

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