(turn): Change the command to allow for both an MOTD and a no-login

message.  Clean 'register' and 's_char' remnants on the way.
Circumvents bug #813167.
This commit is contained in:
Marc Olzheim 2004-12-16 14:17:08 +00:00
parent b3f62f7d66
commit d9f0f475da
7 changed files with 119 additions and 66 deletions

View file

@ -99,7 +99,7 @@ int start_unit_type[];
#endif
/* Variables that get values derived from econfig */
extern char *upfil;
extern char *motdfil;
extern char *downfil;
extern char *disablefil;
extern char *banfil;

View file

@ -261,7 +261,7 @@ extern int natbyname(s_char *, natid *);
extern int natpass(int, s_char *);
/* player.c */
extern struct player *player; /* current player's context */
extern s_char *praddr(struct player *);
extern char *praddr(struct player *);
extern void player_main(struct player *);
extern int match_user(char *, struct player *);
extern int status(void);

View file

@ -1,9 +1,10 @@
.TH Command TURN
.NA turn "Allow/disallow logins. Change login message."
.LV Expert
.SY "turn <on|off|mess>"
Use "turn on" or "turn off" to enable/disable logins. If you just
want to change the login message, then use "turn mess". In all three
cases, you will be put into the telegram prompter to enter a new motd
(message of the day) which is printed when the player logs in.
.SY "turn <on|off|motd>"
Use "turn on" or "turn off" to enable/disable logins. If you want to
change the login message, then use "turn motd". With "turn motd" and
"turn off", you will be put into the telegram prompter to enter a new
motd (message of the day) which is printed when the player logs in, or
an additional "no-login" message printed while logins are disabled.
.SA "Deity"

View file

@ -37,52 +37,94 @@
#include "commands.h"
#include "optlist.h"
#include <errno.h>
#include <fcntl.h>
/*
* Enable / disable logins and set the message of the day.
*/
int
turn(void)
{
int fd;
struct telstr tgm;
register s_char *p;
s_char buf[MAXTELSIZE];
char *p;
char buf[MAXTELSIZE];
char *msgfilepath;
p = getstarg(player->argp[1], "on, off or message? ", buf);
p = getstarg(player->argp[1], "on, off or motd? ", buf);
if (!p)
return RET_SYN;
if (strcmp(p, "off") == 0) {
(void)unlink(upfil);
#if !defined(_WIN32)
fd = open(downfil, O_RDWR | O_CREAT | O_TRUNC, 0660);
#else
fd = open(downfil, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660);
#endif
pr("off ");
msgfilepath = downfil;
} else if (strcmp(p, "on") == 0) {
(void)unlink(downfil);
#if !defined(_WIN32)
fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC, 0660);
#else
fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660);
#endif
pr("on ");
pr("Removing no-login message and re-enabling logins.\n");
if ((unlink(downfil) == -1) && (errno != ENOENT))
{
pr("Could not remove no-login file, logins still disabled.\n");
logerror("Could not remove no-login file (%s).\n", downfil);
return RET_SYS;
}
return RET_OK;
} else {
#if !defined(_WIN32)
fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC, 0660);
#else
fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660);
#endif
pr("motd ");
msgfilepath = motdfil;
}
(void)time(&tgm.tel_date);
if ((tgm.tel_length = getele("The World", buf)) <= 0) {
if (msgfilepath == downfil)
pr("Enter a message shown to countries trying to log in.\n");
else
pr("Enter a new message of the day.\n");
time(&tgm.tel_date);
tgm.tel_length = getele("The World", buf);
if (tgm.tel_length < 0)
{
pr("Ignored\n");
close(fd);
if (msgfilepath == downfil)
pr("NOT disabling logins.\n");
return RET_SYN;
} else if (tgm.tel_length == 0)
{
if (msgfilepath == motdfil)
{
pr("Removing exsting motd.\n");
if ((unlink(msgfilepath) == -1) && (errno != ENOENT))
{
pr("Could not remove motd.\n");
logerror("Could not remove motd file (%s).\n", msgfilepath);
return RET_SYS;
}
return RET_OK;
} else
pr("Writing empty no-login message.\n");
}
#if !defined(_WIN32)
fd = open(msgfilepath, O_RDWR | O_CREAT | O_TRUNC, 0660);
#else
fd = open(msgfilepath, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660);
#endif
if (fd == -1)
{
pr("Something went wrong opening the message file.\n");
logerror("Could not open message file (%s).\n", msgfilepath);
return RET_SYS;
}
if (msgfilepath == downfil)
pr("Logins disabled.\n");
if ((write(fd, &tgm, sizeof(tgm)) < sizeof(tgm)) ||
(write(fd, buf, tgm.tel_length) < tgm.tel_length) ||
(close(fd) == -1))
{
pr("Something went wrong writing the message file.\n");
logerror("Could not properly write message file (%s).\n",
msgfilepath);
return RET_SYS;
}
(void)write(fd, (s_char *)&tgm, sizeof(tgm));
(void)write(fd, buf, tgm.tel_length);
(void)close(fd);
pr("\n");
return RET_OK;
}

View file

@ -173,7 +173,7 @@ struct otherfiles {
/* list of other well known files... -maybe tailor these oneday
* anyway - meantime they are all relative to datadir */
static struct otherfiles ofiles[] = {
{&upfil, "up"},
{&motdfil, "motd"},
{&downfil, "down"},
{&disablefil, "disable"},
{&banfil, "ban"},

View file

@ -39,7 +39,7 @@ char *infodir = EMPDIR "/info.nr";
char *datadir = EMPDIR "/data";
char *teldir = EMPDIR "/data/tel";
char *upfil = EMPDIR "/data/up";
char *motdfil = EMPDIR "/data/motd";
char *downfil = EMPDIR "/data/down";
char *disablefil = EMPDIR "/data/disable";
char *telfil = EMPDIR "/data/tel/tel";

View file

@ -56,6 +56,7 @@
#include <sys/time.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
struct player *player;
@ -65,12 +66,12 @@ player_main(struct player *p)
{
struct natstr *natp;
int secs;
s_char buf[128];
char buf[128];
p->state = PS_PLAYING;
player = p;
time(&player->lasttime);
(void)time(&player->curup);
time(&player->curup);
showvers(CLIENTPROTO);
show_motd();
if (init_nats() < 0)
@ -102,9 +103,9 @@ player_main(struct player *p)
natp->nat_last_logout ? ctime(&natp->
nat_last_logout) : "?");
pr(" by: %s@%s\n",
*natp->nat_userid ? natp->nat_userid : (s_char *)"nobody",
*natp->nat_userid ? natp->nat_userid : "nobody",
*natp->nat_hostname ? natp->nat_hostname : *natp->
nat_hostaddr ? natp->nat_hostaddr : (s_char *)"nowhere");
nat_hostaddr ? natp->nat_hostaddr : "nowhere");
}
}
if (*player->userid)
@ -158,8 +159,8 @@ int
command(void)
{
unsigned int x;
s_char *redir;
s_char scanspace[1024];
char *redir;
char scanspace[1024];
if (getcommand(player->combuf) < 0)
return 0;
@ -171,7 +172,7 @@ command(void)
/* DONT USE IT!!!! alarm and sleep may and dont work
together -- Sasha */
/* alarm((unsigned int)60*60); 1 hour */
if (player->condarg != (s_char *)0)
if (player->condarg != NULL)
for (x = 0; x < strlen(player->condarg); x++)
if (isupper(*(player->condarg + x)))
*(player->condarg + x) =
@ -188,7 +189,7 @@ status(void)
struct natstr *natp;
int minute;
struct sctstr sect;
s_char buf[128];
char buf[128];
if (player->state == PS_SHUTDOWN)
return 0;
@ -236,7 +237,7 @@ status(void)
if (natp->nat_flags & NF_SACKED)
player->nstat &= ~CAP; /* No capital yet */
player->ncomstat = player->nstat;
(void)time(&player->curup);
time(&player->curup);
minute = (player->curup - player->lasttime) / 60;
if (minute > 0) {
player->minleft -= minute;
@ -303,18 +304,18 @@ status(void)
int
execute(void)
{
s_char buf[512];
char buf[512];
int failed;
s_char *p;
s_char *redir;
s_char scanspace[1024];
char *p;
char *redir;
char scanspace[1024];
failed = 0;
redir = 0;
p = getstarg(player->argp[1], "File? ", buf);
if (p == (s_char *)0 || *p == '\0')
if (p == NULL || *p == '\0')
return RET_SYN;
prexec(player->argp[1]);
@ -342,31 +343,40 @@ execute(void)
int
show_motd(void)
{
int upf;
int motdf;
struct telstr tgm;
s_char buf[MAXTELSIZE];
char buf[MAXTELSIZE];
#if !defined(_WIN32)
if ((upf = open(upfil, O_RDONLY, 0)) < 0)
if ((motdf = open(motdfil, O_RDONLY, 0)) < 0)
#else
if ((upf = open(upfil, O_RDONLY | O_BINARY, 0)) < 0)
if ((motdf = open(motdfil, O_RDONLY | O_BINARY, 0)) < 0)
#endif
return RET_FAIL;
if (read(upf, (s_char *)&tgm, sizeof(tgm)) != sizeof(tgm)) {
logerror("bad header on login message (upfil)");
close(upf);
{
if (errno == ENOENT)
return RET_OK;
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)) {
logerror("bad header on login message (motdfil)");
close(motdf);
return RET_FAIL;
}
if (read(upf, buf, tgm.tel_length) != tgm.tel_length) {
if (read(motdf, buf, tgm.tel_length) != tgm.tel_length) {
logerror("bad length %ld on login message", tgm.tel_length);
close(upf);
close(motdf);
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(upf);
(void)close(motdf);
return RET_OK;
}
@ -375,8 +385,8 @@ match_user(char *file, struct player *p)
{
FILE *fp;
int match = 0;
s_char host[256];
s_char user[256];
char host[256];
char user[256];
if ((fp = fopen(file, "r")) == NULL) {
/*logerror("Cannot find file %s", file); */
@ -408,7 +418,7 @@ quit(void)
return RET_OK;
}
s_char *
char *
praddr(struct player *p)
{
return prbuf("%s@%s", p->userid,