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.48 by root, Sun Aug 27 15:24:22 2006 UTC vs.
Revision 1.51 by root, Mon Aug 28 14:05:24 2006 UTC

72 72
73@safe::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object'; 73@safe::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object';
74 74
75# we bless all objects into (empty) derived classes to force a method lookup 75# we bless all objects into (empty) derived classes to force a method lookup
76# within the Safe compartment. 76# within the Safe compartment.
77for my $pkg (qw(cf::object cf::object::player cf::player cf::map cf::party cf::region cf::arch)) { 77for my $pkg (qw(cf::object cf::object::player cf::player cf::map cf::party cf::region cf::arch cf::living)) {
78 no strict 'refs'; 78 no strict 'refs';
79 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; 79 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
80} 80}
81 81
82$Event::DIED = sub { 82$Event::DIED = sub {
262 $obj->{$name} = \%arg; 262 $obj->{$name} = \%arg;
263 } else { 263 } else {
264 warn "object uses attachment '$name' that is not available, postponing.\n"; 264 warn "object uses attachment '$name' that is not available, postponing.\n";
265 } 265 }
266 266
267 push @{$obj->{_attachment}}, $name; 267 $obj->{_attachment}{$name} = undef;
268 268
269 $res->{attachment} = $name; 269 $res->{attachment} = $name;
270 $res 270 $res
271} 271}
272 272
356 356
357 $data = from_json $data; 357 $data = from_json $data;
358 358
359 for (@$data) { 359 for (@$data) {
360 my ($name, $args) = @$_; 360 my ($name, $args) = @$_;
361
361 attach $obj, $name, %{$args || {} }; 362 $obj->attach ($name, %{$args || {} });
362 } 363 }
363} 364}
364 365
365# basically do the same as instantiate, without calling instantiate 366# basically do the same as instantiate, without calling instantiate
366sub reattach { 367sub reattach {
367 my ($obj) = @_; 368 my ($obj) = @_;
368 my $registry = $obj->registry; 369 my $registry = $obj->registry;
369 370
370 @$registry = (); 371 @$registry = ();
371 372
373 delete $obj->{_attachment} unless scalar keys %{ $obj->{_attachment} || {} };
374
372 for my $name (@{ $obj->{_attachment} }) { 375 for my $name (keys %{ $obj->{_attachment} || {} }) {
373 if (my $attach = $attachment{$name}) { 376 if (my $attach = $attachment{$name}) {
374 for (@$attach) { 377 for (@$attach) {
375 my ($klass, @attach) = @$_; 378 my ($klass, @attach) = @$_;
376 _attach @$registry, $klass, @attach; 379 _attach @$registry, $klass, @attach;
377 } 380 }
382} 385}
383 386
384sub object_freezer_save { 387sub object_freezer_save {
385 my ($filename, $objs) = @_; 388 my ($filename, $objs) = @_;
386 389
387 $filename .= ".pst";
388
389 if (@$objs) { 390 if (@$objs) {
390 open my $fh, ">:raw", "$filename~"; 391 open my $fh, ">:raw", "$filename.pst~";
391 chmod $fh, SAVE_MODE;
392 syswrite $fh, Storable::nfreeze { version => 1, objs => $objs }; 392 syswrite $fh, Storable::nfreeze { version => 1, objs => $objs };
393 close $fh; 393 close $fh;
394 chmod SAVE_MODE, "$filename.pst~";
394 rename "$filename~", $filename; 395 rename "$filename.pst~", "$filename.pst";
395 } else { 396 } else {
396 unlink $filename; 397 unlink "$filename.pst";
397 } 398 }
399
400 chmod SAVE_MODE, "$filename~";
401 rename "$filename~", $filename;
398} 402}
399 403
400sub object_thawer_load { 404sub object_thawer_load {
401 my ($filename) = @_; 405 my ($filename) = @_;
402 406
413 417
414 @{$dst->registry} = @{$src->registry}; 418 @{$dst->registry} = @{$src->registry};
415 419
416 %$dst = %$src; 420 %$dst = %$src;
417 421
418 $dst->{_attachment} = [@{ $src->{_attachment} }] 422 %{$dst->{_attachment}} = %{$src->{_attachment}}
419 if exists $src->{_attachment}; 423 if exists $src->{_attachment};
420 }, 424 },
421; 425;
422 426
423############################################################################# 427#############################################################################
664 my ($map) = @_; 668 my ($map) = @_;
665 669
666 my $path = $map->tmpname; 670 my $path = $map->tmpname;
667 defined $path or return; 671 defined $path or return;
668 672
669 unlink "$path.cfperl";
670 unlink "$path.pst"; 673 unlink "$path.pst";
671}; 674};
672 675
676# old style persistent data, TODO: remove #d#
673*cf::mapsupport::on_swapin = 677*cf::mapsupport::on_swapin =
674*cf::mapsupport::on_load = sub { 678*cf::mapsupport::on_load = sub {
675 my ($map) = @_; 679 my ($map) = @_;
676 680
677 my $path = $map->tmpname; 681 my $path = $map->tmpname;
684 688
685 $data->{version} <= 1 689 $data->{version} <= 1
686 or return; # too new 690 or return; # too new
687 691
688 $map->_set_obs ($data->{obs}); 692 $map->_set_obs ($data->{obs});
693 $map->invoke (EVENT_MAP_UPGRADE);
689}; 694};
690 695
691attach_to_maps prio => -10000, package => cf::mapsupport::; 696attach_to_maps prio => -10000, package => cf::mapsupport::;
692 697
693############################################################################# 698#############################################################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines