]> git.pond.sub.org Git - empserver/log
empserver
14 years agoGet rid of msl_launch_mindam()
Markus Armbruster [Sat, 10 Oct 2009 20:32:18 +0000 (16:32 -0400)]
Get rid of msl_launch_mindam()

It's awkward, especially in shp_missile_interdiction().  Inline into
callers and simplify.

14 years agoSimplify control logic in msl_intercept()
Markus Armbruster [Sat, 10 Oct 2009 16:23:38 +0000 (12:23 -0400)]
Simplify control logic in msl_intercept()

14 years agoDon't attempt to hide owner of sub-launched satellite
Markus Armbruster [Sat, 10 Oct 2009 15:54:49 +0000 (11:54 -0400)]
Don't attempt to hide owner of sub-launched satellite

The attempt was pointless, because the recipient of the message could
see the owner on skywatch, and the news reported it as well.

14 years agoFix typo in info Selector
Markus Armbruster [Sat, 10 Oct 2009 15:07:29 +0000 (11:07 -0400)]
Fix typo in info Selector

14 years agoMove msl_equip() to callers, internal linkage
Markus Armbruster [Mon, 5 Oct 2009 11:27:43 +0000 (07:27 -0400)]
Move msl_equip() to callers, internal linkage

14 years agoMove "Releasing RV's" message into detonate()
Markus Armbruster [Mon, 5 Oct 2009 11:25:45 +0000 (07:25 -0400)]
Move "Releasing RV's" message into detonate()

14 years agoLimit nukes to strategic missions
Markus Armbruster [Mon, 5 Oct 2009 11:02:40 +0000 (07:02 -0400)]
Limit nukes to strategic missions

Before Empire 2, nukes could be delivered only with bomb (special
mission 'n', airburst only) and launch (targeting sectors or
satellites only).

Empire 2 made nukes available for any kind of bombing, and for any
missile strike on sectors or ships.  This included interdiction and
support missions.  Nuclear-tipped anti-sats and bomb mission n were
removed.

Unfortunately, this was done in a messy way, which led to
inconsistencies and bugs.  The problem is that ordinary damage affects
just the target, while nuke damage affects an area.  Code dealing with
plane damage was designed for the former.  Instead of rewriting it to
cope with area damage cleanly, nuke damage got shoehorned into
pln_damage(), the function to compute conventional plane damage, as a
side effect: computing damage blasted sectors in the area.

If the plane carried a nuke, pln_damage() returned zero (conventional)
damage.  Without further logic, this simply bypassed the code to apply
damage to the target.  This worked out okay when the target already
got damaged correctly by the side effect.

However, some targets are immune to the side effect: when interdicting
a move or explore command, the commodities being moved are not in any
sector.

For other targets, damage has effects other than damaging the target:
offensive and defensive support don't apply the (conventional) damage
to the target sector.  Instead, they turn it into a combat bonus.
Without further logic, nuclear damage doesn't contribute to that.

To make all that work, pln_damage() returned the nuclear damage for
ground zero as well.  Because a plane does either conventional or
nuclear damage, one of them is always zero.

Most callers simply ignored the nuclear damage, and applied only the
conventional damage.

Bug: land units and ships failed to retreat when pin-bombed or
missiled with a nuke.  That's because they received zero conventional
damage.

The mission code flies planes and missiles and tallies their damage.
This mission damage included nuclear damage at ground zero (except for
missiles sometimes, see below), to make support and commodity
interdiction work.  Unfortunately, this broke other things.

Bug: when bombers interdicted ships or land units, nukes first damaged
the ships or land units by the side effect, then again through mission
damage.  Interdicting missiles had a special case to avoid this.

Bug: when interdicting move, explore or transport, nukes first damaged
the sector by the side effect, then again through mission damage's
collateral damage.

There may well be more bugs hiding in this mess.

The mess is not worth fixing.  While the idea of interdicting and
supporting with nukes sounds kind of cool, I believe it's pretty
irrelevant in actual play.

Instead, go back to a variation of the original rules: nukes can be
delivered only through bomb mission 's' and launch at sectors.

Make arm reject marine missiles in addition to satellites, ABMs and
SAMs, and clear the mission.  Make mission reject planes armed with
nukes.  Oops when they show up in mission_pln_equip() anyway.

Make pln_equip() allow planes with nukes only for missions 's' and
't'.

Clean up pln_damage() to just compute damage, without side effect.
Change strat_bomb() and launch_missile() to detonate nukes.  Simplify
the other callers.  Parameter mission of msl_launch_mindam() is now
unused, remove it.

Missiles exploding on launch no longer set off their nukes.  That was
pretty ridiculous anyway.

14 years agoRemove unused missions from mission_pln_equip()
Markus Armbruster [Mon, 5 Oct 2009 09:46:20 +0000 (05:46 -0400)]
Remove unused missions from mission_pln_equip()

14 years agoImprove launch diagnostic messages, switch off supply
Markus Armbruster [Mon, 5 Oct 2009 09:40:39 +0000 (05:40 -0400)]
Improve launch diagnostic messages, switch off supply

msl_equip() used mission_pln_equip(), which is for automatic defenses,
and therefore silent.  Its users launch_as(), launch_missile() and
launch_sat() printed failure diagnostics based on assumptions on what
could go wrong.

Switch to the appropriate function for commands, pln_equip(), and
remove the guesswork.  Implement mission 'i' there.  When launching
from a foreign base, its owner now gets informed.  Unimportant at this
time, as players can't easily deploy missiles in foreign bases.

This change also switches off automatic supply for launch.  Consistent
with bomb.

14 years agoMake anti-sat launch consistent with interception
Markus Armbruster [Sun, 4 Oct 2009 22:42:15 +0000 (18:42 -0400)]
Make anti-sat launch consistent with interception

When a manually launched anti-sat hits, it now always destroys the
satellite.  This matches what it does when it intercepts
automatically.  Before, it only damaged the satellite.

14 years agoFix satellite interception not to break "positioned over" line
Markus Armbruster [Sun, 4 Oct 2009 22:00:14 +0000 (18:00 -0400)]
Fix satellite interception not to break "positioned over" line

14 years agoComment fix
Markus Armbruster [Sun, 4 Oct 2009 21:12:22 +0000 (17:12 -0400)]
Comment fix

14 years agoImprove message when refusing to load plane on unsuitable ship
Markus Armbruster [Sun, 4 Oct 2009 20:44:06 +0000 (16:44 -0400)]
Improve message when refusing to load plane on unsuitable ship

Test more specific causes before more general ones.  Also get rid of
silly strcpy().

14 years agoDon't permit nukes on satellites, ABMs and SAMs
Markus Armbruster [Sun, 4 Oct 2009 18:54:39 +0000 (14:54 -0400)]
Don't permit nukes on satellites, ABMs and SAMs

Before, satellites could be disarmed and armed even in orbit.  Nukes
on satellites went along into orbit, where they did nothing in
particular.

Nukes on ABMs and SAMs were lost without effect when their missile
intercepted.

The stock game is not affected, because its satellites, ABMs and SAMs
all have zero load.

14 years agoDrop capabilities stealth and half-stealth
Markus Armbruster [Sun, 4 Oct 2009 17:13:36 +0000 (13:13 -0400)]
Drop capabilities stealth and half-stealth

These were leftovers from Chainsaw, and their only remaining effect
was a flak bonus.

The got replaced except for flak by plane selector stealth under
Chainsaw option STEALTHV, which became mandatory in Empire 2.  It is
unclear why STEALTHV didn't cover flak.  No planes with these
capabilities have existed in the stock game since Empire 2.

14 years agoRemove redundant load checks before pln_damage()
Markus Armbruster [Sat, 3 Oct 2009 20:32:03 +0000 (16:32 -0400)]
Remove redundant load checks before pln_damage()

pln_damage() copes with any load just fine.

14 years agoSimplify how plane cargo is tracked
Markus Armbruster [Sat, 3 Oct 2009 20:25:50 +0000 (16:25 -0400)]
Simplify how plane cargo is tracked

Fold struct plist members bombs (used for bombing runs) and misc (used
for everything else) into a single member load.

14 years agoPenalize fighter combat value for any load, not just bombs
Markus Armbruster [Sat, 3 Oct 2009 20:02:17 +0000 (16:02 -0400)]
Penalize fighter combat value for any load, not just bombs

This can affect only planes with capabilities intercept and either
cargo or mine.  No such planes exist in the stock game.

14 years agoFix bomb for non-tactical cargo bomber
Markus Armbruster [Sat, 3 Oct 2009 19:57:49 +0000 (15:57 -0400)]
Fix bomb for non-tactical cargo bomber

The various bombing functions silently skipped planes not carrying
bombs.  This sanity check was wrong: it checked capabilities "tactical
or not cargo" instead of "tactical or bomber", and failed for
non-tactical cargo bombers.  No such planes exist in the stock game.
The broken check comes from Chainsaw; it replaced an equally wrong
"not cargo" check.

Because pln_sel() lets only suitable planes go on a bombing run, the
broken sanity check is unnecessary.  Drop it.

14 years agoRevise rules for cargo plane loads
Markus Armbruster [Sun, 27 Sep 2009 22:03:13 +0000 (18:03 -0400)]
Revise rules for cargo plane loads

There are three ways to fly cargo: transport (fly command with a
commodity argument), cargo drops (drop command that isn't a sea mine
drop), and paradrops.

A cargo flight can be either an airlift or an airdrop.  Airlifts carry
more cargo than airdrops.  A cargo drop or paradrop with a non-VTOL
plane is an airdrop.  Anything else is an airlift.

Before, paradrop always behaved like an airdrop, regardless of VTOL,
and drop always like an airlift.  This made little sense.

Effect of the change on the stock game: paradrop with tc carries twice
the punch, and np/tr/jt can drop less than they can fly.  In
particular, tr can't drop guns anymore, and jt can drop only one
instead of three.

14 years agoSimplify load computation in pln_equip(), mission_pln_equip()
Markus Armbruster [Sun, 27 Sep 2009 21:35:13 +0000 (17:35 -0400)]
Simplify load computation in pln_equip(), mission_pln_equip()

14 years agoSimplify plane selection for drop, fly, recon and sweep
Markus Armbruster [Sun, 27 Sep 2009 19:07:57 +0000 (15:07 -0400)]
Simplify plane selection for drop, fly, recon and sweep

Plane flying commands first select the planes to fly the mission and
their escorts, then equip them.  They all fail when no planes to fly
the mission can be equipped.

Unlike bomb and paradrop, commands drop, fly, recon and sweep had an
additional check that made them fail when no planes to fly the mission
could be selected.  Because "none selected" implies "none equipped",
the additional check is redundant.  Remove it.

While there, break lines in calls of pln_sel() more tastefully.

14 years agoMake bomb require capability bomber or tactical
Markus Armbruster [Sun, 27 Sep 2009 18:44:39 +0000 (14:44 -0400)]
Make bomb require capability bomber or tactical

Before, bomb selected any plane, but planes with zero load could not
be equipped.  Cargo planes could be equipped fine, and they flew bombs
to the target, where they silently vanished.

Closes#1388263.

14 years agoMake sweep require capability sweep
Markus Armbruster [Sun, 27 Sep 2009 17:53:40 +0000 (13:53 -0400)]
Make sweep require capability sweep

Before, sweep accepted any plane.  Planes without capability sweep
flew an ordinary recon mission.

Partial fix for #1388263.

14 years agoMake drop require capability cargo
Markus Armbruster [Sun, 27 Sep 2009 17:32:34 +0000 (13:32 -0400)]
Make drop require capability cargo

Before, drop worked like fly: it accepted any plane, but planes
without capability cargo dropped nothing.

Partial fix for #1388263.

14 years agoClarify flying command info pages on plane selection
Markus Armbruster [Sun, 27 Sep 2009 17:12:36 +0000 (13:12 -0400)]
Clarify flying command info pages on plane selection

14 years agoDon't let players paradrop their own sectors
Scott C. Zielinski [Sun, 27 Sep 2009 16:39:54 +0000 (12:39 -0400)]
Don't let players paradrop their own sectors

Such a paradrop always failed, and the paratroopers were lost.

14 years agoSimplify wantflags calculation in bomb(), fly(), para(), reco()
Markus Armbruster [Sun, 27 Sep 2009 15:10:08 +0000 (11:10 -0400)]
Simplify wantflags calculation in bomb(), fly(), para(), reco()

14 years agoClean up outmoded tests for paradrop capability
Markus Armbruster [Sun, 27 Sep 2009 14:55:33 +0000 (10:55 -0400)]
Clean up outmoded tests for paradrop capability

Initially, paradrop capability was implied both by capability cargo
and by capability VTOL.  Chainsaw changed para() to require cargo, and
added compile-time option PARAFLAG to additionally require new
capability para.  The optional PARAFLAG rule became mandatory in
Empire 2.

Chainsaw left the old tests for "cargo or VTOL" in place.  Because
para() checked "cargo and para" first, the old tests for "cargo or
VTOL" always passed, so they had no effect.

Clean them up anyway.

14 years agoMake passing paradrop & mine cargo to pln_arm() & friends optional
Markus Armbruster [Sun, 27 Sep 2009 13:31:50 +0000 (09:31 -0400)]
Make passing paradrop & mine cargo to pln_arm() & friends optional

These missions imply the cargo type, just like bombing missions.  Use
the implied type instead of cargo type parameter ip there.  Parameter
ip is now optional except for missions 't' (transport) and 'd' (drop).

Simplify para() not to pass the optional cargo type.  Leave drop()
alone, because always passing the type is simpler there.

14 years agoRemove superfluous variable ip from bomb()
Markus Armbruster [Sun, 27 Sep 2009 13:20:10 +0000 (09:20 -0400)]
Remove superfluous variable ip from bomb()

14 years agoSimplify calling of pln_arm() & friends
Markus Armbruster [Mon, 14 Sep 2009 01:35:17 +0000 (21:35 -0400)]
Simplify calling of pln_arm() & friends

pln_arm(), pln_equip(), mission_pln_arm() mission_pln_equip() took a
mission parameter encoding the kind of sortie (strategic bomb,
pinpoint bomb, transport, ...), a flag parameter to further specify
the plane's role, and a parameter ip to specify the load.

The flags argument was always either P_F (intercept), P_F | P_ESC
(escort), or zero (any other role).

With non-zero flags, mission and ip argument were not used in any way.

Use mission 'e' and null load for escorts, and remove flags.
Intercept can still be identified by mission zero.

Also change pln_mobcost() to take a mission parameter instead of
flags, so that pln_arm() and mission_pln_arm() can simply pass on
their mission.

14 years agoFix pln_equip()'s check for foreign civilians
Markus Armbruster [Sun, 27 Sep 2009 00:43:01 +0000 (20:43 -0400)]
Fix pln_equip()'s check for foreign civilians

Check the true load instead of the ip parameter.  Makes a difference
only when callers pass a bogus ip that isn't actually used.  Happens
for escorts, but then the call can only be reached for deities,
because for mortals the transports fail before the escorts.

14 years agoSimplify reco() not to pass useless flags to pln_arm()
Markus Armbruster [Mon, 14 Sep 2009 01:13:31 +0000 (21:13 -0400)]
Simplify reco() not to pass useless flags to pln_arm()

Flags P_S and P_I have no effect.

14 years agoStreamline missile hit chance messages
Markus Armbruster [Sun, 13 Sep 2009 17:44:07 +0000 (13:44 -0400)]
Streamline missile hit chance messages

Don't print hit chance for nuclear warheads, it's always 100%.
Instead, print "Arming nuclear warheads" there.  That message is now
printed after interception instead of before.

14 years agoChange launch of anti-sat to take plane# argument
Markus Armbruster [Sun, 13 Sep 2009 17:19:19 +0000 (13:19 -0400)]
Change launch of anti-sat to take plane# argument

Before, it took a sector argument, and targeted the lowest-numbered
satellite there.  Rather inconvenient when your own satellite masks
one of the enemy's.

Moreover, the command could be abused to find all sectors with
satellites.  Now it can "only" be abused to find satellite ids, and
whether they're in range.  Still not ideal, but tolerable.

14 years agoEnable marine msl. unconditionally, remove option PINPOINTMISSILE
Markus Armbruster [Sun, 13 Sep 2009 15:37:17 +0000 (11:37 -0400)]
Enable marine msl. unconditionally, remove option PINPOINTMISSILE

Deities can still control them by customizing table plane-chr.

14 years agoUpdate info version example to current output
Markus Armbruster [Sun, 13 Sep 2009 15:31:06 +0000 (11:31 -0400)]
Update info version example to current output

14 years agoSimplify satmap() to avoid compiler warning
Markus Armbruster [Mon, 7 Sep 2009 19:31:32 +0000 (15:31 -0400)]
Simplify satmap() to avoid compiler warning

14 years agoSimplify detonate() to avoid compiler warning
Markus Armbruster [Mon, 7 Sep 2009 19:30:57 +0000 (15:30 -0400)]
Simplify detonate() to avoid compiler warning

14 years agoFix value of detonate() when target sector takes no damage
Markus Armbruster [Mon, 7 Sep 2009 19:20:41 +0000 (15:20 -0400)]
Fix value of detonate() when target sector takes no damage

This can happen when hitting a sanctuary, or for ridiculously impotent
nukes: groundburst for dam < 5, airburst for dam < 7.  detonate()
returned unpredictable value then.

This screwed up interdiction damage, except for missiles interdicting
ships or land units.  Since nothing can move into a sanctuary, the bug
bit only with ridiculously impotent nukes.

14 years agoFix prod() to limit level production to resource contents
Markus Armbruster [Mon, 7 Sep 2009 19:18:17 +0000 (15:18 -0400)]
Fix prod() to limit level production to resource contents

This could make production command mispredict resource-depleting level
production.  Stock game is not affected.  In fact, such a product
would be highly unusual.

14 years agoFix use of invalid pointer when depleting resource "none"
Markus Armbruster [Mon, 7 Sep 2009 19:18:17 +0000 (15:18 -0400)]
Fix use of invalid pointer when depleting resource "none"

prod() and produce() dereferenced resource uninitialized for products
depleting resource "none" (p_nrdep != 0 && p_nrndx == 0).  The latter
even wrote to it.

Depleting "none" makes no sense, and the depletion is now ignored.
Before, it could conceivably crash the server or corrupt the game.

14 years agoFix workforce formula in info Innards
Markus Armbruster [Sun, 6 Sep 2009 20:03:21 +0000 (16:03 -0400)]
Fix workforce formula in info Innards

14 years agoFactor new lnd_sabo() out of sabo()
Markus Armbruster [Sat, 1 Aug 2009 22:34:20 +0000 (18:34 -0400)]
Factor new lnd_sabo() out of sabo()

This permits giving seagun(), fortgun() and landunitgun() internal
linkage.

14 years agoFix show help text to include news and product
Markus Armbruster [Sat, 1 Aug 2009 19:27:20 +0000 (15:27 -0400)]
Fix show help text to include news and product

Commit 1bca66c0 added show news and commit 71bbd642 show product
without updating the help text.  Fix that.  The prompt is now too
long, so add option '?' to show it, and change the prompt to refer to
that.

14 years agoSlight info markup normalization
Markus Armbruster [Sun, 26 Jul 2009 17:48:22 +0000 (13:48 -0400)]
Slight info markup normalization

Consistently use \*(f, not \f, and \e, not \\.

14 years agoInfo markup fixes
Markus Armbruster [Sun, 26 Jul 2009 17:47:09 +0000 (13:47 -0400)]
Info markup fixes

14 years agoFix w32_sysdep_init() to complain to stderr, not stdout
Markus Armbruster [Sun, 19 Apr 2009 07:39:44 +0000 (09:39 +0200)]
Fix w32_sysdep_init() to complain to stderr, not stdout

14 years agoEmpty out and remove sysdep_w32.c sysdep_w32.h
Markus Armbruster [Sun, 19 Apr 2009 07:37:42 +0000 (09:37 +0200)]
Empty out and remove sysdep_w32.c sysdep_w32.h

Not much remains in sysdep_w32.c, and it's mostly for main.c.  Move
that there, and the rest to misc.h.

14 years agoUse src/lib/w32/w32sockets.c for client
Markus Armbruster [Sat, 18 Apr 2009 21:01:23 +0000 (23:01 +0200)]
Use src/lib/w32/w32sockets.c for client

Move client's w32_connect() to w32sockets.c.

Replace w32_recv() and w32_send() by read() and write().

Replace w32_close() by w32_close_function.

Replace call of WSAStartup() in w32_sysdep_init() by
w32_socket_init().

Remove the identical copies of fd_is_socket(),
w32_set_winsock_errno(), w32_socket().

14 years agoUse src/lib/w32/w32io.c for client
Markus Armbruster [Sat, 18 Apr 2009 20:16:00 +0000 (22:16 +0200)]
Use src/lib/w32/w32io.c for client

Replaces w32_writev_socket() and w32_readv_fd().  Split w32types.h off
w32misc.h, to avoid putting irrelevant stuff into client tarball.

14 years agoRevert "MinGW provides random() in -liberty, no need to replace it"
Markus Armbruster [Sat, 5 Dec 2009 14:09:19 +0000 (15:09 +0100)]
Revert "MinGW provides random() in -liberty, no need to replace it"

This reverts commit 3ec807e99a8dfa6094660896d17bf20dd92e0de8.

Our nightly build test cases rely on the PRN sequence generated by GNU
libc's random().  We used to have such a PRNG in our tree (derived
from an old version of GNU libc's), for use under Windows.  Thus we
got the same PRN sequence on both our nightly test systems.  Commit
3ec807e9 switched to -liberty under Windows and removed our random().
Now we got a different sequence there, breaking the test cases.

Test cases still don't work on non-Windows systems where random()
doesn't match GNU libc's.  We should switch to a PRNG that produces
the same sequence everywhere.

Conflicts:

src/lib/w32/w32misc.h

14 years agoClean up w32misc.h, sysdep_w32.h not to override needlessly
Markus Armbruster [Sat, 18 Apr 2009 15:36:43 +0000 (17:36 +0200)]
Clean up w32misc.h, sysdep_w32.h not to override needlessly

14 years agoreadv() and writev() for Windows returned -1 instead of 0
Markus Armbruster [Sat, 18 Apr 2009 20:07:51 +0000 (22:07 +0200)]
readv() and writev() for Windows returned -1 instead of 0

14 years agoMinGW provides random() in -liberty, no need to replace it
Markus Armbruster [Sat, 18 Apr 2009 15:21:14 +0000 (17:21 +0200)]
MinGW provides random() in -liberty, no need to replace it

14 years agoMinGW provides getopt(), no need to replace it
Markus Armbruster [Sat, 18 Apr 2009 14:33:08 +0000 (16:33 +0200)]
MinGW provides getopt(), no need to replace it

14 years agoChange naming convention of POSIX emulation layer for Windows
Markus Armbruster [Mon, 13 Apr 2009 17:55:12 +0000 (19:55 +0200)]
Change naming convention of POSIX emulation layer for Windows

Use prefix w32 instead of posix: Rename posixfile.c, posixio.c to
w32file.c, w32io.c.  Rename posix_accept(), posix_bind(),
posix_close(), posix_fd2socket(), posix_listen(), posix_mkdir(),
posix_setsockopt(), posix_shutdown(), posix_socket() to w32_accept(),
w32_bind(), w32_fd2socket(), w32_list(), w32_mkdir(),
w32_setsockopt(), w32_shutdown(), w32_socket().

14 years agoMove Windows socket stuff out off posixio.c into w32sockets.c
Markus Armbruster [Mon, 13 Apr 2009 17:25:25 +0000 (19:25 +0200)]
Move Windows socket stuff out off posixio.c into w32sockets.c

This is so we can avoid linking utilities with socket libraries (see
commit 8b778634).

When using sockets, we need to replace close(), because Windows'
close() can't cope with socket file descriptors.  But replacing it
always would pull in the socket stuff again.  Define close() to call
function pointer w32_close_function, which is initially _close.
Rename posix_close() to w32_close_maybe_socket().  Make new
w32_socket_init() put it in w32_close_function.

Same for read() and write(): define read(), write() to call function
pointers w32_read_function, w32_write_function, initially _read(),
_write(); rename posix_read(), posix_write() to
w32_read_maybe_socket(), w32_write_maybe_socket(), and put them into
w32_read_function, w32_write_function in w32_socket_init().

Also call WSAStartup() there, and use that from loc_NTInit().
WSACleanup() now belongs next to w32_socket_init().  Don't bother,
just drop it, along with loc_NTTerm().

14 years agoInclude <winsock2.h> only through "sys/socket.h"
Markus Armbruster [Sat, 18 Apr 2009 16:16:22 +0000 (18:16 +0200)]
Include <winsock2.h> only through "sys/socket.h"

Because we need to #undef NS_ALL after <winsock2.h>, and want to do
that in just one place.

14 years agoInclude <windows.h> from service.h to make it self-contained
Markus Armbruster [Sat, 18 Apr 2009 16:13:27 +0000 (18:13 +0200)]
Include <windows.h> from service.h to make it self-contained

Remove now superfluous includes elsewhere.

14 years agoDon't fake open() and fcntl() just for ef_open()
Markus Armbruster [Mon, 13 Apr 2009 16:20:52 +0000 (18:20 +0200)]
Don't fake open() and fcntl() just for ef_open()

Put the Windows code into new open_locked() instead.  It's ugly having
that in file.c, but the fakes are ugly too, and somewhat brittle.
Remove posix_open(), F_SETLK, F_RDLCK, F_WRLCK, struct flock, and
simplify fcntl().

14 years agoRemove macro S_IRWUG
Markus Armbruster [Mon, 13 Apr 2009 15:27:08 +0000 (17:27 +0200)]
Remove macro S_IRWUG

Use its expansion instead.

14 years agoRevamp server's Windows POSIX compatibility code
Markus Armbruster [Mon, 13 Apr 2009 13:35:40 +0000 (15:35 +0200)]
Revamp server's Windows POSIX compatibility code

Unlike POSIX sockets, Windows sockets are not file descriptors, but
"OS handles", with a completely separate set of functions.

However, Windows can create a file descriptor for a socket, and return
a file descriptor's underlying handle.  Use that instead of wrapping
our own file descriptors around Windows file descriptors and sockets.

Remove the wrapping machinery: MAX_FDS, enum fdmap_io_type, struct
fdmap, fdmap[], nfd, get_fd(), free_fd(), set_fd(), lookup_handle(),
lookup_fd().

Rewrite SOCKET_FUNCTION(), posix_accept(), posix_socket(),
posix_close(), ftruncate(), posix_open(), posix_read(), posix_write(),
fcntl().

Remove FILE_FUNCTION(), posix_fstat(), posix_lseek(),
SHARED_FUNCTION(), and fileno(), because the system's functions now
work fine.

posix_fsync() is used only #ifdef _WIN32, remove it, and call
_commit() directly.

The old code stuffed WSA error codes into errno, which doesn't work.
Use new w32_set_winsock_errno() to retrieve, convert & stuff into
errno.  Adapt inet_ntop() to set the WSA error code instead of errno,
so it can use w32_set_winsock_errno().

Move EWOULDBLOCK from sys/socket.h to w32misc.h, and drop unused
ENOTSOCK, EAFNOSUPPORT.

Use SOCKET rather than int in Windows-specific code.

14 years agoRevamp client's Windows POSIX compatibility code
Markus Armbruster [Mon, 13 Apr 2009 13:08:13 +0000 (15:08 +0200)]
Revamp client's Windows POSIX compatibility code

Unlike POSIX sockets, Windows sockets are not file descriptors, but
"OS handles", with a completely separate set of functions.

However, Windows can create a file descriptor for a socket, and return
a file descriptor's underlying handle.  Use that instead of our gross
hacks to keep up the illusion that sockets are file descriptors.
Slightly dirty: we put file descriptors into fd_set.  Works because
both boil down to int.  Change w32_select(), w32_socket(),
w32_connect(), w32_recv(), w32_writev_socket(), w32_send() to take and
return only file descriptors, and map to sockets internally.  Replace
w32_close_socket() by w32_close(), and drop the close() macro hackery
that made tcp_connect(), host_connect() use w32_close_socket().  New
fd_is_socket().

Windows provides select()-like functions only for handles.  Because of
that, the client used a handle for reading script files, and stored it
in file descriptor input_fd.  Drop this dirty hack, use a file
descriptor instead.  Works because we can get its underlying handle.
Remove the dirty macro hackery that made play(), ring_from_file() and
doexecute() unwittingly work with a handle.  Remove w32_openhandle()
and w32_close_handle().  Replace w32_readv_handle() by w32_readv_fd().
Update w32_select().

Remove w32_openfd(), it's not really needed.

The old code stuffed WSA error codes into errno, which doesn't work.
Use new w32_set_winsock_errno() to convert & stuff.

Fix signed vs. unsigned warnings in Windows client.

Move the struct sigaction replacement next to the sigaction()
replacement.

Rename sysdep_init() to w32_sysdep_init() for consistency.

14 years agoSimplify Windows client to react to Ctrl-C always
Markus Armbruster [Sun, 12 Apr 2009 09:46:22 +0000 (11:46 +0200)]
Simplify Windows client to react to Ctrl-C always

When select() gets interrupted by SIGINT while a handler is active
without SA_RESTART, it returns immediately with EINTR.  w32_select()
did that only while it waited for standard input to become ready for
reading.  This isn't the case when:

* The client has already received EOF on standard input.  But then the
  action is SIG_DFL, so there was no problem.

* Reading standard input is suspended until the server drains the
  input buffer.  Then reaction to Ctrl-C got delayed until the socket
  got ready, and w32_select() returned normally.  Harmless, because
  the reaction merely appends to the input buffer.

Change w32_select() to match select()'s behavior anyway.

14 years agoDon't log out player when update aborts a command under Windows
Markus Armbruster [Sun, 5 Jul 2009 22:56:06 +0000 (18:56 -0400)]
Don't log out player when update aborts a command under Windows

pthread.c's empth_select() returned 1 instead of 0 when empth_wakeup()
interrupted select().  This made io_input() attempt to read input,
which failed with WSAEWOULDBLOCK.  The failure then got propagated all
the way up, and the player got logged out.  Fix by returning 0 in that
case.

14 years agoFix accepting connections from hosts with "long" IPv6 address
Markus Armbruster [Sun, 5 Jul 2009 17:26:15 +0000 (13:26 -0400)]
Fix accepting connections from hosts with "long" IPv6 address

This could fail because struct player member hostaddr had insufficient
space.  Should have been enlarged in commit 19d88af3.

14 years agoPlug memory leak on error path in player_accept()
Markus Armbruster [Sun, 5 Jul 2009 13:58:06 +0000 (09:58 -0400)]
Plug memory leak on error path in player_accept()

14 years agoDelay shutdown up to 3s to let player output buffers drain
Markus Armbruster [Fri, 19 Jun 2009 08:18:37 +0000 (10:18 +0200)]
Delay shutdown up to 3s to let player output buffers drain

14 years agoFix player thread race with update_init()
Markus Armbruster [Tue, 28 Apr 2009 21:06:16 +0000 (23:06 +0200)]
Fix player thread race with update_init()

start_server() creates the thread running player_accept() before it
calls update_init().  However, update_init() initializes stuff used to
player threads: update_time[] and play_lock.  In theory, a player
thread could start before that, and crash when taking the
uninitialized play_lock.

Delay starting that tread until after update_init().

14 years agoSimplify checks whether player thread may sleep
Markus Armbruster [Tue, 28 Apr 2009 18:31:59 +0000 (20:31 +0200)]
Simplify checks whether player thread may sleep

A player thread may sleep on input or output, except:

(1) While it is executing a C_MOD command, it may only sleep on input.

(2) While it is being aborted by the update or shutdown, it may not
    sleep at all.

To find out whether a player thread may sleep on input, code has to
check condition (2).  It needs do to that in recvclient().

To find out whether it may sleep on output, it has to check both
conditions.  It needs to do that in pr_player() and upr_player().

The code tracked condition (1) in global variable play_lock_wanted.
It checked condition (2) by examining struct player member command.

Replace all that by new struct player member may_sleep.  Initialize it
in player_new(), update it in dispatch(), shutdwn() and update_run().
This makes the tests in recvclient(), pr_player() and upr_player()
obvious.  play_wrlock_wanted() is now unused, remove it.

14 years agoTweak LWP debug messages
Markus Armbruster [Tue, 28 Apr 2009 17:58:51 +0000 (19:58 +0200)]
Tweak LWP debug messages

14 years agoMove queue flush out of io.c
Markus Armbruster [Mon, 27 Apr 2009 21:23:30 +0000 (23:23 +0200)]
Move queue flush out of io.c

Player threads may only sleep under certain conditions.  In
particular, they must not sleep while a command is being aborted by
the update or shutdown.

io.c should not know about that.  Yet io_output_all() does, because it
needs to give up when update or shutdown interrupt it.  The function
was introduced in Empire 2, but it didn't give up then.  Fixed in
commit a7fa7dee, v4.2.22.  The fix dragged unwanted knowledge of
command abortion into io.c.

To clean up this mess, io_output_all() has to go.

First user is io_write().  io_write() automatically flushes the queue.
In wait-mode, it calls io_output_all() when the queue is longer than
the bufsize, to attempt flushing the queue completely.  In
no-wait-mode, it calls io_output() every bufsize bytes.  Except the
test for that is screwy, so it actually misses some of the flush
conditions.

The automatic flush makes io_write() differ from io_gets(), which is
ugly.  It wasn't present in BSD Empire 1.1.  Remove it again, dropping
io_write()'s last argument.

Flush the queue in its callers pr_player() and upr_player() instead.
Provide new io_output_if_queue_long() for them.  Requires new struct
iop member last_out to keep track of queue growth.  pr_player() and
upr_player() call repeatedly until it makes no more progress.  This
flushes a bit less eagerly in wait-mode, and a bit more eagerly in
non-wait mode.

Second user is recvclient().  It needs to flush the queue before
potentially sleeping in io_input().  Do that with a simple loop around
io_output().  No functional change there.

14 years agoIndentation fix
Markus Armbruster [Sun, 26 Apr 2009 21:49:41 +0000 (23:49 +0200)]
Indentation fix

14 years agoMake empth_rwlock_t prefer writers
Markus Armbruster [Sun, 26 Apr 2009 21:48:05 +0000 (23:48 +0200)]
Make empth_rwlock_t prefer writers

LWP and Windows implementations already did that.  Rewrite the
pthreads implementation.

The write-bias makes the stupid play_wrlock_wanted busy wait in
dispatch() unnecessary.  Remove it.

14 years agoFix lwp_rwlock_unlock() to wake up all readers
Markus Armbruster [Sun, 26 Apr 2009 17:44:34 +0000 (19:44 +0200)]
Fix lwp_rwlock_unlock() to wake up all readers

It woke up just one.  Bug couldn't bite, because the update never
sleeps, and therefore no reader gets a chance to sleep.

14 years agoRemove IO_NOWAIT, IO_WAIT
Markus Armbruster [Sun, 26 Apr 2009 08:36:57 +0000 (10:36 +0200)]
Remove IO_NOWAIT, IO_WAIT

They make the code slightly clearer in some places, and more
complicated in others.  Not worth it.

14 years agoHide struct io and implementation of struct ioqueue
Markus Armbruster [Sun, 26 Apr 2009 05:43:47 +0000 (07:43 +0200)]
Hide struct io and implementation of struct ioqueue

Move struct io and struct ioqueue from ioqueue.h to ioqueue.c.
Declare incomplete struct ioqueue in ioqueue.h.

14 years agoMake io_output() return a sane value
Markus Armbruster [Fri, 24 Apr 2009 18:10:00 +0000 (20:10 +0200)]
Make io_output() return a sane value

Return number of bytes written on success, -1 on error.  In
particular, return zero when nothing was written because the queue was
empty, or because the write slept and got woken up, or because the
write refused to sleep.

Before, it instead returned the number of bytes remaining to be
written when empth_select() failed, when woken up from sleep, or
refusing to sleep.  You couldn't tell from the return value whether
the call made progress writing out the queue.

The current callers don't actually notice the change.

14 years agoClean up bogus setting of IO_EOF in io_output()
Markus Armbruster [Wed, 22 Apr 2009 21:20:29 +0000 (23:20 +0200)]
Clean up bogus setting of IO_EOF in io_output()

Don't set IO_EOF when writev() returns zero.  I don't think this could
happen, but it's wrong anyway, because a short write should not stop
future reads.

14 years agoRemove blocking struct iop operation
Markus Armbruster [Wed, 22 Apr 2009 18:16:13 +0000 (20:16 +0200)]
Remove blocking struct iop operation

The blocking I/O option makes no sense in the server, because it
blocks the server process instead of the thread.  In fact, it's been
unused since Empire 2, except for one place, where it was used
incorrectly, and got removed in the previous commit.

Make I/O non-blocking in io_open() unconditionally.  Remove IO_NBLOCK
and io_noblocking().

14 years agoRemove bogus io_noblocking() from player_login()
Markus Armbruster [Wed, 22 Apr 2009 17:52:59 +0000 (19:52 +0200)]
Remove bogus io_noblocking() from player_login()

The call switched the connection with the player to blocking I/O for
draining of output before closing the connection.  Looks scary,
because blocking on I/O blocks the complete server process, not just
the player thread.  But we don't do input, and we do output only with
IO_WAIT, which can't block.  So this has no effect.

14 years agoRemove long defunct IO_NEWSOCK
Markus Armbruster [Tue, 21 Apr 2009 17:47:36 +0000 (19:47 +0200)]
Remove long defunct IO_NEWSOCK

Chainsaw used this together with the notify callback to make the iop
data type usable for sockets it listened on, so that io_select() could
multiplex them along with the sockets used for actual I/O.
io_select() became unused in Empire 2, and finally got removed in
commit 875d72a0, v4.2.13.  That made the IO_NEWSOCK and the notify
callback defunct.  The latter got removed in commit 7d5a6b81, v4.3.1.

14 years agoFix race condition in empth_sleep() for Windows
Markus Armbruster [Sun, 14 Jun 2009 16:48:38 +0000 (18:48 +0200)]
Fix race condition in empth_sleep() for Windows

Calculation of sleep duration tried to protect against integer
underflow, but the protection was racy.  Rewrite the whole thing.

14 years agoFix empth_sleep() for argument in the past and pthreads
Markus Armbruster [Sun, 14 Jun 2009 15:49:41 +0000 (17:49 +0200)]
Fix empth_sleep() for argument in the past and pthreads

Calculation of sleep duration suffered integer underflow for unsigned
time_t and arguments in the past.  This made empth_sleep() sleep for
"a few" years instead of not at all.

14 years agoFix fcntl() emulation for Windows
Markus Armbruster [Sun, 14 Jun 2009 16:30:53 +0000 (18:30 +0200)]
Fix fcntl() emulation for Windows

F_GETFL always failed with WSAEINVAL.  io_noblocking() always failed
without doing anything.  Callers didn't check for failure, and newly
opened sockets remained blocking.  But because because
WSAEventSelect() makes sockets non-blocking automatically, they became
non-blocking soon enough to keep things working.

Remove the broken code to query the non-blocking state, and just
return 0.  Document why this works.

While there, simplify the F_SETFL case by using ioctlsocket() instead
of WSAIoctl().

14 years agoMake budget's "Sector building" line look better
Markus Armbruster [Fri, 20 Feb 2009 18:47:28 +0000 (19:47 +0100)]
Make budget's "Sector building" line look better

Number of sectors were not aligned with the other lines.  While there,
print properly plurized "sector" instead of "sct(s)".

14 years agoMake sector maintenance cost configurable
Markus Armbruster [Fri, 20 Feb 2009 17:58:01 +0000 (18:58 +0100)]
Make sector maintenance cost configurable

Replace the fixed $1 per ETU maintenance for capital/city sectors that
are at least 60% efficient by a configurable maintenance cost, payable
regardless of efficiency.  The only change in the default
configuration is that inefficient capitals now pay maintenance.
Charging sector maintenance regardless of efficiency is consistent
with unit maintenance.

New struct dchrstr member d_maint and sector-chr selector maint.  Make
show_sect_build() show it.  Change produce_sect() to record
maintenance in new slot p_sect[SCT_MAINT] instead of abusing
p_sect[SCT_CAPIT].  Replace the "Capital maintenance" line in budget
by "Sector maintenance".

14 years agoNew SCT_BUDG_MAX
Markus Armbruster [Fri, 20 Feb 2009 17:21:37 +0000 (18:21 +0100)]
New SCT_BUDG_MAX

14 years agoOverhaul show sect b
Markus Armbruster [Sat, 21 Feb 2009 15:36:39 +0000 (16:36 +0100)]
Overhaul show sect b

Print sector type mnemonic and name, like show sect s and c.  Print
"can't" instead of negative number for sectors players can't designate
(this was not an issue before the previous commit).  Show build cost
per 100%, like show ship, land, plane and nuke.  Size the columns more
sensibly.

14 years agoFix show sect b not to omit undesignatable sectors
Markus Armbruster [Sat, 21 Feb 2009 14:59:36 +0000 (15:59 +0100)]
Fix show sect b not to omit undesignatable sectors

show sect b needs to explain any sector players can build.
show_sect_build() omitted sectors players can't designate.  That's
wrong, because players can certainly own and thus build sectors they
can't designate.  Test for infinite mobility cost instead, like
show_sect_stats().

14 years agoClean up automatic supply leftovers in ship update
Markus Armbruster [Sat, 23 May 2009 08:08:55 +0000 (10:08 +0200)]
Clean up automatic supply leftovers in ship update

Commit 7da69c92 (v4.3.20) removed use of automatic supply from
prod_ship().  It removed bp_enable_cachepath(), but left behind the
final bp_disable_cachepath(); bp_clear_cachepath().  Clean that up.

14 years agoFix mine production resource limit for peffic != 100%
Markus Armbruster [Thu, 21 May 2009 16:57:55 +0000 (18:57 +0200)]
Fix mine production resource limit for peffic != 100%

With etu_per_update large and resource depletion quick, a sector can
produce more work than is required to fully deplete a mine.  In that
case, produce() and prod() limit production to what is actually in the
ground.  Except produce() got it wrong for sector types with
production efficiency other than 100%.

This affects mountains in the stock game, but only with impractically
large etu_per_update.

14 years agoClean up poorly chosen loop control variable names
Markus Armbruster [Sat, 21 Feb 2009 14:30:13 +0000 (15:30 +0100)]
Clean up poorly chosen loop control variable names

Calling a counting loop's control variable q or x is tasteless
bordering on actively misleading.

14 years agoBump version to 4.3.23
Markus Armbruster [Thu, 30 Apr 2009 19:16:56 +0000 (21:16 +0200)]
Bump version to 4.3.23

14 years agoUpdate change log for 4.3.22 v4.3.22
Markus Armbruster [Sat, 25 Apr 2009 08:12:56 +0000 (10:12 +0200)]
Update change log for 4.3.22

14 years agoFix autoconfiguration of libraries
Markus Armbruster [Sat, 25 Apr 2009 10:18:32 +0000 (12:18 +0200)]
Fix autoconfiguration of libraries

configure checked for library functions with LIBS instead of
LIBS_server, which could break detection of getaddrinfo() on systems
where LIB_SOCKET isn't empty.

GNUmakefile put @PTHREAD_LIBS@ only in LDLIBS, which breaks linking of
server and possibly client on systems where it is not empty.

Broken in commit 8b778634.

14 years agoRename m4/my_termlib.m4 to m4/my_terminfo.m4
Markus Armbruster [Sat, 25 Apr 2009 08:27:01 +0000 (10:27 +0200)]
Rename m4/my_termlib.m4 to m4/my_terminfo.m4

14 years agoRemove useless memset() before free()
Markus Armbruster [Sat, 25 Apr 2009 08:00:06 +0000 (10:00 +0200)]
Remove useless memset() before free()