… | |
… | |
53 | use Coro::Util (); |
53 | use Coro::Util (); |
54 | |
54 | |
55 | use JSON::XS 2.01 (); |
55 | use JSON::XS 2.01 (); |
56 | use BDB (); |
56 | use BDB (); |
57 | use Data::Dumper; |
57 | use Data::Dumper; |
58 | use Digest::MD5; |
|
|
59 | use Fcntl; |
58 | use Fcntl; |
60 | use YAML::XS (); |
59 | use YAML::XS (); |
61 | use IO::AIO (); |
60 | use IO::AIO (); |
62 | use Time::HiRes; |
61 | use Time::HiRes; |
63 | use Compress::LZF; |
62 | use Compress::LZF; |
… | |
… | |
2785 | sub cf::client::send_drawinfo { |
2784 | sub cf::client::send_drawinfo { |
2786 | my ($self, $text, $flags) = @_; |
2785 | my ($self, $text, $flags) = @_; |
2787 | |
2786 | |
2788 | utf8::encode $text; |
2787 | utf8::encode $text; |
2789 | $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text); |
2788 | $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text); |
|
|
2789 | } |
|
|
2790 | |
|
|
2791 | =item $client->send_big_packet ($pkt) |
|
|
2792 | |
|
|
2793 | Like C<send_packet>, but tries to compress large packets, and fragments |
|
|
2794 | them as required. |
|
|
2795 | |
|
|
2796 | =cut |
|
|
2797 | |
|
|
2798 | our $MAXFRAGSIZE = cf::MAXSOCKBUF - 64; |
|
|
2799 | |
|
|
2800 | sub cf::client::send_big_packet { |
|
|
2801 | my ($self, $pkt) = @_; |
|
|
2802 | |
|
|
2803 | # try lzf for large packets |
|
|
2804 | $pkt = "lzf " . Compress::LZF::compress $pkt |
|
|
2805 | if 1024 <= length $pkt and $self->{can_lzf}; |
|
|
2806 | |
|
|
2807 | # split very large packets |
|
|
2808 | if ($MAXFRAGSIZE < length $pkt and $self->{can_lzf}) { |
|
|
2809 | $self->send_packet ("frag $_") for unpack "(a$MAXFRAGSIZE)*", $pkt; |
|
|
2810 | $pkt = "frag"; |
|
|
2811 | } |
|
|
2812 | |
|
|
2813 | $self->send_packet ($pkt); |
2790 | } |
2814 | } |
2791 | |
2815 | |
2792 | =item $client->send_msg ($channel, $msg, $color, [extra...]) |
2816 | =item $client->send_msg ($channel, $msg, $color, [extra...]) |
2793 | |
2817 | |
2794 | Send a drawinfo or msg packet to the client, formatting the msg for the |
2818 | Send a drawinfo or msg packet to the client, formatting the msg for the |
… | |
… | |
2946 | my $pkt = "msg " |
2970 | my $pkt = "msg " |
2947 | . $self->{json_coder}->encode ( |
2971 | . $self->{json_coder}->encode ( |
2948 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra] |
2972 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra] |
2949 | ); |
2973 | ); |
2950 | |
2974 | |
2951 | # try lzf for large packets |
|
|
2952 | $pkt = "lzf " . Compress::LZF::compress $pkt |
|
|
2953 | if 1024 <= length $pkt and $self->{can_lzf}; |
|
|
2954 | |
|
|
2955 | # split very large packets |
|
|
2956 | if (8192 < length $pkt and $self->{can_lzf}) { |
|
|
2957 | $self->send_packet ("frag $_") for unpack "(a8192)*", $pkt; |
|
|
2958 | $pkt = "frag"; |
|
|
2959 | } |
|
|
2960 | |
|
|
2961 | $self->send_packet ($pkt); |
2975 | $self->send_big_packet ($pkt); |
2962 | } |
2976 | } |
2963 | |
2977 | |
2964 | =item $client->ext_msg ($type, @msg) |
2978 | =item $client->ext_msg ($type, @msg) |
2965 | |
2979 | |
2966 | Sends an ext event to the client. |
2980 | Sends an ext event to the client. |
… | |
… | |
2969 | |
2983 | |
2970 | sub cf::client::ext_msg($$@) { |
2984 | sub cf::client::ext_msg($$@) { |
2971 | my ($self, $type, @msg) = @_; |
2985 | my ($self, $type, @msg) = @_; |
2972 | |
2986 | |
2973 | if ($self->extcmd == 2) { |
2987 | if ($self->extcmd == 2) { |
2974 | $self->send_packet ("ext " . $self->{json_coder}->encode ([$type, @msg])); |
2988 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg])); |
2975 | } elsif ($self->extcmd == 1) { # TODO: remove |
2989 | } elsif ($self->extcmd == 1) { # TODO: remove |
2976 | push @msg, msgtype => "event_$type"; |
2990 | push @msg, msgtype => "event_$type"; |
2977 | $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
2991 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
2978 | } |
2992 | } |
2979 | } |
2993 | } |
2980 | |
2994 | |
2981 | =item $client->ext_reply ($msgid, @msg) |
2995 | =item $client->ext_reply ($msgid, @msg) |
2982 | |
2996 | |
… | |
… | |
2986 | |
3000 | |
2987 | sub cf::client::ext_reply($$@) { |
3001 | sub cf::client::ext_reply($$@) { |
2988 | my ($self, $id, @msg) = @_; |
3002 | my ($self, $id, @msg) = @_; |
2989 | |
3003 | |
2990 | if ($self->extcmd == 2) { |
3004 | if ($self->extcmd == 2) { |
2991 | $self->send_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg])); |
3005 | $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg])); |
2992 | } elsif ($self->extcmd == 1) { |
3006 | } elsif ($self->extcmd == 1) { |
2993 | #TODO: version 1, remove |
3007 | #TODO: version 1, remove |
2994 | unshift @msg, msgtype => "reply", msgid => $id; |
3008 | unshift @msg, msgtype => "reply", msgid => $id; |
2995 | $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
3009 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
2996 | } |
3010 | } |
2997 | } |
3011 | } |
2998 | |
3012 | |
2999 | =item $success = $client->query ($flags, "text", \&cb) |
3013 | =item $success = $client->query ($flags, "text", \&cb) |
3000 | |
3014 | |
… | |
… | |
3277 | while (my ($face, $info) = each %$faces) { |
3291 | while (my ($face, $info) = each %$faces) { |
3278 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
3292 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
3279 | |
3293 | |
3280 | cf::face::set_visibility $idx, $info->{visibility}; |
3294 | cf::face::set_visibility $idx, $info->{visibility}; |
3281 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3295 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3282 | cf::face::set_data $idx, 0, $info->{data32}, Digest::MD5::md5 $info->{data32}; |
3296 | cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; |
3283 | cf::face::set_data $idx, 1, $info->{data64}, Digest::MD5::md5 $info->{data64}; |
3297 | cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; |
3284 | |
3298 | |
3285 | cf::cede_to_tick; |
3299 | cf::cede_to_tick; |
3286 | } |
3300 | } |
3287 | |
3301 | |
3288 | while (my ($face, $info) = each %$faces) { |
3302 | while (my ($face, $info) = each %$faces) { |
… | |
… | |
3312 | |
3326 | |
3313 | cf::anim::invalidate_all; # d'oh |
3327 | cf::anim::invalidate_all; # d'oh |
3314 | } |
3328 | } |
3315 | |
3329 | |
3316 | { |
3330 | { |
3317 | # TODO: for gcfclient pleasure, we should give resources |
|
|
3318 | # that gcfclient doesn't grok a >10000 face index. |
|
|
3319 | my $res = $facedata->{resource}; |
3331 | my $res = $facedata->{resource}; |
3320 | |
3332 | |
3321 | while (my ($name, $info) = each %$res) { |
3333 | while (my ($name, $info) = each %$res) { |
3322 | if (defined $info->{type}) { |
3334 | if (defined $info->{type}) { |
3323 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3335 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3324 | my $data; |
|
|
3325 | |
3336 | |
3326 | if ($info->{type} & 1) { |
3337 | cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; |
3327 | # prepend meta info |
|
|
3328 | |
|
|
3329 | my $meta = $enc->encode ({ |
|
|
3330 | name => $name, |
|
|
3331 | %{ $info->{meta} || {} }, |
|
|
3332 | }); |
|
|
3333 | |
|
|
3334 | $data = pack "(w/a*)*", $meta, $info->{data}; |
|
|
3335 | } else { |
|
|
3336 | $data = $info->{data}; |
|
|
3337 | } |
|
|
3338 | |
|
|
3339 | cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data; |
|
|
3340 | cf::face::set_type $idx, $info->{type}; |
3338 | cf::face::set_type $idx, $info->{type}; |
3341 | } else { |
3339 | } else { |
3342 | $RESOURCE{$name} = $info; |
3340 | $RESOURCE{$name} = $info; |
3343 | } |
3341 | } |
3344 | |
3342 | |
… | |
… | |
3507 | }; |
3505 | }; |
3508 | |
3506 | |
3509 | evthread_start IO::AIO::poll_fileno; |
3507 | evthread_start IO::AIO::poll_fileno; |
3510 | |
3508 | |
3511 | cf::sync_job { |
3509 | cf::sync_job { |
|
|
3510 | cf::load_settings; |
|
|
3511 | cf::load_materials; |
|
|
3512 | |
3512 | reload_resources; |
3513 | reload_resources; |
3513 | reload_config; |
3514 | reload_config; |
3514 | db_init; |
3515 | db_init; |
3515 | |
3516 | |
3516 | cf::load_settings; |
|
|
3517 | cf::load_materials; |
|
|
3518 | cf::init_uuid; |
3517 | cf::init_uuid; |
3519 | cf::init_signals; |
3518 | cf::init_signals; |
3520 | cf::init_commands; |
3519 | cf::init_commands; |
3521 | cf::init_skills; |
3520 | cf::init_skills; |
3522 | |
3521 | |