ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_names.c
Revision: 1832
Committed: Fri Apr 19 19:16:09 2013 UTC (13 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 4599 byte(s)
Log Message:
- Made all numeric defines use the actual string instead of the numeric value
  which allows to use gcc's printf format attribute
- Remove current message locale implementation

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), 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 while (*para == ',')
147 ++para;
148
149 if ((s = strchr(para, ',')) != NULL)
150 *s = '\0';
151
152 if (*para == '\0')
153 return;
154
155 if ((chptr = hash_find_channel(para)) != NULL)
156 channel_member_names(source_p, chptr, 1);
157 else
158 sendto_one(source_p, RPL_ENDOFNAMES,
159 me.name, source_p->name, para);
160 }
161 else
162 {
163 names_all_visible_channels(source_p);
164 names_non_public_non_secret(source_p);
165 sendto_one(source_p, RPL_ENDOFNAMES,
166 me.name, source_p->name, "*");
167 }
168 }
169
170 static struct Message names_msgtab = {
171 "NAMES", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
172 {m_unregistered, m_names, m_ignore, m_ignore, m_names, m_ignore}
173 };
174
175 static void
176 module_init(void)
177 {
178 mod_add_cmd(&names_msgtab);
179 }
180
181 static void
182 module_exit(void)
183 {
184 mod_del_cmd(&names_msgtab);
185 }
186
187 struct module module_entry = {
188 .node = { NULL, NULL, NULL },
189 .name = NULL,
190 .version = "$Revision$",
191 .handle = NULL,
192 .modinit = module_init,
193 .modexit = module_exit,
194 .flags = 0
195 };

Properties

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