ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/login.ext
(Generate patch)

Comparing deliantra/server/ext/login.ext (file contents):
Revision 1.122 by root, Thu Nov 15 07:08:15 2012 UTC vs.
Revision 1.123 by root, Fri Nov 16 12:02:46 2012 UTC

243} 243}
244 244
245cf::client->attach (on_addme => sub { 245cf::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
408cf::client->attach ( 408cf::client->attach (
409 on_version => sub { 409 on_version => sub {
410 my ($ns, $arg) = @_; 410 my ($ns, $arg) = @_;
411 411
412 srand 1;#d#
412 $ns->ext_msg (nonces => map { join "", map { chr rand 256 } 0..63 } 1..2); 413 $ns->{nonces} = [map { join "", map { chr rand 256 } 0..63 } 1..2];
414 $ns->ext_msg (nonces => @{ $ns->{nonces} });
413 }, 415 },
414); 416);
415 417
416#cf::register_async_exticmd create_login => sub { 418#cf::register_async_exticmd create_login => sub {
417# my ($ns, $reply, $user, $pass) = @_; 419# my ($ns, $reply, $user, $pass) = @_;
418# 420#
419# $ns->pl and return $ns->destroy; 421# $ns->{addme}++ and return $ns->destroy;
420#}; 422#};
421 423
422cf::register_async_exticmd login => sub { 424cf::register_async_exticmd login => sub {
423 my ($ns, $reply, $user, $hash) = @_; 425 my ($ns, $reply, $user, $hash) = @_;
424 426
425 $ns->pl and return $ns->destroy; 427 $ns->{addme}++ and return $ns->destroy;
428
429 $ns->async (sub {
430 local $cf::LOGIN_LOCK{$user} = 1;
431
432 $Coro::current->{desc} = "login($user) check";
433
434 my $fail = sub {
435 $reply->(0, $_[0]);
436 $ns->flush; # does not ensure that the data reaches the client - TODO
437 # need to do this in another thread, as this one gets canceled
438 Coro::async_pool {
439 Coro::AnyEvent::sleep 0.1; # TODO, see above, extra hack
440 $ns->destroy;
441 };
442 Coro::schedule; # do the destroy, should not return
443 };
444
445 # try to read the user file and check the password
446 my $pl = cf::player::find $user
447 or return $fail->("User '$user' does not exist - wrong spelling?");
448
449 aio_stat $pl->path
450 and return $ns->destroy;
451
452 my $mtime = (stat _)[9];
453 my $token = $pl->password;
454
455 $token = $token =~ /^!/
456 ? Deliantra::Util::hash_pw pack "H*", substr $token, 1
457 : pack "H*", $token;
458
459 $token = Deliantra::Util::auth_pw $token, $ns->{nonces}[0], $ns->{nonces}[1];
460
461 $token eq $hash
462 or $cf::CFG{ext_login_nocheck}
463 or return $fail->("User exists, but the password doesn't match - check your spelling, NumLock/CapsLock etc.");
464
465 # player exists and passwords match - we can proceed
466
467 $pl->connect ($ns);
468 enter_map $pl;
469 login_done $pl;
470
471 $reply->(1, "Success");
472 });
426}; 473};
427 474
428cf::register_command password => sub { 475cf::register_command password => sub {
429 my ($pl, $arg) = @_; 476 my ($pl, $arg) = @_;
430 477

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines