Commit Graph

257 Commits

Author SHA1 Message Date
PatR
adf64764f4 minor memory leak
I ran the fuzzer with MONITOR_HEAP enabled and heaputil found a dozen
or so un-free'd allocations, all made by the same dupstr() call in
special_handling() for "symset" and "roguesymset".  (Reproducible with
a few tens of thousands of fuzzer moves, although you have to take
over from the fuzzer and make a clean exit rather than just interrupt
it or there'll be lots of other un-free'd memory.)  I haven't actually
figured out how/why it was leaking, but reorganizing the code has made
the leak go away (according to a couple of even longer fuzzer runs) so
I'm settling for that.
2018-12-29 20:41:16 -08:00
PatR
0ad8a192bf formatting: parse_conf_file() 2018-12-24 17:50:21 -08:00
nhmall
dc2539701a Revert "some fixes provided from Hardfought"
This reverts commit ab9e28d1aa.
2018-12-04 11:59:41 -05:00
nhmall
ab9e28d1aa some fixes provided from Hardfought 2018-12-04 11:58:05 -05:00
nhmall
4a4b3fb8f1 add a macro to ease conditional testing based on active window port
Add WINDOWPORT macro

example:
if (WINDOWPORT("tty"))
	pline("Look at me, I'm on tty at the moment!");
2018-12-02 09:56:44 -05:00
PatR
98afe5541d mouse_support compile bits
There was a spurious seli-colon after an if's test, making a boundary
check be ineffective.  When looking at that, I noticed that the 'O'
command's display of the current value for mouse_support ("0=off" and
so forth) was relying on implicit concatenation of adjacent string
literals, which would break K&R compilation.  Do that concatenation
the old fashioned way....

While testing (after temporarily adding WC_MOUSE_SUPPORT to tty's
window_procs), I also noticed that wording used by config_error_add
looked strange when it was in response to giving a bad value via 'O'
command.  Suppress its "config_error_add: " prefix is that situation.
2018-11-28 01:02:44 -08:00
PatR
50cb52ab31 sentence spacing
Use two spaces between sentences.  This only fixes the instances of
one-space that were fairly easy to find.
2018-11-20 17:56:16 -08:00
PatR
91f973306b build and bug fixes for USE_OLDARGS
New:  call to panic() in impossible() used arbitrary string as a
format so was vulnerable to percent signs in that string.  (This
potentially serious problem is not limited to USE_OLDARGS.)

Old:  revised message string for impossible ("save/restore might fix
this" instead of "perhaps you'd better quit") passed wrong number of
arguments to pline() when using the clumsy VA_PASSx() mechanism (was
missing arg 0 for the fixed-arg format argument).

Old:  varargs config_error_add() in files.c wouldn't compile for
USE_OLDARGS.  Evidently no one has been impacted by that but this
fixes it anyway.  (Two problems:  prototype used FDECL() when it
should have been using VDECL(), and calls to config_error_add() in
the same file would need the VA_PASSx() stuff to force presence of
all optional args.  I moved it instead of adding the latter.)
2018-11-08 15:33:03 -08:00
PatR
14bef9a02d formatting cleanup src/*.c
Remove trailing spaces, and remove tabs from the files that had
trailing spaces.

Also, rndorcname() was using a random value to terminate a loop
and was recalculating a new one each iteration.
2018-10-02 16:53:22 -07:00
PatR
fc75055263 debug logging
Remove unused variables.
2018-05-15 04:15:41 -07:00
nhmall
04c85aa59d update files.c with testinglog 2018-05-10 18:54:58 -04:00
nhmall
4e5c41401f last line of config file wasn't heeded if newline was missing 2018-04-28 17:22:21 -04:00
nhmall
72d38f1f67 windows-only bit 2018-04-26 18:00:32 -04:00
keni
d8c49ec9d1 Add updated copyright lines, part 1. 2018-04-25 15:00:13 -04:00
nhmall
e236c23b35 windows record file diagnostic info 2018-04-22 12:15:30 -04:00
nhmall
9773742e82 fix some msdos build errors 2018-02-24 23:26:25 -05:00
Pasi Kallinen
491b40897f Ignore Qt specific config options silently
If the binary wasn't compiled with Qt, don't complain
about Qt specific config options.
2017-10-16 12:47:07 +03:00
Pasi Kallinen
69f7a78dba Hilite Status: Improved
Allow defining multiple stops per field. Add hitpointbar.
2017-09-26 10:04:25 +03:00
Pasi Kallinen
5aaec6a990 Lint for strncpy return value 2017-09-19 14:12:10 +03:00
Pasi Kallinen
b82b41cb5a Fix possible buffer overrun 2017-09-19 14:09:01 +03:00
Pasi Kallinen
45401a13bb Show regex error before asking for color
When entering a new menucolor via options, show regex error
immediately afterwards, instead of asking for color and attribute
before showing the error.

Also actually show config errors even if config error handler
hasn't been initialized.
2017-09-17 13:20:28 +03:00
Pasi Kallinen
11863dd5e9 Read symbols with config file handler
Also, make config file error handler able to cope with recursion.
2017-09-17 10:15:08 +03:00
Pasi Kallinen
127f74bb24 Fix more warnings 2017-09-13 14:12:38 +03:00
Pasi Kallinen
bd7568b71d Fix compile warnings 2017-09-13 13:59:25 +03:00
Pasi Kallinen
b6737fd1f6 config parse return values and error msgs 2017-09-13 13:26:37 +03:00
Pasi Kallinen
2c688a12d5 Handle config file reading at single function
The function handles comments, empty lines, config sections,
CHOOSE, and line continuation, while calling another function
for other lines.

Currently used for config file, sysconf, and WIZKIT.
2017-09-13 12:27:38 +03:00
Pasi Kallinen
9c118b5b6b Secure config errors
If user can make NETHACKOPTIONS point to a file, that user could then
get the file contents via the extended config file error reporting.
Add CONFIG_ERROR_SECURE compile-time option to make that case output
only the first error, no line number or error context.
2017-09-10 21:05:51 +03:00
Pasi Kallinen
cfb09c9bf8 Handle windowtype and CHOOSE config errors 2017-09-09 13:50:34 +03:00
Pasi Kallinen
87f991ecfc Show error on unknown line 2017-09-09 13:25:46 +03:00
Pasi Kallinen
f8211f69f2 Improve config file error reporting
Show the original line from the config file, followed by the line number and
a specific error message. Also show all errors from the config file before
waiting for key press.
2017-09-09 13:04:08 +03:00
Pasi Kallinen
697d2953ff Fix proto decl 2017-09-02 18:51:45 +03:00
Pasi Kallinen
bfad877fba Add optional config file sections, selected with CHOOSE
Allows the user to define arbitrarily named optional sections
in the config file, and select which of those sections are used.

For example:

  OPTIONS=color
  CHOOSE=char A,char B

  [char A]
  OPTIONS=role:arc,race:dwa,align:law,gender:fem

  [char B]
  OPTIONS=role:wiz,race:elf,align:cha,gender:mal
2017-09-02 12:21:51 +03:00
Alex Smith
a2f886c665 Handle the case where we continue after locking a nonexistent file
The previous version of this would lead to big warnings and
impossibles. This doesn't seem like a useful case, but it's still
better to have better warning messages just in case it does
happen.
2017-09-01 18:49:43 +01:00
Alex Smith
49ddedc138 Merge branch 'NetHack-3.6.0' of https://rodney.nethack.org:20040/git/NHsource into NetHack-3.6.0 2017-09-01 17:44:31 +01:00
Alex Smith
1d4b6aae40 Fix error behaviour when perm is missing
The previous behaviour was to mention the missing file, but then to
try and fail to lock the nonexistent file 10 times, which rather
obscured the original cause of the error as it took up so much more
room on the screen.

This patch also changes the error message. Failure to lock a
nonexistent file is almost always the result of a mistake during
the install process (e.g. running from the wrong directory, or
running without an install). We should give the user a hint about
that.
2017-09-01 17:43:04 +01:00
PatR
eadecb1baf BONES_POOLS fix and bonesid fix
The BONES_POOLS implementation added an extra dot to the bones file
name (only when enabled) which would be a problem on some filesystems.
This changes the name from "bonD0.15.3" to "bon3D0.15" which avoids
the second dot and also fits within 8.3 characters.  To enforce that,
the maximum value for BONES_POOLS is now 10 (yielding single-digit pool
numbers 0 through 9).

BONES_POOLS==1 will omit the pool number (that's not a change, just a
reminder), yielding "bonD0.15" and so on.  Right now, BONES_POOLS==0
is equivalent to BONES_POOLS=1, but it could be changed someday to
mean that bones files shouldn't be used if we decide to support that.

The pool number as a suffix was being included in content validation,
so it wasn't possible to move "bonD0.15.3" to pool 2 by renaming it to
"bonD0.15.2".  I'm not sure whether that was intentional, but it seems
overly draconian.  "bon3D0.15" can be renamed to "bon2D0.15" and then
be loaded by a game assigned to pool 2.  Also, pre-pool bones can be
retained by renaming to any valid pool and should still work.

The three letter filecode for quest bones has made the bonesid be
broken since 3.3.0 introduced it (the three letter code, not bones-id).
"QArc.2" for level 2 of the Archeologist quest was being written into
the bones file as "rc.2", but worked as intended because validation
when loading bones had the same mistake.  This fixes it to use "QArc.2"
when saving and accept either "QArc.2" or "rc.2" when loading, so 3.6.0
bones files (and existing to-be-3.6.1 bones) will continue to work.
2017-08-21 02:50:26 -07:00
Pasi Kallinen
1eca824321 Add sysconf BONES_POOLS to allow more bones-files per level
Reduce the chance of a player playing on a public server encountering
their own bones, by implementing separate bones pools. The pool a player
belongs to is determined at game start, and only bones in that pool
are used. The sysconf BONES_POOLS allows the sysadmin to define how
many pools there are.
2017-08-20 23:04:59 +03:00
Pasi Kallinen
189809a55c Rename terminate to nh_terminate so VS2015 can compile 2017-08-19 14:10:29 +03:00
Pasi Kallinen
d1c1fd5faf Fix syntax error 2017-08-19 13:40:47 +03:00
PatR
fd74f2e149 fix files.c part of #H5778 - file descriptor leaks
Fix the SELF_RECOVER part of files.c which was actually in slightly
worse shape than previously fixed recover.c itself.

I think the HOLD_LOCKFILE_OPEN edition of nhclose() is the only
remaining file descriptor leak from the original #H5778 report.

The revised code compiles when SELF_RECOVER is defined, but I didn't
actually force a recovery to fully test it.

This patch includes a couple of reformatting and/or reorganization
bits in addition to the fd leak fix.
2017-08-12 16:44:39 -07:00
Pasi Kallinen
7d8b4d4f97 Add end-of-game dumplogs
This is based on the "new" dumplog patch for 3.6.0, by Maxime Bacoux.

Define DUMPLOG to enable. By default only enabled for the TTY linux.
2017-02-19 15:33:27 +02:00
Pasi Kallinen
680c8a542c Add key rebinding
This is a modified version of Jason Dorje Short's key rebinding
patch, and allows also binding special keys, such as the ones
used in getloc and getpos.

One of the ways to play NetHack on nethack.alt.org is via a HTML
terminal in browser. Unfortunately this means several ctrl-key
combinations cannot be entered, because the browser intercepts
those. Similar thing applies to some international keyboard layouts
on Windows. With this patch, the user can just rebind the command
to a key that works best for them.

I've tested this on Linux TTY, X11, and Windows TTY and GUI.
2016-10-05 20:04:56 +03:00
PatR
93dbc7216a config file typo 2016-06-15 23:58:21 -07:00
Pasi Kallinen
942ee14d0f Move generic usernames to sysconf 2016-06-13 11:01:05 +03:00
PatR
4ff8d8ac7e fix #H4060 - sysconf is re-read if no config file
Config file handling remembers the name of the last config file
read in order for options processing to use it in messages, but
it was also reused as default config file name if user-supplied
config file name failed access() test.  So the SYSCF file became
the default user config file after it was used.  The config file
handling was a real mess.

This patch fixes it for Unix but there is a lot of scope for
typos in the changes for other platforms.  Testing is needed.
2016-06-12 17:52:12 -07:00
PatR
3381aa4122 symset parsing
Add support for character enclosed within single quotes.  Single
character without quotes would work for most characters, but not
'#' and possibly not '^' or '\\'.  All the values in dat/symbols
are specified via backslash+digits so it isn't obvious that some
other form of value is allowed.

I think this parsing accepts all valid values.  It doesn't reject
all invalid ones:  opening quote followed by valid escape sequence
followed by junk followed by closing quote will ignore the junk.
I don't think there's any pressing need to worry about that.
2016-04-06 17:06:33 -07:00
PatR
ba5449e17e tribute passage limit
Death Quotes have reached the current limit of 30 passages per 'book'.
Instead of increasing that, change the selection code to be able to
operate on a subset (dropped from 30 down to 20) at a time while
keeping the excess available for later selection.

Chatting with Death (more than 20 times since he also delivers non-
tribute messages) should cycle through 20 of his 30 passages without
repeating.  After that, another subset of 20 out of the 30 will be
chosen, independent of the first set so might contain all, some, or
none of the 10 that left out before.
2016-02-18 14:46:25 -08:00
Pasi Kallinen
fe006b9c0a Add CHECK_PLNAME to sysconf
Setting CHECK_PLNAME to 1 makes WIZARDS, EXPLORERS, and SHELLERS
check the player name instead of the user's login name.

This is mostly useful for public servers which have external
login system and don't create user accounts for players.
2016-02-05 20:39:17 +02:00
David Cohrs
288ac4b07c avoid crash for long lines in nethackrc
read_config_file() has used a buffer of size (4 * BUFSZ) since 3.4.x
so parse_config_line() needs a buffer of the same size to avoid
buffer overrun. Allows my old .nethackrc to work again.
2016-01-28 18:40:59 -08:00
PatR
350dcf067b tribute streamlining
Chatting with Death doesn't always deliver a tribute Death Quote but
when it does, it wasn't giving each of them once before reusing them
even though they should have been treated the same as passage
selections from a novel.  I'm still not sure why it wasn't working
as intended, but after some revision to the tribute parsing code, now
it is.  If you #chat with Death enough times to get 20 tribute quotes,
you will see each of the 20 quotes once (in random order), then
further chatting will give them again (in different random order).
2016-01-16 17:36:48 -08:00