Commit graph

116 commits

Author SHA1 Message Date
afe5001a23 Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 09:38:32 +02:00
92693cba65 relations: Move relations state from struct natstr to relatstr
Relations state is relatively bulky: it's a big chunk of struct
natstr, and adds 200 bytes per country to xdump nat.

Relations change rarely.  Rewriting it to disk on every nation update
and retransmitting it in every xdump nat is wasteful.

To avoid this waste, move relations state to its own struct relatstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:22 +02:00
de24545963 relations: Create EF_RELAT table of struct relatstr
New struct relatstr is basically empty so far.  The next commit will
move relations state from struct natstr to struct relatstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
33f7ae79fe nat: Move putnat() into nat_reset() and simplify
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
414a5e179f relations: Eliminate getrel()
Most uses of getrel() have been replaced by the safer relations_with()
in commit 0c60e57..67b9135, v4.3.27.  Eliminate the remaining ones:

* Convert rela() to use relations_with().  The case of relations to
  self, where the two differ, doesn't occur.  The code becomes more
  easier to understand, even.

* relations_with() is then getrel()'s last user.  Inline.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
f54f655130 relations: Inline relatename() into its only caller rela()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
129fe58c19 relations: Encapsulate relates[] in relations_string()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
0b05f11d28 relations: New enum relations
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
f88365e762 relations: Inline putrel() into its only caller setrel()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
e5db45058d reject: Change nat_accepts()'s first parameter to natid
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
eaa678c903 reject: Move reject state from struct natstr to rejectstr
Reject state is relatively bulky: it's a big chunk of struct natstr,
and adds almost 200 bytes per country to xdump nat.

Reject state changes rarely.  Rewriting it to disk on every nation
update and retransmitting it in every xdump nat is wasteful.

To avoid this waste, move reject state to its own struct rejectstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
f35f16c0a2 reject: Create EF_REJECT table of struct rejectstr
New struct rejectstr is basically empty so far.  The next commit will
move reject state from struct natstr to struct rejectstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
4628661b40 reject: New enum rej_comm for REJ_TELE & friends
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
9d153f547c reject: Replace getrejects() by nat_accepts()
All callers of getrejects() also check whether the sender is a deity.
Factor out the common code into nat_accepts(), and drop getrejects().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
8a129dee20 reject: Inline putreject() into its only caller setrej()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
d35303d426 contact: Change in_contact()'s first parameter to natid
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
c8e7548f24 contact: Move contact state from struct natstr to contactstr
Contact state is relatively bulky: it's a big chunk of struct natstr,
and adds almost 200 bytes per country to xdump nat for deities.

Contact changes rarely.  Since we avoid unnecessary updates, it
doesn't change at all unless option HIDDEN is enabled.  Rewriting it
to disk on every nation update and retransmitting it in every deity
xdump nat is wasteful.

To avoid this waste, move contact state to its own struct contactstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
4b4df53485 contact: Create EF_CONTACT table of struct contactstr
New struct contactstr is basically empty so far.  The next commit will
move contact state from struct natstr to struct contactstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
7cc34abaca contact: Rename getcontact() to in_contact()
The next commit will create a contact file, and the macro to get a
contact entry will be named getcontact().  Rename the existing
getcontact() out of the way.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
00d0664bcd contact: Inline putcontact() into its only caller setcont()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
549561ff03 Include "file.h" where it's needed
Several headers define macros that use ef_ptr() without including
"file.h".  Fix that.  Drop redundant inclusions elsewhere.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:31 +02:00
bae3f5447e Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-07-02 17:45:44 +02:00
eba87789ab Fix and clean up some comments
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-12-05 12:31:08 +01:00
b14f5276ab Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-28 16:21:34 +01:00
9ef4f1bf50 player: Drop long-disabled code to resolve IP addresses
Disabled since commit 32fac04 (v4.2.13) because it could at the time
use more stack space than we provided.  Additional issues: code still
uses obsolete gethostbyaddr() rather than getnameinfo(), and we
provide only 512 bytes for host names instead of the customary
NI_MAXHOST (1025) bytes.

All three issues would be easy enough to fix.  What's not so easy is
to avoid blocking on the synchronous DNS lookup.  Without that,
connecting repeatedly from a range of addresses with slow reverse
lookup could conceivably be employed as a denial of service attack.

We've been living without reverse lookup for close to ten years.  Bury
the corpse, and move on.

Bonus: sizeof(struct natstr) is cut in half.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:59 +01:00
a109de948b Remove option TREATIES
TREATIES has issues:

* Treaties can cover attack, assault, paradrop, board, lboard, fire,
  build (s|p|l|n) and enlist, but not bomb, launch, torpedo and
  enlistment centers.

* Usability is very poor.  While a treaty is in effect, every player
  action that violates a treaty condition triggers a prompt like this:

    This action is in contravention of  treaty #0 (with Curmudgeon)
    Do you wish to go ahead anyway? [yn]

  If you decline, the action is not executed.  If you accept, it is.
  In both cases, your decision is reported in the news.

  You cannot get rid of these prompts until the treaty expires.

* Virtually nobody uses them.

* Virtually unused code is buggy code.  There is at least one race
  condition: multifire() reads the firing sector, ship or land unit
  before the treaty prompt, and writes it back after, triggering a
  generation oops.  Any updates made by other threads while trechk()
  waits for input are wiped out, triggering a seqno mismatch oops.

* The treaty prompts could confuse smart clients that aren't prepared
  for them.  WinACE isn't, but is reported to work anyway at least
  common usage.  Ron Koenderink (the WinACE maintainer) suspects there
  could be a few situations where it will fail.

This feature is not earning its keep.  Remove it.  Drop command
treaty, consider treaty, offer treaty, xdump treaty, reject treaties.
Output of accept changed, obviously.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:44:14 +01:00
4877a2f024 accept: rejectname() makes no sense outside acce(); inline
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-03 20:45:25 +01:00
bb467c335d Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:33:48 +01:00
61a32b8b69 prnat() prnatid(): New, common country name (#number) formatting
prnat() is more convenient when you already got the struct natstr *.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +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
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
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
df4925d696 Update copyright notice 2013-01-12 17:45:01 +01:00
1118f1c0ca Update copyright notice 2012-06-10 10:52:22 +02: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
5232add0f5 nat_reset() is no longer used with STAT_SANCT, simplify 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
98cd2a3a70 Update known contributors comments 2011-04-14 20:21:23 +02:00
7e2008e7f4 License upgrade to GPL version 3 or later
Why upgrade?  I'm not a lawyer, but here's my take on the differences
to version 2:

* Software patents: better protection against abuse of patents to
  prevent users from exercising the rights under the GPL.  I doubt
  we'll get hit with a patent suit, but it's a good move just on
  general principles.

* License compatibility: compatible with more free licenses, i.e. can
  "steal" more free software for use in Empire.  I don't expect to steal
  much, but it's nice to have the option.

* Definition of "source code": modernization of some details for today's
  networked world, to make it easier to distribute the software.  Not
  really relevant to us now, as we normally distribute full source code.

* Tivoization: this is about putting GPL-licensed software in hardware,
  then make the hardware refuse to run modified software.  "Neat" trick
  to effectively deny its users their rights under the GPL.  Abuse was
  "pioneered" by TiVo (popular digital video recorders).  GPLv3 forbids
  it.  Unlikely to become a problem for us.

* Internationalization: more careful wording, to harden the license
  outside the US.  The lawyers tell us it better be done that way.

* License violations: friendlier way to deal with license violations.
  This has come out of past experience enforcing the GPL.

* Additional permissions: Probably not relevant to us.

Also include myself in the list of principal authors.
2011-04-12 21:20:58 +02:00
bb5cd07ce5 New relations_with()
Relations checking with getrel() often needs a special case for "is
same country".  If you forget, you get behavior appropriate for a
neutral foreign country, which is usually very wrong (see commit
16c68eb4 for an example).

Unlike getrel(), relations_with() considers countries allied to
themselves.  Less dangerous.  In fact, allied behavior is typically
just right, so the special case isn't even needed.
2011-02-13 17:48:58 +01:00
439f111f98 Remove option SLOW_WAR
SLOW_WAR has issues:

* The check whether the attacker old-owns the attacked sector is
  broken, because att_abort() uses sect.sct_oldown uninitialized.

  Spotted by the Clang Static Analyzer.

* Its implementation in setrel() is somewhat scary.  It's actually
  okay, because that part of setrel() only runs within decl().  Other
  callers don't reach it: update_main() because player->god != 0
  there, and the rest because they never pass a rel < HOSTILE.

* Documentation is a bit vague.

SLOW_WAR hasn't been used in a public game in years.  Fixing it is not
worth it, so remove it instead.
2011-02-13 15:59:49 +01:00
b1a36aebf7 Tidy up whitespace in macro replacement lists 2010-06-20 18:39:31 +02:00
25d29c8f8f Convert tab after #define to space 2010-06-20 18:38:54 +02:00
7465574195 Break long lines more tastefully 2010-06-20 18:36:44 +02:00
373651359e Coding style fixes, mostly indentation and whitespace 2010-06-20 18:36:38 +02:00
73e25ff21e Update copyright notice 2010-01-19 08:40:17 +01:00
2fa5f65257 Generation numbers to catch write back of stale copies
Oops when a stale copy is written back, i.e. the processor was yielded
since the copy was made.  Such bugs are difficult to spot.  Sequence
numbers catch them when they do actual harm (they also catch different
bugs).  Generation numbers catch them even when they don't.

New ef_generation to count generations.  Call new ef_make_stale() to
increment it whenever the processor may be yielded.

New struct emptypedstr member generation.  To conserve space, make it
a bit-field of twelve bits, i.e. generations are only recorded modulo
2^12.  Make sure all members of unit empobj_storage share it.  It is
only used in copies; its value on disk and in the cache is
meaningless.  Copies with generation other than ef_generation are
stale.  Stale copies that are a multiple of 2^12 generations old can't
be detected, but that is sufficiently improbable.

Set generation to ef_generation by calling new ef_mark_fresh() when
making copies in ef_read() and ef_blank().  nav_ship() and
fltp_to_list() make copies without going through ef_read(), and
therefore need to call ef_mark_fresh() as well.  Also call it in
obj_changed() to make check_sect_ok() & friends freshen their argument
when it is unchanged.

New must_be_fresh() oopses when its argument is stale.  Call it in
ef_write() to catch write back of stale copies.
2010-01-19 08:36:01 +01:00
358aee203e Store sequence numbers more compactly
Store them and ef_type in bit-fields.

Allocate eight bits for ef_type.  Values range from 0 to EF_GAME
(currently 16), so this is plenty.

Allocate twelve bits for sequence numbers.  Sequence number mismatches
are now missed when the numbers are equal modulo 2^12.  Still
sufficiently improbable.

Common machines store the bit-fields in a 32 bit word.  There are
twelve bits left in that word for future use.  Total savings 16 bits,
which is exactly what the previous commit spent on wider uids on
common machines.
2010-01-19 08:31:10 +01:00