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

Comparing cf.schmorp.de/server/lib/cf.pm (file contents):
Revision 1.374 by root, Wed Sep 19 22:07:16 2007 UTC vs.
Revision 1.380 by root, Mon Oct 8 13:58:07 2007 UTC

10use Event; 10use Event;
11use Opcode; 11use Opcode;
12use Safe; 12use Safe;
13use Safe::Hole; 13use Safe::Hole;
14 14
15use Coro 3.64 (); 15use Coro 4.1 ();
16use Coro::State; 16use Coro::State;
17use Coro::Handle; 17use Coro::Handle;
18use Coro::Event; 18use Coro::Event;
19use Coro::Timer; 19use Coro::Timer;
20use Coro::Signal; 20use Coro::Signal;
27use BDB (); 27use BDB ();
28use Data::Dumper; 28use Data::Dumper;
29use Digest::MD5; 29use Digest::MD5;
30use Fcntl; 30use Fcntl;
31use YAML::Syck (); 31use YAML::Syck ();
32use IO::AIO 2.32 (); 32use IO::AIO 2.51 ();
33use Time::HiRes; 33use Time::HiRes;
34use Compress::LZF; 34use Compress::LZF;
35use Digest::MD5 (); 35use Digest::MD5 ();
36 36
37# configure various modules to our taste 37# configure various modules to our taste
373 } 373 }
374 } 374 }
375 } 375 }
376 376
377 if (@SLOT_QUEUE) { 377 if (@SLOT_QUEUE) {
378 # we do not use wait_For_tick() as it returns immediately when tick is inactive 378 # we do not use wait_for_tick() as it returns immediately when tick is inactive
379 push @cf::WAIT_FOR_TICK, $signal; 379 push @cf::WAIT_FOR_TICK, $signal;
380 $signal->wait; 380 $signal->wait;
381 } else { 381 } else {
382 Coro::schedule; 382 Coro::schedule;
383 } 383 }
427 my $time = Event::time; 427 my $time = Event::time;
428 428
429 # this is the main coro, too bad, we have to block 429 # this is the main coro, too bad, we have to block
430 # till the operation succeeds, freezing the server :/ 430 # till the operation succeeds, freezing the server :/
431 431
432 LOG llevError | logBacktrace, Carp::longmess "sync job";#d#
433
432 # TODO: use suspend/resume instead 434 # TODO: use suspend/resume instead
433 # (but this is cancel-safe) 435 # (but this is cancel-safe)
434 my $freeze_guard = freeze_mainloop; 436 my $freeze_guard = freeze_mainloop;
435 437
436 my $busy = 1; 438 my $busy = 1;
1044 close $fh; 1046 close $fh;
1045 1047
1046 if (@$objs) { 1048 if (@$objs) {
1047 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { 1049 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) {
1048 chmod SAVE_MODE, $fh; 1050 chmod SAVE_MODE, $fh;
1049 my $data = Storable::nfreeze { version => 1, objs => $objs }; 1051 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs };
1050 aio_write $fh, 0, (length $data), $data, 0; 1052 aio_write $fh, 0, (length $data), $data, 0;
1051 aio_fsync $fh if $cf::USE_FSYNC; 1053 aio_fsync $fh if $cf::USE_FSYNC;
1052 close $fh; 1054 close $fh;
1053 aio_rename "$filename.pst~", "$filename.pst"; 1055 aio_rename "$filename.pst~", "$filename.pst";
1054 } 1056 }
1085 1087
1086 unless (aio_stat "$filename.pst") { 1088 unless (aio_stat "$filename.pst") {
1087 (aio_load "$filename.pst", $av) >= 0 1089 (aio_load "$filename.pst", $av) >= 0
1088 or return; 1090 or return;
1089 1091
1090 $av = eval { (Storable::thaw $av)->{objs} }; 1092 my $st = eval { Coro::Storable::thaw $av }
1093 || eval { my $guard = Coro::Storable::guard; Storable::thaw $av }; #d# compatibility, remove
1094 $av = $st->{objs};
1091 } 1095 }
1092 1096
1093 utf8::decode (my $decname = $filename); 1097 utf8::decode (my $decname = $filename);
1094 warn sprintf "loading %s (%d,%d)\n", 1098 warn sprintf "loading %s (%d,%d)\n",
1095 $decname, length $data, scalar @{$av || []}; 1099 $decname, length $data, scalar @{$av || []};
2273=cut 2277=cut
2274 2278
2275sub deref { 2279sub deref {
2276 my ($ref) = @_; 2280 my ($ref) = @_;
2277 2281
2278 # temporary compatibility#TODO#remove
2279 $ref =~ s{^<}{player/<};
2280
2281 if ($ref =~ m{^player\/(<1\.\d+>)/(.*)$}) { 2282 if ($ref =~ m{^player\/(<1\.[0-9a-f]+>)/(.*)$}) {
2282 my ($uuid, $name) = ($1, $2); 2283 my ($uuid, $name) = ($1, $2);
2283 my $pl = $cf::PLAYER_LOADING{$name} || cf::player::find $name 2284 my $pl = $cf::PLAYER_LOADING{$name} || cf::player::find $name
2284 or return; 2285 or return;
2285 $pl->ob->uuid eq $uuid 2286 $pl->ob->uuid eq $uuid
2286 or return; 2287 or return;
2633 2634
2634=cut 2635=cut
2635 2636
2636our %CHANNEL = ( 2637our %CHANNEL = (
2637 "c/identify" => { 2638 "c/identify" => {
2638 id => "identify", 2639 id => "infobox",
2639 title => "Identify", 2640 title => "Identify",
2640 reply => undef, 2641 reply => undef,
2641 tooltip => "Items recently identified", 2642 tooltip => "Items recently identified",
2642 }, 2643 },
2643 "c/examine" => { 2644 "c/examine" => {
2644 id => "examine", 2645 id => "infobox",
2645 title => "Examine", 2646 title => "Examine",
2646 reply => undef, 2647 reply => undef,
2647 tooltip => "Signs and other items you examined", 2648 tooltip => "Signs and other items you examined",
2648 }, 2649 },
2650 "c/lookat" => {
2651 id => "infobox",
2652 title => "Look",
2653 reply => undef,
2654 tooltip => "What you saw there",
2655 },
2649); 2656);
2650 2657
2651sub cf::client::send_msg { 2658sub cf::client::send_msg {
2652 my ($self, $channel, $msg, $color, @extra) = @_; 2659 my ($self, $channel, $msg, $color, @extra) = @_;
2653 2660
2654 $msg = $self->pl->expand_cfpod ($msg); 2661 $msg = $self->pl->expand_cfpod ($msg);
2655 2662
2656 $color &= cf::NDI_CLIENT_MASK; # just in case... 2663 $color &= cf::NDI_CLIENT_MASK; # just in case...
2657 2664
2658 # check predefined channels, for the benefit of C 2665 # check predefined channels, for the benefit of C
2659 $channel = $CHANNEL{$channel} if $CHANNEL{$channel}; 2666 if ($CHANNEL{$channel}) {
2667 $channel = $CHANNEL{$channel};
2660 2668
2669 $self->ext_msg (channel_info => $channel)
2670 if $self->can_msg;
2671
2672 $channel = $channel->{id};
2673
2661 if (ref $channel) { 2674 } elsif (ref $channel) {
2662 # send meta info to client, if not yet sent 2675 # send meta info to client, if not yet sent
2663 unless (exists $self->{channel}{$channel->{id}}) { 2676 unless (exists $self->{channel}{$channel->{id}}) {
2664 $self->{channel}{$channel->{id}} = $channel; 2677 $self->{channel}{$channel->{id}} = $channel;
2665 $self->ext_msg (channel_info => $channel) 2678 $self->ext_msg (channel_info => $channel)
2666 if $self->can_msg; 2679 if $self->can_msg;
3614 $AIO_POLL_WATCHER = Event->io ( 3627 $AIO_POLL_WATCHER = Event->io (
3615 reentrant => 0, 3628 reentrant => 0,
3616 data => WF_AUTOCANCEL, 3629 data => WF_AUTOCANCEL,
3617 fd => IO::AIO::poll_fileno, 3630 fd => IO::AIO::poll_fileno,
3618 poll => 'r', 3631 poll => 'r',
3619 prio => 6, 3632 prio => 0,
3620 cb => \&IO::AIO::poll_cb, 3633 cb => \&IO::AIO::poll_cb,
3621 ); 3634 );
3622} 3635}
3623 3636
3624my $_log_backtrace; 3637my $_log_backtrace;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines