--- deliantra/server/lib/cf.pm 2006/07/30 17:42:14 1.28 +++ deliantra/server/lib/cf.pm 2006/08/15 18:07:25 1.32 @@ -7,6 +7,7 @@ use Safe; use Safe::Hole; +use Time::HiRes; use Event; $Event::Eval = 1; # no idea why this is required, but it is @@ -72,7 +73,7 @@ # we bless all objects into derived classes to force a method lookup # within the Safe compartment. -for my $pkg (qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region)) { +for my $pkg (qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region cf::arch)) { no strict 'refs'; @{"ext::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; } @@ -183,10 +184,6 @@ warn "removing extension $pkg\n"; - if (my $cb = $pkg->can ("on_unload")) { - $cb->($pkg); - } - # remove hooks for my $idx (0 .. $#EVENT) { delete $hook[$idx]{$pkg}; @@ -210,6 +207,13 @@ delete $extcmd{$name}; } + if (my $cb = $pkg->can ("on_unload")) { + eval { + $cb->($pkg); + 1 + } or warn "$pkg unloaded, but with errors: $@"; + } + Symbol::delete_package $pkg; } @@ -291,13 +295,13 @@ use JSON::Syck (); # TODO# replace by JSON::PC once working -$JSON::Syck::ImplicitUnicode = 1; - sub from_json($) { + $JSON::Syck::ImplicitUnicode = 1; # work around JSON::Syck bugs JSON::Syck::Load $_[0] } sub to_json($) { + $JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs JSON::Syck::Dump $_[0] } @@ -405,6 +409,18 @@ ############################################################################# # core extensions - in perl +my $delta_timer = Event->timer ( + parked => 1, + prio => Event::PRIO_HIGH, + cb => sub { Event::unloop (undef) }, +); + +sub sleep_delta($) { + $delta_timer->at (Event::time + $_[0]); + $delta_timer->start; + Event::loop; +} + =item cf::player::exists $login Returns true when the given account exists.