--- deliantra/server/ext/login.ext 2007/07/20 16:11:10 1.67 +++ deliantra/server/ext/login.ext 2008/05/05 22:38:47 1.86 @@ -54,6 +54,24 @@ 1 } +sub safe_spot($) { + my ($pl) = @_; + + my $ob = $pl->ob; + + my $m = $ob->map + or return; + my $x = $ob->x; + my $y = $ob->y; + +# return 0;#d# +# warn join ":", $m->at ($x, $y);#d# +# warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; +# return 0; + + scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y) +} + sub enter_map { my ($pl) = @_; @@ -66,47 +84,47 @@ $ob->enter_link; - if (my $time = delete $pl->{unclean_save}) { - if (my $m = cf::map::find $map) { - if ($time < $m->{instantiate_time}) { - # the map was reset in the meantime - my $age = $cf::RUNTIME - $time; + my $m = cf::map::find $map; + my $time = delete $pl->{unclean_save}; - warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# + if ($time && $m) { + if ($time < $m->{instantiate_time}) { + # the map was reset in the meantime + my $age = $cf::RUNTIME - $time; - # for now, just go back to savebed - ($map, $x, $y) = $pl->savebed; + warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# - if ($age >= $MAX_DISCONNECT_TIME) { - $ob->message ( - "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " - . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " - . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... " - . "H", - cf::NDI_RED - ); - # kill them. - # reminds me of the famous badness 10000 syndrome... - $ob->stats->hp (-10000); #] if they survive this they deserved to live - $pl->killer ("a cave-in"); - } else { - $ob->message ( - "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " - . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " - . "Better use a savebed next time, much worse things could have happened... " - . "H", - cf::NDI_RED - ); - } + if ($age >= $MAX_DISCONNECT_TIME) { + $ob->message ( + "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " + . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " + . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... " + . "H", + cf::NDI_RED + ); + # 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; } else { + ($map, $x, $y) = $pl->savebed; + $ob->message ( - "You didn't use a bed to reality to leave this realm. This is very dangerous, " - . "as lots of things could happen when you leave by other means, such as cave-ins, " - . "or monsters suddenly snapping your body. Better use a savebed next time. " - . "H", + "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " + . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " + . "Better use a savebed next time, much worse things could have happened... " + . "H", cf::NDI_RED ); } + } else { + $ob->message ( + "You didn't use a bed to reality to leave this realm. This is very dangerous, " + . "as lots of things could happen when you leave by other means, such as cave-ins, " + . "or monsters suddenly snapping your body. Better use a savebed next time. " + . "H", + cf::NDI_RED + ); } } @@ -118,10 +136,12 @@ sub nuke_playerdir { my ($user) = @_; - aio_stat "$PLAYERDIR/$user"; - system "cd \Q$PLAYERDIR\E " - . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " - . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; + my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; + + cf::fork_call { + rename "$PLAYERDIR/$user", $temp; + system "rm", "-rf", $temp; + }; } cf::client->attach (on_addme => sub { @@ -140,12 +160,12 @@ *** *** Look at your client preferences: *** -*** CFPlus: all known versions automatically enable the facecache. +*** deliantra: all known versions automatically enable the facecache. *** cfclient: use the -cache commandline option. *** cfclient: map will not redraw automatically (bug). *** gcfclient: use -cache commandline option, or enable -*** gcfclient: Client=>Configure=>Map & Image=>Cache Images. -*** jcrossclient: your client is broken, use CFPlus or gcfclient. +*** gcfclient: Client => Configure => Map & Image => Cache Images. +*** jcrossclient: your client is broken, use deliantra or gcfclient. *** *** EOF @@ -175,6 +195,8 @@ $ns->pl and return $ns->destroy; $ns->async (sub { + $Coro::current->{desc} = "addme init"; + my ($user, $pass); $ns->send_packet ("addme_success"); @@ -212,6 +234,8 @@ check_playing $ns, $user and next; + $Coro::current->{desc} = "addme($user) pass"; + $ns->send_drawinfo ( "Welcome $user, please enter your password now. " . "New users should now choose a password. " @@ -244,6 +268,8 @@ check_playing $ns, $user and next; + $Coro::current->{desc} = "addme($user) check"; + # try to read the user file and check the password if (my $pl = cf::player::find $user) { aio_stat $pl->path and next; @@ -306,6 +332,7 @@ } # the rest of this function is character creation + $Coro::current->{desc} = "addme($user) chargen"; # just to make sure nothing is left over nuke_playerdir $user; @@ -373,6 +400,9 @@ Coro::Timer::sleep 0.2; } + # create the playerdir, if necessary, as chargen_race_done did it before + # presumably because of unique maps + aio_mkdir playerdir $pl, 0770; $pl->chargen_race_done; while () { @@ -389,7 +419,7 @@ Coro::Timer::sleep 0.2; } - $ob->reply (undef, "Welcome to Crossfire!"); + $ob->reply (undef, "Welcome to Deliantra!"); delete $pl->{deny_save}; @@ -440,7 +470,7 @@ $pl->savebed ($bed->map->path, $bed->x, $bed->y); cf::async { $pl->save }; - $pl->killer ("left"); + 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."); @@ -472,20 +502,22 @@ $_->ob->message ("$name left the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; } else { $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; - $pl->{unclean_save} = $cf::RUNTIME; + $pl->{unclean_save} = $cf::RUNTIME + unless safe_spot $pl; } }, ); ############################################################################# -our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs -our $SAVE_TIMEOUT = 20; # save players every n seconds +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 { - my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); + $Coro::current->{desc} = "player scheduler"; + while () { - $schedule_interval->next; + Coro::EV::timer_once $SCHEDULE_INTERVAL; # this weird form of iteration over values is used because # the hash changes underneath us frequently, and for @@ -499,7 +531,6 @@ eval { if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { - cf::wait_for_tick_begin; $pl->save; unless ($pl->active || $pl->ns) { @@ -523,13 +554,13 @@ my $a_ = $pl->refcnt;#d# my $b_ = $ob->refcnt;#d# - warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref ob $ob_ref (C pl $a_ ob $b_)\n";#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 $@; - Coro::cede; + cf::cede_to_tick; }; } };