]> git.pond.sub.org Git - empserver/log
empserver
6 years agoclient: Rewrite readline configuration
Markus Armbruster [Mon, 7 Dec 2015 20:27:42 +0000 (21:27 +0100)]
client: Rewrite readline configuration

AX_LIB_READLINE tries to cope with systems where readline lacks
history support, or lacks headers, or needs headers included in
unorthodox ways.  It puts six HAVE_ macros into config.h, and its
usage example takes 24 lines of code just to include two headers.

Way too complicated for my taste.  Replace with new MY_LIB_READLINE,
which succeeds only when you have a sane readline, and then defines
*one* macro: HAVE_LIBREADLINE.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Collect readline-related code in play.c
Markus Armbruster [Sun, 6 Dec 2015 07:40:14 +0000 (08:40 +0100)]
client: Collect readline-related code in play.c

Move prompt() from servcmd.c to play.c and give it external linkage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Redistribute work among prompt() and its callers
Markus Armbruster [Sun, 6 Dec 2015 07:29:17 +0000 (08:29 +0100)]
client: Redistribute work among prompt() and its callers

Two out of three callers want an extra newline.  Letting the callers
do that is simpler, especially now that readline added another case to
prompt().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Fix obscure readline hang
Markus Armbruster [Sun, 6 Nov 2016 16:05:19 +0000 (17:05 +0100)]
client: Fix obscure readline hang

If recv_input() can't stuff the whole line into @inbuf, it leaves its
tail in @input_from_rl.  If send_input() then empties @inbuf, the next
iteration will select @input_fd for reading instead of @sock for
writing, because @inbuf is empty.  Since @has_rl_input is still set,
recv_input() will do nothing, and the client hangs.

Fix as follows.  Factor ring_from_rl() out of recv_input().  Also call
it in send_input() to refill @inbuf from @input_from_rl.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Tie up a few lose readline ends
Markus Armbruster [Sun, 13 Dec 2015 08:10:08 +0000 (09:10 +0100)]
client: Tie up a few lose readline ends

Document readline in more detail in man/empire.6.

Make @history_file local to main().

main() silently truncates the home directory name to 1000 characters
when constructing the history file name; mark FIXME.

Set @rl_already_prompted just once.

Write history file on unsuccessful exit, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Add readline support to empire client
Martin Haukeli [Sun, 8 Nov 2015 22:57:14 +0000 (23:57 +0100)]
client: Add readline support to empire client

Readline provides fancy command line editing such as <Arrow Up> for
previous commands and CTRL+A to jump to the beginning of the line.

This patch does not add any completion on <tab> key, a TODO, if you
will.

A new command line flag, -H, turns on saving the history to disk.
This may have security implications on shared computers, as all
commands are saved as-is.  Thus "change re 1234" would be logged
directly to the file.

Signed-off-by: Martin Haukeli <martin.haukeli@gmail.com>
Rebase on top of preparatory work, fix a few bugs, and tidy up:

* Update the standalone client build, too.

* Fix the Windows build.

* Keep command line options sorted case-insensitively.

* Error out when $HOME is unset and getpwuid() fails, just like we do
  for $LOGNAME.

* Give @input_from_rl, @has_rl_input static linkage.

* @has_rl_input is a flag, not a counter, set and test it accordingly.

* Save all input in history, not just commands.  Martin's attempt to
  recognize commands works only as long as the server sends prompts
  faster than the user sends input.  Drop that part, and update commit
  message accordingly.

* Fix recv_input() not to truncate value of strlen() to int, and to
  use memmove() for updating @input_from_rl in place.

* Clean up whitespace in a few places.

* Tweak commit message.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Remove unused ring_to_file()
Markus Armbruster [Sun, 25 Jun 2017 10:00:52 +0000 (12:00 +0200)]
client: Remove unused ring_to_file()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Delay additional input processing until after send
Markus Armbruster [Sun, 25 Jun 2017 09:13:00 +0000 (11:13 +0200)]
client: Delay additional input processing until after send

We need to copy input to @auxfp to implement command line option -2,
and pass it to save_input() to enable protection against a rogue
server exploiting redirection and execute.  We currently do this right
when input enters the ring buffer, in recv_input().

Calling save_input() before sending input to the server is sloppy: it
can make the client accept "future" redirections and executes.

Delay save_input() until after input is sent.  For simplicity, delay
copying to @auxfp as well.

This is actually pretty close to how things worked before commit
8b7d0b9 (v4.3.11).

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Inline ring_to_file() into new send_input()
Markus Armbruster [Sun, 25 Jun 2017 08:27:48 +0000 (10:27 +0200)]
client: Inline ring_to_file() into new send_input()

In preparation for the next commit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Rearrange ring_to_iovec() for clarity
Markus Armbruster [Sun, 25 Jun 2017 08:23:08 +0000 (10:23 +0200)]
client: Rearrange ring_to_iovec() for clarity

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Split ring_to_iovec() off ring_to_file()
Markus Armbruster [Sun, 25 Jun 2017 08:20:53 +0000 (10:20 +0200)]
client: Split ring_to_iovec() off ring_to_file()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Lift assignment to @input_fd to recv_output()
Markus Armbruster [Mon, 10 Apr 2017 20:22:21 +0000 (22:22 +0200)]
client: Lift assignment to @input_fd to recv_output()

On successful execute, servercmd() sets @input_fd to the batch file
descriptor.  Return the file descriptor instead, and let its caller
recv_output() set @input_fd.  This permits giving @input_fd static
linkage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Fix obscure misdetection of input EOF
Markus Armbruster [Sat, 2 Jan 2016 09:11:28 +0000 (10:11 +0100)]
client: Fix obscure misdetection of input EOF

recv_input(input_fd, &inbuf) returns zero when @inbuf is full or
@input_fd is at EOF.  We avoid the former by putting @input_fd in
@rdfd only when @inbuf has space, so we can detect EOF easily.  But we
missed the case where adding a cookie fills up @inbuf.  We
misinterpret "can't read into full buffer" as "EOF on input" then.

Fix by checking for space again.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Clear pending interrupt on stdin EOF
Markus Armbruster [Wed, 30 Dec 2015 09:21:18 +0000 (10:21 +0100)]
client: Clear pending interrupt on stdin EOF

The client can send an interrupt cookie after the EOF cookie.
Harmless, as the server throws away input after the EOF cookie.  Clean
it up anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Simplify input EOF handling
Markus Armbruster [Tue, 29 Dec 2015 18:26:58 +0000 (19:26 +0100)]
client: Simplify input EOF handling

We increment @send_eof only when read() returns zero, and we read()
only when it's zero.  Therefore, we never increment it beyond one.
Change it from counter to flag.

This effectively reverts commit 51846ec (v4.3.11).  Possible only
because the previous commit got rid of the @send_eof increment on
failed execute.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Signal interrupt instead of EOF on batch file error
Markus Armbruster [Tue, 29 Dec 2015 17:05:56 +0000 (18:05 +0100)]
client: Signal interrupt instead of EOF on batch file error

The server doesn't currently care for the difference, but interrupt is
more accurate than EOF.  The change also enables the next commit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Simplify rogue redirection and execute protection further
Markus Armbruster [Sun, 18 Jun 2017 16:57:28 +0000 (18:57 +0200)]
client: Simplify rogue redirection and execute protection further

recv_input() passes full lines to save_input().  Pass characters
instead.  Simpler, and doesn't truncate long lines.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Fix rogue execute protection
Markus Armbruster [Sun, 27 Dec 2015 19:22:45 +0000 (20:22 +0100)]
client: Fix rogue execute protection

To protect against a rogue server reading your files, the client
honors C_EXECUTE only when it matches recent player input.

This has a somewhat troubled history, detailed in the previous commit.

The remaining major issue comes from commit 8b7d0b9 (v4.3.11): any
suffix of a recent line of input is accepted as C_EXECUTE text.
Before, only text that looked like an argument of an execute command
or a redirection was accepted.

Fix by again requiring the text to be preceded by something that looks
like an execute command.  But do it more carefully: don't break
execute with a prompted for argument, and prevent abuse of
redirections for execute.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Simplify rogue redirection and execute protection
Markus Armbruster [Sun, 27 Dec 2015 17:10:13 +0000 (18:10 +0100)]
client: Simplify rogue redirection and execute protection

Redirections let the server write files and run pipelines, and execute
lets it read files.

Before 4.2.0, the client simply trusted the server.  4.2.0 added
fairly complex code to recognize redirections and execute, replace the
filenames and pipelines by tag strings, remember tag string and
replaced text, and honor redirection and execute only when their text
is a known tag string.  Tag and replaced text were freed on use.

Broken by design because the client cannot know whether a line will
actually be read as a command by the server.  Issues included:

(1) Non-command lines could be messed up.

(2) The memory used for remembering their tags was never freed.

(3) execute prompting for its argument was incorrectly rejected.

(4) A rogue server could use a tag for the wrong purpose.  For
instance, "execute fire" creates a tag for "fire", which a rogue
server could use for a pipeline to command "ire".

4.2.10 dropped the tag strings, and used the actual text as key.  This
took care of (1).

Commit 17d6997 and commit 2456a71 (both v4.3.11) tightened checking of
redirections, which took care of (4) for redirections, but not
execute.  Relatively harmless, because redirection text always starts
with '>' or '|', but filenames rarely do.

Commit 8b7d0b9 (v4.3.11) replaced the protection code wholesale.
Instead of attempting to recognize redirections and execute, we now
save everything in a ring buffer, and require redirections and execute
to match at a line end in the ring buffer.  Much simpler, takes care
of issues (2) and (3), but adds new issues:

(5) When sent-ahead input exceeds the ring buffer, good redirections
and executes get rejected.  Could be avoided by limiting send-ahead,
or remembering input until its output arrives.  However, bogus
rejections haven't been a problem in practice even with a tiny 4KiB
ring buffer.

(6) The protection against rogue execute is *much* weaker, because we
now accept any line suffix.  Before, we accepted any tag,
i.e. anything that looks like a redirection or an execute command.

(7) When we find a match in the ring buffer, we used to drop
everything up to that line right away.  This broke redirected execute
commands.  Commit 02a9af0 (v4.3.11) fixed it by delaying the drop
until the next prompt, but that's overly complicated.

This commit addresses (7): don't drop on use, simply let new input
push old input out of the ring buffer.

The next commit will address (6) and the remainder of (4).

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Improve the client's messages
Markus Armbruster [Sun, 27 Dec 2015 14:54:10 +0000 (15:54 +0100)]
client: Improve the client's messages

Use a "Warning: " prefix for server output violating the protocol and
for rogue redirections and executes.  Don't shout "WARNING!"

In redir_authorized(), check for server issues (conflicting
redirections, rogue redirections and executes) before enforcing
restrictions (restricted mode, executing batch file), so server issues
aren't masked.

Surprisingly, popen() may not set errno on failure.  Avoid reporting a
bogus errno in dopipe().

doexecute() complains about an "execute file".  We call that a "batch
file" elsewhere.  Reword for consistency.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Drop extra newlines from the client's messages
Markus Armbruster [Sun, 27 Dec 2015 14:37:06 +0000 (15:37 +0100)]
client: Drop extra newlines from the client's messages

servercmd()'s argument arg ends with a newline already.  Broken in
commit 8b7d0b9, v4.3.11.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoclient: Fix integer wrap around in ring_peek()
Markus Armbruster [Sun, 27 Dec 2015 14:32:00 +0000 (15:32 +0100)]
client: Fix integer wrap around in ring_peek()

Peeking beyond either end of the ring buffer must return EOF.  We
first compute the index, then check whether it's in range.

Unfortunately, the index computation r->prod - -n can wrap around
while r->prod is still <= RING_SIZE.  If it happens, ring_peek()
returns r->buf[(r->prod - -n) % RING_SIZE] instead of EOF.

Currently harmless, because no caller peeks out of range.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoman/empire: Trim unwanted space in synopsis
Markus Armbruster [Sun, 13 Dec 2015 08:18:54 +0000 (09:18 +0100)]
man/empire: Trim unwanted space in synopsis

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agodoc/contributing: Fix git format-patch topic branch example
Markus Armbruster [Sun, 13 Dec 2015 07:27:26 +0000 (08:27 +0100)]
doc/contributing: Fix git format-patch topic branch example

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agotravis: Enable OS X
Markus Armbruster [Sun, 29 Nov 2015 13:53:40 +0000 (14:53 +0100)]
travis: Enable OS X

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agonavigate march: Fix abort not to wipe out concurrent updates
Markus Armbruster [Sun, 29 Nov 2015 10:30:45 +0000 (11:30 +0100)]
navigate march: Fix abort not to wipe out concurrent updates

When the player aborts the command at the movement prompt, we write
back stale ships or land units, triggering a generation oops.  Any
updates made by other threads meanwhile are wiped out, triggering a
seqno mismatch oops.

Broken in commit 24000b4, v4.3.33.  Fix by restoring the lost
shp_nav_stay_behind() and lnd_mar_stay_behind() calls.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agotests/navi-march: Cover abort at movement prompt
Markus Armbruster [Sun, 29 Nov 2015 09:53:14 +0000 (10:53 +0100)]
tests/navi-march: Cover abort at movement prompt

This exposes generation oopses.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agomarch: Fix concurrent updates at sector abandon prompt
Markus Armbruster [Sun, 29 Nov 2015 09:37:40 +0000 (10:37 +0100)]
march: Fix concurrent updates at sector abandon prompt

When the player declines to abandon a sector, we write back stale land
units, triggering a generation oops.  Any updates made by other
threads meanwhile are wiped out, triggering a seqno mismatch oops.

The culprit is lnd_abandon_askyn(): when the player declines, it
returns without calling check_sect_ok(), check_land_ok().  Broken in
commit 7c1b166, v4.3.33.  Fix it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agorecvclient: Track potential yield on input
Markus Armbruster [Sun, 29 Nov 2015 09:20:52 +0000 (10:20 +0100)]
recvclient: Track potential yield on input

recvclient() calls ef_make_stale() only when it does actual I/O, via
io_output() and io_input().  Missed in commit 2fa5f652, v4.3.24.  Call
it directly when it doesn't do actual I/O.

This makes navi-march-test expose a bug in march: when the player
declines to abandon a sector, we write back stale land units,
triggering a generation oops.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoconfigure: Use -fstack-protector-strong when available
Markus Armbruster [Sun, 22 Nov 2015 09:38:24 +0000 (10:38 +0100)]
configure: Use -fstack-protector-strong when available

Testing whether the compiler supports it is a bit tricky.

The obvious AX_APPEND_COMPILE_FLAGS([-fstack-protector-strong])
doesn't suffice, since some ports of the GNU toolchain reportedly pass
this test, then fail to link.  That's because the compiler accepts the
flag, duly emits references to helper code in libc, but libc doesn't
provide, and linking fails.

Instead, use AX_APPEND_LINK_FLAGS with an input source that makes the
compiler emit the extra stack checking code.  This requires the latest
version from the autoconf-archive, so update m4/ax* to commit e3d948b.
Also update m4/my_append_compile_flags.m4 to keep it in sync with
upstream's ax_append_compile_flags.m4.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoscripts/savecore: Report nicely when there's no core dump
Markus Armbruster [Sun, 15 Nov 2015 07:40:36 +0000 (08:40 +0100)]
scripts/savecore: Report nicely when there's no core dump

When savecore can't find a core dump, it reports something like

    ls: cannot access core.*: No such file or directory

to stderr, and fails.  If privlog is set, it also mails out a "Could
not save core dump" note.

Suppress the error message, and mail out "Could not find core dump to
save" instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoconfigure: Use -fno-strict-aliasing -fno-strict-overflow
Markus Armbruster [Sun, 18 Oct 2015 15:48:15 +0000 (17:48 +0200)]
configure: Use -fno-strict-aliasing -fno-strict-overflow

Contemporary compilers can squeeze out some extra performance by
assuming the program never executes code that has undefined behavior
according to the C standard.  Unfortunately, this can break programs.
Pointing out that these programs are non-conforming is as correct as
it is unhelpful, at least as long as the compiler is unable to
diagnose the non-conformingness.

Since keeping our programs working is a lot more important to us than
running them as fast as possible, forbid some assumptions that are
known to break real-world programs:

* Aliasing: perfectly clean programs don't engage in type-punning, and
  perfectly conforming programs do it only in full accordance with the
  standard's (subtle!) aliasing rules.  Neither kind of perfection is
  realistic for us, therefore -fno-strict-aliasing.

* Signed integer overflow: perfectly clean programs won't ever do
  signed integer arithmetic that overflows.  This is an imperfect
  program, therefore -fno-strict-overflow.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agotests: Enable GNU libc memory allocation error checking
Markus Armbruster [Sun, 27 Sep 2015 07:56:21 +0000 (09:56 +0200)]
tests: Enable GNU libc memory allocation error checking

MALLOC_CHECK_=3 makes glibc check for memory allocation programming
errors.  It's the factory default, but set it anyway just in case
someone disabled it for speed.

Non-zero MALLOC_PERTURB_ makes glibc wipe memory value on allocation
and deallocation.  The actual value determines the bit pattern.  Set
it to the value of environment variable EMPIRE_CHECK_MALLOC_PERTURB or
else a pseudo-random number, and record it in sandbox/malloc-perturb.

See mallopt(3) for more information.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agonavigate march: Plug memory leaks
Markus Armbruster [Sun, 20 Sep 2015 13:24:22 +0000 (15:24 +0200)]
navigate march: Plug memory leaks

When the player aborts the command at the movement prompt, or declines
to abandon a sector, unit_move() returns without freeing the list.
Found with valgrind.  Broken in commit 24000b4 and commit 7c1b166,
both v4.3.33.

Free the list on these returns, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agonavigate march retreat lretreat: Fix read beyond buffer
Markus Armbruster [Sun, 20 Sep 2015 11:17:33 +0000 (13:17 +0200)]
navigate march retreat lretreat: Fix read beyond buffer

shp_nav_gauntlet() and lnd_mar_gauntlet() read beyond the list head
when the list is empty.  The values read aren't used then.  Could
conceivably crash the server anyway, but it's unlikely.

Empty list happens when shp_nav_dir(), lnd_mar_dir() empty the list
and return zero.  Broken in commit beedf8d, v4.3.33.  Occurs in
navi-march-test (since the last commit) and in retreat-test.

Change shp_nav_dir() and lnd_mar_dir() to return one then.  For
additional safety, make shp_nav_gauntlet() and lnd_mar_gauntlet() oops
on empty list and recover safely.

I think I originally found this bug with -fsanitize, but I've since
upgraded, and I can't diagnose it that way anymore.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agotests/navi-march: Cover running out of mobility completely
Markus Armbruster [Sun, 20 Sep 2015 10:30:33 +0000 (12:30 +0200)]
tests/navi-march: Cover running out of mobility completely

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agobomb drop fly paradrop recon sweep: Fix read before array
Markus Armbruster [Sun, 26 Jul 2015 18:28:34 +0000 (20:28 +0200)]
bomb drop fly paradrop recon sweep: Fix read before array

The code computing the length of the flight path checks whether the
path ends with 'h'.  When getpath() returns an empty path, it accesses
flightpath[-1].  This could set the length to -1 (unlikely), or crash
(even less likely).  The former could be abused to gain mobility for
sufficiently inefficient or short-ranged planes.  Found with valgrind.

Broken in commit 404a76f7, v4.3.27.

Historically, getpath() could return paths with or without 'h', and
the check was necessary.  It returned an empty path only when the
player gave no input, aborting the command.  When the player entered
the assembly point's coordinates, it returned "h".

Commit 404a76f7 accidentally changed it to return "" then.  Also broke
flying to the assembly point's coordinates.  Commit 0f1e14f (v4.3.31)
fixed that part by changing getpath()'s contract: always return paths
without 'h' ("" simply means empty path), and return NULL on invalid
input, including no input.

The flawed check is superfluous since then.  Drop it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoAvoid shifting into sign bit
Markus Armbruster [Sun, 26 Jul 2015 16:00:27 +0000 (18:00 +0200)]
Avoid shifting into sign bit

It's undefined behavior.  Found with gcc -fsanitize=undefined.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoConvert run-time to build-time assertion
Markus Armbruster [Sat, 4 Jul 2015 14:19:16 +0000 (16:19 +0200)]
Convert run-time to build-time assertion

There's just one, in show_product().

Use new BUILD_ASSERT() there, because its contract is even simpler
than BUILD_ASSERT_ONE()'s.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoProvide proper build-time assertions for NSC_SITYPE()
Markus Armbruster [Sat, 4 Jul 2015 12:53:20 +0000 (14:53 +0200)]
Provide proper build-time assertions for NSC_SITYPE()

We want to cause a diagnostic when NSC_SITYPE()'s argument isn't
implemented.  Commit aa6ad9d's solution is to have the macro expand
into 1/0 then.  Works with GCC, but Clang always warns "division by
zero is undefined".

The better, portable way to conditionally break the build is an array
type with a size that's negative when the build should fail, else
positive.  Implement that wrapped in a sizeof() to make it an
expression as macro BUILD_ASSERT_ONE(), and use it in NSC_SITYPE().

No more warnings from Clang 3.5.0.  GCC still produces its "may be
used uninitialized" false positives.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agosubs: Don't squash telegrams together when time goes backwards
Markus Armbruster [Sat, 4 Jul 2015 12:31:28 +0000 (14:31 +0200)]
subs: Don't squash telegrams together when time goes backwards

We've always squashed them when the time difference is smaller than
TEL_SECONDS, regardless of sign.  This involves passing the difference
to abs(), implicitly casting from time_t to int, which triggers a
Clang warning.

I could clean this up to get rid of the warning, but time should never
go backwards, and trying to make things prettier when it does isn't
worthwhile.  Simply drop the abs().

While there, drop the function comment.  It's been inaccurate since
Empire 3 dropped mail.c, and bogus since commit 17223e8 (v4.3.29)
added tel_cont.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Nuke-types: Document show columns avail, res, abilities
Markus Armbruster [Thu, 2 Jul 2015 07:40:34 +0000 (09:40 +0200)]
info/Nuke-types: Document show columns avail, res, abilities

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Unit-types: Belatedly remove capability xlight
Markus Armbruster [Thu, 2 Jul 2015 07:19:48 +0000 (09:19 +0200)]
info/Unit-types: Belatedly remove capability xlight

L_XLIGHT was replaced in commit e28c14f, v4.3.0.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Plane-types: Belatedly remove stealth and half-stealth
Markus Armbruster [Thu, 2 Jul 2015 07:17:29 +0000 (09:17 +0200)]
info/Plane-types: Belatedly remove stealth and half-stealth

P_X and P_H were removed in commit 61233e4, v4.3.23.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Ship-types: Belatedly remove capability spy
Markus Armbruster [Thu, 2 Jul 2015 07:14:14 +0000 (09:14 +0200)]
info/Ship-types: Belatedly remove capability spy

M_SPY was removed in commit 498d9fb, v4.3.0.  It never did anything.

Reported-by: Harald Katzer
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo: Belatedly update for change of stop prefix to '!'
Markus Armbruster [Thu, 25 Jun 2015 05:19:55 +0000 (07:19 +0200)]
info: Belatedly update for change of stop prefix to '!'

Commit eb1512d (v4.3.6) added the '=' if stopped before efficiency.
Commit 016249c (v4.3.6) changed it to '!' without updating info ship,
plane, land, nuke.

Reported-by: Harald Katzer
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/version: Update example to current output
Markus Armbruster [Sun, 21 Jun 2015 07:10:33 +0000 (09:10 +0200)]
info/version: Update example to current output

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo: Fix option NOMOBCOST misinformation
Markus Armbruster [Sun, 21 Jun 2015 06:59:01 +0000 (08:59 +0200)]
info: Fix option NOMOBCOST misinformation

The cost of firing naval guns is 15 mobility with option NOMOBCOST
disabled.  Mobility.t is correct.

Fix Options.t not to claim submarines pay half the sector movement
cost when NOMOBCOST is enabled.

Fix fire.t not to claim ships pay half the sector movement cost when
NOMOBCOST is disabled.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Options: Nicer markup, more consistent format
Markus Armbruster [Sun, 21 Jun 2015 06:32:47 +0000 (08:32 +0200)]
info/Options: Nicer markup, more consistent format

Don't list options separately for major server versions.  It's only of
historical interest, which "info History" satisfies.

Make it a list (.L) instead of preformatted text (.nf).

Fix up so the option explanations are full sentences, starting with a
capital letter and ending with a period.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Options: Belatedly remove SAIL
Markus Armbruster [Sun, 21 Jun 2015 06:05:24 +0000 (08:05 +0200)]
info/Options: Belatedly remove SAIL

Missed in commit dc73207.

Reported-by: Harald Katzer
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agolwp: Rename LwpSigCatched to LwpSigCaught
Markus Armbruster [Sun, 14 Jun 2015 09:44:19 +0000 (11:44 +0200)]
lwp: Rename LwpSigCatched to LwpSigCaught

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agodocs/coding: Explain function/struct/union comment conventions
Markus Armbruster [Sun, 14 Jun 2015 09:39:07 +0000 (11:39 +0200)]
docs/coding: Explain function/struct/union comment conventions

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoFix and clean up some comments
Markus Armbruster [Sun, 14 Jun 2015 09:36:40 +0000 (11:36 +0200)]
Fix and clean up some comments

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoChange comment style to use @foo rather than FOO
Markus Armbruster [Sun, 14 Jun 2015 08:33:43 +0000 (10:33 +0200)]
Change comment style to use @foo rather than FOO

... when referring to a function's parameter or a struct/union's
member.

The idea of using FOO comes from the GNU coding standards:

    The comment on a function is much clearer if you use the argument
    names to speak about the argument values.  The variable name
    itself should be lower case, but write it in upper case when you
    are speaking about the value rather than the variable itself.
    Thus, "the inode number NODE_NUM" rather than "an inode".

Upcasing names is problematic for a case-sensitive language like C,
because it can create ambiguity.  Moreover, it's too much shouting for
my taste.

GTK-Doc's convention to prefix the identifier with @ makes references
to variables stand out nicely.  The rest of the GTK-Doc conventions
make no sense for us, however.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoconfigure: Suppress Clang warning on carg()
Markus Armbruster [Sat, 6 Jun 2015 17:44:46 +0000 (19:44 +0200)]
configure: Suppress Clang warning on carg()

Renaming carg() would be smarter, but I'd rather do that as part of a
consistent renaming of all command functions, and I'm not up to that
right now.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoconfigure: Enable -Wformat-security
Markus Armbruster [Sat, 6 Jun 2015 16:09:02 +0000 (18:09 +0200)]
configure: Enable -Wformat-security

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agopr: Make prdate() more obviously correct
Markus Armbruster [Sat, 6 Jun 2015 16:01:42 +0000 (18:01 +0200)]
pr: Make prdate() more obviously correct

Using ctime() as pr()'s first argument is safe, because its value
never contains '%'.  Clean it up anyway, so we can enable
-Wformat-security.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoconfigure: Enable more gcc warnings
Markus Armbruster [Sat, 6 Jun 2015 15:46:56 +0000 (17:46 +0200)]
configure: Enable more gcc warnings

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoconfigure: Test compiler flags
Markus Armbruster [Sat, 6 Jun 2015 13:53:00 +0000 (15:53 +0200)]
configure: Test compiler flags

When AC_PROG_CC detects GCC, Make.mk adds a bunch of flags to CFLAGS.
Works only for flags that any version of gcc in use accepts.

Instead, make configure add the flags that actually work to CFLAGS.
This will let us add flags that work only for some compilers.

The new autoconf macros are from autoconf-archive v2015.02.24.

Unfortunately, AX_APPEND_COMPILE_FLAGS doesn't work reliably for
-Wno-*: gcc complains about unknown -Wno-foo only when other
diagnostics are being produced.  Test -Wfoo instead of -Wno-foo, and
rename to MY_APPEND_COMPILE_FLAGS.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoconfigure: Drop unused AC_C_CHAR_UNSIGNED test
Markus Armbruster [Sat, 6 Jun 2015 12:37:39 +0000 (14:37 +0200)]
configure: Drop unused AC_C_CHAR_UNSIGNED test

Unused since commit 0c8c169. v4.3.3.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoBump version to 4.3.34
Markus Armbruster [Thu, 4 Jun 2015 08:52:11 +0000 (10:52 +0200)]
Bump version to 4.3.34

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoUpdate change log timestamp for 4.3.33 v4.3.33
Markus Armbruster [Wed, 20 May 2015 18:20:40 +0000 (20:20 +0200)]
Update change log timestamp for 4.3.33

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoRevert "commands: Always put ship or land unit before retreating it"
Markus Armbruster [Sun, 17 May 2015 16:11:20 +0000 (18:11 +0200)]
Revert "commands: Always put ship or land unit before retreating it"

This reverts commit f4d8d64bb34dee75cb2485c130e125fdd3980c18.

Breaks retreat after ship got sunk by bombs or missile.

ship_bomb() and launch_missile() pass .shp_own to retreat_ship().
Wrong after putship(), because putship() resets the owner when the
ship got sunk.  retreat_ship() then oopses and fails to retreat the
surviving members of the group.

Other callers save the owner before putting the ship, and pass that.
We could change these two to do the same.  But since we're trying to
get a release out, simply revert the broken commit instead.

8 years agoTidy up some comments
Markus Armbruster [Sun, 17 May 2015 16:08:45 +0000 (18:08 +0200)]
Tidy up some comments

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoUpdate change log again for 4.3.33
Markus Armbruster [Thu, 14 May 2015 07:46:13 +0000 (09:46 +0200)]
Update change log again for 4.3.33

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoImprove portability to really outmoded compilers
Markus Armbruster [Thu, 14 May 2015 07:27:05 +0000 (09:27 +0200)]
Improve portability to really outmoded compilers

A few modernisms have crept in:

* Trailing comma in enum definition (commit 71320ed, v4.3.10)

* // comment (commit 265e71e, v4.3.11)

* <stdint.h> (commit 9102ecc, v4.3.31)

  MSC actually chokes on this one.

Avoid them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoxundump: Pass unsigned * for scanf directive %3o, not int *
Markus Armbruster [Thu, 14 May 2015 07:03:27 +0000 (09:03 +0200)]
xundump: Pass unsigned * for scanf directive %3o, not int *

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agordsched: Pass unsigned * for scanf directive %u, not int *
Markus Armbruster [Thu, 14 May 2015 06:57:52 +0000 (08:57 +0200)]
rdsched: Pass unsigned * for scanf directive %u, not int *

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/History: Cover removal of Autonav, SAIL and TREATIES
Markus Armbruster [Sun, 5 Apr 2015 09:53:07 +0000 (11:53 +0200)]
info/History: Cover removal of Autonav, SAIL and TREATIES

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agow32/strptime: Fix for 64 bit pointers
Markus Armbruster [Sun, 5 Apr 2015 07:45:11 +0000 (09:45 +0200)]
w32/strptime: Fix for 64 bit pointers

The __UNCONST() stolen from NetBSD assumes unsigned long can hold a
pointer.  Not true with Win64's LLP64 data model.  There, we cast the
64 bit pointer to 32 bits and back.  Works only because Windows puts
the stack at a very low address, and the casts don't actually change
the pointer.

Dumb it down to a straight cast to void * for safety.

Thanks to Harald Katzer and Ron Koenderink for their help figuring out
the bug's impact.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoUpdate change log again for 4.3.33
Markus Armbruster [Fri, 13 Mar 2015 06:07:03 +0000 (07:07 +0100)]
Update change log again for 4.3.33

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoINSTALL: Refresh from automake 1.13
Markus Armbruster [Sun, 8 Mar 2015 17:23:33 +0000 (18:23 +0100)]
INSTALL: Refresh from automake 1.13

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoman: Get rid of unwanted space in SYNOPSIS
Markus Armbruster [Sun, 8 Mar 2015 16:48:17 +0000 (17:48 +0100)]
man: Get rid of unwanted space in SYNOPSIS

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoclient: New option -r for restricted mode
Marisa Giancarla [Sat, 7 Dec 2013 15:43:13 +0000 (16:43 +0100)]
client: New option -r for restricted mode

Redirections and the execute command let the user read and write files
and run programs on the local system.

Restricted mode prevents such access.  This is useful when you want to
grant somebody access to just Empire, but not to the host system's
user account that runs the client.

Signed-off-by: Marisa Giancarla <fstltna@me.com>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotorpedo mission: Print rounded, not truncated hit chance
Markus Armbruster [Sun, 8 Mar 2015 13:58:04 +0000 (14:58 +0100)]
torpedo mission: Print rounded, not truncated hit chance

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agobuild: Fix inexact calculation of required materials
Markus Armbruster [Sun, 8 Mar 2015 13:06:02 +0000 (14:06 +0100)]
build: Fix inexact calculation of required materials

sector_can_build() computes mat[i] * (effic / 100.0).  The division is
inexact.  The result gets randomly rounded, so errors are vanishingly
unlikely to screw up material consumption.

However, we require the amount rounded up to be present since commit
1227d2c.  Errors *can* screw that up.  Fix by avoiding inexact
computation for that part.

We should probably review rounding of inexact values in general.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests/README: Cover info.ps and document .NA use for commands
Markus Armbruster [Sun, 8 Mar 2015 11:44:02 +0000 (12:44 +0100)]
tests/README: Cover info.ps and document .NA use for commands

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests/README: Update for replacement of info/checklist.pl
Markus Armbruster [Sun, 8 Mar 2015 11:42:00 +0000 (12:42 +0100)]
tests/README: Update for replacement of info/checklist.pl

Replaced by tests/info-test in commit 90eaf9d.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agobuild-aux: Refresh from automake 1.13
Markus Armbruster [Thu, 5 Mar 2015 20:23:46 +0000 (21:23 +0100)]
build-aux: Refresh from automake 1.13

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agom4: Refresh from autoconf-archive v2015.02.24
Markus Armbruster [Wed, 4 Mar 2015 19:07:00 +0000 (20:07 +0100)]
m4: Refresh from autoconf-archive v2015.02.24

commit dd946914edb9da25e2d8c8b2186fab5d8103f3d4
Author: Daniel Richard G <skunk@iSKUNK.ORG>
Date:   Thu Oct 3 18:56:24 2013 +0200

    AX_PTHREAD: add support for Clang

    Further details can be found at <http://savannah.gnu.org/patch/?8186>.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: Rewrite the previous commit's sed_i helper
Markus Armbruster [Wed, 4 Mar 2015 07:15:13 +0000 (08:15 +0100)]
tests: Rewrite the previous commit's sed_i helper

Last night's version looks unnecessarily ugly in the morning.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: Avoid non-portable sed -i
Markus Armbruster [Tue, 3 Mar 2015 19:45:03 +0000 (20:45 +0100)]
tests: Avoid non-portable sed -i

Crept in in commit 7c3186f.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: Fix for builds outside git-controlled source tree
Markus Armbruster [Tue, 3 Mar 2015 19:09:50 +0000 (20:09 +0100)]
tests: Fix for builds outside git-controlled source tree

We run "git ls-files" in the build tree.  Doesn't work when the source
directory isn't a git repository, or the build directory is outside
the source directory.  Broken in commit 71cb2d8.

Find source files like Make.mk does: if the source tree is a git
repository, use git ls-files, else use sources.mk.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoBelatedly bump version to 4.3.33
Markus Armbruster [Mon, 2 Mar 2015 20:16:27 +0000 (21:16 +0100)]
Belatedly bump version to 4.3.33

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agobridgefall: Clean up literal 20 to SCT_MINEFF
Markus Armbruster [Sun, 1 Mar 2015 17:02:14 +0000 (18:02 +0100)]
bridgefall: Clean up literal 20 to SCT_MINEFF

Messed up in commit 4824648.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoUpdate change log for 4.3.33
Markus Armbruster [Sun, 1 Mar 2015 10:14:00 +0000 (11:14 +0100)]
Update change log for 4.3.33

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoadd: Drop syntax deprecated in 4.3.29
Markus Armbruster [Sun, 1 Mar 2015 09:02:25 +0000 (10:02 +0100)]
add: Drop syntax deprecated in 4.3.29

Deprecated in commit 373f20a: argument "new".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosubs/move: Drop syntax deprecated in 4.3.27
Markus Armbruster [Sun, 1 Mar 2015 08:58:55 +0000 (09:58 +0100)]
subs/move: Drop syntax deprecated in 4.3.27

Deprecated in commit 28d4847: no space between 'm' and its first
argument.  Affects explore, move, test, transport.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agomaps: Drop bmap flags syntax deprecated in 4.3.27
Markus Armbruster [Sun, 1 Mar 2015 08:47:19 +0000 (09:47 +0100)]
maps: Drop bmap flags syntax deprecated in 4.3.27

Deprecated in commit a00f9e2: 'r' with flags, and bad flags after 't'.
Affects flags argument of bmap, sbmap, pbmap, lbmap, nbmap, and
navigate and march sub-command 'B'.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoinfo/fire: Drop misinformation on damage varying with gun size
Markus Armbruster [Sun, 22 Feb 2015 09:55:40 +0000 (10:55 +0100)]
info/fire: Drop misinformation on damage varying with gun size

Goes all the way back to Empire 1, and as far as I can tell was
misleading there already.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoinfo/fire info/torpedo: Purge references to option MULTIFIRE
Markus Armbruster [Sun, 22 Feb 2015 09:49:58 +0000 (10:49 +0100)]
info/fire info/torpedo: Purge references to option MULTIFIRE

MULTIFIRE became non-optional in Chainsaw 3, more than two decades
ago.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoemp_config: Don't monkey-patch WORLD_X to be even
Markus Armbruster [Sun, 22 Feb 2015 07:04:41 +0000 (08:04 +0100)]
emp_config: Don't monkey-patch WORLD_X to be even

emp_config() silently truncates WORLD_X to even.  Drop that.  We could
flag odd WORLD_X as error, but we don't validate the other
configuration values, so why this one?  Instead document it needs to
be even.  WORLD_Y, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoef_verify: Polish product error message
Markus Armbruster [Sat, 21 Feb 2015 18:07:44 +0000 (19:07 +0100)]
ef_verify: Polish product error message

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoinit ef_verify: Don't monkey-patch capability VTOL, require it
Markus Armbruster [Sat, 21 Feb 2015 17:56:32 +0000 (18:56 +0100)]
init ef_verify: Don't monkey-patch capability VTOL, require it

A plane with capability missile must have capability VTOL.  When it's
missing, global_init() silently adds it.

Drop that.  Check for it in ef_verify_config() instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoinit ef_verify: Don't monkey-patch capability miss, require it
Markus Armbruster [Sat, 21 Feb 2015 17:19:39 +0000 (18:19 +0100)]
init ef_verify: Don't monkey-patch capability miss, require it

A ship with non-zero nplanes must have capability plane or miss.  When
one doesn't, global_init() silently adds capability miss.

Drop that.  Check for it in ef_verify_config() instead.  Fix up
ship.config accordingly.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoef_verify: Require ship glim != 0 with capability dchrg
Markus Armbruster [Sat, 21 Feb 2015 17:12:07 +0000 (18:12 +0100)]
ef_verify: Require ship glim != 0 with capability dchrg

Because the fire command doesn't work with zero glim (commit a109de9).

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotorpedo: Suppress bulletin when player torpedoes his own ship
Markus Armbruster [Sun, 15 Feb 2015 14:22:01 +0000 (15:22 +0100)]
torpedo: Suppress bulletin when player torpedoes his own ship

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotorpedo: Print "Starting our attack run" regardless of target
Markus Armbruster [Sun, 15 Feb 2015 14:06:14 +0000 (15:06 +0100)]
torpedo: Print "Starting our attack run" regardless of target

Instead of printing it only when the target owned by somebody else.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotorpedo: Let torpedo hit land only when target is in range
Markus Armbruster [Sun, 15 Feb 2015 13:25:39 +0000 (14:25 +0100)]
torpedo: Let torpedo hit land only when target is in range

Telling the player his torpedo "slams into land" can give a clue on
the direction to the target.  No good when the target is out of range,
because we shouldn't tell the player more than that then.

Screwed up in 4.2.2.  Fix by checking range before line of sight.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoinfo/torpedo: Fix misinformation on submarine identification
Markus Armbruster [Sun, 15 Feb 2015 08:57:13 +0000 (09:57 +0100)]
info/torpedo: Fix misinformation on submarine identification

Claims the victim of a torpedo attack gets told the attacking ship's
number.  This hasn't been the case for submarines since Empire 2.3.
Recent commits again reveal the attacking submarine's number, but only
when it gets hit by return fire.  Update info accordingly.

Reported-by: Neeraj Jain <thisisfranz@gmail.com>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>