/*
 * reload.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_reload(char *a);

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

  snprintf(dl->help, MAX_COMMAND_HELP_LEN,
	   "/msg %s RELOAD <command>\n/msg %s RELOAD ALL\nReload one or all commands (dynamic libraries)\n", BOT_NAME, BOT_NAME);
  snprintf(dl->summary, MAX_COMMAND_SUMMARY_LEN,
	   "Reload one or all commands.");
  dl->level = 999;
#if 0
  dl->func = m_reload;
#else
  dl->func = (void (*)(char*)) DL_sym(dl->val, "m_reload");
#endif
  return 1;
}

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

MODULE_PUBLIC void m_reload(char *a)
{
  int i;
  char command_name[100+1];

  struct dbaseuser *db;
  db = sender_au->dbuser;
  if(db) {
    log("From: %s reload [%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;
  strncpy(command_name,getword(a,&i),100);
  command_name[100] = '\0';
  if(!strlen(command_name)) {
    say_sender("You forgot the command_name parameter");
    say_sender_( "/msg %s RELOAD <command>", BOT_NAME);
    say_sender_( "/msg %s RELOAD ALL", BOT_NAME);
    return;
  }

  /*
    reload will be done in the main loop
  */
  reload_command = 1;
  strncpy(reload_command_name, command_name, 100);
  return;
}
