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.176 by root, Sun Jan 14 22:14:35 2007 UTC vs.
Revision 1.180 by root, Fri Jan 19 00:38:02 2007 UTC

957 957
958sub exists($) { 958sub exists($) {
959 my ($login) = @_; 959 my ($login) = @_;
960 960
961 $cf::PLAYER{$login} 961 $cf::PLAYER{$login}
962 or cf::sync_job { !aio_stat $login } 962 or cf::sync_job { !aio_stat path $login }
963} 963}
964 964
965sub find($) { 965sub find($) {
966 return $cf::PLAYER{$_[0]} || do { 966 return $cf::PLAYER{$_[0]} || do {
967 my $login = $_[0]; 967 my $login = $_[0];
1121our $MAX_RESET = 3600; 1121our $MAX_RESET = 3600;
1122our $DEFAULT_RESET = 3000; 1122our $DEFAULT_RESET = 3000;
1123 1123
1124sub generate_random_map { 1124sub generate_random_map {
1125 my ($self, $rmp) = @_; 1125 my ($self, $rmp) = @_;
1126
1127 # mit "rum" bekleckern, nicht 1126 # mit "rum" bekleckern, nicht
1128 $self->_create_random_map ( 1127 $self->_create_random_map (
1129 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle}, 1128 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle},
1130 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, 1129 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle},
1131 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map}, 1130 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map},
1813 1812
1814sub parse_random_map_params { 1813sub parse_random_map_params {
1815 my ($spec) = @_; 1814 my ($spec) = @_;
1816 1815
1817 my $rmp = { # defaults 1816 my $rmp = { # defaults
1818 xsize => 10, 1817 xsize => -1,
1819 ysize => 10, 1818 ysize => -1,
1820 }; 1819 };
1821 1820
1822 for (split /\n/, $spec) { 1821 for (split /\n/, $spec) {
1823 my ($k, $v) = split /\s+/, $_, 2; 1822 my ($k, $v) = split /\s+/, $_, 2;
1824 1823
1828 $rmp 1827 $rmp
1829} 1828}
1830 1829
1831sub prepare_random_map { 1830sub prepare_random_map {
1832 my ($exit) = @_; 1831 my ($exit) = @_;
1832
1833 my $guard = cf::lock_acquire "exit_prepare:$exit";
1833 1834
1834 # all this does is basically replace the /! path by 1835 # all this does is basically replace the /! path by
1835 # a new random map path (?random/...) with a seed 1836 # a new random map path (?random/...) with a seed
1836 # that depends on the exit object 1837 # that depends on the exit object
1837 1838
1846 1847
1847 $rmp->{random_seed} ||= $exit->random_seed; 1848 $rmp->{random_seed} ||= $exit->random_seed;
1848 1849
1849 my $data = cf::to_json $rmp; 1850 my $data = cf::to_json $rmp;
1850 my $md5 = Digest::MD5::md5_hex $data; 1851 my $md5 = Digest::MD5::md5_hex $data;
1852 my $meta = "$cf::RANDOM_MAPS/$md5.meta";
1851 1853
1852 if (my $fh = aio_open "$cf::RANDOM_MAPS/$md5.meta", O_WRONLY | O_CREAT, 0666) { 1854 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) {
1853 aio_write $fh, 0, (length $data), $data, 0; 1855 aio_write $fh, 0, (length $data), $data, 0;
1856 undef $fh;
1857 aio_rename "$meta~", $meta;
1854 1858
1855 $exit->slaying ("?random/$md5"); 1859 $exit->slaying ("?random/$md5");
1856 $exit->msg (undef); 1860 $exit->msg (undef);
1857 } 1861 }
1858} 1862}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines