From 9ff2c62309d4c33dbac30fe1d73b0ac3ee1c8768 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 8 Feb 2009 14:54:02 +0100 Subject: [PATCH] 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. --- include/player.h | 4 +++- include/prototypes.h | 3 +-- src/lib/player/empdis.c | 24 +++++++++++++++--------- src/lib/player/player.c | 6 +++--- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/player.h b/include/player.h index 51e974b70..a95d1d7c8 100644 --- a/include/player.h +++ b/include/player.h @@ -89,7 +89,9 @@ struct player { /* player flags */ 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 diff --git a/include/prototypes.h b/include/prototypes.h index b20997c13..8a580c54f 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -369,8 +369,7 @@ extern void log_last_commands(void); extern void update_timeused_login(time_t now); extern void update_timeused(time_t now); extern void enforce_minimum_session_time(void); -extern int may_play_now(struct natstr *natp, time_t current_time, - int suppress_deity_message); +extern int may_play_now(struct natstr *, time_t); /* more under Commands */ /* empmod.c */ /* init_nats.c */ diff --git a/src/lib/player/empdis.c b/src/lib/player/empdis.c index eabb5be68..b2bdff77c 100644 --- a/src/lib/player/empdis.c +++ b/src/lib/player/empdis.c @@ -231,27 +231,33 @@ enforce_minimum_session_time(void) } int -may_play_now(struct natstr *natp, time_t now, - int suppress_deity_message) +may_play_now(struct natstr *natp, time_t now) { if (CANT_HAPPEN(natp->nat_cnum != player->cnum)) return 0; - if (!gamehours(now)) { - if (natp->nat_stat != STAT_GOD || !suppress_deity_message) - pr("Empire hours restriction in force\n"); + if (gamehours(now)) { + if (player->flags & PF_HOURS) { + 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) return 0; } if (game_play_disabled()) { - if (natp->nat_stat != STAT_GOD) { + if (!(player->flags & PF_DOWN)) { show_first_tel(downfil); pr("\nThe game is down\n"); - return 0; + player->flags |= PF_DOWN; } - if (!suppress_deity_message) - pr("The game is down\n"); + if (natp->nat_stat != STAT_GOD) + return 0; } if ((natp->nat_stat != STAT_GOD && natp->nat_stat != STAT_VIS) diff --git a/src/lib/player/player.c b/src/lib/player/player.c index 4666d179e..1b56b142d 100644 --- a/src/lib/player/player.c +++ b/src/lib/player/player.c @@ -70,7 +70,7 @@ player_main(struct player *p) return; } natp = getnatp(player->cnum); - if (!may_play_now(natp, player->curup, 0)) + if (!may_play_now(natp, player->curup)) return; if (natp->nat_stat != STAT_VIS && natp->nat_last_login @@ -125,7 +125,7 @@ command(void) now = time(NULL); update_timeused(now); - if (!may_play_now(getnatp(player->cnum), now, 1)) + if (!player->god && !may_play_now(getnatp(player->cnum), now)) return 0; if (parse(player->combuf, scanspace, player->argp, player->comtail, @@ -173,7 +173,7 @@ status(void) time(&player->curup); update_timeused(player->curup); - if (!may_play_now(natp, player->curup, 0)) + if (!may_play_now(natp, player->curup)) return 0; if (player->btused) { natp->nat_btu -= player->btused; -- 2.43.0