(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

@ -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;
}