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.469 by root, Mon Mar 2 22:25:19 2009 UTC vs.
Revision 1.477 by root, Wed Sep 2 22:52:36 2009 UTC

72 72
73# make sure c-lzf reinitialises itself 73# make sure c-lzf reinitialises itself
74Compress::LZF::set_serializer "Storable", "Storable::net_mstore", "Storable::mretrieve"; 74Compress::LZF::set_serializer "Storable", "Storable::net_mstore", "Storable::mretrieve";
75Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later 75Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later
76 76
77# strictly for debugging
78$SIG{QUIT} = sub { Carp::cluck "SIGQUIT" };
79
77sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload 80sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload
78 81
79our %COMMAND = (); 82our %COMMAND = ();
80our %COMMAND_TIME = (); 83our %COMMAND_TIME = ();
81 84
134our $JITTER; # average jitter 137our $JITTER; # average jitter
135our $TICK_START; # for load detecting purposes 138our $TICK_START; # for load detecting purposes
136 139
137our @POST_INIT; 140our @POST_INIT;
138 141
139our $REATTACH_ON_RELOAD; # ste to true to force object reattach on reload (slow) 142our $REATTACH_ON_RELOAD; # set to true to force object reattach on reload (slow)
143our $REALLY_UNLOOP; # never set to true, please :)
140 144
141binmode STDOUT; 145binmode STDOUT;
142binmode STDERR; 146binmode STDERR;
143 147
144# read virtual server time, if available 148# read virtual server time, if available
218 222
219=back 223=back
220 224
221=cut 225=cut
222 226
223BEGIN { 227$Coro::State::WARNHOOK = sub {
224 *CORE::GLOBAL::warn = sub {
225 my $msg = join "", @_; 228 my $msg = join "", @_;
226 229
227 $msg .= "\n" 230 $msg .= "\n"
228 unless $msg =~ /\n$/; 231 unless $msg =~ /\n$/;
229 232
230 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge; 233 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge;
231 234
232 LOG llevError, $msg; 235 LOG llevError, $msg;
233 }; 236};
234}
235 237
236$Coro::State::DIEHOOK = sub { 238$Coro::State::DIEHOOK = sub {
237 return unless $^S eq 0; # "eq", not "==" 239 return unless $^S eq 0; # "eq", not "=="
240
241 warn Carp::longmess $_[0];
238 242
239 if ($Coro::current == $Coro::main) {#d# 243 if ($Coro::current == $Coro::main) {#d#
240 warn "DIEHOOK called in main context, Coro bug?\n";#d# 244 warn "DIEHOOK called in main context, Coro bug?\n";#d#
241 return;#d# 245 return;#d#
242 }#d# 246 }#d#
243 247
244 # kill coroutine otherwise 248 # kill coroutine otherwise
245 warn Carp::longmess $_[0];
246 Coro::terminate 249 Coro::terminate
247}; 250};
248
249$SIG{__DIE__} = sub { }; #d#?
250 251
251@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable'; 252@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable';
252@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable'; 253@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable';
253@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable'; 254@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable';
254@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable'; 255@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable';
1151 $decname, length $$rdata, scalar @$objs; 1152 $decname, length $$rdata, scalar @$objs;
1152 1153
1153 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { 1154 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) {
1154 aio_chmod $fh, SAVE_MODE; 1155 aio_chmod $fh, SAVE_MODE;
1155 aio_write $fh, 0, (length $$rdata), $$rdata, 0; 1156 aio_write $fh, 0, (length $$rdata), $$rdata, 0;
1156 aio_fsync $fh if $cf::USE_FSYNC; 1157 if ($cf::USE_FSYNC) {
1158 aio_sync_file_range $fh, 0, 0, IO::AIO::SYNC_FILE_RANGE_WAIT_BEFORE | IO::AIO::SYNC_FILE_RANGE_WRITE | IO::AIO::SYNC_FILE_RANGE_WAIT_AFTER;
1159 aio_fsync $fh;
1160 }
1157 aio_close $fh; 1161 aio_close $fh;
1158 1162
1159 if (@$objs) { 1163 if (@$objs) {
1160 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { 1164 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) {
1161 aio_chmod $fh, SAVE_MODE; 1165 aio_chmod $fh, SAVE_MODE;
1162 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs }; 1166 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs };
1163 aio_write $fh, 0, (length $data), $data, 0; 1167 aio_write $fh, 0, (length $data), $data, 0;
1164 aio_fsync $fh if $cf::USE_FSYNC; 1168 if ($cf::USE_FSYNC) {
1169 aio_sync_file_range $fh, 0, 0, IO::AIO::SYNC_FILE_RANGE_WAIT_BEFORE | IO::AIO::SYNC_FILE_RANGE_WRITE | IO::AIO::SYNC_FILE_RANGE_WAIT_AFTER;
1170 aio_fsync $fh;
1171 }
1165 aio_close $fh; 1172 aio_close $fh;
1166 aio_rename "$filename.pst~", "$filename.pst"; 1173 aio_rename "$filename.pst~", "$filename.pst";
1167 } 1174 }
1168 } else { 1175 } else {
1169 aio_unlink "$filename.pst"; 1176 aio_unlink "$filename.pst";
1320 1327
1321# "readahead" all extensions 1328# "readahead" all extensions
1322sub cache_extensions { 1329sub cache_extensions {
1323 my $grp = IO::AIO::aio_group; 1330 my $grp = IO::AIO::aio_group;
1324 1331
1325 add $grp IO::AIO::aio_readdir $LIBDIR, sub { 1332 add $grp IO::AIO::aio_readdirx $LIBDIR, IO::AIO::READDIR_STAT_ORDER, sub {
1326 for (grep /\.ext$/, @{$_[0]}) { 1333 for (grep /\.ext$/, @{$_[0]}) {
1327 add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data; 1334 add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data;
1328 } 1335 }
1329 }; 1336 };
1330 1337
2524 2531
2525 $map->load; 2532 $map->load;
2526 $map->load_neighbours; 2533 $map->load_neighbours;
2527 2534
2528 return unless $self->contr->active; 2535 return unless $self->contr->active;
2529 $self->flag (cf::FLAG_DEBUG, 0);#d# temp
2530 $self->activate_recursive;
2531 2536
2532 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext 2537 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext
2533 $self->enter_map ($map, $x, $y); 2538 $self->enter_map ($map, $x, $y);
2539
2540 # only activate afterwards, to support waiting in hooks
2541 $self->activate_recursive;
2534} 2542}
2535 2543
2536=item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) 2544=item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]])
2537 2545
2538Moves the player to the given map-path and coordinates by first freezing 2546Moves the player to the given map-path and coordinates by first freezing
2785 id => "infobox", 2793 id => "infobox",
2786 title => "Skills", 2794 title => "Skills",
2787 reply => undef, 2795 reply => undef,
2788 tooltip => "Shows your experience per skill and item power", 2796 tooltip => "Shows your experience per skill and item power",
2789 }, 2797 },
2798 "c/shopitems" => {
2799 id => "infobox",
2800 title => "Shop Items",
2801 reply => undef,
2802 tooltip => "Shows the items currently for sale in this shop",
2803 },
2790 "c/resistances" => { 2804 "c/resistances" => {
2791 id => "infobox", 2805 id => "infobox",
2792 title => "Resistances", 2806 title => "Resistances",
2793 reply => undef, 2807 reply => undef,
2794 tooltip => "Shows your resistances", 2808 tooltip => "Shows your resistances",
2796 "c/pets" => { 2810 "c/pets" => {
2797 id => "infobox", 2811 id => "infobox",
2798 title => "Pets", 2812 title => "Pets",
2799 reply => undef, 2813 reply => undef,
2800 tooltip => "Shows information abotu your pets/a specific pet", 2814 tooltip => "Shows information abotu your pets/a specific pet",
2815 },
2816 "c/perceiveself" => {
2817 id => "infobox",
2818 title => "Perceive Self",
2819 reply => undef,
2820 tooltip => "You gained detailed knowledge about yourself",
2801 }, 2821 },
2802 "c/uptime" => { 2822 "c/uptime" => {
2803 id => "infobox", 2823 id => "infobox",
2804 title => "Uptime", 2824 title => "Uptime",
2805 reply => undef, 2825 reply => undef,
3382 3402
3383 seek $fh, 0, 0; 3403 seek $fh, 0, 0;
3384 print $fh $$; 3404 print $fh $$;
3385} 3405}
3386 3406
3407sub main_loop {
3408 warn "EV::loop starting\n";
3409 if (1) {
3410 EV::loop;
3411 }
3412 warn "EV::loop returned\n";
3413 goto &main_loop unless $REALLY_UNLOOP;
3414}
3415
3387sub main { 3416sub main {
3388 cf::init_globals; # initialise logging 3417 cf::init_globals; # initialise logging
3389 3418
3390 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3419 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3391 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3420 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3429 load_extensions; 3458 load_extensions;
3430 3459
3431 utime time, time, $RUNTIMEFILE; 3460 utime time, time, $RUNTIMEFILE;
3432 3461
3433 # no (long-running) fork's whatsoever before this point(!) 3462 # no (long-running) fork's whatsoever before this point(!)
3463 use POSIX ();
3434 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; 3464 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD};
3435 3465
3436 (pop @POST_INIT)->(0) while @POST_INIT; 3466 (pop @POST_INIT)->(0) while @POST_INIT;
3437 }; 3467 };
3438 3468
3439 EV::loop; 3469 main_loop;
3440} 3470}
3441 3471
3442############################################################################# 3472#############################################################################
3443# initialisation and cleanup 3473# initialisation and cleanup
3444 3474

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines