Commit graph

4252 commits

Author SHA1 Message Date
91c2ecec53 Land units loaded on land units fight che again
They didn't since commit 93d033cf, v4.3.26.  Drawback: micromanagement
incentive to unload them for the update.  Similar incentive has always
existed for military on ships.

Since the previous commit, land units loaded on land units get
unloaded when the carrier dies fighting che.  Such land units get
stuck in the sector if the take over, and can be boarded.  Doesn't
feel right, and increases the micromanagement incentive.  Avoid by
letting them fight.
2011-07-10 21:10:17 +02:00
7aba25e826 Don't leave cargo stuck on land unit killed by che
When che destroy a land unit, any embarked units remain stuck on their
now dead carrier.  Closely related to and same impact as the bug fixed
in commit 8ccad0d7.  Broken since Chainsaw 3 added land units.

The obvious fix would be to match what normally happens when a carrier
gets destroyed: destroy the cargo.  Requires recursion.  To keep
things as simple as possible, destroy plane cargo, but unload land
unit cargo.  That way, the only cargo of cargo to visit are nukes on
planes.

Unloading the land units creates another problem, which will be
addressed in the next commit.
2011-07-10 21:09:37 +02:00
4c8d4228c8 Factor lnd_dies_fighting_che() out of take_casualties() 2011-07-10 21:08:56 +02:00
8ccad0d779 Units no longer die from lack of maintenance
Damage due to lack of maintenance is now limited by the unit's minimum
efficiency.

Before, units could die.  Unfortunately, the update left any embarked
units on their dead carrier.  Should have seen this when I fixed a
related bug in commit c2c0d1ff, v4.3.22.  Broken for ships and land
units when Empire 2 added their maintenance cost, and for planes when
commit 2e40a4bb (v4.3.4) replaced nuclear stockpiles by nuke units.
The common root cause of these bugs is the update bypassing pre-write
functions (bug#1010856).

If another unit with the same number got built, it picked up the stuck
cargo, triggering the oops from commit 6fb5caf6, which see.

In "stuck on dead carrier" state, units pretty much behave as if their
carrier was still alive, with additional protection from the fact that
a dead carrier can't be damaged or boarded.

The server detects this state on startup since commit 7da9aab5, and
refuses to start.

Only a deity can take units off a dead carrier.
2011-07-10 21:08:50 +02:00
8621911b4d Belatedly update info Maintenance for removed budget priorities
Missed in commit 520446ef, v4.3.6.
2011-07-10 11:43:44 +02:00
6fb5caf633 Oops when stuck cargo snaps to new ship, plane or land unit
When units somehow get stuck on a dead carrier, a new build reusing
the dead carrier's UID picks up its cargo.  The cargo gets teleported
to its new carrier when the carrier moves.

Oops when a ship, plane or land unit is created with cargo.  To
recover, destroy the cargo.
2011-07-10 11:43:44 +02:00
3de1e8be28 Avoid false positive generation oops in navigate and march
Commit e3cf1e32 (v4.3.27) created make_stale_if_command_arg() to
permit catching more potential yields on input.  Unfortunately, the
implementation of navigate and march sub-commands 'r', 'l' and 's'
breaks it.

do_unit_move() reads units into a unit list at the beginning and at
each stop.  It writes them back when they move or sweep.  If a unit
changed in the file in between, the changes would get wiped out.
Therefore, do_unit_move() must not yield between stops.

do_unit_move() parses sub-commands into player->argp[], then supplies
defaults for missing arguments, so that code using them (radar(),
do_look(), sona(), mine(), landmine()) won't prompt for missing
arguments.  Unclean and brittle.  See also commit 28cc236e and commit
45106ab9.

Unfortunately, make_stale_if_command_arg() doesn't recognize the
difference between these defaulted arguments and parsed arguments, so
it makes objects stale, even though the defaulted arguments can't be
missing.  If a move or sweep follows, it triggers a false positive
generation oops.

To fix, test "points into argument buffer" (only true for parsed
arguments) instead of "is in player->argp[]".  Requires making the
argument buffer accessible: new struct player member argbuf[].  Use it
for parsing commands, in command(), execute(), do_unit_move().  Don't
use it in emp_config(), player_login(), move_ground(), because these
parse something else.
2011-07-09 15:16:21 +02:00
36015e8c0e Fix client redirection and execute for non-ASCII characters
The client rejects unauthorized redirection and execute.  Its
authorized check always fails for arguments with non-ASCII characters.
The culprit is ring_search(): It compares plain char to unsigned char,
which breaks when char is signed.  Believed to be broken in commit
8b7d0b91, v4.3.11.

Note that non-ASCII characters only work in UTF-8 sessions.  In ASCII
sessions, the server replaces them, and the authorized check fails.
Works as designed.
2011-07-09 15:16:21 +02:00
afb45d933e Fix prexec() comment pasto 2011-07-09 15:16:21 +02:00
0bfdbfcbdd Fix execute not to mangle the argument when it prompts for it
The argument is UTF-8.  If it's missing, execute() gets it with
getstring(), which mangles non-ASCII characters.  Clients reject
mangled file names for security reasons.

Fix by switching to ugetstring().  Missed in commit 69832255, v4.3.11.

Non-ASCII characters are still mangled in ASCII sessions, but that's
not expected to work.
2011-07-09 15:16:21 +02:00
0493cbc655 Revert "Simplify execute(): use getstarg() instead of getstring()"
This reverts commit 96d1039c24.  It's in
the next commit's way.
2011-07-09 15:16:21 +02:00
e2e69a29d5 Fix execute to filter input just like the main command loop
When we added input filtering in v4.2.21, we missed the execute
command.  Because of that, funny characters can be treated differently
in batch files.

The main command loop uses getcommand(), which filters input.
execute() uses recvclient() directly, and doesn't filter input.  Both
feed the command to parse(), which drops unwanted control and
non-ASCII characters.

Input filtering drops unwanted control characters and, for ASCII
sessions, replaces non-ASCII characters by '?'.

Because of that, execute in ASCII sessions drops non-ASCII command
characters in batch files rather than replacing them.

Except where parts of the command are used raw: execute's command
echo, flash and wall message argument.  There, unwanted control
characters aren't dropped in UTF-8 sessions, and non-ASCII characters
are interpreted as UTF-8 in ASCII sessions.  Output filtering replaces
any resulting non-ASCII characters.

players column "last command" also uses the command raw, but commands
executed from batch files are not visible there, so it isn't affected.

To get rid of the differences, move the prompting from getcommand() to
command(), then switch execute() over to getcommand().

Side effect: the batch file's commands are now recorded in
player_commands[].  That's desirable.
2011-07-09 15:16:21 +02:00
a9611a5794 Don't record prompts in player_commands[]
Recording prompts is of marginal value, and it's in the next commit's
way.

If you need better logs after a crash, consider enabling the journal
log file.
2011-07-09 15:15:51 +02:00
d3899f5732 Fix execute to print UTF-8 command correctly
execute() prints the UTF-8 command as normal text, which messes up
non-ASCII characters.  Broken in commit 2cc44bb1, v4.2.21.
2011-07-09 15:14:30 +02:00
b464b0fcc2 Fix input/output filtering to ASCII
copy_utf8_to_ascii_no_funny() eats the character following a replaced
non-ASCII character.  Buffer overrun possible when the terminating
zero gets eaten.  Broken in commit b5ff7e3b, v4.2.21.

Affected commands:

* players column "last command" in ASCII sessions: struct player
  member combuf is UTF-8, uprnf() filters to ASCII.

* read in ASCII sessions: telegram chunks are UTF-8, uprnf() filters
  to ASCII.

* flash and wall with message argument in ASCII sessions: argument is
  used raw, i.e. UTF-8, pr_flash() filters to ASCII.  Safe as long as
  we have input filtering sanitizing the raw argument.  command() does
  that, but execute() doesn't (bug, to be fixed in a later commit).

* execute prompting for its argument in UTF-8 sessions: prmptrd()
  receives user text, and filters to ASCII.

Unaffected:

* dispatch() argument redir is UTF-8, uprnf() can filter to ASCII.
  Safe as long as we have input filtering sanitizing the raw argument.
  command() does that.  execute() doesn't, but rejects redirections
  before calling dispatch().

* getele() buffer is UTF-8, uprnf() can filter to ASCII.  Safe,
  because its contents comes from uprmptrd(), which filters input.
2011-07-09 15:14:00 +02:00
727e6194c8 Update and report status even after empty command
When getcommand() reads an empty string, it prints another prompt and
reads another line, without running status().  That's bad:

* nat_timeused is not updated.  Affects the player's prompt, deities'
  nat selector timeused, and commands edit, players, xdump nat.

* Mortal player isn't logged off for game hours, game down, and time
  limit.

* Notifications are delayed: going broke, becoming solvent, new
  telegrams (toggle inform off only), new announcements, capital lost.

Fix by removing the loop.  Callers handle empty input just fine since
4.2.2.

Side effect: empty commands are now recorded in player_commands[].
That's okay.
2011-07-09 15:12:47 +02:00
2bbe648d78 Fix xundump's "value must match" check for split tables
The check applies to selectors with flag NSC_CONST set.  It permits
initializing them in new objects, but prevents changing them in
existing objects.  For split tables, initialization worked only in the
first part, because new objects were considered old in later parts.

For instance, in a custom config sect-chr with mnem in the second
part's field 2, new sector types were rejected with `Value for field 2
must be ""'.
2011-06-25 17:12:40 +02:00
84a285e9b1 Belatedly update xdump.pl not to use "xdump ver"
"version" is a normal table since commit da8a1dae, v4.3.12.  xdump.pl
wasn't updated for that, and queried the version table twice.  When
the deprecated special "xdump ver" was removed in commit 78b3af20
(v4.3.27), the extra query broke.  Remove it.
2011-06-25 17:12:40 +02:00
2abe2baeef Disable test of pre_update_hook in nightly build
Where exactly the output from pre_update_hook gets inserted in the log
depends on timing.  Messes up diffs between test runs.
2011-06-25 17:12:39 +02:00
c697fd8856 Fix nightly's diff_to_prev.sh
Broken in commit 5d512312, v4.3.11
2011-06-25 17:12:39 +02:00
3403cb2ecb Factor product code out of ef_verify() into verify_products() 2011-06-25 17:12:39 +02:00
ca4312061e Fold pln_zap_transient_flags() into verify_planes() 2011-06-25 17:12:37 +02:00
6f6d76fcc9 Verify carrier references are sane
Catch bad references here, before unit_cargo_init() chokes on them.
2011-06-25 17:10:29 +02:00
b991ddf8de Drop pln_zap_transient_flags()'s work-around for unusable putplane()
I believe putplane() became usable here in commit 3cf29456, v4.3.17.
The work-around was pretty wasteful (not that it mattered).
2011-06-25 17:06:48 +02:00
6eec001050 Fix empdump not to touch plane file when import fails
pln_zap_transient_flags() fixes up planes stuck in the air (commit
7ca4f412, v4.3.12).  Since commit 4e9e58bf (v4.3.14), it writes back
the fixed planes.  This is wrong for empdump.

empdump should touch data only on successful import.  When it fails
because ef_verify() fails, and any planes are found stuck in the air,
the plane file gets rewritten.

Make parameter ef_verify() take parameter may_put to let empdump
suppress the plane write-back.  The plane file still get written out
on successful import, along with the other imported game state.
2011-06-25 17:05:12 +02:00
7da9aab5a1 Verify game state and configuration reference sanity
Table elements reference other table elements.  Bad things happen when
references dangle.  ef_verify() already checks whether the referenced
table elements exist.  This commit makes it check whether the elements
are "in use".  This catches stuff like living planes on dead carriers.
2011-06-25 16:54:29 +02:00
b30c83cd64 Verify table uid sanity more tightly
verify_row() refrains from rejecting zero uids, because some tables
may contain blank entries, with zero uid.

Change it to check only header sanity for entries that are not in use.
This filters out all legitimately blank entries.  Tighten up the uid
check.

For computing "in use", factor empobj_in_use() out of xdvisible().
Note that xdvisible()'s case EF_COUNTRY doesn't bother to check
nat_stat, because that's implied by what it does check.  It's not
implied in empobj_in_use(), so add it there.
2011-06-25 16:54:29 +02:00
fbf5b78129 Factor verify_tabref() out of verify_row() 2011-06-25 16:54:29 +02:00
815a1b4193 Change xdump realm not to dump unused countries' realms
Affects only deities; mortals can only see their own realms.
2011-06-25 16:53:12 +02:00
93edcf0ac4 Remove option LANDSPIES, customize table land-chr instead
Spy units are now enabled when a land unit type with capability spy
exists.  To disable them, deities have to customize table land-chr.

Before, spy units types were ignored when option LANDSPIES was
disabled.  Except for xdump land-chr, which happily dumped unusable
spy unit types.
2011-06-25 16:53:02 +02:00
352bc320d2 Remove option TRADESHIPS, customize table ship-chr instead
Trade ships are now enabled when a ship type with capability trade
exists.  No such type exists by default; to enable trade ships,
deities have to customize table ship-chr.

Before, trade ship types were ignored when option TRADESHIPS was
disabled.  Except for xdump ship-chr, which happily dumped unusable
trade ship types.
2011-06-25 16:52:08 +02:00
c4254764bf Fix scuttle_it()'s "is a trade ship" sanity check
Only trade ships can be auto-scuttled.  orde() rejects scuttle orders
for other ships.  scuttle_it() double-checks, but gets the test wrong:
it rejects only when opt_TRADESHIPS is enabled.  Fix that.  While
there, make it oops on inadmissible ships.
2011-06-25 16:51:56 +02:00
7457573a50 Fix how configuration tables and empdump treat omitted entries
Change xundump to blank out omitted rows.  Before, they were left
alone.  Impact:

* No change for reading builtin tables.

* Reading custom tables now replaces the builtin tables instead of
  sort-of-merging them.  Wasn't a real merge, because it dropped
  builtin entries after the last custom entry, except for
  non-truncatable tables item, sect-chr and infrastructure.

* empdump -i now replaces the old state instead of sort-of-merging the
  dump into the old state.  Wasn't a real merge, because it dropped
  old state entries after the last entry in the dump, except for the
  fixed-size tables sect, nat, realm and game.
2011-06-25 16:51:56 +02:00
84d88442b3 Don't misinterpret blank configuration entries as sentinels
Configuration table entries not defined by builtin and custom
configuration files remain blank.  They get misinterpreted as sentinel
in tables that use one.  Affected are tables product, ship-chr,
plane-chr, land-chr and nuke-chr.  Tables item, sect-chr and
infrastructure are immune despite using a sentinel, because omitting
entries is not permitted there.

Code relying on the sentinel fails to pick up entries after the first
blank one.  They don't get set up correctly, they're invisible to
build and show, and not recognized as symbolic selector values (the
frg in ship ?type=frg).  xdump is fine, because it doesn't rely on
sentinels.  It dumps blank entries normally.

The bugs don't bite in the stock game, because the builtin
configuration files are all dense.

The sentinels are all null strings.  Set them to "" in the affected
tables' oninit callback.  Fix up code iterating over the tables to
ignore such entries.  This is precisely the code relying on sentinels,
plus xdump's xdvisible().
2011-06-25 16:51:56 +02:00
1e9c9c8273 Change stmtch() to recognize only null as sentinel
Before, it also recognized "" (since commit 844b654d, v4.2.14), but
no caller depends on that.

While there, back out the macro cleverness added in commit 844b654d.
2011-06-25 16:51:56 +02:00
29d7b30b2f Permit omitting rows at the end of tables nat and game
When not enough rows are supplied for a table with fixed size, treat
the rows missing at the end just like rows omitted elsewhere: make
them blank if the omission is permitted (tables nat and game), else
fail (tables sect and realm; no change).
2011-06-25 16:51:56 +02:00
4a4ec917f6 Forbid omitting rows in config item and sect-chr
Forbid omitting rows for tables with const fields: item and sect-chr.
This is consistent with the rule for truncation.

The server expects certain entries in these two tables, and
malfunctions when they're blank.  Omitting them in the builtin tables
has always left them blank, but deities are not supposed to edit them,
and maintainers are supposed to know what they're doing, so the issue
was deemed unimportant and ignored.  However, I plan to blank out
omitted rows in custom tables as well, and then the issue isn't
unimportant anymore.
2011-06-25 16:51:44 +02:00
4e23c45e61 Make xundump check each partial table supplies the same rows
Also streamline the error message for missing rows at end of table.
2011-06-25 16:51:44 +02:00
4c731905cf Make xundump reject out-of-order rows
This also catches duplicate rows.  Will make blanking out gaps easier.
2011-06-25 16:51:44 +02:00
cff42775ac Permit truncating table product
Truncating is actually fine for table product.  It's forbidden because
selector sname has flag NSC_CONST set.  I don't remember why sname was
made const in commit 445dfec9 along with item selector mnem, sect-chr
selector mnem and infrastructure selector name.  Unlike the other
tables, no code depends on product's builtin values.  Clear the flag.
2011-06-25 16:51:35 +02:00
3a3b9409b2 Clean up xundump's test whether table may be truncated
A table may be truncated when its size is variable and it doesn't have
const fields.  The old code tested table IDs instead.
2011-06-25 16:50:41 +02:00
63f972d31c Overhaul how xundump keeps track of current object
Factor tracking of cur_type, cur_obj, cur_id and cur_is_blank into a
set of functions.  They replace getobj().  While there, improve some
error messages.
2011-06-25 16:50:41 +02:00
465c0c8587 Move src/lib/subs/empobj.c back to src/lib/common/
Commit 77e95bd7 (v4.3.12) moved it from its natural home because
obj_nameof() required stuff from subs/.  Now that obj_nameof() is
gone, move it back.
2011-06-25 16:50:20 +02:00
1c93c5fbc8 Rename obj_nameof() to unit_nameof() and move to unitsub.c 2011-06-25 16:50:20 +02:00
766788480f Remove unused get_empobj_chr()
Unused since commit 5e77193c, v4.3.24.
2011-06-25 16:50:20 +02:00
79f289c365 Refuse to grow or truncate files with fixed size
Make ef_write() treat it like any other invalid write beyond the file
size: oops.  Be less harsh in ef_extend() and ef_truncate(): log an
error.
2011-06-25 16:50:20 +02:00
7d2269b5ae Make ef_open() extend files with fixed size automatically
Turns the fixed size into an invariant.  Before, the files utility
created them empty, then extended them.
2011-06-25 16:50:06 +02:00
31b9ff08f3 Move pln_oninit(), lnd_oninit(), nuk_oninit() to filetable.c
They set up invariants, and thus should be always active, not just in
the server.  Since ef_blank() isn't used for these files outside the
server right now, this isn't a bug fix, just cleanup.
2011-06-25 16:50:06 +02:00
3fe3cd376f Move file initialization from files.c to empfile oninit()
files.c writes initial contents to game state files with fixed size.
Necessary for setting up invariants, such as struct sctstr members
sct_x, sct_y matching sct_uid.

Do that from the oninit() callback, so ef_blank() sets up invariants
correctly.  Since ef_blank() isn't used for these files right now,
this isn't a bug fix, just cleanup.
2011-06-25 16:50:06 +02:00
576a3c60ed Initialize empfile user callbacks explicitly
Instead of stuffing NULL initializers into the cache initializer
macros UNMAPPED_CACHE(), ARRAY_CACHE(), PTR_CACHE(), ARRAY_TABLE().
In preparation of having some non-NULL initializers.
2011-06-25 16:50:06 +02:00