--- deliantra/server/ext/login.ext 2009/06/28 16:46:50 1.98 +++ deliantra/server/ext/login.ext 2010/05/04 21:45:42 1.109 @@ -1,4 +1,4 @@ -#! perl # mandatory +#! perl # mandatory depends=highscore # login handling @@ -72,7 +72,6 @@ sub enter_map { my ($pl) = @_; - warn $pl->ob->name, ": enter map 1\n";#d# my $ob = $pl->ob; my ($map, $x, $y) @@ -80,20 +79,17 @@ ? @{delete $ob->{_link_pos}} : ($pl->maplevel, $ob->x, $ob->y); - warn $pl->ob->name, ": enter map 2\n";#d# $ob->enter_link; - warn $pl->ob->name, ": enter map 3\n";#d# my $m = cf::map::find $map; my $time = delete $pl->{unclean_save}; - warn $pl->ob->name, ": enter map 4\n";#d# if ($time && $m) { if ($time < $m->{instantiate_time}) { # 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 ( @@ -129,16 +125,13 @@ } } - warn $pl->ob->name, ": enter map 5\n";#d# - #$ob->goto ($map, $x, $y); - $ob->goto ($map, $x, $y, sub { - warn $pl->ob->name, ": enter map check\n";#d# - $_[0] - }, sub { - warn $pl->ob->name, ": enter map done\n";#d# - }); - warn $pl->ob->name, ": enter map 6\n";#d# + $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... @@ -246,8 +239,6 @@ # password matches, wonderful my $pl = cf::player::find $user or next; $pl->connect ($ns); - $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp - #d# Coro::Timer::sleep 60;#d# log out here to trigger DEBUG bug enter_map $pl; last; } elsif (can_cleanup $pl, $mtime) { @@ -320,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; @@ -364,7 +355,7 @@ last if $res =~ /[dD]/; $pl->chargen_race_next; - Coro::Timer::sleep 0.2; + Coro::Timer::sleep 0.05; } # create the playerdir, if necessary, as chargen_race_done did it before @@ -383,7 +374,7 @@ $pl->gender (0); last; } - Coro::Timer::sleep 0.2; + Coro::Timer::sleep 0.05; } $ob->reply (undef, "Welcome to Deliantra!"); @@ -395,9 +386,79 @@ last; } + + if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) { + $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); + } }); }); +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) = @_; @@ -418,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; + }; } }); }; @@ -437,7 +501,7 @@ cf::async { $pl->save }; my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; - $ob->check_score; + 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); @@ -474,4 +538,3 @@ }, ); -