zim/area/
zim/bin/
zim/clans/plists/
zim/corefiles/
zim/doc/muddy/
zim/gods/
zim/log/
zim/player/
zim/skill_tree/
zim/tmp/
/*
 * $Id: log.c 871 2006-05-31 04:08:21Z zsuzsu $
 */

/***************************************************************************
 *     ANATOLIA 2.1 is copyright 1996-1997 Serdar BULUT, Ibrahim CANPUNAR  *	
 *     ANATOLIA has been brought to you by ANATOLIA consortium		   *
 *	 Serdar BULUT {Chronos}		bulut@rorqual.cc.metu.edu.tr       *
 *	 Ibrahim Canpunar  {Asena}	canpunar@rorqual.cc.metu.edu.tr    *	
 *	 Murat BICER  {KIO}		mbicer@rorqual.cc.metu.edu.tr	   *	
 *	 D.Baris ACAR {Powerman}	dbacar@rorqual.cc.metu.edu.tr	   *	
 *     By using this code, you have agreed to follow the terms of the      *
 *     ANATOLIA license, in the file Anatolia/anatolia.licence             *	
 ***************************************************************************/

/***************************************************************************
 *  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
 *  Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.   *
 *                                                                         *
 *  Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael          *
 *  Chastain, Michael Quan, and Mitchell Tse.                              *
 *                                                                         *
 *  In order to use any part of this Merc Diku Mud, you must comply with   *
 *  both the original Diku license in 'license.doc' as well the Merc       *
 *  license in 'license.txt'.  In particular, you may not remove either of *
 *  these copyright notices.                                               *
 *                                                                         *
 *  Much time and thought has gone into this software and you are          *
 *  benefitting.  We hope that you share your changes too.  What goes      *
 *  around, comes around.                                                  *
 ***************************************************************************/

/***************************************************************************
*	ROM 2.4 is copyright 1993-1995 Russ Taylor			   *
*	ROM has been brought to you by the ROM consortium		   *
*	    Russ Taylor (rtaylor@pacinfo.com)				   *
*	    Gabrielle Taylor (gtaylor@pacinfo.com)			   *
*	    Brian Moore (rom@rom.efn.org)				   *
*	By using this code, you have agreed to follow the terms of the	   *
*	ROM license, in the file Rom24/doc/rom.license			   *
***************************************************************************/

#include <stdarg.h>
#include <stdio.h>
#include <time.h>

#include "typedef.h"
#include "const.h"
#include "merc.h"
#include "log.h"
#include "util.h"

#ifdef SUNOS
#	include "compat/compat.h"
#endif
#ifdef WIN32
#	include <string.h>
#	define vsnprintf	_vsnprintf
#endif

/*
 * Writes a string to the log.
 */
void log_printf(const char *format, ...)
{
#if defined(WIN32)
	FILE *logfile;
#endif
	time_t current_time;
	char buf[MAX_STRING_LENGTH];
	va_list ap;

	va_start(ap, format);
	vsnprintf(buf, sizeof(buf), format, ap);
	va_end(ap);

	time(&current_time);
	fprintf(stderr, "%s :: %s\n", strtime(current_time), buf);

#if defined (WIN32)
	/* Also add to logfile */
	logfile = fopen("sog.log", "a+b");
	if (logfile) {
		fprintf(logfile, "%s :: %s\n", strtime(current_time), buf);
		fclose(logfile);
	}
#endif
}


/*
 * Reports a bug.
 */
void bug(const char *str, int param)
{
	char buf[MAX_STRING_LENGTH];
	char buf2[MAX_STRING_LENGTH];

	snprintf(buf2, sizeof(buf2), str, param);
	snprintf(buf, sizeof(buf), "[*****] BUG: %s", buf2);
	wiznet(buf, NULL, NULL, WIZ_ANNOUNCE, 0, 0);
	log(buf);
}

/*
 * Sends a String to WizNet Bug, and the logfile
 */
void bug_printf(const char *format, ...)
{
#if defined(WIN32)
	FILE *logfile;
#endif
	time_t current_time;
	char buf[MAX_STRING_LENGTH], buf2[MAX_STRING_LENGTH];
	va_list ap;

	va_start(ap, format);
	vsnprintf(buf2, sizeof(buf2), format, ap);
	va_end(ap);

	time(&current_time);
	snprintf(buf, sizeof(buf), "[*****] BUG: %s", buf2);
	fprintf(stderr, "%s :: %s\n", strtime(current_time), buf);
	snprintf(buf, sizeof(buf), "{w[{Y**BUG**{w]{x %s", buf2);

	wiznet(buf, NULL, NULL, WIZ_ANNOUNCE, 0, 0);

#if defined (WIN32)
	/* Also add to logfile */
	logfile = fopen("sog.log", "a+b");
	if (logfile) {
		fprintf(logfile, "%s :: %s\n", strtime(current_time), buf);
		fclose(logfile);
	}
#endif
}

/*
 * Sends a String to WizNet Builder Debug, and the logfile
 */
void builder_printf(const char *format, ...)
{
#if defined(WIN32)
	FILE *logfile;
#endif
	time_t current_time;
	char buf[MAX_STRING_LENGTH], buf2[MAX_STRING_LENGTH];
	va_list ap;

	va_start(ap, format);
	vsnprintf(buf2, sizeof(buf2), format, ap);
	va_end(ap);

	time(&current_time);
	snprintf(buf, sizeof(buf), "BUILDER: %s", buf2);
	fprintf(stderr, "%s :: %s\n", strtime(current_time), buf);
	snprintf(buf, sizeof(buf), "{w[{DBUILDER{w]{x %s", buf2);

	wiznet(buf, NULL, NULL, WIZ_BUILDER_DEBUG, 0, 0);

#if defined (WIN32)
	/* Also add to logfile */
	logfile = fopen("sog.log", "a+b");
	if (logfile) {
		fprintf(logfile, "%s :: %s\n", strtime(current_time), buf);
		fclose(logfile);
	}
#endif
}