]> granicus.if.org Git - nethack/commitdiff
Don't leak ID of magic tools in charging prompt
authorMichael Meyer <me@entrez.cc>
Wed, 16 Nov 2022 20:40:16 +0000 (15:40 -0500)
committerPatR <rankin@nethack.org>
Sat, 19 Nov 2022 08:41:52 +0000 (00:41 -0800)
The getobj prompt for charging was presenting any chargeable tool in the
hero's inventory as a suggested charging target, even tools which were
unidentified and undistinguishable from their mundane counterparts
(e.g. bag of tricks, magic harp, horn of plenty...).  This leaked
information about the identity of these items and made it possible to
determine whether a generic 'harp' was magic or not.

When suggesting chargeable tools, include only those which are actually
known to be chargeable (unidentified or unseen chargeable tools can
still be selected, they just won't be suggested targets).  Basically the
same as what's done for a potion of oil in the apply prompt.

src/read.c

index f9533991d65b4d1d28144b70a4a19f3ccd853004..3d66a8acd5f9bf91bd86f30ff1e3d11cd294c1a8 100644 (file)
@@ -698,7 +698,13 @@ charge_ok(struct obj* obj)
                 && !objects[MAGIC_LAMP].oc_name_known)) {
             return GETOBJ_SUGGEST;
         }
-        return objects[obj->otyp].oc_charged ? GETOBJ_SUGGEST : GETOBJ_EXCLUDE;
+        /* suggest chargeable tools only if discovered, to prevent leaking
+           info (e.g. revealing if an unidentified 'flute' is magic or not) */
+        if (objects[obj->otyp].oc_charged) {
+            return (obj->dknown && objects[obj->otyp].oc_name_known)
+                     ? GETOBJ_SUGGEST : GETOBJ_DOWNPLAY;
+        }
+        return GETOBJ_EXCLUDE;
     }
     /* why are weapons/armor considered charged anyway?
      * make them selectable even so for "feeling of loss" message */