/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
*
*/
+#include <config.h>
+
#include "prototypes.h"
#include <string.h>
-#include "gamesdef.h"
#include "misc.h"
#include "player.h"
#include "proto.h"
#include <errno.h>
#include <fcntl.h>
+static int status(void);
+
struct player *player;
void
player = p;
time(&player->lasttime);
time(&player->curup);
- showvers(CLIENTPROTO);
show_motd();
if (init_nats() < 0)
return;
}
if (!gamehours(player->curup)) {
pr("Empire hours restriction in force\n");
- if ((natp->nat_stat & STAT_GOD) == 0)
+ if (natp->nat_stat != STAT_GOD)
return;
}
daychange(player->curup);
pr("Time exceeded today\n");
return;
}
- if ((*natp->nat_hostaddr &&
- *player->hostaddr &&
- strcmp(natp->nat_hostaddr, player->hostaddr)) ||
- (*natp->nat_userid &&
- *player->userid && strcmp(natp->nat_userid, player->userid))) {
- if (natp->nat_stat != VIS) {
- pr("Last connection from: %s", ctime(&natp->nat_last_login));
- pr(" to: %s", natp->nat_last_login <
- natp->nat_last_logout ? ctime(&natp->
- nat_last_logout) : "?");
- pr(" by: %s@%s\n",
- *natp->nat_userid ? natp->nat_userid : "nobody",
- *natp->nat_hostname ? natp->nat_hostname : *natp->
- nat_hostaddr ? natp->nat_hostaddr : "nowhere");
- }
+ if (natp->nat_stat != STAT_VIS
+ && natp->nat_last_login
+ && (strcmp(natp->nat_hostaddr, player->hostaddr)
+ || strcmp(natp->nat_userid, player->userid))) {
+ pr("Last connection from: %s", ctime(&natp->nat_last_login));
+ pr(" to: %s",
+ natp->nat_last_login <= natp->nat_last_logout
+ ? ctime(&natp->nat_last_logout) : "?");
+ pr(" by: %s@%s\n",
+ natp->nat_userid,
+ *natp->nat_hostname ? natp->nat_hostname : natp->nat_hostaddr);
}
- if (*player->userid)
- strcpy(natp->nat_userid, player->userid);
- else
- strcpy(natp->nat_userid, "nobody");
-
- if (*player->hostname)
- strcpy(natp->nat_hostname, player->hostname);
- else
- strcpy(natp->nat_hostname, "nowhere");
-
- if (*player->hostaddr)
- strcpy(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_connected = 1;
putnat(natp);
if (natp->nat_flags & NF_INFORM && natp->nat_tgms > 0) {
if (natp->nat_tgms == 1)
if (command() == 0 && !player->aborted)
break;
player->aborted = 0;
+ empth_yield();
}
/* #*# I put the following line in to prevent server crash -KHS */
natp = getnatp(player->cnum);
* charging at least 15 seconds.
*/
time(&natp->nat_last_logout);
- secs = max(natp->nat_last_logout - player->lasttime, 15);
+ secs = MAX(natp->nat_last_logout - player->lasttime, 15);
natp->nat_minused += secs / 60;
secs = secs % 60;
if (chance(secs / 60.0))
natp->nat_minused += 1;
- natp->nat_connected = 0;
putnat(natp);
pr("Bye-bye\n");
}
command(void)
{
unsigned int x;
- char *redir;
+ char *redir; /* UTF-8 */
char scanspace[1024];
if (getcommand(player->combuf) < 0)
return 1;
}
-int
+static int
status(void)
{
struct natstr *natp;
putnat(natp);
return 0;
}
- player->visitor = (natp->nat_stat & (STAT_NORM | STAT_GOD)) == 0;
+ player->visitor = natp->nat_stat < STAT_SANCT;
if (player->dolcost != 0.0) {
if (player->dolcost > 100.0)
pr("That just cost you $%.2f\n", player->dolcost);
}
}
getsect(natp->nat_xcap, natp->nat_ycap, §);
- if ((sect.sct_type == SCT_CAPIT || sect.sct_type == SCT_MOUNT ||
- sect.sct_type == SCT_SANCT) && sect.sct_own == player->cnum)
- player->nstat |= CAP;
- else
+ if (influx(natp))
player->nstat &= ~CAP;
- /* Ok, has the country owner reset his capital yet after it was sacked? */
- if (natp->nat_flags & NF_SACKED)
- player->nstat &= ~CAP; /* No capital yet */
+ else
+ player->nstat |= CAP;
player->ncomstat = player->nstat;
+ if (player->god)
+ player->ncomstat |= CAP | MONEY;
time(&player->curup);
minute = (player->curup - player->lasttime) / 60;
if (minute > 0) {
daychange(player->curup);
if (!gamehours(player->curup)) {
pr("Empire hours restriction in force\n");
- if ((natp->nat_stat & STAT_GOD) == 0) {
+ if (natp->nat_stat != STAT_GOD) {
putnat(natp);
return 0;
}
player->lasttime += minute * 60;
natp->nat_minused += minute;
}
- if ((player->nstat & NORM) && natp->nat_minused > m_m_p_d) {
+ if (natp->nat_stat == STAT_ACTIVE && natp->nat_minused > m_m_p_d) {
pr("Max minutes per day limit exceeded.\n");
player->ncomstat = VIS;
}
int
execute(void)
{
- char buf[512];
+ char buf[1024];
int failed;
char *p;
- char *redir;
+ char *redir; /* UTF-8 */
char scanspace[1024];
failed = 0;
- redir = 0;
+ redir = NULL;
p = getstarg(player->argp[1], "File? ", buf);
if (p == NULL || *p == '\0')
return RET_SYN;
+ /* FIXME should use raw argument here, to support UTF-8 file names */
prexec(player->argp[1]);
+
while (!failed && status()) {
if (recvclient(buf, sizeof(buf)) < 0)
break;
failed = 1;
continue;
}
- if (redir == 0)
+ if (redir == NULL)
pr("\nExecute : %s\n", buf);
if (dispatch(buf, redir) < 0)
failed = 1;
if (failed) {
while (recvclient(buf, sizeof(buf)) >= 0) ;
}
- if (redir == 0)
+ if (redir == NULL)
pr("Execute : %s\n", failed ? "aborted" : "terminated");
return RET_OK;
}
{
FILE *motd_fp;
struct telstr tgm;
- char buf[MAXTELSIZE];
+ char buf[MAXTELSIZE + 1]; /* UTF-8 */
- if ((motd_fp = fopen(motdfil, "rb")) == NULL)
- {
+ if ((motd_fp = fopen(motdfil, "rb")) == NULL) {
if (errno == ENOENT)
return RET_OK;
- else
- {
+ else {
pr ("Could not open motd.\n");
logerror("Could not open motd (%s).\n", motdfil);
return RET_SYS;
}
}
- if (fread((void *)&tgm, sizeof(tgm), 1, motd_fp) != 1) {
+ if (fread(&tgm, sizeof(tgm), 1, motd_fp) != 1) {
logerror("bad header on login message (motdfil)");
fclose(motd_fp);
return RET_FAIL;
return RET_FAIL;
}
buf[tgm.tel_length] = 0;
- prnf(buf);
+ uprnf(buf);
fclose(motd_fp);
return RET_OK;
}
}
match = 0;
while (!feof(fp) && !match) {
- if (fgets(host, sizeof(host) - 1, fp) == NULL)
+ if (fgets(host, sizeof(host), fp) == NULL)
break;
if (host[0] == '#')
continue;
- if (fgets(user, sizeof(user) - 1, fp) == NULL)
+ if (fgets(user, sizeof(user), fp) == NULL)
break;
host[strlen(host) - 1] = '\0';
user[strlen(user) - 1] = '\0';