/*
 *   IRC - Internet Relay Chat, modules/m_names.c
 *
 *   Copyright (C) 2000-2003 TR-IRCD Development
 *
 *   Copyright (C) 1990 Jarkko Oikarinen and
 *                      University of Oulu, Co Center
 *
 *   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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * $Id: m_names.c,v 1.3 2003/06/14 13:55:51 tr-ircd Exp $ 
 */

#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "channel.h"
#include "h.h"
#include "msg.h"

static struct Message _msgtab[] = {
    {MSG_NAMES, 0, 1, M_SLOW, 0L,
     m_unregistered, m_names, m_names, m_ignore, m_ignore}
};

#ifndef STATIC_MODULES

char *_version = "$Revision: 1.3 $";

void _modinit(void)
{
    mod_add_cmd(_msgtab);
}

void _moddeinit(void)
{
    mod_del_cmd(_msgtab);
}
#else
void m_names_init(void)
{
    mod_add_cmd(_msgtab);
}
#endif

/************************************************************************
 * m_names() - Added by Jto 27 Apr 1989
 * 12 Feb 2000 - geesh, time for a rewrite -lucas
 ************************************************************************/
/*
 * m_names 
 * parv[0] = sender prefix 
 * parv[1] = channel
 */

/*
 * maximum names para to show to opers when abuse occurs 
 */
#define TRUNCATED_NAMES 64

int m_names(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
    aChannel *chptr;
    char *s = NULL;
    char *para = parv[1];

    if (parc < 2 || !MyConnect(sptr)) {
	send_me_numeric(sptr, RPL_ENDOFNAMES, "*");
	return 0;
    }

    for (s = para; *s; s++) {
	if (*s == ',') {
	    if (strlen(para) > TRUNCATED_NAMES)
		para[TRUNCATED_NAMES] = '\0';
	    sendto_ops("Names abuser %s %s", get_client_name(sptr, FALSE), para);
	    send_me_numeric(sptr, ERR_TOOMANYTARGETS, MSG_NAMES);
	    return 0;
	}
    }

    if (!check_channelname(sptr, (unsigned char *) para))
	return 0;

    chptr = find_channel(para);

    /* We do not need link traversal here, because users
     * do not exist in the root channel, and it is already
     * set to +tnL, after cleaning. -TimeMr14C
     */

    if (!chptr || !ShowChannelNames(sptr, chptr)) {
	send_me_numeric(sptr, RPL_ENDOFNAMES, para);
	return 0;
    }

    send_names(sptr, chptr);

    return 0;
}


syntax highlighted by Code2HTML, v. 0.9.1