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.192 by root, Wed Jan 24 01:43:01 2007 UTC vs.
Revision 1.199 by root, Mon Jan 29 14:46:01 2007 UTC

8use Storable; 8use Storable;
9use Opcode; 9use Opcode;
10use Safe; 10use Safe;
11use Safe::Hole; 11use Safe::Hole;
12 12
13use Coro 3.4 (); 13use Coro 3.5 ();
14use Coro::Event; 14use Coro::Event;
15use Coro::Timer; 15use Coro::Timer;
16use Coro::Signal; 16use Coro::Signal;
17use Coro::Semaphore; 17use Coro::Semaphore;
18use Coro::AIO; 18use Coro::AIO;
82mkdir cf::localdir . "/" . cf::tmpdir; 82mkdir cf::localdir . "/" . cf::tmpdir;
83mkdir cf::localdir . "/" . cf::uniquedir; 83mkdir cf::localdir . "/" . cf::uniquedir;
84mkdir $RANDOM_MAPS; 84mkdir $RANDOM_MAPS;
85 85
86our $EMERGENCY_POSITION; 86our $EMERGENCY_POSITION;
87
88sub cf::map::normalise;
87 89
88############################################################################# 90#############################################################################
89 91
90=head2 GLOBAL VARIABLES 92=head2 GLOBAL VARIABLES
91 93
1078 for (@$files) { 1080 for (@$files) {
1079 utf8::decode $_; 1081 utf8::decode $_;
1080 next if /\.(?:pl|pst)$/; 1082 next if /\.(?:pl|pst)$/;
1081 next unless /^$PATH_SEP/o; 1083 next unless /^$PATH_SEP/o;
1082 1084
1083 s/\.map$//;
1084 push @paths, "~" . $pl->ob->name . "/" . $_; 1085 push @paths, cf::map::normalise "~" . $pl->ob->name . "/" . $_;
1085 } 1086 }
1086 1087
1087 \@paths 1088 \@paths
1088} 1089}
1089 1090
1178sub normalise { 1179sub normalise {
1179 my ($path, $base) = @_; 1180 my ($path, $base) = @_;
1180 1181
1181 $path = "$path"; # make sure its a string 1182 $path = "$path"; # make sure its a string
1182 1183
1184 $path =~ s/\.map$//;
1185
1183 # map plan: 1186 # map plan:
1184 # 1187 #
1185 # /! non-realised random map exit (special hack!) 1188 # /! non-realised random map exit (special hack!)
1186 # {... are special paths that are not being touched 1189 # {... are special paths that are not being touched
1187 # ?xxx/... are special absolute paths 1190 # ?xxx/... are special absolute paths
1362 $map->{last_save} = $cf::RUNTIME; 1365 $map->{last_save} = $cf::RUNTIME;
1363 1366
1364 $map->load_header 1367 $map->load_header
1365 or return; 1368 or return;
1366 1369
1367 if ($map->should_reset) { 1370 if ($map->should_reset && 0) {#d#TODO# disabled, crashy (locking issue?)
1368 # doing this can freeze the server in a sync job, obviously 1371 # doing this can freeze the server in a sync job, obviously
1369 #$cf::WAIT_FOR_TICK->wait; 1372 #$cf::WAIT_FOR_TICK->wait;
1370 $map->reset; 1373 $map->reset;
1371 undef $guard; 1374 undef $guard;
1372 return find $path; 1375 return find $path;
1379sub pre_load { } 1382sub pre_load { }
1380sub post_load { } 1383sub post_load { }
1381 1384
1382sub load { 1385sub load {
1383 my ($self) = @_; 1386 my ($self) = @_;
1387
1388 local $self->{deny_reset} = 1; # loading can take a long time
1384 1389
1385 my $path = $self->{path}; 1390 my $path = $self->{path};
1386 my $guard = cf::lock_acquire "map_load:$path"; 1391 my $guard = cf::lock_acquire "map_load:$path";
1387 1392
1388 return if $self->in_memory != cf::MAP_SWAPPED; 1393 return if $self->in_memory != cf::MAP_SWAPPED;
1626 for (@$files) { 1631 for (@$files) {
1627 utf8::decode $_; 1632 utf8::decode $_;
1628 next if /\.pst$/; 1633 next if /\.pst$/;
1629 next unless /^$PATH_SEP/o; 1634 next unless /^$PATH_SEP/o;
1630 1635
1631 s/\.map$//; 1636 push @paths, cf::map::normalise $_;
1632 push @paths, $_;
1633 } 1637 }
1634 1638
1635 \@paths 1639 \@paths
1636} 1640}
1637 1641
1731=cut 1735=cut
1732 1736
1733sub link_map { 1737sub link_map {
1734 unless ($LINK_MAP) { 1738 unless ($LINK_MAP) {
1735 $LINK_MAP = cf::map::find "{link}" 1739 $LINK_MAP = cf::map::find "{link}"
1736 or do { warn "FATAL: unable to provide {link} map, exiting."; exit 1 }; 1740 or cf::cleanup "FATAL: unable to provide {link} map, exiting.";
1737 $LINK_MAP->load; 1741 $LINK_MAP->load;
1738 } 1742 }
1739 1743
1740 $LINK_MAP 1744 $LINK_MAP
1741} 1745}
1748 return if UNIVERSAL::isa $self->map, "ext::map_link"; 1752 return if UNIVERSAL::isa $self->map, "ext::map_link";
1749 1753
1750 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] 1754 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y]
1751 if $self->map; 1755 if $self->map;
1752 1756
1753 $self->enter_map ($LINK_MAP || link_map, 20, 20); 1757 $self->enter_map ($LINK_MAP || link_map, 10, 10);
1754} 1758}
1755 1759
1756sub cf::object::player::leave_link { 1760sub cf::object::player::leave_link {
1757 my ($self, $map, $x, $y) = @_; 1761 my ($self, $map, $x, $y) = @_;
1758 1762
1825 my ($self, $path, $x, $y) = @_; 1829 my ($self, $path, $x, $y) = @_;
1826 1830
1827 $self->enter_link; 1831 $self->enter_link;
1828 1832
1829 (async { 1833 (async {
1834 my $map = eval {
1830 my $map = cf::map::find $path; 1835 my $map = cf::map::find $path;
1831 $map = $map->customise_for ($self) if $map; 1836 $map = $map->customise_for ($self) if $map;
1832 1837 $map
1833# warn "entering ", $map->path, " at ($x, $y)\n" 1838 } or
1834# if $map;
1835
1836 $map or $self->message ("The exit to '" . ($path->visible_name) . "' is closed", cf::NDI_UNIQUE | cf::NDI_RED); 1839 $self->message ("The exit to '$path' is closed", cf::NDI_UNIQUE | cf::NDI_RED);
1837 1840
1838 $self->leave_link ($map, $x, $y); 1841 $self->leave_link ($map, $x, $y);
1839 })->prio (1); 1842 })->prio (1);
1840} 1843}
1841 1844
1872 # that depends on the exit object 1875 # that depends on the exit object
1873 1876
1874 my $rmp = parse_random_map_params $exit->msg; 1877 my $rmp = parse_random_map_params $exit->msg;
1875 1878
1876 if ($exit->map) { 1879 if ($exit->map) {
1877 $rmp->{region} = $exit->map->region_name; 1880 $rmp->{region} = $exit->region->name;
1878 $rmp->{origin_map} = $exit->map->path; 1881 $rmp->{origin_map} = $exit->map->path;
1879 $rmp->{origin_x} = $exit->x; 1882 $rmp->{origin_x} = $exit->x;
1880 $rmp->{origin_y} = $exit->y; 1883 $rmp->{origin_y} = $exit->y;
1881 } 1884 }
1882 1885
1899sub cf::object::player::enter_exit { 1902sub cf::object::player::enter_exit {
1900 my ($self, $exit) = @_; 1903 my ($self, $exit) = @_;
1901 1904
1902 return unless $self->type == cf::PLAYER; 1905 return unless $self->type == cf::PLAYER;
1903 1906
1907 if ($exit->slaying eq "/!") {
1908 #TODO: this should de-fi-ni-te-ly not be a sync-job
1909 cf::sync_job { prepare_random_map $exit };
1910 }
1911
1912 my $slaying = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path;
1913 my $hp = $exit->stats->hp;
1914 my $sp = $exit->stats->sp;
1915
1904 $self->enter_link; 1916 $self->enter_link;
1905 1917
1906 (async { 1918 (async {
1907 $self->deactivate_recursive; # just to be sure 1919 $self->deactivate_recursive; # just to be sure
1908 unless (eval { 1920 unless (eval {
1909 prepare_random_map $exit 1921 $self->goto ($slaying, $hp, $sp);
1910 if $exit->slaying eq "/!";
1911
1912 my $path = new_from_path cf::map $exit->slaying, $exit->map && $exit->map->path;
1913 $self->goto ($path, $exit->stats->hp, $exit->stats->sp);
1914 1922
1915 1; 1923 1;
1916 }) { 1924 }) {
1917 $self->message ("Something went wrong deep within the crossfire server. " 1925 $self->message ("Something went wrong deep within the crossfire server. "
1918 . "I'll try to bring you back to the map you were before. " 1926 . "I'll try to bring you back to the map you were before. "

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines