… | |
… | |
8 | use Storable; |
8 | use Storable; |
9 | use Opcode; |
9 | use Opcode; |
10 | use Safe; |
10 | use Safe; |
11 | use Safe::Hole; |
11 | use Safe::Hole; |
12 | |
12 | |
13 | use Coro 3.3 (); |
13 | use Coro 3.4 (); |
14 | use Coro::Event; |
14 | use Coro::Event; |
15 | use Coro::Timer; |
15 | use Coro::Timer; |
16 | use Coro::Signal; |
16 | use Coro::Signal; |
17 | use Coro::Semaphore; |
17 | use Coro::Semaphore; |
18 | use Coro::AIO; |
18 | use Coro::AIO; |
… | |
… | |
1113 | |
1113 | |
1114 | use Fcntl; |
1114 | use Fcntl; |
1115 | use Coro::AIO; |
1115 | use Coro::AIO; |
1116 | |
1116 | |
1117 | use overload |
1117 | use overload |
1118 | '""' => \&as_string; |
1118 | '""' => \&as_string, |
|
|
1119 | fallback => 1; |
1119 | |
1120 | |
1120 | our $MAX_RESET = 3600; |
1121 | our $MAX_RESET = 3600; |
1121 | our $DEFAULT_RESET = 3000; |
1122 | our $DEFAULT_RESET = 3000; |
1122 | |
1123 | |
1123 | sub generate_random_map { |
1124 | sub generate_random_map { |
… | |
… | |
1151 | |
1152 | |
1152 | # also paths starting with '/' |
1153 | # also paths starting with '/' |
1153 | $EXT_MAP{"cf::map"} = qr{^(?=/)}; |
1154 | $EXT_MAP{"cf::map"} = qr{^(?=/)}; |
1154 | |
1155 | |
1155 | sub thawer_merge { |
1156 | sub thawer_merge { |
|
|
1157 | my ($self, $merge) = @_; |
|
|
1158 | |
1156 | # we have to keep some variables in memory intact |
1159 | # we have to keep some variables in memory intact |
1157 | local $_[0]{path}; |
1160 | local $self->{path}; |
|
|
1161 | local $self->{load_path}; |
1158 | local $_[0]{deny_save}; |
1162 | local $self->{deny_save}; |
1159 | local $_[0]{deny_reset}; |
1163 | local $self->{deny_reset}; |
1160 | |
1164 | |
1161 | $_[0]->SUPER::thawer_merge ($_[1]); |
1165 | $self->SUPER::thawer_merge ($merge); |
1162 | } |
1166 | } |
1163 | |
1167 | |
1164 | sub normalise { |
1168 | sub normalise { |
1165 | my ($path, $base) = @_; |
1169 | my ($path, $base) = @_; |
1166 | |
1170 | |
… | |
… | |
1336 | |
1340 | |
1337 | $map->load_header |
1341 | $map->load_header |
1338 | or return; |
1342 | or return; |
1339 | |
1343 | |
1340 | if ($map->should_reset) { |
1344 | if ($map->should_reset) { |
|
|
1345 | $cf::WAIT_FOR_TICK->wait; |
1341 | $map->reset; |
1346 | $map->reset; |
1342 | undef $guard; |
1347 | undef $guard; |
1343 | $map = find $path |
1348 | $map = find $path |
1344 | or return; |
1349 | or return; |
1345 | } |
1350 | } |
… | |
… | |
1530 | my ($self) = @_; |
1535 | my ($self) = @_; |
1531 | |
1536 | |
1532 | $self->reset_at <= $cf::RUNTIME |
1537 | $self->reset_at <= $cf::RUNTIME |
1533 | } |
1538 | } |
1534 | |
1539 | |
1535 | sub rename { |
|
|
1536 | my ($self, $new_path) = @_; |
|
|
1537 | |
|
|
1538 | normalise $new_path; |
|
|
1539 | |
|
|
1540 | $self->unlink_save; |
|
|
1541 | |
|
|
1542 | delete $cf::MAP{$self->path}; |
|
|
1543 | $self->{path} = $new_path; $self->path ($self->{path}); |
|
|
1544 | $cf::MAP{$self->path} = $self; |
|
|
1545 | |
|
|
1546 | $self->save; |
|
|
1547 | } |
|
|
1548 | |
|
|
1549 | sub reset { |
1540 | sub reset { |
1550 | my ($self) = @_; |
1541 | my ($self) = @_; |
1551 | |
1542 | |
1552 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
1543 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
1553 | |
1544 | |
… | |
… | |
1570 | my $nuke_counter = "aaaa"; |
1561 | my $nuke_counter = "aaaa"; |
1571 | |
1562 | |
1572 | sub nuke { |
1563 | sub nuke { |
1573 | my ($self) = @_; |
1564 | my ($self) = @_; |
1574 | |
1565 | |
|
|
1566 | delete $cf::MAP{$self->path}; |
|
|
1567 | |
|
|
1568 | $self->unlink_save; |
|
|
1569 | |
|
|
1570 | bless $self, "cf::map"; |
|
|
1571 | delete $self->{deny_reset}; |
1575 | $self->{deny_save} = 1; |
1572 | $self->{deny_save} = 1; |
1576 | $self->reset_timeout (1); |
1573 | $self->reset_timeout (1); |
1577 | $self->rename ("{nuke}/" . ($nuke_counter++)); |
1574 | $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++)); |
|
|
1575 | |
|
|
1576 | $cf::MAP{$self->path} = $self; |
|
|
1577 | |
1578 | $self->reset; # polite request, might not happen |
1578 | $self->reset; # polite request, might not happen |
1579 | } |
1579 | } |
1580 | |
1580 | |
1581 | =item cf::map::unique_maps |
1581 | =item cf::map::unique_maps |
1582 | |
1582 | |
… | |
… | |
2228 | |
2228 | |
2229 | sub main { |
2229 | sub main { |
2230 | # we must not ever block the main coroutine |
2230 | # we must not ever block the main coroutine |
2231 | local $Coro::idle = sub { |
2231 | local $Coro::idle = sub { |
2232 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
2232 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
|
|
2233 | (async { |
2233 | async { Event::one_event }; |
2234 | Event::one_event; |
|
|
2235 | })->prio (Coro::PRIO_MAX); |
2234 | }; |
2236 | }; |
2235 | |
2237 | |
2236 | cfg_load; |
2238 | cfg_load; |
2237 | db_load; |
2239 | db_load; |
2238 | load_extensions; |
2240 | load_extensions; |
… | |
… | |
2386 | } |
2388 | } |
2387 | |
2389 | |
2388 | warn "reloaded"; |
2390 | warn "reloaded"; |
2389 | }; |
2391 | }; |
2390 | |
2392 | |
|
|
2393 | our $RELOAD_WATCHER; # used only during reload |
|
|
2394 | |
2391 | register_command "reload" => sub { |
2395 | register_command "reload" => sub { |
2392 | my ($who, $arg) = @_; |
2396 | my ($who, $arg) = @_; |
2393 | |
2397 | |
2394 | if ($who->flag (FLAG_WIZ)) { |
2398 | if ($who->flag (FLAG_WIZ)) { |
2395 | $who->message ("start of reload."); |
2399 | $who->message ("reloading server."); |
|
|
2400 | |
|
|
2401 | # doing reload synchronously and two reloads happen back-to-back, |
|
|
2402 | # coro crashes during coro_state_free->destroy here. |
|
|
2403 | |
|
|
2404 | $RELOAD_WATCHER ||= Event->timer (after => 0, data => WF_AUTOCANCEL, cb => sub { |
2396 | reload; |
2405 | reload; |
2397 | $who->message ("end of reload."); |
2406 | undef $RELOAD_WATCHER; |
|
|
2407 | }); |
2398 | } |
2408 | } |
2399 | }; |
2409 | }; |
2400 | |
2410 | |
2401 | unshift @INC, $LIBDIR; |
2411 | unshift @INC, $LIBDIR; |
2402 | |
2412 | |