]> 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 4b1eacbe2958708c9fb66c081fa11f60c15f7050..b2bdff77c949c893db19e44f60ed727c56a1576b 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
@@ -177,62 +177,23 @@ disable_coms(void)
     free(tmp);
 }
 
-/*
- * returns true if down
- */
-int
-gamedown(void)
-{
-    FILE *down_fp;
-    struct telstr tgm;
-    char buf[MAXTELSIZE + 1];  /* UTF-8 */
-
-    if (player->god)
-       return 0;
-    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;
-    uprnf(buf);
-    pr("\nThe game is down\n");
-    fclose(down_fp);
-    return 1;
-}
-
 static int
 seconds_since_midnight(time_t time)
 {
     struct tm *tm = localtime(&time);
-    time_t midnight;
 
     tm->tm_hour = 0;
     tm->tm_min = 0;
     tm->tm_sec = 0;
     tm->tm_isdst = -1;
-    midnight = mktime(tm);
-
-    return(time - midnight);
+    return time - mktime(tm);
 }
 
 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;
@@ -268,3 +229,41 @@ enforce_minimum_session_time(void)
        natp->nat_timeused += 15 - dt;
     putnat(natp);
 }
+
+int
+may_play_now(struct natstr *natp, time_t now)
+{
+    if (CANT_HAPPEN(natp->nat_cnum != player->cnum))
+       return 0;
+
+    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 (!(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) {
+       pr("Max minutes per day limit exceeded.\n");
+       return 0;
+    }
+    return 1;
+}