]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/journal.c
New journal event command
[empserver] / src / lib / subs / journal.c
index ed111a25c7701522f5f88567b736519f49db72fb..90c34a62a01f375b6d8541466dd2ae36b368bd7e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  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
  */
@@ -63,6 +66,9 @@
 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)
 {
@@ -79,8 +85,9 @@ journal_entry(char *fmt, ...)
 
     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);
@@ -92,8 +99,7 @@ journal_entry(char *fmt, ...)
                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);
@@ -143,6 +149,12 @@ journal_reopen(void)
     return 0;
 }
 
+void
+journal_prng(unsigned seed)
+{
+    journal_entry("prng BSD %d", seed);
+}
+
 void
 journal_login(void)
 {
@@ -162,6 +174,13 @@ journal_input(char *input)
     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)
 {