1 /* File jump.c */
2 /***************************************************************************
3 *  Copyright 2003 -   Steven Shipway <steve@cheshire.demon.co.uk>          *
4 *                     Put "nospam" in subject to avoid spam filter         *
5 *                                                                          *
6 *  This program is free software; you can redistribute it and/or modify    *
7 *  it under the terms of the GNU General Public License as published by    *
8 *  the Free Software Foundation; either version 2 of the License, or       *
9 *  (at your option) any later version.                                     *
10 *                                                                          *
11 *  This program is distributed in the hope that it will be useful,         *
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
14 *  GNU General Public License for more details.                            *
15 *                                                                          *
16 *  You should have received a copy of the GNU General Public License       *
17 *  along with this program; if not, write to the Free Software             *
18 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA               *
19 *  02111-1307, USA.                                                        *
20 ***************************************************************************/
21 
22 
23 #include "wand_head.h"
24 
25 extern int debug_disp;
26 extern int no_passwords;
27 extern int maxscreens;
28 
29 /************************************************************
30 *                   function scrn_passwd                    *
31 *              reads password num into passwd               *
32 *************************************************************/
scrn_passwd(num,passwd)33 int scrn_passwd(num, passwd)    /* reads password num into passwd */
34 int num;
35 char *passwd;
36 {
37         long position;
38         FILE *fp;
39 
40         position = PASSWD;
41         while(position > 200000)
42                 position -= 200000;
43         if((fp = fopen(DICTIONARY,"r")) == NULL)
44                 return 0;
45         fseek(fp,position,ftell(fp));
46         while(fgetc(fp) != '\n');
47         fscanf(fp,"%s\n",passwd);
48         /* read a word into passwd */
49         fclose(fp);
50         return (1);
51 }
52 
53 /*******************************************************
54 *                   function showpass                  *
55 ********************************************************/
showpass(num)56 void showpass(num)
57      int num;
58 {
59     long position;
60     char correct[20];
61     char buffer[100];
62     FILE *fp;
63     char ch;
64     if(no_passwords)
65         return;
66     if(!debug_disp)
67         move(18,0);
68     else
69         move(20,0);
70     if(!scrn_passwd(num,correct))
71         return;
72     (void) sprintf(buffer,"The password to jump to level %d ( using ~ ) is : %s        \n",(num+1),correct);
73     addstr(buffer);
74     addstr("PRESS ANY KEY TO REMOVE IT AND CONTINUE                          \n");
75     refresh();
76     ch = getch();
77     if(!debug_disp)
78         move(18,0);
79     else
80         move(20,0);
81     addstr("                                                                        \n");
82     addstr("                                              ");
83     if(!debug_disp)
84         move(18,0);
85     else
86         move(20,0);
87     refresh();
88 }
89 
90 /**********************************************************
91 *                    function jumpscreen                  *
92 ***********************************************************/
jumpscreen(num)93 int jumpscreen(num)
94     int num;
95 {
96     char word[20],
97          buffer[100],
98          correct[20];
99     int index=0, input;
100     char ch;
101     long position;
102     int  fp, scrn;
103 
104     if(no_passwords == 1) {
105         if(!debug_disp)
106             move(16,0);
107         else
108             move(18,0);
109         addstr("Enter number of desired level.\n");
110         refresh();
111         scrn = getnum();
112         if(scrn > num) {
113             if(!debug_disp)
114                 move(16,0);
115             else
116                 move(18,0);
117             addstr("                                                ");
118             return scrn;
119             }
120         if(!debug_disp)
121             move(16,0);
122         else
123             move(18,0);
124         addstr("No way, Jose! Back-jumping is prohibited!");
125         refresh();
126         return num;
127     }
128 
129     if(!debug_disp)
130         move(16,0);
131     else
132         move(18,0);
133     addstr("Please enter password of screen to jump to:");
134     refresh();
135     while(((word[index++] = getch()) != '\n')&&(index < 19))
136     {
137         addch('*');
138         refresh();
139     }
140     word[--index]='\0';
141     if(!debug_disp)
142         move(16,0);
143     else
144         move(18,0);
145     addstr("Validating...                                             \n");
146     refresh();
147 
148     if(strcmp(word,MASTERPASSWORD) == 0)
149     {
150         if(!debug_disp)
151             move(16,0);
152         else
153             move(18,0);
154         addstr("Enter number of desired level.");
155         refresh();
156         num = getnum();
157         (void) scrn_passwd(num-1,correct);
158         sprintf(buffer,"Certainly master, but the correct word is %s.       \n",correct);
159         if(!debug_disp)
160             move(16,0);
161         else
162             move(18,0);
163         addstr(buffer);
164         addstr("PRESS ANY KEY TO REMOVE IT AND CONTINUE                          \n");
165         refresh();
166         getchar();
167         if(!debug_disp)
168             move(16,0);
169         else
170             move(18,0);
171         addstr("                                                             ");
172         if(!debug_disp)
173             move(17,0);
174         else
175             move(19,0);
176         addstr("                                                             ");
177         if(!debug_disp)
178             move(16,0);
179         else
180             move(18,0);
181         refresh();
182         return num;
183     }
184 
185     for(scrn = num;scrn < maxscreens;scrn++) {
186         if(!scrn_passwd(scrn,correct))
187             break;
188         if(strcmp(correct,word) == 0)
189         {
190             if(!debug_disp)
191                 move(16,0);
192             else
193                 move(18,0);
194             addstr("Password Validated..... Jumping to desired screen.        ");
195             refresh();
196             return ++scrn;
197         }
198     }
199 
200     if(!debug_disp)
201         move(16,0);
202     else
203         move(18,0);
204     addstr("PASSWORD NOT RECOGNISED!                    ");
205     refresh();
206     usleep(750000);  /* Marina */
207     if(!debug_disp)
208         move(16,0);
209     else
210         move(18,0);
211     addstr("                                                          ");
212 
213     return num;
214 }
215 
216 /***********************************************************
217 *                     function getnum                      *
218 ************************************************************/
getnum()219 int getnum()
220 {
221     char ch;
222     int num = 0;
223 
224     for(ch = getch(),addch(ch),refresh();
225         ch >= '0' && ch <= '9';
226         ch = getch(),addch(ch),refresh())
227     {
228         num = num * 10 + ch - '0';
229     }
230     return num;
231 }
232