Mercurial > ~darius > hgwebdir.cgi > paradise_server
comparison src/getname.c @ 4:aa38447a4b21
First entry of Paradise Server 2.9 patch 10 Beta
author | darius |
---|---|
date | Sat, 06 Dec 1997 04:37:03 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:cafa94d86546 | 4:aa38447a4b21 |
---|---|
1 /*-------------------------------------------------------------------------- | |
2 NETREK II -- Paradise | |
3 | |
4 Permission to use, copy, modify, and distribute this software and its | |
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL | |
6 purpose and without fee is hereby granted, provided that this copyright | |
7 notice appear in all copies. No representations are made about the | |
8 suitability of this software for any purpose. This software is provided | |
9 "as is" without express or implied warranty. | |
10 | |
11 Xtrek Copyright 1986 Chris Guthrie | |
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith | |
13 Scott Silvey | |
14 Paradise II (Netrek II) Copyright 1993 Larry Denys | |
15 Kurt Olsen | |
16 Brandon Gillespie | |
17 --------------------------------------------------------------------------*/ | |
18 | |
19 #include "config.h" | |
20 #include <stdio.h> | |
21 #include <sys/types.h> | |
22 #include <sys/stat.h> | |
23 #include <sys/file.h> | |
24 #include <sys/ipc.h> | |
25 #include <sys/shm.h> | |
26 #include <sys/time.h> | |
27 #ifndef ULTRIX | |
28 #include <sys/fcntl.h> | |
29 #endif | |
30 #include <errno.h> | |
31 #include <pwd.h> | |
32 #include <string.h> | |
33 #include <ctype.h> | |
34 #include <time.h> | |
35 #include "defs.h" | |
36 #include "struct.h" | |
37 #include "data.h" | |
38 #include "packets.h" | |
39 #include "path.h" | |
40 #include "shmem.h" | |
41 | |
42 #define crypt(a, b) (a) | |
43 | |
44 void handleLogin(); | |
45 extern int exitGame(); | |
46 extern int isClientDead(); | |
47 extern int socketPause(); | |
48 extern int readFromClient(); | |
49 int lockout(); | |
50 extern int sendClientLogin(); | |
51 extern int flushSockBuf(); | |
52 #ifdef BAD_SVR4_HACKS | |
53 int updateMOTD(); | |
54 #else | |
55 extern int updateMOTD(); | |
56 #endif | |
57 #ifndef IRIX | |
58 extern int printf(); | |
59 #endif | |
60 extern int read(); | |
61 extern int close(); | |
62 extern off_t lseek(); | |
63 extern int write(); | |
64 extern time_t time(); | |
65 | |
66 /* replace non-printable characters in string with spaces */ | |
67 static void | |
68 remove_ctl(str) | |
69 char *str; | |
70 { | |
71 while (*str) | |
72 { | |
73 if (!isgraph(*str)) /* not a printable character */ | |
74 *str = ' '; /* replace it with space */ | |
75 str++; | |
76 } | |
77 } | |
78 | |
79 void | |
80 getname() | |
81 /* Let person identify themselves from w */ | |
82 { | |
83 *(me->p_name) = 0; | |
84 while (*(me->p_name) == 0) | |
85 { | |
86 handleLogin(); | |
87 } | |
88 } | |
89 | |
90 void | |
91 handleLogin() | |
92 { | |
93 static struct statentry player; | |
94 static int position = -1; | |
95 int plfd; | |
96 int entries; | |
97 struct stat buf; | |
98 char *paths; | |
99 | |
100 paths = build_path(PLAYERFILE); | |
101 *namePick = '\0'; | |
102 inputMask = CP_LOGIN; | |
103 while (*namePick == '\0') | |
104 { | |
105 /* Been ghostbusted? */ | |
106 if (me->p_status == PFREE) | |
107 exitGame(); | |
108 if (isClientDead()) | |
109 exitGame(); | |
110 socketPause(); | |
111 readFromClient(); | |
112 } | |
113 #ifdef REMOVE_CTL /* untested */ | |
114 /* Change those annoying control characters to spaces */ | |
115 remove_ctl(namePick); | |
116 #endif | |
117 if ((strcmp(namePick, "Guest") == 0 || strcmp(namePick, "guest") == 0) && | |
118 !lockout()) | |
119 { | |
120 hourratio = 5; | |
121 memset(&player.stats, 0, sizeof(struct stats)); | |
122 player.stats.st_tticks = 1; | |
123 player.stats.st_flags = ST_INITIAL; | |
124 /* | |
125 * If this is a query on Guest, the client is screwed, but I'll send him | |
126 * some crud anyway. | |
127 */ | |
128 if (passPick[15] != 0) | |
129 { | |
130 sendClientLogin(&player.stats); | |
131 flushSockBuf(); | |
132 return; | |
133 } | |
134 sendClientLogin(&player.stats); | |
135 | |
136 updateMOTD(); /* added here 1/19/93 KAO */ | |
137 | |
138 flushSockBuf(); | |
139 strcpy(me->p_name, namePick); | |
140 me->p_pos = -1; | |
141 memcpy(&(me->p_stats), &player.stats, sizeof(struct stats)); | |
142 return; | |
143 } | |
144 hourratio = 1; | |
145 /* We look for the guy in the stat file */ | |
146 if (strcmp(player.name, namePick) != 0) | |
147 { | |
148 for (;;) | |
149 { /* so I can use break; */ | |
150 plfd = open(paths, O_RDONLY, 0644); | |
151 if (plfd < 0) | |
152 { | |
153 printf("I cannot open the player file!\n"); | |
154 strcpy(player.name, namePick); | |
155 position = -1; | |
156 printf("Error number: %d\n", errno); | |
157 break; | |
158 } | |
159 position = 0; | |
160 while (read(plfd, (char *) &player, sizeof(struct statentry)) == | |
161 sizeof(struct statentry)) | |
162 { | |
163 #ifdef REMOVE_CTL /* untested */ | |
164 /* | |
165 * this is a temporary thing to remove control chars from existing | |
166 * entries in the player db | |
167 */ | |
168 remove_ctl(player.name); | |
169 #endif | |
170 if (strcmp(namePick, player.name) == 0) | |
171 { | |
172 close(plfd); | |
173 break; | |
174 } | |
175 position++; | |
176 } | |
177 if (strcmp(namePick, player.name) == 0) | |
178 break; | |
179 close(plfd); | |
180 position = -1; | |
181 strcpy(player.name, namePick); | |
182 break; | |
183 } | |
184 } | |
185 /* Was this just a query? */ | |
186 if (passPick[15] != 0) | |
187 { | |
188 if (position == -1) | |
189 { | |
190 sendClientLogin(NULL); | |
191 } | |
192 else | |
193 { | |
194 sendClientLogin(&player.stats); | |
195 } | |
196 flushSockBuf(); | |
197 return; | |
198 } | |
199 /* A new guy? */ | |
200 if ((position == -1) && !lockout()) | |
201 { | |
202 strcpy(player.name, namePick); | |
203 strcpy(player.password, crypt(passPick, namePick)); | |
204 memset(&player.stats, 0, sizeof(struct stats)); | |
205 player.stats.st_tticks = 1; | |
206 player.stats.st_flags = ST_INITIAL; | |
207 player.stats.st_royal = 0; | |
208 plfd = open(paths, O_RDWR | O_CREAT, 0644); | |
209 if (plfd < 0) | |
210 { | |
211 sendClientLogin(NULL); | |
212 } | |
213 else | |
214 { | |
215 fstat(plfd, &buf); | |
216 entries = buf.st_size / sizeof(struct statentry); | |
217 lseek(plfd, entries * sizeof(struct statentry), 0); | |
218 write(plfd, (char *) &player, sizeof(struct statentry)); | |
219 close(plfd); | |
220 me->p_pos = entries; | |
221 memcpy(&(me->p_stats), &player.stats, sizeof(struct stats)); | |
222 strcpy(me->p_name, namePick); | |
223 sendClientLogin(&player.stats); | |
224 updateMOTD(); /* added here 1/19/93 KAO */ | |
225 } | |
226 flushSockBuf(); | |
227 return; | |
228 } | |
229 /* An actual login attempt */ | |
230 if ((strcmp(player.password, crypt(passPick, player.password)) != 0) || | |
231 lockout()) | |
232 { | |
233 sendClientLogin(NULL); | |
234 } | |
235 else | |
236 { | |
237 strcpy(me->p_name, namePick); | |
238 me->p_pos = position; | |
239 memcpy(&(me->p_stats), &player.stats, sizeof(struct stats)); | |
240 | |
241 sendClientLogin(&player.stats); | |
242 | |
243 updateMOTD(); /* st_flags&ST_NOBITMAPS */ | |
244 } | |
245 flushSockBuf(); | |
246 | |
247 #if 1 | |
248 /* Try to make the first person in the player database an Emperor */ | |
249 if (position == 0) | |
250 me->p_stats.st_royal = NUMROYALRANKS - 1; | |
251 #endif | |
252 | |
253 return; | |
254 } | |
255 | |
256 void | |
257 savestats() | |
258 { | |
259 int fd; | |
260 char *paths; | |
261 | |
262 if (me->p_pos < 0) | |
263 return; | |
264 | |
265 paths = build_path(PLAYERFILE); | |
266 | |
267 fd = open(paths, O_WRONLY, 0644); | |
268 if (fd >= 0) | |
269 { | |
270 me->p_stats.st_lastlogin = time(NULL); | |
271 lseek(fd, 32 + me->p_pos * sizeof(struct statentry), 0); | |
272 write(fd, (char *) &me->p_stats, sizeof(struct stats)); | |
273 close(fd); | |
274 } | |
275 } | |
276 | |
277 /* return true if we want a lockout */ | |
278 int | |
279 lockout() | |
280 { | |
281 return ( | |
282 /* | |
283 * (strncmp (login, "bozo", 4) == 0) || | |
284 */ | |
285 0 | |
286 ); | |
287 } |