]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_names.c
Various changes for libratbox.
[irc/rqf/shadowircd.git] / modules / m_names.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_names.c: Shows the users who are online.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
24 * $Id: m_names.c 254 2005-09-21 23:35:12Z nenolod $
25 */
26
27#include "stdinc.h"
28#include "sprintf_irc.h"
29#include "tools.h"
30#include "channel.h"
31#include "client.h"
32#include "common.h"
33#include "hash.h"
34#include "irc_string.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
44static int m_names(struct Client *, struct Client *, int, const char **);
45
46struct Message names_msgtab = {
47 "NAMES", 0, 0, 0, MFLG_SLOW,
48 {mg_unreg, {m_names, 0}, mg_ignore, mg_ignore, mg_ignore, {m_names, 0}}
49};
50
51mapi_clist_av1 names_clist[] = { &names_msgtab, NULL };
52DECLARE_MODULE_AV1(names, NULL, NULL, names_clist, NULL, NULL, "$Revision: 254 $");
53
54static void names_global(struct Client *source_p);
55
56/************************************************************************
57 * m_names() - Added by Jto 27 Apr 1989
58 ************************************************************************/
59
60/*
61 * m_names
62 * parv[0] = sender prefix
63 * parv[1] = channel
64 */
65static int
66m_names(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
67{
68 static time_t last_used = 0;
69 struct Channel *chptr = NULL;
70 char *s;
71
72 if(parc > 1 && !EmptyString(parv[1]))
73 {
74 char *p = LOCAL_COPY(parv[1]);
75 if((s = strchr(p, ',')))
76 *s = '\0';
77
78 if(!check_channel_name(p))
79 {
80 sendto_one_numeric(source_p, ERR_BADCHANNAME,
81 form_str(ERR_BADCHANNAME),
82 (unsigned char *) p);
83 return 0;
84 }
85
86 if((chptr = find_channel(p)) != NULL)
87 channel_member_names(chptr, source_p, 1);
88 else
89 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
90 me.name, source_p->name, p);
91 }
92 else
93 {
94 if(!IsOper(source_p))
95 {
96 if((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
97 {
98 sendto_one(source_p, form_str(RPL_LOAD2HI),
99 me.name, source_p->name, "NAMES");
100 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
101 me.name, source_p->name, "*");
102 return 0;
103 }
104 else
105 last_used = CurrentTime;
106 }
107
108 names_global(source_p);
109 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
110 me.name, source_p->name, "*");
111 }
112
113 return 0;
114}
115
116/*
117 * names_global
118 *
119 * inputs - pointer to client struct requesting names
120 * output - none
121 * side effects - lists all non public non secret channels
122 */
123static void
124names_global(struct Client *source_p)
125{
126 int mlen;
127 int tlen;
128 int cur_len;
129 int dont_show = NO;
08d11e34 130 rb_dlink_node *lp, *ptr;
212380e3 131 struct Client *target_p;
132 struct Channel *chptr = NULL;
133 struct membership *msptr;
134 char buf[BUFSIZE];
135 char *t;
136
137 /* first do all visible channels */
08d11e34 138 RB_DLINK_FOREACH(ptr, global_channel_list.head)
212380e3 139 {
140 chptr = ptr->data;
141 channel_member_names(chptr, source_p, 0);
142 }
581fa5c4 143 cur_len = mlen = rb_sprintf(buf, form_str(RPL_NAMREPLY),
212380e3 144 me.name, source_p->name, "*", "*");
145 t = buf + mlen;
146
147 /* Second, do all clients in one big sweep */
08d11e34 148 RB_DLINK_FOREACH(ptr, global_client_list.head)
212380e3 149 {
150 target_p = ptr->data;
151 dont_show = NO;
152
153 if(!IsPerson(target_p) || IsInvisible(target_p))
154 continue;
155
156 /* we want to show -i clients that are either:
157 * a) not on any channels
158 * b) only on +p channels
159 *
160 * both were missed out above. if the target is on a
161 * common channel with source, its already been shown.
162 */
08d11e34 163 RB_DLINK_FOREACH(lp, target_p->user->channel.head)
212380e3 164 {
165 msptr = lp->data;
166 chptr = msptr->chptr;
167
168 if(PubChannel(chptr) || IsMember(source_p, chptr) ||
169 SecretChannel(chptr))
170 {
171 dont_show = YES;
172 break;
173 }
174 }
175
176 if(dont_show)
177 continue;
178
179 if((cur_len + NICKLEN + 2) > (BUFSIZE - 3))
180 {
181 sendto_one(source_p, "%s", buf);
182 cur_len = mlen;
183 t = buf + mlen;
184 }
185
581fa5c4 186 tlen = rb_sprintf(t, "%s ", target_p->name);
212380e3 187 cur_len += tlen;
188 t += tlen;
189 }
190
191 if(cur_len > mlen)
192 sendto_one(source_p, "%s", buf);
193}