Verify table uid sanity more tightly
verify_row() refrains from rejecting zero uids, because some tables may contain blank entries, with zero uid. Change it to check only header sanity for entries that are not in use. This filters out all legitimately blank entries. Tighten up the uid check. For computing "in use", factor empobj_in_use() out of xdvisible(). Note that xdvisible()'s case EF_COUNTRY doesn't bother to check nat_stat, because that's implied by what it does check. It's not implied in empobj_in_use(), so add it there.
This commit is contained in:
parent
fbf5b78129
commit
b30c83cd64
4 changed files with 60 additions and 39 deletions
|
@ -100,5 +100,6 @@ struct empobj_chr;
|
||||||
|
|
||||||
extern char *empobj_chr_name(struct empobj *gp);
|
extern char *empobj_chr_name(struct empobj *gp);
|
||||||
extern int get_empobj_mob_max(int type);
|
extern int get_empobj_mob_max(int type);
|
||||||
|
extern int empobj_in_use(int, void *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,10 +35,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "empobj.h"
|
#include "empobj.h"
|
||||||
#include "news.h"
|
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
#include "product.h"
|
|
||||||
#include "version.h"
|
|
||||||
#include "xdump.h"
|
#include "xdump.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -53,63 +50,45 @@ xdvisible(int type, void *p)
|
||||||
struct lonstr *lp = p;
|
struct lonstr *lp = p;
|
||||||
struct natstr *natp;
|
struct natstr *natp;
|
||||||
int tlev;
|
int tlev;
|
||||||
char *name;
|
|
||||||
|
if (!empobj_in_use(type, p))
|
||||||
|
return 0;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case EF_SECTOR:
|
case EF_SECTOR:
|
||||||
return gp->own == player->cnum || player->god;
|
|
||||||
case EF_SHIP:
|
case EF_SHIP:
|
||||||
case EF_PLANE:
|
case EF_PLANE:
|
||||||
case EF_LAND:
|
case EF_LAND:
|
||||||
case EF_NUKE:
|
case EF_NUKE:
|
||||||
case EF_LOST:
|
case EF_LOST:
|
||||||
return gp->own != 0 && (gp->own == player->cnum || player->god);
|
case EF_REALM:
|
||||||
case EF_NATION:
|
return gp->own == player->cnum || player->god;
|
||||||
return ((struct natstr *)p)->nat_stat != STAT_UNUSED;
|
|
||||||
case EF_COUNTRY:
|
case EF_COUNTRY:
|
||||||
return gp->own == player->cnum;
|
return gp->own == player->cnum;
|
||||||
case EF_NEWS:
|
case EF_NEWS:
|
||||||
return ((struct nwsstr *)p)->nws_vrb != 0
|
return !opt_HIDDEN || player->god; /* FIXME */
|
||||||
&& (!opt_HIDDEN || player->god); /* FIXME */
|
|
||||||
case EF_TREATY:
|
case EF_TREATY:
|
||||||
return tp->trt_status != TS_FREE
|
return tp->trt_cna == player->cnum
|
||||||
&& (tp->trt_cna == player->cnum || tp->trt_cnb == player->cnum
|
|| tp->trt_cnb == player->cnum
|
||||||
|| player->god);
|
|| player->god;
|
||||||
case EF_LOAN:
|
case EF_LOAN:
|
||||||
if (lp->l_status == LS_FREE)
|
|
||||||
return 0;
|
|
||||||
if (lp->l_status == LS_SIGNED)
|
if (lp->l_status == LS_SIGNED)
|
||||||
return 1;
|
return 1;
|
||||||
return lp->l_loner == player->cnum || lp->l_lonee == player->cnum
|
return lp->l_loner == player->cnum || lp->l_lonee == player->cnum
|
||||||
|| player->god;
|
|| player->god;
|
||||||
case EF_TRADE:
|
|
||||||
case EF_COMM:
|
|
||||||
return gp->own != 0;
|
|
||||||
case EF_REALM:
|
|
||||||
natp = getnatp(((struct realmstr *)p)->r_cnum);
|
|
||||||
return (gp->own == player->cnum || player->god)
|
|
||||||
&& (natp->nat_stat != STAT_UNUSED);
|
|
||||||
case EF_PRODUCT:
|
|
||||||
return ((struct pchrstr *)p)->p_sname[0] != 0;
|
|
||||||
case EF_SHIP_CHR:
|
case EF_SHIP_CHR:
|
||||||
tlev = ((struct mchrstr *)p)->m_tech;
|
tlev = ((struct mchrstr *)p)->m_tech;
|
||||||
name = ((struct mchrstr *)p)->m_name;
|
|
||||||
goto tech;
|
goto tech;
|
||||||
case EF_PLANE_CHR:
|
case EF_PLANE_CHR:
|
||||||
tlev = ((struct plchrstr *)p)->pl_tech;
|
tlev = ((struct plchrstr *)p)->pl_tech;
|
||||||
name = ((struct plchrstr *)p)->pl_name;
|
|
||||||
goto tech;
|
goto tech;
|
||||||
case EF_LAND_CHR:
|
case EF_LAND_CHR:
|
||||||
tlev = ((struct lchrstr *)p)->l_tech;
|
tlev = ((struct lchrstr *)p)->l_tech;
|
||||||
name = ((struct lchrstr *)p)->l_name;
|
|
||||||
tech:
|
tech:
|
||||||
natp = getnatp(player->cnum);
|
natp = getnatp(player->cnum);
|
||||||
if (!name[0])
|
|
||||||
return 0;
|
|
||||||
return player->god || tlev <= (int)(1.25 * natp->nat_level[NAT_TLEV]);
|
return player->god || tlev <= (int)(1.25 * natp->nat_level[NAT_TLEV]);
|
||||||
case EF_NUKE_CHR:
|
case EF_NUKE_CHR:
|
||||||
tlev = ((struct nchrstr *)p)->n_tech;
|
tlev = ((struct nchrstr *)p)->n_tech;
|
||||||
name = ((struct nchrstr *)p)->n_name;
|
|
||||||
if (drnuke_const > MIN_DRNUKE_CONST) {
|
if (drnuke_const > MIN_DRNUKE_CONST) {
|
||||||
natp = getnatp(player->cnum);
|
natp = getnatp(player->cnum);
|
||||||
if (tlev > (int)((int)(1.25 * natp->nat_level[NAT_RLEV])
|
if (tlev > (int)((int)(1.25 * natp->nat_level[NAT_RLEV])
|
||||||
|
@ -117,8 +96,6 @@ xdvisible(int type, void *p)
|
||||||
return player->god;
|
return player->god;
|
||||||
}
|
}
|
||||||
goto tech;
|
goto tech;
|
||||||
case EF_NEWS_CHR:
|
|
||||||
return ((struct rptstr *)p)->r_newspage != 0;
|
|
||||||
case EF_TABLE:
|
case EF_TABLE:
|
||||||
return ((struct empfile *)p)->cadef != NULL;
|
return ((struct empfile *)p)->cadef != NULL;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Ron Koenderink, 2005
|
* Ron Koenderink, 2005
|
||||||
* Markus Armbruster, 2006-2010
|
* Markus Armbruster, 2006-2011
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -36,10 +36,10 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "empobj.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "nsc.h"
|
#include "nsc.h"
|
||||||
#include "plane.h"
|
|
||||||
#include "product.h"
|
#include "product.h"
|
||||||
|
|
||||||
static void verify_fail(int, int, struct castr *, int, char *, ...)
|
static void verify_fail(int, int, struct castr *, int, char *, ...)
|
||||||
|
@ -130,7 +130,7 @@ static int
|
||||||
verify_row(int type, int row)
|
verify_row(int type, int row)
|
||||||
{
|
{
|
||||||
struct castr *ca = ef_cadef(type);
|
struct castr *ca = ef_cadef(type);
|
||||||
struct emptypedstr *row_ref;
|
struct empobj *row_ref;
|
||||||
int i, j, n;
|
int i, j, n;
|
||||||
struct valstr val;
|
struct valstr val;
|
||||||
int ret_val = 0;
|
int ret_val = 0;
|
||||||
|
@ -150,6 +150,9 @@ verify_row(int type, int row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empobj_in_use(type, row_ref))
|
||||||
|
return ret_val;
|
||||||
|
|
||||||
for (i = 0; ca[i].ca_name; ++i) {
|
for (i = 0; ca[i].ca_name; ++i) {
|
||||||
if (ca[i].ca_get)
|
if (ca[i].ca_get)
|
||||||
continue; /* virtual */
|
continue; /* virtual */
|
||||||
|
@ -166,10 +169,6 @@ verify_row(int type, int row)
|
||||||
}
|
}
|
||||||
if (ca[i].ca_table == type && i == 0) {
|
if (ca[i].ca_table == type && i == 0) {
|
||||||
/* uid */
|
/* uid */
|
||||||
/* Some files contain zeroed records, cope */
|
|
||||||
/* TODO tighten this check */
|
|
||||||
if (val.val_as.lng == 0)
|
|
||||||
continue;
|
|
||||||
if (val.val_as.lng != row) {
|
if (val.val_as.lng != row) {
|
||||||
verify_fail(type, row, &ca[i], j,
|
verify_fail(type, row, &ca[i], j,
|
||||||
"value is %ld instead of %d",
|
"value is %ld instead of %d",
|
||||||
|
|
|
@ -36,7 +36,9 @@
|
||||||
|
|
||||||
#include "empobj.h"
|
#include "empobj.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
#include "news.h"
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
|
#include "product.h"
|
||||||
|
|
||||||
char *
|
char *
|
||||||
empobj_chr_name(struct empobj *gp)
|
empobj_chr_name(struct empobj *gp)
|
||||||
|
@ -73,3 +75,45 @@ get_empobj_mob_max(int type)
|
||||||
CANT_REACH();
|
CANT_REACH();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
empobj_in_use(int type, void *p)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case EF_SHIP:
|
||||||
|
case EF_PLANE:
|
||||||
|
case EF_LAND:
|
||||||
|
case EF_NUKE:
|
||||||
|
case EF_TRADE:
|
||||||
|
case EF_COMM:
|
||||||
|
case EF_LOST:
|
||||||
|
return ((struct empobj *)p)->own != 0;
|
||||||
|
case EF_NATION:
|
||||||
|
case EF_COUNTRY:
|
||||||
|
return ((struct natstr *)p)->nat_stat != STAT_UNUSED;
|
||||||
|
case EF_NEWS:
|
||||||
|
return ((struct nwsstr *)p)->nws_vrb != 0;
|
||||||
|
case EF_TREATY:
|
||||||
|
return ((struct trtstr *)p)->trt_status != TS_FREE;
|
||||||
|
case EF_LOAN:
|
||||||
|
return ((struct lonstr *)p)->l_status != LS_FREE;
|
||||||
|
case EF_REALM:
|
||||||
|
return empobj_in_use(EF_NATION,
|
||||||
|
ef_ptr(EF_NATION,
|
||||||
|
((struct realmstr *)p)->r_cnum));
|
||||||
|
case EF_PRODUCT:
|
||||||
|
return ((struct pchrstr *)p)->p_sname[0];
|
||||||
|
case EF_SHIP_CHR:
|
||||||
|
return ((struct mchrstr *)p)->m_name[0];
|
||||||
|
case EF_PLANE_CHR:
|
||||||
|
return ((struct plchrstr *)p)->pl_name[0];
|
||||||
|
case EF_LAND_CHR:
|
||||||
|
return ((struct lchrstr *)p)->l_name[0];
|
||||||
|
case EF_NUKE_CHR:
|
||||||
|
return ((struct nchrstr *)p)->n_name[0];
|
||||||
|
case EF_NEWS_CHR:
|
||||||
|
return ((struct rptstr *)p)->r_newspage != 0;
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue