]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_names.c
Line doesn't exists in ratbox3 and makes compile warning - gone
[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"
212380e3 29#include "channel.h"
30#include "client.h"
31#include "common.h"
32#include "hash.h"
33#include "irc_string.h"
34#include "ircd.h"
35#include "numeric.h"
36#include "send.h"
37#include "s_serv.h"
38#include "s_conf.h"
39#include "msg.h"
40#include "parse.h"
41#include "modules.h"
42
43static int m_names(struct Client *, struct Client *, int, const char **);
44
45struct Message names_msgtab = {
46 "NAMES", 0, 0, 0, MFLG_SLOW,
47 {mg_unreg, {m_names, 0}, mg_ignore, mg_ignore, mg_ignore, {m_names, 0}}
48};
49
50mapi_clist_av1 names_clist[] = { &names_msgtab, NULL };
51DECLARE_MODULE_AV1(names, NULL, NULL, names_clist, NULL, NULL, "$Revision: 254 $");
52
53static void names_global(struct Client *source_p);
54
55/************************************************************************
56 * m_names() - Added by Jto 27 Apr 1989
57 ************************************************************************/
58
59/*
60 * m_names
61 * parv[0] = sender prefix
62 * parv[1] = channel
63 */
64static int
65m_names(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
66{
67 static time_t last_used = 0;
68 struct Channel *chptr = NULL;
69 char *s;
70
71 if(parc > 1 && !EmptyString(parv[1]))
72 {
73 char *p = LOCAL_COPY(parv[1]);
74 if((s = strchr(p, ',')))
75 *s = '\0';
76
77 if(!check_channel_name(p))
78 {
79 sendto_one_numeric(source_p, ERR_BADCHANNAME,
80 form_str(ERR_BADCHANNAME),
81 (unsigned char *) p);
82 return 0;
83 }
84
85 if((chptr = find_channel(p)) != NULL)
86 channel_member_names(chptr, source_p, 1);
87 else
88 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
89 me.name, source_p->name, p);
90 }
91 else
92 {
93 if(!IsOper(source_p))
94 {
9f6bbe3c 95 if((last_used + ConfigFileEntry.pace_wait) > rb_current_time())
212380e3 96 {
97 sendto_one(source_p, form_str(RPL_LOAD2HI),
98 me.name, source_p->name, "NAMES");
99 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
100 me.name, source_p->name, "*");
101 return 0;
102 }
103 else
9f6bbe3c 104 last_used = rb_current_time();
212380e3 105 }
106
107 names_global(source_p);
108 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
109 me.name, source_p->name, "*");
110 }
111
112 return 0;
113}
114
115/*
116 * names_global
117 *
118 * inputs - pointer to client struct requesting names
119 * output - none
120 * side effects - lists all non public non secret channels
121 */
122static void
123names_global(struct Client *source_p)
124{
125 int mlen;
126 int tlen;
127 int cur_len;
128 int dont_show = NO;
08d11e34 129 rb_dlink_node *lp, *ptr;
212380e3 130 struct Client *target_p;
131 struct Channel *chptr = NULL;
132 struct membership *msptr;
133 char buf[BUFSIZE];
134 char *t;
135
136 /* first do all visible channels */
08d11e34 137 RB_DLINK_FOREACH(ptr, global_channel_list.head)
212380e3 138 {
139 chptr = ptr->data;
140 channel_member_names(chptr, source_p, 0);
141 }
581fa5c4 142 cur_len = mlen = rb_sprintf(buf, form_str(RPL_NAMREPLY),
212380e3 143 me.name, source_p->name, "*", "*");
144 t = buf + mlen;
145
146 /* Second, do all clients in one big sweep */
08d11e34 147 RB_DLINK_FOREACH(ptr, global_client_list.head)
212380e3 148 {
149 target_p = ptr->data;
150 dont_show = NO;
151
152 if(!IsPerson(target_p) || IsInvisible(target_p))
153 continue;
154
155 /* we want to show -i clients that are either:
156 * a) not on any channels
157 * b) only on +p channels
158 *
159 * both were missed out above. if the target is on a
160 * common channel with source, its already been shown.
161 */
08d11e34 162 RB_DLINK_FOREACH(lp, target_p->user->channel.head)
212380e3 163 {
164 msptr = lp->data;
165 chptr = msptr->chptr;
166
167 if(PubChannel(chptr) || IsMember(source_p, chptr) ||
168 SecretChannel(chptr))
169 {
170 dont_show = YES;
171 break;
172 }
173 }
174
175 if(dont_show)
176 continue;
177
178 if((cur_len + NICKLEN + 2) > (BUFSIZE - 3))
179 {
180 sendto_one(source_p, "%s", buf);
181 cur_len = mlen;
182 t = buf + mlen;
183 }
184
581fa5c4 185 tlen = rb_sprintf(t, "%s ", target_p->name);
212380e3 186 cur_len += tlen;
187 t += tlen;
188 }
189
190 if(cur_len > mlen)
191 sendto_one(source_p, "%s", buf);
192}