… | |
… | |
421 | |
421 | |
422 | if (my $pid = fork) { |
422 | if (my $pid = fork) { |
423 | close $fh2; |
423 | close $fh2; |
424 | |
424 | |
425 | my $res = (Coro::Handle::unblock $fh1)->readline (undef); |
425 | my $res = (Coro::Handle::unblock $fh1)->readline (undef); |
|
|
426 | warn "pst<$res>" unless $res =~ /^pst/; |
426 | $res = Coro::Storable::thaw $res; |
427 | $res = Coro::Storable::thaw $res; |
427 | |
428 | |
428 | waitpid $pid, 0; # should not block anymore, we expect the child to simply behave |
429 | waitpid $pid, 0; # should not block anymore, we expect the child to simply behave |
429 | |
430 | |
430 | die $$res unless "ARRAY" eq ref $res; |
431 | Carp::confess $$res unless "ARRAY" eq ref $res; |
431 | |
432 | |
432 | return wantarray ? @$res : $res->[-1]; |
433 | return wantarray ? @$res : $res->[-1]; |
433 | } else { |
434 | } else { |
434 | reset_signals; |
435 | reset_signals; |
435 | local $SIG{__WARN__}; |
436 | local $SIG{__WARN__}; |
436 | local $SIG{__DIE__}; |
437 | local $SIG{__DIE__}; |
|
|
438 | local $Coro::idle; |
|
|
439 | $Coro::current->prio (Coro::PRIO_MAX); |
437 | eval { |
440 | eval { |
438 | close $fh1; |
441 | close $fh1; |
439 | |
442 | |
440 | my @res = eval { $cb->(@args) }; |
443 | my @res = eval { $cb->(@args) }; |
441 | syswrite $fh2, Coro::Storable::freeze +($@ ? \"$@" : \@res); |
444 | |
|
|
445 | open my $fh, ">", \my $buf |
|
|
446 | or die "fork_call: cannot open fh-to-buf in child : $!"; |
|
|
447 | Storable::store_fd +($@ ? \"$@" : \@res), $fh; |
|
|
448 | close $fh; |
|
|
449 | |
|
|
450 | warn "writing ", length $buf; |
|
|
451 | my $x; |
|
|
452 | (length $buf) == ($x = syswrite $fh2, $buf) |
|
|
453 | or warn "error writing ".(length $buf)." != $x\n"; |
|
|
454 | close $fh2; |
442 | }; |
455 | }; |
443 | |
456 | |
444 | warn $@ if $@; |
457 | warn $@ if $@; |
445 | _exit 0; |
458 | _exit 0; |
446 | } |
459 | } |
… | |
… | |
1412 | |
1425 | |
1413 | # create single paragraphs (very hackish) |
1426 | # create single paragraphs (very hackish) |
1414 | s/(?<=\S)\n(?=\w)/ /g; |
1427 | s/(?<=\S)\n(?=\w)/ /g; |
1415 | |
1428 | |
1416 | # compress some whitespace |
1429 | # compress some whitespace |
1417 | 1 while s/\s*\n\s*\n\s*/\n/; |
1430 | s/\s+\n/\n/g; # ws line-ends |
|
|
1431 | s/\n\n+/\n/g; # double lines |
|
|
1432 | s/^\n+//; # beginning lines |
|
|
1433 | s/\n+$//; # ending lines |
1418 | |
1434 | |
1419 | $_ |
1435 | $_ |
1420 | } |
1436 | } |
1421 | |
1437 | |
1422 | sub hintmode { |
1438 | sub hintmode { |
… | |
… | |
2354 | my $hp = $exit->stats->hp; |
2370 | my $hp = $exit->stats->hp; |
2355 | my $sp = $exit->stats->sp; |
2371 | my $sp = $exit->stats->sp; |
2356 | |
2372 | |
2357 | $self->enter_link; |
2373 | $self->enter_link; |
2358 | |
2374 | |
|
|
2375 | # if exit is damned, update players death & WoR home-position |
|
|
2376 | $self->contr->savebed ($slaying, $hp, $sp) |
|
|
2377 | if $exit->flag (FLAG_DAMNED); |
|
|
2378 | |
2359 | (async { |
2379 | (async { |
2360 | $self->deactivate_recursive; # just to be sure |
2380 | $self->deactivate_recursive; # just to be sure |
2361 | unless (eval { |
2381 | unless (eval { |
2362 | $self->goto ($slaying, $hp, $sp); |
2382 | $self->goto ($slaying, $hp, $sp); |
2363 | |
2383 | |
… | |
… | |
2403 | |
2423 | |
2404 | sub cf::client::send_msg { |
2424 | sub cf::client::send_msg { |
2405 | my ($self, $color, $type, $msg, @extra) = @_; |
2425 | my ($self, $color, $type, $msg, @extra) = @_; |
2406 | |
2426 | |
2407 | $msg = $self->pl->expand_cfpod ($msg); |
2427 | $msg = $self->pl->expand_cfpod ($msg); |
|
|
2428 | |
|
|
2429 | return unless @extra || length $msg; |
2408 | |
2430 | |
2409 | if ($self->can_msg) { |
2431 | if ($self->can_msg) { |
2410 | $self->send_packet ("msg " . $self->{json_coder}->encode ([$color, $type, $msg, @extra])); |
2432 | $self->send_packet ("msg " . $self->{json_coder}->encode ([$color, $type, $msg, @extra])); |
2411 | } else { |
2433 | } else { |
2412 | # replace some tags by gcfclient-compatible ones |
2434 | # replace some tags by gcfclient-compatible ones |
… | |
… | |
2573 | |
2595 | |
2574 | =pod |
2596 | =pod |
2575 | |
2597 | |
2576 | The following functions and methods are available within a safe environment: |
2598 | The following functions and methods are available within a safe environment: |
2577 | |
2599 | |
2578 | cf::object contr pay_amount pay_player map |
2600 | cf::object |
|
|
2601 | contr pay_amount pay_player map x y force_find force_add |
|
|
2602 | insert remove |
|
|
2603 | |
2579 | cf::object::player player |
2604 | cf::object::player |
2580 | cf::player peaceful |
2605 | player |
2581 | cf::map trigger |
2606 | |
|
|
2607 | cf::player |
|
|
2608 | peaceful |
|
|
2609 | |
|
|
2610 | cf::map |
|
|
2611 | trigger |
2582 | |
2612 | |
2583 | =cut |
2613 | =cut |
2584 | |
2614 | |
2585 | for ( |
2615 | for ( |
2586 | ["cf::object" => qw(contr pay_amount pay_player map)], |
2616 | ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y |
|
|
2617 | insert remove)], |
2587 | ["cf::object::player" => qw(player)], |
2618 | ["cf::object::player" => qw(player)], |
2588 | ["cf::player" => qw(peaceful)], |
2619 | ["cf::player" => qw(peaceful)], |
2589 | ["cf::map" => qw(trigger)], |
2620 | ["cf::map" => qw(trigger)], |
2590 | ) { |
2621 | ) { |
2591 | no strict 'refs'; |
2622 | no strict 'refs'; |