annotate getname.c @ 3:5a977ccbc7a9 default tip

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