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.120 by root, Thu Nov 15 06:00:16 2012 UTC vs.
Revision 1.124 by root, Sat Nov 17 06:41:16 2012 UTC

58 my $y = $ob->y; 58 my $y = $ob->y;
59 59
60 # never happens normally, but helps when shell users make mistakes 60 # never happens normally, but helps when shell users make mistakes
61 $m->linkable 61 $m->linkable
62 or return 1; 62 or return 1;
63
64# return 0;#d#
65# warn join ":", $m->at ($x, $y);#d#
66# warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n";
67# return 0;
68 63
69 scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y) 64 scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y)
70} 65}
71 66
72sub enter_map { 67sub enter_map {
248} 243}
249 244
250cf::client->attach (on_addme => sub { 245cf::client->attach (on_addme => sub {
251 my ($ns) = @_; 246 my ($ns) = @_;
252 247
253 $ns->pl and return $ns->destroy; 248 $ns->{addme}++ and return $ns->destroy;
254 249
255 $ns->async (sub { 250 $ns->async (sub {
256 $Coro::current->{desc} = "addme init"; 251 $Coro::current->{desc} = "addme init";
257 252
258 my ($user, $pass); 253 my ($user, $pass);
335 my $token = $pl->password; 330 my $token = $pl->password;
336 331
337 if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) { 332 if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) {
338 # player exists and passwords match - we can proceed 333 # player exists and passwords match - we can proceed
339 334
340 $pl->password (encode_password $pass); # make sure we store the new encoding #d#
341 # password matches, wonderful 335 # password matches, wonderful
342 my $pl = cf::player::find $user or next; 336 my $pl = cf::player::find $user or next;
343 $pl->connect ($ns); 337 $pl->connect ($ns);
344 enter_map $pl; 338 enter_map $pl;
345 login_done $pl; 339 login_done $pl;
409 chargen $ns, $user, $pass; 403 chargen $ns, $user, $pass;
410 login_done $ns->pl; 404 login_done $ns->pl;
411 }); 405 });
412}); 406});
413 407
408cf::client->attach (
409 on_version => sub {
410 my ($ns, $arg) = @_;
411
412 $ns->{nonces} = [map { join "", map { chr rand 256 } 0..63 } 1..2];
413 $ns->ext_msg (nonces => @{ $ns->{nonces} });
414 },
415);
416
417#cf::register_async_exticmd create_login => sub {
418# my ($ns, $reply, $user, $pass) = @_;
419#
420# $ns->{addme}++ and return $ns->destroy;
421#};
422
423cf::register_async_exticmd login => sub {
424 my ($ns, $reply, $user, $hash) = @_;
425
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 });
472};
473
414cf::register_command password => sub { 474cf::register_command password => sub {
415 my ($pl, $arg) = @_; 475 my ($pl, $arg) = @_;
416 476
417 unless ($pl->flag (cf::FLAG_WIZ)) { 477 unless ($pl->flag (cf::FLAG_WIZ)) {
418 $pl->message ( 478 $pl->message (
419 "The password can currently only changed by a DM.", 479 "The password can currently only changed by a DM.",
420 cf::NDI_UNIQUE | cf::NDI_REPLY); 480 cf::NDI_UNIQUE | cf::NDI_REPLY);
421 return; 481 return;
422 } 482 }
483
484 $pl->message (#d#
485 "Passwords cannot currently be changed.",#d#
486 cf::NDI_UNIQUE | cf::NDI_REPLY);#d#
487 return;#d#
423 488
424 my (@args) = split /\s+/, $arg; 489 my (@args) = split /\s+/, $arg;
425 my ($player, $new_pw) = @args; 490 my ($player, $new_pw) = @args;
426 491
427 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { 492 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines