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.373 by root, Sat Sep 15 15:58:06 2007 UTC vs.
Revision 1.379 by root, Thu Oct 4 23:59:07 2007 UTC

354our @SLOT_QUEUE; 354our @SLOT_QUEUE;
355our $SLOT_QUEUE; 355our $SLOT_QUEUE;
356 356
357$SLOT_QUEUE->cancel if $SLOT_QUEUE; 357$SLOT_QUEUE->cancel if $SLOT_QUEUE;
358$SLOT_QUEUE = Coro::async { 358$SLOT_QUEUE = Coro::async {
359 $Coro::current->desc ("timeslot manager");
360
359 my $signal = new Coro::Signal; 361 my $signal = new Coro::Signal;
360 362
361 while () { 363 while () {
362 next_job: 364 next_job:
363 my $avail = cf::till_tick; 365 my $avail = cf::till_tick;
425 my $time = Event::time; 427 my $time = Event::time;
426 428
427 # this is the main coro, too bad, we have to block 429 # this is the main coro, too bad, we have to block
428 # till the operation succeeds, freezing the server :/ 430 # till the operation succeeds, freezing the server :/
429 431
432 LOG llevError | logBacktrace, Carp::longmess "sync job";#d#
433
430 # TODO: use suspend/resume instead 434 # TODO: use suspend/resume instead
431 # (but this is cancel-safe) 435 # (but this is cancel-safe)
432 my $freeze_guard = freeze_mainloop; 436 my $freeze_guard = freeze_mainloop;
433 437
434 my $busy = 1; 438 my $busy = 1;
435 my @res; 439 my @res;
436 440
437 (async { 441 (async {
442 $Coro::current->desc ("sync job coro");
438 @res = eval { $job->() }; 443 @res = eval { $job->() };
439 warn $@ if $@; 444 warn $@ if $@;
440 undef $busy; 445 undef $busy;
441 })->prio (Coro::PRIO_MAX); 446 })->prio (Coro::PRIO_MAX);
442 447
2036 } 2041 }
2037 2042
2038 $MAP_PREFETCH{$path} |= $load; 2043 $MAP_PREFETCH{$path} |= $load;
2039 2044
2040 $MAP_PREFETCHER ||= cf::async { 2045 $MAP_PREFETCHER ||= cf::async {
2046 $Coro::current->{desc} = "map prefetcher";
2047
2041 while (%MAP_PREFETCH) { 2048 while (%MAP_PREFETCH) {
2042 while (my ($k, $v) = each %MAP_PREFETCH) { 2049 while (my ($k, $v) = each %MAP_PREFETCH) {
2043 if (my $map = find $k) { 2050 if (my $map = find $k) {
2044 $map->load if $v; 2051 $map->load if $v;
2045 } 2052 }
2071 return if $self->{deny_save}; 2078 return if $self->{deny_save};
2072 2079
2073 local $self->{last_access} = $self->last_access;#d# 2080 local $self->{last_access} = $self->last_access;#d#
2074 2081
2075 cf::async { 2082 cf::async {
2083 $Coro::current->{desc} = "map player save";
2076 $_->contr->save for $self->players; 2084 $_->contr->save for $self->players;
2077 }; 2085 };
2078 2086
2079 if ($uniq) { 2087 if ($uniq) {
2080 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS); 2088 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS);
2267=cut 2275=cut
2268 2276
2269sub deref { 2277sub deref {
2270 my ($ref) = @_; 2278 my ($ref) = @_;
2271 2279
2272 # temporary compatibility#TODO#remove
2273 $ref =~ s{^<}{player/<};
2274
2275 if ($ref =~ m{^player\/(<1\.\d+>)/(.*)$}) { 2280 if ($ref =~ m{^player\/(<1\.[0-9a-f]+>)/(.*)$}) {
2276 my ($uuid, $name) = ($1, $2); 2281 my ($uuid, $name) = ($1, $2);
2277 my $pl = $cf::PLAYER_LOADING{$name} || cf::player::find $name 2282 my $pl = $cf::PLAYER_LOADING{$name} || cf::player::find $name
2278 or return; 2283 or return;
2279 $pl->ob->uuid eq $uuid 2284 $pl->ob->uuid eq $uuid
2280 or return; 2285 or return;
2451 my $gen = $self->{_goto_generation} = ++$GOTOGEN; 2456 my $gen = $self->{_goto_generation} = ++$GOTOGEN;
2452 2457
2453 $self->enter_link; 2458 $self->enter_link;
2454 2459
2455 (async { 2460 (async {
2461 $Coro::current->{desc} = "player::goto $path $x $y";
2462
2456 # *tag paths override both path and x|y 2463 # *tag paths override both path and x|y
2457 if ($path =~ /^\*(.*)$/) { 2464 if ($path =~ /^\*(.*)$/) {
2458 if (my @obs = grep $_->map, ext::map_tags::find $1) { 2465 if (my @obs = grep $_->map, ext::map_tags::find $1) {
2459 my $ob = $obs[rand @obs]; 2466 my $ob = $obs[rand @obs];
2460 2467
2577 # if exit is damned, update players death & WoR home-position 2584 # if exit is damned, update players death & WoR home-position
2578 $self->contr->savebed ($slaying, $hp, $sp) 2585 $self->contr->savebed ($slaying, $hp, $sp)
2579 if $exit->flag (FLAG_DAMNED); 2586 if $exit->flag (FLAG_DAMNED);
2580 2587
2581 (async { 2588 (async {
2589 $Coro::current->{desc} = "enter_exit $slaying $hp $sp";
2590
2582 $self->deactivate_recursive; # just to be sure 2591 $self->deactivate_recursive; # just to be sure
2583 unless (eval { 2592 unless (eval {
2584 $self->goto ($slaying, $hp, $sp); 2593 $self->goto ($slaying, $hp, $sp);
2585 2594
2586 1; 2595 1;
2623 2632
2624=cut 2633=cut
2625 2634
2626our %CHANNEL = ( 2635our %CHANNEL = (
2627 "c/identify" => { 2636 "c/identify" => {
2628 id => "identify", 2637 id => "infobox",
2629 title => "Identify", 2638 title => "Identify",
2630 reply => undef, 2639 reply => undef,
2631 tooltip => "Items recently identified", 2640 tooltip => "Items recently identified",
2632 }, 2641 },
2633 "c/examine" => { 2642 "c/examine" => {
2634 id => "examine", 2643 id => "infobox",
2635 title => "Examine", 2644 title => "Examine",
2636 reply => undef, 2645 reply => undef,
2637 tooltip => "Signs and other items you examined", 2646 tooltip => "Signs and other items you examined",
2638 }, 2647 },
2648 "c/lookat" => {
2649 id => "infobox",
2650 title => "Look",
2651 reply => undef,
2652 tooltip => "What you saw there",
2653 },
2639); 2654);
2640 2655
2641sub cf::client::send_msg { 2656sub cf::client::send_msg {
2642 my ($self, $channel, $msg, $color, @extra) = @_; 2657 my ($self, $channel, $msg, $color, @extra) = @_;
2643 2658
2644 $msg = $self->pl->expand_cfpod ($msg); 2659 $msg = $self->pl->expand_cfpod ($msg);
2645 2660
2646 $color &= cf::NDI_CLIENT_MASK; # just in case... 2661 $color &= cf::NDI_CLIENT_MASK; # just in case...
2647 2662
2648 # check predefined channels, for the benefit of C 2663 # check predefined channels, for the benefit of C
2649 $channel = $CHANNEL{$channel} if $CHANNEL{$channel}; 2664 if ($CHANNEL{$channel}) {
2665 $channel = $CHANNEL{$channel};
2650 2666
2667 $self->ext_msg (channel_info => $channel)
2668 if $self->can_msg;
2669
2670 $channel = $channel->{id};
2671
2651 if (ref $channel) { 2672 } elsif (ref $channel) {
2652 # send meta info to client, if not yet sent 2673 # send meta info to client, if not yet sent
2653 unless (exists $self->{channel}{$channel->{id}}) { 2674 unless (exists $self->{channel}{$channel->{id}}) {
2654 $self->{channel}{$channel->{id}} = $channel; 2675 $self->{channel}{$channel->{id}} = $channel;
2655 $self->ext_msg (channel_info => $channel) 2676 $self->ext_msg (channel_info => $channel)
2656 if $self->can_msg; 2677 if $self->can_msg;
3175sub main { 3196sub main {
3176 # we must not ever block the main coroutine 3197 # we must not ever block the main coroutine
3177 local $Coro::idle = sub { 3198 local $Coro::idle = sub {
3178 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 3199 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
3179 (async { 3200 (async {
3201 $Coro::current->{desc} = "IDLE BUG HANDLER";
3180 Event::one_event; 3202 Event::one_event;
3181 })->prio (Coro::PRIO_MAX); 3203 })->prio (Coro::PRIO_MAX);
3182 }; 3204 };
3183 3205
3184 reload_config; 3206 reload_config;
3428register_command "reload" => sub { 3450register_command "reload" => sub {
3429 my ($who, $arg) = @_; 3451 my ($who, $arg) = @_;
3430 3452
3431 if ($who->flag (FLAG_WIZ)) { 3453 if ($who->flag (FLAG_WIZ)) {
3432 $who->message ("reloading server."); 3454 $who->message ("reloading server.");
3455 async {
3456 $Coro::current->{desc} = "perl_reload";
3433 async { reload_perl }; 3457 reload_perl;
3458 };
3434 } 3459 }
3435}; 3460};
3436 3461
3437unshift @INC, $LIBDIR; 3462unshift @INC, $LIBDIR;
3438 3463
3480 $NEXT_TICK += $TICK; 3505 $NEXT_TICK += $TICK;
3481 3506
3482 if ($NOW >= $NEXT_RUNTIME_WRITE) { 3507 if ($NOW >= $NEXT_RUNTIME_WRITE) {
3483 $NEXT_RUNTIME_WRITE = $NOW + 10; 3508 $NEXT_RUNTIME_WRITE = $NOW + 10;
3484 Coro::async_pool { 3509 Coro::async_pool {
3510 $Coro::current->{desc} = "runtime saver";
3485 write_runtime 3511 write_runtime
3486 or warn "ERROR: unable to write runtime file: $!"; 3512 or warn "ERROR: unable to write runtime file: $!";
3487 }; 3513 };
3488 } 3514 }
3489 3515
3599 $AIO_POLL_WATCHER = Event->io ( 3625 $AIO_POLL_WATCHER = Event->io (
3600 reentrant => 0, 3626 reentrant => 0,
3601 data => WF_AUTOCANCEL, 3627 data => WF_AUTOCANCEL,
3602 fd => IO::AIO::poll_fileno, 3628 fd => IO::AIO::poll_fileno,
3603 poll => 'r', 3629 poll => 'r',
3604 prio => 6, 3630 prio => 0,
3605 cb => \&IO::AIO::poll_cb, 3631 cb => \&IO::AIO::poll_cb,
3606 ); 3632 );
3607} 3633}
3608 3634
3609my $_log_backtrace; 3635my $_log_backtrace;
3615 3641
3616 # limit the # of concurrent backtraces 3642 # limit the # of concurrent backtraces
3617 if ($_log_backtrace < 2) { 3643 if ($_log_backtrace < 2) {
3618 ++$_log_backtrace; 3644 ++$_log_backtrace;
3619 async { 3645 async {
3646 $Coro::current->{desc} = "abt $msg";
3647
3620 my @bt = fork_call { 3648 my @bt = fork_call {
3621 @addr = map { sprintf "%x", $_ } @addr; 3649 @addr = map { sprintf "%x", $_ } @addr;
3622 my $self = (-f "/proc/$$/exe") ? "/proc/$$/exe" : $^X; 3650 my $self = (-f "/proc/$$/exe") ? "/proc/$$/exe" : $^X;
3623 open my $fh, "exec addr2line -C -f -i -e \Q$self\E @addr 2>&1 |" 3651 open my $fh, "exec addr2line -C -f -i -e \Q$self\E @addr 2>&1 |"
3624 or die "addr2line: $!"; 3652 or die "addr2line: $!";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines