-
Notifications
You must be signed in to change notification settings - Fork 4
/
jump.c
215 lines (201 loc) · 5.12 KB
/
jump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* File jump.c */
#include "jump.h"
#include "wand_head.h"
#include <curses.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
extern int debug_disp;
extern int no_passwords;
extern int maxscreens;
/************************************************************
* function scrn_passwd *
* reads password num into passwd *
*************************************************************/
int scrn_passwd(int num, char *passwd) /* reads password num into passwd */
{
long position;
FILE *fp;
position = PASSWD;
while (position > 200000)
position -= 200000;
if ((fp = fopen(DICTIONARY, "r")) == NULL)
return 0;
fseek(fp, position, ftell(fp));
while (fgetc(fp) != '\n');
if (fscanf(fp, "%s\n", passwd) == EOF && errno != 0)
{
fprintf(stderr, "fscanf error\n");
exit(EXIT_FAILURE);
}
/* read a word into passwd */
fclose(fp);
return (1);
}
/*******************************************************
* function showpass *
********************************************************/
void showpass(int num)
{
char correct[20];
if (no_passwords)
return;
if (!debug_disp)
move(18, 0);
else
move(20, 0);
if (!scrn_passwd(num, correct))
return;
printw("The password to jump to level %d ( using ~ ) is : %s \n",
(num + 1), correct);
printw("%-65s\n", "PRESS ANY KEY TO REMOVE IT AND CONTINUE");
refresh();
getch();
if (!debug_disp)
move(18, 0);
else
move(20, 0);
printw("%72s\n", "");
printw("%46s", "");
if (!debug_disp)
move(18, 0);
else
move(20, 0);
refresh();
}
/**********************************************************
* function jumpscreen *
***********************************************************/
int jumpscreen(int num)
{
char word[20], correct[20];
int index = 0;
int scrn;
struct timespec t;
if (no_passwords == 1)
{
if (!debug_disp)
move(16, 0);
else
move(18, 0);
addstr("Enter number of desired level.\n");
refresh();
scrn = getnum();
if (scrn > num)
{
if (!debug_disp)
move(16, 0);
else
move(18, 0);
printw("*48s", "");
return scrn;
}
if (!debug_disp)
move(16, 0);
else
move(18, 0);
addstr("No way, Jose! Back-jumping is prohibited!");
refresh();
return num;
}
if (!debug_disp)
move(16, 0);
else
move(18, 0);
addstr("Please enter password of screen to jump to:");
refresh();
while (((word[index++] = getch()) != '\n') && (index < 19))
{
addch('*');
refresh();
}
word[--index] = '\0';
if (!debug_disp)
move(16, 0);
else
move(18, 0);
printw("%-58s\n", "Validating...");
refresh();
if (strcmp(word, MASTERPASSWORD) == 0)
{
if (!debug_disp)
move(16, 0);
else
move(18, 0);
addstr("Enter number of desired level.");
refresh();
num = getnum();
(void) scrn_passwd(num - 1, correct);
if (!debug_disp)
move(16, 0);
else
move(18, 0);
printw("Certainly master, but the correct word is %s. \n",
correct);
printw("%-65s\n", "PRESS ANY KEY TO REMOVE IT AND CONTINUE");
refresh();
getchar();
if (!debug_disp)
move(16, 0);
else
move(18, 0);
printw("%61s", "");
if (!debug_disp)
move(17, 0);
else
move(19, 0);
printw("%61s", "");
if (!debug_disp)
move(16, 0);
else
move(18, 0);
refresh();
return num;
}
for (scrn = num; scrn < maxscreens; scrn++)
{
if (!scrn_passwd(scrn, correct))
break;
if (strcmp(correct, word) == 0)
{
if (!debug_disp)
move(16, 0);
else
move(18, 0);
printw("%-58s",
"Password Validated..... Jumping to desired screen.");
refresh();
return ++scrn;
}
}
if (!debug_disp)
move(16, 0);
else
move(18, 0);
printw("%-44s", "PASSWORD NOT RECOGNISED!");
refresh();
t.tv_sec = 0;
t.tv_nsec = 750000000;
nanosleep(&t, NULL);
if (!debug_disp)
move(16, 0);
else
move(18, 0);
printw("%61s", "");
return num;
}
/***********************************************************
* function getnum *
************************************************************/
int getnum()
{
char ch;
int num = 0;
for (ch = getch(), addch(ch), refresh(); ch >= '0' && ch <= '9';
ch = getch(), addch(ch), refresh())
{
num = num * 10 + ch - '0';
}
return num;
}