… | |
… | |
20 | my ($class, %arg) = @_; |
20 | my ($class, %arg) = @_; |
21 | |
21 | |
22 | my $self = $class->SUPER::new (%arg, |
22 | my $self = $class->SUPER::new (%arg, |
23 | setup_req => { |
23 | setup_req => { |
24 | extmap => 1, |
24 | extmap => 1, |
|
|
25 | excmd => 1, |
25 | %{$arg{setup_req} || {}}, |
26 | %{$arg{setup_req} || {}}, |
26 | }, |
27 | }, |
27 | ); |
28 | ); |
28 | |
29 | |
29 | $self->{map_widget}->clr_commands; |
30 | $self->{map_widget}->clr_commands; |
… | |
… | |
248 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
249 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
249 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
250 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
250 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
251 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
251 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
252 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
252 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
253 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
253 | my $rng = $stats->{+CS_STAT_RANGE}; |
254 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
254 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
255 | $::GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
256 | my $title = $stats->{+CS_STAT_TITLE}; |
255 | my $title = $stats->{+CS_STAT_TITLE}; |
257 | $title =~ s/^Player: //; |
256 | $title =~ s/^Player: //; |
258 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
257 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
259 | |
258 | |
260 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
259 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
… | |
… | |
633 | $LAST_QUERY = $prompt; |
632 | $LAST_QUERY = $prompt; |
634 | |
633 | |
635 | $self->{query}-> ($self, $flags, $prompt); |
634 | $self->{query}-> ($self, $flags, $prompt); |
636 | } |
635 | } |
637 | |
636 | |
638 | sub drawinfo { |
637 | sub sanitise_xml($) { |
639 | my ($self, $color, $text) = @_; |
638 | local $_ = shift; |
640 | |
639 | |
641 | my @color = ( |
640 | # we now weed out all tags we do not support |
|
|
641 | s%<(?!/?i>|/?u>|/?b>|fg |/fg>)%<%g; |
|
|
642 | # now all entities |
|
|
643 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/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 | |
|
|
652 | our %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 | |
|
|
668 | our @CF_COLOR = ( |
642 | [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], |
643 | [1.00, 1.00, 1.00], |
670 | [1.00, 1.00, 1.00], |
644 | [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] |
645 | [1.00, 0.00, 0.00], |
672 | [1.00, 0.00, 0.00], |
646 | [1.00, 0.54, 0.00], |
673 | [1.00, 0.54, 0.00], |
647 | [0.11, 0.56, 1.00], |
674 | [0.11, 0.56, 1.00], |
648 | [0.93, 0.46, 0.00], |
675 | [0.93, 0.46, 0.00], |
649 | [0.18, 0.54, 0.34], |
676 | [0.18, 0.54, 0.34], |
650 | [0.56, 0.73, 0.56], |
677 | [0.56, 0.73, 0.56], |
651 | [0.80, 0.80, 0.80], |
678 | [0.80, 0.80, 0.80], |
652 | [0.75, 0.61, 0.20], |
679 | [0.75, 0.61, 0.20], |
653 | [0.99, 0.77, 0.26], |
680 | [0.99, 0.77, 0.26], |
654 | [0.74, 0.65, 0.41], |
681 | [0.74, 0.65, 0.41], |
655 | ); |
682 | ); |
656 | |
683 | |
657 | my $fg = $color[$color % @color]; |
684 | sub msg { |
|
|
685 | my ($self, $color, $type, $text, @extra) = @_; |
658 | |
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 { |
659 | $self->logprint ("info: ", $text); |
695 | $self->logprint ("msg: ", $text); |
|
|
696 | return if $color < 0; # negative color == ignore if not understood |
660 | |
697 | |
|
|
698 | my $fg = $CF_COLOR[$color % @CF_COLOR]; |
|
|
699 | |
661 | ## 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 |
662 | # no longer neecssary with TRT servers |
701 | # no longer neecssary with TRT servers |
663 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
702 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
664 | |
703 | |
665 | $text = CFPlus::asxml $text; |
|
|
666 | $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
|
|
667 | $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
|
|
668 | |
|
|
669 | ::message ({ fg => $fg, markup => $_ }) |
704 | ::message ({ fg => $fg, markup => $_ }) |
670 | for split /\n/, $text; |
705 | for split /\n/, $text; |
671 | |
706 | |
672 | $self->{statusbox}->add ($text, |
707 | $self->{statusbox}->add ($text, |
673 | group => $text, |
708 | group => $text, |
674 | fg => $fg, |
709 | fg => $fg, |
675 | timeout => $color >= 2 ? 180 : 10, |
710 | timeout => $color >= 2 ? 180 : 10, |
676 | tooltip_font => $::FONT_FIXED, |
711 | tooltip_font => $::FONT_FIXED, |
677 | ); |
712 | ); |
678 | } |
713 | } |
679 | |
|
|
680 | sub drawextinfo { |
|
|
681 | my ($self, $color, $type, $subtype, $message) = @_; |
|
|
682 | |
|
|
683 | $self->drawinfo ($color, $message); |
|
|
684 | } |
714 | } |
685 | |
715 | |
686 | sub spell_add { |
716 | sub spell_add { |
687 | my ($self, $spell) = @_; |
717 | my ($self, $spell) = @_; |
688 | |
718 | |
… | |
… | |
921 | $::SERVER_INFO->set_markup ( |
951 | $::SERVER_INFO->set_markup ( |
922 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
952 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
923 | . "protocol version <tt>$self->{version}</tt>\n" |
953 | . "protocol version <tt>$self->{version}</tt>\n" |
924 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
954 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
925 | . "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" |
926 | . "editing support $yesno[!!$self->{editor_support}]\n" |
957 | . "editing support $yesno[!!$self->{editor_support}]\n" |
927 | . "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" |
928 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
960 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
929 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
961 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
930 | . "map size $self->{mapw}×$self->{maph}\n" |
962 | . "map size $self->{mapw}×$self->{maph}\n" |
931 | ); |
963 | ); |
932 | |
964 | |
… | |
… | |
1095 | |
1127 | |
1096 | if ($msg->{msgtype} eq "reply") { |
1128 | if ($msg->{msgtype} eq "reply") { |
1097 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1129 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1098 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1130 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1099 | |
1131 | |
1100 | my $text = "\n" . CFPlus::asxml $msg->{msg}; |
1132 | my $text = "\n" . CFPlus::Protocol::sanitise_xml $msg->{msg}; |
1101 | 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} }; |
1102 | my @link; |
1134 | my @link; |
1103 | $text =~ s{ |
1135 | $text =~ s{ |
1104 | ($match) |
1136 | ($match) |
1105 | }{ |
1137 | }{ |