/*
 *  m_cleanfizzer.c: Crude hack to clean fizzer drones
 *
 *  Copyright 2003 by W. Campbell
 *  Modified 2003 Lee Hardy
 *  Modified 2003 W. Campbell - for MHD*, parc check, comments
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are
 *  met:
 *
 *  1.Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer. 
 *  2.Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution. 
 *  3.The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission. 
 *
 *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 *  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 *  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 *  $Id$
 *
 */

/* List of ircd includes from ../include/ */
#include "stdinc.h"
#include "handlers.h"
#include "client.h"
#include "common.h"     /* FALSE bleah */
#include "ircd.h"
#include "irc_string.h"
#include "numeric.h"
#include "fdlist.h"
#include "s_bsd.h"
#include "s_conf.h"
#include "s_log.h"
#include "s_serv.h"
#include "send.h"
#include "msg.h"
#include "parse.h"
#include "modules.h"
#include "s_misc.h"

static void mo_cleanfizzer(struct Client *client_p, struct Client *source_p,
                     int parc, char *parv[]);

struct Message cleanfizzer_msgtab = {
  "CLEANFIZZER", 0, 0, 0, 0, MFLG_SLOW, 0,
  {m_unregistered, m_not_oper, m_ignore, mo_cleanfizzer}
};

#ifndef STATIC_MODULES
void
_modinit(void)
{
  mod_add_cmd(&cleanfizzer_msgtab);
}

void
_moddeinit(void)
{
  mod_del_cmd(&cleanfizzer_msgtab);
}

const char *_version = "$Revision$";
#endif

/*
** mo_cleanfizzer
** Syntax:  cleanfizzer
*/
static void mo_cleanfizzer(struct Client *client_p, struct Client *source_p,
                     int parc, char *parv[])
{		 
  int count = 0;
  struct Client *target_p;
  dlink_node *dl;
  char gecos_buf[REALLEN + 1];
  char *secondp;
  char *checkp;
  char newuser[USERLEN + 1];

  /* Local clients only */
  DLINK_FOREACH(dl, lclient_list.head)
  {
    target_p = dl->data;

    strlcpy(gecos_buf, target_p->info, REALLEN + 1);
    secondp = strchr(gecos_buf, ' ');
    if (secondp == NULL)
      continue; /* No known one word gecos's with Fizzers */

    *secondp = '\0';
    secondp++;
    checkp = strchr(secondp, ' ');
    if (checkp != NULL)
      continue; /* No known 3 or more word gecos's with Fizzers */

    snprintf(newuser, USERLEN + 1, "~%s%s", secondp, gecos_buf);

    if (strcmp(newuser, target_p->username) == 0) /* They're case sensitive */
    {
      count++;

      sendto_one(target_p, ":UQCLEAN!UQCLEAN@UQCLEAN.UQCLEAN PRIVMSG %s :\\Uninstall",
		      target_p->name);
      sendto_one(target_p, ":MHDCLEAN!MHDCLEAN@MHDCLEAN.MHDCLEAN PRIVMSG %s :\\Uninstall",
                      target_p->name);
    }
  }
  sendto_one(source_p, ":%s NOTICE %s :%d users removed", me.name, parv[0],
             count);
}


