]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/empdis.c
Avoid repeated hours and game down status notifications
[empserver] / src / lib / player / empdis.c
index e8df9a38b13d28462815fba450e0c06cc329a688..b2bdff77c949c893db19e44f60ed727c56a1576b 100644 (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"
@@ -47,7 +48,6 @@
 #include "player.h"
 #include "proto.h"
 #include "prototypes.h"
-#include "tel.h"
 
 
 #define KEEP_COMMANDS 50
@@ -177,45 +177,6 @@ disable_coms(void)
     free(tmp);
 }
 
-/*
- * returns true if down
- */
-static int
-gamedown(int suppress_deity_message)
-{
-    FILE *down_fp;
-    struct telstr tgm;
-    char buf[MAXTELSIZE + 1];  /* UTF-8 */
-
-    if ((down_fp = fopen(downfil, "rb")) == NULL)
-       return 0;
-    if (fread(&tgm, sizeof(tgm), 1, down_fp) != 1) {
-       logerror("bad header on login message (downfil)");
-       fclose(down_fp);
-       return 1;
-    }
-    if (tgm.tel_length >= (long)sizeof(buf)) {
-       logerror("text length (%ld) is too long for login message (downfil)", tgm.tel_length);
-       fclose(down_fp);
-       return 1;
-    }
-    if (fread(buf, tgm.tel_length, 1, down_fp) != 1) {
-       logerror("bad length %ld on login message", tgm.tel_length);
-       fclose(down_fp);
-       return 1;
-    }
-    buf[tgm.tel_length] = 0;
-    fclose(down_fp);
-    if (player->god) {
-       if (!suppress_deity_message)
-           pr("The game is down\n");
-       return 0;
-    }
-    uprnf(buf);
-    pr("\nThe game is down\n");
-    return 1;
-}
-
 static int
 seconds_since_midnight(time_t time)
 {
@@ -270,20 +231,34 @@ 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)
 {
-    update_timeused(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 (gamedown(suppress_deity_message))
-       return 0;
+    if (game_play_disabled()) {
+       if (!(player->flags & PF_DOWN)) {
+           show_first_tel(downfil);
+           pr("\nThe game is down\n");
+           player->flags |= PF_DOWN;
+       }
+       if (natp->nat_stat != STAT_GOD)
+           return 0;
+    }
 
     if ((natp->nat_stat != STAT_GOD && natp->nat_stat != STAT_VIS)
        && natp->nat_timeused > m_m_p_d * 60) {