1 /* $OpenBSD: wizard.c,v 1.20 2017/06/23 12:56:25 fcambus Exp $ */
2 /* $NetBSD: wizard.c,v 1.3 1995/04/24 12:21:41 cgd Exp $ */
3
4 /*-
5 * Copyright (c) 1991, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * The game adventure was originally written in Fortran by Will Crowther
9 * and Don Woods. It was later translated to C and enhanced by Jim
10 * Gillogly. This code is derived from software contributed to Berkeley
11 * by Jim Gillogly at The Rand Corporation.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38 /* Re-coding of advent in C: privileged operations */
39
40 #include <limits.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <time.h>
44
45 #include "extern.h"
46 #include "hdr.h"
47
48 char magic[6];
49
50 void
poof(void)51 poof(void)
52 {
53 strlcpy(magic, DECR(d,w,a,r,f), sizeof magic);
54 latncy = 45;
55 }
56
57 int
Start(void)58 Start(void)
59 {
60 time_t t, delay;
61
62 time(&t);
63 delay = (t - savet) / 60; /* Minutes */
64 saved = -1;
65
66 if (delay >= latncy)
67 return (FALSE);
68 printf("This adventure was suspended a mere %d minute%s ago.",
69 (int)delay, delay == 1 ? "" : "s");
70 if (delay <= latncy / 3) {
71 mspeak(2);
72 exit(0);
73 }
74 mspeak(8);
75 if (!wizard()) {
76 mspeak(9);
77 exit(0);
78 }
79 return (FALSE);
80 }
81
82 int
wizard(void)83 wizard(void) /* not as complex as advent/10 (for now) */
84 {
85 if (!yesm(16, 0, 7))
86 return (FALSE);
87 mspeak(17);
88 getin(wd1, sizeof(wd1), wd2, sizeof(wd2));
89 if (!weq(wd1, magic)) {
90 mspeak(20);
91 return (FALSE);
92 }
93 mspeak(19);
94 return (TRUE);
95 }
96
97 void
ciao(void)98 ciao(void)
99 {
100 int ch;
101 char *c;
102 char fname[PATH_MAX];
103
104 printf("What would you like to call the saved version?\n");
105 for (c = fname; c - fname < sizeof(fname); c++) {
106 if ((ch = getchar()) == '\n' || ch == EOF)
107 break;
108 *c = ch;
109 }
110 if (c - fname == sizeof(fname)) {
111 c--;
112 FLUSHLINE;
113 }
114 *c = '\0';
115 if (save(fname) != 0)
116 return; /* Save failed */
117 printf("To resume, say \"adventure %s\".\n", fname);
118 printf("\"With these rooms I might now have been familiarly acquainted.\"\n");
119 exit(0);
120 }
121
122
123 int
ran(int range)124 ran(int range)
125 {
126 return (arc4random_uniform(range));
127 }
128