]> git.pond.sub.org Git - empserver/log
empserver
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()

14 years agoFix misuse of CreateThread() in Windows client
Markus Armbruster [Sat, 25 Apr 2009 07:59:36 +0000 (09:59 +0200)]
Fix misuse of CreateThread() in Windows client

We use the C run-time, so we better use its _beginthread(), too.
CreateThread() can lead to deadlocks, at least with some versions of
the C run-time.  Broken in commit f082ef9f, v4.3.11.

14 years agoFix Windows client's stdin read thread's error handling
Markus Armbruster [Sat, 25 Apr 2009 07:43:48 +0000 (09:43 +0200)]
Fix Windows client's stdin read thread's error handling

stdin_read_thread() zeroed bounce_status on failure, effectifely
treating it like EOF.  Fix by setting to -1.

It treated main thread termination like failure, and set bounce_error
to a bogus value.  Can't happen, because the program terminates when
the main thread terminates, and the only user of bounce_error is the
main thread anyway.  Regardless, handle the case by terminating,
because that's more obviously correct.

Broken in commit f082ef9f, v4.3.11.

14 years agoFix generation of src/client/aclocal.m4
Markus Armbruster [Sat, 25 Apr 2009 06:52:47 +0000 (08:52 +0200)]
Fix generation of src/client/aclocal.m4

Revert commit c3d2786f, because the resulting aclocal.m4 includes
stuff from outside the standalone build.  Generate with cat instead.

14 years agoFix ersatz_getpass() to use its parameter
Markus Armbruster [Sat, 25 Apr 2009 06:30:10 +0000 (08:30 +0200)]
Fix ersatz_getpass() to use its parameter

It used its only actual argument instead.

14 years agoMake Windows client read password without echo again
Markus Armbruster [Thu, 23 Apr 2009 18:38:15 +0000 (20:38 +0200)]
Make Windows client read password without echo again

Commit 8c3b8d10 replaced the getpass() for Windows by a generic
ersatz_getpass().  This lost the "switch off echo" feature, with the
excuse that it doesn't work for me (MinGW & Wine).  Turns out it works
under real Windows.  Restore the feature.

14 years agoMake savecore put $PWD in the mail subject
Markus Armbruster [Thu, 23 Apr 2009 18:32:42 +0000 (20:32 +0200)]
Make savecore put $PWD in the mail subject

Useful when you monitor multiple games.

15 years agoAdd includes to make headers self-contained
Markus Armbruster [Tue, 21 Apr 2009 17:30:42 +0000 (19:30 +0200)]
Add includes to make headers self-contained

15 years agoMake configure print a configuration summary
Markus Armbruster [Sun, 19 Apr 2009 13:47:40 +0000 (15:47 +0200)]
Make configure print a configuration summary

15 years agoAutoconfigure use of terminfo
Markus Armbruster [Sun, 19 Apr 2009 13:42:19 +0000 (15:42 +0200)]
Autoconfigure use of terminfo

New configure --with-terminfo.  Before, terminfo was assumed to be
available everywhere but on Windows.

15 years agoDeclare getsose() & friends in one place
Markus Armbruster [Sat, 18 Apr 2009 21:47:02 +0000 (23:47 +0200)]
Declare getsose() & friends in one place

15 years agoRebase strptime.c to fix license incompatibility
Markus Armbruster [Sat, 18 Apr 2009 20:03:39 +0000 (22:03 +0200)]
Rebase strptime.c to fix license incompatibility

The old upstream version carries the original BSD license, which is
incompatible with the GPL.  Fix by rebasing to a version that is
licensed under the 2-clause BSD license.

15 years agoTrim a bogus make dependency in standalone client build
Markus Armbruster [Sat, 18 Apr 2009 17:08:03 +0000 (19:08 +0200)]
Trim a bogus make dependency in standalone client build

It got added in commit f082ef9f.

15 years agoReally, really fix bomb not to wipe out plane updates
Markus Armbruster [Sat, 18 Apr 2009 12:41:24 +0000 (14:41 +0200)]
Really, really fix bomb not to wipe out plane updates

Commit 82b5e3c2 missed escorts.

15 years agoFix tend land not to wipe out concurrent updates
Markus Armbruster [Sat, 18 Apr 2009 06:41:28 +0000 (08:41 +0200)]
Fix tend land not to wipe out concurrent updates

Fix tend_land() to bail out if the tender changed while tend_land()
slept for the last argument (receiving ship).

15 years agoFix return value of s_commod() when it can't draw enough
Markus Armbruster [Thu, 16 Apr 2009 11:06:32 +0000 (13:06 +0200)]
Fix return value of s_commod() when it can't draw enough

s_commod() could incorrectly claim success when the sink ended up with
at least as many supplies than were missing initially.  This caused a
number of problems:

* shp_torp() let a ship with two shells fire a torpedo, resulting in
  -1 shells, which then made item_prewrite() oops.  Affected missions
  and return fire, but not the torpedo command.

* shp_missile_defense() let a ship with one shell use missile defense,
  resulting in -1 shells, and the same item_prewrite() oops.

* Land units were considered in supply even when they had not quite
  enough supplies.  Such land units could defend without penalty,
  attack and react.  Commands load and lload weren't affected, because
  they use lnd_in_supply(), which doesn't use s_commod().

Broken in 98f24d5c, v4.3.20.

15 years agoFix update to take dead units off carriers
Markus Armbruster [Wed, 15 Apr 2009 21:06:54 +0000 (23:06 +0200)]
Fix update to take dead units off carriers

upd_plane() upd_land() and left planes and land units lost to lack of
maintenance on their carriers.  Cargo lists were fine anyway, because
unit_cargo_init() ignored dead units.  But when the dead unit got
reused for building a new one, pln_prewrite() / lnd_prewrite() got
confused and attempted to take it off its carrier, which made
clink_rem() oops, because the unit wasn't on the cargo list.  No real
harm done, as oops recovery was fine.

Fix upd_plane() and upd_land() to clear the carrier.  Make
unit_cargo_init() oops when it finds dead units on carriers.

15 years agoRun git describe in nightlybuild.sh to identify what's built
Markus Armbruster [Wed, 15 Apr 2009 20:12:44 +0000 (22:12 +0200)]
Run git describe in nightlybuild.sh to identify what's built

15 years agoClean up autoconfiguration of libraries
Markus Armbruster [Sun, 12 Apr 2009 17:11:58 +0000 (19:11 +0200)]
Clean up autoconfiguration of libraries

Make configure compute three sets of libraries: LIBS_client for the
client, LIBS_server for the server, and LIBS for the rest.  This
replaces termlibs.

Unfortunately, LIBS doesn't work with Windows, because
src/lib/w32/posixio.c pulls in socket stuff.  Temporary workaround:
use LIBS_server instead.

15 years agoStandalone client build for Windows made empire without .exe
Markus Armbruster [Sun, 12 Apr 2009 17:10:29 +0000 (19:10 +0200)]
Standalone client build for Windows made empire without .exe

15 years agoDefine WIN32_LEAN_AND_MEAN for Windows
Markus Armbruster [Sun, 12 Apr 2009 17:07:30 +0000 (19:07 +0200)]
Define WIN32_LEAN_AND_MEAN for Windows

15 years agoSimplify autoconfiguration for Windows
Markus Armbruster [Sun, 12 Apr 2009 17:00:55 +0000 (19:00 +0200)]
Simplify autoconfiguration for Windows

Checking Windows libraries with autoconf is cumbersome, because
linking often fails unless you include the header, and AC_SEARCH_LIBS
doesn't permit that.

Just detect the Windows API instead, with new MY_WINDOWS_API.

15 years agoRemake src/client/aclocal.m4 with aclocal instead of cp
Markus Armbruster [Sun, 12 Apr 2009 16:32:24 +0000 (18:32 +0200)]
Remake src/client/aclocal.m4 with aclocal instead of cp

15 years agoFix client to abort script execution on SIGINT
Markus Armbruster [Sat, 11 Apr 2009 20:52:52 +0000 (22:52 +0200)]
Fix client to abort script execution on SIGINT

15 years agoFix Windows client for EOF on stdin
Markus Armbruster [Sat, 11 Apr 2009 15:56:21 +0000 (17:56 +0200)]
Fix Windows client for EOF on stdin

stdin_read_thread() went into a tight loop on EOF.  Observed with
Wine.  Broken in commit f082ef9f, v4.3.11.

15 years agoInclude stdlib.h unconditionally, for simplicity
Markus Armbruster [Fri, 10 Apr 2009 13:08:40 +0000 (15:08 +0200)]
Include stdlib.h unconditionally, for simplicity

15 years agoUse sys/select.h for select()
Markus Armbruster [Fri, 10 Apr 2009 13:07:19 +0000 (15:07 +0200)]
Use sys/select.h for select()

Should be more portable to modern systems and could be less portable
to obsolete systems than the traditional sys/time.h sys/types.h
unistd.h incantation.

15 years agoReplace missing getpass()
Markus Armbruster [Fri, 10 Apr 2009 12:57:13 +0000 (14:57 +0200)]
Replace missing getpass()

getpass() is traditional Unix, but has been withdrawn from POSIX.  As
such, it may be missing.  Check for that, and provide ersatz.  It's
not a real replacement, because it doesn't do the special magic
getpass() is supposed to do: read from /dev/tty without echo.

This bypasses our existing getpass() for Windows.  In contrast to the
portable getpass(), the Windows one tries to turn off echo, but that
doesn't work for me (MinGW & Wine).  Remove it.

15 years agoBelatedly update make dependencies for standalone client build
Markus Armbruster [Fri, 10 Apr 2009 08:17:17 +0000 (10:17 +0200)]
Belatedly update make dependencies for standalone client build

expect.$O was out of date since commit c9c9305c.

ringbuf.$O and sysdep_w32.$O were out of date since commit f082ef9f.

15 years agoFix documentation not to refer to client as emp_client
Markus Armbruster [Sun, 5 Apr 2009 09:34:57 +0000 (11:34 +0200)]
Fix documentation not to refer to client as emp_client

15 years agoFix client not to hang when EOF on stdin overtakes C_EXECUTE
Markus Armbruster [Sun, 5 Apr 2009 08:58:30 +0000 (10:58 +0200)]
Fix client not to hang when EOF on stdin overtakes C_EXECUTE

Player input may overtake batch file contents (well-known protocol
flaw, see doc/clients-howto for details).  This includes EOF.  When
that happens, the client closes standard input, sends an EOF cookie,
and continues reading output until the server closes the connection.
When it gets C_EXECUTE, it redirects input to the batch file.  But it
then failed to read the batch file.  The server waited forever for the
execute's EOF cookie, the client waited forever for the server closing
the connection.

Fix by stopping only reading from standard input.  Broken in 8b7d0b91,
v4.3.11.

Note that the EOF cookie still overtakes the batch file contents,
which makes the server interpret the input between the execute command
and the EOF as batch file, and the batch file contents as ordinary
input.

15 years agoBelatedly document batch file restrictions
Markus Armbruster [Sun, 5 Apr 2009 08:55:46 +0000 (10:55 +0200)]
Belatedly document batch file restrictions

The server rejects redirections in batch files since commit ed8e0cd5,
and execute commands since commit adfab434, both v4.3.11.

15 years agoRemove dead EASY_BRIDGES code from bridgefall()
Markus Armbruster [Sun, 29 Mar 2009 17:18:10 +0000 (19:18 +0200)]
Remove dead EASY_BRIDGES code from bridgefall()

Dead since commit 40eb78eb, v4.3.12.

15 years agoSimplify build_tower() a bit
Markus Armbruster [Sun, 29 Mar 2009 15:48:06 +0000 (17:48 +0200)]
Simplify build_tower() a bit

No functional change.

15 years agoFix info build, mine, navigate, sweep on mines
Markus Armbruster [Sun, 29 Mar 2009 15:20:41 +0000 (17:20 +0200)]
Fix info build, mine, navigate, sweep on mines

15 years agoChange mine command not to work under bridges for now
Markus Armbruster [Sun, 29 Mar 2009 15:16:48 +0000 (17:16 +0200)]
Change mine command not to work under bridges for now

This is for consistency with aerial mining.  Seamines don't work under
bridges anyway (they did a long time ago, until Empire 2).

Making seamines work under bridges again wouldn't be hard, but it
would make the 'X' in bmaps ambiguous.

15 years agoSimplify retreat_ship1() and retreat_land1() slightly
Markus Armbruster [Sun, 29 Mar 2009 13:25:17 +0000 (15:25 +0200)]
Simplify retreat_ship1() and retreat_land1() slightly

No functional change.

15 years agoFix confusion of landmines with seamines
Markus Armbruster [Sun, 29 Mar 2009 13:03:44 +0000 (15:03 +0200)]
Fix confusion of landmines with seamines

Seamines and landmines share storage.  Sea and bridge span sectors can
hold only sea mines, other sector types only landmines.  Sector type
checks were missing or incorrect in several places:

* Seamines under bridge spans were mistaken for landmines in several
  places:

  - ground combat mine defense bonus, in get_mine_dsupport() and
    stre(),

  - land units retreating from bombs, in retreat_land1(),

  - non-land unit ground movement (commands explore, move, transport,
    and INTERDICT_ATT of military), in check_lmines(),

  Fix them to check the sector type with new SCT_MINES_ARE_SEAMINES(),
  SCT_LANDMINES().

* plane_sweep() mistook landmines for seamines in harbors.  Bug could
  not bite, because it's only called for sea sectors.  Drop the bogus
  check for harbor.

* Collapsing a bridge tower magically converted landmines into
  seamines.  Make knockdown() clear landmines.

Also use SCT_MINES_ARE_SEAMINES() and SCT_LANDMINES() in mine(),
landmine(), lnd_sweep() and lnd_check_mines().  No functional change
there.

Keep checking only for sea in pln_mine(), plane_sweep(),
retreat_ship1(), shp_sweep() and shp_check_one_mines().  This means
seamines continue not to work under bridges.  Making them work there
is tempting, but as long as finding seamines clobbers the sector
designation in the bmap, it's better to have them in sea sectors only.

Historical notes:

Mines started out simple enough: you could mine sea and bridge spans,
and ships hit and swept mines in foreign sectors.

Chainsaw 2 introduced aerial mining and sweeping.  Unlike ships,
planes could not mine bridge spans.  plane_sweep() could sweep
harbors, which was wrong, but it was never called there, so the bug
could not bite.

Chainsaw 3 introduced landmines.  The idea was to permit only seamines
in some sector types, and only landmines in the others, so they can
share storage.  To figure out whether a sector has a particular kind
of mines, you need to check the sector type.  Such checks already
existed in mine, drop and sweep, and they were kept unchanged.  The
new lmine command also got the check.  Everything else did not.
Ground movement and combat could hit and sweep seamines in bridge
spans.  Ships could hit and sweep landmines in harbors.

Empire 2 fixed land unit movement (march, INTERDICT_ATT) not to
mistake seamines for landmines on bridge spans.  It fixed ships not to
mistake landmines for seamines.  The fix also neutered seamines under
bridge spans: ships could neither hit nor sweep them anymore.  Both
fixes missed retreat.

Commit 5663713b (v4.3.1) made ship retreat consistent with other ship
movement.

15 years agoClean up useless declarations
Markus Armbruster [Sat, 28 Mar 2009 12:03:57 +0000 (13:03 +0100)]
Clean up useless declarations

Commit fbf9f15b removed SO, SE, but left their declarations behind.
Ditto commit 3aea20e1 for bigcity_dchr, and commit 08b94556 for
player_kill_idle.

Commit afa65c8f accidentally added a declaration for xedit().

15 years agoDon't use 0 as null pointer constant, part 3
Markus Armbruster [Mon, 23 Mar 2009 21:58:54 +0000 (22:58 +0100)]
Don't use 0 as null pointer constant, part 3

This part replaces E == 0 by !E, where E has pointer type.

15 years agoDon't use 0 as null pointer constant, part 2
Markus Armbruster [Mon, 23 Mar 2009 19:17:44 +0000 (20:17 +0100)]
Don't use 0 as null pointer constant, part 2

This part replaces E != 0 by E, where E has pointer type.

15 years agoDon't use 0 as null pointer constant, part 1
Markus Armbruster [Sun, 22 Mar 2009 17:50:43 +0000 (18:50 +0100)]
Don't use 0 as null pointer constant, part 1

Use NULL instead of 0, for clarity.  Except in pointer comparisons;
leave that to the next two commits.

15 years agoClean up more unreadable assignments within if conditionals
Markus Armbruster [Mon, 23 Mar 2009 21:43:52 +0000 (22:43 +0100)]
Clean up more unreadable assignments within if conditionals

15 years agoSimplify explain()
Markus Armbruster [Mon, 23 Mar 2009 19:15:31 +0000 (20:15 +0100)]
Simplify explain()

No functional change.

15 years agoClean up non-ANSI definition of ef_verify()
Markus Armbruster [Sun, 22 Mar 2009 17:02:57 +0000 (18:02 +0100)]
Clean up non-ANSI definition of ef_verify()

Harmless, because declaration is fine.

15 years agoGive fairland's variables internal linkage
Markus Armbruster [Sun, 22 Mar 2009 16:55:00 +0000 (17:55 +0100)]
Give fairland's variables internal linkage

15 years agoMake non-static function definitions match static declarations
Markus Armbruster [Sun, 22 Mar 2009 16:47:14 +0000 (17:47 +0100)]
Make non-static function definitions match static declarations

Just to avoid confusion.

15 years agoDon't advertize ^D as means to end a telegram
Markus Armbruster [Sun, 22 Mar 2009 08:52:06 +0000 (09:52 +0100)]
Don't advertize ^D as means to end a telegram

getele() aborts the telegram on EOF since commit bc8a4432 (v4.2.21).
Besides, ^D may not work with some clients.

15 years agoDon't log out player when he interrupts a command
Markus Armbruster [Sun, 22 Mar 2009 07:58:10 +0000 (08:58 +0100)]
Don't log out player when he interrupts a command

Broken in commit 3da4030a, v4.3.19.

15 years agoClean up unreadable assignments within if conditionals
Markus Armbruster [Sat, 21 Mar 2009 08:24:45 +0000 (09:24 +0100)]
Clean up unreadable assignments within if conditionals

Pinpointed assignments within if conditionals with spatch -sp_file
tests/bad_assign.cocci (from coccinelle-0.1.4).  Cherry-picked diff
hunks affecting conditionals split over multiple lines, and cleaned
them up.