ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_names.c
Revision: 1876
Committed: Sat Apr 27 09:36:33 2013 UTC (13 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 4589 byte(s)
Log Message:
- m_whowas.c,m_names.c,m_kick.c: remove pointless code. There's no real reason why
  we should skip preceding commas in nick-/channelnames

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

Properties

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