2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * xdump.c: Extended dump
30 * Known contributors to this file:
31 * Markus Armbruster, 2004-2008
44 * Is object P of type TYPE visible to the player?
45 * TODO: Fold this into interators.
48 xdvisible(int type, void *p)
50 struct empobj *gp = p;
51 struct trtstr *tp = p;
52 struct lonstr *lp = p;
59 return gp->own == player->cnum || player->god;
65 return gp->own != 0 && (gp->own == player->cnum || player->god);
67 return ((struct natstr *)p)->nat_stat != STAT_UNUSED;
69 return gp->own == player->cnum;
71 return ((struct nwsstr *)p)->nws_vrb != 0
72 && (!opt_HIDDEN || player->god); /* FIXME */
74 return tp->trt_status != TS_FREE
75 && (tp->trt_cna == player->cnum || tp->trt_cnb == player->cnum
78 if (lp->l_status == LS_FREE)
80 if (lp->l_status == LS_SIGNED)
82 return lp->l_loner == player->cnum || lp->l_lonee == player->cnum
88 tlev = ((struct mchrstr *)p)->m_tech;
91 tlev = ((struct plchrstr *)p)->pl_tech;
94 tlev = ((struct lchrstr *)p)->l_tech;
96 natp = getnatp(player->cnum);
97 return player->god || tlev <= (int)(1.25 * natp->nat_level[NAT_TLEV]);
99 tlev = ((struct nchrstr *)p)->n_tech;
100 if (drnuke_const > MIN_DRNUKE_CONST) {
101 natp = getnatp(player->cnum);
102 if (tlev > (int)((int)(1.25 * natp->nat_level[NAT_RLEV])
108 return ((struct rptstr *)p)->r_newspage != 0;
110 return ((struct empfile *)p)->cadef != NULL;
117 * Dump items of type TYPE selected by ARG to XD.
118 * Return RET_OK on success, RET_SYN on error.
121 xditem(struct xdstr *xd, int type, char *arg)
126 char buf[2048]; /* FIXME buffer size? */
132 if (!snxtitem(&ni, type, arg, NULL))
135 xdhdr(xd, ef_nameof(type), 0);
138 while (nxtitem(&ni, buf)) {
139 if (!xdvisible(type, buf))
151 /* Extended dump command */
162 p = getstarg(player->argp[1], "Table name, or meta? ", buf);
163 if (p && strcmp(p, "meta") == 0) {
165 p = getstarg(player->argp[2], "Table name? ", buf);
170 xdinit(&xd, player->cnum, 0, pr);
171 natp = getnatp(player->cnum);
172 type = isdigit(p[0]) ? atoi(p) : ef_byname(p);
173 if (type < 0 || type >= EF_MAX)
176 return xdmeta(&xd, type);
177 if ((EF_IS_GAME_STATE(type) || EF_IS_VIEW(type))
178 && !(natp->nat_stat == STAT_ACTIVE || player->god)) {
179 pr("Access to table %s denied\n", ef_nameof(type));
182 if (type == EF_VERSION && !player->argp[2])
183 return xditem(&xd, type, "*"); /* backward compatibility */
184 return xditem(&xd, type, player->argp[2]);