--- deliantra/server/ext/login.ext 2007/01/08 19:25:53 1.19 +++ deliantra/server/ext/login.ext 2007/01/23 03:45:44 1.28 @@ -1,4 +1,4 @@ -#! perl +#! perl # MANDATORY # login handling @@ -57,7 +57,13 @@ sub check_clean_save { my ($pl) = @_; - unless (delete $pl->{clean_save}) { + if (my $time = delete $pl->{unclean_save}) { + $pl->ns->send_drawinfo ( + "You didn't use a savebed 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.", + cf::NDI_RED + ); #d#TODO } } @@ -158,7 +164,6 @@ my $pl = cf::player::find $user or next; $pl->connect ($ns); check_clean_save $pl; - $pl->{clean_save} = 1; last; } elsif (can_cleanup $pl, $mtime) { Coro::Timer::sleep 1; @@ -296,6 +301,7 @@ # update respawn position $pl->savebed ($bed->map->path, $bed->x, $bed->y); + cf::async { $pl->save }; $pl->killer ("left"); $ob->check_score; @@ -329,7 +335,7 @@ $_->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; - delete $pl->{clean_save}; + $pl->{unclean_save} = $cf::RUNTIME; } }, ); @@ -340,13 +346,13 @@ ############################################################################# -our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs -our $SAVE_TIMEOUT = 200; # save players every n seconds -our $SAVE_INTERVAL = 0.1; # save at max. one player every $SAVE_INTERVAL +our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs +our $SAVE_TIMEOUT = 20; # save players every n seconds our $SCHEDULER = cf::async_ext { + my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); while () { - Coro::Timer::sleep $SCHEDULE_INTERVAL; + $schedule_interval->next; # this weird form of iteration over values is used because # the hash changes underneath us frequently, and for @@ -360,29 +366,34 @@ eval { if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { + $cf::WAIT_FOR_TICK_ONE->wait; $pl->save; - Coro::Timer::sleep $SAVE_INTERVAL; - } - unless ($pl->active) { - # check refcounts, this is tricky and needs to be adjusted to fit server internals - my $ob = $pl->ob; - Scalar::Util::weaken $pl; - Scalar::Util::weaken $ob; - my $a_ = $pl->refcnt; - my $b_ = $ob->refcnt; - my $pl_ref = $pl->refcnt_cnt; - my $ob_ref = $ob->refcnt_cnt; - - if ($pl_ref == 2 && $ob_ref == 1) { - warn "player-scheduler destroy ", $ob->name;#d# - delete $cf::PLAYER{$ob->name}; - # pl_ref == one from object + one from cf::PLAYER - # ob_ref == one from simply being an object - $ob->destroy; - $pl->destroy; - } else { - warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d# + unless ($pl->active) { + # check refcounts, this is tricky and needs to be adjusted to fit server internals + my $ob = $pl->ob; + Scalar::Util::weaken $pl; + Scalar::Util::weaken $ob; + my $a_ = $pl->refcnt;#d# + my $b_ = $ob->refcnt;#d# + my $pl_ref = $pl->refcnt_cnt; + my $ob_ref = $ob->refcnt_cnt; + + ## pl_ref == one from object + one from cf::PLAYER + ## ob_ref == one from simply being an object + #TODO: the above should be correct, understand the 1/0, respectively + if ($pl_ref == 1 && $ob_ref == 0) { + warn "player-scheduler destroy ", $ob->name;#d# + + # remove from sight and get fresh "copies" + $pl = delete $cf::PLAYER{$ob->name}; + $ob = $pl->ob; + + $ob->destroy; + $pl->destroy; + } else { + warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d# + } } } };