ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.103 by root, Mon Apr 23 19:17:41 2007 UTC vs.
Revision 1.108 by root, Sun Jun 24 04:11:22 2007 UTC

249 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 249 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
250 $::GAUGES->{food} ->set_value ($fo, $fo_m); 250 $::GAUGES->{food} ->set_value ($fo, $fo_m);
251 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 251 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
252 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 252 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))
253 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 253 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
254 my $rng = $stats->{+CS_STAT_RANGE}; 254 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
255 $rng =~ s/^Range: //; # thank you so much dear server
256 $::GAUGES->{range} ->set_text ("Rng: " . $rng);
257 my $title = $stats->{+CS_STAT_TITLE}; 255 my $title = $stats->{+CS_STAT_TITLE};
258 $title =~ s/^Player: //; 256 $title =~ s/^Player: //;
259 $::STATWIDS->{title} ->set_text ("Title: " . $title); 257 $::STATWIDS->{title} ->set_text ("Title: " . $title);
260 258
261 $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); 259 $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR});
634 $LAST_QUERY = $prompt; 632 $LAST_QUERY = $prompt;
635 633
636 $self->{query}-> ($self, $flags, $prompt); 634 $self->{query}-> ($self, $flags, $prompt);
637} 635}
638 636
637sub sanitise_xml($) {
638 local $_ = shift;
639
640 # we now weed out all tags we do not support
641 s%<(?!/?i>|/?u>|/?b>|fg |/fg>)%&lt;%g;
642 # now all entities
643 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
644
645 # handle some elements
646 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
647 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
648
649 $_
650}
651
652our %NAME_TO_COLOR = (
653 black => 0,
654 white => 1,
655 darkblue => 2,
656 red => 3,
657 orange => 4,
658 lightblue => 5,
659 darkorange => 6,
660 green => 7,
661 darkgreen => 8,
662 grey => 9,
663 brown => 10,
664 yellow => 11,
665 tan => 12,
666);
667
639our @CF_COLOR = ( 668our @CF_COLOR = (
640 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 669 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
641 [1.00, 1.00, 1.00], 670 [1.00, 1.00, 1.00],
642 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] 671 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
643 [1.00, 0.00, 0.00], 672 [1.00, 0.00, 0.00],
650 [0.75, 0.61, 0.20], 679 [0.75, 0.61, 0.20],
651 [0.99, 0.77, 0.26], 680 [0.99, 0.77, 0.26],
652 [0.74, 0.65, 0.41], 681 [0.74, 0.65, 0.41],
653); 682);
654 683
655sub drawinfo { 684sub msg {
656 my ($self, $color, $text) = @_; 685 my ($self, $color, $type, $text, @extra) = @_;
657 686
687 $text = sanitise_xml $text;
688
689 if (my $cb = $self->{cb_msg}{$type}) {
690 $_->($self, $color, $type, $text, @extra) for values %$cb;
691 } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) {
692 $type =~ s/-/_/g;
693 $self->{$type} = $text;
694 } else {
695 $self->logprint ("msg: ", $text);
696 return if $color < 0; # negative color == ignore if not understood
697
658 my $fg = $CF_COLOR[$color % @CF_COLOR]; 698 my $fg = $CF_COLOR[$color % @CF_COLOR];
659 699
660 $self->logprint ("info: ", $text);
661
662 ## try to create single paragraphs of multiple lines sent by the server 700 ## try to create single paragraphs of multiple lines sent by the server
663 # no longer neecssary with TRT servers 701 # no longer neecssary with TRT servers
664 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 702 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
665 703
666 $text = CFPlus::asxml $text;
667 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
668 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
669
670 ::message ({ fg => $fg, markup => $_ }) 704 ::message ({ fg => $fg, markup => $_ })
671 for split /\n/, $text; 705 for split /\n/, $text;
672 706
673 $self->{statusbox}->add ($text, 707 $self->{statusbox}->add ($text,
674 group => $text, 708 group => $text,
675 fg => $fg, 709 fg => $fg,
676 timeout => $color >= 2 ? 180 : 10, 710 timeout => $color >= 2 ? 180 : 10,
677 tooltip_font => $::FONT_FIXED, 711 tooltip_font => $::FONT_FIXED,
678 ); 712 );
679} 713 }
680
681sub drawextinfo {
682 my ($self, $color, $type, $subtype, $message) = @_;
683
684 $self->drawinfo ($color, $message);
685} 714}
686 715
687sub spell_add { 716sub spell_add {
688 my ($self, $spell) = @_; 717 my ($self, $spell) = @_;
689 718
922 $::SERVER_INFO->set_markup ( 951 $::SERVER_INFO->set_markup (
923 "server <tt>$self->{host}:$self->{port}</tt>\n" 952 "server <tt>$self->{host}:$self->{port}</tt>\n"
924 . "protocol version <tt>$self->{version}</tt>\n" 953 . "protocol version <tt>$self->{version}</tt>\n"
925 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 954 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
926 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 955 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
956 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
927 . "editing support $yesno[!!$self->{editor_support}]\n" 957 . "editing support $yesno[!!$self->{editor_support}]\n"
928 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 958 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
959 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
929 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 960 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
930 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 961 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
931 . "map size $self->{mapw}×$self->{maph}\n" 962 . "map size $self->{mapw}×$self->{maph}\n"
932 ); 963 );
933 964
1096 1127
1097 if ($msg->{msgtype} eq "reply") { 1128 if ($msg->{msgtype} eq "reply") {
1098 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1129 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1099 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1130 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1100 1131
1101 my $text = "\n" . CFPlus::asxml $msg->{msg}; 1132 my $text = "\n" . CFPlus::Protocol::sanitise_xml $msg->{msg};
1102 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; 1133 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} };
1103 my @link; 1134 my @link;
1104 $text =~ s{ 1135 $text =~ s{
1105 ($match) 1136 ($match)
1106 }{ 1137 }{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines