#ifndef lint
static char *RCSid = "$Header: turn.c,v 1.6 89/09/26 20:02:59 mr-frog Exp $";
#endif /* not lint */

/*
 * turn.c
 *
 * turn the game on, off, or set login message.
 *
 * from PSL Empire, 1985
 */

#include "misc.h"
#include "tel.h"

#include <fcntl.h>

turn()
{
	extern	char *argp[];
	extern	char upfil[];
	extern	char downfil[];
	int	fd;
	struct	telstr tgm;
	register char *p;
	char	buf[512];

	p = getstarg(argp[1], "on, off or message? ");
	if (strcmp(p, "off") == 0) {
		(void) unlink(upfil);
		fd = open(downfil, O_RDWR|O_CREAT|O_TRUNC, 0660);
	} else if (strcmp(p, "on") == 0) {
		(void) unlink(downfil);
		fd = open(upfil, O_RDWR|O_CREAT|O_TRUNC, 0660);
		pr("on ");
	} else {
		fd = open(upfil, O_RDWR|O_CREAT|O_TRUNC, 0660);
	}
	(void) time(&tgm.tel_date);
	if ((tgm.tel_length = getele("The World", buf)) <= 0) {
		pr("Ignored\n");
		return RET_SYN;
	}
	(void) write(fd, (char *)&tgm, sizeof (tgm));
	(void) write(fd, buf, tgm.tel_length);
	(void) close(fd);
	pr("\n");
	return RET_OK;
}
