Avoid repeated hours and game down status notifications
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 8 Feb 2009 13:54:02 +0000 (14:54 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 8 Feb 2009 13:59:26 +0000 (14:59 +0100)
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
include/prototypes.h
src/lib/player/empdis.c
src/lib/player/player.c

index 51e974b70117d68b2a4d4dbfd954b410124c40ac..a95d1d7c8b50a0088f5e032696702b650eb400b9 100644 (file)
@@ -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
index b20997c13b35e5b026f8a751ad1de0f8e98ad90a..8a580c54fb39f7dbc041885f216c7f58d6dbee85 100644 (file)
@@ -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 */
index eabb5be68c99e4064533829fea100d6119acfdc7..b2bdff77c949c893db19e44f60ed727c56a1576b 100644 (file)
@@ -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)
index 4666d179ed7465ad20cc960623c775cb66471ac3..1b56b142d35061f0a411b3e254a456306eb89d26 100644 (file)
@@ -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;