All pastes #778550 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-11-17 18:16 UTC
rendered paste body
/*
 * ==================================================================
 * Filename:             m_loggit.c
 * Description:          Real-time Logging
 * Written by:		 MartinCo
 * ==================================================================
 */

#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include "h.h"

// ==================================================================
// Definitions & macros
// ================================
#define MyMod			LoggitModInfo->handle
#define DelHook(x)		if (x) HookDel(x); x = NULL

DLLFUNC char		*loggit_privmsg(aClient *, aClient *, aClient *, char *, int);
DLLFUNC char		*loggit_chanmsg(aClient *, aClient *, aChannel *, char *, int);


// ==================================================================
// Module header
// ==================================================================

ModuleHeader MOD_HEADER(m_loggit)
  = {
	"Loggit",
	"$Id: m_loggit.c,v 3.6 2007 MartinCo Exp $",
	"Loggit",
	"3.2-b8-1",
	NULL
    };

ModuleInfo		*LoggitModInfo;

static Hook		*HookPrivMsg;
static Hook		*HookChanMsg;
static FILE *fp;


DLLFUNC int MOD_INIT(m_loggit)(ModuleInfo *modinfo)
{
	int ret = MOD_SUCCESS;
  	
        LoggitModInfo	= modinfo;

	HookPrivMsg	= HookAddPCharEx(MyMod, HOOKTYPE_USERMSG, loggit_privmsg);
	HookChanMsg	= HookAddPCharEx(MyMod, HOOKTYPE_CHANMSG, loggit_chanmsg);

	return ret;
}

DLLFUNC int MOD_LOAD(m_loggit)(int module_load)
{
	return MOD_SUCCESS;
}

DLLFUNC int MOD_UNLOAD(m_loggit)(int module_unload)
{

	DelHook(HookChanMsg);
	DelHook(HookPrivMsg);

	return MOD_SUCCESS;
}

// ==================================================================
// Functions for nicknames, channel names and prefixes
// ==================================================================


DLLFUNC char *loggit_privmsg(aClient *cptr, aClient *sptr, aClient *acptr, char *text, int notice)
{
	aClient *tonick;

	time_t calender_time;
	struct tm tdate;
	calender_time = time(NULL);
	tdate = *localtime(&calender_time);

	FILE * pFile;

	pFile = fopen ("mloggit.log", "a");

	fprintf (pFile, "%02d-%02d-%02d %02d:%02d [%s > %s] %s\n", tdate.tm_mday, tdate.tm_mon + 1, tdate.tm_year - 100, tdate.tm_hour, tdate.tm_min, cptr->name, acptr->name, text);

	fclose (pFile);


	return text;
}

DLLFUNC char *loggit_chanmsg(aClient *cptr, aClient *sptr, aChannel *chptr, char *text, int notice)
{
	aClient *tonick;

	time_t calender_time;
	struct tm tdate;
	calender_time = time(NULL);
	tdate = *localtime(&calender_time);

	FILE * pFile;

	pFile = fopen ("mloggit.log", "a");

	fprintf (pFile, "%02d-%02d-%02d %02d:%02d [%s] [%s] %s\n", tdate.tm_mday, tdate.tm_mon + 1, tdate.tm_year - 100, tdate.tm_hour, tdate.tm_min, chptr->chname, cptr->name, text);
	
	fclose (pFile);

	return text;
}