… | |
… | |
2 | |
2 | |
3 | # login handling |
3 | # login handling |
4 | |
4 | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
|
|
7 | use Deliantra::Util (); |
7 | |
8 | |
8 | CONF MAX_DISCONNECT_TIME = 3600; |
9 | CONF MAX_DISCONNECT_TIME = 3600; |
9 | |
10 | |
10 | sub query { |
11 | sub query { |
11 | my ($ns, $flags, $text) = @_; |
12 | my ($ns, $flags, $text) = @_; |
… | |
… | |
57 | my $y = $ob->y; |
58 | my $y = $ob->y; |
58 | |
59 | |
59 | # never happens normally, but helps when shell users make mistakes |
60 | # never happens normally, but helps when shell users make mistakes |
60 | $m->linkable |
61 | $m->linkable |
61 | or return 1; |
62 | or return 1; |
62 | |
|
|
63 | # return 0;#d# |
|
|
64 | # warn join ":", $m->at ($x, $y);#d# |
|
|
65 | # warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; |
|
|
66 | # return 0; |
|
|
67 | |
63 | |
68 | scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y) |
64 | scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y) |
69 | } |
65 | } |
70 | |
66 | |
71 | sub enter_map { |
67 | sub enter_map { |
… | |
… | |
169 | $Coro::current->{desc} = "addme($user) chargen"; |
165 | $Coro::current->{desc} = "addme($user) chargen"; |
170 | |
166 | |
171 | # just to make sure nothing is left over |
167 | # just to make sure nothing is left over |
172 | # normally, nothing is there. |
168 | # normally, nothing is there. |
173 | nuke_playerdir $user; |
169 | 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 | |
170 | |
186 | my $pl = cf::player::new $user; |
171 | my $pl = cf::player::new $user; |
187 | $pl->password (encode_password $pass); |
172 | $pl->password (encode_password $pass); |
188 | $pl->connect ($ns); |
173 | $pl->connect ($ns); |
189 | my $ob = $pl->ob; |
174 | my $ob = $pl->ob; |
… | |
… | |
345 | my $token = $pl->password; |
330 | my $token = $pl->password; |
346 | |
331 | |
347 | if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) { |
332 | if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) { |
348 | # player exists and passwords match - we can proceed |
333 | # player exists and passwords match - we can proceed |
349 | |
334 | |
350 | $pl->password (encode_password $pass); # make sure we store the new encoding #d# |
|
|
351 | # password matches, wonderful |
335 | # password matches, wonderful |
352 | my $pl = cf::player::find $user or next; |
336 | my $pl = cf::player::find $user or next; |
353 | $pl->connect ($ns); |
337 | $pl->connect ($ns); |
354 | enter_map $pl; |
338 | enter_map $pl; |
355 | login_done $pl; |
339 | login_done $pl; |
… | |
… | |
397 | ); |
381 | ); |
398 | next; |
382 | next; |
399 | } |
383 | } |
400 | } |
384 | } |
401 | |
385 | |
|
|
386 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
|
|
387 | |
|
|
388 | if ($pass2 ne $pass) { |
|
|
389 | $ns->send_drawinfo ( |
|
|
390 | "The passwords do not match, please try again.", |
|
|
391 | cf::NDI_RED |
|
|
392 | ); |
|
|
393 | Coro::Timer::sleep 0.5; |
|
|
394 | next; |
|
|
395 | } |
|
|
396 | |
402 | last; |
397 | last; |
403 | } |
398 | } |
404 | |
399 | |
405 | # lock again, too layz to make this nicer |
400 | # lock again, too layz to make this nicer |
406 | local $cf::LOGIN_LOCK{$user} = 1; |
401 | local $cf::LOGIN_LOCK{$user} = 1; |
|
|
402 | |
407 | chargen $ns, $user, $pass; |
403 | chargen $ns, $user, $pass; |
408 | login_done $ns->pl; |
404 | login_done $ns->pl; |
409 | }); |
405 | }); |
410 | }); |
406 | }); |
|
|
407 | |
|
|
408 | cf::client->attach ( |
|
|
409 | on_version => sub { |
|
|
410 | my ($ns, $arg) = @_; |
|
|
411 | |
|
|
412 | $ns->ext_msg (nonces => map { join "", map { chr rand 256 } 0..63 } 1..2); |
|
|
413 | }, |
|
|
414 | ); |
|
|
415 | |
|
|
416 | #cf::register_async_exticmd create_login => sub { |
|
|
417 | # my ($ns, $reply, $user, $pass) = @_; |
|
|
418 | # |
|
|
419 | # $ns->pl and return $ns->destroy; |
|
|
420 | #}; |
|
|
421 | |
|
|
422 | cf::register_async_exticmd login => sub { |
|
|
423 | my ($ns, $reply, $user, $hash) = @_; |
|
|
424 | |
|
|
425 | $ns->pl and return $ns->destroy; |
|
|
426 | }; |
411 | |
427 | |
412 | cf::register_command password => sub { |
428 | cf::register_command password => sub { |
413 | my ($pl, $arg) = @_; |
429 | my ($pl, $arg) = @_; |
414 | |
430 | |
415 | unless ($pl->flag (cf::FLAG_WIZ)) { |
431 | unless ($pl->flag (cf::FLAG_WIZ)) { |