… | |
… | |
243 | } |
243 | } |
244 | |
244 | |
245 | cf::client->attach (on_addme => sub { |
245 | cf::client->attach (on_addme => sub { |
246 | my ($ns) = @_; |
246 | my ($ns) = @_; |
247 | |
247 | |
248 | $ns->pl and return $ns->destroy; |
248 | $ns->{addme}++ and return $ns->destroy; |
249 | |
249 | |
250 | $ns->async (sub { |
250 | $ns->async (sub { |
251 | $Coro::current->{desc} = "addme init"; |
251 | $Coro::current->{desc} = "addme init"; |
252 | |
252 | |
253 | my ($user, $pass); |
253 | my ($user, $pass); |
… | |
… | |
407 | |
407 | |
408 | cf::client->attach ( |
408 | cf::client->attach ( |
409 | on_version => sub { |
409 | on_version => sub { |
410 | my ($ns, $arg) = @_; |
410 | my ($ns, $arg) = @_; |
411 | |
411 | |
412 | $ns->ext_msg (nonces => map { join "", map { chr rand 256 } 0..63 } 1..2); |
412 | $ns->{nonces} = [map { join "", map { chr rand 256 } 0..63 } 1..2]; |
|
|
413 | $ns->ext_msg (nonces => @{ $ns->{nonces} }); |
413 | }, |
414 | }, |
414 | ); |
415 | ); |
415 | |
416 | |
416 | #cf::register_async_exticmd create_login => sub { |
417 | #cf::register_async_exticmd create_login => sub { |
417 | # my ($ns, $reply, $user, $pass) = @_; |
418 | # my ($ns, $reply, $user, $pass) = @_; |
418 | # |
419 | # |
419 | # $ns->pl and return $ns->destroy; |
420 | # $ns->{addme}++ and return $ns->destroy; |
420 | #}; |
421 | #}; |
421 | |
422 | |
422 | cf::register_async_exticmd login => sub { |
423 | cf::register_async_exticmd login => sub { |
423 | my ($ns, $reply, $user, $hash) = @_; |
424 | my ($ns, $reply, $user, $hash) = @_; |
424 | |
425 | |
425 | $ns->pl and return $ns->destroy; |
426 | $ns->{addme}++ and return $ns->destroy; |
|
|
427 | |
|
|
428 | $ns->async (sub { |
|
|
429 | local $cf::LOGIN_LOCK{$user} = 1; |
|
|
430 | |
|
|
431 | $Coro::current->{desc} = "login($user) check"; |
|
|
432 | |
|
|
433 | my $fail = sub { |
|
|
434 | $reply->(0, $_[0]); |
|
|
435 | $ns->flush; # does not ensure that the data reaches the client - TODO |
|
|
436 | # need to do this in another thread, as this one gets canceled |
|
|
437 | Coro::async_pool { |
|
|
438 | Coro::AnyEvent::sleep 0.1; # TODO, see above, extra hack |
|
|
439 | $ns->destroy; |
|
|
440 | }; |
|
|
441 | Coro::schedule; # do the destroy, should not return |
|
|
442 | }; |
|
|
443 | |
|
|
444 | # try to read the user file and check the password |
|
|
445 | my $pl = cf::player::find $user |
|
|
446 | or return $fail->("User '$user' does not exist - wrong spelling?"); |
|
|
447 | |
|
|
448 | aio_stat $pl->path |
|
|
449 | and return $ns->destroy; |
|
|
450 | |
|
|
451 | my $mtime = (stat _)[9]; |
|
|
452 | my $token = $pl->password; |
|
|
453 | |
|
|
454 | $token = $token =~ /^!/ |
|
|
455 | ? Deliantra::Util::hash_pw pack "H*", substr $token, 1 |
|
|
456 | : pack "H*", $token; |
|
|
457 | |
|
|
458 | $token = Deliantra::Util::auth_pw $token, $ns->{nonces}[0], $ns->{nonces}[1]; |
|
|
459 | |
|
|
460 | $token eq $hash |
|
|
461 | or $cf::CFG{ext_login_nocheck} |
|
|
462 | or return $fail->("User exists, but the password doesn't match - check your spelling, NumLock/CapsLock etc."); |
|
|
463 | |
|
|
464 | # player exists and passwords match - we can proceed |
|
|
465 | |
|
|
466 | $pl->connect ($ns); |
|
|
467 | enter_map $pl; |
|
|
468 | login_done $pl; |
|
|
469 | |
|
|
470 | $reply->(1, "Success"); |
|
|
471 | }); |
426 | }; |
472 | }; |
427 | |
473 | |
428 | cf::register_command password => sub { |
474 | cf::register_command password => sub { |
429 | my ($pl, $arg) = @_; |
475 | my ($pl, $arg) = @_; |
430 | |
476 | |
… | |
… | |
432 | $pl->message ( |
478 | $pl->message ( |
433 | "The password can currently only changed by a DM.", |
479 | "The password can currently only changed by a DM.", |
434 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
480 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
435 | return; |
481 | return; |
436 | } |
482 | } |
|
|
483 | |
|
|
484 | $pl->message (#d# |
|
|
485 | "Passwords cannot currently be changed.",#d# |
|
|
486 | cf::NDI_UNIQUE | cf::NDI_REPLY);#d# |
|
|
487 | return;#d# |
437 | |
488 | |
438 | my (@args) = split /\s+/, $arg; |
489 | my (@args) = split /\s+/, $arg; |
439 | my ($player, $new_pw) = @args; |
490 | my ($player, $new_pw) = @args; |
440 | |
491 | |
441 | if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { |
492 | if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { |