… | |
… | |
354 | our @SLOT_QUEUE; |
354 | our @SLOT_QUEUE; |
355 | our $SLOT_QUEUE; |
355 | our $SLOT_QUEUE; |
356 | |
356 | |
357 | $SLOT_QUEUE->cancel if $SLOT_QUEUE; |
357 | $SLOT_QUEUE->cancel if $SLOT_QUEUE; |
358 | $SLOT_QUEUE = Coro::async { |
358 | $SLOT_QUEUE = Coro::async { |
|
|
359 | $Coro::current->desc ("timeslot manager"); |
|
|
360 | |
359 | my $signal = new Coro::Signal; |
361 | my $signal = new Coro::Signal; |
360 | |
362 | |
361 | while () { |
363 | while () { |
362 | next_job: |
364 | next_job: |
363 | my $avail = cf::till_tick; |
365 | my $avail = cf::till_tick; |
… | |
… | |
425 | my $time = Event::time; |
427 | my $time = Event::time; |
426 | |
428 | |
427 | # this is the main coro, too bad, we have to block |
429 | # this is the main coro, too bad, we have to block |
428 | # till the operation succeeds, freezing the server :/ |
430 | # till the operation succeeds, freezing the server :/ |
429 | |
431 | |
|
|
432 | LOG llevError | logBacktrace, Carp::longmess "sync job";#d# |
|
|
433 | |
430 | # TODO: use suspend/resume instead |
434 | # TODO: use suspend/resume instead |
431 | # (but this is cancel-safe) |
435 | # (but this is cancel-safe) |
432 | my $freeze_guard = freeze_mainloop; |
436 | my $freeze_guard = freeze_mainloop; |
433 | |
437 | |
434 | my $busy = 1; |
438 | my $busy = 1; |
435 | my @res; |
439 | my @res; |
436 | |
440 | |
437 | (async { |
441 | (async { |
|
|
442 | $Coro::current->desc ("sync job coro"); |
438 | @res = eval { $job->() }; |
443 | @res = eval { $job->() }; |
439 | warn $@ if $@; |
444 | warn $@ if $@; |
440 | undef $busy; |
445 | undef $busy; |
441 | })->prio (Coro::PRIO_MAX); |
446 | })->prio (Coro::PRIO_MAX); |
442 | |
447 | |
… | |
… | |
1025 | }, |
1030 | }, |
1026 | ); |
1031 | ); |
1027 | |
1032 | |
1028 | sub object_freezer_save { |
1033 | sub object_freezer_save { |
1029 | my ($filename, $rdata, $objs) = @_; |
1034 | my ($filename, $rdata, $objs) = @_; |
1030 | |
|
|
1031 | my $guard = cf::lock_acquire "io"; |
|
|
1032 | |
1035 | |
1033 | sync_job { |
1036 | sync_job { |
1034 | if (length $$rdata) { |
1037 | if (length $$rdata) { |
1035 | utf8::decode (my $decname = $filename); |
1038 | utf8::decode (my $decname = $filename); |
1036 | warn sprintf "saving %s (%d,%d)\n", |
1039 | warn sprintf "saving %s (%d,%d)\n", |
… | |
… | |
1062 | } else { |
1065 | } else { |
1063 | aio_unlink $filename; |
1066 | aio_unlink $filename; |
1064 | aio_unlink "$filename.pst"; |
1067 | aio_unlink "$filename.pst"; |
1065 | } |
1068 | } |
1066 | }; |
1069 | }; |
1067 | |
|
|
1068 | undef $guard; |
|
|
1069 | } |
1070 | } |
1070 | |
1071 | |
1071 | sub object_freezer_as_string { |
1072 | sub object_freezer_as_string { |
1072 | my ($rdata, $objs) = @_; |
1073 | my ($rdata, $objs) = @_; |
1073 | |
1074 | |
… | |
… | |
1078 | |
1079 | |
1079 | sub object_thawer_load { |
1080 | sub object_thawer_load { |
1080 | my ($filename) = @_; |
1081 | my ($filename) = @_; |
1081 | |
1082 | |
1082 | my ($data, $av); |
1083 | my ($data, $av); |
1083 | |
|
|
1084 | my $guard = cf::lock_acquire "io"; |
|
|
1085 | |
1084 | |
1086 | (aio_load $filename, $data) >= 0 |
1085 | (aio_load $filename, $data) >= 0 |
1087 | or return; |
1086 | or return; |
1088 | |
1087 | |
1089 | unless (aio_stat "$filename.pst") { |
1088 | unless (aio_stat "$filename.pst") { |
1090 | (aio_load "$filename.pst", $av) >= 0 |
1089 | (aio_load "$filename.pst", $av) >= 0 |
1091 | or return; |
1090 | or return; |
1092 | |
1091 | |
1093 | undef $guard; |
|
|
1094 | $av = eval { (Storable::thaw $av)->{objs} }; |
1092 | $av = eval { (Storable::thaw $av)->{objs} }; |
1095 | } |
1093 | } |
1096 | |
1094 | |
1097 | utf8::decode (my $decname = $filename); |
1095 | utf8::decode (my $decname = $filename); |
1098 | warn sprintf "loading %s (%d,%d)\n", |
1096 | warn sprintf "loading %s (%d,%d)\n", |
… | |
… | |
2043 | } |
2041 | } |
2044 | |
2042 | |
2045 | $MAP_PREFETCH{$path} |= $load; |
2043 | $MAP_PREFETCH{$path} |= $load; |
2046 | |
2044 | |
2047 | $MAP_PREFETCHER ||= cf::async { |
2045 | $MAP_PREFETCHER ||= cf::async { |
|
|
2046 | $Coro::current->{desc} = "map prefetcher"; |
|
|
2047 | |
2048 | while (%MAP_PREFETCH) { |
2048 | while (%MAP_PREFETCH) { |
2049 | while (my ($k, $v) = each %MAP_PREFETCH) { |
2049 | while (my ($k, $v) = each %MAP_PREFETCH) { |
2050 | if (my $map = find $k) { |
2050 | if (my $map = find $k) { |
2051 | $map->load if $v; |
2051 | $map->load if $v; |
2052 | } |
2052 | } |
… | |
… | |
2078 | return if $self->{deny_save}; |
2078 | return if $self->{deny_save}; |
2079 | |
2079 | |
2080 | local $self->{last_access} = $self->last_access;#d# |
2080 | local $self->{last_access} = $self->last_access;#d# |
2081 | |
2081 | |
2082 | cf::async { |
2082 | cf::async { |
|
|
2083 | $Coro::current->{desc} = "map player save"; |
2083 | $_->contr->save for $self->players; |
2084 | $_->contr->save for $self->players; |
2084 | }; |
2085 | }; |
2085 | |
2086 | |
2086 | if ($uniq) { |
2087 | if ($uniq) { |
2087 | $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS); |
2088 | $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS); |
… | |
… | |
2274 | =cut |
2275 | =cut |
2275 | |
2276 | |
2276 | sub deref { |
2277 | sub deref { |
2277 | my ($ref) = @_; |
2278 | my ($ref) = @_; |
2278 | |
2279 | |
2279 | # temporary compatibility#TODO#remove |
|
|
2280 | $ref =~ s{^<}{player/<}; |
|
|
2281 | |
|
|
2282 | if ($ref =~ m{^player\/(<1\.\d+>)/(.*)$}) { |
2280 | if ($ref =~ m{^player\/(<1\.[0-9a-f]+>)/(.*)$}) { |
2283 | my ($uuid, $name) = ($1, $2); |
2281 | my ($uuid, $name) = ($1, $2); |
2284 | my $pl = $cf::PLAYER_LOADING{$name} || cf::player::find $name |
2282 | my $pl = $cf::PLAYER_LOADING{$name} || cf::player::find $name |
2285 | or return; |
2283 | or return; |
2286 | $pl->ob->uuid eq $uuid |
2284 | $pl->ob->uuid eq $uuid |
2287 | or return; |
2285 | or return; |
… | |
… | |
2458 | my $gen = $self->{_goto_generation} = ++$GOTOGEN; |
2456 | my $gen = $self->{_goto_generation} = ++$GOTOGEN; |
2459 | |
2457 | |
2460 | $self->enter_link; |
2458 | $self->enter_link; |
2461 | |
2459 | |
2462 | (async { |
2460 | (async { |
|
|
2461 | $Coro::current->{desc} = "player::goto $path $x $y"; |
|
|
2462 | |
2463 | # *tag paths override both path and x|y |
2463 | # *tag paths override both path and x|y |
2464 | if ($path =~ /^\*(.*)$/) { |
2464 | if ($path =~ /^\*(.*)$/) { |
2465 | if (my @obs = grep $_->map, ext::map_tags::find $1) { |
2465 | if (my @obs = grep $_->map, ext::map_tags::find $1) { |
2466 | my $ob = $obs[rand @obs]; |
2466 | my $ob = $obs[rand @obs]; |
2467 | |
2467 | |
… | |
… | |
2584 | # if exit is damned, update players death & WoR home-position |
2584 | # if exit is damned, update players death & WoR home-position |
2585 | $self->contr->savebed ($slaying, $hp, $sp) |
2585 | $self->contr->savebed ($slaying, $hp, $sp) |
2586 | if $exit->flag (FLAG_DAMNED); |
2586 | if $exit->flag (FLAG_DAMNED); |
2587 | |
2587 | |
2588 | (async { |
2588 | (async { |
|
|
2589 | $Coro::current->{desc} = "enter_exit $slaying $hp $sp"; |
|
|
2590 | |
2589 | $self->deactivate_recursive; # just to be sure |
2591 | $self->deactivate_recursive; # just to be sure |
2590 | unless (eval { |
2592 | unless (eval { |
2591 | $self->goto ($slaying, $hp, $sp); |
2593 | $self->goto ($slaying, $hp, $sp); |
2592 | |
2594 | |
2593 | 1; |
2595 | 1; |
… | |
… | |
2630 | |
2632 | |
2631 | =cut |
2633 | =cut |
2632 | |
2634 | |
2633 | our %CHANNEL = ( |
2635 | our %CHANNEL = ( |
2634 | "c/identify" => { |
2636 | "c/identify" => { |
2635 | id => "identify", |
2637 | id => "infobox", |
2636 | title => "Identify", |
2638 | title => "Identify", |
2637 | reply => undef, |
2639 | reply => undef, |
2638 | tooltip => "Items recently identified", |
2640 | tooltip => "Items recently identified", |
2639 | }, |
2641 | }, |
2640 | "c/examine" => { |
2642 | "c/examine" => { |
2641 | id => "examine", |
2643 | id => "infobox", |
2642 | title => "Examine", |
2644 | title => "Examine", |
2643 | reply => undef, |
2645 | reply => undef, |
2644 | tooltip => "Signs and other items you examined", |
2646 | tooltip => "Signs and other items you examined", |
2645 | }, |
2647 | }, |
|
|
2648 | "c/lookat" => { |
|
|
2649 | id => "infobox", |
|
|
2650 | title => "Look", |
|
|
2651 | reply => undef, |
|
|
2652 | tooltip => "What you saw there", |
|
|
2653 | }, |
2646 | ); |
2654 | ); |
2647 | |
2655 | |
2648 | sub cf::client::send_msg { |
2656 | sub cf::client::send_msg { |
2649 | my ($self, $channel, $msg, $color, @extra) = @_; |
2657 | my ($self, $channel, $msg, $color, @extra) = @_; |
2650 | |
2658 | |
2651 | $msg = $self->pl->expand_cfpod ($msg); |
2659 | $msg = $self->pl->expand_cfpod ($msg); |
2652 | |
2660 | |
2653 | $color &= cf::NDI_CLIENT_MASK; # just in case... |
2661 | $color &= cf::NDI_CLIENT_MASK; # just in case... |
2654 | |
2662 | |
2655 | # check predefined channels, for the benefit of C |
2663 | # check predefined channels, for the benefit of C |
2656 | $channel = $CHANNEL{$channel} if $CHANNEL{$channel}; |
2664 | if ($CHANNEL{$channel}) { |
|
|
2665 | $channel = $CHANNEL{$channel}; |
2657 | |
2666 | |
|
|
2667 | $self->ext_msg (channel_info => $channel) |
|
|
2668 | if $self->can_msg; |
|
|
2669 | |
|
|
2670 | $channel = $channel->{id}; |
|
|
2671 | |
2658 | if (ref $channel) { |
2672 | } elsif (ref $channel) { |
2659 | # send meta info to client, if not yet sent |
2673 | # send meta info to client, if not yet sent |
2660 | unless (exists $self->{channel}{$channel->{id}}) { |
2674 | unless (exists $self->{channel}{$channel->{id}}) { |
2661 | $self->{channel}{$channel->{id}} = $channel; |
2675 | $self->{channel}{$channel->{id}} = $channel; |
2662 | $self->ext_msg (channel_info => $channel) |
2676 | $self->ext_msg (channel_info => $channel) |
2663 | if $self->can_msg; |
2677 | if $self->can_msg; |
… | |
… | |
3182 | sub main { |
3196 | sub main { |
3183 | # we must not ever block the main coroutine |
3197 | # we must not ever block the main coroutine |
3184 | local $Coro::idle = sub { |
3198 | local $Coro::idle = sub { |
3185 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3199 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3186 | (async { |
3200 | (async { |
|
|
3201 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3187 | Event::one_event; |
3202 | Event::one_event; |
3188 | })->prio (Coro::PRIO_MAX); |
3203 | })->prio (Coro::PRIO_MAX); |
3189 | }; |
3204 | }; |
3190 | |
3205 | |
3191 | reload_config; |
3206 | reload_config; |
… | |
… | |
3435 | register_command "reload" => sub { |
3450 | register_command "reload" => sub { |
3436 | my ($who, $arg) = @_; |
3451 | my ($who, $arg) = @_; |
3437 | |
3452 | |
3438 | if ($who->flag (FLAG_WIZ)) { |
3453 | if ($who->flag (FLAG_WIZ)) { |
3439 | $who->message ("reloading server."); |
3454 | $who->message ("reloading server."); |
|
|
3455 | async { |
|
|
3456 | $Coro::current->{desc} = "perl_reload"; |
3440 | async { reload_perl }; |
3457 | reload_perl; |
|
|
3458 | }; |
3441 | } |
3459 | } |
3442 | }; |
3460 | }; |
3443 | |
3461 | |
3444 | unshift @INC, $LIBDIR; |
3462 | unshift @INC, $LIBDIR; |
3445 | |
3463 | |
… | |
… | |
3487 | $NEXT_TICK += $TICK; |
3505 | $NEXT_TICK += $TICK; |
3488 | |
3506 | |
3489 | if ($NOW >= $NEXT_RUNTIME_WRITE) { |
3507 | if ($NOW >= $NEXT_RUNTIME_WRITE) { |
3490 | $NEXT_RUNTIME_WRITE = $NOW + 10; |
3508 | $NEXT_RUNTIME_WRITE = $NOW + 10; |
3491 | Coro::async_pool { |
3509 | Coro::async_pool { |
|
|
3510 | $Coro::current->{desc} = "runtime saver"; |
3492 | write_runtime |
3511 | write_runtime |
3493 | or warn "ERROR: unable to write runtime file: $!"; |
3512 | or warn "ERROR: unable to write runtime file: $!"; |
3494 | }; |
3513 | }; |
3495 | } |
3514 | } |
3496 | |
3515 | |
… | |
… | |
3606 | $AIO_POLL_WATCHER = Event->io ( |
3625 | $AIO_POLL_WATCHER = Event->io ( |
3607 | reentrant => 0, |
3626 | reentrant => 0, |
3608 | data => WF_AUTOCANCEL, |
3627 | data => WF_AUTOCANCEL, |
3609 | fd => IO::AIO::poll_fileno, |
3628 | fd => IO::AIO::poll_fileno, |
3610 | poll => 'r', |
3629 | poll => 'r', |
3611 | prio => 6, |
3630 | prio => 0, |
3612 | cb => \&IO::AIO::poll_cb, |
3631 | cb => \&IO::AIO::poll_cb, |
3613 | ); |
3632 | ); |
3614 | } |
3633 | } |
3615 | |
3634 | |
3616 | my $_log_backtrace; |
3635 | my $_log_backtrace; |
… | |
… | |
3622 | |
3641 | |
3623 | # limit the # of concurrent backtraces |
3642 | # limit the # of concurrent backtraces |
3624 | if ($_log_backtrace < 2) { |
3643 | if ($_log_backtrace < 2) { |
3625 | ++$_log_backtrace; |
3644 | ++$_log_backtrace; |
3626 | async { |
3645 | async { |
|
|
3646 | $Coro::current->{desc} = "abt $msg"; |
|
|
3647 | |
3627 | my @bt = fork_call { |
3648 | my @bt = fork_call { |
3628 | @addr = map { sprintf "%x", $_ } @addr; |
3649 | @addr = map { sprintf "%x", $_ } @addr; |
3629 | my $self = (-f "/proc/$$/exe") ? "/proc/$$/exe" : $^X; |
3650 | my $self = (-f "/proc/$$/exe") ? "/proc/$$/exe" : $^X; |
3630 | open my $fh, "exec addr2line -C -f -i -e \Q$self\E @addr 2>&1 |" |
3651 | open my $fh, "exec addr2line -C -f -i -e \Q$self\E @addr 2>&1 |" |
3631 | or die "addr2line: $!"; |
3652 | or die "addr2line: $!"; |