… | |
… | |
52 | |
52 | |
53 | 1 |
53 | 1 |
54 | } |
54 | } |
55 | |
55 | |
56 | sub clean_random_maps { |
56 | sub clean_random_maps { |
|
|
57 | my $files = Coro::AIO::aio_readdir $cf::RANDOM_MAPS |
|
|
58 | or return; |
|
|
59 | |
|
|
60 | my $META_TIMEOUT = $cf::CFG{map_random_meta_timeout} || 86400 * 7; |
|
|
61 | my $MAP_TIMEOUT = $cf::CFG{map_random_map_timeout} || 3600 * 6; |
|
|
62 | |
|
|
63 | for my $file (@$files) { |
|
|
64 | next if $file =~ /\.pst$/; |
|
|
65 | |
|
|
66 | Coro::AIO::aio_stat "$cf::RANDOM_MAPS/$file" |
|
|
67 | and next; |
|
|
68 | |
|
|
69 | my $age = $cf::NOW - (stat _)[8]; |
|
|
70 | |
|
|
71 | if ($file =~ /\.meta$/) { |
|
|
72 | if ($age > $META_TIMEOUT) { |
|
|
73 | warn "resetting random meta data for $file"; |
|
|
74 | IO::AIO::aio_unlink "$cf::RANDOM_MAPS/$file"; |
|
|
75 | } |
|
|
76 | } else { |
|
|
77 | if ($age > $MAP_TIMEOUT) { |
|
|
78 | warn "resetting random map $file"; |
|
|
79 | IO::AIO::aioreq_pri 4; IO::AIO::aio_unlink "$cf::RANDOM_MAPS/$file"; |
|
|
80 | IO::AIO::aioreq_pri 4; IO::AIO::aio_unlink "$cf::RANDOM_MAPS/$file.pst"; |
|
|
81 | } |
|
|
82 | } |
|
|
83 | } |
|
|
84 | } |
|
|
85 | |
|
|
86 | # clean up old temp maps regularly |
|
|
87 | Event->timer ( |
|
|
88 | reentrant => 0, |
|
|
89 | data => cf::WF_AUTOCANCEL, |
|
|
90 | interval => 3600, |
|
|
91 | after => 60, |
|
|
92 | cb => Coro::unblock_sub { clean_random_maps }, |
|
|
93 | ); |
|
|
94 | |
|
|
95 | # map generator stresstest, never enable under normal circumstances |
|
|
96 | if (0) { |
57 | cf::async { |
97 | cf::async { |
58 | my $files = Coro::AIO::aio_readdir $cf::RANDOM_MAPS |
98 | my $seed = 0; |
59 | or return; |
99 | while () { |
60 | |
100 | my $map = cf::map::new; |
61 | my $META_TIMEOUT = $cf::CFG{map_random_meta_timeout} || 86400 * 7; |
101 | $map->generate_random_map ({ |
62 | my $MAP_TIMEOUT = $cf::CFG{map_random_map_timeout} || 3600 * 6; |
102 | region => "scorn", |
63 | |
103 | random_seed => $seed++, |
64 | for my $file (@$files) { |
104 | xsize => 12, |
65 | next if $file =~ /\.pst$/; |
105 | ysize => 12, |
66 | |
|
|
67 | Coro::AIO::aio_stat "$cf::RANDOM_MAPS/$file" |
|
|
68 | and next; |
|
|
69 | |
|
|
70 | my $age = $cf::NOW - (stat _)[8]; |
|
|
71 | |
|
|
72 | if ($file =~ /\.meta$/) { |
|
|
73 | if ($age > $META_TIMEOUT) { |
|
|
74 | warn "resetting random meta data for $file"; |
|
|
75 | IO::AIO::aio_unlink "$cf::RANDOM_MAPS/$file"; |
|
|
76 | } |
|
|
77 | } else { |
|
|
78 | if ($age > $MAP_TIMEOUT) { |
|
|
79 | warn "resetting random map $file"; |
|
|
80 | IO::AIO::aioreq_pri 4; IO::AIO::aio_unlink "$cf::RANDOM_MAPS/$file"; |
|
|
81 | IO::AIO::aioreq_pri 4; IO::AIO::aio_unlink "$cf::RANDOM_MAPS/$file.pst"; |
|
|
82 | } |
|
|
83 | } |
106 | }); |
|
|
107 | warn sprintf "%d: %d %d\n", $seed, $map->width, $map->height;#d# |
|
|
108 | $map->destroy; |
84 | } |
109 | } |
85 | }; |
110 | }; |
86 | } |
111 | } |
87 | |
112 | |
88 | # clean up old temp maps regularly |
|
|
89 | Event->timer ( |
|
|
90 | data => cf::WF_AUTOCANCEL, |
|
|
91 | interval => 3600, |
|
|
92 | after => 600, |
|
|
93 | cb => \&clean_random_maps, |
|
|
94 | ); |
|
|
95 | |
|
|
96 | 1 |
113 | 1 |
97 | |
114 | |