empserver
9 years agoUpdate change log again for 4.3.32 v4.3.32
Markus Armbruster [Sun, 25 Aug 2013 07:56:58 +0000 (09:56 +0200)]
Update change log again for 4.3.32

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoactofgod: Simplify fmtflags()'s error checking
Markus Armbruster [Sun, 25 Aug 2013 07:51:39 +0000 (09:51 +0200)]
actofgod: Simplify fmtflags()'s error checking

Permit finding length by passing no buffer.  Not currently used.

Oops at most once.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoserver: Grow small thread stacks from 50 KiB to 64 KiB
Markus Armbruster [Sat, 17 Aug 2013 15:57:40 +0000 (17:57 +0200)]
server: Grow small thread stacks from 50 KiB to 64 KiB

Affected are threads AcceptPlayers, MarketUpdate, shutdownSeq.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agolwp: Increase EventHandler's stack size from 16 KiB to 64 KiB
Markus Armbruster [Sat, 17 Aug 2013 14:34:26 +0000 (16:34 +0200)]
lwp: Increase EventHandler's stack size from 16 KiB to 64 KiB

Stack overflow observed on IBM Power 730 Express running AIX 7.1.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosrc/client/Makefile.in: Avoid :=, it breaks traditional make
Markus Armbruster [Sat, 17 Aug 2013 14:13:09 +0000 (16:13 +0200)]
src/client/Makefile.in: Avoid :=, it breaks traditional make

Broken in commit c4ffd0a, v4.3.0.  Observed on AIX 7.1.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoconfigure: Fix check for term.h to include curses.h first
Markus Armbruster [Sat, 17 Aug 2013 14:05:37 +0000 (16:05 +0200)]
configure: Fix check for term.h to include curses.h first

Traditional curses needs this.  Observed on AIX 7.1.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoUpdate change log for 4.3.32
Markus Armbruster [Sun, 11 Aug 2013 12:25:33 +0000 (14:25 +0200)]
Update change log for 4.3.32

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoaccept: Drop outdated FIXME SO_KEEPALIVE
Markus Armbruster [Sun, 11 Aug 2013 11:53:52 +0000 (13:53 +0200)]
accept: Drop outdated FIXME SO_KEEPALIVE

SO_KEEPALIVE isn't useless with long idle timeouts.  Before v4.3.30's
idle timeout changes, such long timeouts had serious drawbacks (easy
denial of service), but they're just fine since then.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agodoc/clients-howto: Document use of bell character
Markus Armbruster [Sun, 11 Aug 2013 11:52:29 +0000 (13:52 +0200)]
doc/clients-howto: Document use of bell character

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosupply: Fix harmless bug in supply from ship in same sector
Markus Armbruster [Sat, 17 Aug 2013 15:57:23 +0000 (17:57 +0200)]
supply: Fix harmless bug in supply from ship in same sector

Bug bites when a ship supplies the sector it's in.  First the sector
is charged zero mob for moving the stuff, and is written back.  Next,
the sector receives the stuff, and is written back, clobbering the
first write (no effect), and triggering a seqno oops.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agofairland: Fix usage information to include -v
Markus Armbruster [Sun, 9 Jun 2013 15:20:37 +0000 (17:20 +0200)]
fairland: Fix usage information to include -v

Forgotten in commit 68a7ae7, v4.3.0.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agofairland.6: Belatedly drop reference to ore
Markus Armbruster [Mon, 3 Jun 2013 04:39:32 +0000 (06:39 +0200)]
fairland.6: Belatedly drop reference to ore

Missed in commit e3eadcd8, v4.2.14.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agodoc/xdump: Fix grammar nit
Markus Armbruster [Mon, 3 Jun 2013 04:36:58 +0000 (06:36 +0200)]
doc/xdump: Fix grammar nit

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests/actofgod: Disable in "make check" unless LWP
Markus Armbruster [Mon, 3 Jun 2013 04:26:35 +0000 (06:26 +0200)]
tests/actofgod: Disable in "make check" unless LWP

Expected to work only with thread package LWP, just like the smoke
test.  Commit 7a91041 carelessly enabled it for all thread packages.
Revert, except with LWP.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agobuild: Factor out pick_unused_unit_uid()
Markus Armbruster [Mon, 20 May 2013 15:43:11 +0000 (17:43 +0200)]
build: Factor out pick_unused_unit_uid()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Trim trailing tab in output
Markus Armbruster [Sun, 2 Jun 2013 09:37:03 +0000 (11:37 +0200)]
edit: Trim trailing tab in output

print_plane() ends its output with '\t' instead of '\n'.  Next is a
prompt, which supplies the missing newline (see pr_id()).

Ugly, clean up.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoinfo/edit info/give: Add see also swapsector
Markus Armbruster [Fri, 29 Mar 2013 20:36:37 +0000 (21:36 +0100)]
info/edit info/give: Add see also swapsector

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agobreak: Honor new designation of sanctuaries
Markus Armbruster [Fri, 3 May 2013 07:02:58 +0000 (09:02 +0200)]
break: Honor new designation of sanctuaries

Breaking sanctuary turns 100% sanctuaries into capitals, all others
into highways.  Before Empire 3, sanctuaries always became capitals.

Give deities more control over initial state of countries than
choosing between 100% capital and <100% highway sectors: turn
sanctuaries into their new designation on break.  Except make a
capital when the new designation is sanctuary (which it normally is).

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosetsector setresource: Mark as obsolete
Markus Armbruster [Fri, 29 Mar 2013 20:35:00 +0000 (21:35 +0100)]
setsector setresource: Mark as obsolete

"info setsector" claims you "can change anything that appears in dump
or peek (I think)", which has always been wrong.

edit is much more complete.  However, edit used to be more limited in
that it could change only one sector.  For mass-changes, you had to
use setsector and setresource.  Since that limitation is gone, there's
no real use left for setsector and setresource.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Generalize edit to multiple objects
Markus Armbruster [Fri, 29 Mar 2013 18:34:12 +0000 (19:34 +0100)]
edit: Generalize edit to multiple objects

Accept general <SECTS|SHIPS|PLANES|LANDS|NATS> argument instead of
just <SECT|SHIP|PLANE|LAND|NAT>.

edit with <KEY> <VALUE>... arguments applies the arguments to all
selected objects.  Without such arguments, edit lets you edit the
selected objects interactively one after the other.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: De-duplicate code in edit()'s main switch
Markus Armbruster [Fri, 29 Mar 2013 17:58:13 +0000 (18:58 +0100)]
edit: De-duplicate code in edit()'s main switch

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Detect concurrent updates during interactive nation edit
Markus Armbruster [Fri, 29 Mar 2013 17:19:40 +0000 (18:19 +0100)]
edit: Detect concurrent updates during interactive nation edit

Unlike other edits, editing a country modifies the object in-place.
It has to, because editing may send bulletins, which updates nat_tgms,
and writing back a copy would clobber these updates, triggering a
seqno mismatch oops.

However, the in-place editing neglects to detect concurrent updates.
Fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Move write-back from edit_nat() to edit(), check for errors
Markus Armbruster [Fri, 29 Mar 2013 16:41:11 +0000 (17:41 +0100)]
edit: Move write-back from edit_nat() to edit(), check for errors

This is how edit() works for everything else.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Clean up a few assignments within conditionals
Markus Armbruster [Fri, 29 Mar 2013 16:35:50 +0000 (17:35 +0100)]
edit: Clean up a few assignments within conditionals

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Make uninmplemented edit n fail instead of doing nothing
Markus Armbruster [Sun, 3 Mar 2013 16:37:32 +0000 (17:37 +0100)]
edit: Make uninmplemented edit n fail instead of doing nothing

Doing nothing is in the way.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Use empobj_storage
Markus Armbruster [Sun, 3 Mar 2013 16:24:34 +0000 (17:24 +0100)]
edit: Use empobj_storage

In preparation of some refactoring.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Don't reprint edited object when done with it
Markus Armbruster [Sun, 3 Mar 2013 06:12:07 +0000 (07:12 +0100)]
edit: Don't reprint edited object when done with it

Interactive edit prints the edited object, then reads player input.
If it gets key and value, it applies them to the object, and repeats.
If it gets nothing, it prints the edited object again, and stops.

Remove this last print, because it's not really useful.  The object is
commonly the same after reading input as before.  Except when a nation
gets updated while "edit c" is waiting for input: then the second
print actually reflects the updates.  Has always been that way.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Add remaining missing nation change reporting
Markus Armbruster [Sun, 3 Feb 2013 17:11:53 +0000 (18:11 +0100)]
edit: Add remaining missing nation change reporting

Print a message describing the actual change for keys 't' (nat_tgms)
and 's' (nat_status).  The message is necessary to give the deity a
chance to catch unexpected changes, e.g. a player reading telegrams
just before the deity edits nat_tgms.

Send a bulletin to the country for key 's'.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Improve remaining existing nation change reporting
Markus Armbruster [Sun, 3 Feb 2013 17:11:27 +0000 (18:11 +0100)]
edit: Improve remaining existing nation change reporting

Print "FOO of CNAME (#CNUM)" instead of just "FOO".  Print "unchanged"
instead of "changed from X to X" on no-op.

Send a bulletin to the country and report news when appropriate.

Affected keys:

        key   struct member   before  after   notes
        -------------------------------------------
         n    nat_cnam        --      BN         1
         r    nat_pnam        --      B-         2
         b    nat_btu         --      BN         3
         m    nat_reserve     BN      BN
         c    nat_xcap,ycap   --      B-
         o    nat_xorg,yorg   --      B-
         u    nat_timeused    --      BN
         M    nat_money       B-      BN

Notes:

1. Reports N_NAME_CHNG rather than N_AIDS/N_HURTS.

2. Message improved to accurately reflect string truncation.

3. Greengrocers' apostrophe in message fixed.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Improve tech, research, edu, happiness change reporting
Markus Armbruster [Sun, 3 Feb 2013 17:09:28 +0000 (18:09 +0100)]
edit: Improve tech, research, edu, happiness change reporting

Print "Technology" instead of "Tech".  Print "FOO of CNAME (#CNUM)"
instead of just "FOO".  Print "unchanged" instead of "changed from X
to X" on no-op.

Send a bulletin to the unit owner and report news on change.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoactofgod: New divine_nat_change(), similar to divine_sct_change()
Markus Armbruster [Sun, 3 Feb 2013 16:42:18 +0000 (17:42 +0100)]
actofgod: New divine_nat_change(), similar to divine_sct_change()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Add remaining missing unit change reporting
Markus Armbruster [Sun, 3 Feb 2013 14:22:54 +0000 (15:22 +0100)]
edit: Add remaining missing unit change reporting

Print a message (always), send a bulletin to the unit owner and report
news (sometimes).

The message is necessary to give the deity a chance to catch
unexpected changes, e.g. a player spending mobility right before the
deity edits it.  Watching out for such changes is especially important
with non-interactive edit.

Affected keys:

    cmd  key    struct member   action
    ----------------------------------
    edit s L    shp_x,y         B-
           E    shp_effic       BN
           M    shp_mobil       BN
           F    shp_fleet       B-
           T    shp_tech        BN
           a    shp_pstage      --
           b    shp_ptime       --
           R    shp_rpath       B-
    edit p l    pln_x,y         B-
           e    pln_effic       BN
           m    pln_mobil       BN
           w    pln_wing        B-
           t    pln_tech        BN
           r    pln_range       B-
    edit u L    lnd_x,y         B-
           e    lnd_effic       BN
           M    lnd_mobil       BN
           a    lnd_army        B-
           t    lnd_tech        BN
           F    lnd_harden      BN
           Z    lnd_retreat     B-
           R    lnd_rpath       B-

The two characters in column action show whether the command sends a
bulletin (B) or not (-), and whether it reports news (N) or not (-).

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Report flags change properly
Markus Armbruster [Sun, 3 Feb 2013 14:10:46 +0000 (15:10 +0100)]
edit: Report flags change properly

Print a message, send bulletin to owner.  Affects ship key 'W', land
unit key 'W', and plane key 'f'.  The message is necessary to give the
deity a chance to catch unexpected changes, e.g. a player modifying
retreat conditions right before the deity edits them.  Watching out
for such changes is especially important with non-interactive edit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Teleport planes and land units to carrier on load
Markus Armbruster [Sun, 3 Feb 2013 13:59:00 +0000 (14:59 +0100)]
edit: Teleport planes and land units to carrier on load

Edit lets deities load units onto remote carriers, resulting in a
carriers having cargo in another sector.  Not good.  Cargo gets
teleported to its carrier belatedly when the carrier moves.

Better let edit take care of the teleport.

Also tell the deity that he just caused a teleport.  Necessary to give
the deity a chance to catch unexpected changes, e.g. a player moving a
plane right before the deity edits it.  Watching out for such changes
is especially important with non-interactive edit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Refuse to move planes and land units on carriers
Markus Armbruster [Sun, 3 Feb 2013 13:40:36 +0000 (14:40 +0100)]
edit: Refuse to move planes and land units on carriers

They really need to stay with their carrier.  Else, cargo gets
silently teleported to its carrier when the carrier moves.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Report loading/unloading of planes & land units properly
Markus Armbruster [Sun, 3 Feb 2013 12:28:26 +0000 (13:28 +0100)]
edit: Report loading/unloading of planes & land units properly

Print a message, send bulletin to owner.  Affects plane keys 's', 'y',
and land unit keys 'S', 'Y'.  The message is necessary to give the
deity a chance to catch unexpected changes, e.g. a player loading a
plane right before the deity edits it.  Watching out for such changes
is especially important with non-interactive edit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Report unit loss and gain properly for key 'U'
Markus Armbruster [Sun, 27 Jan 2013 17:10:48 +0000 (18:10 +0100)]
edit: Report unit loss and gain properly for key 'U'

Send bulletin to owner and report news exactly like for key 'O' or
sector key 'L'.

Print a "duplicated" message, just for consistency with other keys.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests/actofgod: Enable in "make check"
Markus Armbruster [Sat, 1 Jun 2013 12:15:36 +0000 (14:15 +0200)]
tests/actofgod: Enable in "make check"

The showstopper bugs have been fixed.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Report unit key 'U' failure more nicely, and avoid oops
Markus Armbruster [Sun, 27 Jan 2013 14:43:39 +0000 (15:43 +0100)]
edit: Report unit key 'U' failure more nicely, and avoid oops

Two failure modes:

* When the argument is negative, edit() attempts an invalid write,
  triggering an oops.  edit() detects the write failure, and returns
  RET_FAIL.

  Detect the negative argument instead, and return RET_SYN, like we do
  for other invalid edit arguments.

* When the argument requires the table to be extended, but the
  extension fails, edit() returns RET_FAIL.

  Additionally report the failure to the player.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Report unit loss and gain properly for unit key 'O'
Markus Armbruster [Sun, 27 Jan 2013 14:37:51 +0000 (15:37 +0100)]
edit: Report unit loss and gain properly for unit key 'O'

Print a message describing the actual change.  Necessary to give the
deity a chance to catch unexpected changes, e.g. a player boarding a
ship right before the deity edits it.  Watching out for such changes
is especially important with non-interactive edit.

Code already sends bulletins.  Also report news.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Factor out edit_unit()
Markus Armbruster [Sun, 27 Jan 2013 14:22:16 +0000 (15:22 +0100)]
edit: Factor out edit_unit()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Report ship and land unit commodity change properly
Markus Armbruster [Sun, 3 Feb 2013 12:16:48 +0000 (13:16 +0100)]
edit: Report ship and land unit commodity change properly

Print a message describing the actual change.  Necessary to give the
deity a chance to catch unexpected changes, e.g. a player unloading
stuff right before the deity edits it, leaving fewer items than the
deity intends to take.  Watching out for such changes is especially
important with non-interactive edit.

Send bulletin to owner and report news exactly like the give command.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoactofgod: New divine_unit_change(), similar to divine_sct_change()
Markus Armbruster [Sun, 3 Feb 2013 11:53:03 +0000 (12:53 +0100)]
actofgod: New divine_unit_change(), similar to divine_sct_change()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoactofgod: Factor report_divine_gift() out of give()
Markus Armbruster [Sun, 3 Feb 2013 11:24:32 +0000 (12:24 +0100)]
actofgod: Factor report_divine_gift() out of give()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit &c: Report sector non-change differently
Markus Armbruster [Sun, 3 Feb 2013 09:43:46 +0000 (10:43 +0100)]
edit &c: Report sector non-change differently

Print "unchanged" instead of "changed from X to X".  Affects edit,
setresource, setsector.  Suppress bulletin and news.  Affects only
edit sector key 'L'.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoactofgod: Factor divine_sct_change() out of edit.c
Markus Armbruster [Sun, 3 Feb 2013 07:27:31 +0000 (08:27 +0100)]
actofgod: Factor divine_sct_change() out of edit.c

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Streamline wording of sector change reports slightly
Markus Armbruster [Sun, 3 Feb 2013 06:58:03 +0000 (07:58 +0100)]
edit: Streamline wording of sector change reports slightly

Most places use "FOO of X,Y changed", some use "FOO in X,Y changed",
"FOO in X,Y was changed", "FOO of sector X,Y changed".  Normalize to
the former.

Most places do not end the message with a period, some do.  Normalize
to no period.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosect: Catch clobbered sector coordinates in sct_prewrite()
Markus Armbruster [Sun, 27 Jan 2013 09:31:49 +0000 (10:31 +0100)]
sect: Catch clobbered sector coordinates in sct_prewrite()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoef_verify: Cover sector coordinates in game state verification
Markus Armbruster [Sun, 27 Jan 2013 09:27:36 +0000 (10:27 +0100)]
ef_verify: Cover sector coordinates in game state verification

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosctoff2xy(): New, factored out of sct_oninit()
Markus Armbruster [Sun, 27 Jan 2013 09:22:03 +0000 (10:22 +0100)]
sctoff2xy(): New, factored out of sct_oninit()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoxy.h: Move declaration of sctoff() from sect.h to xy.h
Markus Armbruster [Sun, 27 Jan 2013 09:13:11 +0000 (10:13 +0100)]
xy.h: Move declaration of sctoff() from sect.h to xy.h

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Fix stack smash in sector key 'L'
Markus Armbruster [Sun, 27 Jan 2013 08:28:34 +0000 (09:28 +0100)]
edit: Fix stack smash in sector key 'L'

Key 'L' copies the source sector to a destination sector.  Bug: it
doesn't copy, it messes up the source sector badly instead, and can
smash the stack on some machines.

Root cause: doland() passes &sect instead of sect to ef_set_uid().
Impact:

1. ef_setuid() clobbers a few bytes at &sect.

   When the bitfield and uid fit into sizeof(sect) bytes, it clobbers
   just sect, which has no effect, because doland() returns without
   using it again.  This is the case on a typical 64-bit machine: bit
   field and uid are both 4 bytes, sizeof(sect) is 8.

   When they don't fit, whatever is adjacent to sect gets clobbered.
   On a typical 32-bit machine with stack growing down, that's p.
   Again, no effect, because doland() returns without using it again.
   With stack growing up, it could well be the return address,
   crashing the server.

2. ef_setuid() fails to update *sect.  Impact (when we survive 1):

   sect->sct_uid remains unchanged.  putsect() writes to the source
   sector instead of the destination sector, clobbering the source's
   sct_x, sct_y.  Breaks invariant sctoff(sct_x, sct_y) == sct_uid!
   Subsequent edits are all applied to the source sector.

   sect->sct_seqno remains unchanged.  No effect, because we write to
   the source sector, and the unchanged sequence number is the right
   one there.

Broken in commit 536ef0b0, v4.3.15.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoswapsector: Notify affected sector owners
Markus Armbruster [Sat, 26 Jan 2013 22:18:01 +0000 (23:18 +0100)]
swapsector: Notify affected sector owners

Send bulletins, like edit does.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosetsector setresource: Switch to edit_sect()
Markus Armbruster [Sat, 26 Jan 2013 14:54:54 +0000 (15:54 +0100)]
setsector setresource: Switch to edit_sect()

One copy of the code suffices.

"Fertility content" becomes just "Fertility" in messages.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Parse int values in edit_FOO() helpers rather than edit()
Markus Armbruster [Sat, 26 Jan 2013 11:28:36 +0000 (12:28 +0100)]
edit: Parse int values in edit_FOO() helpers rather than edit()

Non-integer values are already parsed there.  Treating integer values
specially complicates things for no real gain.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoset_coastal: Fix function comment
Markus Armbruster [Sat, 26 Jan 2013 10:47:59 +0000 (11:47 +0100)]
set_coastal: Fix function comment

Screwed up in commit 6db2e6ec, v4.3.8.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit &c: Add remaining missing sector change reporting
Markus Armbruster [Sat, 26 Jan 2013 10:45:18 +0000 (11:45 +0100)]
edit &c: Add remaining missing sector change reporting

edit, setresource and setsector report change in three ways:

* Print a message.

* Send a bulletin to the changed object's owner.  This should be done
  if and only if the change is visible to the owner, e.g. in census or
  xdump.

* Report divine aid in news.  This should be done if and only if a
  bulletin was sent, except for changes that are neither negative nor
  positive, such as changing the distribution sector.

Fix the places that don't get it right for sectors:

    cmd  key    sctstr member   before  after   notes
    -------------------------------------------------
    edit l O    sct_oldown      --      B-
    edit l F    sct_fallout     --      BN      1
    edit l M    sct_mines       --      BN      2 3
    edit l D    sct_dist_x,y    --      B-      1
    edit l s    sct_type        --      B-      1
    edit l S    sct_newtype     --      B-      1
    setse ow    sct_own         B-      BN
    setse ol    sct_oldown      --      B-
    setse e     sct_effic       --      BN      2
    setse mo    sct_mobil       --      BN      2
    setse a     sct_avail       --      BN      2
    setse w     sct_work        --      BN      2

The two characters in columns before, after show whether the command
sends a bulletin (B) or not (-), and whether it reports news (N) or
not (-).

Notes:

1. Printed message massaged slightly for consistency with other keys.

2. Printed message improved to show the old value, too.  Necessary to
   give the deity a chance to catch unexpected changes, e.g. a player
   laying mines right before the deity edits them.  Watching out for
   such changes is especially important with non-interactive edit.

3. Bulletin and news suppressed for occupied sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Report sector loss and gain properly for key 'L'
Markus Armbruster [Sat, 26 Jan 2013 07:58:14 +0000 (08:58 +0100)]
edit: Report sector loss and gain properly for key 'L'

Send bulletin to owner and report news exactly like for key 'o'.

Also print a "sector duplicated" message, just for consistency with
other keys.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Limit resources to 100 instead of 127
Markus Armbruster [Fri, 25 Jan 2013 18:30:18 +0000 (19:30 +0100)]
edit: Limit resources to 100 instead of 127

Back in Empire 1, resources were limited consistently: fertility to
120, all others to 100.

When Chainsaw added setresource, consistency was lost: fertility got
limited to 100 there.

Chainsaw 3 changed edit to limit all resources to 127.

Commit 3fcee8dd and commit 8e430ae2 (both v4.3.11) changed fairland
and setsector to limit fertility to 100, matching setresource.

Now only edit remains different.  Change it to finally make things
consistent again.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosetsector: Clean up read beyond end of string
Markus Armbruster [Thu, 24 Jan 2013 21:01:45 +0000 (22:01 +0100)]
setsector: Clean up read beyond end of string

setsector() reads the first two characters unconditionally.  Wrong if
the first character is NUL.  The second character read isn't actually
used then.  Screwed up in Chainsaw.

When getstarg() returns an empty string, it's always in the buffer
passed as third argument.  Thus, reading the second character is
actually safe.

Clean it up anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoprototypes.h: Fix and complete documentation of src/lib/gen/
Markus Armbruster [Thu, 24 Jan 2013 06:51:41 +0000 (07:51 +0100)]
prototypes.h: Fix and complete documentation of src/lib/gen/

Commit 77e95bd7 (v4.3.12) missed the move of log.c there.  A few
pointers to other headers are missing.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosetsector setresource: Print effect for unowned sectors, too
Markus Armbruster [Wed, 23 Jan 2013 06:52:45 +0000 (07:52 +0100)]
setsector setresource: Print effect for unowned sectors, too

The "changed from" message has always been suppressed for unowned
sectors.  Makes no sense.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosetsector: Don't disclose number of landmines to occupier
Markus Armbruster [Mon, 21 Jan 2013 20:44:51 +0000 (21:44 +0100)]
setsector: Don't disclose number of landmines to occupier

When the deity sets the number of mines with setsector, the sector
owner (if any) is told the resulting number of mines.  Even for
occupied sectors, where mines belong to the old owner, and thus
shouldn't be disclosed.  Oops.

Fix setsector not to tell the sector owner anything then.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoRevert "Fix setsector not to disclose number of landmines to occupier"
Markus Armbruster [Mon, 21 Jan 2013 20:40:05 +0000 (21:40 +0100)]
Revert "Fix setsector not to disclose number of landmines to occupier"

Fails to print actual change for occupied sectors.  Broken in v4.3.31.

This reverts commit eb4adc93ffc072da7ab1c561fc84e896b7c70d12.

Conflicts:
    src/lib/commands/setsect.c

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit &c: Suppress bulletins for acts of god to himself
Markus Armbruster [Tue, 22 Jan 2013 21:05:06 +0000 (22:05 +0100)]
edit &c: Suppress bulletins for acts of god to himself

Deities get bulletins when they use edit, give, setsector and
setresource on stuff they own.  Except for POGO, who can't own
anything.

The bulletins are annoying; suppress them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit &c: Suppress news for acts of god to gods
Markus Armbruster [Tue, 22 Jan 2013 21:12:43 +0000 (22:12 +0100)]
edit &c: Suppress news for acts of god to gods

Option GODNEWS is documented to be about deities giving or taking
things from players.  Nevertheless, edit, give, setsector and
setresource report news of deities meddling with things owned by
deities other than POGO.  Don't.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit &c: Suppress news and bulletins on no-op acts of god
Markus Armbruster [Tue, 22 Jan 2013 20:33:40 +0000 (21:33 +0100)]
edit &c: Suppress news and bulletins on no-op acts of god

give already suppresses when the new value equals the old one, but
edit, setresource and setsector don't.  Make them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoSend bulletins only from POGO
Markus Armbruster [Mon, 21 Jan 2013 19:58:28 +0000 (20:58 +0100)]
Send bulletins only from POGO

In the beginning, all bulletins came from POGO.  Chainsaw changed edit
and give to send them from the deity using the command.  Its new
command setresource sent from POGO regardless.  Its new command
setsector did both.

Go back to sending them only from POGO.

Some of the affected bulletins don't mention the acting deity.  Reword
them so they do.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: De-duplicate code for commodities on ships and land units
Markus Armbruster [Mon, 21 Jan 2013 19:50:40 +0000 (20:50 +0100)]
edit: De-duplicate code for commodities on ships and land units

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Pass full keys around, not just first characters
Markus Armbruster [Sun, 20 Jan 2013 22:40:10 +0000 (23:40 +0100)]
edit: Pass full keys around, not just first characters

To simplify the next commit.

Changes the error message for unknown keys to show the full key.
Shouldn't matter.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Accept interactive empty key argument again
Markus Armbruster [Sun, 20 Jan 2013 22:39:03 +0000 (23:39 +0100)]
edit: Accept interactive empty key argument again

Empty key arguments work fine when passed as command arguments, but
not interactively.  For example, 'edit s 42 R ""' clears the retreat
path, but in an interactive 'edit s 43', 'R ""' sets it to "".

In Empire 1, omitting the argument made it empty.  Empire 2 turned
that into an error without providing an alternative.

Switch to the common command parser, so that quoting works, and "" is
parsed as empty argument.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Treat blank interactive input like empty input
Markus Armbruster [Sun, 20 Jan 2013 22:38:40 +0000 (23:38 +0100)]
edit: Treat blank interactive input like empty input

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agogive: Report number given when less than requested amount
Markus Armbruster [Sun, 20 Jan 2013 16:38:06 +0000 (17:38 +0100)]
give: Report number given when less than requested amount

Necessary to give the deity a chance to catch unexpected changes,
e.g. a player moving away stuff right before a give command, leaving
fewer items than the deity intends to take.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agogive: Fix integer overflows on silly third arguments
Markus Armbruster [Sun, 20 Jan 2013 15:39:32 +0000 (16:39 +0100)]
give: Fix integer overflows on silly third arguments

give() silently caps the resulting number of items to 0..ITEM_MAX.

However, its test for "< 0" suffers integer overflow on two's
complement machines (i.e. practically everywhere) when the amount
argument is INT_MIN.  give() proceeds as if the result was in range:
it sets the number of items to (short)(n + INT_MIN), telexes the owner
that INT_MIN items were stolen (obviously bogus), and tells the deity
that there are now n + INT_MIN items in X,Y.

On common machines, (short)(n + INT_MIN) == n, i.e. nothing is given.

On an oddball machine with short as wide as int, the cast to short
does nothing, item_prewrite() oopses, and corrects the number of items
to zero.

In both cases, output and telegram lie.

Likewise, its test for "> ITEM_MAX" suffers integer overflow for
sufficiently big amount arguments.  Again, give() proceeds as if the
result was in range: it sets the number of items to (short)(n + amt),
telexes the owner that -amt items were stolen (obviously bogus), and
tells the deity that there are now close to INT_MIN items in X,Y.

On common machines, (short)(n + amt) = n + INT_MAX - amt - 1,
i.e. some items are stolen.

On an oddball machine with short as wide as int, the cast to short
does nothing, item_prewrite() oopses, and corrects the number of items
to zero.

Again, output and telegram lie.

Aside: setsector can suffer similar overflows, but it reports the
resulting change correctly.  Good enough.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Don't permit putting a land unit or plane on two carriers
Markus Armbruster [Wed, 16 Jan 2013 20:07:21 +0000 (21:07 +0100)]
edit: Don't permit putting a land unit or plane on two carriers

Only one of struct lndstr members lnd_ship, lnd_land may be
non-negative.  When a deity screws that up, the server oopses.  Be
nice: when setting one, zap the other.

Same for struct plnstr members pln_ship, pln_land.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Fix integer argument range checking
Markus Armbruster [Wed, 16 Jan 2013 19:53:56 +0000 (20:53 +0100)]
edit: Fix integer argument range checking

Upper bounds corrected:

    cmd  key  struct member   wrong   correct   notes
    -------------------------------------------------
    edit l m  sct_mobil         255       127      1
           t  sct_ptime         255     32767
    edit c b  nat_btu          1024  max_btus
    edit p m  pln_mobil         255       127      1
    edit u F  lnd_harden        255       127    1

Missing bounds supplied, arguments out of bounds are silently clipped
unless noted otherwise:

    cmd  key     struct member   bounds           notes
    ---------------------------------------------------
    edit c t     nat_tgms        0   USHRT_MAX       2
           m     nat_reserve     0   INT_MAX
           T...  nat_level[]     0   infinity
    edit s a     shp_pstage      0   PLG_EXPOSED     3
           b     shp_ptime       0   32767
           M     shp_mobil    -127   127
           c...  shp_item[]      0   load limit      4
    edit u Y     lnd_land       -1   size of table   5
           M     lnd_mobil    -127   127
           S     lnd_ship       -1   size of table   5
           Z     lnd_retreat     0   100
           c...  lnd_item[]      0   load limit      4
    edit p r     pln_range       0   max range
           s     pln_ship       -1   size of table   5
           y     pln_land       -1   size of table   5

Notes:

1. Values between SCHAR_MAX and 255 were cast to signed char, changing
the sign.

2. The real upper bound is the number of telegrams in the mailbox, but
counting them isn't worth it.

3. This check is particularly important, because values out of bounds
make the server refuse to start without -F, and empdump -x warn
"export has errors, not importable as is".

4. Values outside 0..ITEM_MAX got caught and clipped by
item_prewrite().  This check avoids the oops, and tightens the upper
bound for units.

5. Argument out-of-bounds are rejected.  This check is particularly
important, because unit numbers beyond the size of the table trigger
oopses.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Drop pointless doland() variables old, des
Markus Armbruster [Tue, 15 Jan 2013 20:22:39 +0000 (21:22 +0100)]
edit: Drop pointless doland() variables old, des

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Suppress "sunk!" after "taken from you by deity"
Markus Armbruster [Tue, 15 Jan 2013 20:00:44 +0000 (21:00 +0100)]
edit: Suppress "sunk!" after "taken from you by deity"

The fact that the ship wasn't given to anyone is none of the
ex-owner's business.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Fix and unify handling of invalid country numbers
Markus Armbruster [Tue, 15 Jan 2013 19:30:36 +0000 (20:30 +0100)]
edit: Fix and unify handling of invalid country numbers

Negative numbers and numbers greater or equal than MAXNOC are invalid.
edit handles such arguments inconsistently:

    cmd  key  struct member   arg < 0     arg >= MAXNOC
    ---------------------------------------------------
    edit l o  sct_own         reject      MAXNOC - 1
           O  sct_oldown      reject      MAXNOC - 1
           X  sct_che_target  0           MAXNOC - 1
    edit s O  shp_own         cast        skip
    edit u O  lnd_own         cast        skip
    edit p O  pln_own         cast        skip

Legend:

    0           replace arg by 0
    MAXNOC - 1  replace arg by MAXNOC - 1
    reject      command fails
    cast        replace arg by (natid)arg
                bug: can be >= MAXNOC!
    skip        ignore this key and arg
                bug: telexes the owner he lost the unit, which is a lie

Unify to reject.  Matches setsector.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Don't show loyalty, plague stage and time as percentages
Markus Armbruster [Tue, 15 Jan 2013 18:25:40 +0000 (19:25 +0100)]
edit: Don't show loyalty, plague stage and time as percentages

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Show edited planes and land units just like ships
Markus Armbruster [Tue, 15 Jan 2013 18:19:56 +0000 (19:19 +0100)]
edit: Show edited planes and land units just like ships

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Show the edited ship even when its owner is invalid
Markus Armbruster [Mon, 14 Jan 2013 22:23:23 +0000 (23:23 +0100)]
edit: Show the edited ship even when its owner is invalid

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoprnatid: Recover from getnatp() failure
Markus Armbruster [Mon, 14 Jan 2013 22:18:11 +0000 (23:18 +0100)]
prnatid: Recover from getnatp() failure

cname() calls getnatp(), and returns a null pointer when it fails.
Some systems (GNU, Windows) deal gracefully with printing null
strings, others crash.

Because we keep table EF_NATION entirely in memory, getnatp() should
fail only on invalid country number.

Rewrite prnatid() to catch this error and recover.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoprnat() prnatid(): New, common country name (#number) formatting
Markus Armbruster [Mon, 14 Jan 2013 22:15:03 +0000 (23:15 +0100)]
prnat() prnatid(): New, common country name (#number) formatting

prnat() is more convenient when you already got the struct natstr *.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoedit: Rename some of helpers, and reorder parameters
Markus Armbruster [Mon, 14 Jan 2013 22:02:58 +0000 (23:02 +0100)]
edit: Rename some of helpers, and reorder parameters

doland() edits a sector, not a land unit.  That one's called dounit().
Lacks taste.  Call the helper for editing a FOO edit_FOO(), and make
the FOO * the first parameter instead of the last.

Rename the print helpers to print_FOO(), for consistency.  Also frees
up identifier prnat for the next commit.

While there, clean up an unused #define.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoReplace common pattern by new LIMIT_TO()
Markus Armbruster [Mon, 14 Jan 2013 21:34:05 +0000 (22:34 +0100)]
Replace common pattern by new LIMIT_TO()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests/actofgod: New, disabled for now because it oopses
Markus Armbruster [Sat, 1 Jun 2013 10:46:40 +0000 (12:46 +0200)]
tests/actofgod: New, disabled for now because it oopses

This is a fairly comprehensive test of the deity commands to edit game
state: edit, setresource, setsector, give, swapsector.

The test makes edit screw up game state, triggering oopses.  The
server refuses to start without -F then, and empdump -x warns "export
has errors, not importable as is".  Until these bugs are fixed, skip
this test in "make check".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agomake: Drop unused support for parallel test runs
Markus Armbruster [Sat, 1 Jun 2013 10:44:02 +0000 (12:44 +0200)]
make: Drop unused support for parallel test runs

Tests can't run in parallel anyway, because they use uses a single
sandbox directory and a single TCP port.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoempdump: Don't abort() on unresolvable symbols
Markus Armbruster [Sat, 1 Jun 2013 08:36:33 +0000 (10:36 +0200)]
empdump: Don't abort() on unresolvable symbols

empdump flags them since commit 2a5d12b (v4.3.28), but still aborts.
Avoid the abort.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: Capture player output via journal instead of client
Markus Armbruster [Fri, 31 May 2013 08:41:18 +0000 (10:41 +0200)]
tests: Capture player output via journal instead of client

Capturing the client's output tests both client and server, which is
nice.  However, player input isn't visible in the resulting file,
which makes it more difficult to understand.

Route player output to journal (econfig key "keep_journal 2"), and
ignore client output.

Separate tests for the client would be useful.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoclient: Send login commands without trailing space
Markus Armbruster [Fri, 31 May 2013 08:02:54 +0000 (10:02 +0200)]
client: Send login commands without trailing space

Cosmetical improvement; the server is just fine with trailing space.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: Cut off log file timestamp instead of normalizing it
Markus Armbruster [Fri, 31 May 2013 07:54:50 +0000 (09:54 +0200)]
tests: Cut off log file timestamp instead of normalizing it

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotests: Enable thread stack checking (emp_server -s)
Markus Armbruster [Fri, 31 May 2013 07:27:09 +0000 (09:27 +0200)]
tests: Enable thread stack checking (emp_server -s)

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agocutoff level: Add FIXME comments to narrow coordinate columns
Markus Armbruster [Sun, 26 May 2013 09:31:21 +0000 (11:31 +0200)]
cutoff level: Add FIXME comments to narrow coordinate columns

When formatting coordinates for fixed-width output, the width should
be at least four characters.

cutoff was fine until 4.0.2 reduced coordinate width to three to make
space for civilian and military delivery thresholds.

level has always used width three.

Can't fix either without making lines too long or dropping
information, so just document the problem for now.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agomission: Widen coordinate columns to four characters
Markus Armbruster [Sun, 26 May 2013 09:08:37 +0000 (11:08 +0200)]
mission: Widen coordinate columns to four characters

When formatting coordinates for fixed-width output, the width should
be at least four characters.

Columns x,y and op-sect use three.  Has always been that way.  Widen
them both to four.  This cleans up output for world sizes between 200
and 1998.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosorder: Widen coordinate columns to four characters
Markus Armbruster [Sun, 26 May 2013 08:58:23 +0000 (10:58 +0200)]
sorder: Widen coordinate columns to four characters

When formatting coordinates for fixed-width output, the width should
be at least four characters.

Columns x,y, start and end use three.  Has always been that way,
except for end, which used two until commit e07fb30 (v4.2.13).

Widen them all to four.  This cleans up output for world sizes between
200 and 1998.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoland: Separate columns x,y and a in output properly
Markus Armbruster [Sat, 25 May 2013 17:59:19 +0000 (19:59 +0200)]
land: Separate columns x,y and a in output properly

Coordinates run into army when the y coordinate is wider than three
characters.  Has always been broken.  Insert a separating space.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agosatmap: Separate and align columns in output properly
Markus Armbruster [Sat, 25 May 2013 17:37:22 +0000 (19:37 +0200)]
satmap: Separate and align columns in output properly

Land unit coordinates run into efficiency in output of satellite when
the y coordinate is wider than three characters.  Broken in Empire 2.
Restore the separating space.

Both ship and land unit table header aren't aligned with the table
body.  Affects recon and sweep with spy planes, and satellite.  Fix
the header.

Reported-by: William Fittge <ptkei2@gmail.com>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agotcp_listen: Plug fd leak on OpenBSD with IPv6
Markus Armbruster [Sat, 25 May 2013 15:08:26 +0000 (17:08 +0200)]
tcp_listen: Plug fd leak on OpenBSD with IPv6

Leaks one file descriptor per configured IPv6 address, which should be
pretty harmless.  Broken in commit da154ff, v4.3.31.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
9 years agoinfo/version: Update example to current output
Markus Armbruster [Sat, 25 May 2013 15:02:11 +0000 (17:02 +0200)]
info/version: Update example to current output

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>