changeset 41:5ea4a4d8f961

srogue: add logging.
author elwin
date Sat, 04 Dec 2010 14:45:38 +0000
parents 984f7d5afb6f
children 30fb47f21d35
files srogue/command.c srogue/rip.c
diffstat 2 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/srogue/command.c	Sat Dec 04 02:26:49 2010 +0000
+++ b/srogue/command.c	Sat Dec 04 14:45:38 2010 +0000
@@ -372,6 +372,7 @@
 		clear();
 		move(LINES-1, 0);
 		refresh();
+		writelog(purse, CHICKEN, 0);
 		score(purse, CHICKEN, 0);
 		byebye(0);
 	}
--- a/srogue/rip.c	Sat Dec 04 02:26:49 2010 +0000
+++ b/srogue/rip.c	Sat Dec 04 14:45:38 2010 +0000
@@ -22,6 +22,8 @@
 #include "rogue.h"
 #include "rogue.ext"
 
+#define LOGFILE "/usr/local/games/roguelike/srogue.log"
+
 static char scoreline[100];
 
 static char *rip[] = {
@@ -82,6 +84,7 @@
 	mvaddstr(18, 32, prbuf);
 	move(LINES-1, 0);
 	refresh();
+	writelog(purse, KILLED, monst);
 	score(purse, KILLED, monst);
 	byebye(0);
 }
@@ -215,6 +218,45 @@
 	showtop(prflags);		/* print top ten list */
 }
 
+void writelog(int amount, int aflag, char monst)
+{
+	char logmessage[160], ltemp[80], mlev[40];
+	char *killer;
+	FILE *logfi;
+
+	if (waswizard)
+		return;
+#ifdef LOGFILE
+	sprintf(logmessage, "%d %d %.20s %d ", time(NULL), amount, whoami,
+		him->s_lvl);
+	if (amulet)
+		sprintf(mlev, " [max %d] with the Amulet", max_level);
+	else
+		mlev[0] = '\0';
+	if (aflag == KILLED) {
+		killer = killname(monst);
+		sprintf(ltemp, "killed by a%s %s on level %d%s\n", 
+			vowelstr(killer), killer, level, mlev);
+	}
+	else if (aflag == CHICKEN) {
+		sprintf(ltemp, "quit on level %d%s\n", level, mlev);
+	}
+        else if (aflag == WINNER) {
+		sprintf(ltemp, "escaped with the Amulet [deepest level: %d]\n", 
+			max_level);
+	}
+	else
+		return;
+	strcat(logmessage, ltemp);
+	logfi = fopen(LOGFILE, "a");
+	if (logfi == NULL)
+		return;
+	fprintf(logfi, "%s", logmessage);
+	fclose(logfi);
+#endif
+	return;
+}
+
 /*
  * showtop:
  *	Display the top ten on the screen
@@ -296,6 +338,7 @@
 	clear();
 	oldpurse = purse;
 	showpack(TRUE, NULL);
+	writelog(purse, WINNER, 0);
 	score(purse, WINNER, 0);
 	byebye(0);
 }