ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_names.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (15 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_names.c
File size: 4744 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

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

Properties

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