3
|
1 /* $Id: getname.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */
|
|
2
|
|
3 /*
|
|
4 * getname.c
|
|
5 *
|
|
6 * Kevin P. Smith 09/28/88
|
|
7 *
|
|
8 */
|
|
9 #include "copyright2.h"
|
|
10
|
|
11 #include <stdio.h>
|
|
12 #ifdef __STDC__
|
|
13 #include <stdlib.h>
|
|
14 #include <unistd.h>
|
|
15 #endif
|
|
16 #include <sys/types.h>
|
|
17 #include <sys/stat.h>
|
|
18 #include <sys/file.h>
|
|
19 #include <errno.h>
|
|
20 #include <pwd.h>
|
|
21 #include <string.h>
|
|
22 #include <ctype.h>
|
|
23 #include <time.h>
|
|
24 #ifndef hpux
|
|
25 #include <sys/time.h>
|
|
26 #endif
|
|
27 #include "Wlib.h"
|
|
28 #include "defs.h"
|
|
29 #include "struct.h"
|
|
30 #include "data.h"
|
|
31 #include "proto.h"
|
|
32
|
|
33 static char tempname[16];
|
|
34 static char password1[16];
|
|
35 static char password2[16];
|
|
36 static int state, autolog;
|
|
37 static char username[32] = "****";
|
|
38 #define ST_GETNAME 0
|
|
39 #define ST_GETPASS 1
|
|
40 #define ST_MAKEPASS1 2
|
|
41 #define ST_MAKEPASS2 3
|
|
42 #define ST_DONE 4
|
|
43
|
|
44 /* Prototypes */
|
|
45 static void adjustString P((int ch, char *str, char *defname));
|
|
46 static void checkpassword P((void));
|
|
47 static void displayStartup P((char *defname));
|
|
48 static void loaddude P((void));
|
|
49 static void makeNewGuy P((void));
|
|
50 static void loginproced P((int ch, char *defname));
|
|
51
|
|
52 void
|
|
53 noautologin()
|
|
54 {
|
|
55 char *tempstr;
|
|
56
|
|
57 autolog = 0;
|
|
58 *defpasswd = *password1 = *password2 = '\0';
|
|
59 tempstr = "Automatic login failed";
|
|
60 W_WriteText(w, 100, 100, textColor, tempstr, strlen(tempstr),
|
|
61 W_BoldFont);
|
|
62 }
|
|
63
|
|
64 void
|
|
65 getname(defname, defpasswd)
|
|
66 char *defname, *defpasswd;
|
|
67 /* Let person identify themselves from w */
|
|
68 {
|
|
69 W_Event event;
|
|
70 register ch = 0;
|
|
71 int secondsLeft = 99, laststate;
|
|
72 char tempstr[40];
|
|
73 long lasttime;
|
|
74 register int j;
|
|
75
|
|
76 #ifdef RECORDER
|
|
77 if (playback)
|
|
78 return;
|
|
79 #endif
|
|
80 autolog = (*defpasswd && *defname) ? 1 : 0;
|
|
81
|
|
82 {
|
|
83 struct passwd *passwd;
|
|
84
|
|
85 passwd = getpwuid(getuid());
|
|
86 if (passwd) /* believe it or not, getpwuid failed on me -
|
|
87 RF */
|
|
88 strcpy(username, passwd->pw_name);
|
|
89 }
|
|
90
|
|
91 bzero(mystats, sizeof(struct stats));
|
|
92 mystats->st_tticks = 1;
|
|
93 mystats->st_flags =
|
|
94 (ST_NOBITMAPS * (!sendmotdbitmaps) +
|
|
95 ST_KEEPPEACE * keeppeace +
|
|
96 0);
|
|
97 lasttime = time(NULL);
|
|
98
|
|
99 if (ghoststart)
|
|
100 return;
|
|
101
|
|
102 tempname[0] = '\0';
|
|
103 password1[0] = '\0';
|
|
104 password2[0] = '\0';
|
|
105 laststate = state = ST_GETNAME;
|
|
106 displayStartup(defname);
|
|
107 for (;;) {
|
|
108 if (isServerDead()) {
|
|
109 printf("Ack! We've been ghostbusted!\n");
|
|
110 #ifdef AUTOKEY
|
|
111 if (autoKey)
|
|
112 W_AutoRepeatOn();
|
|
113 #endif
|
|
114 EXIT(0);
|
|
115 }
|
|
116 if (lasttime != time(NULL)) {
|
|
117 lasttime++;
|
|
118 secondsLeft--;
|
|
119 if (!autolog) {
|
|
120 sprintf(tempstr, "Seconds to go: %d ", secondsLeft);
|
|
121 W_WriteText(w, 150, 400, textColor, tempstr, strlen(tempstr),
|
|
122 W_BoldFont);
|
|
123 }
|
|
124 if (secondsLeft == 0) {
|
|
125 me->p_status = PFREE;
|
|
126 printf("Auto-Quit\n");
|
|
127 #ifdef AUTOKEY
|
|
128 if (autoKey)
|
|
129 W_AutoRepeatOn();
|
|
130 #endif
|
|
131 EXIT(0);
|
|
132 }
|
|
133 }
|
|
134 if (state == ST_DONE) {
|
|
135 W_ClearWindow(w);
|
|
136 return;
|
|
137 }
|
|
138 readFromServer(); /* Just in case it wants to say something */
|
|
139
|
|
140 if (autolog) {
|
|
141 switch (state) {
|
|
142 case ST_GETNAME:
|
|
143 tempname[0] = '\0';
|
|
144 ch = 13;
|
|
145 j = 0;
|
|
146 break;
|
|
147
|
|
148 case ST_GETPASS:
|
|
149 case ST_MAKEPASS1:
|
|
150 case ST_MAKEPASS2:
|
|
151 ch = defpasswd[j++];
|
|
152 if (ch == '\0') {
|
|
153 j = 0;
|
|
154 ch = 13;
|
|
155 }
|
|
156 break;
|
|
157
|
|
158 default:
|
|
159 break;
|
|
160 }
|
|
161
|
|
162 loginproced(ch, defname);
|
|
163
|
|
164 }
|
|
165 laststate = state;
|
|
166
|
|
167 if (!W_EventsPending())
|
|
168 continue;
|
|
169 W_NextEvent(&event);
|
|
170 if (event.Window != w)
|
|
171 continue;
|
|
172 switch ((int) event.type) {
|
|
173 case W_EV_EXPOSE:
|
|
174 displayStartup(defname);
|
|
175 break;
|
|
176 case W_EV_KEY:
|
|
177 ch = event.key;
|
|
178 if (!autolog)
|
|
179 loginproced(ch, defname);
|
|
180 }
|
|
181 }
|
|
182 }
|
|
183
|
|
184
|
|
185 static
|
|
186 void
|
|
187 loginproced(ch, defname)
|
|
188 int ch;
|
|
189 char *defname;
|
|
190 {
|
|
191 if (ch > 255)
|
|
192 ch -= 256; /* was alt key, ignore it */
|
|
193 if (ch == 10)
|
|
194 ch = 13;
|
|
195 if ((ch == ('d' + 128) || ch == ('D' + 128)) && state == ST_GETNAME && *tempname == '\0') {
|
|
196 #ifdef AUTOKEY
|
|
197 if (autoKey)
|
|
198 W_AutoRepeatOn();
|
|
199 #endif
|
|
200 EXIT(0);
|
|
201 }
|
|
202 if ((ch < 32 || ch > 127) && ch != 21 && ch != 13 && ch != 8)
|
|
203 return;
|
|
204 switch (state) {
|
|
205 case ST_GETNAME:
|
|
206 if (ch == 13) {
|
|
207 if (*tempname == '\0') {
|
|
208 strcpy(tempname, defname);
|
|
209 }
|
|
210 loaddude();
|
|
211 displayStartup(defname);
|
|
212 } else {
|
|
213 adjustString(ch, tempname, defname);
|
|
214 }
|
|
215 break;
|
|
216 case ST_GETPASS:
|
|
217 if (ch == 13) {
|
|
218 checkpassword();
|
|
219 displayStartup(defname);
|
|
220 } else {
|
|
221 adjustString(ch, password1, defname);
|
|
222 }
|
|
223 break;
|
|
224 case ST_MAKEPASS1:
|
|
225 if (ch == 13) {
|
|
226 state = ST_MAKEPASS2;
|
|
227 displayStartup(defname);
|
|
228 } else {
|
|
229 adjustString(ch, password1, defname);
|
|
230 }
|
|
231 break;
|
|
232 case ST_MAKEPASS2:
|
|
233 if (ch == 13) {
|
|
234 makeNewGuy();
|
|
235 displayStartup(defname);
|
|
236 } else {
|
|
237 adjustString(ch, password2, defname);
|
|
238 }
|
|
239 break;
|
|
240 }
|
|
241 }
|
|
242
|
|
243 static void
|
|
244 loaddude()
|
|
245 /* Query dude.
|
|
246 */
|
|
247 {
|
|
248 if (strcmp(tempname, "Guest") == 0 || strcmp(tempname, "guest") == 0) {
|
|
249 loginAccept = -1;
|
|
250 sendLoginReq(tempname, "", username, 0);
|
|
251 state = ST_DONE;
|
|
252 me->p_pos = -1;
|
|
253 me->p_stats.st_tticks = 1; /* prevent overflow */
|
|
254 strcpy(me->p_name, tempname);
|
|
255 while (loginAccept == -1) {
|
|
256 socketPause(1, 0);
|
|
257 readFromServer();
|
|
258 if (isServerDead()) {
|
|
259 printf("Server is dead!\n");
|
|
260 #ifdef AUTOKEY
|
|
261 if (autoKey)
|
|
262 W_AutoRepeatOn();
|
|
263 #endif
|
|
264
|
|
265 EXIT(0);
|
|
266 }
|
|
267 }
|
|
268 if (loginAccept == 0) {
|
|
269 printf("Hmmm... The SOB server won't let me log in as guest!\n");
|
|
270 #ifdef AUTOKEY
|
|
271 if (autoKey)
|
|
272 W_AutoRepeatOn();
|
|
273 #endif
|
|
274
|
|
275 EXIT(0);
|
|
276 }
|
|
277 return;
|
|
278 }
|
|
279 /* Ask about the user */
|
|
280 loginAccept = -1;
|
|
281 sendLoginReq(tempname, "", username, 1);
|
|
282 while (loginAccept == -1) {
|
|
283 socketPause(1, 0);
|
|
284 readFromServer();
|
|
285 if (isServerDead()) {
|
|
286 printf("Server is dead!\n");
|
|
287 #ifdef AUTOKEY
|
|
288 if (autoKey)
|
|
289 W_AutoRepeatOn();
|
|
290 #endif
|
|
291
|
|
292 EXIT(0);
|
|
293 }
|
|
294 }
|
|
295 *password1 = *password2 = 0;
|
|
296 if (loginAccept == 0) {
|
|
297 state = ST_MAKEPASS1;
|
|
298 } else {
|
|
299 state = ST_GETPASS;
|
|
300 }
|
|
301 }
|
|
302
|
|
303 static void
|
|
304 checkpassword()
|
|
305 /* Check dude's password.
|
|
306 * If he is ok, move to state ST_DONE.
|
|
307 */
|
|
308 {
|
|
309 char *s;
|
|
310
|
|
311 sendLoginReq(tempname, password1, username, 0);
|
|
312 loginAccept = -1;
|
|
313 while (loginAccept == -1) {
|
|
314 socketPause(1, 0);
|
|
315 readFromServer();
|
|
316 if (isServerDead()) {
|
|
317 printf("Server is dead!\n");
|
|
318 #ifdef AUTOKEY
|
|
319 if (autoKey)
|
|
320 W_AutoRepeatOn();
|
|
321 #endif
|
|
322
|
|
323 EXIT(0);
|
|
324 }
|
|
325 }
|
|
326 if (loginAccept == 0) {
|
|
327 if (!autolog) {
|
|
328 s = "Bad password!";
|
|
329 W_WriteText(w, 100, 100, textColor, s, strlen(s), W_BoldFont);
|
|
330 (void) W_EventsPending();
|
|
331 sleep(3);
|
|
332 W_ClearWindow(w);
|
|
333 } else
|
|
334 noautologin();
|
|
335 *tempname = 0;
|
|
336 state = ST_GETNAME;
|
|
337 return;
|
|
338 }
|
|
339 strcpy(me->p_name, tempname);
|
|
340 sendmotdbitmaps = !((me->p_stats.st_flags / ST_NOBITMAPS) & 1);
|
|
341 keeppeace = (me->p_stats.st_flags / ST_KEEPPEACE) & 1;
|
|
342 state = ST_DONE;
|
|
343 }
|
|
344
|
|
345 static void
|
|
346 makeNewGuy()
|
|
347 /* Make the dude with name tempname and password password1.
|
|
348 * Move to state ST_DONE.
|
|
349 */
|
|
350 {
|
|
351 char *s;
|
|
352
|
|
353 if (strcmp(password1, password2) != 0) {
|
|
354 if (!autolog) {
|
|
355 s = "Passwords do not match";
|
|
356 W_WriteText(w, 100, 120, textColor, s, strlen(s), W_BoldFont);
|
|
357 (void) W_EventsPending();
|
|
358 sleep(3);
|
|
359 W_ClearWindow(w);
|
|
360 } else
|
|
361 noautologin();
|
|
362 *tempname = 0;
|
|
363 state = ST_GETNAME;
|
|
364 return;
|
|
365 }
|
|
366 /* same routine! */
|
|
367 checkpassword();
|
|
368 }
|
|
369
|
|
370 static void
|
|
371 adjustString(ch, str, defname)
|
|
372 char ch, *str;
|
|
373 char *defname;
|
|
374 {
|
|
375 if (ch == 21) {
|
|
376 *str = '\0';
|
|
377 if (state == ST_GETNAME)
|
|
378 displayStartup(defname);
|
|
379 } else if (ch == 8 || ch == '\177') {
|
|
380 if ((int) strlen(str) > 0) {
|
|
381 str[strlen(str) - 1] = '\0';
|
|
382 if (state == ST_GETNAME)
|
|
383 displayStartup(defname);
|
|
384 }
|
|
385 } else {
|
|
386 if (strlen(str) == 15)
|
|
387 return;
|
|
388 str[strlen(str) + 1] = '\0';
|
|
389 str[strlen(str)] = ch;
|
|
390 if (state == ST_GETNAME)
|
|
391 displayStartup(defname);
|
|
392 }
|
|
393 }
|
|
394
|
|
395 static void
|
|
396 displayStartup(defname)
|
|
397 char *defname;
|
|
398 /* Draws entry screen based upon state. */
|
|
399 {
|
|
400 char s[100];
|
|
401 char *t;
|
|
402
|
|
403 if (state == ST_DONE || autolog)
|
|
404 return;
|
|
405 t = "Enter your name. Use the name 'guest' to remain anonymous.";
|
|
406 W_WriteText(w, 100, 30, textColor, t, strlen(t), W_BoldFont);
|
|
407 t = "Type ^D (Ctrl - D) to quit.";
|
|
408 W_WriteText(w, 100, 40, textColor, t, strlen(t), W_BoldFont);
|
|
409 sprintf(s, "Your name (default = %s): %s ", defname, tempname);
|
|
410 W_WriteText(w, 100, 50, textColor, s, strlen(s), W_BoldFont);
|
|
411 if (state == ST_GETPASS) {
|
|
412 t = "Enter password: ";
|
|
413 W_WriteText(w, 100, 60, textColor, t, strlen(t), W_BoldFont);
|
|
414 }
|
|
415 if (state > ST_GETPASS) {
|
|
416 t = "You need to make a password.";
|
|
417 W_WriteText(w, 100, 70, textColor, t, strlen(t), W_BoldFont);
|
|
418 t = "So think of a password you can remember, and enter it.";
|
|
419 W_WriteText(w, 100, 80, textColor, t, strlen(t), W_BoldFont);
|
|
420 t = "What is your password? :";
|
|
421 W_WriteText(w, 100, 90, textColor, t, strlen(t), W_BoldFont);
|
|
422 }
|
|
423 if (state == ST_MAKEPASS2) {
|
|
424 t = "Enter it again to make sure you typed it right.";
|
|
425 W_WriteText(w, 100, 100, textColor, t, strlen(t), W_BoldFont);
|
|
426 t = "Your password? :";
|
|
427 W_WriteText(w, 100, 110, textColor, t, strlen(t), W_BoldFont);
|
|
428 }
|
|
429 }
|