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.273 by root, Mon Jun 4 12:19:08 2007 UTC vs.
Revision 1.277 by root, Sun Jun 10 04:24:50 2007 UTC

423 or return; 423 or return;
424 424
425 aio_rename "$runtime~", $runtime 425 aio_rename "$runtime~", $runtime
426 and return; 426 and return;
427 427
428 warn "runtime file written.\n";#d# 428 warn "runtime file written.\n";
429 429
430 1 430 1
431} 431}
432 432
433=item cf::datalog type => key => value, ... 433=item cf::datalog type => key => value, ...
873 or return; 873 or return;
874 $av = eval { (Storable::thaw $av)->{objs} }; 874 $av = eval { (Storable::thaw $av)->{objs} };
875 } 875 }
876 876
877 warn sprintf "loading %s (%d)\n", 877 warn sprintf "loading %s (%d)\n",
878 $filename, length $data, scalar @{$av || []};#d# 878 $filename, length $data, scalar @{$av || []};
879 return ($data, $av); 879 return ($data, $av);
880} 880}
881 881
882############################################################################# 882#############################################################################
883# command handling &c 883# command handling &c
1305 my ($self, $merge) = @_; 1305 my ($self, $merge) = @_;
1306 1306
1307 # we have to keep some variables in memory intact 1307 # we have to keep some variables in memory intact
1308 local $self->{path}; 1308 local $self->{path};
1309 local $self->{load_path}; 1309 local $self->{load_path};
1310 local $self->{deny_save};
1311 local $self->{deny_reset};
1312 1310
1313 $self->SUPER::thawer_merge ($merge); 1311 $self->SUPER::thawer_merge ($merge);
1314} 1312}
1315 1313
1316sub normalise { 1314sub normalise {
1416 1414
1417 $_->change_map_light ($change) 1415 $_->change_map_light ($change)
1418 for grep $_->outdoor, values %cf::MAP; 1416 for grep $_->outdoor, values %cf::MAP;
1419} 1417}
1420 1418
1419sub decay_objects {
1420 my ($self) = @_;
1421
1422 return if $self->{deny_reset};
1423
1424 $self->do_decay_objects;
1425}
1426
1421sub unlink_save { 1427sub unlink_save {
1422 my ($self) = @_; 1428 my ($self) = @_;
1423 1429
1424 utf8::encode (my $save = $self->save_path); 1430 utf8::encode (my $save = $self->save_path);
1425 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save; 1431 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save;
1481 $self->load_header_orig 1487 $self->load_header_orig
1482 or return; 1488 or return;
1483 $self->prepare_orig; 1489 $self->prepare_orig;
1484 } 1490 }
1485 1491
1492 $self->{deny_reset} = 1
1493 if $self->no_reset;
1494
1486 $self->default_region (cf::region::find_by_path $self->{path}) 1495 $self->default_region (cf::region::find_by_path $self->{path})
1487 unless $self->default_region; 1496 unless $self->default_region;
1488 1497
1489 1 1498 1
1490} 1499}
1505 $map->{last_save} = $cf::RUNTIME; 1514 $map->{last_save} = $cf::RUNTIME;
1506 1515
1507 $map->load_header 1516 $map->load_header
1508 or return; 1517 or return;
1509 1518
1510 if ($map->should_reset && 0) {#d#TODO# disabled, crashy (locking issue?) 1519 if ($map->should_reset) {#d#TODO# disabled, crashy (locking issue?)
1511 # doing this can freeze the server in a sync job, obviously 1520 # doing this can freeze the server in a sync job, obviously
1512 #$cf::WAIT_FOR_TICK->wait; 1521 #$cf::WAIT_FOR_TICK->wait;
1513 $map->reset; 1522 $map->reset;
1514 undef $guard; 1523 undef $guard;
1515 return find $path; 1524 return find $path;
1582 my ($self, $ob) = @_; 1591 my ($self, $ob) = @_;
1583 1592
1584 return find "~" . $ob->name . "/" . $self->{path} 1593 return find "~" . $ob->name . "/" . $self->{path}
1585 if $self->per_player; 1594 if $self->per_player;
1586 1595
1596# return find "?party/" . $ob->name . "/" . $self->{path}
1597# if $self->per_party;
1598
1587 $self 1599 $self
1588} 1600}
1589 1601
1590# find and load all maps in the 3x3 area around a map 1602# find and load all maps in the 3x3 area around a map
1591sub load_diag { 1603sub load_diag {
1701 1713
1702sub reset_at { 1714sub reset_at {
1703 my ($self) = @_; 1715 my ($self) = @_;
1704 1716
1705 # TODO: safety, remove and allow resettable per-player maps 1717 # TODO: safety, remove and allow resettable per-player maps
1706 return 1e99 if $self->isa ("ext::map_per_player");#d#
1707 return 1e99 if $self->{deny_reset}; 1718 return 1e99 if $self->{deny_reset};
1708 1719
1709 my $time = $self->fixed_resettime ? $self->{instantiate_time} : $self->last_access; 1720 my $time = $self->fixed_resettime ? $self->{instantiate_time} : $self->last_access;
1710 my $to = List::Util::min $MAX_RESET, $self->reset_timeout || $DEFAULT_RESET; 1721 my $to = List::Util::min $MAX_RESET, $self->reset_timeout || $DEFAULT_RESET;
1711 1722
1722 my ($self) = @_; 1733 my ($self) = @_;
1723 1734
1724 my $lock = cf::lock_acquire "map_data:$self->{path}"; 1735 my $lock = cf::lock_acquire "map_data:$self->{path}";
1725 1736
1726 return if $self->players; 1737 return if $self->players;
1727 return if $self->isa ("ext::map_per_player");#d#
1728 1738
1729 warn "resetting map ", $self->path;#d# 1739 warn "resetting map ", $self->path;
1730 1740
1731 $self->in_memory (cf::MAP_SWAPPED); 1741 $self->in_memory (cf::MAP_SWAPPED);
1732 1742
1733 # need to save uniques path 1743 # need to save uniques path
1734 unless ($self->{deny_save}) { 1744 unless ($self->{deny_save}) {
1766 $cf::MAP{$self->path} = $self; 1776 $cf::MAP{$self->path} = $self;
1767 1777
1768 $self->reset; # polite request, might not happen 1778 $self->reset; # polite request, might not happen
1769} 1779}
1770 1780
1781=item $maps = cf::map::tmp_maps
1782
1783Returns an arrayref with all map paths of currently instantiated and saved
1784maps. May block.
1785
1786=cut
1787
1788sub tmp_maps() {
1789 [
1790 map {
1791 utf8::decode $_;
1792 /\.map$/
1793 ? normalise $_
1794 : ()
1795 } @{ aio_readdir $TMPDIR or [] }
1796 ]
1797}
1798
1799=item $maps = cf::map::random_maps
1800
1801Returns an arrayref with all map paths of currently instantiated and saved
1802random maps. May block.
1803
1804=cut
1805
1806sub random_maps() {
1807 [
1808 map {
1809 utf8::decode $_;
1810 /\.map$/
1811 ? normalise "?random/$_"
1812 : ()
1813 } @{ aio_readdir $RANDOMDIR or [] }
1814 ]
1815}
1816
1771=item cf::map::unique_maps 1817=item cf::map::unique_maps
1772 1818
1773Returns an arrayref of paths of all shared maps that have 1819Returns an arrayref of paths of all shared maps that have
1774instantiated unique items. May block. 1820instantiated unique items. May block.
1775 1821
1776=cut 1822=cut
1777 1823
1778sub unique_maps() { 1824sub unique_maps() {
1779 my $files = aio_readdir $UNIQUEDIR 1825 [
1780 or return; 1826 map {
1781
1782 my @paths;
1783
1784 for (@$files) {
1785 utf8::decode $_; 1827 utf8::decode $_;
1786 next if /\.pst$/; 1828 /\.map$/
1787 next unless /^$PATH_SEP/o; 1829 ? normalise $_
1788 1830 : ()
1789 push @paths, cf::map::normalise $_; 1831 } @{ aio_readdir $UNIQUEDIR or [] }
1790 } 1832 ]
1791
1792 \@paths
1793} 1833}
1794 1834
1795package cf; 1835package cf;
1796 1836
1797=back 1837=back
2560sub reload_resources { 2600sub reload_resources {
2561 warn "reloading resource files...\n"; 2601 warn "reloading resource files...\n";
2562 2602
2563 reload_regions; 2603 reload_regions;
2564 reload_facedata; 2604 reload_facedata;
2605 #reload_archetypes;#d#
2565 reload_archetypes; 2606 reload_archetypes;
2566 reload_treasures; 2607 reload_treasures;
2567 2608
2568 warn "finished reloading resource files\n"; 2609 warn "finished reloading resource files\n";
2569} 2610}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines