/************************************************************************
 *   IRC - Internet Relay Chat, modules/m_exclude.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.
 */

#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_EXCLUDE, 0, MAXPARA, M_SLOW, 0L,
     m_unregistered, m_ignore, m_ignore, m_exclude, m_exclude}
};

static char *token = TOK1_EXCLUDE;

#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_exclude_init(void)
{
    mod_add_cmd(_msgtab);
    tok1_msgtab[(u_char) *token].msg = _msgtab;
}
#endif

/*
 * m_exclude -
 * * Parse EXCLUDE command
 * * parv[1]=host, parv[2]=user, parv[3]=length, parv[4]=excluder, parv[5]=time set, parv[6]=reason
 */
int m_exclude(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
    aMaskItem *ami, *ami2;
    char *user, *host, *reason, *excluder, buffer[1024], *current_date;
    time_t length = 0, timeset = 0;

    if (parc < 6)
        return 0;

    host = parv[1];
    user = parv[2];  
    length = atoi(parv[3]);
    excluder = parv[4];
    timeset = atoi(parv[5]);
    reason = (parv[6] ? parv[6] : "<no reason>");

    current_date = smalldate((time_t) timeset);
    /*
     * cut reason down a little, eh?
     * 250 chars max
     */
    if (strlen(reason) > 250)
        reason[251] = 0;

    ami2 = find_maskitem(host, user, MASKITEM_EXCLUDE, 1);

    if (ami2 != NULL) {
        sendto_serv_butone(cptr, sptr, TOK1_EXCLUDE, "%s %s %d %s %d :%s",
                           host, user, length, excluder, timeset, reason);
        return 0;
    }

    ami = create_maskitem(excluder, host, user, MASKITEM_EXCLUDE, length);

    ircsprintf(buffer, "%s (%s)", reason, current_date);

    DupString(ami->reason, buffer);

    rehashed = 1;

    sendto_serv_butone(cptr, sptr, TOK1_EXCLUDE, "%s %s %d %s %d :%s",
                       host, user, length, excluder, timeset, reason);
    return 0;
}



syntax highlighted by Code2HTML, v. 0.9.1