]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/xdump.c
Update copyright notice
[empserver] / src / lib / commands / xdump.c
index 6058220a45fa3bc26154f09b2944b29c36fb44a3..9e93a2f5f72c49037005dd26a384e3893b34e4d6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  xdump.c: Experimental extended dump
+ *  xdump.c: Extended dump
  * 
  *  Known contributors to this file:
- *     Markus Armbruster, 2004-2006
+ *     Markus Armbruster, 2004-2007
  */
 
-#include <config.h>
-
-#include <stddef.h>
-#include "misc.h"
-#include "file.h"
-#include "match.h"
-#include "news.h"
-#include "nsc.h"
-#include "optlist.h"
-#include "version.h"
-#include "commands.h"
-
 /*
  * Dump everything under the sun
  *
@@ -58,6 +46,7 @@
  * - News item characteristics: rpt[]
  * - News page headings: page_headings[]
  * - Commands: player_coms[] (TODO)
+ * - Update schedule: update_time[] (not really static)
  * - Configuration: configkeys[]
  *
  * Dynamic game data:
  * - Market: EF_COMM
  */
 
-/* FIXME document dump format */
+/*
+ * See doc/xdump for motivation, syntax, semantics, and rationale.
+ * Make sure to keep it up-to-date!
+ */
+
 /* TODO don't dump stuff that's useless due to options */
 
+#include <config.h>
+
+#include <ctype.h>
+#include <stddef.h>
+#include "commands.h"
+#include "empobj.h"
+#include "match.h"
+#include "news.h"
+#include "optlist.h"
+#include "treaty.h"
+#include "version.h"
+
 /*
  * Evaluate a attribute of an object into VAL, return VAL.
  * TYPE is the attribute's type.
@@ -108,7 +113,6 @@ xdprval(struct valstr *val, char *sep)
     unsigned char *s, *e, *l;
 
     switch (val->val_type) {
-    case NSC_TYPEID:
     case NSC_LONG:
        pr("%s%ld", sep, val->val_as.lng);
        break;
@@ -122,7 +126,10 @@ xdprval(struct valstr *val, char *sep)
            l = s + val->val_as.str.maxsz;
            /* FIXME maxsz == INT_MAX ! */
            for (;;) {
-               for (e=s; e<l && *e != '"' && *e != '\\' && isgraph(*e); ++e) ;
+               for (e = s;
+                    e < l && *e != '"' && *e != '\\' && isgraph(*e);
+                    ++e)
+                   ;
                pr("%.*s", (int)(e-s), s);
                if (e < l && *e)
                    pr("\\%03o", *e++);
@@ -135,7 +142,7 @@ xdprval(struct valstr *val, char *sep)
            pr("%snil", sep);
        break;
     default:
-       CANT_HAPPEN("Bad VAL type");
+       CANT_REACH();
        pr("0");
     }
     return " ";
@@ -191,7 +198,7 @@ xdftr(int n)
 static int
 xdvisible(int type, void *p)
 {
-    struct genitem *gp = p;
+    struct empobj *gp = p;
     struct trtstr *tp = p;
     struct lonstr *lp = p;
     struct natstr *natp;
@@ -199,6 +206,7 @@ xdvisible(int type, void *p)
 
     switch (type) {
     case EF_SECTOR:
+    case EF_REALM:
        return gp->own == player->cnum || player->god;
     case EF_SHIP:
     case EF_PLANE:
@@ -207,11 +215,9 @@ xdvisible(int type, void *p)
     case EF_LOST:
        return gp->own != 0 && (gp->own == player->cnum || player->god);
     case EF_NATION:
-       if (gp->own == player->cnum || player->god)
-           return 1;
-       /* fall through */
-    case EF_COUNTRY:
        return ((struct natstr *)p)->nat_stat != STAT_UNUSED;
+    case EF_COUNTRY:
+       return gp->own == player->cnum;
     case EF_NEWS:
        return ((struct nwsstr *)p)->nws_vrb != 0
            && (!opt_HIDDEN || player->god); /* FIXME */
@@ -242,7 +248,7 @@ xdvisible(int type, void *p)
        return player->god || tlev <= (int)(1.25 * natp->nat_level[NAT_TLEV]);
     case EF_NUKE_CHR:
        tlev = ((struct nchrstr *)p)->n_tech;
-       if (opt_DRNUKE) {
+       if (drnuke_const > MIN_DRNUKE_CONST) {
            natp = getnatp(player->cnum);
            if (tlev > (int)((int)(1.25 * natp->nat_level[NAT_RLEV])
                             / drnuke_const))
@@ -265,7 +271,6 @@ xdvisible(int type, void *p)
 static int
 xditem(int type, char *arg)
 {
-    int check_owner = !player->god && (ef_flags(type) & EFF_OWNER) != 0;
     struct castr *ca;
     struct nstr_item ni;
     int n;
@@ -388,25 +393,26 @@ xdump(void)
     char buf[1024];
     int type;
     int meta = 0;
+    struct natstr *natp;
 
-    if (!opt_GUINEA_PIGS) {
-       pr("You are not a guinea pig!\n");
-       return RET_FAIL;
-    }
-
-    p = getstarg(player->argp[1], "What? ", buf);
+    p = getstarg(player->argp[1], "Table name, or meta? ", buf);
     if (p && strcmp(p, "meta") == 0) {
        meta = 1;
-       p = getstarg(player->argp[2], "What? ", buf);
+       p = getstarg(player->argp[2], "Table name? ", buf);
     }
-    if (!p)
+    if (!p || !*p)
        return RET_SYN;
 
+    natp = getnatp(player->cnum);
     type = isdigit(p[0]) ? atoi(p) : ef_byname(p);
     if (type >= 0 && type < EF_MAX) {
        if (meta)
            return xdmeta(type);
-       else
+       else if ((EF_IS_GAME_STATE(type) || EF_IS_VIEW(type))
+                && !(natp->nat_stat == STAT_ACTIVE || player->god)) {
+           pr("Access to table %s denied\n", ef_nameof(type));
+           return RET_FAIL;
+       } else
            return xditem(type, player->argp[2]);
     } else if (!strncmp(p, "ver", strlen(p))) {
        return xdver(meta);