diff options
author | bentley <bentley@openbsd.org> | 2019-04-05 09:02:27 +0000 |
---|---|---|
committer | bentley <bentley@openbsd.org> | 2019-04-05 09:02:27 +0000 |
commit | dc14b708bc8db640b2f06ceb37eb5b888f20cb2f (patch) | |
tree | cf17f1716cb537e17d13ad349042be0294322503 /games | |
parent | Try to start playback after play buffer pointers are advanced. (diff) | |
download | wireguard-openbsd-dc14b708bc8db640b2f06ceb37eb5b888f20cb2f.tar.xz wireguard-openbsd-dc14b708bc8db640b2f06ceb37eb5b888f20cb2f.zip |
Fix hack(6).
- Write savegames and scorefiles to the current directory instead of /var
- Save oc_name and oc_descr alongside oc_uname in all situations
- When a levitation potion times out, explicitly float down
These patches were contributed last year by "tonypony76"; thanks!
ok deraadt@, with added enthusiasm from tedu@
Diffstat (limited to 'games')
-rw-r--r-- | games/hack/Makefile | 9 | ||||
-rw-r--r-- | games/hack/config.h | 16 | ||||
-rw-r--r-- | games/hack/hack.6 | 14 | ||||
-rw-r--r-- | games/hack/hack.main.c | 16 | ||||
-rw-r--r-- | games/hack/hack.o_init.c | 42 | ||||
-rw-r--r-- | games/hack/hack.timeout.c | 4 |
6 files changed, 62 insertions, 39 deletions
diff --git a/games/hack/Makefile b/games/hack/Makefile index 45102fc152d..64f39445c06 100644 --- a/games/hack/Makefile +++ b/games/hack/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.16 2017/07/10 21:30:37 espie Exp $ +# $OpenBSD: Makefile,v 1.17 2019/04/05 09:02:27 bentley Exp $ PROG= hack CFLAGS+=-I. @@ -27,12 +27,7 @@ makedefs: makedefs.c ${HOSTCC} ${CFLAGS} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${.CURDIR}/${.PREFIX}.c ${LDADD} beforeinstall: - ${INSTALL} ${INSTALL_COPY} -o root -g games -m 660 /dev/null \ - ${DESTDIR}/var/games/hackdir/perm - ${INSTALL} ${INSTALL_COPY} -o root -g games -m 660 /dev/null \ - ${DESTDIR}/var/games/hackdir/record ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/help \ - ${.CURDIR}/hh ${.CURDIR}/data ${DESTDIR}/var/games/hackdir - rm -f ${DESTDIR}/var/games/hackdir/bones* + ${.CURDIR}/hh ${.CURDIR}/data ${.CURDIR}/rumors ${DESTDIR}/usr/share/games/hack .include <bsd.prog.mk> diff --git a/games/hack/config.h b/games/hack/config.h index 012d5fe4952..7fd90e72ccf 100644 --- a/games/hack/config.h +++ b/games/hack/config.h @@ -1,4 +1,4 @@ -/* $OpenBSD: config.h,v 1.13 2015/10/16 07:37:46 tobias Exp $ */ +/* $OpenBSD: config.h,v 1.14 2019/04/05 09:02:27 bentley Exp $ */ /* * $NetBSD: config.h,v 1.3 1995/03/23 08:29:15 cgd Exp $*/ /* @@ -77,10 +77,10 @@ #define WIZARD "bruno" /* the person allowed to use the -D option */ #define RECORD "record"/* the file containing the list of topscorers */ #define NEWS "news" /* the file containing the latest hack news */ -#define HELP "help" /* the file containing a description of the commands */ -#define SHELP "hh" /* abbreviated form of the same */ -#define RUMORFILE "rumors" /* a file with fortune cookies */ -#define DATAFILE "data" /* a file giving the meaning of symbols used */ +#define HELP "/usr/share/games/hack/help" /* the file containing a description of the commands */ +#define SHELP "/usr/share/games/hack/hh" /* abbreviated form of the same */ +#define RUMORFILE "/usr/share/games/hack/rumors" /* a file with fortune cookies */ +#define DATAFILE "/usr/share/games/hack/data" /* a file giving the meaning of symbols used */ #define FMASK 0660 /* file creation mask */ #define HLOCK "perm" /* an empty file used for locking purposes */ #define LLOCK "safelock" /* link to previous */ @@ -93,7 +93,7 @@ * (This might be preferable for security reasons.) * #define DEF_PAGER ".../mydir/mypager" */ -#define DEF_PAGER _PATH_PAGER +/* #define DEF_PAGER _PATH_PAGER */ /* * If you define MAIL, then the player will be notified of new mail @@ -120,7 +120,7 @@ #ifdef QUEST #define HACKDIR _PATH_QUEST #else /* QUEST */ -#define HACKDIR _PATH_HACK +/* #define HACKDIR _PATH_HACK */ #endif /* QUEST */ /* @@ -130,7 +130,7 @@ * since the user might create files in a directory of his choice. * Of course SECURE is meaningful only if HACKDIR is defined. */ -#define SECURE /* do setuid(getuid()) after chdir() */ +/* #define SECURE */ /* do setuid(getuid()) after chdir() */ /* * If it is desirable to limit the number of people that can play Hack diff --git a/games/hack/hack.6 b/games/hack/hack.6 index d20f16ad880..bcdb5db53ec 100644 --- a/games/hack/hack.6 +++ b/games/hack/hack.6 @@ -1,4 +1,4 @@ -.\" $OpenBSD: hack.6,v 1.20 2016/09/09 15:32:28 tb Exp $ +.\" $OpenBSD: hack.6,v 1.21 2019/04/05 09:02:27 bentley Exp $ .\" $NetBSD: hack.6,v 1.5 1995/07/03 19:44:30 jtc Exp $ .\" .\" Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -59,7 +59,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: September 9 2016 $ +.Dd $Mdocdate: April 5 2019 $ .Dt HACK 6 .Os .Sh NAME @@ -75,13 +75,6 @@ .Op Fl d Ar directory .Op Ar playername ... .Sh DESCRIPTION -.Bf -symbolic -.Nm -is currently unusable because it relies on -.Xr setgid 2 -to allow multiple users read and write access to the same files. -.Ef -.Pp .Nm is a display oriented dungeons & dragons - like game. Both display and command structure resemble rogue. @@ -121,9 +114,6 @@ This same directory contains several auxiliary files such as lockfiles and the list of topscorers and a subdirectory .Pa save where games are saved. -The game administrator may however choose to install hack with a fixed -playing ground, usually -.Pa /var/games/hackdir . .Pp The .Fl n diff --git a/games/hack/hack.main.c b/games/hack/hack.main.c index c879206b4da..820efd724d5 100644 --- a/games/hack/hack.main.c +++ b/games/hack/hack.main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.main.c,v 1.22 2016/01/09 21:54:11 mestre Exp $ */ +/* $OpenBSD: hack.main.c,v 1.23 2019/04/05 09:02:27 bentley Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,6 +62,7 @@ */ #include <sys/stat.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -538,6 +539,8 @@ chdirx(char *dir, boolean wr) } /* warn the player if he cannot write the record file */ + /* warn the player if he cannot read the permanent lock file */ + /* warn the player if he cannot create the save directory */ /* perhaps we should also test whether . is writable */ /* unfortunately the access systemcall is worthless */ if(wr) { @@ -545,11 +548,20 @@ chdirx(char *dir, boolean wr) if(dir == NULL) dir = "."; - if((fd = open(RECORD, O_RDWR)) < 0) { + if((fd = open(RECORD, O_RDWR | O_CREAT, FMASK)) < 0) { printf("Warning: cannot write %s/%s", dir, RECORD); getret(); } else (void) close(fd); + if((fd = open(HLOCK, O_RDONLY | O_CREAT, FMASK)) < 0) { + printf("Warning: cannot read %s/%s", dir, HLOCK); + getret(); + } else + (void) close(fd); + if(mkdir("save", 0770) && errno != EEXIST) { + printf("Warning: cannot create %s/save", dir); + getret(); + } } } #endif diff --git a/games/hack/hack.o_init.c b/games/hack/hack.o_init.c index cb01e1c90b4..025f6f8b651 100644 --- a/games/hack/hack.o_init.c +++ b/games/hack/hack.o_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.o_init.c,v 1.8 2016/01/09 21:54:11 mestre Exp $ */ +/* $OpenBSD: hack.o_init.c,v 1.9 2019/04/05 09:02:27 bentley Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -173,18 +173,29 @@ savenames(int fd) { int i; unsigned len; + unsigned zero = 0; bwrite(fd, bases, sizeof bases); bwrite(fd, objects, sizeof objects); - /* as long as we use only one version of Hack/Quest we - need not save oc_name and oc_descr, but we must save - oc_uname for all objects */ for(i=0; i < SIZE(objects); i++) { + if(objects[i].oc_name) { + len = strlen(objects[i].oc_name)+1; + bwrite(fd, &len, sizeof len); + bwrite(fd, objects[i].oc_name, len); + } else + bwrite(fd, &zero, sizeof len); + if(objects[i].oc_descr) { + len = strlen(objects[i].oc_descr)+1; + bwrite(fd, &len, sizeof len); + bwrite(fd, objects[i].oc_descr, len); + } else + bwrite(fd, &zero, sizeof len); if(objects[i].oc_uname) { len = strlen(objects[i].oc_uname)+1; bwrite(fd, &len, sizeof len); bwrite(fd, objects[i].oc_uname, len); - } + } else + bwrite(fd, &zero, sizeof len); } } @@ -196,10 +207,25 @@ restnames(int fd) mread(fd, (char *) bases, sizeof bases); mread(fd, (char *) objects, sizeof objects); - for(i=0; i < SIZE(objects); i++) if(objects[i].oc_uname) { + for(i=0; i < SIZE(objects); i++) { + mread(fd, (char *) &len, sizeof len); + if(len) { + objects[i].oc_name = (char *) alloc(len); + mread(fd, objects[i].oc_name, len); + } else + objects[i].oc_name = 0; + mread(fd, (char *) &len, sizeof len); + if(len) { + objects[i].oc_descr = (char *) alloc(len); + mread(fd, objects[i].oc_descr, len); + } else + objects[i].oc_descr = 0; mread(fd, (char *) &len, sizeof len); - objects[i].oc_uname = (char *) alloc(len); - mread(fd, objects[i].oc_uname, len); + if(len) { + objects[i].oc_uname = (char *) alloc(len); + mread(fd, objects[i].oc_uname, len); + } else + objects[i].oc_uname = 0; } } diff --git a/games/hack/hack.timeout.c b/games/hack/hack.timeout.c index 9383bf9161f..eedb5405176 100644 --- a/games/hack/hack.timeout.c +++ b/games/hack/hack.timeout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.timeout.c,v 1.7 2016/01/09 18:33:15 mestre Exp $ */ +/* $OpenBSD: hack.timeout.c,v 1.8 2019/04/05 09:02:27 bentley Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -73,7 +73,7 @@ hacktimeout(void) if(Stoned) stoned_dialogue(); for(upp = u.uprops; upp < u.uprops+SIZE(u.uprops); upp++) if((upp->p_flgs & TIMEOUT) && !--upp->p_flgs) { - if(upp->p_tofn) (*upp->p_tofn)(); + if(upp->p_tofn) float_down(); else switch(upp - u.uprops){ case STONED: killer = "cockatrice"; |