--- deliantra/server/lib/cf.pm 2006/02/04 20:38:29 1.3 +++ deliantra/server/lib/cf.pm 2006/02/08 03:46:15 1.5 @@ -60,6 +60,7 @@ @cf::object::player::ISA = 'cf::object'; @cf::object::map::ISA = 'cf::object'; +my %ext_pkg; my @exts; my @hook; my %command; @@ -67,6 +68,15 @@ sub inject_event { my ($data) = @_; + my $cb = $hook[$data->{event_code}]{$data->{extension}} + or return; + + $cb->($data) +} + +sub inject_global_event { + my ($data) = @_; + my $cb = $hook[$data->{event_code}] or return; @@ -90,6 +100,8 @@ my $caller = caller; + warn "registering command '$name/$time' to '$caller'"; + push @{ $command{$name} }, [$time, $cb, $caller]; $COMMAND{"$name\000"} = List::Util::max map $_->[0], @{ $command{$name} }; } @@ -98,6 +110,7 @@ my ($path) = @_; $path =~ /([^\/\\]+)\.ext$/ or die "$path"; + my $base = $1; my $pkg = $1; $pkg =~ s/[^[:word:]]/_/g; $pkg = "cf::ext::$pkg"; @@ -117,6 +130,7 @@ or die "$path: $@"; push @exts, $pkg; + $ext_pkg{$base} = $pkg; no strict 'refs'; @@ -125,7 +139,7 @@ for my $idx (0 .. $#EVENT) { if (my $ref = $pkg->can ("on_$EVENT[$idx]")) { warn "registering $EVENT[$idx] hook\n"; - $hook[$idx]{$pkg} = $ref; + $hook[$idx]{$base} = $ref; } } } @@ -175,9 +189,17 @@ $who->message ("reloading..."); warn "reloading...\n"; - unload_extension $_ for @exts; - @exts = 0; - load_extensions; + eval { + unload_extension $_ for @exts; + delete $INC{"cf.pm"}; + + # don't, removes xs symbols, too + #Symbol::delete_package $pkg; + + require cf; + }; + warn $@ if $@; + $who->message ($@) if $@; warn "reloaded\n"; $who->message ("reloaded");