#ifndef lint
static char *RCSid = "$Header: /usr/brule/guest/empire/empire/emprcs/lib/commands/turn.c,v 2.1 1995/07/09 21:26:09 empire Exp $";
#endif /* not lint */

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

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

#include <fcntl.h>

turn()
{
	extern	s_char *upfil;
	extern	s_char *downfil;
	int	fd;
	struct	telstr tgm;
	register s_char *p;
	s_char	buf[MAXTELSIZE];

	p = getstarg(player->argp[1], "on, off or message? ", buf);
	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");
		close(fd);
		return RET_SYN;
	}
	(void) write(fd, (s_char *)&tgm, sizeof (tgm));
	(void) write(fd, buf, tgm.tel_length);
	(void) close(fd);
	pr("\n");
	return RET_OK;
}
