--- deliantra/server/lib/cf.pm 2007/04/17 10:06:33 1.245 +++ deliantra/server/lib/cf.pm 2007/04/17 10:38:28 1.246 @@ -2334,8 +2334,8 @@ ############################################################################# # the server's init and main functions -sub load_facedata { - my $path = sprintf "%s/facedata", cf::datadir; +sub load_facedata($) { + my ($path) = @_; warn "loading facedata from $path\n"; @@ -2386,26 +2386,33 @@ 1 } -sub load_archetypes { - load_archetype_file sprintf "%s/archetypes", cf::datadir; # remove when stable +sub reload_facedata { + load_facedata sprintf "%s/facedata", cf::datadir + or die "unable to load facedata\n"; +} + +sub reload_regions { + load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir + or die "unable to load regions file\n"; +} + +sub reload_archetypes { load_archetype_file sprintf "%s/archetypes", cf::datadir + or die "unable to load archetypes\n"; } -sub load_treasures { +sub reload_treasures { load_treasure_file sprintf "%s/treasures", cf::datadir + or die "unable to load treasurelists\n"; } sub reload_resources { warn "reloading resource files...\n"; - load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir - or die "unable to load regions file\n"; - load_facedata - or die "unable to load facedata\n"; - load_archetypes - or die "unable to load archetypes\n"; - load_treasures - or die "unable to load treasurelists\n"; + reload_regions; + reload_facedata; + reload_archetypes; + reload_treasures; warn "finished reloading resource files\n"; } @@ -2510,7 +2517,7 @@ if $make_core; } -sub reload() { +sub do_reload_perl() { # can/must only be called in main if ($Coro::current != $Coro::main) { warn "can only reload from main coroutine"; @@ -2619,9 +2626,6 @@ warn "reattaching attachments to players"; reattach $_ for values %PLAYER; - warn "loading reloadable resources"; - reload_resources; - warn "leaving sync_job"; 1 @@ -2636,24 +2640,27 @@ our $RELOAD_WATCHER; # used only during reload +sub reload_perl() { + # doing reload synchronously and two reloads happen back-to-back, + # coro crashes during coro_state_free->destroy here. + + $RELOAD_WATCHER ||= Event->timer ( + reentrant => 0, + after => 0, + data => WF_AUTOCANCEL, + cb => sub { + do_reload_perl; + undef $RELOAD_WATCHER; + }, + ); +} + register_command "reload" => sub { my ($who, $arg) = @_; if ($who->flag (FLAG_WIZ)) { $who->message ("reloading server."); - - # doing reload synchronously and two reloads happen back-to-back, - # coro crashes during coro_state_free->destroy here. - - $RELOAD_WATCHER ||= Event->timer ( - reentrant => 0, - after => 0, - data => WF_AUTOCANCEL, - cb => sub { - reload; - undef $RELOAD_WATCHER; - }, - ); + async { reload_perl }; } };