--- deliantra/server/ext/login.ext 2008/05/05 16:02:20 1.85 +++ 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 @@ -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 { @@ -92,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 ( @@ -105,9 +102,7 @@ # kill them. # reminds me of the famous badness 10000 syndrome... $ob->stats->hp (-10000); #] if they survive this they deserved to live - my $killer = cf::arch::get "killer_login"; - $pl->killer ($killer); - $killer->destroy; + my $killer = cf::arch::get "killer_login"; $pl->killer ($killer); $killer->destroy; } else { ($map, $x, $y) = $pl->savebed; @@ -133,8 +128,14 @@ $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... -# (thats hard, so we crap out and fork). +# (that's hard, so we crap out and fork). sub nuke_playerdir { my ($user) = @_; @@ -149,51 +150,6 @@ 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 { @@ -213,7 +169,7 @@ # read username while () { - $user = query $ns, 0, "What is your name?\n:"; + $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; if ($cf::LOGIN_LOCK{$user}) { $ns->send_drawinfo ( @@ -221,13 +177,13 @@ . "Chose another, or wait till the other session has ended.", cf::NDI_RED ); - } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}\z/) { + } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,19}\z/) { last; } else { $ns->send_drawinfo ( "Your username contains illegal characters " . "(only a-z, A-Z and 0-9 are allowed), " - . "or is not between 3 and 18 characters in length.", + . "or is not between 3 and 20 characters in length.", cf::NDI_RED ); } @@ -355,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; @@ -381,7 +337,7 @@ $ob->roll_stats; } - Coro::Timer::sleep 0.2; + Coro::Timer::sleep 0.05; } $ob->set_animation (2); @@ -399,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 @@ -418,25 +374,98 @@ $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) = @_; + + 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) = @_; - $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 { @@ -446,15 +475,14 @@ $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); + $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; + }; } }); }; @@ -472,12 +500,10 @@ $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; + my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; + ext::highscore::check $ob; - $ob->reply (undef, "In the future, you will wake up here when you die."); + $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { if ($_[0] !~ /^[yY]/) { @@ -512,62 +538,3 @@ }, ); -############################################################################# - -our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs -our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds - -our $SCHEDULER = cf::async_ext { - $Coro::current->{desc} = "player scheduler"; - - while () { - Coro::EV::timer_once $SCHEDULE_INTERVAL; - - # this weird form of iteration over values is used because - # the hash changes underneath us frequently, and for - # keeps a direct reference to the value without (in 5.8 perls) - # keeping a reference, so this is prone to crashes or worse. - my @players = keys %cf::PLAYER; - for (@players) { - my $pl = $cf::PLAYER{$_} - or next; - $pl->valid or next; - - eval { - if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { - $pl->save; - - unless ($pl->active || $pl->ns) { - # check refcounts, this is tricky and needs to be adjusted to fit server internals - my $ob = $pl->ob; - - my $pl_ref = $pl->refcnt_cnt; - my $ob_ref = $ob->refcnt_cnt; - - ## pl_ref == $pl + ob->contr + %cf::PLAYER - ## ob_ref == $ob + pl->observe + simply being an object - if ($pl_ref == 3 && $ob_ref == 3) { - warn "player-scheduler destroy ", $ob->name;#d# - - # remove from sight and get fresh "copies" - $pl = delete $cf::PLAYER{$ob->name}; - $ob = $pl->ob; - - $pl->destroy; # destroys $ob - } else { - my $a_ = $pl->refcnt;#d# - my $b_ = $ob->refcnt;#d# - - warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref/3 ob $ob_ref/3 (C pl $a_/1 ob $b_/2)\n";#d# - } - } - } - }; - warn $@ if $@; - cf::cede_to_tick; - }; - } -}; - -$SCHEDULER->prio (1); -