|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 11460 (0x2cc4)
Types: TextFile
Names: »mud.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Abermud/mud.c«
/*
** Program starts here.
*/
#include "kernel.h"
#include <time.h>
#include <sys/stat.h>
#include <signal.h>
#ifdef RCSID
static char RCS[] =
"$Header: mud.c,v 1.1 89/03/13 09:36:58 rsalz Exp $";
#endif /* RCSID */
static int childproc = -2; /* Illegal process id */
static
mygetpass(str)
char *str;
{
fflush(stdout);
/* For SYS V check null on getpass */
strcpy(str, getpass(""));
}
#ifdef KICKOFFGUEST
static
leave_game()
{
printf("AberMUD has now closed\n\n");
printf("Thank you for playing....\n");
sleep(2);
if (childproc != -2)
kill(childproc, 1);
exit(0);
}
static
explode_game()
{
signal(SIGALRM, leave_game);
printf("\007\007AberMUD is closing in 2 minutes.\n");
alarm(120);
}
static
setalrm()
{
struct tm *x;
time_t i;
unsigned int j;
signal(SIGALRM, explode_game);
time(&i);
x = localtime(&i);
/* Now how long is it till kicking off time */
j = 0;
if (x->tm_hour > KICKOFFGUEST) {
/* Its tomorrow */
j = (23 - x->tm_hour) * 60 * 60;
x->tm_hour = 0;
}
j += (60 - x->tm_min) * 60; /* Minutes */
j += (KICKOFFGUEST - x->tm_hour) * 3600;
if (getuid() == GUESTID)
alarm(j);
}
#endif /* KICKOFFGUEST */
static int
mudopen()
{
#ifdef CHECK
time_t x;
struct tm *a;
time(&x);
a = localtime(&x);
return a->tm_hour >= 2 && a->tm_hour <= 6;
#else
return 1;
#endif /* CHECK */
}
\f
readline(s, l)
char *s;
int l;
{
char buff[80], *p;
fgets(buff, sizeof buff, stdin);
if (p = strchr(buff, '\n'))
*p = '\0';
strncpy(s, buff, l);
s[l] = '\0';
}
crapup(p)
char *p;
{
printf("\nFatal error:\n\t%s\nHit return to continue:", p);
while (getchar() != '\n')
;
exit(1);
}
main()
{
char z[60], u[80], user[80];
int isawiz, r, i;
FILE *a;
struct stat sb;
time_t ct;
if (!isatty(fileno(stdin))) {
printf("A funny old man steps out and waves his fingers at you\n");
printf("\"File redirection!\" he screams, \"you think I haven't thought of that!\".\n");
exit(1);
}
#ifdef HOST_MACHINE
/* Check we are running on the correct host; see the notes about the
* use of flock(); and the affects of lockf(); */
gethostname(u, 33);
if (!EQ(u, HOST_MACHINE)) {
fprintf(stderr, "AberMUD is only available on %s, not on %s\n",
HOST_MACHINE, u);
exit(1);
}
#endif /* HOST_MACHINE */
/* Check if there is a no logins file active */
if (a = fopen(NOLOGIN, "r")) {
printf("\n\n\n\n");
while (fgets(u, sizeof u, a))
printf("%s", u);
fclose(a);
exit(0);
}
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
signal(SIGTSTP, SIG_IGN);
#ifdef KICKOFFGUEST
setalrm();
#endif /* KICKOFFGUEST */
/* Show date created, motd, etc. */
cls();
printf("\n A B E R M U D\n\n");
printf(" By Alan Cox, Richard Acott Jim Finnis\n\n");
printf("This AberMUD was created: %s",
stat(EXE, &sb) < 0 ? "<unknown>\n" : ctime(&sb.st_mtime));
if ((a = fopen(RESET_N, "r")) == NULL)
printf("AberMUD has yet to ever start!\n");
else {
fscanf(a, "%d", &r);
fclose(a);
time(&ct);
/* NOSTRICT "warning: long assignment may lose accuracy" */
r = ct - r;
/* Elapsed time. */
printf("Game time elapsed: ");
if (r > 24 * 60 * 60)
printf("Over a day!\n");
else {
if (r >= 3600) {
i = r / 3600;
printf("%d hour%s", i, i == 1 ? "" : "s");
if (r -= i * 3600)
printf(" and ");
}
if (r >= 60) {
i = r / 60;
printf("%d minute%s", i, i == 1 ? "" : "s");
if (r -= i * 60)
printf(" and ");
}
if (r)
printf("%d second%s", r, r == 1 ? "" : "s");
printf("\n");
}
}
/* Does all the login stuff */
login(user);
/* list the message of the day */
cls();
if (a = fopen(MOTD, "r")) {
while (fgets(u, sizeof u, a))
printf("%s", u);
fclose(a);
}
printf("\nType return:");
while (getchar() != '\n')
;
printf("\n\n");
cuserid(u);
isawiz = EQ(u, PRIV1) || EQ(u, PRIV2) || EQ(u, PRIV3)
|| EQ(u, PRIV4) || EQ(u, PRIV5);
for ( ; ; ) {
cls();
printf("\nWelcome To AberMUD II [Unix]\n");
printf("Options:\n");
printf("\t0] Exit AberMUD\n");
if (i = mudopen())
printf("\t1] Enter The Game\n");
else
printf("\t Mud opens at 2am\n");
printf("\t2] Change Password\n");
if (isawiz) {
printf("\t3] Show persona\n");
printf("\t4] Edit persona\n");
printf("\t5] Delete persona\n");
isawiz = 1;
}
printf("\n\nSelect > ");
readline(z, 3);
if (!i && EQ(z, "1"))
z[0] = '?';
switch (z[0]) {
default:
printf("Bad option\n");
sleep(1);
break;
case '0':
exit(0);
case '1':
cls();
printf("The Hallway\n");
printf("You stand in a long dark hallway, which echoes to the tread of your\n");
printf("booted feet. You stride on down the hall, choose your masque and enter the\n");
printf("worlds beyond the known...\n\n");
switch ((childproc = fork())) {
case 0:
execl(EXE, GAMENAME, user, (char *)NULL);
crapup("mud.exe: Not found");
break;
case -1:
crapup("Fork failed");
}
wait((WAITER *)0);
childproc = -2;
break;
case '2':
chpwd(user);
break;
case '3':
if (isawiz)
showuser();
break;
case '4':
if (isawiz)
edituser();
break;
case '5':
if (isawiz)
deluser();
break;
}
}
}
/* The whole login system is called from this */
login(user)
char *user;
{
register char *p;
FILE *fl;
char a[80], pwd[32], block[128];
int i;
for ( ; ; ) {
int uflg = 0;
printf("\nBy what name shall I call you?\n*");
readline(user, 15);
if (user[0] == '\0') {
printf("Ok... by then.\n");
exit(0);
}
for (p = lowercase(user); *p; p++)
if (!isalpha(*p)) uflg = 1;
if (uflg) {
printf("Sorry the name may only contain letters\n");
continue;
}
if (*p)
continue;
if (p - user > 10) {
printf("This name is too long to be a game name\n");
continue;
}
user[0] = toupper(user[0]);
if (EQ(user, "The") || EQ(user, "Me") || EQ(user, "Myself")
|| EQ(user, "It") || EQ(user, "Them") || EQ(user, "Him")
|| EQ(user, "Her") || EQ(user, "Someone") || EQ(user, "There")) {
printf("Sorry I can't call you that\n");
continue;
}
if (UserExists(user, a) == -1) {
printf("\nDid I get the name right %s?", user);
readline(a, 2);
if (a[0] == 'n' || a[0] == 'N') {
printf("\n");
continue;
}
}
/* Check if banned first */
if (fl = fopen(BAN_FILE, "r")) {
while (fgets(a, sizeof a, fl)) {
if (p = strchr(a, '\n'))
*p = 0;
if (EQ(user, a)) {
crapup("Sorry, you've been banned from the Game!");
continue;
}
}
fclose(fl);
}
break;
}
i = UserExists(user, block);
strcpy(pwd, user); /* save for new user */
if (i == 1) {
GetFields(block, user, pwd);
for (i = 0; i < 2; i++) {
printf("\nThis persona already exists, what is the password?\n*");
mygetpass(block);
if(block[0] == '\0') {
printf("Ok... by then..\n");
exit(0);
}
printf("\n");
if (EQ(block, pwd))
break;
}
if (i == 2)
crapup("Bad password");
}
else {
/* this bit registers the new user */
printf("Creating new persona...\n");
for ( ; ; ) {
printf("Give me a password for this persona\n*");
mygetpass(block);
printf("\n");
if (strchr(block, ','))
printf("Illegal character in password\n");
else if (!EMPTY(block))
break;
}
strcpy(user, pwd);
strcpy(pwd, block);
sprintf(block, "%s.%s....", user, pwd);
if ((fl = openlock(PASSWORDFILE, "a")) == NULL) {
crapup("No persona file");
return;
}
fprintf(fl, "%s\n", block);
closelock(fl);
}
}
/* Return block data for user or -1 if not exist */
int
UserExists(uid, block)
char *uid;
char *block;
{
FILE *unit;
char namefromfile[128], wk2[128];
if ((unit = openlock(PASSWORDFILE, "r")) == NULL)
crapup("No persona file");
(void)lowercase(strcpy(wk2, uid));
while (fgets(block, 255, unit)) {
GetFields(block, namefromfile, (char *)NULL);
if (EQ(lowercase(namefromfile), wk2)) {
closelock(unit);
return 1;
}
}
closelock(unit);
return -1;
}
showuser()
{
char name[80], block[256];
printf("\nUser Name:");
gets(name);
(void)shu(name, block);
printf("\nHit Return:");
while (getchar() != '\n')
;
}
int
shu(name, block)
char *name, *block;
{
int a;
char nm[128], pw[128];
if ((a = UserExists(name, block)) == -1)
printf("\nNo user registered in that name\n\n\n");
else {
GetFields(block, nm, pw);
printf("\n\nUser Data For %s:\n\tName:%s\n\tPassword:%s\n",
name, nm, pw);
}
return a;
}
deluser()
{
char name[80], block[256];
printf("\nUser Name:");
gets(name);
if (UserExists(name, block) == -1)
printf("\nCannot delete non-existant user\n");
else
delu2(name);
}
edituser()
{
char name[80], block[256], bk2[256], nam2[128], pas2[128];
FILE *fl;
printf("\nUser Name:");
gets(name);
if (shu(name, block) == -1)
sprintf(block, "%s.default.E..", name);
GetFields(block, nam2, pas2);
printf("\nEditing : %s\n\n", name);
ed_fld("Name:", nam2);
ed_fld("Password:", pas2);
sprintf(bk2, "%s.%s.....", nam2, pas2);
delu2(name);
if ((fl = openlock(PASSWORDFILE, "a")) == NULL)
return;
fprintf(fl, "%s\n", bk2);
closelock(fl);
}
ed_fld(name, string)
char *name, *string;
{
char bk[128];
for ( ; ; ) {
printf("%s (Currently %s):", name, string);
gets(bk);
if (!bk[0])
return;
if (strchr(bk, '.') == NULL)
break;
printf("\nInvalid Data Field\n");
}
strcpy(string, bk);
}
delu2(name)
char *name;
{
char b2[128], buff[128], b3[128];
FILE *a, *b;
if ((a = openlock(PASSWORDFILE, "r")) == NULL)
return;
if ((b = openlock(PASSTEMP, "w")) == NULL) {
fclose(a);
return;
}
lowercase(strcpy(b3, name));
while (fgets(buff, sizeof buff, a)) {
GetFields(buff, b2, (char *)NULL);
if (!EQ(b3, lowercase(b2)))
fprintf(b, "%s", buff);
}
closelock(a);
closelock(b);
if ((a = openlock(PASSWORDFILE, "w")) == NULL)
return;
if ((b = openlock(PASSTEMP, "r")) == NULL) {
fclose(a);
return;
}
while (fgets(buff, sizeof buff, b))
fprintf(a, "%s", buff);
closelock(a);
closelock(b);
}
chpwd(user)
char *user;
{
char block[128], data[128], pwd[80], pv[80];
FILE *fl;
strcpy(data, user);
(void)UserExists(user, block);
strcpy(user, data);
GetFields(block, data, pwd);
printf("\nOld Password\n*");
mygetpass(data);
if (!EQ(data, pwd)) {
printf("\nIncorrect Password\n");
return;
}
printf("\nNew Password\n");
for ( ; ; ) {
printf("*");
mygetpass(pwd);
printf("\n");
if (EMPTY(pwd))
continue;
if (strchr(pwd, '.')) {
printf("Illegal Character in password\n");
continue;
}
printf("\nVerify Password\n*");
mygetpass(pv);
printf("\n");
if (!EQ(pv, pwd)) {
printf("\nNO!\n");
continue;
}
break;
}
/* delete me and tack me on end */
sprintf(block, "%s.%s.....", user, pwd);
delu2(user);
if ((fl = openlock(PASSWORDFILE, "a")) == NULL)
return;
fprintf(fl, "%s\n", block);
closelock(fl);
printf("Changed\n");
}