]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/flash.c
Change flash not to print "Flash sent" for deities
[empserver] / src / lib / commands / flash.c
index 36d2da0090029c48080fbac52d4f729ea2db1048..e07ea128b8fdf3c1296707486d729082be9bfe96 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  flash.c: Flash a message to another player
- * 
+ *
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
  *     Ron Koenderink, 2005
- *     Markus Armbruster, 2004-2007
+ *     Markus Armbruster, 2004-2009
  */
 
 #include <config.h>
 
 #include "commands.h"
 
+static int chat(struct natstr *, struct natstr *, char *);
+static int sendmessage(struct natstr *, struct natstr *, char *, int);
+
 int
 flash(void)
 {
     struct natstr *us;
     struct natstr *to;
-    char buf[1024];            /* UTF-8 */
     int tocn;
-    char *sp;                  /* points into player->combuf[], UTF-8 */
 
     us = getnatp(player->cnum);
     if ((tocn = natarg(player->argp[1], "to which country? ")) < 0)
@@ -68,51 +69,39 @@ flash(void)
        }
     }
 
-    if (player->argp[2]) {
-       for (sp = player->combuf; *sp && *sp != ' '; ++sp) ;
-       for (++sp; *sp && *sp != ' '; ++sp) ;
-       buf[0] = ':';
-       if (player->flags & PF_UTF8)
-           strcpy(buf+1, sp);
-       else
-           copy_utf8_to_ascii_no_funny(buf+1, sp);
-       sendmessage(us, to, buf, 1);
-    } else {
-       sendmessage(us, to, "...", 1);
-       while (ugetstring("> ", buf)) {
-           if (*buf == '.')
-               break;
-           sendmessage(us, to, buf, 0);
-       }
-       sendmessage(us, to, "<EOT>", 0);
-    }
-    return RET_OK;
+    return chat(us, to, player->comtail[2]);
 }
 
 int
 wall(void)
 {
-    struct natstr *us;
+    return chat(getnatp(player->cnum), NULL, player->comtail[1]);
+}
+
+/*
+ * Send flash message(s) from US to TO.
+ * Null TO broadcasts to all.
+ * MESSAGE is UTF-8.  If it is null, prompt for messages interactively.
+ * Return RET_OK.
+ */
+static int
+chat(struct natstr *us, struct natstr *to, char *message)
+{
     char buf[1024];            /* UTF-8 */
-    char *sp;                  /* points into player->combuf[], UTF-8 */
 
-    us = getnatp(player->cnum);
-    if (player->argp[1]) {
-       for (sp = player->combuf; *sp && *sp != ' '; ++sp) ;
+    if (message) {
        buf[0] = ':';
-       if (player->flags & PF_UTF8)
-           strcpy(buf+1, sp);
-       else
-           copy_utf8_to_ascii_no_funny(buf+1, sp);
-       sendmessage(us, 0, buf, 1);
+       buf[1] = ' ';
+       strcpy(buf+2, message);
+       sendmessage(us, to, buf, 1);
     } else {
-       sendmessage(us, 0, "...", 1);
+       sendmessage(us, to, "...", 1);
        while (ugetstring("> ", buf)) {
            if (*buf == '.')
                break;
-           sendmessage(us, 0, buf, 0);
+           sendmessage(us, to, buf, 0);
        }
-       sendmessage(us, 0, "<EOT>", 0);
+       sendmessage(us, to, "<EOT>", 0);
     }
     return RET_OK;
 }
@@ -124,7 +113,7 @@ wall(void)
  * A header identifying US is prepended to the message.  It is more
  * verbose if VERBOSE.
  */
-int
+static int
 sendmessage(struct natstr *us, struct natstr *to, char *message, int verbose)
 {
     struct player *other;
@@ -135,7 +124,7 @@ sendmessage(struct natstr *us, struct natstr *to, char *message, int verbose)
 
     time(&now);
     tm = localtime(&now);
-    for (other = player_next(0); other != 0; other = player_next(other)) {
+    for (other = player_next(NULL); other; other = player_next(other)) {
        if (other->state != PS_PLAYING)
            continue;
        if (to && other->cnum != to->nat_cnum)
@@ -163,13 +152,12 @@ sendmessage(struct natstr *us, struct natstr *to, char *message, int verbose)
                     us->nat_cnam, us->nat_cnum, message);
        sent++;
     }
+    
     if (player->god) {
-       if (to)
-           if (sent)
-               pr("Flash sent to %s\n", to->nat_cnam);
-           else
+       if (to) {
+           if (!sent)
                pr("%s is not logged on\n", to->nat_cnam);
-       else if (sent)
+       else if (sent)
            pr("Broadcast sent to %d players\n", sent);
        else
            pr("No-one is logged in\n");