]> git.pond.sub.org Git - empserver/commitdiff
(EFF_OWNER): The assertion that EFF_OWNER implies ef_read() sets
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 29 May 2005 14:14:33 +0000 (14:14 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 29 May 2005 14:14:33 +0000 (14:14 +0000)
player->owner is no longer used.  Use it to indicate that owner can be
accessed through struct genitem, similar to EFF_XY and EFF_GROUP.
(xdump): Fix ownership checking.  Old version worked only when
nxtitem() set player->owner.

(empfile): Set EFF_OWNER for EF_LOST.  This fixes `xdump lost'
disclosing other countries' losses.
(loststr): Document implications of EFF_OWNER.

(empfile): Set EFF_OWNER for EF_NATION.
(natstr): Rearrange members for EFF_OWNER, document.
(nat_ca): Unused so far.  Clean it up, add most missing selectors.
(fileinit): Use it.  This implements `xdump nation'.

(fileinit): Simplify setting map file size.

include/file.h
include/lost.h
include/nat.h
src/lib/commands/xdump.c
src/lib/global/file.c
src/lib/global/nsc.c
src/lib/subs/fileinit.c

index bf2c2bc77fd733713f1e77b4cf5ba59f09af20d9..51584ba8050d5d3dfe11b2f1f85ade6a2747cc7c 100644 (file)
@@ -58,11 +58,9 @@ struct empfile {
 /*
  * struct empfile flags
  *
- * EFF_XY and EFF_GROUP assert that coordinates / group of such a
- * file's record can be safely obtained by dereferencing its memory
- * address cast to struct genitem *.
- *
- * EFF_OWNER asserts that player->owner is set by ef_read().
+ * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
+ * group of such a file's record can be safely obtained by
+ * dereferencing its memory address cast to struct genitem *.
  */
 #define EFF_XY         bit(0)  /* has location */
 #define EFF_MEM                bit(1)  /* stored entirely in-memory */
index 51cf70cc6c409be1948551d95486395432956650..ae29c8f59e2b2b2faeac6286ea7a24fd6a0681d2 100644 (file)
 #define _LOST_H_
 
 struct loststr {
+    /* initial part must match struct genitem */
     short ef_type;
     natid lost_owner;          /* Who lost it */
+    /* end of part matching struct genitem */
     int lost_uid;              /* lost ID */
     char lost_type;            /* Type of thing (ship, plane, nuke, land, sector) */
     short lost_id;             /* ID of lost thing */
index 2d63877765f1610299571e4a5f86cec896fb8f2d..b65e49f32e5e46078a587025dfcc5c0326cb3886 100644 (file)
@@ -57,7 +57,11 @@ struct boundstr {
 };
 
 struct natstr {
+    /* initial part must match struct genitem */
     short ef_type;
+    natid nat_cnum;            /* our country number */
+    /* end of part matching struct genitem */
+    s_char nat_stat;           /* inuse, norm, god, abs */
     s_char nat_cnam[20];       /* country name */
     s_char nat_pnam[20];       /* representative */
     s_char nat_hostaddr[32];   /* host addr of last user */
@@ -66,8 +70,6 @@ struct natstr {
     coord nat_xstart, nat_ystart;      /* cap location at start */
     coord nat_xcap, nat_ycap;  /* cap location in abs coords */
     coord nat_xorg, nat_yorg;  /* origin location in abs coords */
-    natid nat_cnum;            /* our country number */
-    s_char nat_stat;           /* inuse, norm, god, abs */
     s_char nat_dayno;          /* day of the year mod 128 */
     s_char nat_connected;      /* connected or not? */
     s_char nat_update;         /* Want an update or not. */
index e549c15d971a91e99ec063276a2fab9bc4fbfbf7..97aa14b96caf3181abb5140f425d69519de25b42 100644 (file)
@@ -56,7 +56,7 @@
  * - News item characteristics: rpt[] (TODO)
  * - News page headings: page_headings[] (TODO)
  * - Treaty clause characteristics: tchr[]
- * - Commands: coms[] (TODO)
+ * - Commands: player_coms[] (TODO)
  * - Options: Options[]
  * - Configuration: configkeys[]
  *
@@ -406,6 +406,7 @@ xdftr(int n)
 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;
@@ -422,7 +423,7 @@ xditem(int type, char *arg)
 
     n = 0;
     while (nxtitem(&ni, buf)) {
-       if (!player->owner)
+       if (check_owner && ((struct genitem *)buf)->own != player->cnum)
            continue;
        ++n;
        xdflds(ca, buf);
index c569210854820d5c6aa0bc0e8061322f91ebb028..f97c796f455335a1cce189064cec86ce29d3bae5 100644 (file)
@@ -80,7 +80,7 @@ struct empfile empfile[] = {
     {"pow", "power", 0,
      0, sizeof(struct powstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"nat", "nation", 0,
+    {"nat", "nation", EFF_OWNER,
      0, sizeof(struct natstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
     {"loan", "loan", 0,
@@ -95,7 +95,7 @@ struct empfile empfile[] = {
     {"commodity", "commodity", 0,
      0, sizeof(struct comstr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0},
-    {"lost", "lostitems", 0,
+    {"lost", "lostitems", EFF_OWNER,
      0, sizeof(struct loststr), 0, 0, 0, 0,
      -1, -1, 0, 0, 0, 0, 0}
 };
index 1741d334111a498e7b1de6822b613809d2992816..cb269ce4cefbb27e95921f918ee332f12be81315 100644 (file)
@@ -225,7 +225,7 @@ struct castr nuke_ca[] = {
     {NSC_XCOORD, 0, 0, fldoff(nukstr, nuk_x), "xloc"},
     {NSC_YCOORD, 0, 0, fldoff(nukstr, nuk_y), "yloc"},
     {NSC_CHAR, 0, 0, fldoff(nukstr, nuk_n), "number"},
-    {NSC_SHORT, 0, N_MAXNUKE, fldoff(nukstr, nuk_types[0]), "types"},
+    {NSC_SHORT, 0, N_MAXNUKE, fldoff(nukstr, nuk_types), "types"},
     {NSC_TIME, NSC_EXTRA, 0, fldoff(nukstr, nuk_timestamp), "timestamp"},
     {NSC_NOTYPE, 0, 0, 0, NULL}
 };
@@ -307,40 +307,36 @@ struct castr trade_ca[] = {
 };
 
 struct castr nat_ca[] = {
-    {NSC_CHAR, 0, 20, fldoff(natstr, nat_cnam[0]), "cnam"},
-    {NSC_CHAR, NSC_DEITY, 20, fldoff(natstr, nat_pnam[0]), "pnam"},
+    {NSC_NATID, 0, 0, fldoff(natstr, nat_cnum), "cnum"},
+    {NSC_CHAR, 0, 0, fldoff(natstr, nat_stat), "stat"},
+    {NSC_STRINGY, 0, 20, fldoff(natstr, nat_cnam), "cname"},
+    {NSC_STRINGY, NSC_DEITY, 20, fldoff(natstr, nat_pnam), "passwd"},
+    {NSC_STRINGY, 0, 32, fldoff(natstr, nat_hostaddr), "ip"},
+    {NSC_STRINGY, 0, 512, fldoff(natstr, nat_hostname), "hostname"},
+    {NSC_STRINGY, 0, 32, fldoff(natstr, nat_userid), "userid"},
     {NSC_XCOORD, 0, 0, fldoff(natstr, nat_xstart), "xstart"},
     {NSC_YCOORD, 0, 0, fldoff(natstr, nat_ystart), "ystart"},
     {NSC_XCOORD, 0, 0, fldoff(natstr, nat_xcap), "xcap"},
     {NSC_YCOORD, 0, 0, fldoff(natstr, nat_ycap), "ycap"},
     {NSC_XCOORD, NSC_DEITY, 0, fldoff(natstr, nat_xorg), "xorg"},
     {NSC_YCOORD, NSC_DEITY, 0, fldoff(natstr, nat_yorg), "yorg"},
-    {NSC_NATID, 0, 0, fldoff(natstr, nat_cnum), "cnum"},
-#ifdef MAYBE_LATER
-    {NSC_CHAR, 0, 0, fldoff(natstr, nat_stat), "stat"},
-    {NSC_CHAR, 0, 0, fldoff(natstr, nat_dayno), "dayno"},
     {NSC_CHAR, 0, 0, fldoff(natstr, nat_update), "update"},
     {NSC_UCHAR, 0, 0, fldoff(natstr, nat_missed), "missed"},
-#endif /* MAYBE_LATER */
     {NSC_USHORT, 0, 0, fldoff(natstr, nat_tgms), "tgms"},
     {NSC_USHORT, 0, 0, fldoff(natstr, nat_ann), "ann"},
     {NSC_USHORT, 0, 0, fldoff(natstr, nat_minused), "minused"},
     {NSC_SHORT, 0, 0, fldoff(natstr, nat_btu), "btu"},
-    {NSC_LONG, 0, 0, fldoff(natstr, nat_reserve), "reserve"},
+    {NSC_LONG, 0, 0, fldoff(natstr, nat_reserve), "milreserve"},
     {NSC_LONG, 0, 0, fldoff(natstr, nat_money), "money"},
-#ifdef MAYBE_LATER
-    {NSC_TIME, 0, 0, fldoff(natstr, nat_last_login), "last_login"},
-    {NSC_TIME, 0, 0, fldoff(natstr, nat_last_logout), "last_logout"},
+    {NSC_TIME, 0, 0, fldoff(natstr, nat_last_login), "login"},
+    {NSC_TIME, 0, 0, fldoff(natstr, nat_last_logout), "logout"},
     {NSC_TIME, 0, 0, fldoff(natstr, nat_newstim), "newstim"},
-#endif /* MAYBE_LATER */
+    {NSC_TIME, 0, 0, fldoff(natstr, nat_annotim), "annotim"},
     {NSC_FLOAT, 0, 0, fldoff(natstr, nat_level[NAT_TLEV]), "tech"},
     {NSC_FLOAT, 0, 0, fldoff(natstr, nat_level[NAT_RLEV]), "research"},
     {NSC_FLOAT, 0, 0, fldoff(natstr, nat_level[NAT_ELEV]), "education"},
     {NSC_FLOAT, 0, 0, fldoff(natstr, nat_level[NAT_HLEV]), "happiness"},
-#if 0
-    {NSC_SHORT, 0, MAXNOC, fldoff(natstr, nat_relate[0]),"relate"},
-    {NSC_CHAR, 0, PRI_MAX+1, fldoff(natstr, nat_priorities[0]),"priorities"},
-    {NSC_LONG, 0, 0, fldoff(natstr, nat_flags),"flags",0},
-#endif
+    /* FIXME nat_b[], nat_relate[], nat_contact[], nat_rejects[], nat_priorities[] */
+    {NSC_LONG, 0, 0, fldoff(natstr, nat_flags),"flags"},
     {NSC_NOTYPE, 0, 0, 0, NULL}
 };
index 9c26bd4abacd37599cb825478c8cde0d0aaa5ef4..3f0ab6b066d87a74ca9fe858a65f2ce2cca637df 100644 (file)
@@ -49,10 +49,10 @@ struct fileinit fileinit[EF_MAX] = {
     {NULL, NULL, NULL, treaty_ca},
     {NULL, NULL, NULL, trade_ca},
     {NULL, NULL, NULL, NULL},          /* power */
-    {NULL, NULL, NULL, NULL},          /* nation */
+    {NULL, NULL, NULL, nat_ca},        /* nation */
     {NULL, NULL, NULL, loan_ca},
-    {NULL, NULL, NULL, NULL},          /* map */
-    {NULL, NULL, NULL, NULL},          /* map */
+    {NULL, NULL, NULL, NULL},          /* map, a.k.a. true bmap */
+    {NULL, NULL, NULL, NULL},          /* (working) bmap */
     {NULL, NULL, NULL, commodity_ca},
     {NULL, NULL, NULL, lost_ca}
 };
@@ -71,9 +71,7 @@ ef_init(void)
        ef->postread = fi->postread;
        ef->prewrite = fi->prewrite;
        ef->cadef = fi->cadef;
-       /* We have to set the size for the map and bmap files at
-          runtime. */
-       if (i == EF_MAP || i == EF_BMAP)
-           ef->size = (WORLD_X * WORLD_Y) / 2;
     }
+
+    empfile[EF_MAP].size = empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2;
 }