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.181 by root, Fri Jan 19 15:29:52 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 => (cf::rndm 15, 40),
1819 ysize => 10, 1818 ysize => (cf::rndm 15, 40),
1819 symmetry => (cf::rndm 1, cf::SYMMETRY_XY),
1820 #layout => string
1820 }; 1821 };
1821 1822
1822 for (split /\n/, $spec) { 1823 for (split /\n/, $spec) {
1823 my ($k, $v) = split /\s+/, $_, 2; 1824 my ($k, $v) = split /\s+/, $_, 2;
1824 1825
1828 $rmp 1829 $rmp
1829} 1830}
1830 1831
1831sub prepare_random_map { 1832sub prepare_random_map {
1832 my ($exit) = @_; 1833 my ($exit) = @_;
1834
1835 my $guard = cf::lock_acquire "exit_prepare:$exit";
1833 1836
1834 # all this does is basically replace the /! path by 1837 # all this does is basically replace the /! path by
1835 # a new random map path (?random/...) with a seed 1838 # a new random map path (?random/...) with a seed
1836 # that depends on the exit object 1839 # that depends on the exit object
1837 1840
1846 1849
1847 $rmp->{random_seed} ||= $exit->random_seed; 1850 $rmp->{random_seed} ||= $exit->random_seed;
1848 1851
1849 my $data = cf::to_json $rmp; 1852 my $data = cf::to_json $rmp;
1850 my $md5 = Digest::MD5::md5_hex $data; 1853 my $md5 = Digest::MD5::md5_hex $data;
1854 my $meta = "$cf::RANDOM_MAPS/$md5.meta";
1851 1855
1852 if (my $fh = aio_open "$cf::RANDOM_MAPS/$md5.meta", O_WRONLY | O_CREAT, 0666) { 1856 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) {
1853 aio_write $fh, 0, (length $data), $data, 0; 1857 aio_write $fh, 0, (length $data), $data, 0;
1858 undef $fh;
1859 aio_rename "$meta~", $meta;
1854 1860
1855 $exit->slaying ("?random/$md5"); 1861 $exit->slaying ("?random/$md5");
1856 $exit->msg (undef); 1862 $exit->msg (undef);
1857 } 1863 }
1858} 1864}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines