Commit graph

130 commits

Author SHA1 Message Date
93aa604b67 edit: Improve tech, research, edu, happiness change reporting
Print "Technology" instead of "Tech".  Print "FOO of CNAME (#CNUM)"
instead of just "FOO".  Print "unchanged" instead of "changed from X
to X" on no-op.

Send a bulletin to the unit owner and report news on change.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
a03d804ffc edit: Add remaining missing unit change reporting
Print a message (always), send a bulletin to the unit owner and report
news (sometimes).

The message is necessary to give the deity a chance to catch
unexpected changes, e.g. a player spending mobility right before the
deity edits it.  Watching out for such changes is especially important
with non-interactive edit.

Affected keys:

    cmd  key    struct member   action
    ----------------------------------
    edit s L    shp_x,y         B-
           E    shp_effic       BN
           M    shp_mobil       BN
           F    shp_fleet       B-
           T    shp_tech        BN
           a    shp_pstage      --
           b    shp_ptime       --
           R    shp_rpath       B-
    edit p l    pln_x,y         B-
           e    pln_effic       BN
           m    pln_mobil       BN
           w    pln_wing        B-
           t    pln_tech        BN
           r    pln_range       B-
    edit u L    lnd_x,y         B-
           e    lnd_effic       BN
           M    lnd_mobil       BN
           a    lnd_army        B-
           t    lnd_tech        BN
           F    lnd_harden      BN
           Z    lnd_retreat     B-
           R    lnd_rpath       B-

The two characters in column action show whether the command sends a
bulletin (B) or not (-), and whether it reports news (N) or not (-).

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
4aa2f071ba edit: Report flags change properly
Print a message, send bulletin to owner.  Affects ship key 'W', land
unit key 'W', and plane key 'f'.  The message is necessary to give the
deity a chance to catch unexpected changes, e.g. a player modifying
retreat conditions right before the deity edits them.  Watching out
for such changes is especially important with non-interactive edit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
3dceefbbc9 edit: Refuse to move planes and land units on carriers
They really need to stay with their carrier.  Else, cargo gets
silently teleported to its carrier when the carrier moves.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
cbe9897bfa edit: Report loading/unloading of planes & land units properly
Print a message, send bulletin to owner.  Affects plane keys 's', 'y',
and land unit keys 'S', 'Y'.  The message is necessary to give the
deity a chance to catch unexpected changes, e.g. a player loading a
plane right before the deity edits it.  Watching out for such changes
is especially important with non-interactive edit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
97b3aacaca edit: Report unit loss and gain properly for key 'U'
Send bulletin to owner and report news exactly like for key 'O' or
sector key 'L'.

Print a "duplicated" message, just for consistency with other keys.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
1f950f6a70 edit: Report unit key 'U' failure more nicely, and avoid oops
Two failure modes:

* When the argument is negative, edit() attempts an invalid write,
  triggering an oops.  edit() detects the write failure, and returns
  RET_FAIL.

  Detect the negative argument instead, and return RET_SYN, like we do
  for other invalid edit arguments.

* When the argument requires the table to be extended, but the
  extension fails, edit() returns RET_FAIL.

  Additionally report the failure to the player.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
ccd4368679 edit: Report unit loss and gain properly for unit key 'O'
Print a message describing the actual change.  Necessary to give the
deity a chance to catch unexpected changes, e.g. a player boarding a
ship right before the deity edits it.  Watching out for such changes
is especially important with non-interactive edit.

Code already sends bulletins.  Also report news.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
6e260f7f5e edit: Factor out edit_unit()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
b99a116dd6 edit: Report ship and land unit commodity change properly
Print a message describing the actual change.  Necessary to give the
deity a chance to catch unexpected changes, e.g. a player unloading
stuff right before the deity edits it, leaving fewer items than the
deity intends to take.  Watching out for such changes is especially
important with non-interactive edit.

Send bulletin to owner and report news exactly like the give command.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
004c4d0f23 edit &c: Report sector non-change differently
Print "unchanged" instead of "changed from X to X".  Affects edit,
setresource, setsector.  Suppress bulletin and news.  Affects only
edit sector key 'L'.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
6ff503c288 actofgod: Factor divine_sct_change() out of edit.c
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
82a59fbcc3 edit: Streamline wording of sector change reports slightly
Most places use "FOO of X,Y changed", some use "FOO in X,Y changed",
"FOO in X,Y was changed", "FOO of sector X,Y changed".  Normalize to
the former.

Most places do not end the message with a period, some do.  Normalize
to no period.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
5497126d05 edit: Fix stack smash in sector key 'L'
Key 'L' copies the source sector to a destination sector.  Bug: it
doesn't copy, it messes up the source sector badly instead, and can
smash the stack on some machines.

Root cause: doland() passes &sect instead of sect to ef_set_uid().
Impact:

1. ef_setuid() clobbers a few bytes at &sect.

   When the bitfield and uid fit into sizeof(sect) bytes, it clobbers
   just sect, which has no effect, because doland() returns without
   using it again.  This is the case on a typical 64-bit machine: bit
   field and uid are both 4 bytes, sizeof(sect) is 8.

   When they don't fit, whatever is adjacent to sect gets clobbered.
   On a typical 32-bit machine with stack growing down, that's p.
   Again, no effect, because doland() returns without using it again.
   With stack growing up, it could well be the return address,
   crashing the server.

2. ef_setuid() fails to update *sect.  Impact (when we survive 1):

   sect->sct_uid remains unchanged.  putsect() writes to the source
   sector instead of the destination sector, clobbering the source's
   sct_x, sct_y.  Breaks invariant sctoff(sct_x, sct_y) == sct_uid!
   Subsequent edits are all applied to the source sector.

   sect->sct_seqno remains unchanged.  No effect, because we write to
   the source sector, and the unchanged sequence number is the right
   one there.

Broken in commit 536ef0b0, v4.3.15.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
e109d981b8 setsector setresource: Switch to edit_sect()
One copy of the code suffices.

"Fertility content" becomes just "Fertility" in messages.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
f52a7e2739 edit: Parse int values in edit_FOO() helpers rather than edit()
Non-integer values are already parsed there.  Treating integer values
specially complicates things for no real gain.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
542a9ef83f edit &c: Add remaining missing sector change reporting
edit, setresource and setsector report change in three ways:

* Print a message.

* Send a bulletin to the changed object's owner.  This should be done
  if and only if the change is visible to the owner, e.g. in census or
  xdump.

* Report divine aid in news.  This should be done if and only if a
  bulletin was sent, except for changes that are neither negative nor
  positive, such as changing the distribution sector.

Fix the places that don't get it right for sectors:

    cmd  key    sctstr member   before  after   notes
    -------------------------------------------------
    edit l O    sct_oldown      --      B-
    edit l F    sct_fallout     --      BN      1
    edit l M    sct_mines       --      BN      2 3
    edit l D    sct_dist_x,y    --      B-      1
    edit l s    sct_type        --      B-      1
    edit l S    sct_newtype     --      B-      1
    setse ow    sct_own         B-      BN
    setse ol    sct_oldown      --      B-
    setse e     sct_effic       --      BN      2
    setse mo    sct_mobil       --      BN      2
    setse a     sct_avail       --      BN      2
    setse w     sct_work        --      BN      2

The two characters in columns before, after show whether the command
sends a bulletin (B) or not (-), and whether it reports news (N) or
not (-).

Notes:

1. Printed message massaged slightly for consistency with other keys.

2. Printed message improved to show the old value, too.  Necessary to
   give the deity a chance to catch unexpected changes, e.g. a player
   laying mines right before the deity edits them.  Watching out for
   such changes is especially important with non-interactive edit.

3. Bulletin and news suppressed for occupied sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
fec5ad692d edit: Report sector loss and gain properly for key 'L'
Send bulletin to owner and report news exactly like for key 'o'.

Also print a "sector duplicated" message, just for consistency with
other keys.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
a41c74967d edit: Limit resources to 100 instead of 127
Back in Empire 1, resources were limited consistently: fertility to
120, all others to 100.

When Chainsaw added setresource, consistency was lost: fertility got
limited to 100 there.

Chainsaw 3 changed edit to limit all resources to 127.

Commit 3fcee8dd and commit 8e430ae2 (both v4.3.11) changed fairland
and setsector to limit fertility to 100, matching setresource.

Now only edit remains different.  Change it to finally make things
consistent again.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
d4faa89c45 edit &c: Suppress bulletins for acts of god to himself
Deities get bulletins when they use edit, give, setsector and
setresource on stuff they own.  Except for POGO, who can't own
anything.

The bulletins are annoying; suppress them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
e507486fc1 edit &c: Suppress news for acts of god to gods
Option GODNEWS is documented to be about deities giving or taking
things from players.  Nevertheless, edit, give, setsector and
setresource report news of deities meddling with things owned by
deities other than POGO.  Don't.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
bdf7cbce38 edit &c: Suppress news and bulletins on no-op acts of god
give already suppresses when the new value equals the old one, but
edit, setresource and setsector don't.  Make them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
3072386d8d Send bulletins only from POGO
In the beginning, all bulletins came from POGO.  Chainsaw changed edit
and give to send them from the deity using the command.  Its new
command setresource sent from POGO regardless.  Its new command
setsector did both.

Go back to sending them only from POGO.

Some of the affected bulletins don't mention the acting deity.  Reword
them so they do.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
fb45b04420 edit: De-duplicate code for commodities on ships and land units
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
cdfdbbe5ce edit: Pass full keys around, not just first characters
To simplify the next commit.

Changes the error message for unknown keys to show the full key.
Shouldn't matter.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
c0f3a1e5e5 edit: Accept interactive empty key argument again
Empty key arguments work fine when passed as command arguments, but
not interactively.  For example, 'edit s 42 R ""' clears the retreat
path, but in an interactive 'edit s 43', 'R ""' sets it to "".

In Empire 1, omitting the argument made it empty.  Empire 2 turned
that into an error without providing an alternative.

Switch to the common command parser, so that quoting works, and "" is
parsed as empty argument.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:54:58 +02:00
33456b3371 edit: Treat blank interactive input like empty input
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:53:56 +02:00
546e1220e0 edit: Don't permit putting a land unit or plane on two carriers
Only one of struct lndstr members lnd_ship, lnd_land may be
non-negative.  When a deity screws that up, the server oopses.  Be
nice: when setting one, zap the other.

Same for struct plnstr members pln_ship, pln_land.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
2b80ce93da edit: Fix integer argument range checking
Upper bounds corrected:

    cmd  key  struct member   wrong   correct   notes
    -------------------------------------------------
    edit l m  sct_mobil         255       127      1
           t  sct_ptime         255     32767
    edit c b  nat_btu          1024  max_btus
    edit p m  pln_mobil         255       127      1
    edit u F  lnd_harden        255       127	   1

Missing bounds supplied, arguments out of bounds are silently clipped
unless noted otherwise:

    cmd  key     struct member   bounds           notes
    ---------------------------------------------------
    edit c t     nat_tgms        0   USHRT_MAX       2
           m     nat_reserve     0   INT_MAX
           T...  nat_level[]     0   infinity
    edit s a     shp_pstage      0   PLG_EXPOSED     3
           b     shp_ptime       0   32767
           M     shp_mobil    -127   127
           c...  shp_item[]      0   load limit      4
    edit u Y     lnd_land       -1   size of table   5
           M     lnd_mobil    -127   127
           S     lnd_ship       -1   size of table   5
           Z     lnd_retreat     0   100
           c...  lnd_item[]      0   load limit      4
    edit p r     pln_range       0   max range
           s     pln_ship       -1   size of table   5
           y     pln_land       -1   size of table   5

Notes:

1. Values between SCHAR_MAX and 255 were cast to signed char, changing
the sign.

2. The real upper bound is the number of telegrams in the mailbox, but
counting them isn't worth it.

3. This check is particularly important, because values out of bounds
make the server refuse to start without -F, and empdump -x warn
"export has errors, not importable as is".

4. Values outside 0..ITEM_MAX got caught and clipped by
item_prewrite().  This check avoids the oops, and tightens the upper
bound for units.

5. Argument out-of-bounds are rejected.  This check is particularly
important, because unit numbers beyond the size of the table trigger
oopses.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
c0dc4c42b5 edit: Drop pointless doland() variables old, des
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
29c7ae3d80 edit: Suppress "sunk!" after "taken from you by deity"
The fact that the ship wasn't given to anyone is none of the
ex-owner's business.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
381c479ff8 edit: Fix and unify handling of invalid country numbers
Negative numbers and numbers greater or equal than MAXNOC are invalid.
edit handles such arguments inconsistently:

    cmd  key  struct member   arg < 0     arg >= MAXNOC
    ---------------------------------------------------
    edit l o  sct_own         reject      MAXNOC - 1
           O  sct_oldown      reject      MAXNOC - 1
           X  sct_che_target  0           MAXNOC - 1
    edit s O  shp_own         cast        skip
    edit u O  lnd_own         cast        skip
    edit p O  pln_own         cast        skip

Legend:

    0           replace arg by 0
    MAXNOC - 1  replace arg by MAXNOC - 1
    reject      command fails
    cast        replace arg by (natid)arg
                bug: can be >= MAXNOC!
    skip        ignore this key and arg
                bug: telexes the owner he lost the unit, which is a lie

Unify to reject.  Matches setsector.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
aa07f3393a edit: Don't show loyalty, plague stage and time as percentages
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
53d0edc838 edit: Show edited planes and land units just like ships
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
59a15113d3 edit: Show the edited ship even when its owner is invalid
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02: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
383bbff603 edit: Rename some of helpers, and reorder parameters
doland() edits a sector, not a land unit.  That one's called dounit().
Lacks taste.  Call the helper for editing a FOO edit_FOO(), and make
the FOO * the first parameter instead of the last.

Rename the print helpers to print_FOO(), for consistency.  Also frees
up identifier prnat for the next commit.

While there, clean up an unused #define.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
726b9380d1 Replace common pattern by new LIMIT_TO()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:25 +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
199ea0cb39 Clean up redundant forward declarations 2013-05-08 06:55:21 +02: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
786e2a99d5 Clean up superfluous includes 2012-04-26 19:57:19 +02: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
a93c8f628f Remove edit keys deprecated in 4.3.15, 4.3.17 and 4.3.20
These are: ship and land 'B', land 'P', and plane 'n'.
2011-04-14 20:21:23 +02: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
5eb337e232 Clean up unobvious coordinate system use in doland()
Use the obviously correct newown instead of sect->sct_own.  They're
actually equal here.
2010-07-25 17:48:53 +02:00
373651359e Coding style fixes, mostly indentation and whitespace 2010-06-20 18:36:38 +02:00