1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
/*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* $Id: m_names.c 26094 2008-09-19 15:33:46Z androsyn $
*/
#include "stdinc.h"
#include "struct.h"
#include "channel.h"
#include "client.h"
#include "hash.h"
#include "match.h"
#include "ircd.h"
#include "numeric.h"
#include "send.h"
#include "s_conf.h"
#include "parse.h"
#include "modules.h"
static int m_names(struct Client *, struct Client *, int, const char **);
struct Message names_msgtab = {
"NAMES", 0, 0, 0, MFLG_SLOW,
{mg_unreg, {m_names, 0}, mg_ignore, mg_ignore, mg_ignore, {m_names, 0}}
};
mapi_clist_av1 names_clist[] = { &names_msgtab, NULL };
DECLARE_MODULE_AV1(names, NULL, NULL, names_clist, NULL, NULL, "$Revision: 26094 $");
static void names_global(struct Client *source_p);
/************************************************************************
* m_names() - Added by Jto 27 Apr 1989
************************************************************************/
/*
* m_names
* parv[0] = sender prefix
* parv[1] = channel
*/
static int
m_names(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
static time_t last_used = 0;
struct Channel *chptr = NULL;
char *s;
if(parc > 1 && !EmptyString(parv[1]))
{
char *p = LOCAL_COPY(parv[1]);
if((s = strchr(p, ',')))
*s = '\0';
if(!check_channel_name(p))
{
sendto_one_numeric(source_p, ERR_BADCHANNAME,
form_str(ERR_BADCHANNAME), (unsigned char *)p);
return 0;
}
if((chptr = find_channel(p)) != NULL)
channel_member_names(chptr, source_p, 1);
else
sendto_one(source_p, form_str(RPL_ENDOFNAMES), me.name, source_p->name, p);
}
else
{
if(!IsOper(source_p))
{
if((last_used + ConfigFileEntry.pace_wait) > rb_current_time())
{
sendto_one(source_p, form_str(RPL_LOAD2HI),
me.name, source_p->name, "NAMES");
sendto_one(source_p, form_str(RPL_ENDOFNAMES),
me.name, source_p->name, "*");
return 0;
}
else
last_used = rb_current_time();
}
names_global(source_p);
sendto_one(source_p, form_str(RPL_ENDOFNAMES), me.name, source_p->name, "*");
}
return 0;
}
/*
* names_global
*
* inputs - pointer to client struct requesting names
* output - none
* side effects - lists all non public non secret channels
*/
static void
names_global(struct Client *source_p)
{
int mlen;
int tlen;
int cur_len;
int dont_show = NO;
rb_dlink_node *lp, *ptr;
struct Client *target_p;
struct Channel *chptr = NULL;
struct membership *msptr;
char buf[BUFSIZE];
char *t;
/* first do all visible channels */
RB_DLINK_FOREACH(ptr, global_channel_list.head)
{
chptr = ptr->data;
channel_member_names(chptr, source_p, 0);
}
cur_len = mlen = rb_sprintf(buf, form_str(RPL_NAMREPLY), me.name, source_p->name, "*", "*");
t = buf + mlen;
/* Second, do all clients in one big sweep */
RB_DLINK_FOREACH(ptr, global_client_list.head)
{
target_p = ptr->data;
dont_show = NO;
if(!IsClient(target_p) || IsInvisible(target_p))
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.
*/
RB_DLINK_FOREACH(lp, target_p->user->channel.head)
{
msptr = lp->data;
chptr = msptr->chptr;
if(PubChannel(chptr) || IsMember(source_p, chptr) || SecretChannel(chptr))
{
dont_show = YES;
break;
}
}
if(dont_show)
continue;
if((cur_len + NICKLEN + 2) > (BUFSIZE - 3))
{
sendto_one_buffer(source_p, buf);
cur_len = mlen;
t = buf + mlen;
}
tlen = rb_sprintf(t, "%s ", target_p->name);
cur_len += tlen;
t += tlen;
}
if(cur_len > mlen)
sendto_one_buffer(source_p, buf);
}
|