Commit graph

4179 commits

Author SHA1 Message Date
1c24a812e8 Final change log polish for 4.3.29 2012-01-20 20:21:51 +01:00
46d36f1975 Update change log for 4.3.29 2012-01-15 19:47:04 +01:00
90a263d5ef drop and fly from carrier can fail to load last civ or mil
pln_equip() refuses to abandon its base sector.  Unfortunately, it
checks even when flying off carriers, and refuses to load the last
civilian or military depending on what happens to be in uninitialized
variable sect.

Broken in commit 91139692, v4.3.0.
2011-12-29 11:47:07 +01:00
213501cabb Clean up journal_open() to open the journal write-only
We don't actually need update mode.
2011-12-29 11:47:07 +01:00
421907fcb8 Clean up read to open telegram file read-only
Update mode hasn't been necessary since 4.0.11 dropped use of
ftruncate().
2011-12-29 11:47:07 +01:00
cda63a40d8 Check for mailbox creation failure
Deity command add logs the failure, utility program files reports it
and exits unsuccessfully.  Before, this failure was silently ignored.
2011-12-29 11:47:07 +01:00
c4337f7aec Factor mailbox_create() out of nat_reset() and files.c 2011-12-29 11:47:07 +01:00
8b7591f5d7 Change read and wire to never delete a corrupt mailbox
Before, rea() deleted the mailbox regardless of errors.  Acceptable
only when the user gets a chance to avoid that after the problem is
reported.  Not the case for "read y".

Not an issue for announcements, but treat them the same for
simplicity.
2011-12-29 11:47:07 +01:00
b6f666cff9 Clean up how read deals with new telegram arrivals
Fooling around with the file size is silly.  It works only because
read has flag C_MOD set, so they can only arrive while we're sitting
at the delete confirmation prompt, not during reading.

Simply try to read more telegrams instead.
2011-12-29 11:47:07 +01:00
43f562145e Change wire not to read more after confirming deletion
Telegram deletion deletes the mailbox.  If more telegrams arrive while
we wait for the player to confirm deletion, the mailbox again contains
unread telegrams, so we can't just delete it.  Instead, rea() loops to
read the new telegrams.

Announcements worked the same until Empire 3 put them in a single file
shared by all.  Since then, deleting announcements merely updates
nat_annotim, and there's no need to read new announcements after
getting the player's confirmation.  So don't.
2011-12-29 11:47:07 +01:00
5acdcfec63 Limit telegram squashing to 5s total
Before, only the time between adjacent telegrams was limited, not the
total time.
2011-12-29 11:47:07 +01:00
4d046738fd Don't lie "You have a new telegram" after read with inform off
Here's how telegram notification works with NF_INFORM off: typed_wu()
increments the telegram recipient's nat_tgms.  status(), running right
before command prompts, notifies the player when nat_tgms > 0, and
resets it.  Thus, we tell the player how many telegrams arrived since
the previous command prompt.

However, what we really want is something else, namely the number of
"new telegrams waiting".  That's what the notification message says,
after all.  Telegrams already printed by read shouldn't count, even
when they arrived since the previous command prompt.

Make them not count by clearing pending telegrams on read regardless
of toggle inform.

Same for announcements.
2011-12-29 11:47:07 +01:00
e8f0495950 Fix telegram notifications during read (toggle inform on)
Reset number of pending telegrams before delete prompt instead of
after.

Before, the client claimed pending telegrams at that prompt, because
it wasn't C_INFORMed of the read, yet.  Worse, if more telegrams
arrived while sitting at the prompt, the reset clobbered their number
and sent a bogus clear C_INFORM message, effectively hiding the new
arrivals from the player.
2011-12-29 11:47:07 +01:00
a0e91cbc5e Fix wire not to clear pending telegrams with toggle inform on
Broken since Empire 2 introduced toggle inform.
2011-12-29 11:47:07 +01:00
b98a806d82 Fix pending anno count for annos squashed together
Adjacent announcements are squashed together when the sender is the
same and the timestamp is "close enough".  Except typed_wu()
increments natstr member nat_ann regardless.  Fix that to work exactly
like nat_tgms.
2011-12-29 11:47:07 +01:00
17223e8fe2 Fix read not to split production report when update is slow
Adjacent telegrams are squashed together if type and sender are the
same, and the timestamp is "close enough".  This is done in two
places: rea() and typed_wu().  They're inconsistent: typed_wu()
ignores the timestamp for production reports since Empire 2, but rea()
doesn't.

Record typed_wu()'s decision in new telstr member tel_cont.  Use it in
rea().
2011-12-29 11:47:06 +01:00
a0b82b8d46 Simplify how typed_wu() counts telegrams
typed_wu() counts telegrams to update nat_tgms and, since Empire 2,
send C_INFORM messages.  Adjacent telegrams are squashed together if
type and sender are the same, and the timestamp is within TEL_SECONDS.

typed_wu() increments nat_tgms when it sends a telegram that read
doesn't squash into the previous one.

Since Empire 2, it also sends a C_INFORM message then.  Inexplicably,
it fails to use the same condition: it tests just new_tele, not
new_tele || np->nat_tgms == 0.  C_INFORM messages got missed, until
4.0.18 made rea() call clear_telegram_is_new().  Convoluted.

Send C_INFORM exactly when incrementing nat_tgms, and back out
4.0.18's fix.
2011-12-29 11:47:06 +01:00
a5bcb63b85 Fix clear_telegram_is_new() for TEL_NORM from POGO at the epoch
Purely theoretical, of course.
2011-12-29 11:47:06 +01:00
35e897f70b Clean up how telegram_is_new() detects production report
Test for TEL_UPDATE, not update_running.
2011-12-29 11:47:06 +01:00
ac5dac0690 Move clear_telegram_is_new() call to beginning of update
The call was added in 4.2.5 "so that the next telegram is flagged as
new and not part of the update".  Since the update sends only
TEL_UPDATE telegrams (the previous commit restored that property), and
nothing else does, the next telegram is flagged as new automatically,
except when it's from the next update.  Document that, and move the
call to a more natural place.
2011-12-29 11:47:06 +01:00
d46b168663 Ensure the update's production report isn't split by bulletins
During the update, wu() sends TEL_UPDATE telegrams ("Production
Report") instead of TEL_BULLETIN telegrams, but typed_wu() has no such
logic.  It's used by tele(), which doesn't run during the update, and
mpr(), which may, e.g. called from ship or mission code used by
autonav or sail.  This inserts bulletins in the middle of the
production report, splitting it apart.

Happens since mpr() was added in Empire 2.  Before, only tele() used
typed_wu() directly, and everything else wu().

Change mpr() to use wu().
2011-12-29 11:47:06 +01:00
9f9cbfb20c Saner error handling in typed_wu()
Leave nat_ann, nat_tgm alone and return -1 on all errors.  Before,
only failed open was handled that way.  Failed write and close were
logged and ignored.  While there, improve the log messages a bit.

Note: the return value fix has little effect.  It makes tele() log the
failure, which is redundant.  Everything else goes through wu() and
ignores the value.
2011-12-29 11:47:06 +01:00
0b2b51bbcb Drop superfluous fseek() from rea() 2011-12-29 11:47:06 +01:00
6d98cd3134 Make add require confirmation for unadvisable actions
Deleting a country in state STAT_SANCT, STAT_ACTIVE or STAT_GOD is
risky, because any references to this country become dangling, which
makes ef_verify() unhappy.  For a reason: we may well have code that
isn't prepared for dangling references, and breaks.

Replacing a country that is being used is risky, because it can get us
into weird states.  For instance, replacing a player by a visitor can
result in a visitor that owns stuff.
2011-12-29 11:47:06 +01:00
d2057af7a2 Make add refuse to touch a country while it's being played
I suspect player code could get terminally confused by country state
changing unexpectedly.  Not worth the risk.
2011-12-29 11:47:06 +01:00
881b6fbd2b Fix add not to crash on negative country number 2011-12-29 11:47:06 +01:00
b36727e7fb Don't bother giving POGO BTUs in files
Deity's BTUs get reset to maximum on login anyway.
2011-12-29 11:47:06 +01:00
37e9b6aa9c Create all deities with $123456789, not just POGO 2011-12-29 11:47:06 +01:00
ad308c5de8 Move setting nat_cnam, nat_pnam into nat_reset() 2011-12-29 11:47:06 +01:00
bb442abdcd Use nat_reset() for POGO in files.c
Requires moving it from subs/natsub.c to common/nat.c.
2011-12-29 11:47:06 +01:00
5fd595a59a Make files set the usual nation flags for POGO
The add command sets nation flags NF_FLASH, NF_BEEP, NF_COASTWATCH,
NF_SONAR, and since 4.2.6 NF_TECHLISTS.  POGO is created by the files
utility, which sets only NF_FLASH (since 4.2.2).  Change files to
match add.
2011-12-29 11:47:05 +01:00
5232add0f5 nat_reset() is no longer used with STAT_SANCT, simplify 2011-12-29 11:47:05 +01:00
7739830594 Change newcap back to not wiping the country
Just create sanctuaries, put country into STAT_SANCT, grant BTUs and
money, set origin and initial realms.

This reverts commit e1a68c72 (v4.3.12) as far as newcap is concerned.
Except we still set nat_access, because that needs to be set along
with nat_btu.

Additionally, leave levels and telegrams alone.

Should have no effect in practice, because newcap works only in
STAT_NEW, and we get there with the add command, which wipes the
country.
2011-12-29 11:47:05 +01:00
6984f9d982 Make add always reset the country
Before, add reset the country only when adding a player or a visitor.
When adding a deity or deleting a country, it set just nat_cnam,
nat_pnam and nat_state.  Has always been that way.

Because of that, a newly minted deity country could inherit all kinds
of crap from a previous user of its country number: origin, realms,
relations, telegrams, ...  Harmless if the country number has never
been used before, which is how add is generally used.

When adding a deity country, initial levels (start_education, ...) now
apply, relations start NEUTRAL instead of AT_WAR, and the usual
initial nation flags are set.

Reset on delete as well, just to get rid of the special case.
2011-12-29 11:47:05 +01:00
373f20a8b5 Rename add argument "new" to "player"
This makes the correct choice for player countries obvious.  Keep
recognizing "new" for now, but deprecate it.
2011-12-29 11:47:05 +01:00
3fb00c79d9 Drop add argument "active"
Argument "active" is obscure.  It creates a country in STAT_ACTIVE
that doesn't have a capital, and has its origin at the true origin.
If you really want such a country, create it in STAT_NEW normally,
then use edit to go to STAT_ACTIVE.
2011-12-29 11:47:05 +01:00
62f0da239f Drop add's obscure sector check and wipe functionality
If you really need to wipe out a country, there's much more to wipe
than just sectors.
2011-12-29 11:47:05 +01:00
a9e485b13e Drop add's undocumented land unit destruction feature
It doesn't destroy ships, planes or nukes, either.
2011-12-29 11:47:05 +01:00
062c660e28 Permit no-op country name change again
Commit aa5861d1 (v4.3.20) made add, edit and change reject a country
name that is already in use.  Even if it's used by the same country.
Relax that.
2011-12-29 11:47:05 +01:00
9b2e906ea1 Improve newcap's origin error message 2011-12-29 11:47:05 +01:00
c9b380eee4 Streamline a few files error messages
Write one nice line to stderr instead of a cryptic one to stderr, and
an uninformative one to stdout.
2011-12-29 11:47:05 +01:00
73129c15cc Fix files and fairland to report ef_open() failure just once
ef_open() already reports failure since commit 7eb2fe57, v4.2.20.
Drop the second report from its callers.
2011-12-29 11:47:05 +01:00
f006e373f9 Replace exit(-1) by exit(1)
exit() uses only the least significant byte of its argument.
2011-12-29 11:47:05 +01:00
06753c7e2b Make allocate_memory() return void
It can't fail since commit ba1a320c, v4.3.15.
2011-12-29 11:47:05 +01:00
9be42299b5 Guard against unusable fd in pthreads' empth_select()
0 <= fd < FD_SETSIZE must hold, or else undefined behavior in
FD_SET().
2011-12-29 11:47:05 +01:00
55e689fb31 Fix lwpSleepFd()'s guard against unusable fd
0 <= fd < FD_SETSIZE must hold, or else undefined behavior in FD_SET()
and buffer overrun in LwpFdwait[fd].  Check of upper bound off by one,
check of lower bound missing.
2011-12-29 11:47:05 +01:00
0b66d8e281 Plug FILE leak on show_first_tel() error paths
Leak introduced in commit 4238323d, v4.3.20.  Unlikely to bite in
practice, as only corrupt mailbox files can cause these errors.
2011-12-29 11:47:05 +01:00
8e391f29a1 Plug memory leak in set_paths() error path
Leak appeared in commit 91eefc3f, v4.3.12.  Harmless in practice,
since the error is ultimately fatal.
2011-12-29 11:47:05 +01:00
5a77a8186e Fix read_schedule() not to fclose(stdin)
Did that since the initial commit 71320ed6, v4.3.10.
2011-12-29 11:47:04 +01:00
881dd41626 Plug FILE leak on read_schedule() parse error path
Leak introduced in initial commit 71320ed6, v4.3.10.
2011-12-29 11:47:04 +01:00