Store game down flag in the game table

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.
This commit is contained in:
Markus Armbruster 2009-02-07 18:24:03 +01:00
parent f1d89514a5
commit fe9f02ccfb
5 changed files with 36 additions and 2 deletions

View 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);

View 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;
}

View 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.

View 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},

View 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);