/*
* 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
static int command(void);
static int status(void);
+static int print_sink(char *, size_t, void *);
struct player *player;
return;
}
natp = getnatp(player->cnum);
- if (!gamehours(player->curup)) {
- pr("Empire hours restriction in force\n");
- if (natp->nat_stat != STAT_GOD)
- return;
- }
- if (natp->nat_stat == STAT_ACTIVE &&
- natp->nat_timeused > m_m_p_d * 60) {
- pr("Time exceeded today\n");
+ if (!may_play_now(natp, player->curup, 0))
return;
- }
if (natp->nat_stat != STAT_VIS
&& natp->nat_last_login
&& (strcmp(natp->nat_hostaddr, player->hostaddr)
strcpy(natp->nat_userid, player->userid);
strcpy(natp->nat_hostname, player->hostname);
strcpy(natp->nat_hostaddr, player->hostaddr);
-
- time(&natp->nat_last_login);
+ natp->nat_last_login = player->curup;
putnat(natp);
journal_login();
if (natp->nat_flags & NF_INFORM && natp->nat_tgms > 0) {
natp->nat_tgms = 0;
}
- while (status()) {
- command();
+ while (status() && command()) {
player->aborted = player->eof;
empth_yield();
}
{
char *redir; /* UTF-8 */
char scanspace[1024];
+ time_t now;
if (getcommand(player->combuf) < 0)
return 0;
+
+ now = time(NULL);
+ update_timeused(now);
+ if (!may_play_now(getnatp(player->cnum), now, 1))
+ return 0;
+
if (parse(player->combuf, scanspace, player->argp, player->comtail,
&player->condarg, &redir) < 0) {
pr("See \"info Syntax\"?\n");
time(&player->curup);
update_timeused(player->curup);
- if (natp->nat_stat == STAT_ACTIVE &&
- natp->nat_timeused > m_m_p_d * 60) {
- pr("Max minutes per day limit exceeded.\n");
- player->nstat = (player->nstat & ~NORM) | VIS;
- }
+ if (!may_play_now(natp, player->curup, 0))
+ return 0;
if (player->btused) {
natp->nat_btu -= player->btused;
player->btused = 0;
natp->nat_ann = 0;
}
if (natp->nat_stat == STAT_ACTIVE && (player->nstat & CAP) == 0)
- pr("You lost your capital... better designate one\n");
+ pr("You lost your capital... better designate one (see info capital)\n");
putnat(natp);
- if (gamedown() && !player->god) {
- pr("gamedown\n");
- return 0;
- }
return 1;
}
int
show_motd(void)
{
- FILE *motd_fp;
+ show_first_tel(motdfil);
+ return RET_OK;
+}
+
+/*
+ * Print first telegram in file FNAME.
+ */
+int
+show_first_tel(char *fname)
+{
+ FILE *fp;
struct telstr tgm;
- char buf[MAXTELSIZE + 1]; /* UTF-8 */
- if ((motd_fp = fopen(motdfil, "rb")) == NULL) {
+ if ((fp = fopen(fname, "rb")) == NULL) {
if (errno == ENOENT)
- return RET_OK;
+ return 0;
else {
- pr ("Could not open motd.\n");
- logerror("Could not open motd (%s).\n", motdfil);
- return RET_FAIL;
+ logerror("Could not open %s.\n", fname);
+ return -1;
}
}
- if (fread(&tgm, sizeof(tgm), 1, motd_fp) != 1) {
- logerror("bad header on login message (motdfil)");
- fclose(motd_fp);
- return RET_FAIL;
- }
- if (tgm.tel_length >= (long)sizeof(buf)) {
- logerror("text length (%ld) is too long for login message (motdfil)", tgm.tel_length);
- fclose(motd_fp);
- return RET_FAIL;
- }
- if (fread(buf, tgm.tel_length, 1, motd_fp) != 1) {
- logerror("bad length %ld on login message", tgm.tel_length);
- fclose(motd_fp);
- return RET_FAIL;
- }
- buf[tgm.tel_length] = 0;
- uprnf(buf);
- fclose(motd_fp);
- return RET_OK;
+ if (tel_read_header(fp, fname, &tgm) < 0)
+ return -1;
+ if (tel_read_body(fp, fname, &tgm, print_sink, NULL) < 0)
+ return -1;
+ fclose(fp);
+ return 0;
+}
+
+static int
+print_sink(char *chunk, size_t sz, void *arg)
+{
+ uprnf(chunk);
+ return 0;
}
int