(xdvisible): New.

(xditem): Use it.  This plugs all known information leaks.  It also
avoids dumping of unused records.
This commit is contained in:
Markus Armbruster 2006-01-03 17:07:41 +00:00
parent 6245d97358
commit de8aea7a0f

View file

@ -28,7 +28,7 @@
* xdump.c: Experimental extended dump * xdump.c: Experimental extended dump
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2004 * Markus Armbruster, 2004-2006
*/ */
#include <config.h> #include <config.h>
@ -181,6 +181,68 @@ xdftr(int n)
pr("/%d\n", n); pr("/%d\n", n);
} }
/*
* Is object P of type TYPE visible to the player?
* TODO: Fold this into interators.
*/
static int
xdvisible(int type, void *p)
{
struct genitem *gp = p;
struct trtstr *tp = p;
struct lonstr *lp = p;
struct natstr *natp;
int tlev;
switch (type) {
case EF_SECTOR:
return gp->own == player->cnum || player->god;
case EF_SHIP:
case EF_PLANE:
case EF_LAND:
case EF_NUKE:
case EF_LOST:
return gp->own != 0 && (gp->own == player->cnum || player->god);
case EF_NATION:
return ((struct natstr *)p)->nat_stat != 0
&& (gp->own == player->cnum || player->god);
case EF_NEWS:
return ((struct nwsstr *)p)->nws_vrb != 0 && !opt_HIDDEN; /* FIXME */
case EF_TREATY:
return tp->trt_status != TS_FREE
&& (tp->trt_cna == player->cnum || tp->trt_cnb == player->cnum);
case EF_LOAN:
if (lp->l_status == LS_FREE)
return 0;
if (lp->l_status == LS_SIGNED)
return 1;
return lp->l_loner == player->cnum || lp->l_lonee == player->cnum;
case EF_TRADE:
case EF_COMM:
return gp->own != 0;
case EF_SHIP_CHR:
tlev = ((struct mchrstr *)p)->m_tech;
goto tech;
case EF_PLANE_CHR:
tlev = ((struct plchrstr *)p)->pl_tech;
goto tech;
case EF_LAND_CHR:
tlev = ((struct lchrstr *)p)->l_tech;
goto tech;
case EF_NUKE_CHR:
tlev = ((struct nchrstr *)p)->n_tech;
tech:
natp = getnatp(player->cnum);
return tlev <= (int)(1.25 * natp->nat_level[NAT_TLEV]);
case EF_NEWS_CHR:
return ((struct rptstr *)p)->r_newspage != 0;
case EF_TABLE:
return ((struct empfile *)p)->cadef != NULL;
default:
return 1;
}
}
/* /*
* Dump items of type TYPE selected by ARG. * Dump items of type TYPE selected by ARG.
* Return RET_OK on success, RET_SYN on error. * Return RET_OK on success, RET_SYN on error.
@ -205,7 +267,7 @@ xditem(int type, char *arg)
n = 0; n = 0;
while (nxtitem(&ni, buf)) { while (nxtitem(&ni, buf)) {
if (check_owner && ((struct genitem *)buf)->own != player->cnum) if (!xdvisible(type, buf))
continue; continue;
++n; ++n;
xdflds(ca, buf); xdflds(ca, buf);