/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
*
* Known contributors to this file:
* Steve McClure, 2000
- * Markus Armbruster, 2004-2011
+ * Markus Armbruster, 2004-2012
* Ron Koenderink, 2004-2009
*/
#include <config.h>
-#include "com.h"
#include "empio.h"
#include "empthread.h"
#include "file.h"
-#include "journal.h"
#include "misc.h"
#include "nat.h"
#include "optlist.h"
#include "player.h"
-#include "proto.h"
#include "prototypes.h"
-#include "tel.h"
static int command(void);
struct natstr *natp;
char buf[128];
- p->state = PS_PLAYING;
player = p;
time(&player->curup);
update_timeused_login(player->curup);
strcpy(natp->nat_hostaddr, player->hostaddr);
natp->nat_last_login = player->curup;
putnat(natp);
- journal_login();
if (natp->nat_flags & NF_INFORM && natp->nat_tgms > 0) {
if (natp->nat_tgms == 1)
pr("You have a new telegram waiting ...\n");
}
while (status() && command()) {
- player->aborted = player->eof;
+ if (player->got_ctld)
+ io_set_eof(player->iop);
+ player->aborted = 0;
empth_yield();
}
/* #*# I put the following line in to prevent server crash -KHS */
update_timeused(natp->nat_last_logout);
enforce_minimum_session_time();
pr("Bye-bye\n");
- journal_logout();
}
static int
{
struct natstr *natp = getnatp(player->cnum);
char *redir; /* UTF-8 */
- char scanspace[1024];
time_t now;
prprompt(natp->nat_timeused / 60, natp->nat_btu);
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 (!may_play_now(natp, player->curup))
+ if (io_error(player->iop) || io_eof(player->iop)
+ || !may_play_now(natp, player->curup))
return 0;
+
if (player->btused) {
natp->nat_btu -= player->btused;
player->btused = 0;
return 1;
}
-/* Is ARG one of the player's last command's arguments? */
-static int
-is_command_arg(char *arg)
-{
- int i;
-
- for (i = 1; i < 128 && player->argp[i]; i++) {
- if (arg == player->argp[i])
- return 1;
- }
- return 0;
-}
-
/*
* Make all objects stale if ARG is one of the player's command arguments.
* See ef_make_stale() for what "making stale" means.
void
make_stale_if_command_arg(char *arg)
{
- if (is_command_arg(arg))
+ if (player->argbuf <= arg
+ && arg <= player->argbuf + sizeof(player->argbuf))
ef_make_stale();
}
int failed;
char *p; /* UTF-8 */
char *redir; /* UTF-8 */
- char scanspace[1024];
failed = 0;
return RET_SYN;
prexec(p);
- while (!failed && status()) {
+ while (!failed && status() && !player->got_ctld) {
player->nstat &= ~EXEC;
- if (getcommand(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 : ");
- uprnf(buf);
+ uprnf(player->combuf);
pr("\n");
if (redir) {
pr("Execute : redirection not supported\n");
failed = 1;
- } else if (dispatch(buf, NULL) < 0)
+ } else if (dispatch(player->combuf, NULL) < 0)
failed = 1;
+ /* player->aborted not reset; makes next getcommand() fail */
+ empth_yield();
}
if (failed) {
while (recvclient(buf, sizeof(buf)) >= 0) ;
}
pr("Execute : %s\n", failed ? "aborted" : "terminated");
- player->eof = 0;
+ player->got_ctld = 0;
return RET_OK;
}
int
quit(void)
{
- player->state = PS_SHUTDOWN;
+ io_set_eof(player->iop);
return RET_OK;
}