--- deliantra/server/ext/login.ext 2010/05/04 21:45:42 1.109 +++ deliantra/server/ext/login.ext 2011/05/04 07:36:40 1.116 @@ -61,6 +61,10 @@ my $x = $ob->x; my $y = $ob->y; + # never happens normally, but helps when shell users make mistakes + $m->linkable + or return 1; + # return 0;#d# # warn join ":", $m->at ($x, $y);#d# # warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; @@ -128,23 +132,32 @@ $ob->goto ($map, $x, $y); } -sub encode_password { - crypt $_[0], - join '', - ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)] +sub encode_password($) { +# crypt $_[0], +# join '', +# ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)] + "!" . unpack "H*", $_[0] +} + +sub compare_password($$) { + my ($pass, $token) = @_; + + if ($token =~ /\!(.*)/) { + return $pass eq pack "H*", $1; + } else { + return $token eq crypt $pass, $token; + } } -# delete a player directory, be non-blocking AND synchronous... -# (that's hard, so we crap out and fork). +# delete a player directory sub nuke_playerdir { my ($user) = @_; - my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; + my $lock = cf::lock_acquire "ext::login::nuke_playerdir"; - cf::fork_call { - rename "$PLAYERDIR/$user", $temp; - system "rm", "-rf", $temp; - }; + my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; + aio_rename "$PLAYERDIR/$user", $temp; + IO::AIO::aio_rmtree $temp; } cf::client->attach (on_addme => sub { @@ -232,9 +245,10 @@ if (my $pl = cf::player::find $user) { aio_stat $pl->path and next; my $mtime = (stat _)[9]; - my $hash = $pl->password; + my $token = $pl->password; - if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { + if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) { + $pl->password (encode_password $pass); # make sure we store the new encoding #d# nuke_str $pass; # password matches, wonderful my $pl = cf::player::find $user or next; @@ -276,7 +290,7 @@ } } else { # unable to load the playerfile: - # check wether the player dir exists, which means the file is corrupted or + # check whether the player dir exists, which means the file is corrupted or # something very similar. if (!aio_stat cf::player::playerdir $user) { $ns->send_drawinfo ( @@ -293,6 +307,7 @@ $Coro::current->{desc} = "addme($user) chargen"; # just to make sure nothing is left over + # normally, nothing is there. nuke_playerdir $user; my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; @@ -396,67 +411,44 @@ cf::register_command password => sub { my ($pl, $arg) = @_; - my (@args) = split /\s+/, $arg; - - my ($new_pw, $player); - - if ($pl->flag (cf::FLAG_WIZ)) { - ($player, $new_pw) = @args; - } else { - $new_pw = $args[0]; + unless ($pl->flag (cf::FLAG_WIZ)) { + $pl->message ( + "The password can currently only changed by a DM.", + cf::NDI_UNIQUE | cf::NDI_REPLY); + return; } + my (@args) = split /\s+/, $arg; + my ($player, $new_pw) = @args; + if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { $pl->message ( "Usage: password []", cf::NDI_UNIQUE | cf::NDI_REPLY); return; - } elsif (!$pl->flag (cf::FLAG_WIZ) && $new_pw eq '') { - $pl->message ( - "Usage: password ", - cf::NDI_UNIQUE | cf::NDI_REPLY); - return; } - if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) { - unless ($new_pw ne '') { - $new_pw = - join '', - map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } - 1..9; - } - - cf::async { - my $plc = cf::player::find $player; - if ($plc) { - $plc->password (encode_password $new_pw); - $pl->message ( - "Ok, changed password of '$player' to '$new_pw'!", - cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); - } else { - $pl->message ( - "Fail! Couldn't set password for '$player', " - . "he doesn't seem to exist!", - cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); - } - }; - } else { - my $change = delete $pl->{password_change}; + if ($new_pw eq '') { + $new_pw = + join '', + map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } + 1..9; + } - if ($change && (time - $change->[0]) < 60) { + cf::async { + my $plc = cf::player::find $player; + if ($plc) { + $plc->password (encode_password $new_pw); $pl->message ( - "Ok, changed your password!", + "Ok, changed password of '$player' to '$new_pw'!", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); - $pl->contr->password (encode_password $new_pw); - } else { $pl->message ( - "Ok, please confirm your new password by sending " - . "the command again within one minute!", + "Fail! Couldn't set password for '$player', " + . "he doesn't seem to exist!", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); - $pl->{password_change} = [time, $new_pw]; } - } + }; }; cf::register_command quit => sub { @@ -478,9 +470,7 @@ $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); } else { $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); - $pl->ns->flush; cf::async { - ext::highscore::check $pl->ob; $pl->quit_character; }; } @@ -498,22 +488,26 @@ # update respawn position $pl->savebed ($bed->map->path, $bed->x, $bed->y); - cf::async { $pl->save }; - my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; - ext::highscore::check $ob; + cf::async { + my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; + ext::highscore::check $ob; - $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); + $pl->save; - $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { - if ($_[0] !~ /^[yY]/) { - $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); - $pl->deactivate; - $pl->ns->destroy; - } else { - cf::async { $pl->save }; - } - }); + $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); + + my $ns = $pl->ns + or return; + + $ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { + if ($_[0] !~ /^[yY]/) { + $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); + $pl->deactivate; + $pl->ns->destroy; + } + }); + }; }, );