OSDN Git Service

update year to 2020
[jnethack/source.git] / src / mail.c
index c1a41e2..2503236 100644 (file)
@@ -1,11 +1,11 @@
-/* NetHack 3.6 mail.c  $NHDT-Date: 1519070343 2018/02/19 19:59:03 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.31 $ */
+/* NetHack 3.6 mail.c  $NHDT-Date: 1568508711 2019/09/15 00:51:51 $  $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.40 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Pasi Kallinen, 2018. */
 /* NetHack may be freely redistributed.  See license for details. */
 
 /* JNetHack Copyright */
 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
-/* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2019            */
+/* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2020            */
 /* JNetHack may be freely redistributed.  See license for details. */
 
 #include "hack.h"
@@ -191,7 +191,7 @@ coord *startp;
      */
     lax = 0; /* be picky */
     max_distance = -1;
-retry:
+ retry:
     for (row = 0; row < ROWNO; row++) {
         if (viz_rmin[row] < viz_rmax[row]) {
             /* There are valid positions on this row. */
@@ -276,7 +276,7 @@ coord *startp; /* starting position (read only) */
 }
 
 /* Let the mail daemon have a larger vocabulary. */
-#if 0 /*JP*/
+#if 0 /*JP:T*/
 static NEARDATA const char *mail_text[] = { "Gangway!", "Look out!",
                                             "Pardon me!" };
 #else
@@ -349,19 +349,21 @@ register int tx, ty; /* destination of mail daemon */
 */
             verbalize("\82¿\82å\82Á\82Æ\82µ\82Â\82ê\82¢\81D");
 
+        if (mon)
+            remove_monster(fx, fy);
         place_monster(md, fx, fy); /* put md down */
         newsym(fx, fy);            /* see it */
         flush_screen(0);           /* make sure md shows up */
         delay_output();            /* wait a little bit */
 
         /* Remove md from the dungeon.  Restore original mon, if necessary. */
+        remove_monster(fx, fy);
         if (mon) {
             if ((mon->mx != fx) || (mon->my != fy))
                 place_worm_seg(mon, fx, fy);
             else
                 place_monster(mon, fx, fy);
-        } else
-            remove_monster(fx, fy);
+        }
         newsym(fx, fy);
     }
 
@@ -370,12 +372,14 @@ register int tx, ty; /* destination of mail daemon */
      * very unlikely).  If one exists, then have the md leave in disgust.
      */
     if ((mon = m_at(fx, fy)) != 0) {
+        remove_monster(fx, fy);
         place_monster(md, fx, fy); /* display md with text below */
         newsym(fx, fy);
 /*JP
         verbalize("This place's too crowded.  I'm outta here.");
 */
         verbalize("\82±\82±\82Í\8d¬\82Ý\82·\82¬\81D\82±\82±\82Å\91Ò\82Á\82Ä\82é\82æ\81D");
+        remove_monster(fx, fy);
 
         if ((mon->mx != fx) || (mon->my != fy)) /* put mon back */
             place_worm_seg(mon, fx, fy);
@@ -435,21 +439,24 @@ struct mail_info *info;
 */
             verbalize("\82Ù\82ç\82æ\81I");
         display_nhwindow(WIN_MESSAGE, FALSE);
-#if 0 /*JP*/
+#if 0 /*JP:T*/
         obj = hold_another_object(obj, "Oops!", (const char *) 0,
                                   (const char *) 0);
 #else
         obj = hold_another_object(obj, "\82¨\82Á\82Æ\81I", (const char *) 0,
                                   (const char *) 0);
 #endif
+        nhUse(obj);
     }
 
-/* zip back to starting location */
-go_back:
-    (void) md_rush(md, start.x, start.y);
+ go_back:
+    /* zip back to starting location */
+    if (!md_rush(md, start.x, start.y))
+        md->mx = md->my = 0; /* for mongone, md is not on map */
     mongone(md);
-/* deliver some classes of messages even if no daemon ever shows up */
-give_up:
+
+ give_up:
+    /* deliver some classes of messages even if no daemon ever shows up */
     if (!message_seen && info->message_typ == MSG_OTHER)
 /*JP
         pline("Hark!  \"%s.\"", info->display_txt);
@@ -487,14 +494,19 @@ void
 readmail(otmp)
 struct obj *otmp UNUSED;
 {
-    static char *junk[] = {
-        NULL, /* placeholder for "Report bugs to <devteam@nethack.org>.", */
-/*JP
-        "Please disregard previous letter.", "Welcome to NetHack.",
-*/
-        "\91O\82Ì\83\81\81[\83\8b\82Í\96Y\82ê\82Ä\82­\82¾\82³\82¢\81D", "NetHack\82Ö\82æ\82¤\82±\82»\81I",
+    static const char *junk[] = {
+#if 0 /*JP:T*/
+        "Report bugs to <%s>.", /*** must be first entry ***/
+        "Please disregard previous letter.",
+        "Welcome to NetHack.",
+#else
+        "Report bugs to <%s>.", /*** must be first entry ***/
+        "\91O\82Ì\83\81\81[\83\8b\82Í\96Y\82ê\82Ä\82­\82¾\82³\82¢\81D",
+        "JNetHack\82Ö\82æ\82¤\82±\82»\81I",
+#endif
 #ifdef AMIGA
-        "Only Amiga makes it possible.", "CATS have all the answers.",
+        "Only Amiga makes it possible.",
+        "CATS have all the answers.",
 #endif
 /*JP
         "This mail complies with the Yendorian Anti-Spam Act (YASA)",
@@ -512,24 +524,59 @@ struct obj *otmp UNUSED;
         "Please return to sender (Asmodeus)",
 */
         "\91\97\90M\8eÒ(\83A\83X\83\82\83f\83E\83X)\82É\91\97\82è\95Ô\82µ\82Ä\82­\82¾\82³\82¢",
+        /* when enclosed by "It reads:  \"...\"", this is too long
+           for an ordinary 80-column display so wraps to a second line
+           (suboptimal but works correctly);
+           dollar sign and fractional zorkmids are inappropriate within
+           nethack but are suitable for typical dysfunctional spam mail */
 /*JP
-      "Buy a potion of gain level for only $19.99! Guaranteed to be blessed!",
+     "Buy a potion of gain level for only $19.99!  Guaranteed to be blessed!",
 */
-      "\83\8c\83x\83\8b\83A\83b\83v\82Ì\96ò\82ª\82½\82Á\82½\82Ì1980\89~!\8fj\95\9f\95Û\8fØ!",
+     "\83\8c\83x\83\8b\83A\83b\83v\82Ì\96ò\82ª\82½\82Á\82½\82Ì1980\89~!\8fj\95\9f\95Û\8fØ!",
+        /* DEVTEAM_URL will be substituted for "%s"; terminating punctuation
+           (formerly "!") has deliberately been omitted so that it can't be
+           mistaken for part of the URL (unfortunately that is still followed
+           by a closing quote--in the pline below, not the data here) */
 /*JP
-        "Invitation: Visit the NetHack web site at http://www.nethack.org!"
+        "Invitation: Visit the NetHack web site at %s"
 */
-        "\8fµ\91Ò\8fó: NetHack \83E\83F\83u\83T\83C\83http://www.nethack.org \82É\97\88\82Ä\82Ë!"
+        "\8fµ\91Ò\8fó: NetHack \83E\83F\83u\83T\83C\83%s \82É\97\88\82Ä\82Ë!"
     };
 
     /* XXX replace with more general substitution code and add local
-     * contact message.  Also use DEVTEAM_URL */
-    if (junk[0] == NULL) {
-#define BUGS_FORMAT "Report bugs to <%s>."
-        /* +2 from '%s' suffices as substitute for usual +1 for terminator */
-        junk[0] = (char *) alloc(strlen(BUGS_FORMAT) + strlen(DEVTEAM_EMAIL));
-        Sprintf(junk[0], BUGS_FORMAT, DEVTEAM_EMAIL);
-#undef BUGS_FORMAT
+     * contact message.
+     *
+     * FIXME:  this allocated memory is never freed.  However, if the
+     * game is restarted, the junk[] update will be a no-op for second
+     * and subsequent runs and this updated text will still be appropriate.
+     */
+    if (index(junk[0], '%')) {
+        char *tmp;
+        int i;
+
+        for (i = 0; i < SIZE(junk); ++i) {
+            if (index(junk[i], '%')) {
+                if (i == 0) {
+                    /* +2 from '%s' in junk[0] suffices as substitute
+                       for usual +1 for terminator */
+                    tmp = (char *) alloc(strlen(junk[0])
+                                         + strlen(DEVTEAM_EMAIL));
+                    Sprintf(tmp, junk[0], DEVTEAM_EMAIL);
+                    junk[0] = tmp;
+                } else if (strstri(junk[i], "web site")) {
+                    /* as with junk[0], room for terminator is present */
+                    tmp = (char *) alloc(strlen(junk[i])
+                                         + strlen(DEVTEAM_URL));
+                    Sprintf(tmp, junk[i], DEVTEAM_URL);
+                    junk[i] = tmp;
+                } else {
+                    /* could check for "%%" but unless that becomes needed,
+                       handling it is more complicated than necessary */
+                    impossible("fake mail #%d has undefined substitution", i);
+                    junk[i] = "Bad fake mail...";
+                }
+            }
+        }
     }
     if (Blind) {
 /*JP
@@ -603,7 +650,7 @@ boolean adminmsg;
     struct flock fl = { 0 };
 #endif
     const char *msgfrom = adminmsg
-#if 0 /*JP*/
+#if 0 /*JP:T*/
         ? "The voice of %s booms through the caverns:"
         : "This message is from '%s'.";
 #else
@@ -636,7 +683,7 @@ boolean adminmsg;
             fl.l_type = F_UNLCK;
             fcntl (fileno(mb), F_UNLCK, &fl);
 #endif
-#if 0 /*JP*/
+#if 0 /*JP:T*/
             pline("There is a%s message on this scroll.",
                   seen_one_already ? "nother" : "");
 #else
@@ -684,7 +731,7 @@ boolean adminmsg;
     else
         unlink(mailbox);
     return;
-bail:
+ bail:
     /* bail out _professionally_ */
     if (!adminmsg)
 /*JP
@@ -725,6 +772,8 @@ struct obj *otmp UNUSED;
     return;
 #endif /* SIMPLE_MAIL */
 #ifdef DEF_MAILREADER /* This implies that UNIX is defined */
+    if (iflags.debug_fuzzer)
+        return;
     display_nhwindow(WIN_MESSAGE, FALSE);
     if (!(mr = nh_getenv("MAILREADER")))
         mr = DEF_MAILREADER;
@@ -757,6 +806,8 @@ ckmailstatus()
 {
     struct mail_info *brdcst;
 
+    if (iflags.debug_fuzzer)
+        return;
     if (u.uswallow || !flags.biff)
         return;