Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_names.c
blob38c1471887b1942c563ccc36924be116573e282b
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_names.c: Shows the users who are online.
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
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.
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.
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
25 #include "stdinc.h"
26 #include "sprintf_irc.h"
27 #include "tools.h"
28 #include "channel.h"
29 #include "client.h"
30 #include "common.h"
31 #include "hash.h"
32 #include "irc_string.h"
33 #include "ircd.h"
34 #include "numeric.h"
35 #include "send.h"
36 #include "s_serv.h"
37 #include "s_conf.h"
38 #include "msg.h"
39 #include "parse.h"
40 #include "modules.h"
42 static int m_names(struct Client *, struct Client *, int, const char **);
44 struct Message names_msgtab = {
45 "NAMES", 0, 0, 0, MFLG_SLOW,
46 {mg_unreg, {m_names, 0}, mg_ignore, mg_ignore, mg_ignore, {m_names, 0}}
49 mapi_clist_av1 names_clist[] = { &names_msgtab, NULL };
50 DECLARE_MODULE_AV1(names, NULL, NULL, names_clist, NULL, NULL, "$Revision: 26 $");
52 static void names_global(struct Client *source_p);
54 /************************************************************************
55 * m_names() - Added by Jto 27 Apr 1989
56 ************************************************************************/
59 * m_names
60 * parv[0] = sender prefix
61 * parv[1] = channel
63 static int
64 m_names(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
66 static time_t last_used = 0;
67 struct Channel *chptr = NULL;
68 char *s;
70 if(parc > 1 && !EmptyString(parv[1]))
72 char *p = LOCAL_COPY(parv[1]);
73 if((s = strchr(p, ',')))
74 *s = '\0';
76 if(!check_channel_name(p))
78 sendto_one_numeric(source_p, ERR_BADCHANNAME,
79 form_str(ERR_BADCHANNAME),
80 (unsigned char *) p);
81 return 0;
84 if((chptr = find_channel(p)) != NULL)
85 channel_member_names(chptr, source_p, 1);
86 else
87 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
88 me.name, source_p->name, p);
90 else
92 if(!IsOper(source_p))
94 if((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
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, "*");
100 return 0;
102 else
103 last_used = CurrentTime;
106 names_global(source_p);
107 sendto_one(source_p, form_str(RPL_ENDOFNAMES),
108 me.name, source_p->name, "*");
111 return 0;
115 * names_global
117 * inputs - pointer to client struct requesting names
118 * output - none
119 * side effects - lists all non public non secret channels
121 static void
122 names_global(struct Client *source_p)
124 int mlen;
125 int tlen;
126 int cur_len;
127 int dont_show = NO;
128 dlink_node *lp, *ptr;
129 struct Client *target_p;
130 struct Channel *chptr = NULL;
131 struct membership *msptr;
132 char buf[BUFSIZE];
133 char *t;
135 /* first do all visible channels */
136 DLINK_FOREACH(ptr, global_channel_list.head)
138 chptr = ptr->data;
139 channel_member_names(chptr, source_p, 0);
141 cur_len = mlen = ircsprintf(buf, form_str(RPL_NAMREPLY),
142 me.name, source_p->name, "*", "*");
143 t = buf + mlen;
145 /* Second, do all clients in one big sweep */
146 DLINK_FOREACH(ptr, global_client_list.head)
148 target_p = ptr->data;
149 dont_show = NO;
151 if(!IsPerson(target_p) || IsInvisible(target_p))
152 continue;
154 /* we want to show -i clients that are either:
155 * a) not on any channels
156 * b) only on +p channels
158 * both were missed out above. if the target is on a
159 * common channel with source, its already been shown.
161 DLINK_FOREACH(lp, target_p->user->channel.head)
163 msptr = lp->data;
164 chptr = msptr->chptr;
166 if(PubChannel(chptr) || IsMember(source_p, chptr) ||
167 SecretChannel(chptr))
169 dont_show = YES;
170 break;
174 if(dont_show)
175 continue;
177 if((cur_len + NICKLEN + 2) > (BUFSIZE - 3))
179 sendto_one(source_p, "%s", buf);
180 cur_len = mlen;
181 t = buf + mlen;
184 tlen = ircsprintf(t, "%s ", target_p->name);
185 cur_len += tlen;
186 t += tlen;
189 if(cur_len > mlen)
190 sendto_one(source_p, "%s", buf);