2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * xdump.c: Extended dump
29 * Known contributors to this file:
30 * Markus Armbruster, 2004-2008
43 * Is object P of type TYPE visible to the player?
44 * TODO: Fold this into interators.
47 xdvisible(int type, void *p)
49 struct empobj *gp = p;
50 struct trtstr *tp = p;
51 struct lonstr *lp = p;
58 return gp->own == player->cnum || player->god;
64 return gp->own != 0 && (gp->own == player->cnum || player->god);
66 return ((struct natstr *)p)->nat_stat != STAT_UNUSED;
68 return gp->own == player->cnum;
70 return ((struct nwsstr *)p)->nws_vrb != 0
71 && (!opt_HIDDEN || player->god); /* FIXME */
73 return tp->trt_status != TS_FREE
74 && (tp->trt_cna == player->cnum || tp->trt_cnb == player->cnum
77 if (lp->l_status == LS_FREE)
79 if (lp->l_status == LS_SIGNED)
81 return lp->l_loner == player->cnum || lp->l_lonee == player->cnum
87 tlev = ((struct mchrstr *)p)->m_tech;
90 tlev = ((struct plchrstr *)p)->pl_tech;
93 tlev = ((struct lchrstr *)p)->l_tech;
95 natp = getnatp(player->cnum);
96 return player->god || tlev <= (int)(1.25 * natp->nat_level[NAT_TLEV]);
98 tlev = ((struct nchrstr *)p)->n_tech;
99 if (drnuke_const > MIN_DRNUKE_CONST) {
100 natp = getnatp(player->cnum);
101 if (tlev > (int)((int)(1.25 * natp->nat_level[NAT_RLEV])
107 return ((struct rptstr *)p)->r_newspage != 0;
109 return ((struct empfile *)p)->cadef != NULL;
116 * Dump items of type TYPE selected by ARG to XD.
117 * Return RET_OK on success, RET_SYN on error.
120 xditem(struct xdstr *xd, int type, char *arg)
125 char buf[2048]; /* FIXME buffer size? */
131 if (!snxtitem(&ni, type, arg, NULL))
134 xdhdr(xd, ef_nameof(type), 0);
137 while (nxtitem(&ni, buf)) {
138 if (!xdvisible(type, buf))
150 /* Extended dump command */
161 p = getstarg(player->argp[1], "Table name, or meta? ", buf);
162 if (p && strcmp(p, "meta") == 0) {
164 p = getstarg(player->argp[2], "Table name? ", buf);
169 xdinit(&xd, player->cnum, 0, pr);
170 natp = getnatp(player->cnum);
171 type = isdigit(p[0]) ? atoi(p) : ef_byname(p);
172 if (type < 0 || type >= EF_MAX)
175 return xdmeta(&xd, type);
176 if ((EF_IS_GAME_STATE(type) || EF_IS_VIEW(type))
177 && !(natp->nat_stat == STAT_ACTIVE || player->god)) {
178 pr("Access to table %s denied\n", ef_nameof(type));
181 if (type == EF_VERSION && !player->argp[2])
182 return xditem(&xd, type, "*"); /* backward compatibility */
183 return xditem(&xd, type, player->argp[2]);