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.487 by root, Fri Oct 16 01:56:41 2009 UTC vs.
Revision 1.495 by root, Tue Nov 10 04:38:45 2009 UTC

32use EV; 32use EV;
33use Opcode; 33use Opcode;
34use Safe; 34use Safe;
35use Safe::Hole; 35use Safe::Hole;
36use Storable (); 36use Storable ();
37use Carp ();
37 38
38use Guard (); 39use Guard ();
39use Coro (); 40use Coro ();
40use Coro::State; 41use Coro::State;
41use Coro::Handle; 42use Coro::Handle;
228returns directly I<after> the tick processing (and consequently, can only wake one process 229returns directly I<after> the tick processing (and consequently, can only wake one process
229per tick), while cf::wait_for_tick wakes up all waiters after tick processing. 230per tick), while cf::wait_for_tick wakes up all waiters after tick processing.
230 231
231=item @cf::INVOKE_RESULTS 232=item @cf::INVOKE_RESULTS
232 233
233This array contains the results of the last C<invoke ()> call. When 234This array contains the results of the last C<invoke ()> call. When
234C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of 235C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of
235that call. 236that call.
236 237
237=item %cf::REFLECT 238=item %cf::REFLECT
238 239
289)) { 290)) {
290 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; 291 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
291} 292}
292 293
293$EV::DIED = sub { 294$EV::DIED = sub {
294 warn "error in event callback: @_"; 295 Carp::cluck "error in event callback: @_";
295}; 296};
296 297
297############################################################################# 298#############################################################################
298 299
299=head2 UTILITY FUNCTIONS 300=head2 UTILITY FUNCTIONS
2341 : normalise $_ 2342 : normalise $_
2342 } @{ aio_readdir $UNIQUEDIR or [] } 2343 } @{ aio_readdir $UNIQUEDIR or [] }
2343 ] 2344 ]
2344} 2345}
2345 2346
2347=item cf::map::static_maps
2348
2349Returns an arrayref if paths of all static maps (all preinstalled F<.map>
2350file in the shared directory excluding F</styles> and F</editor>). May
2351block.
2352
2353=cut
2354
2355sub static_maps() {
2356 my @dirs = "";
2357 my @maps;
2358
2359 while (@dirs) {
2360 my $dir = shift @dirs;
2361
2362 next if $dir eq "/styles" || $dir eq "/editor";
2363
2364 my ($dirs, $files) = Coro::AIO::aio_scandir "$MAPDIR$dir", 2
2365 or return;
2366
2367 for (@$files) {
2368 s/\.map$// or next;
2369 utf8::decode $_;
2370 push @maps, "$dir/$_";
2371 }
2372
2373 push @dirs, map "$dir/$_", @$dirs;
2374 }
2375
2376 \@maps
2377}
2378
2346=back 2379=back
2347 2380
2348=head3 cf::object 2381=head3 cf::object
2349 2382
2350=cut 2383=cut
2545 ($x, $y) = (-1, -1) 2578 ($x, $y) = (-1, -1)
2546 unless (defined $x) && (defined $y); 2579 unless (defined $x) && (defined $y);
2547 2580
2548 # use -1 or undef as default coordinates, not 0, 0 2581 # use -1 or undef as default coordinates, not 0, 0
2549 ($x, $y) = ($map->enter_x, $map->enter_y) 2582 ($x, $y) = ($map->enter_x, $map->enter_y)
2550 if $x <=0 && $y <= 0; 2583 if $x <= 0 && $y <= 0;
2551 2584
2552 $map->load; 2585 $map->load;
2553 $map->load_neighbours; 2586 $map->load_neighbours;
2554 2587
2555 return unless $self->contr->active; 2588 return unless $self->contr->active;
2752sub cf::client::send_drawinfo { 2785sub cf::client::send_drawinfo {
2753 my ($self, $text, $flags) = @_; 2786 my ($self, $text, $flags) = @_;
2754 2787
2755 utf8::encode $text; 2788 utf8::encode $text;
2756 $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text); 2789 $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text);
2790}
2791
2792=item $client->send_big_packet ($pkt)
2793
2794Like C<send_packet>, but tries to compress large packets, and fragments
2795them as required.
2796
2797=cut
2798
2799our $MAXFRAGSIZE = cf::MAXSOCKBUF - 64;
2800
2801sub cf::client::send_big_packet {
2802 my ($self, $pkt) = @_;
2803
2804 # try lzf for large packets
2805 $pkt = "lzf " . Compress::LZF::compress $pkt
2806 if 1024 <= length $pkt and $self->{can_lzf};
2807
2808 # split very large packets
2809 if ($MAXFRAGSIZE < length $pkt and $self->{can_lzf}) {
2810 $self->send_packet ("frag $_") for unpack "(a$MAXFRAGSIZE)*", $pkt;
2811 $pkt = "frag";
2812 }
2813
2814 $self->send_packet ($pkt);
2757} 2815}
2758 2816
2759=item $client->send_msg ($channel, $msg, $color, [extra...]) 2817=item $client->send_msg ($channel, $msg, $color, [extra...])
2760 2818
2761Send a drawinfo or msg packet to the client, formatting the msg for the 2819Send a drawinfo or msg packet to the client, formatting the msg for the
2913 my $pkt = "msg " 2971 my $pkt = "msg "
2914 . $self->{json_coder}->encode ( 2972 . $self->{json_coder}->encode (
2915 [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra] 2973 [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra]
2916 ); 2974 );
2917 2975
2918 # try lzf for large packets
2919 $pkt = "lzf " . Compress::LZF::compress $pkt
2920 if 1024 <= length $pkt and $self->{can_lzf};
2921
2922 # split very large packets
2923 if (8192 < length $pkt and $self->{can_lzf}) {
2924 $self->send_packet ("frag $_") for unpack "(a8192)*", $pkt;
2925 $pkt = "frag";
2926 }
2927
2928 $self->send_packet ($pkt); 2976 $self->send_big_packet ($pkt);
2929} 2977}
2930 2978
2931=item $client->ext_msg ($type, @msg) 2979=item $client->ext_msg ($type, @msg)
2932 2980
2933Sends an ext event to the client. 2981Sends an ext event to the client.
2936 2984
2937sub cf::client::ext_msg($$@) { 2985sub cf::client::ext_msg($$@) {
2938 my ($self, $type, @msg) = @_; 2986 my ($self, $type, @msg) = @_;
2939 2987
2940 if ($self->extcmd == 2) { 2988 if ($self->extcmd == 2) {
2941 $self->send_packet ("ext " . $self->{json_coder}->encode ([$type, @msg])); 2989 $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg]));
2942 } elsif ($self->extcmd == 1) { # TODO: remove 2990 } elsif ($self->extcmd == 1) { # TODO: remove
2943 push @msg, msgtype => "event_$type"; 2991 push @msg, msgtype => "event_$type";
2944 $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg})); 2992 $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg}));
2945 } 2993 }
2946} 2994}
2947 2995
2948=item $client->ext_reply ($msgid, @msg) 2996=item $client->ext_reply ($msgid, @msg)
2949 2997
2953 3001
2954sub cf::client::ext_reply($$@) { 3002sub cf::client::ext_reply($$@) {
2955 my ($self, $id, @msg) = @_; 3003 my ($self, $id, @msg) = @_;
2956 3004
2957 if ($self->extcmd == 2) { 3005 if ($self->extcmd == 2) {
2958 $self->send_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg])); 3006 $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg]));
2959 } elsif ($self->extcmd == 1) { 3007 } elsif ($self->extcmd == 1) {
2960 #TODO: version 1, remove 3008 #TODO: version 1, remove
2961 unshift @msg, msgtype => "reply", msgid => $id; 3009 unshift @msg, msgtype => "reply", msgid => $id;
2962 $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg})); 3010 $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg}));
2963 } 3011 }
2964} 3012}
2965 3013
2966=item $success = $client->query ($flags, "text", \&cb) 3014=item $success = $client->query ($flags, "text", \&cb)
2967 3015
3474 }; 3522 };
3475 3523
3476 evthread_start IO::AIO::poll_fileno; 3524 evthread_start IO::AIO::poll_fileno;
3477 3525
3478 cf::sync_job { 3526 cf::sync_job {
3527 cf::load_settings;
3528 cf::load_materials;
3529
3479 reload_resources; 3530 reload_resources;
3480 reload_config; 3531 reload_config;
3481 db_init; 3532 db_init;
3482 3533
3483 cf::load_settings;
3484 cf::load_materials;
3485 cf::init_uuid; 3534 cf::init_uuid;
3486 cf::init_signals; 3535 cf::init_signals;
3487 cf::init_commands; 3536 cf::init_commands;
3488 cf::init_skills; 3537 cf::init_skills;
3489 3538

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines