ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.198 by root, Tue May 20 02:49:56 2008 UTC vs.
Revision 1.226 by root, Thu Nov 15 03:07:46 2012 UTC

1package DC::Protocol; 1package DC::Protocol;
2 2
3use utf8; 3use common::sense;
4use strict; 4
5use Guard ();
5 6
6use Deliantra::Protocol::Constants; 7use Deliantra::Protocol::Constants;
7 8
8use DC; 9use DC;
9use DC::DB; 10use DC::DB;
12use DC::Macro; 13use DC::Macro;
13use DC::Item; 14use DC::Item;
14 15
15use base 'Deliantra::Protocol::Base'; 16use base 'Deliantra::Protocol::Base';
16 17
18our $TEX_DIALOGUE = new_from_resource DC::Texture
19 "dialogue.png", minify => 1, mipmap => 1;
20
21our $TEX_NOFACE = new_from_resource DC::Texture
22 "noface.png", minify => 1, mipmap => 1, wrap => 1;
23
24sub MIN_TEXTURE_UNUSED() { 1 }#d#
25
17sub new { 26sub new {
18 my ($class, %arg) = @_; 27 my ($class, %arg) = @_;
19 28
20 my $self = $class->SUPER::new (%arg, 29 my $self = $class->SUPER::new (%arg,
21 setup_req => { 30 setup_req => {
22 extmap => 1, 31 extmap => 1,
23 excmd => 1,
24 widget => 2, 32 widget => 2,
25 %{$arg{setup_req} || {}}, 33 %{$arg{setup_req} || {}},
26 }, 34 },
27 ); 35 );
36
37 $self->update_fx_want;
38
39 my $exp_guard = $self->addme_guard;
40 my $skl_guard = $self->addme_guard;
41 my $spl_guard = $self->addme_guard;
42 my $cmd_guard = $self->addme_guard;
43 $self->send_exti_req (resource => qw(exp_table skill_info spell_paths command_list), sub {
44 my ($exp, $skl, $spl, $cmd) = @_;
45
46 $self->register_face_handler ($exp, sub {
47 my ($face) = @_;
48
49 undef $exp_guard;
50 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
51 $_->() for values %{ $self->{on_exp_update} };
52 });
53
54 $self->register_face_handler ($skl, sub {
55 my ($face) = @_;
56
57 undef $skl_guard;
58 my $info = $self->{json_coder}->decode (delete $face->{data});
59 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
60 });
61
62 $self->register_face_handler ($spl, sub {
63 my ($face) = @_;
64
65 undef $spl_guard;
66 my $info = $self->{json_coder}->decode (delete $face->{data});
67 $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info };
68 });
69
70 $self->register_face_handler ($cmd, sub {
71 my ($face) = @_;
72
73 undef $cmd_guard;
74 my $info = $self->{json_coder}->decode (delete $face->{data});
75 $self->{command_list} = [ sort map @{ $_->[1] }, grep $_->[0] != 2, @$info ];
76
77 });
78
79 ()
80 });
28 81
29 $self->{map_widget}->clr_commands; 82 $self->{map_widget}->clr_commands;
30 83
31 my @cmd_help = map { 84 my @cmd_help = map {
32 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 85 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
67 for values %{delete $ws->{w} || {}}; 120 for values %{delete $ws->{w} || {}};
68 } 121 }
69 122
70 delete $self->{items}; 123 delete $self->{items};
71 $::INV->clear; 124 $::INV->clear;
125 $::INVR->clear;
72 $::INVR_HB->clear; 126 $::INVR_HB->clear;
73 $::FLOORBOX->clear; 127 $::FLOORBOX->clear;
74 }); 128 });
75 129
76 $self->{map_widget}->add_command (@$_) 130 $self->{map_widget}->add_command (@$_)
77 for @cmd_help; 131 for @cmd_help;
78 132
79 { 133 {
80 $self->{dialogue} = my $tex = new_from_file DC::Texture 134 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
81 DC::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
82 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 135 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
83 } 136 }
84 137
85 { 138 {
86 $self->{noface} = my $tex = new_from_file DC::Texture 139 $self->{noface} = my $tex = $TEX_NOFACE;
87 DC::find_rcfile "noface.png", minify => 1, mipmap => 1;
88 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 140 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
89 } 141 }
142
143# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
144# $self->{expire_w} = AE::timer 1, 1, sub {
145# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
146#
147# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
148# warn DC::SvREFCNT $self->{texture}[$_];
149# $self->{texture}[$_]->unload;
150# warn "expire texture $_\n";#d#
151# }
152#
153# ($self->{expire_count} += $count) < @{ $self->{texture} }
154# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
155# warn "count is $count\n";#d#
156# };
90 157
91 $self->{open_container} = 0; 158 $self->{open_container} = 0;
92 159
93 # per server 160 # per server
94 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 161 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
95 162
96 $self 163 $self
97} 164}
165
166 #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d#
167#sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d#
98 168
99sub update_fx_want { 169sub update_fx_want {
100 my ($self) = @_; 170 my ($self) = @_;
101 171
102 $self->send_exti_msg (fx_want => { 172 $self->send_exti_msg (fx_want => {
106 }); 176 });
107} 177}
108 178
109sub ext_capabilities { 179sub ext_capabilities {
110 my ($self, %cap) = @_; 180 my ($self, %cap) = @_;
111
112 $self->update_fx_want;
113
114 $self->send_exti_req (resource => "exp_table", sub {
115 my ($exp_table) = @_;
116
117 $self->register_face_handler ($exp_table, sub {
118 my ($face) = @_;
119
120 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
121 $_->() for values %{ $self->{on_exp_update} || {} };
122 });
123
124 ()
125 });
126 181
127 if (my $ts = $cap{tileset}) { 182 if (my $ts = $cap{tileset}) {
128 if (my ($default) = grep $_->[2] & 1, @$ts) { 183 if (my ($default) = grep $_->[2] & 1, @$ts) {
129 $self->{tileset} = $default; 184 $self->{tileset} = $default;
130 $self->{tilesize} = $default->[3]; 185 $self->{tilesize} = $default->[3];
255 my %wkw = ( 310 my %wkw = (
256 root => $DC::UI::ROOT, 311 root => $DC::UI::ROOT,
257 tooltip => $DC::UI::TOOLTIP, 312 tooltip => $DC::UI::TOOLTIP,
258 313
259 mapwidget => $::MAPWIDGET, 314 mapwidget => $::MAPWIDGET,
315 menubar => $::MENUBAR,
316 menupopup => $::MENUPOPUP,
317 pickup_enable => $::PICKUP_ENABLE,
260 buttonbar => $::BUTTONBAR, 318 buttonbar => $::BUTTONBAR,
261 metaserver => $::METASERVER, 319 metaserver => $::METASERVER,
262 buttonbar => $::BUTTONBAR, 320 buttonbar => $::BUTTONBAR,
263 login_button => $::LOGIN_BUTTON, 321 login_button => $::LOGIN_BUTTON,
264 quit_dialog => $::QUIT_DIALOG, 322 quit_dialog => $::QUIT_DIALOG,
281 339
282 floorbox => $::FLOORBOX, 340 floorbox => $::FLOORBOX,
283 help_window => $::HELP_WINDOW, 341 help_window => $::HELP_WINDOW,
284 message_window => $::MESSAGE_WINDOW, 342 message_window => $::MESSAGE_WINDOW,
285 message_dist => $::MESSAGE_DIST, 343 message_dist => $::MESSAGE_DIST,
286 statusbox => $::SDTATUSBOX, 344 statusbox => $::STATUSBOX,
287 345
288 inv => $::INV, 346 inv => $::INV,
289 invr => $::INVR, 347 invr => $::INVR,
290 invr_hb => $::INVR_HB, 348 invr_hb => $::INVR_HB,
291 ); 349 );
375 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 433 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
376 : () 434 : ()
377 } 435 }
378 sort { $a <=> $b } keys %{$self->{spell_paths}}; 436 sort { $a <=> $b } keys %{$self->{spell_paths}};
379 437
380 join "", @diff 438 "\u$name: " . (join ", ", @diff)
381} 439}
382 440
383# all stats that are chacked against changes 441# all stats that are chacked against changes
384my @statchange = ( 442my @statchange = (
385 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 443 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
428 486
429 if (my @diffs = 487 if (my @diffs =
430 ( 488 (
431 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), 489 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()),
432 map { 490 map {
433 $stats->{$_} && $prev->{$_} 491 $stats->{$_} && $prev->{$_}
434 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 492 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
435 } sort { $a <=> $b } keys %{$self->{skill_info}} 493 } sort { $a <=> $b } keys %{$self->{skill_info}}
436 ) 494 )
437 ) { 495 ) {
438 my $msg = join " ", @diffs; 496 my $msg = join " ", @diffs;
440 } 498 }
441 499
442 if ( 500 if (
443 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 501 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
444 ) { 502 ) {
445 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 503 my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs);
446 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); 504 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20);
447 } 505 }
448 506
449 $self->update_stats_window ($stats, $prev); 507 $self->update_stats_window ($stats, $prev);
450 508
488 546
489 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 547 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
490 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 548 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
491 $::GAUGES->{food} ->set_value ($fo, $fo_m); 549 $::GAUGES->{food} ->set_value ($fo, $fo_m);
492 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 550 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
493 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 551 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
494 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 552 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
495 $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); 553 $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64});
496 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 554 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
497 my $title = $stats->{+CS_STAT_TITLE}; 555 my $title = $stats->{+CS_STAT_TITLE};
498 $title =~ s/^Player: //; 556 $title =~ s/^Player: //;
499 $::STATWIDS->{title} ->set_text ("Title: " . $title); 557 $::STATWIDS->{title} ->set_text ("Title: " . $title);
500 558
512 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 570 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
513 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); 571 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP});
514 572
515 $self->update_weight; 573 $self->update_weight;
516 574
517 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 575 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
518 for keys %RES_TBL; 576 for keys %RES_TBL;
519 577
520 my $sktbl = $::STATWIDS->{skill_tbl}; 578 my $sktbl = $::STATWIDS->{skill_tbl};
521 my @skills = keys %{ $self->{skill_info} }; 579 my @skills = keys %{ $self->{skill_info} };
522 580
541 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), 599 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
542 ]; 600 ];
543 601
544 my @add = @$sw; 602 my @add = @$sw;
545 603
546 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 604 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
547 605
548 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 606 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
549 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 607 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
550 608
551 my ($x, $y) = (0, 1); 609 my ($x, $y) = (0, 1);
613 my $sw = $self->{skillwid}{$idx}; 671 my $sw = $self->{skillwid}{$idx};
614 $sw->[0]->set_text (::formsep ($val->[1])); 672 $sw->[0]->set_text (::formsep ($val->[1]));
615 $sw->[1]->set_text ($val->[0] * 1); 673 $sw->[1]->set_text ($val->[0] * 1);
616 $sw->[2]->set_value (@$val); 674 $sw->[2]->set_value (@$val);
617 675
618 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 676 $::GAUGES->{skillexp}->set_label ("$name %d%%");
619 $::GAUGES->{sklprg}->set_value (@$val); 677 $::GAUGES->{skillexp}->set_value (@$val);
620 } 678 }
621} 679}
622 680
623sub user_send { 681sub user_send {
624 my ($self, $command) = @_; 682 my ($self, $command) = @_;
637} 695}
638 696
639sub map_scroll { 697sub map_scroll {
640 my ($self, $dx, $dy) = @_; 698 my ($self, $dx, $dy) = @_;
641 699
642 $self->{map}->scroll ($dx, $dy); 700 $self->{map_widget}->scroll ($dx, $dy);
643} 701}
644 702
645sub feed_map1a { 703sub feed_map1a {
646 my ($self, $data) = @_; 704 my ($self, $data) = @_;
647 705
648 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 706 my $missing = $self->{map}->map1a_update ($data);
649 my $delay; 707 my $delay;
650 708
651 for my $tile (@$missing) { 709 for my $tile (@$missing) {
652 next if $self->{delay}{$tile}; 710 next if $self->{delay}{$tile};
653 711
654 $delay = 1; 712 $delay = 1;
655 713
656 if (my $tex = $::CONN->{texture}[$tile]) { 714 if (my $tex = $self->{texture}[$tile]) {
657 $tex->upload; 715 $tex->upload;
658 } else { 716 } else {
659 $self->{delay}{$tile} = 1; 717 $self->{delay}{$tile} = 1;
660 718
661 # we assume the face is in-flight and will eventually come 719 # we assume the face is in-flight and will eventually arrive
662 push @{$self->{tile_cb}{$tile}}, sub { 720 push @{$self->{tile_cb}{$tile}}, sub {
663 delete $self->{delay}{$tile}; 721 delete $self->{delay}{$tile};
664 $_[0]->upload; 722 $_[0]->upload;
665 }; 723 };
666 } 724 }
667 } 725 }
668 726
669 if ($delay) { 727 if ($delay) {
670 # delay the map drawing a tiny bit in the hope of getting the missing fetched 728 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
671 EV::once undef, 0, 0.03, sub { 729 EV::once undef, 0, 0.03, sub {
672 $self->{map_widget}->update 730 $self->{map_widget}->update
673 if $self->{map_widget}; 731 if $self->{map_widget};
674 }; 732 };
675 } else { 733 } else {
963 1021
964 my $tex = $self->{texture}[$tile] ||= 1022 my $tex = $self->{texture}[$tile] ||=
965 new DC::Texture 1023 new DC::Texture
966 tile => $tile, 1024 tile => $tile,
967 image => $data, delete_image => 1, 1025 image => $data, delete_image => 1,
968 minify => 1, mipmap => 1; 1026 minify => 1;
969 1027
970 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1028 if (my $cbs = delete $self->{tile_cb}{$tile}) {
971 $_->($tex) for @$cbs; 1029 $_->($tex) for @$cbs;
972 } 1030 }
973} 1031}
978 my ($self, $num, $cb) = @_; 1036 my ($self, $num, $cb) = @_;
979 1037
980 push @{$self->{face_cb}{$num}}, $cb; 1038 push @{$self->{face_cb}{$num}}, $cb;
981 1039
982 defined wantarray 1040 defined wantarray
983 ? DC::guard { 1041 ? Guard::guard {
984 @{$self->{face_cb}{$num}} 1042 @{$self->{face_cb}{$num}}
985 = grep $_ != $cb, 1043 = grep $_ != $cb,
986 @{$self->{face_cb}{$num}}; 1044 @{$self->{face_cb}{$num}};
987 } 1045 }
988 : () 1046 : ()
1016 my ($self, $flags, $prompt) = @_; 1074 my ($self, $flags, $prompt) = @_;
1017 1075
1018 $prompt = $LAST_QUERY unless length $prompt; 1076 $prompt = $LAST_QUERY unless length $prompt;
1019 $LAST_QUERY = $prompt; 1077 $LAST_QUERY = $prompt;
1020 1078
1021 $self->{query}-> ($self, $flags, $prompt); 1079 $self->{query}->($self, $flags, $prompt);
1022} 1080}
1023 1081
1024sub sanitise_xml($) { 1082sub sanitise_xml($) {
1025 local $_ = shift; 1083 local $_ = shift;
1026 1084
1058 tan => 12, 1116 tan => 12,
1059); 1117);
1060 1118
1061our @CF_COLOR = ( 1119our @CF_COLOR = (
1062 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 1120 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1063 [1.00, 1.00, 1.00], 1121 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1064 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] 1122 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55],
1065 [1.00, 0.00, 0.00], 1123 [1.00, 0.00, 0.00],
1066 [1.00, 0.54, 0.00], 1124 [1.00, 0.54, 0.00],
1067 [0.11, 0.56, 1.00], 1125 [0.11, 0.56, 1.00],
1068 [0.93, 0.46, 0.00], 1126 [0.93, 0.46, 0.00],
1069 [0.18, 0.54, 0.34], 1127 [0.18, 0.54, 0.34],
1088 $self->logprint ("msg: ", $text); 1146 $self->logprint ("msg: ", $text);
1089 return if $color < 0; # negative color == ignore if not understood 1147 return if $color < 0; # negative color == ignore if not understood
1090 1148
1091 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1149 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1092 1150
1093 ## try to create single paragraphs of multiple lines sent by the server
1094 # no longer neecssary with TRT servers
1095 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1096
1097 for (split /\n/, $text) {
1098 ::message ({ 1151 ::message ({
1099 fg => $fg, 1152 fg => $fg,
1100 markup => $_, 1153 markup => $text,
1101 type => $type, 1154 type => $type,
1102 extra => [@extra], 1155 extra => [@extra],
1103 color_flags => $color, #d# ugly, kill 1156 color_flags => $color, #d# ugly, kill
1104 }); 1157 });
1105 1158
1106 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1159# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1107 # actually, this is an ugly design. _we_ should control the channels, 1160# # actually, this is an ugly design. _we_ should control the channels,
1108 # not some random other widget, as the channels are clearly protocol-specific. 1161# # not some random other widget, as the channels are clearly protocol-specific.
1109 # then we could also react to flags such as CLEAR without resorting to 1162# # then we could also react to flags such as CLEAR without resorting to
1110 # hacks such as color_flags, above. 1163# # hacks such as color_flags, above.
1111 }
1112 1164
1113 $self->{statusbox}->add ($text, 1165 $self->{statusbox}->add ($text,
1114 group => $text, 1166 group => $text,
1115 fg => $fg, 1167 fg => $fg,
1116 timeout => $color >= 2 ? 180 : 10, 1168 timeout => $color >= 2 ? 180 : 10,
1323sub update_server_info { 1375sub update_server_info {
1324 my ($self) = @_; 1376 my ($self) = @_;
1325 1377
1326 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); 1378 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>");
1327 1379
1380 my $version = JSON::XS->new->encode ($self->{s_version});
1381
1328 $::SERVER_INFO->set_markup ( 1382 $::SERVER_INFO->set_markup (
1329 "server <tt>$self->{host}:$self->{port}</tt>\n" 1383 "server <tt>$self->{host}:$self->{port}</tt>\n"
1330 . "protocol version <tt>$self->{version}</tt>\n" 1384 . "protocol version <tt>$version</tt>\n"
1331 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1332 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1333 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1334 . "editing support $yesno[!!$self->{editor_support}]\n" 1385 . "editing support $yesno[!!$self->{editor_support}]\n"
1335 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1336 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1337 . "client support $yesno[$self->{cfplus_ext} > 0]" 1386 . "client support $yesno[$self->{cfplus_ext} > 0]"
1338 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1387 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1339 . "map size $self->{mapw}×$self->{maph}\n" 1388 . "map size $self->{mapw}×$self->{maph}\n"
1340 ); 1389 );
1341 1390
1363 }); 1412 });
1364 1413
1365 $self->update_server_info; 1414 $self->update_server_info;
1366 1415
1367 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1416 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1368 $self->send_command ("pickup $::CFG->{pickup}"); 1417 $self->send_pickup ($::CFG->{pickup});
1369} 1418}
1370 1419
1371sub lookat { 1420sub lookat {
1372 my ($self, $x, $y) = @_; 1421 my ($self, $x, $y) = @_;
1373 1422
1375 $self->send_ext_req (lookat => $x, $y, sub { 1424 $self->send_ext_req (lookat => $x, $y, sub {
1376 my (%msg) = @_; 1425 my (%msg) = @_;
1377 1426
1378 if (exists $msg{npc_dialog}) { 1427 if (exists $msg{npc_dialog}) {
1379 # start npc chat dialog 1428 # start npc chat dialog
1380 $self->{npc_dialog} = new DC::NPCDialog:: 1429 $self->{w}{npc_dialog} = new DC::NPCDialog::
1381 token => $msg{npc_dialog}, 1430 token => $msg{npc_dialog},
1382 title => "$msg{npc_dialog}[0] (NPC)", 1431 title => "$msg{npc_dialog}[0] (NPC)",
1383 conn => $self, 1432 conn => $self,
1384 ; 1433 ;
1385 } 1434 }
1390} 1439}
1391 1440
1392sub destroy { 1441sub destroy {
1393 my ($self) = @_; 1442 my ($self) = @_;
1394 1443
1395 (delete $self->{npc_dialog})->destroy 1444 $_->destroy
1396 if $self->{npc_dialog}; 1445 for values %{ $self->{w} };
1397 1446
1398 $self->SUPER::destroy; 1447 $self->SUPER::destroy;
1399 1448
1400 %$self = (); 1449 %$self = ();
1401} 1450}
1537} 1586}
1538 1587
1539sub send { 1588sub send {
1540 my ($self, $msg) = @_; 1589 my ($self, $msg) = @_;
1541 1590
1542 $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); 1591 $self->{textview}->add_paragraph ({
1592 markup =>
1593 "\n<span foreground='#ffff00'><b>"
1594 . (DC::asxml $msg)
1595 . "</b></span>"
1596 });
1543 $self->{textview}->scroll_to_bottom; 1597 $self->{textview}->scroll_to_bottom;
1544 1598
1545 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1599 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1546} 1600}
1547 1601
1550 1604
1551 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 1605 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
1552 1606
1553 if ($self->{conn}) { 1607 if ($self->{conn}) {
1554 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; 1608 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id};
1555 delete $self->{conn}{npc_dialog}; 1609 delete $self->{conn}{w}{npc_dialog};
1556 $self->{conn}->disconnect_ext ($self->{id}); 1610 $self->{conn}->disconnect_ext ($self->{id});
1557 } 1611 }
1558 1612
1559 $self->SUPER::destroy; 1613 $self->SUPER::destroy;
1560} 1614}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines