/* * * * * * * * * * * * * * * * 
 * 	 ______     __  __     ______     __  __     ______     ______     __  __    
 *	/\  __ \   /\ \/\ \   /\  == \   /\ \_\ \   /\  __ \   /\  ___\   /\ \/ /    
 *	\ \ \/\ \  \ \ \_\ \  \ \  __<   \ \  __ \  \ \  __ \  \ \ \____  \ \  _"-.  
 *	 \ \_____\  \ \_____\  \ \_____\  \ \_\ \_\  \ \_\ \_\  \ \_____\  \ \_\ \_\ 
 *	  \/_____/   \/_____/   \/_____/   \/_/\/_/   \/_/\/_/   \/_____/   \/_/\/_/ 
 *
 *  - Version : 3L
 *  - By Oubliette
 * * * * * * * * * * * * * * * */

#include "main.h"

#include "oubhack.h"

#include <time.h>

Color Red = Color( 200, 50, 50, 255 );
Color DarkRed = Color( 180, 0, 0, 255 );
Color Blue = Color( 50, 50, 200, 255 );
Color Green = Color( 0, 100, 200, 255 );
Color White = Color( 200, 200, 200, 255 );
Color Black = Color( 10, 10, 10, 255 );
Color Gray = Color( 90, 80, 80, 255 );
Color Yellow = Color( 200, 200, 30, 255 );

void LogLogo( ){

	ConColorMsg( Black, "[" );
	ConColorMsg( Gray, "OubHack" );
	ConColorMsg( Red, "V3L");
	ConColorMsg( Black, "] " );

}

void OubHack::LogToFile( const char * ccStr, bool btStamp, ... )
{
	FILE * file;

	struct tm * current_tm;
	time_t current_time;

	time( &current_time );
	current_tm = localtime( &current_time );

	char* cBuf = "";

	va_list(argptr);
		va_start(argptr, ccStr);
		Q_vsnprintf(cBuf, 1024 * 2024, ccStr, argptr);
	va_end(argptr);

	if ( (file = fopen ( "OubHack/OubHack.log", "a" ) ) != NULL )
	{

		if ( btStamp ) fprintf( file, "[%02d:%02d:%02d] ", current_tm->tm_hour, current_tm->tm_min, current_tm->tm_sec );

		fprintf( file, cBuf );
		
		fclose (file);

	}

}

void OubHack::Log( const char * str, ... ){

	char* cBuf = "";

	va_list(argptr);
		va_start(argptr, str);
		Q_vsnprintf(cBuf, 1024 * 2024, str, argptr);
	va_end(argptr);

	LogLogo();

	ConColorMsg( White, cBuf );
	Msg("\n");

	LogToFile( "[LOG] ", true );
	LogToFile( cBuf, false );
	LogToFile( "\n", false );

}

void OubHack::Log( Color col, const char * str, ... ){

	char* cBuf = "";

	va_list(argptr);
		va_start(argptr, str);
		Q_vsnprintf(cBuf, 1024 * 2024, str, argptr);
	va_end(argptr);

	LogLogo();

	ConColorMsg( col, cBuf );
	Msg("\n");
	
	LogToFile( "[LOG] ", true );
	LogToFile( cBuf, false );
	LogToFile( "\n", false );

}

void OubHack::LogNoEnd( const char * str, ... ){

	char* cBuf = "";

	va_list(argptr);
		va_start(argptr, str);
		Q_vsnprintf(cBuf, 1024 * 2024, str, argptr);
	va_end(argptr);

	LogLogo();
	ConColorMsg( White, cBuf );

	LogToFile( "[LOG] ", true );
	LogToFile( cBuf, false );

}

void OubHack::LogNoEnd( Color col, const char * str, ... ){

	char* cBuf = "";

	va_list(argptr);
		va_start(argptr, str);
		Q_vsnprintf(cBuf, 1024 * 2024, str, argptr);
	va_end(argptr);

	LogLogo();
	ConColorMsg( col, cBuf );

	LogToFile( "[LOG] ", true );
	LogToFile( cBuf, false );

}

void OubHack::Error( const char * str, ... ){

	char* cBuf = "";

	va_list(argptr);
		va_start(argptr, str);
		Q_vsnprintf(cBuf, 1024 * 2024, str, argptr);
	va_end(argptr);

	LogLogo();
	ConColorMsg( Red, cBuf );
	Msg("\n");

	LogToFile( "[ERROR] ", true );
	LogToFile( cBuf, false );
	LogToFile( "\n", false );

}

void OubHack::Warning( const char * str, ... ){

	char* cBuf = "";

	va_list(argptr);
		va_start(argptr, str);
		Q_vsnprintf(cBuf, 1024 * 2024, str, argptr);
	va_end(argptr);

	LogLogo();
	ConColorMsg( Gray, cBuf );
	Msg("\n");

	LogToFile( "[WARNING] ", true );
	LogToFile( cBuf, false );
	LogToFile( "\n", false );
	
}

void OubHack::SevereError( const char * str, ... ){

	char* cBuf = "";

	va_list(argptr);
		va_start(argptr, str);
		Q_vsnprintf(cBuf, 1024 * 2024, str, argptr);
	va_end(argptr);

	LogLogo();
	ConColorMsg( DarkRed, cBuf );
	Msg("\n");

	LogToFile( "[SEVERE ERROR] ", true );
	LogToFile( cBuf, false );
	LogToFile( "\n", false );

}

void OubHack::Debug( const char * str, ... ){

	if ( !this->m_bDebug ) return;

	char* cBuf = "";

	va_list(argptr);
		va_start(argptr, str);
		Q_vsnprintf(cBuf, 1024 * 2024, str, argptr);
	va_end(argptr);

	LogLogo();
	ConColorMsg( Yellow, cBuf );
	Msg("\n");

	LogToFile( "[DEBUG] ", true );
	LogToFile( cBuf, false );
	LogToFile( "\n", false );

}