diff options
author | Anthony J. Bentley <bentley@cvs.openbsd.org> | 2019-04-05 09:02:28 +0000 |
---|---|---|
committer | Anthony J. Bentley <bentley@cvs.openbsd.org> | 2019-04-05 09:02:28 +0000 |
commit | b28801d08d0aab22288dc5c3692775a9fa1c7a63 (patch) | |
tree | f6cbf153fd5ec791bde8f2b405cd5fbbf0f06931 /games/hack/hack.o_init.c | |
parent | 1933f7cd6e67ccbaace9d973a0d769b475d6b25e (diff) |
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/hack/hack.o_init.c')
-rw-r--r-- | games/hack/hack.o_init.c | 42 |
1 files changed, 34 insertions, 8 deletions
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; } } |