ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.407 by root, Sun Jan 13 09:53:53 2008 UTC vs.
Revision 1.411 by root, Fri Feb 1 15:54:07 2008 UTC

27use JSON::XS 2.01 (); 27use JSON::XS 2.01 ();
28use BDB (); 28use BDB ();
29use Data::Dumper; 29use Data::Dumper;
30use Digest::MD5; 30use Digest::MD5;
31use Fcntl; 31use Fcntl;
32use YAML::Syck (); 32use YAML ();
33use IO::AIO 2.51 (); 33use IO::AIO 2.51 ();
34use Time::HiRes; 34use Time::HiRes;
35use Compress::LZF; 35use Compress::LZF;
36use Digest::MD5 (); 36use Digest::MD5 ();
37 37
38# configure various modules to our taste 38# configure various modules to our taste
39# 39#
40$Storable::canonical = 1; # reduce rsync transfers 40$Storable::canonical = 1; # reduce rsync transfers
41Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator 41Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator
42Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later 42Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later
43
44# work around bug in YAML::Syck - bad news for perl6, will it be as broken wrt. unicode?
45$YAML::Syck::ImplicitUnicode = 1;
46 43
47$Coro::main->prio (Coro::PRIO_MAX); # run main coroutine ("the server") with very high priority 44$Coro::main->prio (Coro::PRIO_MAX); # run main coroutine ("the server") with very high priority
48 45
49sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload 46sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload
50 47
195 LOG llevError, $msg; 192 LOG llevError, $msg;
196 }; 193 };
197} 194}
198 195
199$Coro::State::DIEHOOK = sub { 196$Coro::State::DIEHOOK = sub {
197 return unless $^S eq 0; # "eq", not "=="
198
199 if ($Coro::current == $Coro::main) {#d#
200 warn "DIEHOOK called in main context, Coro bug?\n";#d#
201 return;#d#
202 }#d#
203
204 # kill coroutine otherwise
200 warn Carp::longmess $_[0]; 205 warn Carp::longmess $_[0];
201 Coro::terminate; 206 Coro::terminate
202}; 207};
208
209$SIG{__DIE__} = sub { }; #d#?
203 210
204@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable'; 211@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable';
205@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable'; 212@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable';
206@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable'; 213@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable';
207@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable'; 214@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable';
1309 my $msg = $@ ? "$v->{path}: $@\n" 1316 my $msg = $@ ? "$v->{path}: $@\n"
1310 : "$v->{base}: extension inactive.\n"; 1317 : "$v->{base}: extension inactive.\n";
1311 1318
1312 if (exists $v->{meta}{mandatory}) { 1319 if (exists $v->{meta}{mandatory}) {
1313 warn $msg; 1320 warn $msg;
1314 warn "mandatory extension failed to load, exiting.\n"; 1321 cf::cleanup "mandatory extension failed to load, exiting.";
1315 exit 1;
1316 } 1322 }
1317 1323
1318 warn $msg; 1324 warn $msg;
1319 } 1325 }
1320 1326
3313sub reload_config { 3319sub reload_config {
3314 open my $fh, "<:utf8", "$CONFDIR/config" 3320 open my $fh, "<:utf8", "$CONFDIR/config"
3315 or return; 3321 or return;
3316 3322
3317 local $/; 3323 local $/;
3318 *CFG = YAML::Syck::Load <$fh>; 3324 *CFG = YAML::Load <$fh>;
3319 3325
3320 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_105_115", 5, 37]; 3326 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_105_115", 5, 37];
3321 3327
3322 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; 3328 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset};
3323 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; 3329 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset};
3551 warn "leaving sync_job"; 3557 warn "leaving sync_job";
3552 3558
3553 1 3559 1
3554 } or do { 3560 } or do {
3555 warn $@; 3561 warn $@;
3556 warn "error while reloading, exiting."; 3562 cf::cleanup "error while reloading, exiting.";
3557 exit 1;
3558 }; 3563 };
3559 3564
3560 warn "reloaded"; 3565 warn "reloaded";
3561}; 3566};
3562 3567
3565sub reload_perl() { 3570sub reload_perl() {
3566 # doing reload synchronously and two reloads happen back-to-back, 3571 # doing reload synchronously and two reloads happen back-to-back,
3567 # coro crashes during coro_state_free->destroy here. 3572 # coro crashes during coro_state_free->destroy here.
3568 3573
3569 $RELOAD_WATCHER ||= EV::timer 0, 0, sub { 3574 $RELOAD_WATCHER ||= EV::timer 0, 0, sub {
3575 do_reload_perl;
3570 undef $RELOAD_WATCHER; 3576 undef $RELOAD_WATCHER;
3571 do_reload_perl;
3572 }; 3577 };
3573} 3578}
3574 3579
3575register_command "reload" => sub { 3580register_command "reload" => sub {
3576 my ($who, $arg) = @_; 3581 my ($who, $arg) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines