Avoid repeated hours and game down status notifications

may_play_now() tells deities about hours restriction and game down
status.  It runs at login and before and after each command.  Getting
notified that often is annoying.

Avoid repetition by remembering notification in new player flags
PF_HOURS and PF_DOWN.  Add a notification when hours restriction has
been lifted.  Ensure the notification is printed before the prompt,
not before the command, by calling may_play_now() from command() only
for mortals.  Safe, because may_play_now() always returns true for
deities anyway.
This commit is contained in:
Markus Armbruster 2009-02-08 14:54:02 +01:00
parent b404216dbe
commit 9ff2c62309
4 changed files with 22 additions and 15 deletions

View file

@ -89,7 +89,9 @@ struct player {
/* player flags */ /* player flags */
enum { enum {
PF_UTF8 = bit(0) /* client wants UTF-8 */ PF_UTF8 = bit(0), /* client wants UTF-8 */
PF_DOWN = bit(1), /* told player game is down */
PF_HOURS = bit(2) /* told player hours restriction is on */
}; };
#endif #endif

View file

@ -369,8 +369,7 @@ extern void log_last_commands(void);
extern void update_timeused_login(time_t now); extern void update_timeused_login(time_t now);
extern void update_timeused(time_t now); extern void update_timeused(time_t now);
extern void enforce_minimum_session_time(void); extern void enforce_minimum_session_time(void);
extern int may_play_now(struct natstr *natp, time_t current_time, extern int may_play_now(struct natstr *, time_t);
int suppress_deity_message);
/* more under Commands */ /* more under Commands */
/* empmod.c */ /* empmod.c */
/* init_nats.c */ /* init_nats.c */

View file

@ -231,27 +231,33 @@ enforce_minimum_session_time(void)
} }
int int
may_play_now(struct natstr *natp, time_t now, may_play_now(struct natstr *natp, time_t now)
int suppress_deity_message)
{ {
if (CANT_HAPPEN(natp->nat_cnum != player->cnum)) if (CANT_HAPPEN(natp->nat_cnum != player->cnum))
return 0; return 0;
if (!gamehours(now)) { if (gamehours(now)) {
if (natp->nat_stat != STAT_GOD || !suppress_deity_message) if (player->flags & PF_HOURS) {
pr("Empire hours restriction in force\n"); pr("\nEmpire hours restriction lifted\n");
player->flags &= ~PF_HOURS;
}
} else {
if (!(player->flags & PF_HOURS)) {
pr("\nEmpire hours restriction in force\n");
player->flags |= PF_HOURS;
}
if (natp->nat_stat != STAT_GOD) if (natp->nat_stat != STAT_GOD)
return 0; return 0;
} }
if (game_play_disabled()) { if (game_play_disabled()) {
if (natp->nat_stat != STAT_GOD) { if (!(player->flags & PF_DOWN)) {
show_first_tel(downfil); show_first_tel(downfil);
pr("\nThe game is down\n"); pr("\nThe game is down\n");
return 0; player->flags |= PF_DOWN;
} }
if (!suppress_deity_message) if (natp->nat_stat != STAT_GOD)
pr("The game is down\n"); return 0;
} }
if ((natp->nat_stat != STAT_GOD && natp->nat_stat != STAT_VIS) if ((natp->nat_stat != STAT_GOD && natp->nat_stat != STAT_VIS)

View file

@ -70,7 +70,7 @@ player_main(struct player *p)
return; return;
} }
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
if (!may_play_now(natp, player->curup, 0)) if (!may_play_now(natp, player->curup))
return; return;
if (natp->nat_stat != STAT_VIS if (natp->nat_stat != STAT_VIS
&& natp->nat_last_login && natp->nat_last_login
@ -125,7 +125,7 @@ command(void)
now = time(NULL); now = time(NULL);
update_timeused(now); update_timeused(now);
if (!may_play_now(getnatp(player->cnum), now, 1)) if (!player->god && !may_play_now(getnatp(player->cnum), now))
return 0; return 0;
if (parse(player->combuf, scanspace, player->argp, player->comtail, if (parse(player->combuf, scanspace, player->argp, player->comtail,
@ -173,7 +173,7 @@ status(void)
time(&player->curup); time(&player->curup);
update_timeused(player->curup); update_timeused(player->curup);
if (!may_play_now(natp, player->curup, 0)) if (!may_play_now(natp, player->curup))
return 0; return 0;
if (player->btused) { if (player->btused) {
natp->nat_btu -= player->btused; natp->nat_btu -= player->btused;