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
24 * $Id: m_names.c 254 2005-09-21 23:35:12Z nenolod $
28 #include "sprintf_irc.h"
34 #include "irc_string.h"
44 static int m_names(struct Client
*, struct Client
*, int, const char **);
46 struct 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}}
51 mapi_clist_av1 names_clist
[] = { &names_msgtab
, NULL
};
52 DECLARE_MODULE_AV1(names
, NULL
, NULL
, names_clist
, NULL
, NULL
, "$Revision: 254 $");
54 static void names_global(struct Client
*source_p
);
56 /************************************************************************
57 * m_names() - Added by Jto 27 Apr 1989
58 ************************************************************************/
62 * parv[0] = sender prefix
66 m_names(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
68 static time_t last_used
= 0;
69 struct Channel
*chptr
= NULL
;
72 if(parc
> 1 && !EmptyString(parv
[1]))
74 char *p
= LOCAL_COPY(parv
[1]);
75 if((s
= strchr(p
, ',')))
78 if(!check_channel_name(p
))
80 sendto_one_numeric(source_p
, ERR_BADCHANNAME
,
81 form_str(ERR_BADCHANNAME
),
86 if((chptr
= find_channel(p
)) != NULL
)
87 channel_member_names(chptr
, source_p
, 1);
89 sendto_one(source_p
, form_str(RPL_ENDOFNAMES
),
90 me
.name
, source_p
->name
, p
);
96 if((last_used
+ ConfigFileEntry
.pace_wait
) > CurrentTime
)
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
, "*");
105 last_used
= CurrentTime
;
108 names_global(source_p
);
109 sendto_one(source_p
, form_str(RPL_ENDOFNAMES
),
110 me
.name
, source_p
->name
, "*");
119 * inputs - pointer to client struct requesting names
121 * side effects - lists all non public non secret channels
124 names_global(struct Client
*source_p
)
130 dlink_node
*lp
, *ptr
;
131 struct Client
*target_p
;
132 struct Channel
*chptr
= NULL
;
133 struct membership
*msptr
;
137 /* first do all visible channels */
138 DLINK_FOREACH(ptr
, global_channel_list
.head
)
141 channel_member_names(chptr
, source_p
, 0);
143 cur_len
= mlen
= ircsprintf(buf
, form_str(RPL_NAMREPLY
),
144 me
.name
, source_p
->name
, "*", "*");
147 /* Second, do all clients in one big sweep */
148 DLINK_FOREACH(ptr
, global_client_list
.head
)
150 target_p
= ptr
->data
;
153 if(!IsPerson(target_p
) || IsInvisible(target_p
))
156 /* we want to show -i clients that are either:
157 * a) not on any channels
158 * b) only on +p channels
160 * both were missed out above. if the target is on a
161 * common channel with source, its already been shown.
163 DLINK_FOREACH(lp
, target_p
->user
->channel
.head
)
166 chptr
= msptr
->chptr
;
168 if(PubChannel(chptr
) || IsMember(source_p
, chptr
) ||
169 SecretChannel(chptr
))
179 if((cur_len
+ NICKLEN
+ 2) > (BUFSIZE
- 3))
181 sendto_one(source_p
, "%s", buf
);
186 tlen
= ircsprintf(t
, "%s ", target_p
->name
);
192 sendto_one(source_p
, "%s", buf
);