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.561 by root, Fri Apr 22 06:10:33 2011 UTC vs.
Revision 1.565 by root, Sat Apr 30 05:41:17 2011 UTC

1# 1#
2# This file is part of Deliantra, the Roguelike Realtime MMORPG. 2# This file is part of Deliantra, the Roguelike Realtime MMORPG.
3# 3#
4# Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4# Copyright (©) 2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5# 5#
6# Deliantra is free software: you can redistribute it and/or modify it under 6# Deliantra is free software: you can redistribute it and/or modify it under
7# the terms of the Affero GNU General Public License as published by the 7# the terms of the Affero GNU General Public License as published by the
8# Free Software Foundation, either version 3 of the License, or (at your 8# Free Software Foundation, either version 3 of the License, or (at your
9# option) any later version. 9# option) any later version.
1954 # {... are special paths that are not being touched 1954 # {... are special paths that are not being touched
1955 # ?xxx/... are special absolute paths 1955 # ?xxx/... are special absolute paths
1956 # ?random/... random maps 1956 # ?random/... random maps
1957 # /... normal maps 1957 # /... normal maps
1958 # ~user/... per-player map of a specific user 1958 # ~user/... per-player map of a specific user
1959 # !up !down for quad maps, or other maps with up/down layers
1959 1960
1960 $path =~ s/$PATH_SEP/\//go; 1961 $path =~ s/$PATH_SEP/\//go;
1961 1962
1962 # treat it as relative path if it starts with 1963 # treat it as relative path if it starts with
1963 # something that looks reasonable 1964 # something that looks reasonable
1964 if ($path =~ m{^(?:\./|\.\./|\w)}) { 1965 if ($path =~ m{^(?:\./|\.\./|\w)}) {
1965 $base or Carp::carp "normalise called with relative path and no base: '$path'"; 1966 $base or Carp::carp "normalise called with relative path and no base: '$path'";
1966 1967
1967 $base =~ s{[^/]+/?$}{}; 1968 $base =~ s{[^/]+/?$}{};
1968 $path = "$base/$path"; 1969 $path = "$base/$path";
1970
1971 } elsif ($path eq '!up') {
1972 $base && ref $base
1973 or Carp::carp "normalise called with relative tile path and no base: '$path'";
1974
1975 my $uppth = $base->tile_path (cf::TILE_UP);
1976 $path = $uppth if $uppth;
1977
1978 } elsif ($path eq '!down') {
1979 $base && ref $base
1980 or Carp::carp "normalise called with relative tile path and no base: '$path'";
1981
1982 my $dpth = $base->tile_path (cf::TILE_DOWN);
1983 $path = $dpth if $dpth;
1969 } 1984 }
1970 1985
1971 for ($path) { 1986 for ($path) {
1972 redo if s{/\.?/}{/}; 1987 redo if s{/\.?/}{/};
1973 redo if s{/[^/]+/\.\./}{/}; 1988 redo if s{/[^/]+/\.\./}{/};
2126sub find { 2141sub find {
2127 my ($path, $origin) = @_; 2142 my ($path, $origin) = @_;
2128 2143
2129 cf::cede_to_tick; 2144 cf::cede_to_tick;
2130 2145
2131 $path = normalise $path, $origin && $origin->path; 2146 $path = normalise $path, $origin;
2132 2147
2133 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove 2148 my $guard1 = cf::lock_acquire "map_data:$path";#d#remove
2134 my $guard2 = cf::lock_acquire "map_find:$path"; 2149 my $guard2 = cf::lock_acquire "map_find:$path";
2135 2150
2136 $cf::MAP{$path} || do { 2151 $cf::MAP{$path} || do {
2176 $self->alloc; 2191 $self->alloc;
2177 2192
2178 $self->pre_load; 2193 $self->pre_load;
2179 cf::cede_to_tick; 2194 cf::cede_to_tick;
2180 2195
2196 if (exists $self->{load_path}) {
2181 my $f = new_from_file cf::object::thawer $self->{load_path}; 2197 my $f = new_from_file cf::object::thawer $self->{load_path};
2182 $f->skip_block; 2198 $f->skip_block;
2183 $self->_load_objects ($f) 2199 $self->_load_objects ($f)
2184 or return; 2200 or return;
2185 2201
2186 $self->post_load_original 2202 $self->post_load_original
2187 if delete $self->{load_original}; 2203 if delete $self->{load_original};
2188 2204
2189 if (my $uniq = $self->uniq_path) { 2205 if (my $uniq = $self->uniq_path) {
2190 utf8::encode $uniq; 2206 utf8::encode $uniq;
2191 unless (aio_stat $uniq) { 2207 unless (aio_stat $uniq) {
2192 if (my $f = new_from_file cf::object::thawer $uniq) { 2208 if (my $f = new_from_file cf::object::thawer $uniq) {
2193 $self->clear_unique_items; 2209 $self->clear_unique_items;
2194 $self->_load_objects ($f); 2210 $self->_load_objects ($f);
2195 $f->resolve_delayed_derefs; 2211 $f->resolve_delayed_derefs;
2212 }
2196 } 2213 }
2197 } 2214 }
2198 }
2199 2215
2200 $f->resolve_delayed_derefs; 2216 $f->resolve_delayed_derefs;
2217 }
2201 2218
2202 cf::cede_to_tick; 2219 cf::cede_to_tick;
2203 # now do the right thing for maps 2220 # now do the right thing for maps
2204 $self->link_multipart_objects; 2221 $self->link_multipart_objects;
2205 $self->difficulty ($self->estimate_difficulty) 2222 $self->difficulty ($self->estimate_difficulty)
2289our $MAP_PREFETCHER = undef; 2306our $MAP_PREFETCHER = undef;
2290 2307
2291sub find_async { 2308sub find_async {
2292 my ($path, $origin, $load) = @_; 2309 my ($path, $origin, $load) = @_;
2293 2310
2294 $path = normalise $path, $origin && $origin->{path}; 2311 $path = normalise $path, $origin;
2295 2312
2296 if (my $map = $cf::MAP{$path}) { 2313 if (my $map = $cf::MAP{$path}) {
2297 return $map if !$load || $map->in_memory == cf::MAP_ACTIVE; 2314 return $map if !$load || $map->in_memory == cf::MAP_ACTIVE;
2298 } 2315 }
2299 2316
2810 ($path, $x, $y) = (undef, undef, undef); 2827 ($path, $x, $y) = (undef, undef, undef);
2811 } 2828 }
2812 } 2829 }
2813 2830
2814 my $map = eval { 2831 my $map = eval {
2815 my $map = defined $path ? cf::map::find $path : undef; 2832 my $map = defined $path ? cf::map::find $path, $self->map : undef;
2816 2833
2817 if ($map) { 2834 if ($map) {
2818 $map = $map->customise_for ($self); 2835 $map = $map->customise_for ($self);
2819 $map = $check->($map, $x, $y, $self) if $check && $map; 2836 $map = $check->($map, $x, $y, $self) if $check && $map;
2820 } else { 2837 } else {
2918 2935
2919 prepare_random_map $exit 2936 prepare_random_map $exit
2920 if $exit->slaying eq "/!"; 2937 if $exit->slaying eq "/!";
2921 } 2938 }
2922 2939
2923 my $map = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; 2940 my $map = cf::map::normalise $exit->slaying, $exit->map;
2924 my $x = $exit->stats->hp; 2941 my $x = $exit->stats->hp;
2925 my $y = $exit->stats->sp; 2942 my $y = $exit->stats->sp;
2926 2943
2927 $self->goto ($map, $x, $y); 2944 $self->goto ($map, $x, $y);
2928 2945

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines