]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/nsc.c
New macro ARRAY_SIZE()
[empserver] / src / lib / common / nsc.c
index 3d2f5fd7f57d14940d89015889ee5aa6f9637cbe..d66493e64518f82ff000a0f2a3241341b9072a3e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -27,7 +27,7 @@
  *  nsc.c: Empire selection global structures
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2004-2016
+ *     Markus Armbruster, 2004-2020
  */
 
 /*
@@ -37,6 +37,7 @@
 
 #include <config.h>
 
+#include <limits.h>
 #include <stdlib.h>
 #include "empobj.h"
 #include "optlist.h"
 #include "nsc.h"
 #include "product.h"
 #include "unit.h"
+#include "version.h"
 
 static void *nsc_ver(struct valstr *, struct natstr *, void *);
 static void *nsc_ver_maxnoc(struct valstr *, struct natstr *, void *);
+static void *nsc_ver_version(struct valstr *, struct natstr *, void *);
 static void *nsc_sct_terr(struct valstr *, struct natstr *, void *);
 static void *nsc_sct_track(struct valstr *, struct natstr *, void *);
 static void *nsc_cargo_nplane(struct valstr *, struct natstr *, void *);
@@ -496,7 +499,7 @@ struct castr news_ca[] = {
     {"action", fldoff(nws_vrb), NSC_UCHAR, 0, NULL, EF_NEWS_CHR, 0,
      CA_DUMP},
     {"victim", fldoff(nws_vno), NSC_NATID, 0, NULL, EF_NATION, 0, CA_DUMP},
-    {"times", fldoff(nws_ntm), NSC_CHAR, 0, NULL, EF_BAD, 0, CA_DUMP},
+    {"times", fldoff(nws_ntm), NSC_USHORT, 0, NULL, EF_BAD, 0, CA_DUMP},
     {"duration", fldoff(nws_duration), NSC_SHORT, 0, NULL, EF_BAD, 0,
      CA_DUMP},
     {"time", fldoff(nws_when), NSC_TIME, 0, NULL, EF_BAD, 0, CA_DUMP},
@@ -599,7 +602,6 @@ struct castr cou_ca[] = {
      EF_BAD, NSC_DEITY, CA_DUMP_NONE},
     {"ip", fldoff(nat_hostaddr), NSC_STRINGY, 46, NULL, EF_BAD, 0,
      CA_DUMP},
-    {"hostname", 0, NSC_STRINGY, 0, NULL, EF_BAD, 0, CA_DUMP}, /* deprecated */
     {"userid", fldoff(nat_userid), NSC_STRINGY, 32, NULL, EF_BAD, 0,
      CA_DUMP},
     {"xcap", fldoff(nat_xcap), NSC_XCOORD, 0, NULL, EF_BAD, 0, CA_DUMP},
@@ -634,20 +636,47 @@ struct castr cou_ca[] = {
      EF_BAD, 0, CA_DUMP},
     {"happiness", fldoff(nat_level[NAT_HLEV]), NSC_FLOAT, 0, NULL,
      EF_BAD, 0, CA_DUMP},
-    {"relations", fldoff(nat_relate), NSC_UCHAR, MAXNOC, NULL,
-     EF_NATION_RELATIONS, NSC_HIDDEN, CA_DUMP_NONE},
-    /* mortals know there's contact (relations show), but not how strong */
-    {"contacts", fldoff(nat_contact), NSC_UCHAR, MAXNOC, NULL,
-     EF_BAD, NSC_DEITY, CA_DUMP_NONE},
-    {"rejects", fldoff(nat_rejects), NSC_UCHAR, MAXNOC, NULL,
-     EF_NATION_REJECTS, NSC_BITS, CA_DUMP_NONE},
     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP}
 #undef CURSTR
 };
 
-struct castr nat_ca[sizeof(cou_ca) / sizeof(*cou_ca)];
+struct castr nat_ca[ARRAY_SIZE(cou_ca)];
 /* initialized by nsc_init() */
 
+struct castr relat_ca[] = {
+#define CURSTR struct relatstr
+    {"uid", fldoff(rel_uid), NSC_INT, 0, NULL, EF_RELAT, 0, CA_DUMP},
+    {"timestamp", fldoff(rel_timestamp), NSC_TIME, 0, NULL,
+     EF_BAD, 0, CA_DUMP_NONE},
+    {"relations", fldoff(rel_relate), NSC_UCHAR, MAXNOC, NULL,
+     EF_NATION_RELATIONS, NSC_HIDDEN, CA_DUMP},
+    {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP}
+#undef CURSTR
+};
+
+struct castr contact_ca[] = {
+#define CURSTR struct contactstr
+    {"uid", fldoff(con_uid), NSC_INT, 0, NULL, EF_CONTACT, 0, CA_DUMP},
+    {"timestamp", fldoff(con_timestamp), NSC_TIME, 0, NULL,
+     EF_BAD, 0, CA_DUMP_NONE},
+    /* mortals know there's contact (relations show), but not how strong */
+    {"contacts", fldoff(con_contact), NSC_UCHAR, MAXNOC, NULL,
+     EF_BAD, NSC_DEITY, CA_DUMP},
+    {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP}
+#undef CURSTR
+};
+
+struct castr reject_ca[] = {
+#define CURSTR struct rejectstr
+    {"uid", fldoff(rej_uid), NSC_INT, 0, NULL, EF_REJECT, 0, CA_DUMP},
+    {"timestamp", fldoff(rej_timestamp), NSC_TIME, 0, NULL,
+     EF_BAD, 0, CA_DUMP_NONE},
+    {"rejects", fldoff(rej_rejects), NSC_UCHAR, MAXNOC, NULL,
+     EF_NATION_REJECTS, NSC_BITS, CA_DUMP},
+    {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP}
+#undef CURSTR
+};
+
 struct castr realm_ca[] = {
 #define CURSTR struct realmstr
     /* uid is encoded in cnum, realm */
@@ -686,10 +715,9 @@ struct castr intrchr_ca[] = {
     /* no need for uid as long as it's not referenced from other tables */
     {"name", fldoff(in_name), NSC_STRING, 0, NULL, EF_BAD, 0,
      CA_DUMP_CONST},
-    {"lcms", fldoff(in_lcms), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP},
-    {"hcms", fldoff(in_hcms), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP},
-    {"dcost", fldoff(in_dcost), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP},
-    {"mcost", fldoff(in_mcost), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP},
+    NSC_MVEC(fldoff(in_mat), CA_DUMP_ONLY, CA_DUMP_ONLY, CA_DUMP_ONLY),
+    {"bmobil", fldoff(in_bmobil), NSC_SHORT, 0, NULL, EF_BAD, 0, CA_DUMP},
+    {"cost", fldoff(in_cost), NSC_INT, 0, NULL, EF_BAD, 0, CA_DUMP},
     {"enable", fldoff(in_enable), NSC_UCHAR, 0, NULL, EF_BAD, 0, CA_DUMP},
     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0, CA_DUMP}
 #undef CURSTR
@@ -724,7 +752,7 @@ struct castr empfile_ca[] = {
 struct castr symbol_ca[] = {
 #define CURSTR struct symbol
     /*
-     * value is is const because it has to match what is compiled into
+     * value is const because it has to match what is compiled into
      * the server.  name is const because clients key on it.
      */
     {"value", fldoff(value), NSC_INT, 0, NULL, EF_BAD, 0, CA_DUMP_CONST},
@@ -755,8 +783,7 @@ void
 nsc_init(void)
 {
     static struct castr version_ca0 = {
-       "version", 0, NSC_STRINGY, sizeof(PACKAGE_STRING), NULL, EF_BAD, 0,
-           CA_DUMP
+       "version", 0, NSC_STRING, 0, nsc_ver_version, EF_BAD, 0, CA_DUMP
     };
     static struct castr version_ca1 = {
        "maxnoc", 0, NSC_LONG, 0, nsc_ver_maxnoc, EF_BAD, 0, CA_DUMP
@@ -820,6 +847,14 @@ nsc_ver_maxnoc(struct valstr *val, struct natstr *np, void *ptr)
     return NULL;
 }
 
+static void *
+nsc_ver_version(struct valstr *val, struct natstr *np, void *ptr)
+{
+    val->val_as.str.base = version;
+    val->val_as.str.maxsz = INT_MAX; /* really SIZE_MAX, but that's C99 */
+    return NULL;
+}
+
 static void *
 nsc_sct_terr(struct valstr *val, struct natstr *np, void *ptr)
 {