1 | package DC::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use common::sense; |
4 | use strict; |
|
|
5 | |
4 | |
6 | use Guard (); |
5 | use Guard (); |
7 | |
6 | |
8 | use Deliantra::Protocol::Constants; |
7 | use Deliantra::Protocol::Constants; |
9 | |
8 | |
10 | use DC; |
9 | use DC; |
11 | use DC::DB; |
10 | use DC::DB; |
12 | use DC::UI; |
11 | use DC::UI; |
13 | use DC::Pod; |
|
|
14 | use DC::Macro; |
12 | use DC::Macro; |
15 | use DC::Item; |
13 | use DC::Item; |
16 | |
14 | |
17 | use base 'Deliantra::Protocol::Base'; |
15 | use base 'Deliantra::Protocol::Base'; |
18 | |
16 | |
19 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
17 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
20 | "dialogue.png", minify => 1, mipmap => 1; |
18 | "dialogue.png", minify => 1, mipmap => 1; |
21 | |
19 | |
22 | our $TEX_NOFACE = new_from_resource DC::Texture |
20 | our $TEX_NOFACE = new_from_resource DC::Texture |
23 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
21 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
24 | |
|
|
25 | our $TEX_HIDDEN = new_from_resource DC::Texture # MUST be POT |
|
|
26 | "hidden-0.png", minify => 1, mipmap => 1, wrap => 1; |
|
|
27 | |
22 | |
28 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
23 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
29 | |
24 | |
30 | sub new { |
25 | sub new { |
31 | my ($class, %arg) = @_; |
26 | my ($class, %arg) = @_; |
32 | |
27 | |
33 | my $self = $class->SUPER::new (%arg, |
28 | my $self = $class->SUPER::new (%arg, |
34 | setup_req => { |
29 | setup_req => { |
35 | extmap => 1, |
30 | extmap => 1, |
36 | excmd => 1, |
|
|
37 | widget => 2, |
31 | widget => 2, |
38 | %{$arg{setup_req} || {}}, |
32 | %{$arg{setup_req} || {}}, |
39 | }, |
33 | }, |
40 | ); |
34 | ); |
41 | |
35 | |
42 | $self->{map_widget}->clr_commands; |
36 | $self->update_fx_want; |
43 | |
37 | |
44 | my @cmd_help = map { |
38 | my $exp_guard = $self->addme_guard; |
45 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
39 | my $skl_guard = $self->addme_guard; |
46 | or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; |
40 | my $spl_guard = $self->addme_guard; |
|
|
41 | $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub { |
|
|
42 | my ($exp, $skl, $spl) = @_; |
47 | |
43 | |
48 | my $cmd = $1; |
44 | $self->register_face_handler ($exp, sub { |
49 | my @args = split /\|/, $2; |
45 | my ($face) = @_; |
50 | @args = (".*") unless @args; |
|
|
51 | |
46 | |
52 | my (undef, @par) = DC::Pod::section_of $_; |
47 | undef $exp_guard; |
53 | my $text = DC::Pod::as_label @par; |
48 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
49 | $_->() for values %{ $self->{on_exp_update} }; |
|
|
50 | }); |
54 | |
51 | |
55 | $_ = $_ eq ".*" ? "" : " $_" |
52 | $self->register_face_handler ($skl, sub { |
56 | for @args; |
53 | my ($face) = @_; |
57 | |
54 | |
58 | map ["$cmd$_", $text], |
55 | undef $skl_guard; |
59 | sort { (length $a) <=> (length $b) } |
56 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
60 | @args |
57 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
61 | } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } |
58 | }); |
62 | DC::Pod::find command => "*"; |
59 | |
|
|
60 | $self->register_face_handler ($spl, sub { |
|
|
61 | my ($face) = @_; |
|
|
62 | |
|
|
63 | undef $spl_guard; |
|
|
64 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
65 | $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info }; |
|
|
66 | }); |
|
|
67 | |
|
|
68 | () |
|
|
69 | }); |
|
|
70 | |
|
|
71 | $::COMPLETER->reset; |
63 | |
72 | |
64 | $self->{json_coder} |
73 | $self->{json_coder} |
65 | ->convert_blessed |
74 | ->convert_blessed |
66 | ->filter_json_single_key_object ("\fw" => sub { |
75 | ->filter_json_single_key_object ("\fw" => sub { |
67 | $self->{widget}{$_[0]} |
76 | $self->{widget}{$_[0]} |
… | |
… | |
85 | $::INVR->clear; |
94 | $::INVR->clear; |
86 | $::INVR_HB->clear; |
95 | $::INVR_HB->clear; |
87 | $::FLOORBOX->clear; |
96 | $::FLOORBOX->clear; |
88 | }); |
97 | }); |
89 | |
98 | |
90 | $self->{map_widget}->add_command (@$_) |
|
|
91 | for @cmd_help; |
|
|
92 | |
|
|
93 | { |
99 | { |
94 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
100 | $self->{dialogue} = my $tex = $TEX_DIALOGUE; |
95 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
101 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
96 | } |
102 | } |
97 | |
103 | |
98 | { |
104 | { |
99 | $self->{noface} = my $tex = $TEX_NOFACE; |
105 | $self->{noface} = my $tex = $TEX_NOFACE; |
100 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
106 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
101 | } |
107 | } |
102 | |
108 | |
103 | { |
|
|
104 | $self->{hidden} = my $tex = $TEX_HIDDEN; |
|
|
105 | $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
106 | $self->{map_widget}{hidden_tex} = $tex;#d# |
|
|
107 | } |
|
|
108 | |
|
|
109 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
109 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
110 | # $self->{expire_w} = EV::timer 1, 1, sub { |
110 | # $self->{expire_w} = AE::timer 1, 1, sub { |
111 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
111 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
112 | # |
112 | # |
113 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
113 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
114 | # warn DC::SvREFCNT $self->{texture}[$_]; |
114 | # warn DC::SvREFCNT $self->{texture}[$_]; |
115 | # $self->{texture}[$_]->unload; |
115 | # $self->{texture}[$_]->unload; |
… | |
… | |
127 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
127 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
128 | |
128 | |
129 | $self |
129 | $self |
130 | } |
130 | } |
131 | |
131 | |
|
|
132 | #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d# |
|
|
133 | #sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d# |
|
|
134 | |
132 | sub update_fx_want { |
135 | sub update_fx_want { |
133 | my ($self) = @_; |
136 | my ($self) = @_; |
134 | |
137 | |
135 | $self->send_exti_msg (fx_want => { |
138 | $self->send_exti_msg (fx_want => { |
136 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
139 | 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC |
… | |
… | |
140 | } |
143 | } |
141 | |
144 | |
142 | sub ext_capabilities { |
145 | sub ext_capabilities { |
143 | my ($self, %cap) = @_; |
146 | my ($self, %cap) = @_; |
144 | |
147 | |
145 | $self->update_fx_want; |
|
|
146 | |
|
|
147 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
148 | my ($exp_table) = @_; |
|
|
149 | |
|
|
150 | $self->register_face_handler ($exp_table, sub { |
|
|
151 | my ($face) = @_; |
|
|
152 | |
|
|
153 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
154 | $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
155 | }); |
|
|
156 | |
|
|
157 | () |
|
|
158 | }); |
|
|
159 | |
|
|
160 | if (my $ts = $cap{tileset}) { |
148 | if (my $ts = $cap{tileset}) { |
161 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
149 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
162 | $self->{tileset} = $default; |
150 | $self->{tileset} = $default; |
163 | $self->{tilesize} = $default->[3]; |
151 | $self->{tilesize} = $default->[3]; |
164 | $self->setup_req (tileset => $default->[0]); |
152 | $self->setup_req (tileset => $default->[0]); |
… | |
… | |
172 | } |
160 | } |
173 | |
161 | |
174 | sub ext_ambient_music { |
162 | sub ext_ambient_music { |
175 | my ($self, $songs) = @_; |
163 | my ($self, $songs) = @_; |
176 | &::audio_music_set_ambient ($songs); |
164 | &::audio_music_set_ambient ($songs); |
|
|
165 | } |
|
|
166 | |
|
|
167 | sub ext_command_list { |
|
|
168 | my ($self, @faces) = @_; |
|
|
169 | |
|
|
170 | my $handler = $self->{command_facehandler} = {}; |
|
|
171 | my $commands = $::COMPLETER->{command_list} = {}; |
|
|
172 | |
|
|
173 | for my $idx (@faces) { |
|
|
174 | $handler->{$idx} = $self->register_face_handler ($idx, sub { |
|
|
175 | my ($face) = @_; |
|
|
176 | |
|
|
177 | $commands->{$idx} = |
|
|
178 | $face->{cache} ||= $self->{json_coder}->decode ($face->{data}); |
|
|
179 | }); |
|
|
180 | } |
177 | } |
181 | } |
178 | |
182 | |
179 | ############################################################################# |
183 | ############################################################################# |
180 | |
184 | |
181 | sub widget_associate { |
185 | sub widget_associate { |
… | |
… | |
464 | |
468 | |
465 | if (my @diffs = |
469 | if (my @diffs = |
466 | ( |
470 | ( |
467 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
471 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
468 | map { |
472 | map { |
469 | $stats->{$_} && $prev->{$_} |
473 | $stats->{$_} && $prev->{$_} |
470 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
474 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
471 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
475 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
472 | ) |
476 | ) |
473 | ) { |
477 | ) { |
474 | my $msg = join " ", @diffs; |
478 | my $msg = join " ", @diffs; |
… | |
… | |
548 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
552 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
549 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
553 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
550 | |
554 | |
551 | $self->update_weight; |
555 | $self->update_weight; |
552 | |
556 | |
553 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
557 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
554 | for keys %RES_TBL; |
558 | for keys %RES_TBL; |
555 | |
559 | |
556 | my $sktbl = $::STATWIDS->{skill_tbl}; |
560 | my $sktbl = $::STATWIDS->{skill_tbl}; |
557 | my @skills = keys %{ $self->{skill_info} }; |
561 | my @skills = keys %{ $self->{skill_info} }; |
558 | |
562 | |
… | |
… | |
622 | # progress |
626 | # progress |
623 | (new DC::UI::ExperienceProgress), |
627 | (new DC::UI::ExperienceProgress), |
624 | |
628 | |
625 | # label |
629 | # label |
626 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, |
630 | (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, |
627 | can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), |
631 | can_events => 1, can_hover => 1, tooltip => "#(skill/$name)$TOOLTIP_ALL"), |
628 | ]; |
632 | ]; |
629 | |
633 | |
630 | push @add, |
634 | push @add, |
631 | $x * 4 + 0, $y, $sw->[0], |
635 | $x * 4 + 0, $y, $sw->[0], |
632 | $x * 4 + 1, $y, $sw->[1], |
636 | $x * 4 + 1, $y, $sw->[1], |
… | |
… | |
679 | } |
683 | } |
680 | |
684 | |
681 | sub feed_map1a { |
685 | sub feed_map1a { |
682 | my ($self, $data) = @_; |
686 | my ($self, $data) = @_; |
683 | |
687 | |
684 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
688 | my $missing = $self->{map}->map1a_update ($data); |
685 | my $delay; |
689 | my $delay; |
686 | |
690 | |
687 | for my $tile (@$missing) { |
691 | for my $tile (@$missing) { |
688 | next if $self->{delay}{$tile}; |
692 | next if $self->{delay}{$tile}; |
689 | |
693 | |
… | |
… | |
1052 | my ($self, $flags, $prompt) = @_; |
1056 | my ($self, $flags, $prompt) = @_; |
1053 | |
1057 | |
1054 | $prompt = $LAST_QUERY unless length $prompt; |
1058 | $prompt = $LAST_QUERY unless length $prompt; |
1055 | $LAST_QUERY = $prompt; |
1059 | $LAST_QUERY = $prompt; |
1056 | |
1060 | |
1057 | $self->{query}-> ($self, $flags, $prompt); |
1061 | $self->{query}->($self, $flags, $prompt); |
1058 | } |
|
|
1059 | |
|
|
1060 | sub sanitise_xml($) { |
|
|
1061 | local $_ = shift; |
|
|
1062 | |
|
|
1063 | # we now weed out all tags we do not support |
|
|
1064 | s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>) |
|
|
1065 | }{ |
|
|
1066 | "<" |
|
|
1067 | }gex; |
|
|
1068 | |
|
|
1069 | # now all entities |
|
|
1070 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
|
|
1071 | |
|
|
1072 | # handle some elements |
|
|
1073 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
|
|
1074 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
1075 | |
|
|
1076 | s/\s+$//; |
|
|
1077 | |
|
|
1078 | $_ |
|
|
1079 | } |
1062 | } |
1080 | |
1063 | |
1081 | our %NAME_TO_COLOR = ( |
1064 | our %NAME_TO_COLOR = ( |
1082 | black => 0, |
1065 | black => 0, |
1083 | white => 1, |
1066 | white => 1, |
… | |
… | |
1094 | tan => 12, |
1077 | tan => 12, |
1095 | ); |
1078 | ); |
1096 | |
1079 | |
1097 | our @CF_COLOR = ( |
1080 | our @CF_COLOR = ( |
1098 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1081 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1099 | [1.00, 1.00, 1.00], |
1082 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1100 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
1083 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55], |
1101 | [1.00, 0.00, 0.00], |
1084 | [1.00, 0.00, 0.00], |
1102 | [1.00, 0.54, 0.00], |
1085 | [1.00, 0.54, 0.00], |
1103 | [0.11, 0.56, 1.00], |
1086 | [0.11, 0.56, 1.00], |
1104 | [0.93, 0.46, 0.00], |
1087 | [0.93, 0.46, 0.00], |
1105 | [0.18, 0.54, 0.34], |
1088 | [0.18, 0.54, 0.34], |
… | |
… | |
1111 | ); |
1094 | ); |
1112 | |
1095 | |
1113 | sub msg { |
1096 | sub msg { |
1114 | my ($self, $color, $type, $text, @extra) = @_; |
1097 | my ($self, $color, $type, $text, @extra) = @_; |
1115 | |
1098 | |
1116 | $text = sanitise_xml $text; |
1099 | $text = DC::sanitise_cfxml $text; |
1117 | |
1100 | |
1118 | if (my $cb = $self->{cb_msg}{$type}) { |
1101 | if (my $cb = $self->{cb_msg}{$type}) { |
1119 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
1102 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
1120 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
1103 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
1121 | $type =~ s/-/_/g; |
1104 | $type =~ s/-/_/g; |
… | |
… | |
1124 | $self->logprint ("msg: ", $text); |
1107 | $self->logprint ("msg: ", $text); |
1125 | return if $color < 0; # negative color == ignore if not understood |
1108 | return if $color < 0; # negative color == ignore if not understood |
1126 | |
1109 | |
1127 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1110 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1128 | |
1111 | |
1129 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1130 | # no longer neecssary with TRT servers |
|
|
1131 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1132 | |
|
|
1133 | ::message ({ |
1112 | ::message ({ |
1134 | fg => $fg, |
1113 | fg => $fg, |
1135 | markup => $text, |
1114 | markup => $text, |
1136 | type => $type, |
1115 | type => $type, |
1137 | extra => [@extra], |
1116 | extra => [@extra], |
… | |
… | |
1154 | } |
1133 | } |
1155 | |
1134 | |
1156 | sub spell_add { |
1135 | sub spell_add { |
1157 | my ($self, $spell) = @_; |
1136 | my ($self, $spell) = @_; |
1158 | |
1137 | |
1159 | # try to create single paragraphs out of the multiple lines sent by the server |
|
|
1160 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1161 | $spell->{message} =~ s/\n+$//; |
|
|
1162 | $spell->{message} ||= "Server did not provide a description for this spell."; |
|
|
1163 | |
|
|
1164 | $::SPELL_LIST->add_spell ($spell); |
1138 | $::SPELL_LIST->add_spell ($spell); |
1165 | |
1139 | delete $::COMPLETER->{command_list}{spells}; |
1166 | $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message}); |
|
|
1167 | $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message}); |
|
|
1168 | } |
1140 | } |
1169 | |
1141 | |
1170 | sub spell_delete { |
1142 | sub spell_delete { |
1171 | my ($self, $spell) = @_; |
1143 | my ($self, $spell) = @_; |
1172 | |
1144 | |
1173 | $::SPELL_LIST->remove_spell ($spell); |
1145 | $::SPELL_LIST->remove_spell ($spell); |
|
|
1146 | delete $::COMPLETER->{command_list}{spells}; |
1174 | } |
1147 | } |
1175 | |
1148 | |
1176 | sub setup { |
1149 | sub setup { |
1177 | my ($self, $setup) = @_; |
1150 | my ($self, $setup) = @_; |
1178 | |
1151 | |
1179 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
1152 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
1180 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
1153 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
1181 | } |
1154 | } |
1182 | |
1155 | |
1183 | sub addme_success { |
|
|
1184 | my ($self) = @_; |
|
|
1185 | |
|
|
1186 | my %skill_help; |
|
|
1187 | |
|
|
1188 | for my $node (DC::Pod::find skill_description => "*") { |
|
|
1189 | my (undef, @par) = DC::Pod::section_of $node; |
|
|
1190 | $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; |
|
|
1191 | }; |
|
|
1192 | |
|
|
1193 | for my $skill (values %{$self->{skill_info}}) { |
|
|
1194 | $self->{map_widget}->add_command ("ready_skill $skill", |
|
|
1195 | (DC::asxml "Ready the skill '$skill'\n\n") |
|
|
1196 | . $skill_help{$skill}); |
|
|
1197 | $self->{map_widget}->add_command ("use_skill $skill", |
|
|
1198 | (DC::asxml "Immediately use the skill '$skill'\n\n") |
|
|
1199 | . $skill_help{$skill}); |
|
|
1200 | } |
|
|
1201 | } |
|
|
1202 | |
|
|
1203 | sub eof { |
1156 | sub eof { |
1204 | my ($self) = @_; |
1157 | my ($self) = @_; |
1205 | |
1158 | |
1206 | $self->{map_widget}->clr_commands; |
1159 | $::COMPLETER->reset; |
1207 | |
1160 | |
1208 | ::stop_game (); |
1161 | ::stop_game (); |
1209 | } |
1162 | } |
1210 | |
1163 | |
1211 | sub update_floorbox { |
1164 | sub update_floorbox { |
… | |
… | |
1357 | sub update_server_info { |
1310 | sub update_server_info { |
1358 | my ($self) = @_; |
1311 | my ($self) = @_; |
1359 | |
1312 | |
1360 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1313 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1361 | |
1314 | |
|
|
1315 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1316 | |
1362 | $::SERVER_INFO->set_markup ( |
1317 | $::SERVER_INFO->set_markup ( |
1363 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1318 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1364 | . "protocol version <tt>$self->{version}</tt>\n" |
1319 | . "protocol version <tt>$version</tt>\n" |
1365 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
1366 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
1367 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
|
|
1368 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1320 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1369 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
1370 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
|
|
1371 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1321 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1372 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1322 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1373 | . "map size $self->{mapw}×$self->{maph}\n" |
1323 | . "map size $self->{mapw}×$self->{maph}\n" |
1374 | ); |
1324 | ); |
1375 | |
1325 | |
… | |
… | |
1398 | |
1348 | |
1399 | $self->update_server_info; |
1349 | $self->update_server_info; |
1400 | |
1350 | |
1401 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1351 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1402 | $self->send_pickup ($::CFG->{pickup}); |
1352 | $self->send_pickup ($::CFG->{pickup}); |
1403 | |
|
|
1404 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
|
|
1405 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
|
|
1406 | } |
1353 | } |
1407 | |
1354 | |
1408 | sub lookat { |
1355 | sub lookat { |
1409 | my ($self, $x, $y) = @_; |
1356 | my ($self, $x, $y) = @_; |
1410 | |
1357 | |
… | |
… | |
1412 | $self->send_ext_req (lookat => $x, $y, sub { |
1359 | $self->send_ext_req (lookat => $x, $y, sub { |
1413 | my (%msg) = @_; |
1360 | my (%msg) = @_; |
1414 | |
1361 | |
1415 | if (exists $msg{npc_dialog}) { |
1362 | if (exists $msg{npc_dialog}) { |
1416 | # start npc chat dialog |
1363 | # start npc chat dialog |
1417 | $self->{npc_dialog} = new DC::NPCDialog:: |
1364 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1418 | token => $msg{npc_dialog}, |
1365 | token => $msg{npc_dialog}, |
1419 | title => "$msg{npc_dialog}[0] (NPC)", |
1366 | title => "$msg{npc_dialog}[0] (NPC)", |
1420 | conn => $self, |
1367 | conn => $self, |
1421 | ; |
1368 | ; |
1422 | } |
1369 | } |
… | |
… | |
1427 | } |
1374 | } |
1428 | |
1375 | |
1429 | sub destroy { |
1376 | sub destroy { |
1430 | my ($self) = @_; |
1377 | my ($self) = @_; |
1431 | |
1378 | |
1432 | (delete $self->{npc_dialog})->destroy |
1379 | $_->destroy |
1433 | if $self->{npc_dialog}; |
1380 | for values %{ $self->{w} }; |
1434 | |
1381 | |
1435 | $self->SUPER::destroy; |
1382 | $self->SUPER::destroy; |
1436 | |
1383 | |
1437 | %$self = (); |
1384 | %$self = (); |
1438 | } |
1385 | } |
… | |
… | |
1538 | |
1485 | |
1539 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1486 | $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; |
1540 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1487 | $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; |
1541 | |
1488 | |
1542 | if (exists $info{msg}) { |
1489 | if (exists $info{msg}) { |
1543 | my $text = "\n" . DC::Protocol::sanitise_xml $info{msg}; |
1490 | my $text = "\n" . DC::sanitise_cfxml $info{msg}; |
1544 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1491 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1545 | my @link; |
1492 | my @link; |
1546 | $text =~ s{ |
1493 | $text =~ s{ |
1547 | ($match) |
1494 | ($match) |
1548 | }{ |
1495 | }{ |
… | |
… | |
1592 | |
1539 | |
1593 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1540 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1594 | |
1541 | |
1595 | if ($self->{conn}) { |
1542 | if ($self->{conn}) { |
1596 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1543 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1597 | delete $self->{conn}{npc_dialog}; |
1544 | delete $self->{conn}{w}{npc_dialog}; |
1598 | $self->{conn}->disconnect_ext ($self->{id}); |
1545 | $self->{conn}->disconnect_ext ($self->{id}); |
1599 | } |
1546 | } |
1600 | |
1547 | |
1601 | $self->SUPER::destroy; |
1548 | $self->SUPER::destroy; |
1602 | } |
1549 | } |