--- deliantra/Deliantra-Client/DC/Protocol.pm 2007/07/23 15:30:45 1.127 +++ deliantra/Deliantra-Client/DC/Protocol.pm 2007/07/23 21:03:26 1.128 @@ -50,16 +50,16 @@ } sort { $a->{par} <=> $b->{par} } CFPlus::Pod::find command => "*"; - $self->connect_ext (event_music => sub { - my ($ev) = @_; + $self->connect_ext (music => sub { + my (%ev) = @_; return unless $::CFG->{bgm_enable}; - my $faces = $ev->{faces}; + my $faces = $ev{faces}; my @songs; # request music from server if appropriate - if (my $faces = $ev->{faces}) { + if (my $faces = $ev{faces}) { for (@$faces) { my ($face, $pri, $chksum) = @$_; utf8::downgrade $chksum; @@ -99,15 +99,15 @@ } } - if (my $play = $ev->{play}) { + if (my $play = $ev{play}) { &::audio_music_set ($self->{songs} = [map $self->{music_map}{$_}, @$play]); } }); - $self->connect_ext (event_capabilities => sub { - my ($cap) = @_; + $self->connect_ext (capabilities => sub { + my (%cap) = @_; - if (my $ts = $cap->{tileset}) { + if (my $ts = $cap{tileset}) { if (my ($default) = grep $_->[2] & 1, @$ts) { $self->{tileset} = $default; $self->{tilesize} = $default->[3]; @@ -1173,13 +1173,15 @@ sub logged_in { my ($self) = @_; - $self->send_ext_req (cfplus_support => version => 1, sub { - $self->{cfplus_ext} = $_[0]{version}; + $self->send_ext_req (cfplus_support => version => 2, sub { + my (%msg) = @_; + + $self->{cfplus_ext} = $msg{version}; $self->update_server_info; if ($self->{cfplus_ext} >= 2) { $self->send_ext_req ("editor_support", sub { - $self->{editor_support} = $_[0]; + $self->{editor_support} = { @_ }; $self->update_server_info; 0 @@ -1209,15 +1211,14 @@ my ($self, $x, $y) = @_; if ($self->{cfplus_ext}) { - $self->send_ext_req (lookat => dx => $x, dy => $y, sub { - my ($msg) = @_; + $self->send_ext_req (lookat => $x, $y, sub { + my (%msg) = @_; - if (exists $msg->{npc_dialog}) { + if (exists $msg{npc_dialog}) { # start npc chat dialog $self->{npc_dialog} = new CFPlus::NPCDialog:: - dx => $x, - dy => $y, - title => "$msg->{npc_dialog} (NPC)", + token => $msg{npc_dialog}, + title => "$msg{npc_dialog}[0] (NPC)", conn => $self, ; } @@ -1292,10 +1293,12 @@ $self->update_options; - $self->{id} = $self->{conn}->send_ext_req ( - npc_dialog_begin => dx => $self->{dx}, dy => $self->{dy}, - sub { $this && $this->feed (@_) } - ); + $self->{id} = "npc-channel-" . $self->{conn}->token; + $self->{conn}->connect_ext ($self->{id} => sub { + $this->feed (@_) if $this; + }); + + $self->{conn}->send_ext_msg (npc_dialog_begin => $self->{id}, $self->{token}); $self->{entry}->grab_focus; @@ -1328,37 +1331,42 @@ } sub feed { - my ($self, $msg) = @_; + my ($self, $type, @arg) = @_; CFPlus::weaken $self; - if ($msg->{msgtype} eq "reply") { - $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; - $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; - - my $text = "\n" . CFPlus::Protocol::sanitise_xml $msg->{msg}; - my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; - my @link; - $text =~ s{ - ($match) - }{ - my $kw = $1; - - push @link, new CFPlus::UI::Label - markup => "$kw", - can_hover => 1, - can_events => 1, - padding_x => 0, - padding_y => 0, - on_button_up => sub { - $self->send ($kw); - }; + if ($type eq "update") { + my (%info) = @arg; - "\x{fffc}" - }giex; + $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; + $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; - $self->{textview}->add_paragraph ({ markup => $text, widget => \@link }); - $self->{textview}->scroll_to_bottom; + if (exists $info{msg}) { + my $text = "\n" . CFPlus::Protocol::sanitise_xml $info{msg}; + my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; + my @link; + $text =~ s{ + ($match) + }{ + my $kw = $1; + + push @link, new CFPlus::UI::Label + markup => "$kw", + can_hover => 1, + can_events => 1, + padding_x => 0, + padding_y => 0, + on_button_up => sub { + $self->send ($kw); + }; + + "\x{fffc}" + }giex; + + $self->{textview}->add_paragraph ({ markup => $text, widget => \@link }); + $self->{textview}->scroll_to_bottom; + } + $self->update_options; } else { $self->destroy; @@ -1373,7 +1381,7 @@ $self->{textview}->add_paragraph ({ markup => "\n" . CFPlus::asxml $msg }); $self->{textview}->scroll_to_bottom; - $self->{conn}->send_ext_msg (npc_dialog_tell => msgid => $self->{id}, msg => $msg); + $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); } sub destroy { @@ -1382,7 +1390,7 @@ #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 if ($self->{conn}) { - $self->{conn}->send_ext_msg (npc_dialog_end => msgid => $self->{id}) if $self->{id}; + $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; delete $self->{conn}{npc_dialog}; $self->{conn}->disconnect_ext ($self->{id}); }