/*
 * authtrigger.c
 * (C) Christian Magnusson 2000, Email: d1mag@dtek.chalmers.se
 * This program is copyright, and covered by the Gnu Public License.
 * The Q bot.
 */

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "settings.h"
#include "bottypes.h"
#include "globals.h"
#include "dl.h"

void m_authtrigger(char *a);

MODULE_PUBLIC int _init_authtrigger(void *a, void *b)
{
  dl_command_entry_t *dl = a;
  if(!a) return 0;

  snprintf(dl->help, MAX_COMMAND_HELP_LEN,
	   "Set the trigger value to warn opers about multiple auth's.\n\
/msg %s AUTHTRIGGER          Show trigger value.\n\
/msg %s AUTHTRIGGER (2-10)   Set trigger value\n", BOT_NAME, BOT_NAME);
  snprintf(dl->summary, MAX_COMMAND_SUMMARY_LEN,
	   "Trigger to warn opers for multiple-AUTH's");
  dl->level = 999;
#if 0
  dl->func = m_authtrigger;
#else
  dl->func = (void (*)(char*)) DL_sym(dl->val, "m_authtrigger");
#endif
  return 1;
}

MODULE_PUBLIC int _remove_authtrigger(char *a, char *b)
{
  remove_command("authtrigger");
  return 1;
}

MODULE_PUBLIC void m_authtrigger(char *a)
{
#ifdef USERID_HISTORY_LEN
  int i,l;
  char tmp[80];
  char *str;

  struct dbaseuser *db;
  db = sender_au->dbuser;
  if(db) {
    log("From: %s authtrigger [%s]\n", db->nick, a);
  } else
    return;
  if(!is_oper()) {
    say_sender("You are not an Oper.");
    log("To: %s Is not an Oper\n", db->nick);
    return;
  }
  i=0;
  str = getword(a,&i);
  if(!strlen(str)) {
    sprintf(tmp, "Auth trigger warns at %d different auth commands.",
	    authid_history_trigger);
    say_sender( tmp);
    return;
  }
  l = atoi(str);

  if(l <= 2) l = 2;
  else if(l >= 10) l = 10;
  authid_history_trigger = l;

  sprintf(tmp, "Auth trigger set to %d", authid_history_trigger);
  say_sender( tmp);
#else
  say_sender( "Function is not included in this binary.");
#endif
  return;
}
