… | |
… | |
3 | # login handling |
3 | # login handling |
4 | |
4 | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
7 | |
7 | |
8 | our $MAX_DISCONNECT_TIME = $cf::CFG{max_disconnect_time} || 3600; |
8 | CONF MAX_DISCONNECT_TIME = 3600; |
9 | |
|
|
10 | # paranoia function to overwrite a string-in-place |
|
|
11 | sub nuke_str { |
|
|
12 | substr $_[0], 0, (length $_[0]), "x" x length $_[0] |
|
|
13 | } |
|
|
14 | |
9 | |
15 | sub query { |
10 | sub query { |
16 | my ($ns, $flags, $text) = @_; |
11 | my ($ns, $flags, $text) = @_; |
17 | |
12 | |
18 | $ns->query ($flags, $text, Coro::rouse_cb); |
13 | $ns->query ($flags, $text, Coro::rouse_cb); |
… | |
… | |
60 | or return; |
55 | or return; |
61 | my $x = $ob->x; |
56 | my $x = $ob->x; |
62 | my $y = $ob->y; |
57 | my $y = $ob->y; |
63 | |
58 | |
64 | # never happens normally, but helps when shell users make mistakes |
59 | # never happens normally, but helps when shell users make mistakes |
65 | $m->in_memory == cf::MAP_ACTIVE |
60 | $m->linkable |
66 | or return 1; |
61 | or return 1; |
67 | |
62 | |
68 | # return 0;#d# |
63 | # return 0;#d# |
69 | # warn join ":", $m->at ($x, $y);#d# |
64 | # warn join ":", $m->at ($x, $y);#d# |
70 | # warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; |
65 | # warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; |
… | |
… | |
131 | |
126 | |
132 | $ob->goto ($map, $x, $y); |
127 | $ob->goto ($map, $x, $y); |
133 | } |
128 | } |
134 | |
129 | |
135 | sub encode_password($) { |
130 | sub encode_password($) { |
136 | # crypt $_[0], |
|
|
137 | # join '', |
|
|
138 | # ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)] |
|
|
139 | "!" . unpack "H*", $_[0] |
131 | "!" . unpack "H*", $_[0] |
140 | } |
132 | } |
141 | |
133 | |
142 | sub compare_password($$) { |
134 | sub compare_password($$) { |
143 | my ($pass, $token) = @_; |
135 | my ($pass, $token) = @_; |
144 | |
136 | |
145 | if ($token =~ /\!(.*)/) { |
137 | if ($token =~ /!!(.*)/) { |
|
|
138 | return +(substr $pass, 0, 8) eq pack "H*", $1; |
|
|
139 | } elsif ($token =~ /!(.*)/) { |
146 | return $pass eq pack "H*", $1; |
140 | return $pass eq pack "H*", $1; |
147 | } else { |
141 | } else { |
148 | return $token eq crypt $pass, $token; |
142 | return $token eq crypt $pass, $token; |
149 | } |
143 | } |
150 | } |
144 | } |
… | |
… | |
156 | my $lock = cf::lock_acquire "ext::login::nuke_playerdir"; |
150 | my $lock = cf::lock_acquire "ext::login::nuke_playerdir"; |
157 | |
151 | |
158 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
152 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
159 | aio_rename "$PLAYERDIR/$user", $temp; |
153 | aio_rename "$PLAYERDIR/$user", $temp; |
160 | IO::AIO::aio_rmtree $temp; |
154 | IO::AIO::aio_rmtree $temp; |
|
|
155 | } |
|
|
156 | |
|
|
157 | sub login_done { |
|
|
158 | my ($pl) = @_; |
|
|
159 | |
|
|
160 | if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) { |
|
|
161 | $pl->ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); |
|
|
162 | } |
|
|
163 | } |
|
|
164 | |
|
|
165 | sub chargen { |
|
|
166 | my ($ns, $user, $pass) = @_; |
|
|
167 | |
|
|
168 | # the rest of this function is character creation |
|
|
169 | $Coro::current->{desc} = "addme($user) chargen"; |
|
|
170 | |
|
|
171 | # just to make sure nothing is left over |
|
|
172 | # normally, nothing is there. |
|
|
173 | nuke_playerdir $user; |
|
|
174 | |
|
|
175 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
|
|
176 | |
|
|
177 | if ($pass2 ne $pass) { |
|
|
178 | $ns->send_drawinfo ( |
|
|
179 | "The passwords do not match, please try again.", |
|
|
180 | cf::NDI_RED |
|
|
181 | ); |
|
|
182 | Coro::Timer::sleep 0.5; |
|
|
183 | next; |
|
|
184 | } |
|
|
185 | |
|
|
186 | my $pl = cf::player::new $user; |
|
|
187 | $pl->password (encode_password $pass); |
|
|
188 | $pl->connect ($ns); |
|
|
189 | my $ob = $pl->ob; |
|
|
190 | |
|
|
191 | $ob->goto ($pl->maplevel, $ob->x, $ob->y); |
|
|
192 | |
|
|
193 | while () { |
|
|
194 | $ob->update_stats; |
|
|
195 | $pl->save_stats; |
|
|
196 | |
|
|
197 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
198 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)?"; |
|
|
199 | |
|
|
200 | if ($res =~ /^[Nn]/) { |
|
|
201 | last; |
|
|
202 | } elsif ($res > 0 && $res <= 7) { |
|
|
203 | my $swap = query $ns, cf::CS_QUERY_SINGLECHAR, "Swap stat with (will not roll new stats) [1-7]?"; |
|
|
204 | |
|
|
205 | if ($swap > 0 && $swap <= 7) { |
|
|
206 | $ob->swap_stats ($res - 1, $swap - 1); |
|
|
207 | } |
|
|
208 | } else { |
|
|
209 | $ob->roll_stats; |
|
|
210 | } |
|
|
211 | |
|
|
212 | Coro::Timer::sleep 0.05; |
|
|
213 | } |
|
|
214 | |
|
|
215 | $ob->set_animation (2); |
|
|
216 | $ob->add_statbonus; |
|
|
217 | |
|
|
218 | while () { |
|
|
219 | $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1); |
|
|
220 | my $msg = $ob->msg; |
|
|
221 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
|
|
222 | $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE); |
|
|
223 | |
|
|
224 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
225 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; |
|
|
226 | |
|
|
227 | last if $res =~ /[dD]/; |
|
|
228 | |
|
|
229 | $pl->chargen_race_next; |
|
|
230 | Coro::Timer::sleep 0.05; |
|
|
231 | } |
|
|
232 | |
|
|
233 | # create the playerdir, if necessary, as chargen_race_done did it before |
|
|
234 | # presumably because of unique maps |
|
|
235 | aio_mkdir playerdir $pl, 0770; |
|
|
236 | $pl->chargen_race_done; |
|
|
237 | |
|
|
238 | while () { |
|
|
239 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
240 | "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n"; |
|
|
241 | |
|
|
242 | if ($res =~ /^[fF]/) { |
|
|
243 | $pl->gender (1); |
|
|
244 | last; |
|
|
245 | } elsif ($res =~ /^[mM]/) { |
|
|
246 | $pl->gender (0); |
|
|
247 | last; |
|
|
248 | } |
|
|
249 | Coro::Timer::sleep 0.05; |
|
|
250 | } |
|
|
251 | |
|
|
252 | $ob->reply (undef, "Welcome to Deliantra!"); |
|
|
253 | |
|
|
254 | # XXX: Workaround for delayed client ext protocol handshake |
|
|
255 | $pl->esrv_new_player; |
|
|
256 | |
|
|
257 | delete $pl->{deny_save}; |
161 | } |
258 | } |
162 | |
259 | |
163 | cf::client->attach (on_addme => sub { |
260 | cf::client->attach (on_addme => sub { |
164 | my ($ns) = @_; |
261 | my ($ns) = @_; |
165 | |
262 | |
… | |
… | |
246 | aio_stat $pl->path and next; |
343 | aio_stat $pl->path and next; |
247 | my $mtime = (stat _)[9]; |
344 | my $mtime = (stat _)[9]; |
248 | my $token = $pl->password; |
345 | my $token = $pl->password; |
249 | |
346 | |
250 | if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) { |
347 | if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) { |
|
|
348 | # player exists and passwords match - we can proceed |
|
|
349 | |
251 | $pl->password (encode_password $pass); # make sure we store the new encoding #d# |
350 | $pl->password (encode_password $pass); # make sure we store the new encoding #d# |
252 | nuke_str $pass; |
|
|
253 | # password matches, wonderful |
351 | # password matches, wonderful |
254 | my $pl = cf::player::find $user or next; |
352 | my $pl = cf::player::find $user or next; |
255 | $pl->connect ($ns); |
353 | $pl->connect ($ns); |
256 | enter_map $pl; |
354 | enter_map $pl; |
|
|
355 | login_done $pl; |
257 | last; |
356 | return; |
258 | } elsif (can_cleanup $pl, $mtime) { |
357 | } elsif (can_cleanup $pl, $mtime) { |
259 | Coro::Timer::sleep 1; |
358 | Coro::Timer::sleep 1; |
260 | |
359 | |
261 | $ns->send_drawinfo ( |
360 | $ns->send_drawinfo ( |
262 | "Player exists, but password does not match. If this is your account, " |
361 | "Player exists, but password does not match. If this is your account, " |
263 | . "please try again. If not, you can now decide to take over this account " |
362 | . "please try again. If not, you can now decide to take over this account " |
264 | . "because it has not been in-use for some time.", |
363 | . "because it has not been in-use for some time.", |
265 | cf::NDI_RED |
364 | cf::NDI_RED |
266 | ); |
365 | ); |
267 | |
366 | |
268 | #TODO: nuke_str |
|
|
269 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
367 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
270 | or next; |
368 | or next; |
271 | |
369 | |
272 | # check if the file hasn't changed |
370 | # check if the file hasn't changed |
273 | aio_stat cf::player::path $user and next; |
371 | aio_stat cf::player::path $user and next; |
… | |
… | |
275 | |
373 | |
276 | $pl->quit_character; |
374 | $pl->quit_character; |
277 | |
375 | |
278 | # fall through to creation |
376 | # fall through to creation |
279 | } else { |
377 | } else { |
280 | nuke_str $pass; |
|
|
281 | |
|
|
282 | Coro::Timer::sleep 1; |
378 | Coro::Timer::sleep 1; |
283 | |
379 | |
284 | $ns->send_drawinfo ( |
380 | $ns->send_drawinfo ( |
285 | "Wrong username or password. Please try again " |
381 | "Wrong username or password. Please try again " |
286 | . "(check for Numlock and other semi-obvious error sources).", |
382 | . "(check for Numlock and other semi-obvious error sources).", |
… | |
… | |
301 | ); |
397 | ); |
302 | next; |
398 | next; |
303 | } |
399 | } |
304 | } |
400 | } |
305 | |
401 | |
306 | # the rest of this function is character creation |
|
|
307 | $Coro::current->{desc} = "addme($user) chargen"; |
|
|
308 | |
|
|
309 | # just to make sure nothing is left over |
|
|
310 | # normally, nothing is there. |
|
|
311 | nuke_playerdir $user; |
|
|
312 | |
|
|
313 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
|
|
314 | |
|
|
315 | if ($pass2 ne $pass) { |
|
|
316 | nuke_str $pass; |
|
|
317 | nuke_str $pass2; |
|
|
318 | $ns->send_drawinfo ( |
|
|
319 | "The passwords do not match, please try again.", |
|
|
320 | cf::NDI_RED |
|
|
321 | ); |
|
|
322 | Coro::Timer::sleep 0.5; |
|
|
323 | next; |
|
|
324 | } |
|
|
325 | |
|
|
326 | nuke_str $pass2; |
|
|
327 | |
|
|
328 | my $pl = cf::player::new $user; |
|
|
329 | $pl->password (encode_password $pass); |
|
|
330 | nuke_str $pass; |
|
|
331 | $pl->connect ($ns); |
|
|
332 | my $ob = $pl->ob; |
|
|
333 | |
|
|
334 | $ob->goto ($pl->maplevel, $ob->x, $ob->y); |
|
|
335 | |
|
|
336 | while () { |
|
|
337 | $ob->update_stats; |
|
|
338 | $pl->save_stats; |
|
|
339 | |
|
|
340 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
341 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)?"; |
|
|
342 | |
|
|
343 | if ($res =~ /^[Nn]/) { |
|
|
344 | last; |
|
|
345 | } elsif ($res > 0 && $res <= 7) { |
|
|
346 | my $swap = query $ns, cf::CS_QUERY_SINGLECHAR, "Swap stat with (will not roll new stats) [1-7]?"; |
|
|
347 | |
|
|
348 | if ($swap > 0 && $swap <= 7) { |
|
|
349 | $ob->swap_stats ($res - 1, $swap - 1); |
|
|
350 | } |
|
|
351 | } else { |
|
|
352 | $ob->roll_stats; |
|
|
353 | } |
|
|
354 | |
|
|
355 | Coro::Timer::sleep 0.05; |
|
|
356 | } |
|
|
357 | |
|
|
358 | $ob->set_animation (2); |
|
|
359 | $ob->add_statbonus; |
|
|
360 | |
|
|
361 | while () { |
|
|
362 | $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1); |
|
|
363 | my $msg = $ob->msg; |
|
|
364 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
|
|
365 | $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE); |
|
|
366 | |
|
|
367 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
368 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; |
|
|
369 | |
|
|
370 | last if $res =~ /[dD]/; |
|
|
371 | |
|
|
372 | $pl->chargen_race_next; |
|
|
373 | Coro::Timer::sleep 0.05; |
|
|
374 | } |
|
|
375 | |
|
|
376 | # create the playerdir, if necessary, as chargen_race_done did it before |
|
|
377 | # presumably because of unique maps |
|
|
378 | aio_mkdir playerdir $pl, 0770; |
|
|
379 | $pl->chargen_race_done; |
|
|
380 | |
|
|
381 | while () { |
|
|
382 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
383 | "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n"; |
|
|
384 | |
|
|
385 | if ($res =~ /^[fF]/) { |
|
|
386 | $pl->gender (1); |
|
|
387 | last; |
|
|
388 | } elsif ($res =~ /^[mM]/) { |
|
|
389 | $pl->gender (0); |
|
|
390 | last; |
|
|
391 | } |
|
|
392 | Coro::Timer::sleep 0.05; |
|
|
393 | } |
|
|
394 | |
|
|
395 | $ob->reply (undef, "Welcome to Deliantra!"); |
|
|
396 | |
|
|
397 | # XXX: Workaround for delayed client ext protocol handshake |
|
|
398 | $pl->esrv_new_player; |
|
|
399 | |
|
|
400 | delete $pl->{deny_save}; |
|
|
401 | |
|
|
402 | last; |
402 | last; |
403 | } |
403 | } |
404 | |
404 | |
405 | if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) { |
405 | # lock again, too layz to make this nicer |
406 | $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); |
406 | local $cf::LOGIN_LOCK{$user} = 1; |
407 | } |
407 | chargen $ns, $user, $pass; |
|
|
408 | login_done $ns->pl; |
408 | }); |
409 | }); |
409 | }); |
410 | }); |
410 | |
411 | |
411 | cf::register_command password => sub { |
412 | cf::register_command password => sub { |
412 | my ($pl, $arg) = @_; |
413 | my ($pl, $arg) = @_; |