2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_names.c: Shows the users who are online.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char names_desc[] = "Provides the NAMES command to view users on a channel";
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void m_names(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct Message names_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"NAMES", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_unreg, {m_names, 0}, mg_ignore, mg_ignore, mg_ignore, {m_names, 0}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 names_clist[] = { &names_msgtab, NULL };
|
2016-03-07 09:45:37 +01:00
|
|
|
|
|
|
|
DECLARE_MODULE_AV2(names, NULL, NULL, names_clist, NULL, NULL, NULL, NULL, names_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void names_global(client::client &source);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* m_names() - Added by Jto 27 Apr 1989
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* m_names
|
|
|
|
* parv[1] = channel
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
m_names(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
static time_t last_used = 0;
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *chptr = NULL;
|
2007-01-25 07:40:21 +01:00
|
|
|
char *s;
|
|
|
|
|
|
|
|
if(parc > 1 && !EmptyString(parv[1]))
|
|
|
|
{
|
|
|
|
char *p = LOCAL_COPY(parv[1]);
|
|
|
|
if((s = strchr(p, ',')))
|
|
|
|
*s = '\0';
|
|
|
|
|
2016-08-19 01:53:12 +02:00
|
|
|
if(!chan::valid_name(p))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_BADCHANNAME,
|
2007-01-25 07:40:21 +01:00
|
|
|
form_str(ERR_BADCHANNAME),
|
|
|
|
(unsigned char *) p);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-20 04:51:37 +02:00
|
|
|
if((chptr = chan::get(p, std::nothrow)) != NULL)
|
2016-08-23 02:37:07 +02:00
|
|
|
channel_member_names(chptr, &source, 1);
|
2007-01-25 07:40:21 +01:00
|
|
|
else
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_ENDOFNAMES),
|
|
|
|
me.name, source.name, p);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
if(!is(source, umode::OPER))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2008-04-02 01:53:20 +02:00
|
|
|
if((last_used + ConfigFileEntry.pace_wait) > rb_current_time())
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_LOAD2HI),
|
|
|
|
me.name, source.name, "NAMES");
|
|
|
|
sendto_one(&source, form_str(RPL_ENDOFNAMES),
|
|
|
|
me.name, source.name, "*");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
2008-04-02 01:53:20 +02:00
|
|
|
last_used = rb_current_time();
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
names_global(source);
|
|
|
|
sendto_one(&source, form_str(RPL_ENDOFNAMES),
|
|
|
|
me.name, source.name, "*");
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* names_global
|
|
|
|
*
|
|
|
|
* inputs - pointer to client struct requesting names
|
|
|
|
* output - none
|
|
|
|
* side effects - lists all non public non secret channels
|
|
|
|
*/
|
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
names_global(client::client &source)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
int mlen;
|
|
|
|
int tlen;
|
|
|
|
int cur_len;
|
2016-03-09 08:37:03 +01:00
|
|
|
bool dont_show = false;
|
2008-04-01 22:18:48 +02:00
|
|
|
rb_dlink_node *lp, *ptr;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2016-08-18 07:33:38 +02:00
|
|
|
chan::chan *chptr = NULL;
|
2007-01-25 07:40:21 +01:00
|
|
|
char buf[BUFSIZE];
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
/* first do all visible channels */
|
2016-08-20 04:51:37 +02:00
|
|
|
for(const auto &pit : chan::chans)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-20 04:51:37 +02:00
|
|
|
chptr = pit.second.get();
|
2016-08-23 02:37:07 +02:00
|
|
|
channel_member_names(chptr, &source, 0);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-02-10 02:25:32 +01:00
|
|
|
cur_len = mlen = sprintf(buf, form_str(RPL_NAMREPLY),
|
2016-08-23 02:37:07 +02:00
|
|
|
me.name, source.name, "*", "*");
|
2007-01-25 07:40:21 +01:00
|
|
|
t = buf + mlen;
|
|
|
|
|
|
|
|
/* Second, do all clients in one big sweep */
|
2008-04-01 22:18:48 +02:00
|
|
|
RB_DLINK_FOREACH(ptr, global_client_list.head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = (client::client *)ptr->data;
|
2016-03-09 08:37:03 +01:00
|
|
|
dont_show = false;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
if(!is_person(*target_p) || is(*target_p, umode::INVISIBLE))
|
2007-01-25 07:40:21 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* we want to show -i clients that are either:
|
|
|
|
* a) not on any channels
|
|
|
|
* b) only on +p channels
|
|
|
|
*
|
|
|
|
* both were missed out above. if the target is on a
|
|
|
|
* common channel with source, its already been shown.
|
|
|
|
*/
|
2016-08-22 03:57:43 +02:00
|
|
|
for(const auto &pit : chans(user(*target_p)))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-20 02:32:26 +02:00
|
|
|
auto &chptr(pit.first);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
if(is_public(chptr) || is_member(chptr, &source) || is_secret(chptr))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
dont_show = true;
|
2007-01-25 07:40:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dont_show)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if((cur_len + NICKLEN + 2) > (BUFSIZE - 3))
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, "%s", buf);
|
2007-01-25 07:40:21 +01:00
|
|
|
cur_len = mlen;
|
|
|
|
t = buf + mlen;
|
|
|
|
}
|
|
|
|
|
2016-02-10 02:25:32 +01:00
|
|
|
tlen = sprintf(t, "%s ", target_p->name);
|
2007-01-25 07:40:21 +01:00
|
|
|
cur_len += tlen;
|
|
|
|
t += tlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cur_len > mlen)
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, "%s", buf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|