--- deliantra/server/ext/login.ext 2008/09/22 01:33:09 1.92 +++ deliantra/server/ext/login.ext 2012/11/08 00:16:07 1.118 @@ -1,11 +1,11 @@ -#! perl # mandatory +#! perl # mandatory depends=highscore # login handling use Fcntl; use Coro::AIO; -our $MAX_DISCONNECT_TIME = $cf::CFG{max_disconnect_time} || 3600; +CONF MAX_DISCONNECT_TIME = 3600; # paranoia function to overwrite a string-in-place sub nuke_str { @@ -15,11 +15,8 @@ sub query { my ($ns, $flags, $text) = @_; - my $current = $Coro::current; - $ns->query ($flags, $text, sub { $current->ready; $current = $_[0] }); - Coro::schedule while ref $current; - - $current + $ns->query ($flags, $text, Coro::rouse_cb); + Coro::rouse_wait } sub can_cleanup { @@ -64,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"; @@ -75,7 +76,6 @@ sub enter_map { my ($pl) = @_; - warn $pl->ob->name, ": enter map 1\n";#d# my $ob = $pl->ob; my ($map, $x, $y) @@ -83,20 +83,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 ( @@ -132,79 +129,42 @@ } } - 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)] + "!" . unpack "H*", $_[0] +} +sub compare_password($$) { + my ($pass, $token) = @_; + + if ($token =~ /!!(.*)/) { + return +(substr $pass, 0, 8) eq pack "H*", $1; + } elsif ($token =~ /!(.*)/) { + return $pass eq pack "H*", $1; + } else { + return $token eq crypt $pass, $token; + } } -# delete a player directory, be non-blocking AND synchronous... -# (thats 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 { my ($ns) = @_; - if (!$ns->facecache) - { - $ns->send_drawinfo (< Configure => Map & Image => Cache Images. -*** jcrossclient: your client is broken, use deliantra or gcfclient. -*** -*** -EOF - if ($ns->version =~ /jcrossclient/) { - # let them, for now - } else { - $ns->flush; - return $ns->destroy; - } - - # $ns->facecache = true; - } - - if ($ns->mapmode < cf::Map1aCmd) { - $ns->send_drawinfo (<flush; - return $ns->destroy; - } - $ns->pl and return $ns->destroy; $ns->async (sub { @@ -287,14 +247,14 @@ 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; $pl->connect ($ns); - $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp enter_map $pl; last; } elsif (can_cleanup $pl, $mtime) { @@ -332,7 +292,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 ( @@ -349,6 +309,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."; @@ -367,7 +328,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; @@ -411,7 +372,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 @@ -430,25 +391,75 @@ $pl->gender (0); last; } - Coro::Timer::sleep 0.2; + Coro::Timer::sleep 0.05; } $ob->reply (undef, "Welcome to Deliantra!"); + # XXX: Workaround for delayed client ext protocol handshake + $pl->esrv_new_player; + delete $pl->{deny_save}; 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) = @_; + + 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; + } + + if ($new_pw eq '') { + $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); + } + }; +}; + cf::register_command quit => sub { my ($ob, $arg) = @_; - $ob->reply (undef, - "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. " - . "If you are sure you want to do this, then use the quit_character command instead of quit.", - cf::NDI_UNIQUE | cf::NDI_RED); + $ob->send_msg (undef, + "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. " + . "If you are sure you want to do this, then use the quit_character command instead of quit.", + cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); }; cf::register_command quit_character => sub { @@ -458,15 +469,12 @@ $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { if ($_[0] !~ /^[yY]/) { - $ob->reply (undef, - "Ok, not not quitting then.", - cf::NDI_UNIQUE | cf::NDI_RED); + $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); } else { - $ob->reply (undef, - "Ok, quitting, hope to see you again.", - cf::NDI_UNIQUE | cf::NDI_RED); - $pl->ns->flush; - cf::async { $pl->quit_character }; + $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); + cf::async { + $pl->quit_character; + }; } }); }; @@ -482,22 +490,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; - $ob->check_score; - $ob->reply (undef, "In the future, you will wake up here when you die."); - - $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 }; - } - }); + cf::async { + my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; + ext::highscore::check $ob; + + $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; + } + }); + }; }, ); @@ -522,4 +534,3 @@ }, ); -