Commit graph

3601 commits

Author SHA1 Message Date
1c5bfa0eab Clarify flying command info pages on plane selection 2009-12-08 08:15:51 +01:00
Scott C. Zielinski
f79d1680a7 Don't let players paradrop their own sectors
Such a paradrop always failed, and the paratroopers were lost.
2009-12-08 08:15:51 +01:00
b2e6663f39 Simplify wantflags calculation in bomb(), fly(), para(), reco() 2009-12-08 08:15:51 +01:00
df1ca95a2a 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.
2009-12-08 08:15:51 +01:00
062a42fb7b 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.
2009-12-08 08:15:51 +01:00
15d355521a Remove superfluous variable ip from bomb() 2009-12-08 08:15:51 +01:00
0fe43096bc 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.
2009-12-08 08:15:51 +01:00
b1dd82fa61 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.
2009-12-08 08:15:50 +01:00
79154bf0fc Simplify reco() not to pass useless flags to pln_arm()
Flags P_S and P_I have no effect.
2009-12-08 08:15:50 +01:00
e2580b4005 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.
2009-12-08 08:15:50 +01:00
1ee0287595 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.
2009-12-08 08:15:50 +01:00
2b31f644db Enable marine msl. unconditionally, remove option PINPOINTMISSILE
Deities can still control them by customizing table plane-chr.
2009-12-08 08:15:50 +01:00
ac33576a99 Update info version example to current output 2009-12-08 08:15:50 +01:00
927abead50 Simplify satmap() to avoid compiler warning 2009-12-08 08:15:50 +01:00
e5a43ebe26 Simplify detonate() to avoid compiler warning 2009-12-08 08:15:50 +01:00
e0cb1b66b3 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.
2009-12-08 08:15:50 +01:00
8718a9428a 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.
2009-12-08 08:12:55 +01:00
c63ec06d15 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.
2009-12-08 08:11:01 +01:00
c0b2eec69d Fix workforce formula in info Innards 2009-12-05 15:19:37 +01:00
ad296698f9 Factor new lnd_sabo() out of sabo()
This permits giving seagun(), fortgun() and landunitgun() internal
linkage.
2009-12-05 15:19:37 +01:00
162c79bb73 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.
2009-12-05 15:19:37 +01:00
5705ab91b8 Slight info markup normalization
Consistently use \*(f, not \f, and \e, not \\.
2009-12-05 15:19:37 +01:00
2b237bfa89 Info markup fixes 2009-12-05 15:19:37 +01:00
9697912a90 Fix w32_sysdep_init() to complain to stderr, not stdout 2009-12-05 15:19:37 +01:00
518c8d6fbf 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.
2009-12-05 15:19:37 +01:00
4d40a27542 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().
2009-12-05 15:19:36 +01:00
1153d9c995 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.
2009-12-05 15:19:34 +01:00
c8231b120b Revert "MinGW provides random() in -liberty, no need to replace it"
This reverts commit 3ec807e99a.

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
2009-12-05 15:09:19 +01:00
c9508fa588 Clean up w32misc.h, sysdep_w32.h not to override needlessly 2009-11-30 19:45:28 +01:00
bbd5cfdebb readv() and writev() for Windows returned -1 instead of 0 2009-11-30 19:45:28 +01:00
3ec807e99a MinGW provides random() in -liberty, no need to replace it 2009-11-30 19:45:28 +01:00
b8fccf7324 MinGW provides getopt(), no need to replace it 2009-11-30 19:45:28 +01:00
c9de868d55 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().
2009-11-30 19:45:28 +01:00
4c6deb1f98 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().
2009-11-30 19:45:27 +01:00
39398997fe 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.
2009-11-30 19:45:27 +01:00
58e34ebe3d Include <windows.h> from service.h to make it self-contained
Remove now superfluous includes elsewhere.
2009-11-30 19:45:27 +01:00
dbef646f5d 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().
2009-11-30 19:45:27 +01:00
c665c83ba4 Remove macro S_IRWUG
Use its expansion instead.
2009-11-30 19:45:27 +01:00
1c08ccf25b 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.
2009-11-30 19:45:04 +01:00
798af5b45b 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.
2009-11-30 19:44:21 +01:00
f4209f7ea9 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.
2009-11-30 19:43:50 +01:00
2bfe7a1198 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.
2009-11-30 19:43:47 +01:00
ee01ac1912 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.
2009-11-30 19:43:47 +01:00
0dbb5bfd75 Plug memory leak on error path in player_accept() 2009-11-30 19:43:47 +01:00
1e1dfc860a Delay shutdown up to 3s to let player output buffers drain 2009-11-30 19:43:47 +01:00
f5885865da 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().
2009-11-30 19:43:47 +01:00
0a4d77e919 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.
2009-11-30 19:43:18 +01:00
bd6d9d53a0 Tweak LWP debug messages 2009-07-19 14:11:53 -04:00
1b4496253d 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.
2009-07-19 14:11:53 -04:00
7fd5b86990 Indentation fix 2009-07-19 14:11:53 -04:00