ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.28 by root, Sun Jul 30 17:42:14 2006 UTC vs.
Revision 1.32 by root, Tue Aug 15 18:07:25 2006 UTC

5use Storable; 5use Storable;
6use Opcode; 6use Opcode;
7use Safe; 7use Safe;
8use Safe::Hole; 8use Safe::Hole;
9 9
10use Time::HiRes;
10use Event; 11use 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
13use strict; 14use 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.
75for my $pkg (qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region)) { 76for 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
181sub unload_extension { 182sub 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 }
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};
211 } 208 }
212 209
210 if (my $cb = $pkg->can ("on_unload")) {
211 eval {
212 $cb->($pkg);
213 1
214 } or warn "$pkg unloaded, but with errors: $@";
215 }
216
213 Symbol::delete_package $pkg; 217 Symbol::delete_package $pkg;
214} 218}
215 219
216sub load_extensions { 220sub load_extensions {
217 my $LIBDIR = maps_directory "perl"; 221 my $LIBDIR = maps_directory "perl";
289############################################################################# 293#############################################################################
290# utility functions 294# utility functions
291 295
292use JSON::Syck (); # TODO# replace by JSON::PC once working 296use JSON::Syck (); # TODO# replace by JSON::PC once working
293 297
294$JSON::Syck::ImplicitUnicode = 1;
295
296sub from_json($) { 298sub from_json($) {
299 $JSON::Syck::ImplicitUnicode = 1; # work around JSON::Syck bugs
297 JSON::Syck::Load $_[0] 300 JSON::Syck::Load $_[0]
298} 301}
299 302
300sub to_json($) { 303sub to_json($) {
304 $JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs
301 JSON::Syck::Dump $_[0] 305 JSON::Syck::Dump $_[0]
302} 306}
303 307
304############################################################################# 308#############################################################################
305# extcmd framework, basically convert ext <msg> 309# extcmd framework, basically convert ext <msg>
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
412my $delta_timer = Event->timer (
413 parked => 1,
414 prio => Event::PRIO_HIGH,
415 cb => sub { Event::unloop (undef) },
416);
417
418sub 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
410Returns true when the given account exists. 426Returns true when the given account exists.
411 427

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines