(ef_read): Used to get the file size again some circumstances; doesn't
make sense, as no other process may be writing this file.
(ef_write): Don't refuse to write beyond record 65536. This module
can cope with that. Some users have trouble long before that (short
record numbers), but that should be handled there.
(ef_extend): Use do_write() & simplify. Catch table not file-backed.
Catch negative count; used to have no effect with EFF_MEM, and
confusion otherwise. Try to recover from partially successful
extension. Need help from ef_write() to do a better job; to be done.
(ef_open): Failed to reset empfile member fd on failure, and leaked
file descriptors.
(ef_flush, ef_close): Rely on negative fd instead of null cache to
detect unopened file. This is more logical and consistent with the
use of cache by the new tables that are not file-backed (rev. 1.22).
Use CANT_HAPPEN().
(ef_close): Failed to report cash flush failure.
(ef_close): Clear all EFF_OPEN flags. Should have been done in
rev. 1.27.
(do_write): New.
(ef_flush, ef_write): Use it. Old code couldn't cope with interrupted
or short writes (mostly harmless, as disk reads commonly complete).
(ef_write): Use CANT_HAPPEN() for catching unimplemented table
extensions.
(fillcache): Rewrite. Old version failed to check success of lseek(),
couldn't cope with interrupted or short reads (mostly harmless, as
disk reads commonly complete), and left an empty cache after a failed
read.
(ef_open): Use fillcache() instead of read().
(ef_read): Fail if fillcache() fails to read at least one element.
Old version copied garbage to its caller and claimed success.
(ef_open, EFF_RDONLY, EFF_CREATE, EFF_OPEN): Replace mode parameter
(really open flags, not mode) by new flags EFF_RDONLY, EFF_CREATE.
Open flags were needlessly general. Callers changed.
(empfile): Member mode now unused, remove.
(START_UNITS, start_unit_type, deity_build_land, new): Remove
undocumented compile-time option START_UNITS. It hasn't been used in
ages; writing a quick build script is easier than recompiling the
server.
(draw_map): Parameter bmap abused EF_MAP and EF_BMAP, and required the
silly EF_NMAP. Use characters instead: 'b' for bmap (was EF_BMAP),
't' for true bmap (was EF_MAP), 'r' for revert (was EF_MAP+EF_BMAP,
more sillness), and 'n' for nmap (was EF_NMAP). Callers changed.
(EF_NMAP): Remove.
(map, draw_map): Remove undocumented feature that lets deities run map
as another country. It appeared around Chainsaw 3.0 and never fully
worked. See also #1335316.
(ioq_destroy) [aix, NeXT]: Remove special case, which leaked memory,
because freeing it didn't work at some time. Well, it either works
now, or we'll find out what's wrong.
Ron Koenderink [Sat, 22 Oct 2005 16:39:45 +0000 (16:39 +0000)]
(castr,empfile,ship_chr,plane_chr,land_chr,nuke_chr):
Add table index to castr to create a reference to the symbol table.
Add "ship chr flags" table to empfile.
Add "plane chr flags" table to empfile.
Add "land chr flags" table to empfile.
Add "nuke chr flags" table to empfile.
Add EF_SHIP_CHR_FLAGS reference to ship_chr.
Add EF_PLANE_CHR_FLAGS reference to plane_chr.
Add EF_LAND_CHR_FLAGS reference to land_chr.
Add EF_NUKE_CHR_FLAGS reference to nuke_chr.
(show_ship_capab,show_plane_capab,show_land_capab,
show_nuke_capab,ship_flags,land_flags,plane_flags,nuke_flags):
Move ship_flags nsc.c from show.c
Rename ship_flags to ship_chr_flags.
Move plane_flags nsc.c from show.c
Rename plane_flags to plane_chr_flags.
Move land_flags nsc.c from show.c
Rename land_flags to land_chr_flags.
Move nuke_flags nsc.c from show.c
Rename nuke_flags to nuke_chr_flags.
This is to accomodate future symbol table for EF_PLANE table.
Ron Koenderink [Sat, 22 Oct 2005 13:55:04 +0000 (13:55 +0000)]
(ef_init): Remove cadef member from fileinit,
insert directly into the empfile structure.
Add ef_type member to fileinit to identify rows with data.
Remove unused rows of fileinit.
(player_init): Fix initialization of sin. Some systems have a member
sin_zero and choke when it's not zeroed. INADDR_ANY wasn't converted
to network byte order, but since it's zero, the bug couldn't bite.
(empfile, chr_camap): Merge chr_camap[] into empfile[]. No existing
user sees the new elements of empfile[].
(EF_SECTOR_CHR, EF_SHIP_CHR, EF_PLANE_CHR, EF_LAND_CHR, EF_NUKE_CHR)
(EF_TREATY_CHR, EF_ITEM, EF_INFRASTRUCTURE, EF_PRODUCT): New. Not yet
used.
(my_ef_byname): Replacement for ef_byname() that sees the new
elements.
(xdchr): Work with empfile[] instead of chr_camap[].
(xdump): Use my_ef_byname() instead of ef_byname() and
chridx_by_name().
(camap, chr_camap, chridx_by_name): Remove.
Ron Koenderink [Tue, 18 Oct 2005 16:11:19 +0000 (16:11 +0000)]
(do_conv) Move the initialization of the natp to be inside sector loop, this
allows the deity to use the research level of the sector owner. This also
fixes the use of an uninitialized sector data structure.
Ron Koenderink [Tue, 18 Oct 2005 12:14:10 +0000 (12:14 +0000)]
(ichr_ca,pchr_ca,dchr_ca,mchr_ca,plchr_ca,lchr_ca,nchr_ca,
tchr_ca,rpt_ca,intrchr_ca ) Move from src/lib/commands/xdump.c
to src/lib/global/nsc.c; external linkage. They were created in
xdump.c to minimize initial impact on the source, but they
really belong to nsc.c, where other code can use them as well.
(babies): Err, the maxpop case wasn't an optimization... Without
that, we get negative babies, which leads to negative avail and baby
food (cannibalism?) in grow_people(). Restore it.
(get_assembly_point): Close loophole that allowed players to find all
unowned sectors. The assembly point must now be owned or allied, or
have an owned or allied ship.
Info pages didn't match the old rule. Fix them to match the new rule.
(ac_encounter): Non-recon missions no longer make contact to owner of
sectors overflown, because only recon missions identify the owner.
This matches info Hidden.
(add): Initialize nat_last_login and nat_last_logout to zero rather
than current time. Nation addition time is irrelevant.
(natstr): Document zero nat_last_login, nat_last_login mean never
logged in/out.
(player_main): Test nat_last_login zero instead of nat_hostaddr empty.
(player_main): Assign nat_userid, nat_hostname, nat_hostaddr straight
from player. The last connection's host is now shown as dotted quads
instead of nowhere when the name isn't known.
(natstr): Document that nat_userid, nat_hostname may be empty.
(player_main): Simplify printing last connection address: nat_hostaddr
can't be empty here; don't bother to substitute "nobody" for empty
user.
(lndstr, natstr, shpstr): Fix string types from s_char[] to char[].
They were declared NSC_STRINGY in their selector descriptors, and
NSC_STRINGY is specified to represent char[].
(player): Get rid of s_char.
(babies): Factored out of grow_people(). Identical, except it doesn't
bother to `optimize' the maxpop case, and it drops the weird food
limit computation for opt_NOFOOD, which didn't limited for any
reasonable game parameters.
(natstr): Member nat_connected is inappropriate, because it is
transient server state, not persistent game state. Remove.
(player_main, edit): Remove uses.
(coun): Use getplayer() instead of nat_connected. Delete the message
on command being out of order.
(player_find_other): Replace by getplayer. player_find_other()
searches for a player other than US for country CNUM, which is in
state PS_PLAYING. Since there can be at most one player in state
PS_PLAYING, and no caller pass that player as US, they can simply use
getplayer() instead.
(getplayer): There may be multiple players for the same country in the
list of players, but at most one in state PS_PLAYING. getplayer()
used to get the one first in the list. However, its callers need the
one in state PS_PLAYING. In particular, typed_wu() notifies the
player obtained from getplayer(). If the player in state PS_PLAYING
isn't first, say because another one is trying to log in, the
notification gets lost. Fix by making getplayer() return the player
in state PS_PLAYING.