… | |
… | |
2332 | } |
2332 | } |
2333 | |
2333 | |
2334 | ############################################################################# |
2334 | ############################################################################# |
2335 | # the server's init and main functions |
2335 | # the server's init and main functions |
2336 | |
2336 | |
2337 | sub load_facedata { |
2337 | sub load_facedata($) { |
2338 | my $path = sprintf "%s/facedata", cf::datadir; |
2338 | my ($path) = @_; |
2339 | |
2339 | |
2340 | warn "loading facedata from $path\n"; |
2340 | warn "loading facedata from $path\n"; |
2341 | |
2341 | |
2342 | my $facedata; |
2342 | my $facedata; |
2343 | 0 < aio_load $path, $facedata |
2343 | 0 < aio_load $path, $facedata |
… | |
… | |
2384 | } |
2384 | } |
2385 | |
2385 | |
2386 | 1 |
2386 | 1 |
2387 | } |
2387 | } |
2388 | |
2388 | |
|
|
2389 | sub reload_facedata { |
|
|
2390 | load_facedata sprintf "%s/facedata", cf::datadir |
|
|
2391 | or die "unable to load facedata\n"; |
|
|
2392 | } |
|
|
2393 | |
|
|
2394 | sub reload_regions { |
|
|
2395 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
|
|
2396 | or die "unable to load regions file\n"; |
|
|
2397 | } |
|
|
2398 | |
2389 | sub load_archetypes { |
2399 | sub reload_archetypes { |
2390 | load_archetype_file sprintf "%s/archetypes", cf::datadir; # remove when stable |
|
|
2391 | load_archetype_file sprintf "%s/archetypes", cf::datadir |
2400 | load_archetype_file sprintf "%s/archetypes", cf::datadir |
|
|
2401 | or die "unable to load archetypes\n"; |
2392 | } |
2402 | } |
2393 | |
2403 | |
2394 | sub load_treasures { |
2404 | sub reload_treasures { |
2395 | load_treasure_file sprintf "%s/treasures", cf::datadir |
2405 | load_treasure_file sprintf "%s/treasures", cf::datadir |
|
|
2406 | or die "unable to load treasurelists\n"; |
2396 | } |
2407 | } |
2397 | |
2408 | |
2398 | sub reload_resources { |
2409 | sub reload_resources { |
2399 | warn "reloading resource files...\n"; |
2410 | warn "reloading resource files...\n"; |
2400 | |
2411 | |
2401 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2412 | reload_regions; |
2402 | or die "unable to load regions file\n"; |
|
|
2403 | load_facedata |
2413 | reload_facedata; |
2404 | or die "unable to load facedata\n"; |
|
|
2405 | load_archetypes |
2414 | reload_archetypes; |
2406 | or die "unable to load archetypes\n"; |
|
|
2407 | load_treasures |
2415 | reload_treasures; |
2408 | or die "unable to load treasurelists\n"; |
|
|
2409 | |
2416 | |
2410 | warn "finished reloading resource files\n"; |
2417 | warn "finished reloading resource files\n"; |
2411 | } |
2418 | } |
2412 | |
2419 | |
2413 | sub init { |
2420 | sub init { |
… | |
… | |
2508 | |
2515 | |
2509 | warn Carp::longmess "post_cleanup backtrace" |
2516 | warn Carp::longmess "post_cleanup backtrace" |
2510 | if $make_core; |
2517 | if $make_core; |
2511 | } |
2518 | } |
2512 | |
2519 | |
2513 | sub reload() { |
2520 | sub do_reload_perl() { |
2514 | # can/must only be called in main |
2521 | # can/must only be called in main |
2515 | if ($Coro::current != $Coro::main) { |
2522 | if ($Coro::current != $Coro::main) { |
2516 | warn "can only reload from main coroutine"; |
2523 | warn "can only reload from main coroutine"; |
2517 | return; |
2524 | return; |
2518 | } |
2525 | } |
… | |
… | |
2617 | warn "reattaching attachments to maps"; |
2624 | warn "reattaching attachments to maps"; |
2618 | reattach $_ for values %MAP; |
2625 | reattach $_ for values %MAP; |
2619 | warn "reattaching attachments to players"; |
2626 | warn "reattaching attachments to players"; |
2620 | reattach $_ for values %PLAYER; |
2627 | reattach $_ for values %PLAYER; |
2621 | |
2628 | |
2622 | warn "loading reloadable resources"; |
|
|
2623 | reload_resources; |
|
|
2624 | |
|
|
2625 | warn "leaving sync_job"; |
2629 | warn "leaving sync_job"; |
2626 | |
2630 | |
2627 | 1 |
2631 | 1 |
2628 | } or do { |
2632 | } or do { |
2629 | warn $@; |
2633 | warn $@; |
… | |
… | |
2634 | warn "reloaded"; |
2638 | warn "reloaded"; |
2635 | }; |
2639 | }; |
2636 | |
2640 | |
2637 | our $RELOAD_WATCHER; # used only during reload |
2641 | our $RELOAD_WATCHER; # used only during reload |
2638 | |
2642 | |
|
|
2643 | sub reload_perl() { |
|
|
2644 | # doing reload synchronously and two reloads happen back-to-back, |
|
|
2645 | # coro crashes during coro_state_free->destroy here. |
|
|
2646 | |
|
|
2647 | $RELOAD_WATCHER ||= Event->timer ( |
|
|
2648 | reentrant => 0, |
|
|
2649 | after => 0, |
|
|
2650 | data => WF_AUTOCANCEL, |
|
|
2651 | cb => sub { |
|
|
2652 | do_reload_perl; |
|
|
2653 | undef $RELOAD_WATCHER; |
|
|
2654 | }, |
|
|
2655 | ); |
|
|
2656 | } |
|
|
2657 | |
2639 | register_command "reload" => sub { |
2658 | register_command "reload" => sub { |
2640 | my ($who, $arg) = @_; |
2659 | my ($who, $arg) = @_; |
2641 | |
2660 | |
2642 | if ($who->flag (FLAG_WIZ)) { |
2661 | if ($who->flag (FLAG_WIZ)) { |
2643 | $who->message ("reloading server."); |
2662 | $who->message ("reloading server."); |
2644 | |
2663 | async { reload_perl }; |
2645 | # doing reload synchronously and two reloads happen back-to-back, |
|
|
2646 | # coro crashes during coro_state_free->destroy here. |
|
|
2647 | |
|
|
2648 | $RELOAD_WATCHER ||= Event->timer ( |
|
|
2649 | reentrant => 0, |
|
|
2650 | after => 0, |
|
|
2651 | data => WF_AUTOCANCEL, |
|
|
2652 | cb => sub { |
|
|
2653 | reload; |
|
|
2654 | undef $RELOAD_WATCHER; |
|
|
2655 | }, |
|
|
2656 | ); |
|
|
2657 | } |
2664 | } |
2658 | }; |
2665 | }; |
2659 | |
2666 | |
2660 | unshift @INC, $LIBDIR; |
2667 | unshift @INC, $LIBDIR; |
2661 | |
2668 | |