/************************************************************************
 *   IRC - Internet Relay Chat, modules/m_quit.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 "s_conf.h"

static char *token = TOK1_QUIT;

static struct Message _msgtab[] = {
    {MSG_QUIT, 0, MAXPARA, M_SLOW, 0L,
     m_quit, m_quit, m_quit, m_quit, m_quit}
};

#ifndef STATIC_MODULES

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

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

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

/*
 * * m_quit * parv[0] = sender prefix *       parv[1] = comment
 */
int m_quit(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
    char *reason = (parc > 1 && parv[1]) ? parv[1] : cptr->name;
    char comment[TOPICLEN + 1];

    if ((parc > 1) && (check_forbidden_words(reason)))
	strcpy(reason, ChannelConf.default_quit_msg);

    sptr->flags |= FLAGS_NORMALEX;
    if (!IsServer(cptr)) {
	strcpy(comment, "Quit: ");
	strlcpy_irc(comment + 6, reason, TOPICLEN - 6);
	comment[TOPICLEN] = 0;
	return exit_client(sptr, sptr, comment);
    } else
	return exit_client(sptr, sptr, reason);
}


syntax highlighted by Code2HTML, v. 0.9.1