--- deliantra/server/lib/cf.pm 2007/06/19 18:15:34 1.282 +++ deliantra/server/lib/cf.pm 2007/06/24 04:09:29 1.283 @@ -1349,6 +1349,39 @@ \@paths } +=item $protocol_xml = $player->expand_cfpod ($crossfire_pod) + +Expand crossfire pod fragments into protocol xml. + +=cut + +sub expand_cfpod { + ((my $self), (local $_)) = @_; + + # escape & and < + s/&/&/g; + s/(?, I<>, U<> etc. + s/B<([^\>]*)>/$1<\/b>/ + || s/I<([^\>]*)>/$1<\/i>/ + || s/U<([^\>]*)>/$1<\/u>/ + # replace G tags + || s{G<([^>|]*)\|([^>]*)>}{ + $self->gender ? $2 : $1 + }ge + # replace H + || s/H<([^\>]*)>/[$1]<\/fg>/g; + + # create single paragraphs (very hackish) + s/(?<=\S)\n(?=\w)/ /g; + + $_ +} + =item $player->ext_reply ($msgid, %msg) Sends an ext reply to the player. @@ -2054,7 +2087,10 @@ if ($pl->{npc_dialog} && $pl->{npc_dialog}->{id}) { my $diag = $pl->{npc_dialog}; $diag->{pl}->ext_reply ( - $diag->{id}, msgtype => "reply", msg => $msg, add_topics => [] + $diag->{id}, + msgtype => "reply", + msg => $diag->{pl}->expand_cfpod ($msg), + add_topics => [] ); } else { @@ -2315,6 +2351,43 @@ $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text); } +=item $client->send_msg ($color, $type, $msg, [extra...]) + +Send a drawinfo or msg packet to the client, formatting the msg for the +client if neccessary. C<$type> should be a string identifying the type of +the message, with C being the default. If C<$color> is negative, suppress +the message unless the client supports the msg packet. + +=cut + +sub cf::client::send_msg { + my ($self, $color, $type, $msg, @extra) = @_; + + $msg = $self->pl->expand_cfpod ($msg); + + if ($self->can_msg) { + $self->send_packet ("msg " . cf::to_json [$color, $type, $msg, @extra]); + } else { + # replace some tags by gcfclient-compatible ones + for ($msg) { + 1 while + s/([^<]*)<\/b>/[b]${1}[\/b]/ + || s/([^<]*)<\/i>/[i]${1}[\/i]/ + || s/([^<]*)<\/u>/[ul]${1}[\/ul]/ + || s/([^<]*)<\/tt>/[fixed]${1}[\/fixed]/ + || s/([^<]*)<\/fg>/[color=$1]${1}[\/color]/; + } + + if ($color >= 0) { + if ($msg =~ /\[/) { + $self->send_packet ("drawextinfo $color 4 0 $msg") + } else { + $self->send_packet ("drawinfo $color $msg") + } + } + } +} + =item $client->ext_event ($type, %msg) Sends an exti event to the client.