Commit graph

4061 commits

Author SHA1 Message Date
63f972d31c Overhaul how xundump keeps track of current object
Factor tracking of cur_type, cur_obj, cur_id and cur_is_blank into a
set of functions.  They replace getobj().  While there, improve some
error messages.
2011-06-25 16:50:41 +02:00
465c0c8587 Move src/lib/subs/empobj.c back to src/lib/common/
Commit 77e95bd7 (v4.3.12) moved it from its natural home because
obj_nameof() required stuff from subs/.  Now that obj_nameof() is
gone, move it back.
2011-06-25 16:50:20 +02:00
1c93c5fbc8 Rename obj_nameof() to unit_nameof() and move to unitsub.c 2011-06-25 16:50:20 +02:00
766788480f Remove unused get_empobj_chr()
Unused since commit 5e77193c, v4.3.24.
2011-06-25 16:50:20 +02:00
79f289c365 Refuse to grow or truncate files with fixed size
Make ef_write() treat it like any other invalid write beyond the file
size: oops.  Be less harsh in ef_extend() and ef_truncate(): log an
error.
2011-06-25 16:50:20 +02:00
7d2269b5ae Make ef_open() extend files with fixed size automatically
Turns the fixed size into an invariant.  Before, the files utility
created them empty, then extended them.
2011-06-25 16:50:06 +02:00
31b9ff08f3 Move pln_oninit(), lnd_oninit(), nuk_oninit() to filetable.c
They set up invariants, and thus should be always active, not just in
the server.  Since ef_blank() isn't used for these files outside the
server right now, this isn't a bug fix, just cleanup.
2011-06-25 16:50:06 +02:00
3fe3cd376f Move file initialization from files.c to empfile oninit()
files.c writes initial contents to game state files with fixed size.
Necessary for setting up invariants, such as struct sctstr members
sct_x, sct_y matching sct_uid.

Do that from the oninit() callback, so ef_blank() sets up invariants
correctly.  Since ef_blank() isn't used for these files right now,
this isn't a bug fix, just cleanup.
2011-06-25 16:50:06 +02:00
576a3c60ed Initialize empfile user callbacks explicitly
Instead of stuffing NULL initializers into the cache initializer
macros UNMAPPED_CACHE(), ARRAY_CACHE(), PTR_CACHE(), ARRAY_TABLE().
In preparation of having some non-NULL initializers.
2011-06-25 16:50:06 +02:00
58ed1d1b9e Fix empdump not to grow game state files with fixed size
empdump -i now complains about extra rows instead of silently growing
the file to a size the server will reject.  Affects tables sector,
nation, realms, game.

Bonus fix: better error message on I/O error or insufficient memory.
2011-06-25 16:50:06 +02:00
73bd5d6aa3 Fix empdump not to truncate game state files with fixed size
empdump -i now complains about missing rows instead of silently
truncating the file to a size the server will reject.  Affects tables
sector, nation, realms, game.
2011-06-25 16:50:06 +02:00
0fcd935999 Clean up how game state file sizes are checked
New struct empfile member nent replaces ef_open() parameter nelt.
Cleaner, because the expected size is a property of the file, not of
how it's used.  Also fixes empdump to check file sizes.

Complication: with EFF_CREATE, ef_open() creates an empty file, to be
extended to the correct size.  Callers passed nelt argument -1 along
with EFF_CREATE, to make ef_open() accept the empty file.  Can't do
the same for empfile member nent.  Instead, make ef_open() not check
the (zero) size then.

Replaces commit 5750107b, v4.3.15.
2011-06-25 16:50:06 +02:00
516ab86a6e Fix empdump to open views, too
ef_verify() assumes views are open.  Bug is harmless, because
ef_nelem() returns zero for closed views, and ef_verify() accesses
only immutable parts of struct empfile then.
2011-06-25 16:50:06 +02:00
44f97c3297 Clean up how a view's base table is defined
New struct empfile member base replaces ef_open_view() parameter base.
Cleaner, because the base table is a property of the view, not of how
it's used.

Use it to clean up verify_fail()'s base table access, and for extra
sanity checks in ef_open() and ef_open_view().
2011-06-25 16:50:06 +02:00
2b0b53992f Simplify how ef_write() handles write beyond end of file 2011-06-25 16:50:06 +02:00
f50fc19aab Make ef_close() set fids later, so it's cleaned up on error
Just for cleanliness.
2011-06-25 16:50:06 +02:00
5d54e424df Clean up ef_close() to zap csize along with cache 2011-06-25 16:50:06 +02:00
a485084777 Change struct empfile callback onresize() to return void
ef_open() handles onresize() failing incorrectly.  Instead of fixing
that, drop the failure mode.  It's not really used: unit_onresize()
fails only when used incorrectly.  It isn't.  If it ever is, ignoring
the failure is safe.
2011-06-25 16:50:05 +02:00
45c7337e70 Fix clearing mutable flags on ef_close()
Make ef_close() clear them always, even for views.  Harmless, as
ef_open_view() always sets the same flags.

Drop redundant assignment to ep->flags in ef_open().  ef_close()
clears mutable flags, no need to clear them some more right before
calling it.  Missed in commit 3eb3607f, v4.3.0.
2011-06-25 16:50:05 +02:00
84cdd89060 Fix EFF_IMMUTABLE to include EFF_SENTINEL
ef_open() and ef_close() clear EFF_SENTINEL because of that.  Broken
since commit 1492845c (v4.3.17) added EFF_SENTINEL.  Harmless, as no
file-backed table has a sentinel.
2011-06-25 16:50:05 +02:00
5703bdd61c Fix ef_open()'s error message for file larger than static cache
The message claims the file is larger than it actually is.  Broken
since commit 71908018 (v4.3.0) implemented static cache in ef_open().
Harmless, because no file-backed table has a statically allocated
cache.
2011-06-25 16:50:05 +02:00
bd453cd821 Fix how empdump rejects attempt to split table sect
Split tables require the record index in the leftmost column.
defellipsis() correctly rejects "..." when the table doesn't have one.
It fails to reject it when it has one that is NSC_EXTRA, and thus not
permitted in a dump.  This is the case for table sect.  defellipsis()
happily succeeds, then chkflds() demands column "uid" if it's missing,
and rejects it if its present.
2011-06-25 16:50:05 +02:00
b40741dc5f empdump failed to catch some invalid column names
It missed those with more flags than just NSC_EXTRA set: table sect
name uid, table nat names passwd, xorg, yorg, contacts, rejects.
Since xundump() doesn't provide space for these, the bug could lead to
buffer overruns.  Fixes flawed commit 726a8e3d, v4.3.12.
2011-06-25 16:50:05 +02:00
7e95b52bce Fix empdump to check for truncation failure
xubody() neglected to check ef_truncate()'s return value.  Two failure
modes: invalid arguments, and ftruncate() failure.  The former
shouldn't happen, and the latter can happen only for file-backed
tables, hence only in empdump -i.
2011-06-25 16:49:58 +02:00
5cedc533f8 Make xundump report invalid record IDs
It failed silently before.
2011-06-25 16:49:57 +02:00
50070a8f9a Make xundump reject numbers that don't fit into integral field
Numbers are read into a double, then cast to the field type.  The cast
may change the value.  Flag that as error, except for floating-point
fields.
2011-06-25 16:49:57 +02:00
029d929b1b Restrict xundump to tables with a file name
Tables with a file name are: any game state, and any table that's
initialized from a .config file.

Tables that are no longer customizable: "updates" (customization had
no effect, because update_get_schedule() overwrote it), "table",
"meta" and the symbol tables (customization couldn't change them
anyway), and news-chr (customizing r_newsstory[] was kind of neat, but
unsafe because they are format strings for sprintf()).
2011-06-25 16:47:57 +02:00
573d3fe870 Fix xdump updates not to dump bogus extra updates
"xdump updates" believes there are always 15 (UPDATE_TIME_LEN - 1)
scheduled updates.  When fewer than 15 updates are scheduled, it shows
whatever crap update time happens to be in the unused part of
update_time[]: the initial zero or a previously scheduled update.

Root cause is that table EF_UPDATES has always UPDATE_TIME_LEN - 1
entries, which is incorrect when fewer updates are scheduled.  Only
xdump is affected, as the other users ignore the length and stop at
the sentinel.

Fix update_get_schedule() to resize table EF_UPDATES.
2011-06-25 16:45:31 +02:00
5b9d31a4b3 Check record uid comes first in split config tables
setnum() requires the record uid to come first, so we better ensure it
does.
2011-06-25 16:45:31 +02:00
cb3e35cb3a Don't stop checking xdump field headers when join field is missing
Also improve the error message a bit.
2011-06-25 16:45:31 +02:00
6e4772b175 A few comment fixes for nsc.[ch] file.[ch] 2011-06-25 16:45:31 +02:00
03a2c61de4 Better document how .config must match compiled-in UIDs 2011-06-25 16:45:29 +02:00
221268e0e1 Provide proper ca_table for carrier unit# selectors
Makes ef_verify() check carrier UIDs are sane.  Partially protects
unit_cargo_init(), which oopses on bad carriers.

This has become possible only since commit 64a53c90 (v4.3.17) set
their values to -1 in newly created units.  Before, they were zero in
units that had never been used, and a proper ca_table would have made
ef_verify() fail when unit#0 didn't exist.

The only unit# selectors left without a proper ca_table are ship's
follow, lost's id and trade's unitid.  Document why.
2011-06-25 16:44:04 +02:00
54fa510425 Update examples in doc/xdump to current server's output
The NSC_CONST flags added in commit fa63f87b have always been missing
here.  The previous commit changed xdump meta meta.  Other than that,
it's just different encodings.
2011-06-25 16:44:04 +02:00
b461cd3ae7 Provide proper ca_table for meta selector table
No idea why it was missing.
2011-06-25 16:44:04 +02:00
19215160f4 Refer to table names instead of C identifiers in .config
The C identifier permits looking up the table in the source.  The
table name permits lookup with xdump.

Coders should know how to go from table name to C identifier.  Deities
aren't all coders; we shouldn't ask them to guess table names from C
identifiers.
2011-06-06 19:24:13 +02:00
97f475b6c1 Oops in verify_row() when non-integral selector references a table 2011-06-06 19:24:13 +02:00
e1caa11733 Don't ignore non-virtual NSC_EXTRA columns in ef_verify.c
These are commonly timestamps (no verification implemented), or
aliases for a non-extra column (which gets verified).  Commit 49780e2c
(v4.3.12) added the exception: EF_SECTOR's uid.  Proof by example that
ignoring these columns is wrong.  Fix: ignore only virtual columns.
2011-06-06 19:24:13 +02:00
ed715061be Fix use-after-free when plane gets shot down or aborted by flak
ac_fireflak() dereferenced plp after ac_planedamage() freed it.
Broken in commit 16b16e34, v4.3.27.  Diagnosed with valgrind.
2011-06-06 19:21:09 +02:00
de9d7b011f Drop superfluous parameter vec[] of build_ship() & friends
All callers pass sp->sct_item.
2011-05-29 15:45:11 +02:00
6b0a70d3d1 Better diagnostics when build can't find suitable sectors
Report "No sectors" when there are no *owned* sectors, instead of "Bad
sector specification" when there are no sectors at all.
2011-05-29 15:45:11 +02:00
5fb330cfdd Clean up buil()'s variable declarations 2011-05-29 15:45:11 +02:00
c6137c7ba2 Make "build n" accept the optional tech argument
It has currently no real effect on the nuke built (nukes don't improve
with tech), but the special case is ugly, and is inconsistent with
info build.
2011-05-29 15:45:11 +02:00
61e00d5559 Simplify buil(): factor "can't build" handling out of switch cases 2011-05-29 15:45:03 +02:00
164b90760f Simplify buil(): factor getting third argument out of switch cases 2011-04-23 18:11:42 +02:00
98a9b53c0f Simplify buil(): replace a switch by a function pointer
To enable that, make build_ship() & friends all take the same int type
argument instead of each one its own pointer.  Passing pointers
triggered "may be used uninitialized" compiler warnings (the code was
safe despite the warnings).
2011-04-23 18:11:42 +02:00
8f6c4f18d7 Don't truncate research before multiplying with drnuke_const
For drnuke_const 0.33, research level 92.4 now suffices for a tech 280
nuke.  Before, you needed 93, which was inconsistent with what
version's promise "need 0.33 times the tech level in research".
2011-04-23 18:11:42 +02:00
316436bcfa Create nukes at the tech level permitted by research
The tech level is visible to players, but currently has no effect.
2011-04-23 18:11:42 +02:00
df07e45b70 Bridge building required 0.005 tech less than advertized, fix
Has been that way since bridge building required tech.
2011-04-23 18:11:42 +02:00
9ef7200406 Simplify build_bridge(): replace a switch by a function pointer 2011-04-23 18:11:42 +02:00