/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* ---
*
* journal.c: Log a journal of events to a file
- *
+ *
* Known contributors to this file:
- * Markus Armbruster, 2004-2007
+ * Markus Armbruster, 2004-2008
+ * Ron Koenderink, 2008
*/
/*
*
* startup
* shutdown
+ * prng NAME SEED
* login CNUM HOSTADDR USER
* logout CNUM
+ * command NAME
* input INPUT
* update ETU
*/
static char journal_fname[] = "journal.log";
static FILE *journal;
+static void journal_entry(char *fmt, ...)
+ ATTRIBUTE((format (printf, 1, 2)));
+
static FILE *
journal_open(void)
{
if (journal) {
time(&now);
- fprintf(journal, "%.24s %p ", ctime(&now), empth_self());
-
+ fprintf(journal, "%.24s %10.10s ",
+ ctime(&now), empth_name(empth_self()));
+
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
va_end(ap);
fprintf(journal, "\\%03o", *p);
}
fputs("\n", journal);
- if (debug)
- fflush(journal);
+ fflush(journal);
if (ferror(journal)) {
logerror("Error writing journal (%s)", strerror(errno));
clearerr(journal);
return 0;
}
+void
+journal_prng(unsigned seed)
+{
+ journal_entry("prng BSD %d", seed);
+}
+
void
journal_login(void)
{
journal_entry("input %s", input);
}
+void
+journal_command(char *cmd)
+{
+ char *eptr = strchr(cmd, ' ');
+ journal_entry("command %.*s", eptr ? (int)(eptr - cmd) : -1, cmd);
+}
+
void
journal_update(int etu)
{