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.166 by root, Sat Jan 13 23:06:13 2007 UTC vs.
Revision 1.167 by root, Sat Jan 13 23:32:43 2007 UTC

900 } or warn "$ext not loaded: $@"; 900 } or warn "$ext not loaded: $@";
901 } 901 }
902} 902}
903 903
904############################################################################# 904#############################################################################
905# load/save/clean perl data associated with a map
906
907*cf::mapsupport::on_clean = sub {
908 my ($map) = @_;
909
910 my $path = $map->tmpname;
911 defined $path or return;
912
913 unlink "$path.pst";
914};
915
916cf::map->attach (prio => -10000, package => cf::mapsupport::);
917
918#############################################################################
919 905
920=head2 CORE EXTENSIONS 906=head2 CORE EXTENSIONS
921 907
922Functions and methods that extend core crossfire objects. 908Functions and methods that extend core crossfire objects.
923 909
1077 for (@$files) { 1063 for (@$files) {
1078 utf8::decode $_; 1064 utf8::decode $_;
1079 next if /\.(?:pl|pst)$/; 1065 next if /\.(?:pl|pst)$/;
1080 next unless /^$PATH_SEP/o; 1066 next unless /^$PATH_SEP/o;
1081 1067
1068 s/\.map$//;
1082 push @paths, "~" . $pl->ob->name . "/" . $_; 1069 push @paths, "~" . $pl->ob->name . "/" . $_;
1083 } 1070 }
1084 1071
1085 \@paths 1072 \@paths
1086} 1073}
1220# the displayed name, this is a one way mapping 1207# the displayed name, this is a one way mapping
1221sub visible_name { 1208sub visible_name {
1222 &as_string 1209 &as_string
1223} 1210}
1224 1211
1225# escape the /'s in the path
1226sub _escaped_path {
1227 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g;
1228
1229 $path
1230}
1231
1232# the original (read-only) location 1212# the original (read-only) location
1233sub load_path { 1213sub load_path {
1234 my ($self) = @_; 1214 my ($self) = @_;
1235 1215
1236 sprintf "%s/%s/%s", cf::datadir, cf::mapdir, $self->{path} 1216 sprintf "%s/%s/%s", cf::datadir, cf::mapdir, $self->{path}
1238 1218
1239# the temporary/swap location 1219# the temporary/swap location
1240sub save_path { 1220sub save_path {
1241 my ($self) = @_; 1221 my ($self) = @_;
1242 1222
1223 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g;
1243 sprintf "%s/%s/%s.map", cf::localdir, cf::tmpdir, $self->_escaped_path 1224 sprintf "%s/%s/%s", cf::localdir, cf::tmpdir, $path
1244} 1225}
1245 1226
1246# the unique path, undef == no special unique path 1227# the unique path, undef == no special unique path
1247sub uniq_path { 1228sub uniq_path {
1248 my ($self) = @_; 1229 my ($self) = @_;
1249 1230
1231 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g;
1250 sprintf "%s/%s/%s", cf::localdir, cf::uniquedir, $self->_escaped_path 1232 sprintf "%s/%s/%s", cf::localdir, cf::uniquedir, $path
1251} 1233}
1252 1234
1253# and all this just because we cannot iterate over 1235# and all this just because we cannot iterate over
1254# all maps in C++... 1236# all maps in C++...
1255sub change_all_map_light { 1237sub change_all_map_light {
1544} 1526}
1545 1527
1546sub reset { 1528sub reset {
1547 my ($self) = @_; 1529 my ($self) = @_;
1548 1530
1549 my $lock = cf::lock_acquire "map_data:" . $self->path; 1531 my $lock = cf::lock_acquire "map_data:$self->{path}";
1550 1532
1551 return if $self->players; 1533 return if $self->players;
1552 return if $self->isa ("ext::map_per_player");#d# 1534 return if $self->isa ("ext::map_per_player");#d#
1553 1535
1554 warn "resetting map ", $self->path;#d# 1536 warn "resetting map ", $self->path;#d#
1555 1537
1556 delete $cf::MAP{$self->path}; 1538 delete $cf::MAP{$self->path};
1539
1540 $self->in_memory (cf::MAP_SWAPPED);
1541 $self->clear;
1557 1542
1558 $_->clear_links_to ($self) for values %cf::MAP; 1543 $_->clear_links_to ($self) for values %cf::MAP;
1559 1544
1560 $self->unlink_save; 1545 $self->unlink_save;
1561 $self->destroy; 1546 $self->destroy;
1588 for (@$files) { 1573 for (@$files) {
1589 utf8::decode $_; 1574 utf8::decode $_;
1590 next if /\.pst$/; 1575 next if /\.pst$/;
1591 next unless /^$PATH_SEP/o; 1576 next unless /^$PATH_SEP/o;
1592 1577
1578 s/\.map$//;
1593 push @paths, $_; 1579 push @paths, $_;
1594 } 1580 }
1595 1581
1596 \@paths 1582 \@paths
1597} 1583}
2254 warn "enter emergency perl save\n"; 2240 warn "enter emergency perl save\n";
2255 2241
2256 cf::sync_job { 2242 cf::sync_job {
2257 # use a peculiar iteration method to avoid tripping on perl 2243 # use a peculiar iteration method to avoid tripping on perl
2258 # refcount bugs in for. also avoids problems with players 2244 # refcount bugs in for. also avoids problems with players
2259 # and maps saved/Destroyed asynchronously. 2245 # and maps saved/destroyed asynchronously.
2260 warn "begin emergency player save\n"; 2246 warn "begin emergency player save\n";
2261 for my $login (keys %cf::PLAYER) { 2247 for my $login (keys %cf::PLAYER) {
2262 my $pl = $cf::PLAYER{$login} or next; 2248 my $pl = $cf::PLAYER{$login} or next;
2263 $pl->valid or next; 2249 $pl->valid or next;
2264 $pl->save; 2250 $pl->save;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines