ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_names.c
Revision: 1592
Committed: Sat Oct 27 21:02:32 2012 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 4654 byte(s)
Log Message:
- Second time's the charm? Moving svnroot/ircd-hybrid-8 to
  svnroot/ircd-hybrid/trunk

File Contents

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

Properties

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