]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/fileinit.c
New server option -F to force start even when state looks bad
[empserver] / src / lib / subs / fileinit.c
index 48016e71f780a5dc0c9d4a402255caac5ed95fa9..b3c3129290e661dd7c6caf6206b975933b4fef21 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire 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
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  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
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2005
- *     Markus Armbruster, 2005-2008
+ *     Markus Armbruster, 2005-2011
  */
 
 #include <config.h>
 
 #include "file.h"
-#include "nat.h"
-#include "optlist.h"
+#include "nsc.h"
 #include "prototypes.h"
 #include "unit.h"
 
 struct fileinit {
     int ef_type;
-    void (*oninit)(void *);
     void (*postread)(int, void *);
     void (*prewrite)(int, void *, void *);
-    int (*onresize)(int);
+    void (*onresize)(int);
 };
 
 static struct fileinit fileinit[] = {
-    {EF_SECTOR, NULL, sct_postread, sct_prewrite, NULL},
-    {EF_SHIP, NULL, shp_postread, shp_prewrite, unit_onresize},
-    {EF_PLANE, pln_oninit, pln_postread, pln_prewrite, unit_onresize},
-    {EF_LAND, lnd_oninit, lnd_postread, lnd_prewrite, unit_onresize},
-    {EF_NUKE, nuk_oninit, nuk_postread, nuk_prewrite, unit_onresize}
+    {EF_SECTOR, sct_postread, sct_prewrite, NULL},
+    {EF_SHIP, shp_postread, shp_prewrite, unit_onresize},
+    {EF_PLANE, pln_postread, pln_prewrite, unit_onresize},
+    {EF_LAND, lnd_postread, lnd_prewrite, unit_onresize},
+    {EF_NUKE, nuk_postread, nuk_prewrite, unit_onresize}
 };
 
 static void ef_open_srv(void);
@@ -63,21 +60,25 @@ static void ef_close_srv(void);
  * Initialize empfile for full server operations.
  */
 void
-ef_init_srv(void)
+ef_init_srv(int force_bad_state)
 {
     unsigned i;
 
     for (i = 0; i < sizeof(fileinit) / sizeof(fileinit[0]); i++) {
-       empfile[fileinit[i].ef_type].oninit = fileinit[i].oninit;
        empfile[fileinit[i].ef_type].postread = fileinit[i].postread;
        empfile[fileinit[i].ef_type].prewrite = fileinit[i].prewrite;
        empfile[fileinit[i].ef_type].onresize = fileinit[i].onresize;
     }
 
     nsc_init();
+    if (ef_verify_config() < 0)
+       exit(EXIT_FAILURE);
     ef_open_srv();
-    if (ef_verify() < 0)
+    if (ef_verify_state(1) < 0 && !force_bad_state) {
+       fprintf(stderr, "You can try -F to force running anyway,"
+               " but that's risky; see the manual page\n");
        exit(EXIT_FAILURE);
+    }
     global_init();
     unit_cargo_init();
 }
@@ -93,25 +94,25 @@ ef_open_srv(void)
 {
     int failed = 0;
 
-    failed |= !ef_open(EF_NATION, EFF_MEM, MAXNOC);
-    failed |= !ef_open(EF_SECTOR, EFF_MEM, WORLD_SZ());
-    failed |= !ef_open(EF_SHIP, EFF_MEM, -1);
-    failed |= !ef_open(EF_PLANE, EFF_MEM, -1);
-    failed |= !ef_open(EF_LAND, EFF_MEM, -1);
-    failed |= !ef_open(EF_GAME, EFF_MEM, 1);
-    failed |= !ef_open(EF_NEWS, 0, -1);
-    failed |= !ef_open(EF_LOAN, 0, -1);
-    failed |= !ef_open(EF_TREATY, 0, -1);
-    failed |= !ef_open(EF_NUKE, EFF_MEM, -1);
-    failed |= !ef_open(EF_POWER, 0, -1);
-    failed |= !ef_open(EF_TRADE, 0, -1);
-    failed |= !ef_open(EF_MAP, EFF_MEM, MAXNOC);
-    failed |= !ef_open(EF_BMAP, EFF_MEM, MAXNOC);
-    failed |= !ef_open(EF_COMM, 0, -1);
-    failed |= !ef_open(EF_LOST, 0, -1);
-    failed |= !ef_open(EF_REALM, EFF_MEM, MAXNOC * MAXNOR);
+    failed |= !ef_open(EF_NATION, EFF_MEM);
+    failed |= !ef_open(EF_SECTOR, EFF_MEM);
+    failed |= !ef_open(EF_SHIP, EFF_MEM);
+    failed |= !ef_open(EF_PLANE, EFF_MEM);
+    failed |= !ef_open(EF_LAND, EFF_MEM);
+    failed |= !ef_open(EF_GAME, EFF_MEM);
+    failed |= !ef_open(EF_NEWS, 0);
+    failed |= !ef_open(EF_LOAN, 0);
+    failed |= !ef_open(EF_TREATY, 0);
+    failed |= !ef_open(EF_NUKE, EFF_MEM);
+    failed |= !ef_open(EF_POWER, 0);
+    failed |= !ef_open(EF_TRADE, 0);
+    failed |= !ef_open(EF_MAP, EFF_MEM);
+    failed |= !ef_open(EF_BMAP, EFF_MEM);
+    failed |= !ef_open(EF_COMM, 0);
+    failed |= !ef_open(EF_LOST, 0);
+    failed |= !ef_open(EF_REALM, EFF_MEM);
     if (!failed)
-       failed |= ef_open_view(EF_COUNTRY, EF_NATION);
+       failed |= ef_open_view(EF_COUNTRY);
     if (failed) {
        logerror("Missing files, giving up");
        exit(EXIT_FAILURE);