Commit graph

3719 commits

Author SHA1 Message Date
b62025e82c Fix test for capability sweep in shp_hit_mine()
Bogus array index, unpredictable result, can crash the server.  Broken
in commit ef7ea893, v4.3.24.
(cherry picked from commit 054eba7a1d)
2010-03-21 09:34:42 +01:00
e0b21266ce Fix interdiction not to wipe out target ship updates
Ships can expend shells to defend against missiles, in
shp_missile_defense().  Any shell use by the target ship got wiped out
when shp_missile_interdiction() wrote back the target ship, triggering
a seqno mismatch oops.

Ships get updated when they launch planes to intercept interdicting
planes, in mission_pln_equip().  Any petrol use by the target ship got
wiped out when shp_mission_interdiction() wrote back the target ship,
triggering a seqno mismatch oops.

Fix by re-reading the target ship in shp_damage_one().  This also
affects shp_fort_interdiction(), where it is not necessary.  A bit
inefficient, but let's keep this fix simple.
(cherry picked from commit 1d4fea32b8)
2010-03-21 09:34:35 +01:00
03a9ab2cf6 Fix navigate and march not to lay mines free of charge
do_unit_move() reads the ships into a list.  It re-reads them when it
prompts for sub-commands.  shp_nav_one_sector() writes them back when
it moves ships.

Mine-laying (sub-command 'd') updates the minelayer, invalidating the
copy in the list.  Any movement sub-command before the next prompt for
sub-commands wiped out this update, triggering a seno mismatch oops.

Happens only if 'd' is used without arguments, because remaining
sub-commands are discarded when there are arguments.

Broken when mine-laying was added in commits 2438fe7c, v4.3.7.

Same for march, commit 274c8e42, v4.3.7.

Fix by stopping after 'd' regardless of arguments.
(cherry picked from commit 28cc236e12)
2010-03-21 09:34:29 +01:00
8999261119 Fix navigate and march not to prompt for number of mines to lay
When sub-command 'd' was used without arguments, do_unit_move() failed
to supply the second argument to mine(), which duly prompted for it.
This contracticted info, and could trigger a generation oops.

do_unit_move() reads the ships into a list.  It re-reads them when it
prompts for sub-commands.  shp_nav_one_sector() writes them back when
it moves ships.

The mine prompt made the list stale.  Movement sub-commands before the
next prompt for sub-commands wrote back stale ships, triggering a
generation oops.  Example: "nav 15 dg".

Broken when mine-laying was added in commits 2438fe7c, v4.3.7.

Same for march, commit 274c8e42, v4.3.7.
(cherry picked from commit 45106ab91f)
2010-03-21 09:34:23 +01:00
7f3f9c6726 Nuclear-tipped missile exploding on launch could not damage base
Commit a269cdd7 (v4.3.23) removed the nuclear damage.  But it left the
nuke on the missile, which made pln_damage() oops and return zero
damage.

Fix by destroying the nuke separately.
(cherry picked from commit 876f3424b0)
2010-03-21 09:34:09 +01:00
b14edd0f7c Fix news for torpedo attack's return torpedo
When a torpedo attack triggered a return torpedo, the news reported it
to be fired by the attacker instead of the defender.
(cherry picked from commit bb5abd95e0)
2010-03-21 09:33:54 +01:00
bd07ee186b Interdiction attacked submarines with surface-only weapons
shp_mission_interdiction() used MI_INTERDICT instead of MI_SINTERDICT.
Broken in commit cd8fe31e, v4.3.24.
(cherry picked from commit 2dd97dbd00)
2010-03-10 09:44:31 +01:00
1f2865387a Fix unsafe use of shared buffers in commands drawing maps
Maps are generally drawn into static scratch buffers.  Each command
has its own buffers.

Static scratch buffers are safe as long as they're never used across
yields.  Player output can yield unless the command has flag C_MOD
set.  Commands lradar, path, radar, route, satellite, sect, survey
hadn't.  If such a command yields while using scratch buffers, another
instance of the command can clobber them.

Abuse seems tricky, but possible: if a malicious player stalls output
just right, a command yields while printing a map from the scratch
buffer.  It resumes only when the malicious player reads some output.
If another player runs the same command before that, it overwrites the
same static scratch buffer with its map.  The malicious player
receives the last such run's map.

4.2.8 fixed the same bug for bmap, lbmap, lmap, map, nmap, pbmap,
pmap, sbmap and smap.

All were broken in 4.2.0.  Except radar maps (lradar and radar) were
already broken in Empire 2 for AIX.
(cherry picked from commit 8bdb5c5c1b)
2010-03-10 09:44:27 +01:00
069fb10409 Generation numbers didn't catch all potential yields on output
io_output_if_queue_long() called ef_make_stale() only for long queues.
Missed in commit 2fa5f652, v4.3.24.
(cherry picked from commit a38c47a22c)
2010-03-10 09:44:22 +01:00
065881143e Change fairland not to reject small worlds without trying
Instead, print a warning and try.  It may well work, and when it
doesn't, it fails cleanly.
(cherry picked from commit de81e4e20a)
2010-02-06 21:38:04 +01:00
aab337d2e3 Document fortress maintenance cost in info Hvy-Plastic 2010-01-26 22:49:51 +01:00
1227140c67 Update game name and URL for Hvy Plastic 2 in info Hvy-Plastic 2010-01-26 22:49:51 +01:00
48b72af69a Document server time in info Hvy-Plastic 2010-01-26 22:49:51 +01:00
3def3727f8 New info Hvy-Plastic 2010-01-26 22:49:51 +01:00
29d2f5ccfe Change fairland island size probability distribution
Island size is randomly chosen from the interval [1..2*is+1], with
expected value is.  Use two dice to roll the size instead of one.
This makes extreme sizes much less likely.
2010-01-26 22:49:51 +01:00
880f3856d1 Make fairland record the island number in the deity territory
Can be useful for deities when further customizing their game setup.
2010-01-26 22:49:51 +01:00
d1bde67589 Fix recipient thread in output journal
Output journaling was cherry-picked from Hvy Metal II.  However, how
threads are identified in the journal changed since then.
journal_output_1() needs updating for that.
2010-01-26 22:49:51 +01:00
1cd3179b82 Fix journalling of output ids 2010-01-26 22:49:40 +01:00
6be2e3f8c5 Journal output lines instead of chunks
Output often arrives in chunks other than lines.  Hard to read in the
journal.  Delay journalling until we got a full line or our buffer is
exhausted.  This is less precise, but it'll do for now.
2010-01-26 22:44:20 +01:00
221471af6f New journal event output
To enable, set econfig key keep_journal to at least 2.  Output events
are *not* flushed to disk immediately.

Put it in Hvy Metal II now to gather real data for future testing of a
journal replay tool.
2010-01-26 22:44:20 +01:00
83fcc79bca New journal event command
Redundant information, but makes the journal easier to read.  The
redundancy might help making a journal replay tool robust.

Put it in Hvy Metal II now to gather some real data.
2010-01-26 22:44:20 +01:00
52acb4fb3c Update change log again for 4.3.24 2010-01-26 22:30:24 +01:00
2b14f876be Fix generation numbers for order command
orde() uses a "clever" trick to get away with just one
check_ship_ok(): it makes a copy of the ship in the beginning, and
checks it at the end.  Generation numbers (commit 2fa5f652) break this
trick.  It could be fixed by manually marking the ship fresh.
Instead, check the ship the stupid, straightforward way, without a
copy.
2010-01-26 22:20:16 +01:00
b54bc83e26 Normalize order's reaction to bad input
Consistently fail the command on bad or missing argument.  Before, it
merely skipped to the next ship in some cases.
2010-01-26 22:02:34 +01:00
7ac10453a2 Get third argument of "order l" the ordinary way
Now prompts when the argument is empty.  Before, that was interpreted
as zero.  Not likely to affect players.
2010-01-26 21:48:54 +01:00
ae6ad76516 Clean up dead code in orde()
Does not change optimized code (gcc -O) apart from __LINE__.
2010-01-26 21:38:31 +01:00
Ron Koenderink
eea24fb017 Fix windows client not always exiting
The call to WSAEnumNetworkEvents() was reseting network
events in particular WSAECONNRESET was sometimes being lost
causing the client to not exit.  The WSAEnumNetworkEvents()
was called from fd_is_socket() and has been replace with
getsockopt() to determine if the fd is socket or not.

Broken in commit 4d40a275, v4.3.23
2010-01-24 20:45:51 -06:00
0e3bf4c38a Update change log for 4.3.24 2010-01-19 08:40:43 +01:00
b8f5eaff0b Clean up dead stores
Does not change optimized code (gcc -O).

Spotted by the Clang Static Analyzer.
2010-01-19 08:40:42 +01:00
3650587dab Fix navigate/march crash on funny path arguments
For an argument consisting of a valid path plus whitespace,
do_unit_move() eventually passed the whitespace suffix to parse(),
then dereferenced player->argp[0].  But that was null.

Broken in commit 0c12d837, v4.3.7.  Trivial for players to trigger.
2010-01-19 08:40:42 +01:00
6c8ba9c3fd Fix player_login() not to print null pointer
When the input line contains only whitespace, player->argp[0] is null
after parse().  This condition was not checked, comtch() returned
M_IGNORE, and code handling that printed the null pointer.  Some
systems (GNU, Windows) deal gracefully with printing null strings,
others crash.  Trivial to trigger remotely.

Before the fix, the value of parse() was assigned, but never used, and
that was spotted by the Clang Static Analyzer.
2010-01-19 08:40:42 +01:00
8195d5fb88 Clean up useless getnatp() in conv(), nav_map(), tele()
Spotted by the Clang Static Analyzer.
2010-01-19 08:40:42 +01:00
8ededa44f9 Move -h to the end of the emp_server -h output
This is consistent with the other programs.
2010-01-19 08:40:42 +01:00
390841a40a Make empire, empsched and files catch extra operands
This also avoids a dead increment ap++ in src/client/main.c reported
by the Clang Static Analyzer.
2010-01-19 08:40:42 +01:00
fe0ef18e2b Make empire and files not print usage on bad option
Point to -h instead.  This is consistent with the other programs.
2010-01-19 08:40:42 +01:00
6386583c1c Fix lwpReschedule()'s assertion "have runnable thread"
If there is no runnable thread, we're deadlocked.  lwpReschedule() has
an assertion to catch this.  But it didn't work, and the code
following it would crash then.  Can't actually happen, because the
EventHandler thread is always runnable.  Spotted by the Clang Static
Analyzer.
2010-01-19 08:40:42 +01:00
43322c1cb7 Declare cant_listen() noreturn
Local analysis can now easily find out what's up.  Before, inter-
procedural analysis was required.  The Clang Static Analyzer
complained about a dereference of res that is actually fine.
2010-01-19 08:40:20 +01:00
9061ae7b9d Make CANT_HAPPEN() more obvious for static analysis
Local analysis can now easily find out what's up.  Before,
whole-program analysis was required.  The Clang Static Analyzer
complained about code that is actually fine.
2010-01-19 08:40:18 +01:00
ad80846283 Fix getpath() not to crash when path exceeds MAX_PATH_LEN
Trivial for players to trigger.  Broken in commit 0b0612ea, v4.3.16.
Spotted by the Clang Static Analyzer.
2010-01-19 08:40:17 +01:00
9b62b35424 Fix oops on escort, recon, and launch of satellite
Broken in commit 528df9ac, v4.3.23.  pln_equip() recovered fine.
2010-01-19 08:40:17 +01:00
73e25ff21e Update copyright notice 2010-01-19 08:40:17 +01:00
6e30ba88a4 Fix trailing whitespace 2010-01-19 08:40:17 +01:00
227854bca2 Stop ship and land unit movement on interdiction with no damage
Movement stops when shp_interdict() or lnd_interdict() report
interdiction.  However, they reported it only when there was
interdiction damage.

Zero interdiction damage commonly happens when interdicting missiles
miss, or all bombers abort.  Stopping regardless of damage makes more
sense there.

Moreover, not stopping is buggy: do_unit_move() needs to take care not
to wipe out updates made by interdiction to the moving ships or land
units.  It does so only when it stops.  Updates made by interdiction
without interdiction damage could get wiped out, triggering a seqno
mismatch oops.

Known ways moving ships and land units can get updated by interdiction
despite there is no interdiction damage:

* Interdicting bombers get intercepted by planes based on a navigating
  carrier, carrier gets charged petrol.  The bug wipes out the petrol
  use.

* Marching land units get interdicted by planes, but all planes miss.
  Sufficiently large collateral damage to the sector can still damage
  the land units.  The bug wipes out the damage to land units.

To make shp_interdict() and lnd_interdict() report interdiction
regardless of damage, change lnd_missile_interdiction(),
lnd_fort_interdiction(), lnd_mission_interdiction(),
shp_missile_interdiction(), shp_fort_interdiction(),
shp_mission_interdiction() to return whether there was interdiction.
Before, they returned whether there was damage.

Change unit_interdict(), perform_mission(), perform_mission_land(),
perform_mission_ship(), perform_mission_msl(), and
perform_mission_bomb() to return -1 for no interdiction, so that
callers can distinguish no interdiction from interdiction with no
damage.
2010-01-19 08:38:18 +01:00
05b56fa942 Clean up poorly chosen loop control variable names
Calling a counting loop's control variable q or z is tasteless
bordering on actively misleading.
2010-01-19 08:38:16 +01:00
3ce3b2e387 Simplify perform_mission() 2010-01-19 08:38:16 +01:00
5e77193cf0 Remove struct genlist member cp 2010-01-19 08:38:16 +01:00
2e69a24402 Remove perform_mission_land(), perform_mission_ship() parameter md 2010-01-19 08:38:16 +01:00
d471d684be Split up perform_mission()
Move code out of perform_mission() into new perform_mission_land(),
perform_mission_ship(), perform_mission_msl(), perform_mission_bomb().
2010-01-19 08:38:16 +01:00
0706836708 Make lnd_mission_interdiction() apply damage
To make lnd_mission_interdiction() work just like
shp_mission_interdiction().
2010-01-19 08:37:07 +01:00
f8e7fb8ca8 New lnd_mission_interdiction()
Factored out of lnd_interdict().  No functional change.
2010-01-19 08:37:05 +01:00