]> git.pond.sub.org Git - empserver/commitdiff
Store game down flag in the game table
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 7 Feb 2009 17:24:03 +0000 (18:24 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 8 Feb 2009 13:18:04 +0000 (14:18 +0100)
This avoids the silly opening of downfil all the time.

For what it's worth, it also makes the information visible in xdump,
as new game selector down.

include/game.h
src/lib/commands/turn.c
src/lib/common/game.c
src/lib/common/nsc.c
src/lib/player/empdis.c

index f441ccd771385461857058c84d47ba48024095a6..5d6bec91a006849426dd562405fec7e320d5fe84 100644 (file)
@@ -44,6 +44,7 @@ struct gamestr {
     time_t game_timestamp;
     /* end of part matching struct empobj */
     char game_upd_disable;     /* updates disabled? */
+    char game_down;            /* playing disabled? */
     /*
      * The Empire clock.
      * Access it through game_tick_tick(), or else it'll be late.
@@ -58,6 +59,8 @@ struct gamestr {
 
 extern void game_ctrl_update(int);
 extern int updates_disabled(void);
+extern void game_ctrl_play(int);
+extern int game_play_disabled(void);
 extern void game_note_bsanct(void);
 extern void game_record_update(time_t);
 extern struct gamestr *game_tick_tick(void);
index 8f78626b0a7dee9f4a0426fe54c326e89dbf34e0..64a32298fc8215f0b9494145e859ed638048bdb3 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <errno.h>
 #include <unistd.h>
+#include "game.h"
 #include "tel.h"
 #include "commands.h"
 #include "optlist.h"
@@ -64,6 +65,7 @@ turn(void)
            logerror("Could not remove no-login file (%s).\n", downfil);
            return RET_FAIL;
        }
+       game_ctrl_play(1);
        return RET_OK;
     } else {
        msgfilepath = motdfil;
@@ -122,5 +124,6 @@ turn(void)
 
     pr("\n");
 
+    game_ctrl_play(0);
     return RET_OK;
 }
index 29624624ebbb45e4ea41e937527e0332eda3d63c..74634a2c03484cae30a774b3840aaa87aec0bac7 100644 (file)
@@ -51,7 +51,7 @@
 #include "server.h"
 
 /*
- * Disable updates
+ * Enable / disable updates
  */
 void
 game_ctrl_update(int enable)
@@ -71,6 +71,27 @@ updates_disabled(void)
     return getgamep()->game_upd_disable;
 }
 
+/*
+ * Enable / disable play
+ */
+void
+game_ctrl_play(int enable)
+{
+    struct gamestr *game = getgamep();
+
+    game->game_down = !enable;
+    putgame();
+}
+
+/*
+ * Is playing enabled?
+ */
+int
+game_play_disabled(void)
+{
+    return getgamep()->game_down;
+}
+
 /*
  * Notice that a player broke sanctuary.
  * This starts the Empire clock if it hasn't been started yet.
index b14e6284fc2808df986d4aceac3f2045d780d961..8a3dadb8c1780f7df8a9ae88b5060f4b812d47e8 100644 (file)
@@ -619,6 +619,7 @@ struct castr game_ca[] = {
      EF_BAD, NSC_EXTRA},
     {"upd_disable", fldoff(game_upd_disable), NSC_CHAR, 0, NULL,
      EF_BAD, 0},
+    {"down", fldoff(game_down), NSC_CHAR, 0, NULL, EF_BAD, 0},
     {"turn", fldoff(game_turn), NSC_SHORT, 0, NULL, EF_BAD, 0},
     {"tick", fldoff(game_tick), NSC_SHORT, 0, NULL, EF_BAD, NSC_DEITY},
     {"rt", fldoff(game_rt), NSC_TIME, 0, NULL, EF_BAD, NSC_DEITY},
index 0ae85156751bdf50f77899b13a8bab2005746c61..adf589dc64a4614c01a564a143ebddeb6b0d1b3a 100644 (file)
@@ -40,6 +40,7 @@
 #include "com.h"
 #include "empio.h"
 #include "file.h"
+#include "game.h"
 #include "match.h"
 #include "misc.h"
 #include "nat.h"
@@ -187,8 +188,13 @@ gamedown(int suppress_deity_message)
     struct telstr tgm;
     char buf[MAXTELSIZE + 1];  /* UTF-8 */
 
-    if ((down_fp = fopen(downfil, "rb")) == NULL)
+    if (!game_play_disabled())
        return 0;
+
+    if ((down_fp = fopen(downfil, "rb")) == NULL) {
+       logerror("Could not open downfil.\n");
+       return 1;
+    }
     if (fread(&tgm, sizeof(tgm), 1, down_fp) != 1) {
        logerror("bad header on login message (downfil)");
        fclose(down_fp);