Commit graph

985 commits

Author SHA1 Message Date
2af8d77920 Include <sys/time.h> in lwp.h
Missed in commit 08b9455, v4.3.20.  Triggers compiler warnings on
NetBSD 5.1.2.
2013-05-08 14:35:04 +02:00
ba2600e7db Factor prod_resource_limit() out of produce() and prod() 2013-05-08 06:57:58 +02:00
f0927e7f64 prod() duplicates materials_cost(), clean up
Rename materials_cost() to prod_materials_cost(), give external
linkage, use it in prod().
2013-05-08 06:57:58 +02:00
2d3bac803c Drop extra blank line in output of pconfig 2013-05-08 06:57:56 +02:00
1afe0a7993 Document GNU libc lossage in listen_addr doc string
Systems using GNU libc such as Linux are frequently configured in a
way getaddrinfo(NULL, ...) put the IPv4 wildcard "0.0.0.0" *before*
the IPv6 wildcard "::" in the result.  Because of that, listen_addr ""
listens only on all IPv4 addresses.  Workaround: listen_addr "::".

Document it in listen_addr's doc string.
2013-05-08 06:57:56 +02:00
da154ffd06 Fix wildcard bind to at least bind IPv4 or else IPv6 on OpenBSD
OpenBSD refuses to implement IPV6_V6ONLY, in violation of RFC 3493.
RFC 4038 frowningly recognizes this practice.  The only way to bind
both IPv4 and IPv4 there is two separate sockets.  Requires more
surgery than I can do now.

Since we can't have both IPv6 and IPv6 on OpenBSD with our single
socket, prefer IPv4, but if that doesn't work, do IPv6.

To prefer IPv6 instead, put 'listen_addr "::"' into econfig.  Document
that in listen_addr's doc string.
2013-05-08 06:57:56 +02:00
5f46ced826 Use int instead of long for money
Code dealing with money mixes int and long pretty haphazardly.
Harmless, because practical amounts of money fit into int on any
machine capable of running the server.  Clean up anyway.
2013-05-08 06:57:54 +02:00
74b8b9932d Use int instead of long for military reserves
Code dealing with reserves mixes int and long pretty haphazardly.
Harmless, because practical reserves fit easily on any machine capable
of running the server.  Clean up anyway.
2013-05-08 06:57:54 +02:00
5d7f011900 Use int instead of long to count people
Code dealing with counting people mixes int and long pretty
haphazardly.  Harmless, because practical populations fit into int
easily on any machine capable of running the server.  Clean up anyway.
2013-05-08 06:57:54 +02:00
948757cb0c Use int instead of signed char for pln_flags
Just for consistency with other flags members.  Rearrange struct
plnstr to avoid holes.
2013-05-08 06:57:54 +02:00
e51b3fb842 Use int instead of long for flags
As long as symbol_by_value(), show_capab() and togg() support only
int, flags need to fit into int.

Not a problem in practice, because no machine capable of running
Empire has int narrower than 32 bits, and 32 bits suffice.

Some flags members are long instead of int: struct lchrstr member
l_flags, struct natstr member nat_flags, struct mchrstr member m_flags
are long.  Waste of space on machines with long wider than int.
Change them to int.

Rearrange struct lchrstr and struct natstr to avoid holes.
2013-05-08 06:57:51 +02:00
77f8846273 Abridge a few overly verbose declarations 2013-05-08 06:55:21 +02:00
9102ecce54 Fix PRNG seeding to resist guessing
We seed it with value of time().  It's the traditional way, but it
provides only a few bits of effective entropy when an attacker has a
rough idea when the program started.

Instead, seed with a kernel random number.  If we can't get one, fall
back to a hash of gettimeofday() and getpid().  This should happen
only on old systems or Windows.  Far worse than a kernel random
number, but far better than using time().

Note that fairland used to seed with time() + getpid() until commit
331aac2a (v4.2.20) dropped the getpid(), claiming it didn't improve
the randomness.  Perhaps it didn't under Windows then, but it
certainly did elsewhere, so it was a regression.
2013-05-08 06:55:21 +02:00
54ddcd0f5a New pct_chance(), for clarity, and symmetry with chance() 2013-05-08 06:55:20 +02:00
c3be487479 Replace "roll0(N) + M" by "roll(N) + M-1" 2013-05-08 06:55:20 +02:00
866859e912 Encapsulate direct use of random(), srandom() in chance.c
Wrap roll0() around random(), and seed_prng() around srandom().  In
preparation of replacing the PRNG.
2013-05-08 06:55:20 +02:00
8eb78a5a80 Move declarations for chance.c to new chance.h 2013-05-08 06:55:20 +02:00
3a7d7fa866 Really fix accepting connections from "long" IPv6 address
Commit ee01ac19 (v4.3.23) enlarged player member hostaddr from 32 to
46 characters, but missed natstr member nat_hostaddr.  player_main()
copies hostaddr to nat_hostaddr.  Can overrun the destination, but
fortunately just into nat_hostname.

Impact:

* Can makes praddr() print only a suffix of the address.  Used by play
  command, for player messages during login and logout, and for
  logging.

* Can make player_main()'s test for "same address as last time" fail,
  causing extra "Last connection" messages.

* Matching against econfig key privip is not affected.

* Journal event login is not affected.
2013-01-12 17:56:39 +01:00
efa4ecdc4d Drop resnoise()'s second parameter
All callers pass the same argument.
2013-01-12 17:56:26 +01:00
df4925d696 Update copyright notice 2013-01-12 17:45:01 +01:00
3e3c2eecf9 Polish empthread documentation somewhat 2012-08-05 09:26:32 +02:00
fc64b4fa83 Permit empth_self() before empth_init()
Next commit wants this.
2012-08-05 09:24:57 +02:00
324109ae45 Forbid selling units with unsalable cargo, permit selling military
Deities can customize which commodities can be sold in table item.
Default is to allow anything but civilians and military.  However,
this applies only to the commodity market, not to the unit market:
cargo of ships and land units is not restricted.

Make the two markets consistent: permit selling military by default,
forbid selling units carrying unsalable commodities.  This outlaws
selling units carrying civilians by default.
2012-07-13 20:15:34 +02:00
6c086a8110 Drop trade_desc()'s first argument 2012-07-13 20:15:34 +02:00
d9cafc156c Clean up use of union empobj_storage * as parameter type
Use it only for functions that assign objects through a pointer
parameter.  Anything else can and should use struct empobj *.
2012-07-13 20:15:33 +02:00
f75544ee70 Replace trade_check_item_ok() by check_obj_ok()
Relaxes the sanity check of the argument's ef_type.  Could be avoided,
but not worth the bother.
2012-07-13 20:15:33 +02:00
29f6d10a34 Factor check_obj_ok() out of the check_*_ok() 2012-07-13 20:15:33 +02:00
e25ff14f0c New ef_nameof_pretty() 2012-07-13 20:15:33 +02:00
3d3d272eef Don't let scrap give away civilians
Scrapping unloads everything.  Even stuff that unload can't: foreign
civilians.  Kill them off instead, like scuttle does.
2012-07-13 20:15:33 +02:00
612ec6257d Pilots and air cargo now spread the plague
Planes flying one-way with crew or cargo spread plague from their old
base to their new base.  Planes dropping cargo spread plague from
their base to the drop's target sector.
2012-07-13 20:15:33 +02:00
b4acb73fd1 Replace pln_oneway_to_carrier_ok() by pln_can_land_on_carrier()
Avoids reading the target ship again.
2012-07-13 20:15:33 +02:00
d9a915a05b Replace pln_onewaymission() by pln_where_to_land()
New function reads and returns target sector/ship.  Avoids reading the
target sector unnecessarily.  Callers receive the target ship, not
just its number.  Next commit will put it to use.
2012-07-13 20:14:10 +02:00
72f1e22b95 Drop could_be_on_ship()'s load count parameters
Just one caller wants them.  Inline that call, and simplify the
others.
2012-07-12 19:52:33 +02:00
1118f1c0ca Update copyright notice 2012-06-10 10:52:22 +02:00
2503e41bd2 Rename play_lock back to update_lock
It was renamed to play_lock because it synchronized not just updates
but also shutdown.  Since the previous commit, it again only
synchronizes updates.  Rename it back.

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

Issues:

1. Polling is lame.

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

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

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

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

2. New player threads block before entering state PS_PLAYING.

1. shutdwn() still polls up to 3s for player threads to terminate.
   Still lame.  Left for another day.
2012-04-26 20:05:28 +02:00
02293b9bd1 Document the header for empmod.c and trdsub.c in prototypes.h 2012-04-26 19:57:19 +02:00
a1003ea7da io_shutdown() is now unused, remove 2012-04-26 19:57:19 +02:00
918f3ec6ae Separate max_idle_visitor from max_idle
Cut it to 5 minutes, from max_idle's 15.

Since max_idle now applies only to authenticated players, increasing
it is perfectly safe.
2012-04-26 19:57:19 +02:00
1a97cc3cfd Separate login_grace_time from max_idle
max_idle applies in state PS_PLAYING, login_grace_time before (login,
state PS_INIT) and after (logout, state PS_SHUTDOWN).

Cut login_grace_time to two minutes, from max_idle's 15.  Two minutes
is plenty to complete login and logout.  Makes swamping the server
with connections slightly harder, as they get dropped faster.  While
that makes sense all by itself, the real aim is making increasing
max_idle safe.  The next commit will complete that job.
2012-04-26 19:57:19 +02:00
7a3cbf037a Add deadline support to io_output(), io_output_if_queue_long()
Replace parameter wait by deadline.  Non-zero wait argument becomes
(time_t)-1 argument, zero wait argument becomes zero deadline
argument.  No functional change, yet.
2012-04-26 19:43:22 +02:00
ddbcce12c3 Switch io_close(), io_input() from timeouts to deadlines
All users want deadlines.  Move the conversion from deadline to
timeout from callers to io.c, where it becoems an implementation
detail.
2012-03-31 19:03:19 +02:00
ed1cbc97e6 Base idle timeout on player->curup again, not current time
Idle timeout used to expire max_idle minutes after the last
player->curup update.  When we got rid of the idle thread in commit
08b94556 (v4.3.20), this got changed to "wait no more than max_idle
minutes for input".  Time spent computing and time spent blocked on
output no longer counts.  In particular, a connection can block
indefinitely on output since then.  Let's fix that.

Start with basing the input timeout on player->curup again.  The
missing output timeout will be added shortly.

Aside: since status() updates player->curup, the idle timer gets reset
when the update aborts a command.  Left for another day.
2012-03-27 17:23:18 +02:00
a96b400da3 Replace the per-iop input_timeout by per-function timeouts
Commit 08b94556 (v4.3.20) added io_open() parameter input_timeout.  It
applies to io_input() and, since commit 904822e3, to io_close().  Add
timeout parameters to these functions instead.
2012-03-27 17:23:14 +02:00
f9fc80e2de Revise nation status command permissions
Create new command capability NONVIS.  Give it to players in any state
except visitors (and STAT_UNUSED, but those must not exist).  This
makes it possible to have commands available to anyone but visitors.

Command change fails when the player is a visitor.  Simply make it
unavailable instead, by requiring NONVIS.

Make read unavailable to visitors, because it's useless: visitors
can't receive telegrams (typed_wu() fails).

Make census, commodity and sinfra unavailable to visitors.  Visitors
don't normally have sectors.

Make map and nmap unavailable to visitors.  Visitors don't have sectors,
so their maps are always empty.

Make them unavailable to new players (between add and newcap) and
players in sanctuary, too.  This is consistent with all the other
commands to examine the environment.  It also prevents people from
trying multiple unbroken countries in a blitz to find the one with the
nicest vicinity.

Make resource available to new players, for consistency with census
and commodity.

Make country, echo and financial available to anyone.
2012-02-25 11:24:32 +01:00
481d1dabe2 Clean up c_permit values of deity commands
A player may execute a command when his player->nstat has all the bits
in the command's c_permit.

Normal player commands require bit(2).  Command break requires bit(1),
and execute requires bit(5).  Deity commands require both bit(2) and
bit(3).  Works, because deities always have both bits set in nstat, as
they may execute normal player commands, too.  But it's a bit
confusing.  Change them to only require their own bit(3).
2012-02-25 11:22:36 +01:00
364b208f28 Drop useless nstat value VIS
A player may execute a command when his player->nstat has all the bits
in the command's c_permit.

All commands require bit(0).  All players always have it.  Silly; get
rid of it.
2012-02-25 11:20:03 +01:00
9f3e9f833a Clarify buytax econfig doc string
Reported by Scott C. Zielinski.
2012-02-21 18:11:23 +01:00
ca7578f1b8 Fix idle timeout during execute
Timeout during execute gets handled just like an EOF cookie: end the
batch file, resume reading normal commands.  That's wrong, we need to
close the connection.

A real EOF is recorded in the player's connection's EOF indicator.
Let's use that for all "connection needs to be closed" conditions, so
they all work the same.  Create io_set_eof() to provide access.

Make recvclient() set the player connection's EOF indicator on
timeout.  This makes the timeout "stick".  Record receipt of an EOF
cookie in new struct player member got_ctld.  Also abort the command,
as before.  This leaves further interpretation of the EOF cookie to
the command loops.

Make player_main() set the player connection's EOF indicator on
got_ctld.  Player connection gets closed on on EOF cookie, as before.

Change execute() to break the batch command loop when got_ctld is set,
then reset it.  Ends the batch file on EOF cookie, as before.

Change status() back to checking EOF and error indicators (partial
revert of commit 9c5854c8, v4.3.16), and drop struct player member
eof.
2012-02-21 18:10:52 +01:00
c4337f7aec Factor mailbox_create() out of nat_reset() and files.c 2011-12-29 11:47:07 +01:00