/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
player = p;
time(&player->lasttime);
time(&player->curup);
- showvers(CLIENTPROTO);
show_motd();
if (init_nats() < 0)
return;
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");
+ *natp->nat_hostname ? natp->nat_hostname
+ : *natp->nat_hostaddr ? natp->nat_hostaddr : "nowhere");
}
}
if (*player->userid)
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);
command(void)
{
unsigned int x;
- char *redir;
+ char *redir; /* UTF-8 */
char scanspace[1024];
if (getcommand(player->combuf) < 0)
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;
}
int
show_motd(void)
{
- int motdf;
+ FILE *motd_fp;
struct telstr tgm;
- char buf[MAXTELSIZE];
+ char buf[MAXTELSIZE + 1]; /* UTF-8 */
- if ((motdf = open(motdfil, O_RDONLY, 0)) < 0)
- {
+ 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 (read(motdf, &tgm, sizeof(tgm)) != sizeof(tgm)) {
+ if (fread(&tgm, sizeof(tgm), 1, motd_fp) != 1) {
logerror("bad header on login message (motdfil)");
- close(motdf);
+ 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 (read(motdf, buf, tgm.tel_length) != tgm.tel_length) {
+ if (fread(buf, tgm.tel_length, 1, motd_fp) != 1) {
logerror("bad length %ld on login message", tgm.tel_length);
- close(motdf);
+ fclose(motd_fp);
return RET_FAIL;
}
- if (tgm.tel_length >= (long)sizeof(buf))
- tgm.tel_length = sizeof(buf) - 1;
buf[tgm.tel_length] = 0;
- prnf(buf);
- (void)close(motdf);
+ uprnf(buf);
+ fclose(motd_fp);
return RET_OK;
}
char host[256];
char user[256];
- if ((fp = fopen(file, "rt")) == NULL) {
+ if ((fp = fopen(file, "r")) == NULL) {
/*logerror("Cannot find file %s", file); */
return 0;
}