/************************************************************************
 *   IRC - Internet Relay Chat, modules/m_info.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 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_info.c,v 1.10 2004/02/24 19:03:32 tr-ircd Exp $ 
 */

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

static struct Message _msgtab[] = {
    {MSG_INFO, 0, MAXPARA, M_SLOW, 0L,
     m_unregistered, m_info, m_info, m_info, m_ignore}
};

static struct Message ic_msgtab[] = {
    {MSG_INFOCONF, 0, MAXPARA, M_SLOW, 0L,
     m_unregistered, m_permission, m_permission, m_permission, m_ignore}
};

static struct Message c_msgtab[] = {
    {MSG_COPYRIGHT, 0, MAXPARA, M_SLOW, 0L,
     m_unregistered, m_copyright, m_copyright, m_ignore, m_ignore}
};

static char *token = TOK1_INFO;
static char *ic_token = TOK1_INFOCONF;

#ifndef STATIC_MODULES

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

void _modinit(void)
{
    mod_add_cmd(_msgtab);
    tok1_msgtab[(u_char) *token].msg = _msgtab;
    mod_add_cmd(ic_msgtab);
    tok1_msgtab[(u_char) *ic_token].msg = ic_msgtab;
    mod_add_cmd(c_msgtab);
}

void _moddeinit(void)
{
    mod_del_cmd(_msgtab);
    tok1_msgtab[(u_char) *token].msg = NULL;
    mod_del_cmd(ic_msgtab);
    tok1_msgtab[(u_char) *ic_token].msg = NULL;
    mod_del_cmd(c_msgtab);
}
#else
void m_info_init(void)
{
    mod_add_cmd(_msgtab);
    tok1_msgtab[(u_char) *token].msg = _msgtab;
    mod_add_cmd(ic_msgtab);
    tok1_msgtab[(u_char) *ic_token].msg = ic_msgtab;
    mod_add_cmd(c_msgtab);
}
#endif

/*
 * * m_info 
 *      parv[0] = sender prefix 
 *      parv[1] = servername
 */
int m_info(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
    char **text;

    static time_t last_used = 0L;

    if (hunt_server(cptr, sptr, ":%s %s :%s", TOK1_INFO, 1, parc, parv) == HUNTED_ISME) {

	text = infotext;

	sendto_lev(SPY_LEV, "INFO requested by %^C [%s]", sptr, sptr->user->server);

	if (!IsAnOper(sptr)) {
	    if (!MyConnect(sptr))
		return 0;
	    if ((last_used + ServerOpts.motd_wait) > NOW)
		return 0;
	    else
		last_used = NOW;
	}
	if (MyConnect(sptr))
	    while (*text)
		send_me_numeric(sptr, RPL_INFO, *text++);

	send_me_numeric(sptr, RPL_INFO, "");

	sendto_one(sptr,
		   ":%C %N %s :Birth Date: %s, compile # %s",
		   &me, RPL_INFO, parv[0], creation, generation);
	sendto_one(sptr, ":%C %N %s :On-line since %s",
		   &me, RPL_INFO, parv[0], smalldate(me.firsttime));
	send_me_numeric(sptr, RPL_ENDOFINFO);

    }

    return 0;
}

int m_copyright(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
    char **text = copyrighttext;

    static time_t last_used = 0L;

    if (!MyConnect(sptr)) {
	send_me_numeric(sptr, RPL_ENDOFINFO);
	return 0;
    }

    sendto_lev(SPY_LEV, "COPYRIGHT requested by %^C", sptr);

    if (!IsAnOper(sptr)) {
	if ((last_used + ServerOpts.motd_wait) > NOW)
	    return 0;
	else
	    last_used = NOW;
    }

    while (*text)
	send_me_numeric(sptr, RPL_INFO, *text++);

    send_me_numeric(sptr, RPL_INFO, "");

    send_me_numeric(sptr, RPL_ENDOFINFO);

    return 0;
}


syntax highlighted by Code2HTML, v. 0.9.1