From 286dda725ee08fedebf6435da8d9c83d433475b2 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 27 Jul 2007 05:58:40 +0000 Subject: [PATCH] Store update disable flag in the game table to make it visible in xdump: (gamestr): New member game_upd_disable. (game_ca): Update accordingly. (game_ctrl_update): New. (disa, enab): Use it. (updates_disabled): Rewrite and move to game.c (disablefil): Remove. --- include/game.h | 3 +++ include/optlist.h | 1 - include/prototypes.h | 1 - src/lib/commands/disa.c | 16 ++-------------- src/lib/commands/enab.c | 9 ++------- src/lib/common/game.c | 21 +++++++++++++++++++++ src/lib/common/wantupd.c | 11 ----------- src/lib/global/nsc.c | 3 +++ 8 files changed, 31 insertions(+), 34 deletions(-) diff --git a/include/game.h b/include/game.h index 1a5f1f36..4f78585b 100644 --- a/include/game.h +++ b/include/game.h @@ -40,6 +40,7 @@ struct gamestr { /* initial part must match struct empobj */ short ef_type; /* end of part matching struct empobj */ + char game_upd_disable; /* updates disabled? */ /* * The Empire clock. * Access it through game_tick_tick(), or else it'll be late. @@ -52,6 +53,8 @@ struct gamestr { #define putgame() ef_write(EF_GAME, 0, ef_ptr(EF_GAME, 0)) #define getgamep() ((struct gamestr *)ef_ptr(EF_GAME, 0)) +extern void game_ctrl_update(int); +extern int updates_disabled(void); extern void game_record_update(time_t); extern struct gamestr *game_tick_tick(void); extern int game_tick_to_now(short *); diff --git a/include/optlist.h b/include/optlist.h index dcf00314..0b8c396e 100644 --- a/include/optlist.h +++ b/include/optlist.h @@ -49,7 +49,6 @@ extern char *schedulefil; extern char motdfil[]; extern char downfil[]; -extern char disablefil[]; extern char annfil[]; extern char teldir[]; extern char telfil[]; diff --git a/include/prototypes.h b/include/prototypes.h index 4a381ba0..44aa7843 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -346,7 +346,6 @@ extern int sct_typematch(char *); extern int demand_update_want(int *, int *, int); extern int demand_check(void); extern int demandupdatecheck(void); -extern int updates_disabled(void); /* xundump.c */ extern int xundump(FILE *, char *, int); diff --git a/src/lib/commands/disa.c b/src/lib/commands/disa.c index ca2534d5..66316000 100644 --- a/src/lib/commands/disa.c +++ b/src/lib/commands/disa.c @@ -33,25 +33,13 @@ #include -#if defined(_WIN32) -#include -#endif -#include -#include -#if !defined(_WIN32) -#include -#endif #include "commands.h" -#include "optlist.h" +#include "game.h" int disa(void) { - int fd; - - if ((fd = open(disablefil, O_RDWR | O_CREAT | O_TRUNC, S_IRWUG)) < 0) - return RET_FAIL; - close(fd); + game_ctrl_update(0); pr("Updates are disabled\n"); return RET_OK; } diff --git a/src/lib/commands/enab.c b/src/lib/commands/enab.c index 2579fd9d..9dd59f8a 100644 --- a/src/lib/commands/enab.c +++ b/src/lib/commands/enab.c @@ -33,18 +33,13 @@ #include -#if !defined(_WIN32) -#include -#elif defined(__GNUC__) -#include -#endif #include "commands.h" -#include "optlist.h" +#include "game.h" int enab(void) { - (void)unlink(disablefil); + game_ctrl_update(1); pr("Updates are enabled\n"); return RET_OK; } diff --git a/src/lib/common/game.c b/src/lib/common/game.c index 25dcea03..121b56c2 100644 --- a/src/lib/common/game.c +++ b/src/lib/common/game.c @@ -50,6 +50,27 @@ #include "prototypes.h" #include "server.h" +/* + * Disable updates + */ +void +game_ctrl_update(int enable) +{ + struct gamestr *game = getgamep(); + + game->game_upd_disable = !enable; + putgame(); +} + +/* + * Are updates disabled? + */ +int +updates_disabled(void) +{ + return getgamep()->game_upd_disable; +} + /* * Record an update in the game file, the current time is NOW. */ diff --git a/src/lib/common/wantupd.c b/src/lib/common/wantupd.c index f58fedec..30b0e634 100644 --- a/src/lib/common/wantupd.c +++ b/src/lib/common/wantupd.c @@ -116,14 +116,3 @@ demandupdatecheck(void) && demand_update_time(&now) && demand_check(); } - -int -updates_disabled(void) -{ - int fd; - - if ((fd = open(disablefil, O_RDONLY, 0)) < 0) - return 0; - close(fd); - return 1; -} diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index 8a58a4cd..eb68eae9 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -546,6 +546,9 @@ struct castr realm_ca[] = { }; struct castr game_ca[] = { + /* no need for uid */ + {NSC_CHAR, 0, 0, offsetof(struct gamestr, game_upd_disable), + "upd_disable", EF_BAD}, {NSC_SHORT, 0, 0, offsetof(struct gamestr, game_turn), "turn", EF_BAD}, {NSC_SHORT, NSC_DEITY, 0, offsetof(struct gamestr, game_tick), "tick", EF_BAD},