/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
*
* Known contributors to this file:
* Steve McClure, 2000
- * Markus Armbruster, 2004-2008
- * Ron Koenderink, 2004-2007
+ * Markus Armbruster, 2004-2011
+ * Ron Koenderink, 2004-2009
*/
#include <config.h>
-#include <errno.h>
-#include <stdio.h>
#include "com.h"
#include "empio.h"
#include "empthread.h"
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_stat == STAT_SANCT)
- && natp->nat_timeused > m_m_p_d * 60) {
- pr("Max minutes per day limit exceeded.\n");
+ if (!may_play_now(natp, player->curup))
return;
- }
if (natp->nat_stat != STAT_VIS
&& natp->nat_last_login
&& (strcmp(natp->nat_hostaddr, player->hostaddr)
static int
command(void)
{
+ struct natstr *natp = getnatp(player->cnum);
char *redir; /* UTF-8 */
- char scanspace[1024];
time_t now;
- struct natstr *natp;
+ prprompt(natp->nat_timeused / 60, natp->nat_btu);
if (getcommand(player->combuf) < 0)
- return 0;
+ return player->aborted;
now = time(NULL);
update_timeused(now);
- natp = getnatp(player->cnum);
- if (!gamehours(player->curup))
- if (natp->nat_stat != STAT_GOD) {
- pr("Empire hours restriction in force\n");
- return 0;
- }
- if ((natp->nat_stat == STAT_ACTIVE || natp->nat_stat == STAT_SANCT)
- && natp->nat_timeused > m_m_p_d * 60) {
- pr("Max minutes per day limit exceeded.\n");
+ if (!player->god && !may_play_now(natp, now))
return 0;
- }
- if (parse(player->combuf, scanspace, player->argp, player->comtail,
- &player->condarg, &redir) < 0) {
+ if (parse(player->combuf, player->argbuf, player->argp,
+ player->comtail, &player->condarg, &redir) < 0) {
pr("See \"info Syntax\"?\n");
} else {
if (dispatch(player->combuf, redir) < 0)
int old_nstat;
char buf[128];
- if (player->eof || player->state == PS_SHUTDOWN)
- return 0;
natp = getnatp(player->cnum);
if (player->dolcost > 100.0)
pr("That just cost you $%.2f\n", player->dolcost);
time(&player->curup);
update_timeused(player->curup);
- if (!gamehours(player->curup)) {
- pr("Empire hours restriction in force\n");
- if (natp->nat_stat != STAT_GOD)
- return 0;
- }
- if ((natp->nat_stat == STAT_ACTIVE || natp->nat_stat == STAT_SANCT)
- && natp->nat_timeused > m_m_p_d * 60) {
- pr("Max minutes per day limit exceeded.\n");
+ if (player->eof || player->state == PS_SHUTDOWN
+ || !may_play_now(natp, player->curup))
return 0;
- }
+
if (player->btused) {
natp->nat_btu -= player->btused;
player->btused = 0;
if (natp->nat_stat == STAT_ACTIVE && (player->nstat & CAP) == 0)
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;
}
+/*
+ * Make all objects stale if ARG is one of the player's command arguments.
+ * See ef_make_stale() for what "making stale" means.
+ * Useful for functions that prompt for missing arguments.
+ * These can yield the processor, so we'd like to call ef_make_stale()
+ * there. Except that leads to false positives when the caller passes
+ * an argument that is never null, and relies on the fact that the
+ * function doesn't yield then. We can't know that in general. But
+ * we do know in the common special case of command arguments.
+ */
+void
+make_stale_if_command_arg(char *arg)
+{
+ if (player->argbuf <= arg
+ && arg <= player->argbuf + sizeof(player->argbuf))
+ ef_make_stale();
+}
+
/*
* XXX This whole mess should be redone; execute block should
* start with "exec start", and should end with "exec end".
int
execute(void)
{
- char buf[1024];
+ char buf[1024]; /* UTF-8 */
int failed;
- char *p;
+ char *p; /* UTF-8 */
char *redir; /* UTF-8 */
- char scanspace[1024];
failed = 0;
- if (player->comtail[1])
- p = player->comtail[1];
- else
- p = getstring("File? ", buf);
+ p = player->comtail[1];
+ if (!p)
+ p = ugetstring("File? ", buf);
if (p == NULL || *p == '\0')
return RET_SYN;
prexec(p);
while (!failed && status()) {
player->nstat &= ~EXEC;
- if (recvclient(buf, sizeof(buf)) < 0)
+ if (getcommand(player->combuf) < 0)
break;
- if (parse(buf, scanspace, player->argp, player->comtail,
- &player->condarg, &redir) < 0) {
+ if (parse(player->combuf, player->argbuf, player->argp,
+ player->comtail, &player->condarg, &redir) < 0) {
failed = 1;
continue;
}
- pr("\nExecute : %s\n", buf);
+ pr("\nExecute : ");
+ uprnf(buf);
+ pr("\n");
if (redir) {
pr("Execute : redirection not supported\n");
failed = 1;
int
show_motd(void)
{
- FILE *motd_fp;
- struct telstr tgm;
- char buf[MAXTELSIZE + 1]; /* UTF-8 */
-
- if ((motd_fp = fopen(motdfil, "rb")) == NULL) {
- if (errno == ENOENT)
- return RET_OK;
- else {
- pr ("Could not open motd.\n");
- logerror("Could not open motd (%s).\n", motdfil);
- return RET_FAIL;
- }
- }
- 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);
+ show_first_tel(motdfil);
return RET_OK;
}