… | |
… | |
357 | our $json_coder = JSON::XS->new->utf8->max_size (1e6); # accept ~1mb max |
357 | our $json_coder = JSON::XS->new->utf8->max_size (1e6); # accept ~1mb max |
358 | |
358 | |
359 | sub encode_json($) { $json_coder->encode ($_[0]) } |
359 | sub encode_json($) { $json_coder->encode ($_[0]) } |
360 | sub decode_json($) { $json_coder->decode ($_[0]) } |
360 | sub decode_json($) { $json_coder->decode ($_[0]) } |
361 | |
361 | |
|
|
362 | =item $ref = cf::yaml_load $scalar |
|
|
363 | |
|
|
364 | Same as YAML::XS::Load, but doesn't leak, because it forks (and thus blocks). |
|
|
365 | |
|
|
366 | =cut |
|
|
367 | |
|
|
368 | sub fork_call(&@); |
|
|
369 | |
|
|
370 | sub yaml_load($) { |
|
|
371 | fork_call { YAML::XS::Load $_[0] } @_ |
|
|
372 | } |
|
|
373 | |
362 | =item cf::post_init { BLOCK } |
374 | =item cf::post_init { BLOCK } |
363 | |
375 | |
364 | Execute the given codeblock, I<after> all extensions have been (re-)loaded, |
376 | Execute the given codeblock, I<after> all extensions have been (re-)loaded, |
365 | but I<before> the server starts ticking again. |
377 | but I<before> the server starts ticking again. |
366 | |
378 | |
367 | The cdoeblock will have a single boolean argument to indicate whether this |
379 | The codeblock will have a single boolean argument to indicate whether this |
368 | is a reload or not. |
380 | is a reload or not. |
369 | |
381 | |
370 | =cut |
382 | =cut |
371 | |
383 | |
372 | sub post_init(&) { |
384 | sub post_init(&) { |
… | |
… | |
583 | $EXT_CORO{$coro+0} = $coro; |
595 | $EXT_CORO{$coro+0} = $coro; |
584 | |
596 | |
585 | $coro |
597 | $coro |
586 | } |
598 | } |
587 | |
599 | |
588 | =item fork_call { }, $args |
600 | =item fork_call { }, @args |
589 | |
601 | |
590 | Executes the given code block with the given arguments in a seperate |
602 | Executes the given code block with the given arguments in a seperate |
591 | process, returning the results. Everything must be serialisable with |
603 | process, returning the results. Everything must be serialisable with |
592 | Coro::Storable. May, of course, block. Note that the executed sub may |
604 | Coro::Storable. May, of course, block. Note that the executed sub may |
593 | never block itself or use any form of event handling. |
605 | never block itself or use any form of event handling. |
… | |
… | |
606 | # TODO: investigate and fix (likely this will be rather laborious) |
618 | # TODO: investigate and fix (likely this will be rather laborious) |
607 | |
619 | |
608 | my @res = Coro::Util::fork_eval { |
620 | my @res = Coro::Util::fork_eval { |
609 | cf::post_fork; |
621 | cf::post_fork; |
610 | &$cb |
622 | &$cb |
611 | }, @args; |
623 | } @args; |
612 | |
624 | |
613 | wantarray ? @res : $res[-1] |
625 | wantarray ? @res : $res[-1] |
614 | } |
626 | } |
615 | |
627 | |
616 | sub objinfo { |
628 | sub objinfo { |
… | |
… | |
3554 | |
3566 | |
3555 | 0 < aio_load "$CONFDIR/config", my $config |
3567 | 0 < aio_load "$CONFDIR/config", my $config |
3556 | or die "$CONFDIR/config: $!"; |
3568 | or die "$CONFDIR/config: $!"; |
3557 | |
3569 | |
3558 | utf8::decode $config; |
3570 | utf8::decode $config; |
3559 | |
3571 | *CFG = yaml_load $config; |
3560 | cf::get_slot 0.1, 10, "reload_config"; # yaml might be slow... |
|
|
3561 | *CFG = YAML::XS::Load $config; |
|
|
3562 | |
3572 | |
3563 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; |
3573 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; |
3564 | |
3574 | |
3565 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3575 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3566 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
3576 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |