… | |
… | |
5 | use Storable; |
5 | use Storable; |
6 | use Opcode; |
6 | use Opcode; |
7 | use Safe; |
7 | use Safe; |
8 | use Safe::Hole; |
8 | use Safe::Hole; |
9 | |
9 | |
|
|
10 | use Time::HiRes; |
10 | use Event; |
11 | use Event; |
11 | $Event::Eval = 1; # no idea why this is required, but it is |
12 | $Event::Eval = 1; # no idea why this is required, but it is |
12 | |
13 | |
13 | use strict; |
14 | use strict; |
14 | |
15 | |
… | |
… | |
70 | @ext::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object'; |
71 | @ext::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object'; |
71 | @ext::cf::object::map::ISA = @cf::object::map::ISA = 'cf::object'; |
72 | @ext::cf::object::map::ISA = @cf::object::map::ISA = 'cf::object'; |
72 | |
73 | |
73 | # we bless all objects into derived classes to force a method lookup |
74 | # we bless all objects into derived classes to force a method lookup |
74 | # within the Safe compartment. |
75 | # within the Safe compartment. |
75 | for my $pkg (qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region)) { |
76 | for my $pkg (qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region cf::arch)) { |
76 | no strict 'refs'; |
77 | no strict 'refs'; |
77 | @{"ext::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; |
78 | @{"ext::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; |
78 | } |
79 | } |
79 | |
80 | |
80 | $Event::DIED = sub { |
81 | $Event::DIED = sub { |
… | |
… | |
180 | |
181 | |
181 | sub unload_extension { |
182 | sub unload_extension { |
182 | my ($pkg) = @_; |
183 | my ($pkg) = @_; |
183 | |
184 | |
184 | warn "removing extension $pkg\n"; |
185 | warn "removing extension $pkg\n"; |
185 | |
|
|
186 | if (my $cb = $pkg->can ("on_unload")) { |
|
|
187 | $cb->($pkg); |
|
|
188 | } |
|
|
189 | |
186 | |
190 | # remove hooks |
187 | # remove hooks |
191 | for my $idx (0 .. $#EVENT) { |
188 | for my $idx (0 .. $#EVENT) { |
192 | delete $hook[$idx]{$pkg}; |
189 | delete $hook[$idx]{$pkg}; |
193 | } |
190 | } |
… | |
… | |
206 | } |
203 | } |
207 | |
204 | |
208 | # remove extcmds |
205 | # remove extcmds |
209 | for my $name (grep $extcmd{$_}[1] eq $pkg, keys %extcmd) { |
206 | for my $name (grep $extcmd{$_}[1] eq $pkg, keys %extcmd) { |
210 | delete $extcmd{$name}; |
207 | delete $extcmd{$name}; |
|
|
208 | } |
|
|
209 | |
|
|
210 | if (my $cb = $pkg->can ("on_unload")) { |
|
|
211 | eval { |
|
|
212 | $cb->($pkg); |
|
|
213 | 1 |
|
|
214 | } or warn "$pkg unloaded, but with errors: $@"; |
211 | } |
215 | } |
212 | |
216 | |
213 | Symbol::delete_package $pkg; |
217 | Symbol::delete_package $pkg; |
214 | } |
218 | } |
215 | |
219 | |
… | |
… | |
402 | for grep %$_, $ob, $ob->inv; |
406 | for grep %$_, $ob, $ob->inv; |
403 | }; |
407 | }; |
404 | |
408 | |
405 | ############################################################################# |
409 | ############################################################################# |
406 | # core extensions - in perl |
410 | # core extensions - in perl |
|
|
411 | |
|
|
412 | my $delta_timer = Event->timer ( |
|
|
413 | parked => 1, |
|
|
414 | prio => Event::PRIO_HIGH, |
|
|
415 | cb => sub { Event::unloop (undef) }, |
|
|
416 | ); |
|
|
417 | |
|
|
418 | sub sleep_delta($) { |
|
|
419 | $delta_timer->at (Event::time + $_[0]); |
|
|
420 | $delta_timer->start; |
|
|
421 | Event::loop; |
|
|
422 | } |
407 | |
423 | |
408 | =item cf::player::exists $login |
424 | =item cf::player::exists $login |
409 | |
425 | |
410 | Returns true when the given account exists. |
426 | Returns true when the given account exists. |
411 | |
427 | |