]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/empdis.c
Don't log out deity when gamedown() can't read downfil
[empserver] / src / lib / player / empdis.c
index 14b32b96d4e7109f396e088dcc9aedf763c6ceb1..685fc7a5ada6f10e1823a73bf8b72cf796419370 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -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
@@ -180,36 +180,18 @@ disable_coms(void)
 /*
  * returns true if down
  */
-int
-gamedown(void)
+static int
+gamedown(int suppress_deity_message)
 {
-    FILE *down_fp;
-    struct telstr tgm;
-    char buf[MAXTELSIZE + 1];  /* UTF-8 */
-
-    if (player->god)
+    if (!game_play_disabled())
        return 0;
-    if ((down_fp = fopen(downfil, "rb")) == NULL)
+    if (player->god) {
+       if (!suppress_deity_message)
+           pr("The game is down\n");
        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;
-    uprnf(buf);
+    show_first_tel(downfil);
     pr("\nThe game is down\n");
-    fclose(down_fp);
     return 1;
 }
 
@@ -229,7 +211,7 @@ void
 update_timeused_login(time_t now)
 {
     struct natstr *natp = getnatp(player->cnum);
-    time_t midnight_secs = seconds_since_midnight(player->lasttime);
+    time_t midnight_secs = seconds_since_midnight(now);
 
     if (now - natp->nat_last_logout > midnight_secs) {
        natp->nat_timeused = 0;
@@ -265,3 +247,28 @@ enforce_minimum_session_time(void)
        natp->nat_timeused += 15 - dt;
     putnat(natp);
 }
+
+int
+may_play_now(struct natstr *natp, time_t now,
+            int suppress_deity_message)
+{
+    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 (natp->nat_stat != STAT_GOD)
+           return 0;
+    }
+
+    if (gamedown(suppress_deity_message))
+       return 0;
+
+    if ((natp->nat_stat != STAT_GOD && natp->nat_stat != STAT_VIS)
+       && natp->nat_timeused > m_m_p_d * 60) {
+       pr("Max minutes per day limit exceeded.\n");
+       return 0;
+    }
+    return 1;
+}