]> jfr.im git - solanum.git/blame - modules/m_names.c
Add umode +I to allow users to hide their idle time (#220)
[solanum.git] / modules / m_names.c
CommitLineData
212380e3
AC
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
212380e3
AC
23 */
24
25#include "stdinc.h"
212380e3
AC
26#include "channel.h"
27#include "client.h"
212380e3 28#include "hash.h"
4562c604 29#include "match.h"
212380e3
AC
30#include "ircd.h"
31#include "numeric.h"
32#include "send.h"
33#include "s_serv.h"
34#include "s_conf.h"
35#include "msg.h"
36#include "parse.h"
37#include "modules.h"
d4f7eb4c 38#include "s_newconf.h"
212380e3 39
eeabf33a
EM
40static const char names_desc[] = "Provides the NAMES command to view users on a channel";
41
3c7d6fcc 42static void m_names(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
43
44struct Message names_msgtab = {
7baa37a9 45 "NAMES", 0, 0, 0, 0,
212380e3
AC
46 {mg_unreg, {m_names, 0}, mg_ignore, mg_ignore, mg_ignore, {m_names, 0}}
47};
48
49mapi_clist_av1 names_clist[] = { &names_msgtab, NULL };
1fe7d608 50
1fe7d608 51DECLARE_MODULE_AV2(names, NULL, NULL, names_clist, NULL, NULL, NULL, NULL, names_desc);
212380e3
AC
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
212380e3
AC
61 * parv[1] = channel
62 */
3c7d6fcc 63static void
428ca87b 64m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
65{
66 static time_t last_used = 0;
67 struct Channel *chptr = NULL;
68 char *s;
69
70 if(parc > 1 && !EmptyString(parv[1]))
71 {
72 char *p = LOCAL_COPY(parv[1]);
73 if((s = strchr(p, ',')))
74 *s = '\0';
75
76 if(!check_channel_name(p))
77 {
78 sendto_one_numeric(source_p, ERR_BADCHANNAME,
79 form_str(ERR_BADCHANNAME),
80 (unsigned char *) p);
3c7d6fcc 81 return;
212380e3
AC
82 }
83
84 if((chptr = find_channel(p)) != NULL)
85 channel_member_names(chptr, source_p, 1);
86 else
55abcbb2 87 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
212380e3
AC
88 me.name, source_p->name, p);
89 }
90 else
91 {
d4f7eb4c 92 if(!IsOperGeneral(source_p))
212380e3 93 {
e3354945 94 if((last_used + ConfigFileEntry.pace_wait) > rb_current_time())
212380e3
AC
95 {
96 sendto_one(source_p, form_str(RPL_LOAD2HI),
97 me.name, source_p->name, "NAMES");
98 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
99 me.name, source_p->name, "*");
3c7d6fcc 100 return;
212380e3
AC
101 }
102 else
e3354945 103 last_used = rb_current_time();
212380e3
AC
104 }
105
106 names_global(source_p);
55abcbb2 107 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
212380e3
AC
108 me.name, source_p->name, "*");
109 }
212380e3
AC
110}
111
112/*
113 * names_global
114 *
115 * inputs - pointer to client struct requesting names
116 * output - none
117 * side effects - lists all non public non secret channels
118 */
119static void
120names_global(struct Client *source_p)
121{
3c7d6fcc 122 bool dont_show = false;
31db8f00 123 rb_dlink_node *ptr;
212380e3
AC
124 struct Client *target_p;
125 struct Channel *chptr = NULL;
212380e3
AC
126
127 /* first do all visible channels */
5b96d9a6 128 RB_DLINK_FOREACH(ptr, global_channel_list.head)
212380e3
AC
129 {
130 chptr = ptr->data;
131 channel_member_names(chptr, source_p, 0);
132 }
e51d9a67
DF
133
134 send_multiline_init(source_p, " ", form_str(RPL_NAMREPLY),
135 me.name,
136 source_p->name,
137 "*",
138 "*");
212380e3
AC
139
140 /* Second, do all clients in one big sweep */
5b96d9a6 141 RB_DLINK_FOREACH(ptr, global_client_list.head)
212380e3 142 {
31db8f00
EK
143 rb_dlink_node *ps, *pt;
144 struct membership *ms, *mt;
145
212380e3 146 target_p = ptr->data;
3c7d6fcc 147 dont_show = false;
212380e3
AC
148
149 if(!IsPerson(target_p) || IsInvisible(target_p))
150 continue;
151
152 /* we want to show -i clients that are either:
153 * a) not on any channels
154 * b) only on +p channels
155 *
156 * both were missed out above. if the target is on a
157 * common channel with source, its already been shown.
158 */
31db8f00 159 ITER_COMM_CHANNELS(ps, pt, source_p->user->channel.head, target_p->user->channel.head, ms, mt, chptr)
212380e3 160 {
31db8f00 161 if (!mt) continue;
212380e3 162
31db8f00 163 if (PubChannel(chptr) || SecretChannel(chptr) || ms)
212380e3 164 {
3c7d6fcc 165 dont_show = true;
212380e3
AC
166 break;
167 }
168 }
169
170 if(dont_show)
171 continue;
172
54c7ead6 173 if (IsCapable(source_p, CLICAP_USERHOST_IN_NAMES))
212380e3 174 {
e51d9a67
DF
175 send_multiline_item(source_p, "%s!%s@%s",
176 target_p->name,
177 target_p->username,
178 target_p->host);
54c7ead6
EK
179 }
180 else
181 {
e51d9a67 182 send_multiline_item(source_p, "%s", target_p->name);
212380e3 183 }
212380e3
AC
184 }
185
e51d9a67 186 send_multiline_fini(source_p, NULL);
212380e3 187}