… | |
… | |
2512 | sub cf::client::send_msg { |
2512 | sub cf::client::send_msg { |
2513 | my ($self, $channel, $msg, $color, @extra) = @_; |
2513 | my ($self, $channel, $msg, $color, @extra) = @_; |
2514 | |
2514 | |
2515 | $msg = $self->pl->expand_cfpod ($msg); |
2515 | $msg = $self->pl->expand_cfpod ($msg); |
2516 | |
2516 | |
2517 | $color &= ~cf::NDI_UNIQUE; # just in case... |
2517 | $color &= cf::NDI_CLIENT_MASK; # just in case... |
2518 | |
2518 | |
2519 | if (ref $channel) { |
2519 | if (ref $channel) { |
2520 | # send meta info to client, if not yet sent |
2520 | # send meta info to client, if not yet sent |
2521 | unless (exists $self->{channel}{$channel->{id}}) { |
2521 | unless (exists $self->{channel}{$channel->{id}}) { |
2522 | $self->{channel}{$channel->{id}} = $channel; |
2522 | $self->{channel}{$channel->{id}} = $channel; |
2523 | $self->ext_msg (channel_info => %$channel); |
2523 | $self->ext_msg (channel_info => $channel); |
2524 | } |
2524 | } |
2525 | |
2525 | |
2526 | $channel = $channel->{id}; |
2526 | $channel = $channel->{id}; |
2527 | } |
2527 | } |
2528 | |
2528 | |
2529 | return unless @extra || length $msg; |
2529 | return unless @extra || length $msg; |
2530 | |
2530 | |
2531 | if ($self->can_msg) { |
2531 | if ($self->can_msg) { |
|
|
2532 | # default colour, mask it out |
|
|
2533 | $color &= ~(cf::NDI_COLOR_MASK | cf::NDI_DEF) |
|
|
2534 | if $color & cf::NDI_DEF; |
|
|
2535 | |
2532 | $self->send_packet ("msg " . $self->{json_coder}->encode ([$color, $channel, $msg, @extra])); |
2536 | $self->send_packet ("msg " . $self->{json_coder}->encode ( |
|
|
2537 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra])); |
2533 | } else { |
2538 | } else { |
2534 | # replace some tags by gcfclient-compatible ones |
|
|
2535 | for ($msg) { |
|
|
2536 | 1 while |
|
|
2537 | s/<b>([^<]*)<\/b>/[b]${1}[\/b]/ |
|
|
2538 | || s/<i>([^<]*)<\/i>/[i]${1}[\/i]/ |
|
|
2539 | || s/<u>([^<]*)<\/u>/[ul]${1}[\/ul]/ |
|
|
2540 | || s/<tt>([^<]*)<\/tt>/[fixed]${1}[\/fixed]/ |
|
|
2541 | || s/<fg name=\"([^"]+)\">([^<]*)<\/fg>/[color=$1]${2}[\/color]/; |
|
|
2542 | } |
|
|
2543 | |
|
|
2544 | if ($color >= 0) { |
2539 | if ($color >= 0) { |
|
|
2540 | # replace some tags by gcfclient-compatible ones |
|
|
2541 | for ($msg) { |
|
|
2542 | 1 while |
|
|
2543 | s/<b>([^<]*)<\/b>/[b]${1}[\/b]/ |
|
|
2544 | || s/<i>([^<]*)<\/i>/[i]${1}[\/i]/ |
|
|
2545 | || s/<u>([^<]*)<\/u>/[ul]${1}[\/ul]/ |
|
|
2546 | || s/<tt>([^<]*)<\/tt>/[fixed]${1}[\/fixed]/ |
|
|
2547 | || s/<fg name=\"([^"]+)\">([^<]*)<\/fg>/[color=$1]${2}[\/color]/; |
|
|
2548 | } |
|
|
2549 | |
|
|
2550 | $color &= cf::NDI_COLOR_MASK; |
|
|
2551 | |
2545 | if (0 && $msg =~ /\[/) { |
2552 | if (0 && $msg =~ /\[/) { |
2546 | $self->send_packet ("drawextinfo $color 4 0 $msg") |
2553 | $self->send_packet ("drawextinfo $color 4 0 $msg") |
2547 | } else { |
2554 | } else { |
2548 | $msg =~ s/\[\/?(?:b|i|u|fixed|color)[^\]]*\]//g; |
2555 | $msg =~ s/\[\/?(?:b|i|u|fixed|color)[^\]]*\]//g; |
2549 | $self->send_packet ("drawinfo $color $msg") |
2556 | $self->send_packet ("drawinfo $color $msg") |
… | |
… | |
2865 | # TODO: for gcfclient pleasure, we should give resources |
2872 | # TODO: for gcfclient pleasure, we should give resources |
2866 | # that gcfclient doesn't grok a >10000 face index. |
2873 | # that gcfclient doesn't grok a >10000 face index. |
2867 | my $res = $facedata->{resource}; |
2874 | my $res = $facedata->{resource}; |
2868 | my $enc = JSON::XS->new->utf8->canonical; |
2875 | my $enc = JSON::XS->new->utf8->canonical; |
2869 | |
2876 | |
|
|
2877 | my $soundconf = delete $res->{"res/sound.conf"}; |
|
|
2878 | |
2870 | while (my ($name, $info) = each %$res) { |
2879 | while (my ($name, $info) = each %$res) { |
2871 | my $meta = $enc->encode ({ |
2880 | my $meta = $enc->encode ({ |
2872 | name => $name, |
2881 | name => $name, |
2873 | type => $info->{type}, |
2882 | %{ $info->{meta} || {} }, |
2874 | copyright => $info->{copyright}, #TODO# |
|
|
2875 | }); |
2883 | }); |
2876 | |
2884 | |
2877 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
2885 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
2878 | |
2886 | |
2879 | if ($name =~ /\.(?:jpg|png)$/) { |
2887 | if ($info->{type} & 1) { |
2880 | cf::face::set_data $idx, 0, $info->{data}, $info->{chksum};#d# temp hack |
2888 | # prepend meta info |
2881 | cf::face::set_data $idx, 1, $info->{data}, $info->{chksum};#d# temp hack |
2889 | |
2882 | } else { |
|
|
2883 | my $data = pack "(w/a*)*", $meta, $info->{data}; |
2890 | my $data = pack "(w/a*)*", $meta, $info->{data}; |
2884 | my $chk = Digest::MD5::md5 "$info->{chksum},$meta"; # mangle data checksum and metadata |
2891 | my $chk = Digest::MD5::md5 "$info->{chksum},$meta"; # mangle data checksum and metadata |
2885 | |
2892 | |
2886 | cf::face::set_type $idx, 1; |
|
|
2887 | cf::face::set_data $idx, 0, $data, $chk; |
2893 | cf::face::set_data $idx, 0, $data, $chk; |
|
|
2894 | } else { |
|
|
2895 | cf::face::set_data $idx, 0, $info->{data}, $info->{chksum}; |
2888 | } |
2896 | } |
2889 | |
2897 | |
|
|
2898 | cf::face::set_type $idx, $info->{type}; |
|
|
2899 | |
2890 | cf::cede_to_tick; |
2900 | cf::cede_to_tick; |
2891 | } |
2901 | } |
|
|
2902 | |
|
|
2903 | if ($soundconf) { |
|
|
2904 | $soundconf = $enc->decode (delete $soundconf->{data}); |
|
|
2905 | |
|
|
2906 | for (0 .. SOUND_CAST_SPELL_0 - 1) { |
|
|
2907 | my $sound = $soundconf->{compat}[$_] |
|
|
2908 | or next; |
|
|
2909 | |
|
|
2910 | my $face = cf::face::find "sound/$sound->[1]"; |
|
|
2911 | |
|
|
2912 | cf::sound::set $sound->[0] => $face; |
|
|
2913 | cf::sound::old_sound_index $_, $face; # gcfclient-compat |
|
|
2914 | } |
|
|
2915 | |
|
|
2916 | #TODO |
|
|
2917 | } |
2892 | } |
2918 | } |
2893 | |
2919 | |
2894 | 1 |
2920 | 1 |
2895 | } |
2921 | } |
|
|
2922 | |
|
|
2923 | register_exticmd fx_want => sub { |
|
|
2924 | my ($ns, $want) = @_; |
|
|
2925 | |
|
|
2926 | while (my ($k, $v) = each %$want) { |
|
|
2927 | $ns->fx_want ($k, $v); |
|
|
2928 | } |
|
|
2929 | }; |
2896 | |
2930 | |
2897 | sub reload_regions { |
2931 | sub reload_regions { |
2898 | load_resource_file "$MAPDIR/regions" |
2932 | load_resource_file "$MAPDIR/regions" |
2899 | or die "unable to load regions file\n"; |
2933 | or die "unable to load regions file\n"; |
2900 | |
2934 | |