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.113 by root, Mon Jan 1 15:32:40 2007 UTC vs.
Revision 1.117 by root, Mon Jan 1 17:50:26 2007 UTC

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;
1133 $map->per_player (0) if $path->{user_rel}; 1143 $map->per_player (0) if $path->{user_rel};
1134 } 1144 }
1135 1145
1136 $map->path ($key); 1146 $map->path ($key);
1137 $map->{path} = $path; 1147 $map->{path} = $path;
1148 $map->{last_save} = $cf::RUNTIME;
1138 $map->last_access ($cf::RUNTIME); 1149 $map->last_access ($cf::RUNTIME);
1139 1150
1140 if ($map->should_reset) { 1151 if ($map->should_reset) {
1141 $map->reset; 1152 $map->reset;
1142 $map = find_map $path; 1153 $map = find_map $path;
1203} 1214}
1204 1215
1205sub save { 1216sub save {
1206 my ($self) = @_; 1217 my ($self) = @_;
1207 1218
1219 $self->{last_save} = $cf::RUNTIME;
1220
1221 return unless $self->dirty;
1222
1208 my $save = $self->{path}->save_path; utf8::encode $save; 1223 my $save = $self->{path}->save_path; utf8::encode $save;
1209 my $uniq = $self->{path}->uniq_path; utf8::encode $uniq; 1224 my $uniq = $self->{path}->uniq_path; utf8::encode $uniq;
1210
1211 $self->{last_save} = $cf::RUNTIME;
1212
1213 return unless $self->dirty;
1214 1225
1215 $self->{load_path} = $save; 1226 $self->{load_path} = $save;
1216 1227
1217 return if $self->{deny_save}; 1228 return if $self->{deny_save};
1218 1229
1238 1249
1239sub reset_at { 1250sub reset_at {
1240 my ($self) = @_; 1251 my ($self) = @_;
1241 1252
1242 # TODO: safety, remove and allow resettable per-player maps 1253 # TODO: safety, remove and allow resettable per-player maps
1243 return 1e100 if $self->{path}{user_rel}; 1254 return 1e99 if $self->{path}{user_rel};
1244 return 1e100 if $self->{deny_reset}; 1255 return 1e99 if $self->{deny_reset};
1245 1256
1246 my $time = $self->fixed_resettime ? $self->{instantiate_time} : $self->last_access; 1257 my $time = $self->fixed_resettime ? $self->{instantiate_time} : $self->last_access;
1247 my $to = $self->reset_timeout || $DEFAULT_RESET; 1258 my $to = List::Util::min $MAX_RESET, $self->reset_timeout || $DEFAULT_RESET;
1248 $to = $MAX_RESET if $to > $MAX_RESET;
1249 1259
1250 $time + $to 1260 $time + $to
1251} 1261}
1252 1262
1253sub should_reset { 1263sub should_reset {
1269 1279
1270 $self->unlink_save; 1280 $self->unlink_save;
1271 1281
1272 delete $cf::MAP{$self->path}; 1282 delete $cf::MAP{$self->path};
1273 $self->{path} = new cf::path $new_path; 1283 $self->{path} = new cf::path $new_path;
1274 $self->path ($self->{path}->path); 1284 $self->path ($self->{path}->as_string);
1275 $cf::MAP{$self->path} = $self; 1285 $cf::MAP{$self->path} = $self;
1276 1286
1277 $self->save; 1287 $self->save;
1278} 1288}
1279 1289
1289 1299
1290 $_->clear_links_to ($self) for values %cf::MAP; 1300 $_->clear_links_to ($self) for values %cf::MAP;
1291 1301
1292 $self->unlink_save; 1302 $self->unlink_save;
1293 $self->destroy; 1303 $self->destroy;
1304}
1305
1306my $nuke_counter = "aaaa";
1307
1308sub nuke {
1309 my ($self) = @_;
1310
1311 $self->{deny_save} = 1;
1312 $self->reset_timeout (1);
1313 $self->rename ("{nuke}/" . ($nuke_counter++));
1314 $self->reset; # polite request, might not happen
1294} 1315}
1295 1316
1296sub customise_for { 1317sub customise_for {
1297 my ($map, $ob) = @_; 1318 my ($map, $ob) = @_;
1298 1319
1363 (ref $cf::CFG{"may_$access"} 1384 (ref $cf::CFG{"may_$access"}
1364 ? scalar grep $self->name eq $_, @{$cf::CFG{"may_$access"}} 1385 ? scalar grep $self->name eq $_, @{$cf::CFG{"may_$access"}}
1365 : $cf::CFG{"may_$access"}) 1386 : $cf::CFG{"may_$access"})
1366} 1387}
1367 1388
1389=item $player_object->enter_link
1390
1391Freezes the player and moves him/her to a special map (C<{link}>).
1392
1393The player should be reaosnably safe there for short amounts of time. You
1394I<MUST> call C<leave_link> as soon as possible, though.
1395
1396=item $player_object->leave_link ($map, $x, $y)
1397
1398Moves the player out of the specila link map onto the given map. If the
1399map is not valid (or omitted), the player will be moved back to the
1400location he/she was before the call to C<enter_link>, or, if that fails,
1401to the emergency map position.
1402
1403Might block.
1404
1405=cut
1406
1368sub cf::object::player::enter_link { 1407sub cf::object::player::enter_link {
1369 my ($self) = @_; 1408 my ($self) = @_;
1370 1409
1371 return if $self->map == $LINK_MAP; 1410 return if $self->map == $LINK_MAP;
1372 1411
1381 my ($self, $map, $x, $y) = @_; 1420 my ($self, $map, $x, $y) = @_;
1382 1421
1383 my $link_pos = delete $self->{_link_pos}; 1422 my $link_pos = delete $self->{_link_pos};
1384 1423
1385 unless ($map) { 1424 unless ($map) {
1386 $self->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED);
1387
1388 # restore original map position 1425 # restore original map position
1389 ($map, $x, $y) = @{ $link_pos || [] }; 1426 ($map, $x, $y) = @{ $link_pos || [] };
1390 $map = cf::map::find_map $map; 1427 $map = cf::map::find_map $map;
1391 1428
1392 unless ($map) { 1429 unless ($map) {
1424 my $map = cf::map::find_map $path->as_string; 1461 my $map = cf::map::find_map $path->as_string;
1425 $map = $map->customise_for ($self) if $map; 1462 $map = $map->customise_for ($self) if $map;
1426 1463
1427 warn "entering ", $map->path, " at ($x, $y)\n" 1464 warn "entering ", $map->path, " at ($x, $y)\n"
1428 if $map; 1465 if $map;
1466
1467 $map or $self->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED);
1429 1468
1430 $self->leave_link ($map, $x, $y); 1469 $self->leave_link ($map, $x, $y);
1431 })->prio (1); 1470 })->prio (1);
1432} 1471}
1433 1472
1844} 1883}
1845 1884
1846sub main { 1885sub main {
1847 # we must not ever block the main coroutine 1886 # we must not ever block the main coroutine
1848 local $Coro::idle = sub { 1887 local $Coro::idle = sub {
1849 Carp::cluck "FATAL: Coro::idle was called, major BUG\n";#d# 1888 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
1850 (Coro::unblock_sub { 1889 (Coro::unblock_sub {
1851 Event::one_event; 1890 Event::one_event;
1852 })->(); 1891 })->();
1853 }; 1892 };
1854 1893

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines