]> git.pond.sub.org Git - empserver/commitdiff
(ef_init_srv): Add a call ef_verify() to verify game data and game
authorRon Koenderink <rkoenderink@yahoo.ca>
Wed, 30 Nov 2005 19:17:58 +0000 (19:17 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Wed, 30 Nov 2005 19:17:58 +0000 (19:17 +0000)
configuration consistency.

(ef_verify): New.  Verifies game data and game
configuration consistency.

include/file.h
include/prototypes.h
src/lib/common/Makefile
src/lib/common/ef_verify.c [new file with mode: 0644]
src/lib/subs/fileinit.c

index 42c979dd3cc39a98674b57c795f6877365c64083..ff409e3bb503a53466044f23cf6117c50a876edc 100644 (file)
@@ -163,6 +163,7 @@ extern int ef_byname(char *);
 extern int ef_byname_from(char *, int *);
 extern void ef_init(void);
 extern int ef_load(void);
+extern int ef_verify(void);
 
 extern struct empfile empfile[EF_MAX + 1];
 
index 2d93d1af47a46574c30684e396f4b48746558e75..d6dcedc1784b199ff766e6815d889a4b2a0e5bd9 100644 (file)
@@ -285,6 +285,8 @@ extern int check_loan_ok(struct lonstr *);
 extern int check_trade_ok(struct trdstr *);
 /* ef_load.c */
 /* in file.h */
+/* ef_verify.c */
+/* in file.h */
 /* fsize.c */
 extern int fsize(int);
 extern int blksize(int);
index 912482ed16e80cf5c16dbd41288bc06270e196f9..c6802c2aa9d240b00c9803c602f99d2b008a4636 100644 (file)
@@ -35,16 +35,17 @@ include ../../make.defs
 LIB = $(SRCDIR)/lib/libcommon.a
 NTLIB = $(SRCDIR)\lib\libcommon.lib
 
-OBJS =  bestpath.o bridgefall.o check.o damage.o file.o fsize.o \
-       hap_fact.o hours.o land.o log.o mailbox.o maps.o move.o \
-       nat.o path.o res_pop.o sectdamage.o \
-       stmtch.o tfact.o type.o wantupd.o xy.o ef_load.o xundump.o
+OBJS =  bestpath.o bridgefall.o check.o damage.o ef_load.o ef_verify.o \
+       file.o fsize.o hap_fact.o hours.o land.o log.o mailbox.o \
+       maps.o move.o nat.o path.o res_pop.o sectdamage.o \
+       stmtch.o tfact.o type.o wantupd.o xundump.o xy.o
 
-NTOBJS = bestpath.obj bridgefall.obj check.obj damage.obj file.obj fsize.obj \
+NTOBJS = bestpath.obj bridgefall.obj check.obj damage.obj \
+       ef_load.obj ef_verify.obj file.obj fsize.obj \
        hap_fact.obj hours.obj land.obj log.obj \
        mailbox.obj maps.obj move.obj nat.obj path.obj res_pop.obj \
        sectdamage.obj stmtch.obj tfact.obj \
-       type.obj wantupd.obj xy.obj ef_load.obj xundump.obj
+       type.obj wantupd.obj xundump.obj xy.obj
 
 all: $(LIB)
 
diff --git a/src/lib/common/ef_verify.c b/src/lib/common/ef_verify.c
new file mode 100644 (file)
index 0000000..ab1e54d
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ *  Empire - A multi-player, client/server Internet based war game.
+ *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                           Ken Stevens, Steve McClure
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  ---
+ *
+ *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
+ *  related information and legal notices. It is expected that any future
+ *  projects/authors will amend these files as needed.
+ *
+ *  ---
+ *
+ *  ef_verify.c: Verify game configuration
+ * 
+ *  Known contributors to this file:
+ *     Ron Koenderink, 2005
+ *  
+ */
+
+#include <stdio.h>
+#include <time.h>
+
+#include "prototypes.h"
+#include "file.h"
+#include "nsc.h"
+
+static int
+verify_row(int type, int row)
+{
+    struct castr *ca = ef_cadef(type);
+    void *row_ref = malloc(empfile[type].size);
+    int i, j, k, n;
+    struct castr *ca_sym;
+    struct valstr val;
+    int ret_val = 0; 
+    int in_mem = (ef_flags(type) & EFF_MEM) != 0; 
+    if (!in_mem) { 
+       row_ref = malloc(empfile[type].size); 
+       ef_read(type, row, row_ref); 
+    } else 
+       row_ref = ef_ptr(type, row); 
+
+//    if (ef_flags(type) & EFF_OWNER) != 0
+    for (i = 0; ca[i].ca_name; ++i) {
+       if (ca[i].ca_flags & NSC_EXTRA)
+           continue;
+       n = ca[i].ca_type != NSC_STRINGY ? ca[i].ca_len : 0;
+       j = 0;
+       do {
+           if (ca[i].ca_table != EF_BAD && ca[i].ca_table != type) {
+               val.val_type = ca[i].ca_type;
+               val.val_cat = NSC_OFF;
+               val.val_as.sym.off = ca[i].ca_off;
+               val.val_as.sym.idx = j;
+               nstr_exec_val(&val, 0, row_ref, NSC_NOTYPE);
+               if (val.val_type != NSC_LONG && val.val_type != NSC_TYPEID)
+                   continue;
+
+               ca_sym = ef_cadef(ca[i].ca_table);
+               if (ca[i].ca_flags & NSC_BITS) {
+                   if (ca_sym != symbol_ca) {
+                       fprintf(stderr,
+                           "Unable to verify symbol set as the "
+                           "table %s is not created as symbol table "
+                           "for table %s row %d field %s\n",
+                           ef_nameof(ca[i].ca_table), ef_nameof(type),
+                           row + 1, ca[i].ca_name
+                           );
+                       continue;
+                   }
+                   for (k = 0; k < sizeof(long) * 8; k++) {
+                       if (val.val_as.lng & (1 << k))
+                           if (!symbol_by_value(1 << k, ef_ptr(ca[i].ca_table, 0))) {
+                               fprintf(stderr,
+                                   "bit %d not found in symbol table %s "
+                                   "when verify table %s row %d field %s\n",
+                                   k, ef_nameof(ca[i].ca_table),
+                                   ef_nameof(type), row + 1, ca[i].ca_name);
+                               ret_val = -1;
+                           }
+                   }
+               } else {
+                   if (ca_sym != symbol_ca) {
+                       if (val.val_as.lng >= ef_nelem(ca[i].ca_table) ||
+                           val.val_as.lng < -2) {
+                           fprintf(stderr, "Table index %d to table %s "
+                               "out of range, nelements %d for table %s "
+                               "row %d field %s\n",
+                               val.val_as.lng, ef_nameof(ca[i].ca_table),
+                               ef_nelem(ca[i].ca_table), ef_nameof(type), 
+                               row + 1, ca[i].ca_name);
+                           ret_val = -1;
+                       }
+                   } else {
+                       if (val.val_as.lng > -1) {
+                           if (!symbol_by_value(val.val_as.lng,
+                                      ef_ptr(ca[i].ca_table,0))) {
+                               fprintf(stderr, "value %d not found in "
+                                   "symbol table %s when verify table %s "
+                                   "row %d field %s\n",
+                                   val.val_as.lng,
+                                   ef_nameof(ca[i].ca_table),
+                                   ef_nameof(type), row + 1,
+                                   ca[i].ca_name);
+                               ret_val = -1;
+                           }
+                       }
+                   }
+               }
+           }
+       } while (++j < n);
+    } 
+    if (!in_mem)
+        free(row_ref);
+    return(ret_val);
+}
+
+int
+ef_verify()
+{
+    struct empfile *ep;
+    int retval = 0;
+    int i;
+
+    for (ep = empfile; ep->name; ep++) {
+       if (!ef_cadef(ep->uid))
+           continue;
+       for (i = 0; i < ef_nelem(ep->uid); i++) {
+           retval += verify_row(ep->uid, i);
+       }
+    }
+    return retval;
+}
index e34dfd75d9d344c84c5ab7dd5ffc2fda3609621b..7f1dc2b0a8feaf99373a81bbf2a4203a066cde1f 100644 (file)
@@ -96,6 +96,8 @@ ef_init_srv(void)
     }
     ef_init();
     ef_open_srv();
+    if (ef_verify() < 0)
+       exit(EXIT_FAILURE);
     global_init();
 }