]> git.pond.sub.org Git - empserver/commitdiff
New journal event "output"
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 4 Apr 2011 06:09:25 +0000 (08:09 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 14 Apr 2011 18:21:21 +0000 (20:21 +0200)
Redundant information, but incredibly useful when you want to figure
out what happened without a (still nonexistent) journal replay tool.
The redundancy could help making a journal replay tool more robust.

To enable, set econfig key keep_journal to at least 2.  Output events
are *not* flushed to disk immediately.

include/econfig-spec.h
include/journal.h
include/types.h
src/lib/subs/journal.c
src/lib/subs/pr.c

index 5113bfc67ba47dbcafcdf3a4893d4df100104e03..552019cdacdadcbee1c15cd32713094319c329c7 100644 (file)
@@ -89,6 +89,9 @@ EMPCFBOTH("port", loginport, char *, NSC_STRING, KM_INTERNAL,
     "TCP port the server will bind")
 EMPCFBOTH("keep_journal", keep_journal, int, NSC_INT, KM_INTERNAL,
     "Enable journal log file")
+EMPCF_COMMENT("# 0 - Disabled\n"
+    "# 1 - Enabled, player output suppressed\n"
+    "# 2 - Enabled, log everything (big; rotating & compressing advised)\n")
 EMPCFBOTH("post_crash_dump_hook", post_crash_dump_hook, char *, NSC_STRING, KM_INTERNAL,
     "Shell command run right after a crash dump, in the game's data directory")
 EMPCFBOTH("privname", privname, char *, NSC_STRING, 0,
index 4c604a49805392910d8041c4b9c05ddf76991fdb..0d173de70cdb8d0bb6237be9133dae9453d4fbf2 100644 (file)
 #ifndef JOURNAL_H
 #define JOURNAL_H
 
+#include "types.h"
+
 int journal_startup(void);
 void journal_shutdown(void);
 int journal_reopen(void);
 void journal_login(void);
 void journal_logout(void);
 void journal_prng(unsigned);
+void journal_output(struct player *, int, char *);
 void journal_input(char *);
 void journal_command(char *);
 void journal_update(int);
index 1040bab7560d94a64c7f59664ecad2d37aa74309..78393daea07f02f0faf89c260f6dc0185cdae180 100644 (file)
@@ -48,6 +48,7 @@ struct nchrstr;
 struct nstr_item;
 struct nstr_sect;
 struct nukstr;
+struct player;
 struct plist;
 struct plnstr;
 struct range;
index d8d1869e413548c4f26052d52f638ea11cadfade..8a07fb3d3dafe95cfaa8c91d17f4fd21a85d63e0 100644 (file)
@@ -45,6 +45,7 @@
  *     logout CNUM
  *     command NAME
  *     input INPUT
+ *     output THREAD ID OUTPUT
  *     update ETU
  */
 
@@ -69,6 +70,7 @@ static void journal_entry_start(char *fmt, ...)
     ATTRIBUTE((format (printf, 1, 2)));
 static void journal_entry(char *fmt, ...)
     ATTRIBUTE((format (printf, 1, 2)));
+static void journal_output_start(struct player *, int);
 
 static FILE *
 journal_open(void)
@@ -118,10 +120,12 @@ journal_entry_pr(char *s, size_t n)
 }
 
 static void
-journal_entry_end(void)
+journal_entry_end(int newline, int flush)
 {
     if (!journal)
        return;
+    if (!newline)
+       fputc('\\', journal);
     fputc('\n', journal);
     fflush(journal);
     if (ferror(journal)) {
@@ -138,7 +142,7 @@ journal_entry(char *fmt, ...)
     va_start(ap, fmt);
     journal_entry_vstart(fmt, ap);
     va_end(ap);
-    journal_entry_end();
+    journal_entry_end(1, 1);
 }
 
 int
@@ -202,12 +206,59 @@ journal_logout(void)
     journal_entry("logout %d", player->cnum);
 }
 
+void
+journal_output(struct player *pl, int id, char *output)
+{
+    static char buf[1024];
+    static char *bp = buf;
+    static struct player *bpl;
+    static int bid;
+    char *s, *e;
+
+    if (keep_journal < 2)
+       return;
+
+    if (bp != buf && (pl != bpl || id != bid)) {
+       journal_output_start(bpl, bid);
+       journal_entry_pr(buf, bp - buf);
+       journal_entry_end(0, 0);
+       bp = buf;
+    }
+
+    for (s = output; (e = strchr(s, '\n')); s = e + 1) {
+       journal_output_start(pl, id);
+       journal_entry_pr(buf, bp - buf);
+       journal_entry_pr(s, e - s);
+       journal_entry_end(1, 0);
+       bp = buf;
+    }
+    e = strchr(s, 0);
+    if (bp + (e - s) <= buf + sizeof(buf)) {
+       memcpy(bp, s, e - s);
+       bp += e - s;
+       bpl = pl;
+       bid = id;
+    } else {
+       journal_output_start(pl, id);
+       journal_entry_pr(buf, bp - buf);
+       journal_entry_pr(s, e - s);
+       journal_entry_end(0, 0);
+       bp = buf;
+    }
+}
+
+static void
+journal_output_start(struct player *pl, int id)
+{
+    journal_entry_start("output %s %d ", empth_name(pl->proc), id);
+}
+
 void
 journal_input(char *input)
 {
     journal_entry_start("input ");
     journal_entry_pr(input, -1);
-    journal_entry_end();
+    journal_entry_end(1, 1);
 }
 
 void
index 15c24556d00112a7993910fd1d2a1d868738a556..5cf6833d7e11d76b54b74f5dc2ff5af9a09c9f02 100644 (file)
@@ -30,7 +30,7 @@
  *     Dave Pare, 1986, 1989
  *     Steve McClure, 1998-2000
  *     Ron Koenderink, 2005
- *     Markus Armbruster, 2005-2009
+ *     Markus Armbruster, 2005-2011
  */
 
 /*
@@ -55,6 +55,7 @@
 #include "com.h"
 #include "empio.h"
 #include "file.h"
+#include "journal.h"
 #include "misc.h"
 #include "nat.h"
 #include "player.h"
@@ -124,6 +125,7 @@ pr_id(struct player *p, int id, char *format, ...)
 
     if (p->curid >= 0) {
        io_puts(p->iop, "\n");
+       journal_output(p, p->curid, "\n");
        p->curid = -1;
     }
     va_start(ap, format);
@@ -222,6 +224,8 @@ pr_player(struct player *pl, int id, char *buf)
     char *bp;
     int len;
 
+    journal_output(pl, id, buf);
+
     bp = buf;
     while (*bp != '\0') {
        if (pl->curid != -1 && pl->curid != id) {
@@ -263,6 +267,8 @@ upr_player(struct player *pl, int id, char *buf)
     char printbuf[2];
     char ch;
 
+    journal_output(pl, id, buf);
+
     printbuf[0] = '\0';
     printbuf[1] = '\0';