--- deliantra/server/ext/login.ext 2010/04/11 21:26:36 1.103 +++ deliantra/server/ext/login.ext 2010/04/29 10:08:26 1.108 @@ -89,7 +89,7 @@ # the map was reset in the meantime my $age = $cf::RUNTIME - $time; - warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# + cf::info $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# if ($age >= $MAX_DISCONNECT_TIME) { $ob->message ( @@ -128,6 +128,12 @@ $ob->goto ($map, $x, $y); } +sub encode_password { + crypt $_[0], + join '', + ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)] +} + # delete a player directory, be non-blocking AND synchronous... # (that's hard, so we crap out and fork). sub nuke_playerdir { @@ -305,7 +311,7 @@ nuke_str $pass2; my $pl = cf::player::new $user; - $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); + $pl->password (encode_password $pass); nuke_str $pass; $pl->connect ($ns); my $ob = $pl->ob; @@ -387,6 +393,72 @@ }); }); +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]; + } + + 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 ($change && (time - $change->[0]) < 60) { + $pl->message ( + "Ok, changed your password!", + 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!", + cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); + $pl->{password_change} = [time, $new_pw]; + } + } +}; + cf::register_command quit => sub { my ($ob, $arg) = @_; @@ -407,7 +479,10 @@ } 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 { $pl->quit_character }; + cf::async { + ext::highscore::check $pl->ob; + $pl->quit_character; + }; } }); };