--- deliantra/Deliantra-Client/DC/Protocol.pm 2007/07/20 16:32:04 1.124
+++ 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];
@@ -211,7 +211,17 @@
my $w = $self->{widget}{$arg->{id}}
or return;
- $w->{$arg->{name}} = $arg->{value};
+ my $attr = $arg->{attr};
+
+ for (my $i = 0; $i < $#$attr; $i += 2) {
+ my ($member, $value) = @$attr[$i, $i+1];
+ if (defined $value) {
+ $w->{$member} = $value;
+ } else {
+ delete $w->{$member};
+ }
+ $w->{parent}->realloc if $member =~ /^c_/ && $w->{visible};
+ }
});
# widget get
@@ -221,7 +231,7 @@
my $w = $self->{widget}{$arg->{id}}
or return;
- $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->{$arg->{name}}]);
+ $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [map $w->{$_}, @{$arg->{attr}}]);
});
# destroy widgets on logout
@@ -1163,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
@@ -1199,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,
;
}
@@ -1282,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;
@@ -1318,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;
@@ -1363,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 {
@@ -1372,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});
}