/*
 * f_setsince.c
 * (c) fez - sets me.since (e.g., uptime)
 */

// includes
#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "proto.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include "h.h"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif

// module defines
#define MSG_SETSINCE 	"SETSINCE"
#define TOK_SETSINCE 	NULL

// function declarations
DLLFUNC int f_setsince(aClient *cptr, aClient *sptr, int parc, char *parv[]);

// global variables
ModuleInfo *SetsinceModInfo = NULL;	// for local storage of modinfo
Command *SetsinceCmd = NULL;		// setsince command

// module header
ModuleHeader MOD_HEADER(f_setsince)
  = {
	"f_setsince",
	"$Id: f_setsince.c, v1.0.2 2007/10/16 20:43:00 fez Exp $",
	"command /setsince", 
	"3.2.3",
	NULL 
    };

// called before config test
DLLFUNC int MOD_TEST(f_setsince)(ModuleInfo *modinfo)
{
	int ret = MOD_SUCCESS;
	return ret;
}

// called during module initialization
DLLFUNC int MOD_INIT(f_setsince)(ModuleInfo *modinfo)
{
	int ret = MOD_SUCCESS;
	SetsinceModInfo = modinfo;
	SetsinceCmd = CommandAdd(modinfo->handle, MSG_SETSINCE, TOK_SETSINCE, f_setsince, MAXPARA, M_USER|M_SERVER);
	if (!SetsinceCmd)
		ret = MOD_FAILED;
	return ret;
}

// called when ircd is 100% ready
DLLFUNC int MOD_LOAD(f_setsince)(int module_load)
{
	int ret = MOD_SUCCESS;
	return ret;
}

// called when unloading a module
DLLFUNC int MOD_UNLOAD(f_setsince)(int module_unload)
{
	int ret = MOD_SUCCESS;
	CommandDel(SetsinceCmd);
	SetsinceCmd = NULL;
	return ret;
}

/*
 * f_setsince() - fez
 */
//DLLFUNC CMD_FUNC(f_setsince)
DLLFUNC int f_setsince(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
	TS setsince;
	if (!IsAdmin(sptr) && !IsULine(sptr))
	{
		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
		return 0;
	}
	if (parc < 2)
	{
		sendto_one(sptr, ":%s %s %s :*** Boot time is %li", me.name,
		 IsWebTV(sptr)?"PRIVMSG":"NOTICE", sptr->name, (long)me.since);
		return 0;
	}
	setsince = (TS)atoi(parv[1]);
	if (setsince < 1)
	{
		sendto_one(sptr, ":%s %s %s :*** Invalid argument - usage: /setsince <unix_time>",
			me.name, IsWebTV(sptr)?"PRIVMSG":"NOTICE", sptr->name );
		return 0;
	}
	me.since = setsince;
	sendto_one(sptr, ":%s %s %s :*** Changed boot time to %li",
		me.name, IsWebTV(sptr)?"PRIVMSG":"NOTICE", sptr->name, (long)setsince );
	//sendto_realops("%s used SETSINCE to set boot time to %li", sptr->name, (long)setsince);
	return 0;
}

/* end of code */
