… | |
… | |
289 | |
289 | |
290 | $path = $path->as_string if ref $path; |
290 | $path = $path->as_string if ref $path; |
291 | |
291 | |
292 | my $self = bless { }, $class; |
292 | my $self = bless { }, $class; |
293 | |
293 | |
|
|
294 | # {... are special paths that are not touched |
|
|
295 | # ?xxx/... are special absolute paths |
|
|
296 | # ?random/... random maps |
|
|
297 | # /! non-realised random map exit |
|
|
298 | # /... normal maps |
|
|
299 | # ~/... per-player maps without a specific player (DO NOT USE) |
|
|
300 | # ~user/... per-player map of a specific user |
|
|
301 | |
|
|
302 | if ($path =~ /^{/) { |
|
|
303 | # fine as it is |
294 | if ($path =~ s{^\?random/}{}) { |
304 | } elsif ($path =~ s{^\?random/}{}) { |
295 | Coro::AIO::aio_load "$cf::RANDOM_MAPS/$path.meta", my $data; |
305 | Coro::AIO::aio_load "$cf::RANDOM_MAPS/$path.meta", my $data; |
296 | $self->{random} = cf::from_json $data; |
306 | $self->{random} = cf::from_json $data; |
297 | } else { |
307 | } else { |
298 | if ($path =~ s{^~([^/]+)?}{}) { |
308 | if ($path =~ s{^~([^/]+)?}{}) { |
299 | $self->{user_rel} = 1; |
309 | $self->{user_rel} = 1; |
… | |
… | |
1238 | |
1248 | |
1239 | sub reset_at { |
1249 | sub reset_at { |
1240 | my ($self) = @_; |
1250 | my ($self) = @_; |
1241 | |
1251 | |
1242 | # TODO: safety, remove and allow resettable per-player maps |
1252 | # TODO: safety, remove and allow resettable per-player maps |
1243 | return 1e100 if $self->{path}{user_rel}; |
1253 | return 1e99 if $self->{path}{user_rel}; |
1244 | return 1e100 if $self->{deny_reset}; |
1254 | return 1e99 if $self->{deny_reset}; |
1245 | |
1255 | |
1246 | my $time = $self->fixed_resettime ? $self->{instantiate_time} : $self->last_access; |
1256 | my $time = $self->fixed_resettime ? $self->{instantiate_time} : $self->last_access; |
1247 | my $to = $self->reset_timeout || $DEFAULT_RESET; |
1257 | my $to = List::Util::min $MAX_RESET, $self->reset_timeout || $DEFAULT_RESET; |
1248 | $to = $MAX_RESET if $to > $MAX_RESET; |
|
|
1249 | |
1258 | |
1250 | $time + $to |
1259 | $time + $to |
1251 | } |
1260 | } |
1252 | |
1261 | |
1253 | sub should_reset { |
1262 | sub should_reset { |
… | |
… | |
1269 | |
1278 | |
1270 | $self->unlink_save; |
1279 | $self->unlink_save; |
1271 | |
1280 | |
1272 | delete $cf::MAP{$self->path}; |
1281 | delete $cf::MAP{$self->path}; |
1273 | $self->{path} = new cf::path $new_path; |
1282 | $self->{path} = new cf::path $new_path; |
1274 | $self->path ($self->{path}->path); |
1283 | $self->path ($self->{path}->as_string); |
1275 | $cf::MAP{$self->path} = $self; |
1284 | $cf::MAP{$self->path} = $self; |
1276 | |
1285 | |
1277 | $self->save; |
1286 | $self->save; |
1278 | } |
1287 | } |
1279 | |
1288 | |
… | |
… | |
1289 | |
1298 | |
1290 | $_->clear_links_to ($self) for values %cf::MAP; |
1299 | $_->clear_links_to ($self) for values %cf::MAP; |
1291 | |
1300 | |
1292 | $self->unlink_save; |
1301 | $self->unlink_save; |
1293 | $self->destroy; |
1302 | $self->destroy; |
|
|
1303 | } |
|
|
1304 | |
|
|
1305 | my $nuke_counter = "aaaa"; |
|
|
1306 | |
|
|
1307 | sub nuke { |
|
|
1308 | my ($self) = @_; |
|
|
1309 | |
|
|
1310 | $self->{deny_save} = 1; |
|
|
1311 | $self->reset_timeout (1); |
|
|
1312 | $self->rename ("{nuke}/" . ($nuke_counter++)); |
|
|
1313 | $self->reset; # polite request, might not happen |
1294 | } |
1314 | } |
1295 | |
1315 | |
1296 | sub customise_for { |
1316 | sub customise_for { |
1297 | my ($map, $ob) = @_; |
1317 | my ($map, $ob) = @_; |
1298 | |
1318 | |