/*
* 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
#include "com.h"
#include "empio.h"
#include "file.h"
+#include "game.h"
#include "match.h"
#include "misc.h"
#include "nat.h"
#include "player.h"
#include "proto.h"
#include "prototypes.h"
-#include "tel.h"
#define KEEP_COMMANDS 50
/*
* 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;
}
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;
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;
+}