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.217 by root, Thu Apr 8 04:49:32 2010 UTC vs.
Revision 1.227 by root, Tue Nov 20 14:32:12 2012 UTC

14use DC::Item; 14use DC::Item;
15 15
16use base 'Deliantra::Protocol::Base'; 16use base 'Deliantra::Protocol::Base';
17 17
18our $TEX_DIALOGUE = new_from_resource DC::Texture 18our $TEX_DIALOGUE = new_from_resource DC::Texture
19 "dialogue.png", minify => 1, mipmap => 1; 19 "dialogue.png", minify => 1, mipmap => 1;
20 20
21our $TEX_NOFACE = new_from_resource DC::Texture 21our $TEX_NOFACE = new_from_resource DC::Texture
22 "noface.png", minify => 1, mipmap => 1, wrap => 1; 22 "noface.png", minify => 1, mipmap => 1, wrap => 1;
23 23
24sub MIN_TEXTURE_UNUSED() { 1 }#d# 24sub MIN_TEXTURE_UNUSED() { 1 }#d#
27 my ($class, %arg) = @_; 27 my ($class, %arg) = @_;
28 28
29 my $self = $class->SUPER::new (%arg, 29 my $self = $class->SUPER::new (%arg,
30 setup_req => { 30 setup_req => {
31 extmap => 1, 31 extmap => 1,
32 excmd => 1,
33 widget => 2, 32 widget => 2,
34 %{$arg{setup_req} || {}}, 33 %{$arg{setup_req} || {}},
35 }, 34 },
36 ); 35 );
37 36
38 $self->{map_widget}->clr_commands; 37 $self->update_fx_want;
39 38
40 my @cmd_help = map { 39 my $exp_guard = $self->addme_guard;
41 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 40 my $skl_guard = $self->addme_guard;
42 or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; 41 my $spl_guard = $self->addme_guard;
42 $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub {
43 my ($exp, $skl, $spl) = @_;
43 44
44 my $cmd = $1; 45 $self->register_face_handler ($exp, sub {
45 my @args = split /\|/, $2; 46 my ($face) = @_;
46 @args = (".*") unless @args;
47 47
48 my (undef, @par) = DC::Pod::section_of $_; 48 undef $exp_guard;
49 my $text = DC::Pod::as_label @par; 49 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
50 $_->() for values %{ $self->{on_exp_update} };
51 });
50 52
51 $_ = $_ eq ".*" ? "" : " $_" 53 $self->register_face_handler ($skl, sub {
52 for @args; 54 my ($face) = @_;
53 55
54 map ["$cmd$_", $text], 56 undef $skl_guard;
55 sort { (length $a) <=> (length $b) } 57 my $info = $self->{json_coder}->decode (delete $face->{data});
56 @args 58 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
57 } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } 59 });
58 DC::Pod::find command => "*"; 60
61 $self->register_face_handler ($spl, sub {
62 my ($face) = @_;
63
64 undef $spl_guard;
65 my $info = $self->{json_coder}->decode (delete $face->{data});
66 $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info };
67 });
68
69 ()
70 });
71
72 $::COMPLETER->reset;
59 73
60 $self->{json_coder} 74 $self->{json_coder}
61 ->convert_blessed 75 ->convert_blessed
62 ->filter_json_single_key_object ("\fw" => sub { 76 ->filter_json_single_key_object ("\fw" => sub {
63 $self->{widget}{$_[0]} 77 $self->{widget}{$_[0]}
81 $::INVR->clear; 95 $::INVR->clear;
82 $::INVR_HB->clear; 96 $::INVR_HB->clear;
83 $::FLOORBOX->clear; 97 $::FLOORBOX->clear;
84 }); 98 });
85 99
86 $self->{map_widget}->add_command (@$_)
87 for @cmd_help;
88
89 { 100 {
90 $self->{dialogue} = my $tex = $TEX_DIALOGUE; 101 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
91 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 102 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
92 } 103 }
93 104
95 $self->{noface} = my $tex = $TEX_NOFACE; 106 $self->{noface} = my $tex = $TEX_NOFACE;
96 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 107 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
97 } 108 }
98 109
99# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id 110# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
100# $self->{expire_w} = EV::timer 1, 1, sub { 111# $self->{expire_w} = AE::timer 1, 1, sub {
101# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; 112# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
102# 113#
103# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { 114# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
104# warn DC::SvREFCNT $self->{texture}[$_]; 115# warn DC::SvREFCNT $self->{texture}[$_];
105# $self->{texture}[$_]->unload; 116# $self->{texture}[$_]->unload;
117 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 128 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
118 129
119 $self 130 $self
120} 131}
121 132
133 #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d#
134#sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d#
135
122sub update_fx_want { 136sub update_fx_want {
123 my ($self) = @_; 137 my ($self) = @_;
124 138
125 $self->send_exti_msg (fx_want => { 139 $self->send_exti_msg (fx_want => {
126 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC 140 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
130} 144}
131 145
132sub ext_capabilities { 146sub ext_capabilities {
133 my ($self, %cap) = @_; 147 my ($self, %cap) = @_;
134 148
135 $self->update_fx_want;
136
137 $self->send_exti_req (resource => "exp_table", sub {
138 my ($exp_table) = @_;
139
140 $self->register_face_handler ($exp_table, sub {
141 my ($face) = @_;
142
143 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
144 $_->() for values %{ $self->{on_exp_update} || {} };
145 });
146
147 ()
148 });
149
150 if (my $ts = $cap{tileset}) { 149 if (my $ts = $cap{tileset}) {
151 if (my ($default) = grep $_->[2] & 1, @$ts) { 150 if (my ($default) = grep $_->[2] & 1, @$ts) {
152 $self->{tileset} = $default; 151 $self->{tileset} = $default;
153 $self->{tilesize} = $default->[3]; 152 $self->{tilesize} = $default->[3];
154 $self->setup_req (tileset => $default->[0]); 153 $self->setup_req (tileset => $default->[0]);
162} 161}
163 162
164sub ext_ambient_music { 163sub ext_ambient_music {
165 my ($self, $songs) = @_; 164 my ($self, $songs) = @_;
166 &::audio_music_set_ambient ($songs); 165 &::audio_music_set_ambient ($songs);
166}
167
168sub ext_command_list {
169 my ($self, @faces) = @_;
170
171 my $handler = $self->{command_facehandler} = {};
172 my $commands = $::COMPLETER->{command_list} = {};
173
174 for my $idx (@faces) {
175 $handler->{$idx} = $self->register_face_handler ($idx, sub {
176 my ($face) = @_;
177
178 $commands->{$idx} =
179 $face->{cache} ||= $self->{json_coder}->decode ($face->{data});
180 });
181 }
167} 182}
168 183
169############################################################################# 184#############################################################################
170 185
171sub widget_associate { 186sub widget_associate {
454 469
455 if (my @diffs = 470 if (my @diffs =
456 ( 471 (
457 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), 472 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()),
458 map { 473 map {
459 $stats->{$_} && $prev->{$_} 474 $stats->{$_} && $prev->{$_}
460 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 475 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
461 } sort { $a <=> $b } keys %{$self->{skill_info}} 476 } sort { $a <=> $b } keys %{$self->{skill_info}}
462 ) 477 )
463 ) { 478 ) {
464 my $msg = join " ", @diffs; 479 my $msg = join " ", @diffs;
669} 684}
670 685
671sub feed_map1a { 686sub feed_map1a {
672 my ($self, $data) = @_; 687 my ($self, $data) = @_;
673 688
674 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 689 my $missing = $self->{map}->map1a_update ($data);
675 my $delay; 690 my $delay;
676 691
677 for my $tile (@$missing) { 692 for my $tile (@$missing) {
678 next if $self->{delay}{$tile}; 693 next if $self->{delay}{$tile};
679 694
1042 my ($self, $flags, $prompt) = @_; 1057 my ($self, $flags, $prompt) = @_;
1043 1058
1044 $prompt = $LAST_QUERY unless length $prompt; 1059 $prompt = $LAST_QUERY unless length $prompt;
1045 $LAST_QUERY = $prompt; 1060 $LAST_QUERY = $prompt;
1046 1061
1047 $self->{query}-> ($self, $flags, $prompt); 1062 $self->{query}->($self, $flags, $prompt);
1048} 1063}
1049 1064
1050sub sanitise_xml($) { 1065sub sanitise_xml($) {
1051 local $_ = shift; 1066 local $_ = shift;
1052 1067
1084 tan => 12, 1099 tan => 12,
1085); 1100);
1086 1101
1087our @CF_COLOR = ( 1102our @CF_COLOR = (
1088 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 1103 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1089 [1.00, 1.00, 1.00], 1104 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1090 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] 1105 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55],
1091 [1.00, 0.00, 0.00], 1106 [1.00, 0.00, 0.00],
1092 [1.00, 0.54, 0.00], 1107 [1.00, 0.54, 0.00],
1093 [0.11, 0.56, 1.00], 1108 [0.11, 0.56, 1.00],
1094 [0.93, 0.46, 0.00], 1109 [0.93, 0.46, 0.00],
1095 [0.18, 0.54, 0.34], 1110 [0.18, 0.54, 0.34],
1114 $self->logprint ("msg: ", $text); 1129 $self->logprint ("msg: ", $text);
1115 return if $color < 0; # negative color == ignore if not understood 1130 return if $color < 0; # negative color == ignore if not understood
1116 1131
1117 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1132 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1118 1133
1119 ## try to create single paragraphs of multiple lines sent by the server
1120 # no longer neecssary with TRT servers
1121 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1122
1123 ::message ({ 1134 ::message ({
1124 fg => $fg, 1135 fg => $fg,
1125 markup => $text, 1136 markup => $text,
1126 type => $type, 1137 type => $type,
1127 extra => [@extra], 1138 extra => [@extra],
1150 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 1161 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
1151 $spell->{message} =~ s/\n+$//; 1162 $spell->{message} =~ s/\n+$//;
1152 $spell->{message} ||= "Server did not provide a description for this spell."; 1163 $spell->{message} ||= "Server did not provide a description for this spell.";
1153 1164
1154 $::SPELL_LIST->add_spell ($spell); 1165 $::SPELL_LIST->add_spell ($spell);
1155 1166 delete $::COMPLETER->{command_list}{spells};
1156 $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message});
1157 $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message});
1158} 1167}
1159 1168
1160sub spell_delete { 1169sub spell_delete {
1161 my ($self, $spell) = @_; 1170 my ($self, $spell) = @_;
1162 1171
1163 $::SPELL_LIST->remove_spell ($spell); 1172 $::SPELL_LIST->remove_spell ($spell);
1173 delete $::COMPLETER->{command_list}{spells};
1164} 1174}
1165 1175
1166sub setup { 1176sub setup {
1167 my ($self, $setup) = @_; 1177 my ($self, $setup) = @_;
1168 1178
1191} 1201}
1192 1202
1193sub eof { 1203sub eof {
1194 my ($self) = @_; 1204 my ($self) = @_;
1195 1205
1196 $self->{map_widget}->clr_commands; 1206 $::COMPLETER->reset;
1197 1207
1198 ::stop_game (); 1208 ::stop_game ();
1199} 1209}
1200 1210
1201sub update_floorbox { 1211sub update_floorbox {
1347sub update_server_info { 1357sub update_server_info {
1348 my ($self) = @_; 1358 my ($self) = @_;
1349 1359
1350 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); 1360 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>");
1351 1361
1362 my $version = JSON::XS->new->encode ($self->{s_version});
1363
1352 $::SERVER_INFO->set_markup ( 1364 $::SERVER_INFO->set_markup (
1353 "server <tt>$self->{host}:$self->{port}</tt>\n" 1365 "server <tt>$self->{host}:$self->{port}</tt>\n"
1354 . "protocol version <tt>$self->{version}</tt>\n" 1366 . "protocol version <tt>$version</tt>\n"
1355 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1356 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1357 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1358 . "editing support $yesno[!!$self->{editor_support}]\n" 1367 . "editing support $yesno[!!$self->{editor_support}]\n"
1359 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1360 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1361 . "client support $yesno[$self->{cfplus_ext} > 0]" 1368 . "client support $yesno[$self->{cfplus_ext} > 0]"
1362 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1369 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1363 . "map size $self->{mapw}×$self->{maph}\n" 1370 . "map size $self->{mapw}×$self->{maph}\n"
1364 ); 1371 );
1365 1372
1399 $self->send_ext_req (lookat => $x, $y, sub { 1406 $self->send_ext_req (lookat => $x, $y, sub {
1400 my (%msg) = @_; 1407 my (%msg) = @_;
1401 1408
1402 if (exists $msg{npc_dialog}) { 1409 if (exists $msg{npc_dialog}) {
1403 # start npc chat dialog 1410 # start npc chat dialog
1404 $self->{npc_dialog} = new DC::NPCDialog:: 1411 $self->{w}{npc_dialog} = new DC::NPCDialog::
1405 token => $msg{npc_dialog}, 1412 token => $msg{npc_dialog},
1406 title => "$msg{npc_dialog}[0] (NPC)", 1413 title => "$msg{npc_dialog}[0] (NPC)",
1407 conn => $self, 1414 conn => $self,
1408 ; 1415 ;
1409 } 1416 }
1414} 1421}
1415 1422
1416sub destroy { 1423sub destroy {
1417 my ($self) = @_; 1424 my ($self) = @_;
1418 1425
1419 (delete $self->{npc_dialog})->destroy 1426 $_->destroy
1420 if $self->{npc_dialog}; 1427 for values %{ $self->{w} };
1421 1428
1422 $self->SUPER::destroy; 1429 $self->SUPER::destroy;
1423 1430
1424 %$self = (); 1431 %$self = ();
1425} 1432}
1579 1586
1580 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 1587 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
1581 1588
1582 if ($self->{conn}) { 1589 if ($self->{conn}) {
1583 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; 1590 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id};
1584 delete $self->{conn}{npc_dialog}; 1591 delete $self->{conn}{w}{npc_dialog};
1585 $self->{conn}->disconnect_ext ($self->{id}); 1592 $self->{conn}->disconnect_ext ($self->{id});
1586 } 1593 }
1587 1594
1588 $self->SUPER::destroy; 1595 $self->SUPER::destroy;
1589} 1596}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines