/************************************************************************
 *   IRC - Internet Relay Chat, modules/m_userhost.c
 *
 *   Copyright (C) 2000-2003 TR-IRCD Development
 *
 *   Copyright (C) 1990 Jarkko Oikarinen and
 *                      University of Oulu, Co Center
 *
 *   See file AUTHORS in IRC package for additional names of
 *   the programmers.
 *
 *   This program is free softwmare; 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.
 */

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

static char buf[BUFSIZE], buf2[BUFSIZE];

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

#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_userhost_init(void)
{
    mod_add_cmd(_msgtab);
}
#endif

/*
 * m_userhost added by Darren Reed 13/8/91 to aid clients and reduce
 * the need for complicated requests like WHOIS. It returns user/host
 * information only (no spurious AWAY labels or channels).
 */
int m_userhost(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
    char *p = NULL;
    aClient *acptr;
    char *s;
    int i, len;

    if (parc > 2)
	m_userhost(cptr, sptr, parc - 1, parv + 1);

    if (parc < 2) {
	send_me_numeric(sptr, ERR_NEEDMOREPARAMS, MSG_USERHOST);
	return 0;
    }

    ircsprintf(buf, rpl_str(RPL_USERHOST), &me, parv[0]);
    len = strlen(buf);
    *buf2 = '\0';

    for (i = 5, s = strtoken(&p, parv[1], " "); i && s; s = strtoken(&p, (char *) NULL, " "), i--)
	if ((acptr = find_person(s))) {
	    if (*buf2)
		strcat(buf, " ");
	    ircsprintf(buf2, "%s%s=%c%s@%s",
			      acptr->name,
			      IsAnOper(acptr) ? "*" : "",
			      (acptr->user->away) ? '-' : '+', acptr->user->username,
			      IsFake(acptr) ? acptr->user->fakehost : acptr->user->host
		);
	    strncat(buf, buf2, sizeof(buf) - len);
	    len += strlen(buf2);
	}
    sendto_one(sptr, "%s", buf);
    return 0;
}


syntax highlighted by Code2HTML, v. 0.9.1