--- deliantra/Deliantra-Client/DC/Protocol.pm 2010/04/08 19:11:21 1.218 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2012/11/21 13:23:10 1.228 @@ -9,14 +9,13 @@ use DC; use DC::DB; use DC::UI; -use DC::Pod; use DC::Macro; use DC::Item; use base 'Deliantra::Protocol::Base'; our $TEX_DIALOGUE = new_from_resource DC::Texture - "dialogue.png", minify => 1, mipmap => 1; + "dialogue.png", minify => 1, mipmap => 1; our $TEX_NOFACE = new_from_resource DC::Texture "noface.png", minify => 1, mipmap => 1, wrap => 1; @@ -29,33 +28,47 @@ my $self = $class->SUPER::new (%arg, setup_req => { extmap => 1, - excmd => 1, widget => 2, %{$arg{setup_req} || {}}, }, ); - $self->{map_widget}->clr_commands; + $self->update_fx_want; + + my $exp_guard = $self->addme_guard; + my $skl_guard = $self->addme_guard; + my $spl_guard = $self->addme_guard; + $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub { + my ($exp, $skl, $spl) = @_; + + $self->register_face_handler ($exp, sub { + my ($face) = @_; + + undef $exp_guard; + $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); + $_->() for values %{ $self->{on_exp_update} }; + }); + + $self->register_face_handler ($skl, sub { + my ($face) = @_; + + undef $skl_guard; + my $info = $self->{json_coder}->decode (delete $face->{data}); + $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; + }); + + $self->register_face_handler ($spl, sub { + my ($face) = @_; + + undef $spl_guard; + my $info = $self->{json_coder}->decode (delete $face->{data}); + $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info }; + }); - my @cmd_help = map { - $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x - or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; - - my $cmd = $1; - my @args = split /\|/, $2; - @args = (".*") unless @args; - - my (undef, @par) = DC::Pod::section_of $_; - my $text = DC::Pod::as_label @par; - - $_ = $_ eq ".*" ? "" : " $_" - for @args; - - map ["$cmd$_", $text], - sort { (length $a) <=> (length $b) } - @args - } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } - DC::Pod::find command => "*"; + () + }); + + $::COMPLETER->reset; $self->{json_coder} ->convert_blessed @@ -83,9 +96,6 @@ $::FLOORBOX->clear; }); - $self->{map_widget}->add_command (@$_) - for @cmd_help; - { $self->{dialogue} = my $tex = $TEX_DIALOGUE; $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); @@ -97,7 +107,7 @@ } # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id -# $self->{expire_w} = EV::timer 1, 1, sub { +# $self->{expire_w} = AE::timer 1, 1, sub { # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; # # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { @@ -119,6 +129,9 @@ $self } + #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d# +#sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d# + sub update_fx_want { my ($self) = @_; @@ -132,21 +145,6 @@ sub ext_capabilities { my ($self, %cap) = @_; - $self->update_fx_want; - - $self->send_exti_req (resource => "exp_table", sub { - my ($exp_table) = @_; - - $self->register_face_handler ($exp_table, sub { - my ($face) = @_; - - $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); - $_->() for values %{ $self->{on_exp_update} || {} }; - }); - - () - }); - if (my $ts = $cap{tileset}) { if (my ($default) = grep $_->[2] & 1, @$ts) { $self->{tileset} = $default; @@ -166,6 +164,22 @@ &::audio_music_set_ambient ($songs); } +sub ext_command_list { + my ($self, @faces) = @_; + + my $handler = $self->{command_facehandler} = {}; + my $commands = $::COMPLETER->{command_list} = {}; + + for my $idx (@faces) { + $handler->{$idx} = $self->register_face_handler ($idx, sub { + my ($face) = @_; + + $commands->{$idx} = + $face->{cache} ||= $self->{json_coder}->decode ($face->{data}); + }); + } +} + ############################################################################# sub widget_associate { @@ -456,7 +470,7 @@ ( ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), map { - $stats->{$_} && $prev->{$_} + $stats->{$_} && $prev->{$_} && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () } sort { $a <=> $b } keys %{$self->{skill_info}} ) @@ -614,7 +628,7 @@ # label (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, - can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), + can_events => 1, can_hover => 1, tooltip => "#(skill/$name)$TOOLTIP_ALL"), ]; push @add, @@ -671,7 +685,7 @@ sub feed_map1a { my ($self, $data) = @_; - my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); + my $missing = $self->{map}->map1a_update ($data); my $delay; for my $tile (@$missing) { @@ -1044,28 +1058,7 @@ $prompt = $LAST_QUERY unless length $prompt; $LAST_QUERY = $prompt; - $self->{query}-> ($self, $flags, $prompt); -} - -sub sanitise_xml($) { - local $_ = shift; - - # we now weed out all tags we do not support - s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>) - }{ - "<" - }gex; - - # now all entities - s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; - - # handle some elements - s/(.*?)<\/fg>/$2<\/span>/gs; - s/(.*?)<\/fg>/$2<\/span>/gs; - - s/\s+$//; - - $_ + $self->{query}->($self, $flags, $prompt); } our %NAME_TO_COLOR = ( @@ -1086,8 +1079,8 @@ our @CF_COLOR = ( [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], - [1.00, 1.00, 1.00], - [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] + [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], + [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55], [1.00, 0.00, 0.00], [1.00, 0.54, 0.00], [0.11, 0.56, 1.00], @@ -1103,7 +1096,7 @@ sub msg { my ($self, $color, $type, $text, @extra) = @_; - $text = sanitise_xml $text; + $text = DC::sanitise_cfxml $text; if (my $cb = $self->{cb_msg}{$type}) { $_->($self, $color, $type, $text, @extra) for values %$cb; @@ -1116,10 +1109,6 @@ my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; - ## try to create single paragraphs of multiple lines sent by the server - # no longer neecssary with TRT servers - #$text =~ s/(?<=\S)\n(?=\w)/ /g; - ::message ({ fg => $fg, markup => $text, @@ -1146,21 +1135,15 @@ sub spell_add { my ($self, $spell) = @_; - # try to create single paragraphs out of the multiple lines sent by the server - $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; - $spell->{message} =~ s/\n+$//; - $spell->{message} ||= "Server did not provide a description for this spell."; - $::SPELL_LIST->add_spell ($spell); - - $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message}); - $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message}); + delete $::COMPLETER->{command_list}{spells}; } sub spell_delete { my ($self, $spell) = @_; $::SPELL_LIST->remove_spell ($spell); + delete $::COMPLETER->{command_list}{spells}; } sub setup { @@ -1170,30 +1153,10 @@ $::MAP->resize ($self->{mapw}, $self->{maph}); } -sub addme_success { - my ($self) = @_; - - my %skill_help; - - for my $node (DC::Pod::find skill_description => "*") { - my (undef, @par) = DC::Pod::section_of $node; - $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par; - }; - - for my $skill (values %{$self->{skill_info}}) { - $self->{map_widget}->add_command ("ready_skill $skill", - (DC::asxml "Ready the skill '$skill'\n\n") - . $skill_help{$skill}); - $self->{map_widget}->add_command ("use_skill $skill", - (DC::asxml "Immediately use the skill '$skill'\n\n") - . $skill_help{$skill}); - } -} - sub eof { my ($self) = @_; - $self->{map_widget}->clr_commands; + $::COMPLETER->reset; ::stop_game (); } @@ -1354,12 +1317,7 @@ $::SERVER_INFO->set_markup ( "server $self->{host}:$self->{port}\n" . "protocol version $version\n" - . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" - . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" - . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" . "editing support $yesno[!!$self->{editor_support}]\n" - . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" - . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" . "client support $yesno[$self->{cfplus_ext} > 0]" . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" . "map size $self->{mapw}×$self->{maph}\n" @@ -1403,7 +1361,7 @@ if (exists $msg{npc_dialog}) { # start npc chat dialog - $self->{npc_dialog} = new DC::NPCDialog:: + $self->{w}{npc_dialog} = new DC::NPCDialog:: token => $msg{npc_dialog}, title => "$msg{npc_dialog}[0] (NPC)", conn => $self, @@ -1418,8 +1376,8 @@ sub destroy { my ($self) = @_; - (delete $self->{npc_dialog})->destroy - if $self->{npc_dialog}; + $_->destroy + for values %{ $self->{w} }; $self->SUPER::destroy; @@ -1529,7 +1487,7 @@ $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; if (exists $info{msg}) { - my $text = "\n" . DC::Protocol::sanitise_xml $info{msg}; + my $text = "\n" . DC::sanitise_cfxml $info{msg}; my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; my @link; $text =~ s{ @@ -1583,7 +1541,7 @@ if ($self->{conn}) { $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; - delete $self->{conn}{npc_dialog}; + delete $self->{conn}{w}{npc_dialog}; $self->{conn}->disconnect_ext ($self->{id}); }