Commit graph

4276 commits

Author SHA1 Message Date
3d3d272eef Don't let scrap give away civilians
Scrapping unloads everything.  Even stuff that unload can't: foreign
civilians.  Kill them off instead, like scuttle does.
2012-07-13 20:15:33 +02:00
612ec6257d Pilots and air cargo now spread the plague
Planes flying one-way with crew or cargo spread plague from their old
base to their new base.  Planes dropping cargo spread plague from
their base to the drop's target sector.
2012-07-13 20:15:33 +02:00
a8739d86e3 Clarify info Plague slightly 2012-07-13 20:15:33 +02:00
bad2fd5aac Streamline plist initialization
msl_equip(), find_escorts() and perform_mission() memset() the plist,
then assign to all members but load.  Just zero load instead, like
getilists(), msl_sel() and pln_sel() do.
2012-07-13 20:15:33 +02:00
48f3d1c033 Initialize struct plist member queue properly in msl_equip()
Harmless, because queue isn't actually used.  Clean it up anyway.
2012-07-13 20:15:33 +02:00
154f04f218 scripts: Use mailx rather than mail, and drop bogus -e 2012-07-13 20:15:33 +02:00
729cf65e12 Don't let fly and drop give away civilians
Flying them to a foreign destination magically changes their
allegiance.  Prohibit that.

Equivalent change was already in commit 35887222 (v4.2.17) but got
reverted immediately (commit 20199b22), because fly and drop should
stay consistent with load, which let you give away civilians then.  No
more since commit 92a366ce (v4.3.20).  This change makes fly and drop
consistent with load again.
2012-07-13 20:15:33 +02:00
b4acb73fd1 Replace pln_oneway_to_carrier_ok() by pln_can_land_on_carrier()
Avoids reading the target ship again.
2012-07-13 20:15:33 +02:00
d9a915a05b Replace pln_onewaymission() by pln_where_to_land()
New function reads and returns target sector/ship.  Avoids reading the
target sector unnecessarily.  Callers receive the target ship, not
just its number.  Next commit will put it to use.
2012-07-13 20:14:10 +02:00
41b2fa433f Fix fly to permit flying civs to a carrier in an occupied sector
Broken in commit 35887222, v4.2.17.
2012-07-12 19:52:33 +02:00
72f1e22b95 Drop could_be_on_ship()'s load count parameters
Just one caller wants them.  Inline that call, and simplify the
others.
2012-07-12 19:52:33 +02:00
665d0d723d Inline fit_plane_on_ship() and fit_plane_on_land()
Just one call site each.
2012-07-12 19:52:33 +02:00
b60e5be22c Don't let planes fly to a carrier without sufficient space
We test whether the the carrier has space for each plane individually
instead of whether it has space for all of them.  The planes that fit
land, the others abort and get teleported home.  Abusable.

pln_oneway_to_carrier_ok() was created in commit 1127762c (v4.2.17) to
fix almost the same bug.  It worked fine then, because
fit_plane_on_ship() worked with load counters, and incremented them.

Broken in commit 3e370da5 (v4.3.17), which made fit_plane_on_ship()
count the loaded planes, to permit the removal of load counters.  But
unlike load counters, loaded planes don't change during
pln_oneway_to_carrier_ok().  Thus, each plane is checked individually.

Fix by tallying all the planes before checking for space.
2012-07-12 19:51:57 +02:00
81efebd367 Factor inc_shp_nplane() out of could_be_on_ship() 2012-06-24 08:49:57 +02:00
ae279968b9 Factor ship_can_carry() out of could_be_on_ship() 2012-06-24 08:49:57 +02:00
5424142f62 Fix tend to refuse tending civilians to foreign ships
Broken when Chainsaw 2 added tending to allies.
2012-06-24 08:49:34 +02:00
e16fc41b2e Fix tend not to leak which commodities are loaded on friendlies
Tending a negative number of commodities takes from the target ships.
The target ships must be owned.  Tend complains when the target
doesn't have the commodity loaded.  It does that even for friendly
foreign ships.  Don't.

Broken when Chainsaw 2 added tending to allies.
2012-06-24 08:47:08 +02:00
20b2598214 Fix tend from target not to stop on foreign target
Tending a negative number of commodities takes from the target ships.
When a target ship is foreign, tend silently stops.  This is wrong.
Fix it to skip foreign target ships instead.

Broken when Chainsaw 2 added tending to allies.
2012-06-24 08:45:55 +02:00
f11071f3b7 Let march sub-command 'm' sweep own and allied landmines 2012-06-11 17:28:19 +02:00
0b7fba038a Land units no longer sweep allied landmines
They don't hit them since commit fe372539, v4.3.27.  Sweeping was
forgotten then.

Closes #717591.
2012-06-11 17:28:14 +02:00
bf11d42c87 Fix info bdes on funny designation arguments
Quoting "?" was accidentally fixed in commit 90631d56, v4.3.11.
Update documentation accordingly.

Closes #736592.
2012-06-11 17:02:15 +02:00
150b2c5165 Fix bmap commands not to parse empty flags argument as "revert"
Broken in commit a00f9e20, v4.3.27.
2012-06-11 17:02:15 +02:00
1118f1c0ca Update copyright notice 2012-06-10 10:52:22 +02:00
ec41e85ad3 Bump version to 4.3.31 2012-06-10 10:42:17 +02:00
b385ed90eb Update change log again for 4.3.30 2012-05-22 20:56:59 +02:00
ea94ec2f18 Disable damage to base when missile explodes on launch
When a missile explodes on launch, it has a 33% chance to damage its
base.

Unfortunately, damaging the base breaks callers that call msl_launch()
for each member of a list of missiles created by msl_sel() or
perform_mission().  Damage to the base can damage other missiles
there.  Any copies of them in the list become stale.  When
msl_launch() modifies and writes back such a stale copy, the damage
gets wiped out, triggering a seqno oops.

Affects missile interdiction and interception using missiles with
non-zero load.  Stock game's ABMs have zero load, so interception is
safe there.  Relatively harmless in practice.  Broken in Empire 2.

Instead of fixing the bug, simply disable damage to the base for now.
2012-05-22 20:56:47 +02:00
0dd59211aa Fix march not to wipe out concurrent updates
March code reads the land units into a land unit list, and writes them
back when it changes them, e.g. when a land unit stops.  If a land
unit changes in the land unit file while it is in such a land unit
list, the copy in the land unit list becomes stale, and must not be
used.

To that end, do_unit_move() calls lnd_mar() after prompting for path
or destination.  lnd_mar() re-reads all the land units.
Unfortunately, it still writes back stale copies in certain
circumstances.  Known ways to trigger such writes:

* Deity loads land unit onto a ship or land unit

* Land unit's crew killed just right, e.g. by collateral damage from
  interdiction, followed by additional updates, such as shell fire
  damage

* Sector no longer owned or allied, e.g. allied sector captured by an
  enemy (own sector would kill or retreat the land unit)

Writing a stale copy wipes out the updates that made the copy stale,
and triggers a seqno mismatch oops.  For instance, damage that follows
killing of all crew by collateral damage from interdiction is wiped
out.  If no damage follows, we still get a generation oops.
2012-05-22 20:38:19 +02:00
a694e49343 Fix navigate not to wipe out concurrent updates
Navigation code reads the ships into a ship list, and writes them back
when it changes them, e.g. when a ship stops.  If a ship changes in
the ship file while it is in such a ship list, the copy in the ship
list becomes stale, and must not be used.

To that end, do_unit_move() calls shp_nav() after prompting for path
or destination.  shp_nav() re-reads all the ships.  Unfortunately, it
still writes back stale copies in certain circumstances.  Known ways
to trigger such writes:

* Deity sets a sail path

* Ship's crew gone, e.g. killed by shell fire

* Sector no longer navigable, e.g. harbor shelled down, or bridge
  built

Writing a stale copy wipes out the updates that made the copy stale,
and triggers a seqno mismatch oops.  For instance, ship damage that
kills all crew while the ship is being navigated gets wiped out.
2012-05-22 20:38:19 +02:00
Ron Koenderink
0700d97fe3 Fix Windows build: gettimeofday() and SHUT_WR missing
Commit 904822e3 introduced use of SHUT_WR, which Windows calls
SD_SEND.  Add the obvious work-around.

Commit 49ae6a7b introduced use of gettimeofday(), which the Microsoft
CRT lacks.  Add a replacement based on _ftime_s().
2012-05-22 20:38:10 +02:00
6c5dfc870e Update change log again for 4.3.30 2012-05-05 16:18:14 +02:00
4801fad4a8 Fix buffer overruns in fairland for island size zero
Fairland creates islands with size 1 + random() % (2 * is - 1), where
"is" is either chosen by the user (fourth command line argument) or
defaults to half the continent size (second command line argument).
Negative values are silently replaced by zero.

Not only does value zero make no sense, it also breaks the code: the
island size is always one then (because random() % -1 is zero), but
allocate_memory() provides only space for zero sectors in sectx[],
secty[] and sectc[].  This leads to buffer overruns in try_to_grow(),
find_coast(), elevate_land, set_coastal_flags().  Can smash the heap.

Fix by changing the lower bound from zero to one.  Diagnosed with
valgrind.  Has always been broken.
2012-05-05 16:13:08 +02:00
3464a4a9d0 Fix an out-of-bounds subscript in fairland
elevate_land() tests for capital sector in three places.  The third
one is broken: half of the test is done even for islands, subscripting
capx[] and possibly capy[] out of bounds.  This could screw up
elevation (unlikely) or crash (even less likely).  Diagnosed with
valgrind.

Broken since the test was added in Chainsaw 3.12.  Parenthesis were
added blindly 4.0.11 to shut up the compiler.  Reindentation (commit
9b7adfbe and ef383c06, v4.2.13) made the bug stand out more, but it
still managed to hide in the general ugliness of fairland's code.
2012-05-05 13:46:15 +02:00
b4b38bf859 Fix typo in change log 2012-05-05 09:17:00 +02:00
fe33d92ed0 Update change log again for 4.3.30 2012-05-01 18:39:35 +02:00
540526a140 Start the makefile's dependency section with a comment
Just to separate it visually from the preceding section
2012-05-01 18:37:50 +02:00
5729c18458 Journal login before changing the player thread's name
The journal logs a thread name for each event.  The player thread name
changes on entry to the playing phase.  Connecting old and new name
isn't as easy as it should be:

    Sun Apr 29 12:13:39 2012     Conn29 input coun POGO
    Sun Apr 29 12:13:39 2012     Conn29 input pass peter
    Sun Apr 29 12:13:39 2012     Conn29 input play
    Sun Apr 29 12:13:39 2012     Play#0 login 0 127.0.0.1 armbru
    Sun Apr 29 12:15:39 2012     Play#0 logout 0

To connect Conn29 with Play#0, you have to know that country#0 is
named POGO.

Fix that by logging login before the thread name change:

    Sun Apr 29 12:17:41 2012     Conn29 input coun POGO
    Sun Apr 29 12:17:41 2012     Conn29 input pass peter
    Sun Apr 29 12:17:41 2012     Conn29 input play
    Sun Apr 29 12:17:41 2012     Conn29 login 0 127.0.0.1 armbru
    Sun Apr 29 12:19:41 2012     Play#0 logout 0

Now "Conn29 login 0" makes the connection obvious.

This involves moving journal_login() from player_main() before
empth_set_name() in its caller play_cmd().  Move journal_logout() as
well, for symmetry.

If player_main() fails, we now log login/logout instead of nothing in
the journal.  That's okay.  Note that before commit c9f21c0e (v4.3.8),
we logged just login then.
2012-05-01 18:37:49 +02:00
eed7a46aed Fix arm to require nuke and plane to be in the same sector
It happily arms a plane with a remote nuke.  The nuke gets teleported
to the plane when the plane moves (a two-way sortie doesn't count as
move).  Broken in 4.3.3.  Reported by Harald Katzer.
2012-05-01 18:35:32 +02:00
4aaea42a83 Update change log for 4.3.30 2012-04-26 20:15:48 +02:00
0b1218f164 Document login_grace_time and the shutdown phase properly 2012-04-26 20:08:58 +02:00
bc629096c0 Don't send "idle connection terminated" in login phase
Message was introduced in commit 08b94556, v4.3.20.  Revert this
change, because it's undocumented, and probably not useful for
clients.
2012-04-26 20:08:57 +02:00
2503e41bd2 Rename play_lock back to update_lock
It was renamed to play_lock because it synchronized not just updates
but also shutdown.  Since the previous commit, it again only
synchronizes updates.  Rename it back.

Also move its initialization next to shutdown_lock's.
2012-04-26 20:08:57 +02:00
49ae6a7b9d Fix synchronization between shutdown and player threads
shutdwn() sets the EOF indicator, aborts the running command, if any,
forbids sleeping on I/O and wakes up the player thread, for all player
threads in state PS_PLAYING.  It takes play_lock to prevent new
commands from running.  It then waits up to 3s for player threads to
terminate, by polling player_next(), to let output buffers drain.

Issues:

1. Polling is lame.

2. New player threads can still enter state PS_PLAYING.  They'll block
   as soon as they try to run a command.  Somehwat unclean.

3. We can exit before all player threads left state PS_PLAYING, losing
   a treasury update, play time update, and log entries.  Could happen
   when player threads blocked on output until commit 90b3abc5 fixed
   that; its commit message describes the bug's impact in more detail.
   Since then, the bug shouldn't bite in practice, because player
   threads should leave state PS_PLAYING quickly.

Fix by introducing shutdown_lock: player threads in state PS_PLAYING
hold it shared, shutdwn() takes it exclusive, instead of play_lock.
Takes care of the issues as follows:

3. shutdwn() waits until all player threads left state PS_PLAYING, no
   matter how long it takes them.

2. New player threads block before entering state PS_PLAYING.

1. shutdwn() still polls up to 3s for player threads to terminate.
   Still lame.  Left for another day.
2012-04-26 20:05:28 +02:00
86f0294573 Start player thread shutdown grace time at shutdwn() entry
Before, it was started after all commands aborted.  Shouldn't make a
difference in practice, as command abortion is supposed to be quick.
2012-04-26 19:57:19 +02:00
786e2a99d5 Clean up superfluous includes 2012-04-26 19:57:19 +02:00
f75c03dfd9 Belatedly update convert's c_form
Commit 82c91665 (v4.3.16) removed its optional third argument without
updating c_form.
2012-04-26 19:57:19 +02:00
02293b9bd1 Document the header for empmod.c and trdsub.c in prototypes.h 2012-04-26 19:57:19 +02:00
f802630fa3 Document execute()'s subtle use of player->aborted 2012-04-26 19:57:19 +02:00
a1003ea7da io_shutdown() is now unused, remove 2012-04-26 19:57:19 +02:00
eb25be08d4 Change login command kill to kill less ruthlessly
The victim's connection closes without any explanation.  Output may be
lost.  This is because kill_cmd() kills by calling io_shutdown(),
which shuts down the socket and drains the I/O queues.

How this makes the victim's thread terminate is a bit subtle: shutting
down the socket makes it ready.  If the victim's thread is waiting for
I/O, it wakes up.  Since all further reads return EOF, and all further
writes fail, the command terminates quickly (short of inifinite loop
bugs), then the command loop, and finally the thread.

To make kill behave more nicely, change kill_cmd() to work exactly
like server shutdown: send a flash message to the victim, set his EOF
indicator, abort the command, forbid sleeping on I/O, wake up the
victim's thread.  Just as reliable, but doesn't lose output.

If the victim's client fails to close his connection, the victim's
thread may still linger in state PS_SHUTDOWN for up to
login_grace_time (default 120s).  An attacker could try to use that to
make the server run out of file descriptors or memory, but simply
connecting achieves the same effect more cheaply.
2012-04-26 19:57:19 +02:00
918f3ec6ae Separate max_idle_visitor from max_idle
Cut it to 5 minutes, from max_idle's 15.

Since max_idle now applies only to authenticated players, increasing
it is perfectly safe.
2012-04-26 19:57:19 +02:00