]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/pr.c
Journal output lines instead of chunks
[empserver] / src / lib / subs / pr.c
index 6976944f76c941d079daa7f66f06ef7e5b5f4ba7..38bc98faccdb5469c4418a40cc7eea37c9b5da0c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, 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
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  pr.c: Output to players
- * 
+ *
  *  Known contributors to this file:
- *     Dave Pare, 1986, 1989 
+ *     Dave Pare, 1986, 1989
  *     Steve McClure, 1998-2000
+ *     Ron Koenderink, 2005
+ *     Markus Armbruster, 2005-2008
  */
 
 /*
  * starting with 'a'.  Symbolic names for ids are defined in proto.h.
  */
 
-#include <string.h>
-#include <fcntl.h>
-#include <ctype.h>
+#include <config.h>
+
 #include <stdarg.h>
-#include "proto.h"
-#include "misc.h"
-#include "player.h"
-#include "nat.h"
+#include <stdlib.h>
+#include "com.h"
 #include "empio.h"
 #include "file.h"
-#include "com.h"
-#include "tel.h"
-#include "server.h"
+#include "journal.h"
+#include "misc.h"
+#include "nat.h"
+#include "player.h"
+#include "proto.h"
 #include "prototypes.h"
+#include "server.h"
+#include "tel.h"
 
 static void pr_player(struct player *pl, int id, char *buf);
 static void upr_player(struct player *pl, int id, char *buf);
@@ -112,8 +115,7 @@ uprnf(char *buf)
  * arguments.  It is assumed to be already user text.  Plain ASCII and
  * text received from the same player are fine, for anything else the
  * caller has to deal with output filtering.
- * If a partial line with different id is buffered, terminate it with
- * a newline first.
+ * If a partial line is buffered, terminate it with a newline first.
  */
 void
 pr_id(struct player *p, int id, char *format, ...)
@@ -123,6 +125,7 @@ pr_id(struct player *p, int id, char *format, ...)
 
     if (p->curid >= 0) {
        io_puts(p->iop, "\n");
+       journal_output(p, "\n");
        p->curid = -1;
     }
     va_start(ap, format);
@@ -179,17 +182,26 @@ pr_inform(struct player *pl, char *format, ...)
  * Send C_FLASH text to everyone.
  * Format text to send using printf-style FORMAT and optional
  * arguments.  It is assumed to be plain ASCII.
+ * Prefix text it with a header suitable for broadcast from deity.
  * Initiate an output queue flush, but do not wait for it to complete.
  */
 void
 pr_wall(char *format, ...)
 {
+    time_t now;
+    struct tm *tm;
     char buf[4096];            /* UTF-8 */
+    int n;
     struct player *p;
     va_list ap;
 
+    time(&now);
+    tm = localtime(&now);
+    n = sprintf(buf, "BROADCAST from %s @ %02d:%02d: ",
+               getnatp(0)->nat_cnam, tm->tm_hour, tm->tm_min);
+
     va_start(ap, format);
-    (void)vsprintf(buf, format, ap);
+    (void)vsprintf(buf + n, format, ap);
     va_end(ap);
     for (p = player_next(0); p; p = player_next(p)) {
        if (p->state != PS_PLAYING)
@@ -235,6 +247,7 @@ pr_player(struct player *pl, int id, char *buf)
            bp += len;
        }
     }
+    journal_output(pl, buf);
 }
 
 /*
@@ -289,6 +302,7 @@ upr_player(struct player *pl, int id, char *buf)
            io_puts(pl->iop, printbuf);
        }
     }
+    journal_output(pl, buf);
 }
 
 /*
@@ -310,6 +324,7 @@ outid(struct player *pl, int n)
     buf[1] = ' ';
     buf[2] = '\0';
     io_puts(pl->iop, buf);
+    journal_output(pl, buf);
     pl->curid = n;
 }
 
@@ -358,11 +373,8 @@ prmptrd(char *prompt, char *buf, int size)
 {
     int r;
 
-    /*
-     * Each prompt must consume one line of input.  recvclient()
-     * doesn't do that while player->aborted.
-     */
-    CANT_HAPPEN(player->aborted);
+    if (CANT_HAPPEN(!prompt))
+       prompt = "? ";
 
     pr_id(player, C_FLUSH, "%s\n", prompt);
     if ((r = recvclient(buf, size)) < 0)
@@ -390,8 +402,8 @@ uprmptrd(char *prompt, char *buf, int size)
 {
     int r;
 
-    /* See prmptrd() */
-    CANT_HAPPEN(player->aborted);
+    if (CANT_HAPPEN(!prompt))
+       prompt = "? ";
 
     pr_id(player, C_FLUSH, "%s\n", prompt);
     if ((r = recvclient(buf, size)) < 0)
@@ -424,12 +436,10 @@ prdate(void)
 void
 prxy(char *format, coord x, coord y, natid country)
 {
-    char buf[255];
     struct natstr *np;
 
     np = getnatp(country);
-    sprintf(buf, format, xrel(np, x), yrel(np, y));
-    pr(buf);
+    pr(format, xrel(np, x), yrel(np, y));
 }
 
 /*
@@ -456,7 +466,7 @@ PR(int cn, char *format, ...)
     newline = strrchr(buf, '\n') ? 1 : 0;
     strcat(longline[cn], buf);
     if (newline) {
-       if (update_pending || (cn && cn != player->cnum))
+       if (update_running || (cn && cn != player->cnum))
            typed_wu(0, cn, longline[cn], TEL_BULLETIN);
        else
            pr_player(player, C_DATA, longline[cn]);
@@ -493,8 +503,9 @@ pr_beep(void)
 /*
  * Print to country CN similar to printf().
  * Use printf-style FORMAT with the optional arguments.
- * If CN is the current player and we're not in the update, print just
- * like pr().  Else print into a bulletin.
+ * If CN is zero, don't print anything.
+ * Else, if CN is the current player and we're not in the update,
+ * print just like pr().  Else print into a bulletin.
  * Because printing like pr() requires normal text, and bulletins
  * require user text, only plain ASCII is allowed.
  */
@@ -504,15 +515,15 @@ mpr(int cn, char *format, ...)
     char buf[4096];
     va_list ap;
 
+    if (!cn)
+       return;
     va_start(ap, format);
     (void)vsprintf(buf, format, ap);
     va_end(ap);
-    if (cn) {
-       if (update_pending || cn != player->cnum)
-           typed_wu(0, cn, buf, TEL_BULLETIN);
-       else
-           pr_player(player, C_DATA, buf);
-    }
+    if (update_running || cn != player->cnum)
+       typed_wu(0, cn, buf, TEL_BULLETIN);
+    else
+       pr_player(player, C_DATA, buf);
 }
 
 /*