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.212 by root, Thu Dec 17 02:49:38 2009 UTC vs.
Revision 1.227 by root, Tue Nov 20 14:32:12 2012 UTC

1package DC::Protocol; 1package DC::Protocol;
2 2
3use utf8; 3use common::sense;
4use strict;
5 4
6use Guard (); 5use Guard ();
7 6
8use Deliantra::Protocol::Constants; 7use Deliantra::Protocol::Constants;
9 8
15use DC::Item; 14use DC::Item;
16 15
17use base 'Deliantra::Protocol::Base'; 16use base 'Deliantra::Protocol::Base';
18 17
19our $TEX_DIALOGUE = new_from_resource DC::Texture 18our $TEX_DIALOGUE = new_from_resource DC::Texture
20 "dialogue.png", minify => 1, mipmap => 1; 19 "dialogue.png", minify => 1, mipmap => 1;
21 20
22our $TEX_NOFACE = new_from_resource DC::Texture 21our $TEX_NOFACE = new_from_resource DC::Texture
23 "noface.png", minify => 1, mipmap => 1; 22 "noface.png", minify => 1, mipmap => 1, wrap => 1;
24
25our $TEX_HIDDEN = new_from_resource DC::Texture
26 "hidden-0.png", minify => 1, mipmap => 1;
27 23
28sub MIN_TEXTURE_UNUSED() { 1 }#d# 24sub MIN_TEXTURE_UNUSED() { 1 }#d#
29 25
30sub new { 26sub new {
31 my ($class, %arg) = @_; 27 my ($class, %arg) = @_;
32 28
33 my $self = $class->SUPER::new (%arg, 29 my $self = $class->SUPER::new (%arg,
34 setup_req => { 30 setup_req => {
35 extmap => 1, 31 extmap => 1,
36 excmd => 1,
37 widget => 2, 32 widget => 2,
38 %{$arg{setup_req} || {}}, 33 %{$arg{setup_req} || {}},
39 }, 34 },
40 ); 35 );
41 36
42 $self->{map_widget}->clr_commands; 37 $self->update_fx_want;
43 38
44 my @cmd_help = map { 39 my $exp_guard = $self->addme_guard;
45 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 40 my $skl_guard = $self->addme_guard;
46 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) = @_;
47 44
48 my $cmd = $1; 45 $self->register_face_handler ($exp, sub {
49 my @args = split /\|/, $2; 46 my ($face) = @_;
50 @args = (".*") unless @args;
51 47
52 my (undef, @par) = DC::Pod::section_of $_; 48 undef $exp_guard;
53 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 });
54 52
55 $_ = $_ eq ".*" ? "" : " $_" 53 $self->register_face_handler ($skl, sub {
56 for @args; 54 my ($face) = @_;
57 55
58 map ["$cmd$_", $text], 56 undef $skl_guard;
59 sort { (length $a) <=> (length $b) } 57 my $info = $self->{json_coder}->decode (delete $face->{data});
60 @args 58 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
61 } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } 59 });
62 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;
63 73
64 $self->{json_coder} 74 $self->{json_coder}
65 ->convert_blessed 75 ->convert_blessed
66 ->filter_json_single_key_object ("\fw" => sub { 76 ->filter_json_single_key_object ("\fw" => sub {
67 $self->{widget}{$_[0]} 77 $self->{widget}{$_[0]}
85 $::INVR->clear; 95 $::INVR->clear;
86 $::INVR_HB->clear; 96 $::INVR_HB->clear;
87 $::FLOORBOX->clear; 97 $::FLOORBOX->clear;
88 }); 98 });
89 99
90 $self->{map_widget}->add_command (@$_)
91 for @cmd_help;
92
93 { 100 {
94 $self->{dialogue} = my $tex = $TEX_DIALOGUE; 101 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
95 $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}});
96 } 103 }
97 104
98 { 105 {
99 $self->{noface} = my $tex = $TEX_NOFACE; 106 $self->{noface} = my $tex = $TEX_NOFACE;
100 $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}});
101 } 108 }
102 109
103 {
104 $self->{hidden} = my $tex = $TEX_HIDDEN;
105 $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}});
106 }
107
108# $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
109# $self->{expire_w} = EV::timer 1, 1, sub { 111# $self->{expire_w} = AE::timer 1, 1, sub {
110# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; 112# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
111# 113#
112# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { 114# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
113# warn DC::SvREFCNT $self->{texture}[$_]; 115# warn DC::SvREFCNT $self->{texture}[$_];
114# $self->{texture}[$_]->unload; 116# $self->{texture}[$_]->unload;
126 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 128 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
127 129
128 $self 130 $self
129} 131}
130 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
131sub update_fx_want { 136sub update_fx_want {
132 my ($self) = @_; 137 my ($self) = @_;
133 138
134 $self->send_exti_msg (fx_want => { 139 $self->send_exti_msg (fx_want => {
135 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC 140 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
139} 144}
140 145
141sub ext_capabilities { 146sub ext_capabilities {
142 my ($self, %cap) = @_; 147 my ($self, %cap) = @_;
143 148
144 $self->update_fx_want;
145
146 $self->send_exti_req (resource => "exp_table", sub {
147 my ($exp_table) = @_;
148
149 $self->register_face_handler ($exp_table, sub {
150 my ($face) = @_;
151
152 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
153 $_->() for values %{ $self->{on_exp_update} || {} };
154 });
155
156 ()
157 });
158
159 if (my $ts = $cap{tileset}) { 149 if (my $ts = $cap{tileset}) {
160 if (my ($default) = grep $_->[2] & 1, @$ts) { 150 if (my ($default) = grep $_->[2] & 1, @$ts) {
161 $self->{tileset} = $default; 151 $self->{tileset} = $default;
162 $self->{tilesize} = $default->[3]; 152 $self->{tilesize} = $default->[3];
163 $self->setup_req (tileset => $default->[0]); 153 $self->setup_req (tileset => $default->[0]);
171} 161}
172 162
173sub ext_ambient_music { 163sub ext_ambient_music {
174 my ($self, $songs) = @_; 164 my ($self, $songs) = @_;
175 &::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 }
176} 182}
177 183
178############################################################################# 184#############################################################################
179 185
180sub widget_associate { 186sub widget_associate {
463 469
464 if (my @diffs = 470 if (my @diffs =
465 ( 471 (
466 ($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" : ()),
467 map { 473 map {
468 $stats->{$_} && $prev->{$_} 474 $stats->{$_} && $prev->{$_}
469 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 475 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
470 } sort { $a <=> $b } keys %{$self->{skill_info}} 476 } sort { $a <=> $b } keys %{$self->{skill_info}}
471 ) 477 )
472 ) { 478 ) {
473 my $msg = join " ", @diffs; 479 my $msg = join " ", @diffs;
547 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 553 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
548 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); 554 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP});
549 555
550 $self->update_weight; 556 $self->update_weight;
551 557
552 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 558 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
553 for keys %RES_TBL; 559 for keys %RES_TBL;
554 560
555 my $sktbl = $::STATWIDS->{skill_tbl}; 561 my $sktbl = $::STATWIDS->{skill_tbl};
556 my @skills = keys %{ $self->{skill_info} }; 562 my @skills = keys %{ $self->{skill_info} };
557 563
678} 684}
679 685
680sub feed_map1a { 686sub feed_map1a {
681 my ($self, $data) = @_; 687 my ($self, $data) = @_;
682 688
683 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 689 my $missing = $self->{map}->map1a_update ($data);
684 my $delay; 690 my $delay;
685 691
686 for my $tile (@$missing) { 692 for my $tile (@$missing) {
687 next if $self->{delay}{$tile}; 693 next if $self->{delay}{$tile};
688 694
1051 my ($self, $flags, $prompt) = @_; 1057 my ($self, $flags, $prompt) = @_;
1052 1058
1053 $prompt = $LAST_QUERY unless length $prompt; 1059 $prompt = $LAST_QUERY unless length $prompt;
1054 $LAST_QUERY = $prompt; 1060 $LAST_QUERY = $prompt;
1055 1061
1056 $self->{query}-> ($self, $flags, $prompt); 1062 $self->{query}->($self, $flags, $prompt);
1057} 1063}
1058 1064
1059sub sanitise_xml($) { 1065sub sanitise_xml($) {
1060 local $_ = shift; 1066 local $_ = shift;
1061 1067
1093 tan => 12, 1099 tan => 12,
1094); 1100);
1095 1101
1096our @CF_COLOR = ( 1102our @CF_COLOR = (
1097 [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],
1098 [1.00, 1.00, 1.00], 1104 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1099 [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],
1100 [1.00, 0.00, 0.00], 1106 [1.00, 0.00, 0.00],
1101 [1.00, 0.54, 0.00], 1107 [1.00, 0.54, 0.00],
1102 [0.11, 0.56, 1.00], 1108 [0.11, 0.56, 1.00],
1103 [0.93, 0.46, 0.00], 1109 [0.93, 0.46, 0.00],
1104 [0.18, 0.54, 0.34], 1110 [0.18, 0.54, 0.34],
1123 $self->logprint ("msg: ", $text); 1129 $self->logprint ("msg: ", $text);
1124 return if $color < 0; # negative color == ignore if not understood 1130 return if $color < 0; # negative color == ignore if not understood
1125 1131
1126 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1132 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1127 1133
1128 ## try to create single paragraphs of multiple lines sent by the server
1129 # no longer neecssary with TRT servers
1130 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1131
1132 ::message ({ 1134 ::message ({
1133 fg => $fg, 1135 fg => $fg,
1134 markup => $text, 1136 markup => $text,
1135 type => $type, 1137 type => $type,
1136 extra => [@extra], 1138 extra => [@extra],
1159 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 1161 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
1160 $spell->{message} =~ s/\n+$//; 1162 $spell->{message} =~ s/\n+$//;
1161 $spell->{message} ||= "Server did not provide a description for this spell."; 1163 $spell->{message} ||= "Server did not provide a description for this spell.";
1162 1164
1163 $::SPELL_LIST->add_spell ($spell); 1165 $::SPELL_LIST->add_spell ($spell);
1164 1166 delete $::COMPLETER->{command_list}{spells};
1165 $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message});
1166 $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message});
1167} 1167}
1168 1168
1169sub spell_delete { 1169sub spell_delete {
1170 my ($self, $spell) = @_; 1170 my ($self, $spell) = @_;
1171 1171
1172 $::SPELL_LIST->remove_spell ($spell); 1172 $::SPELL_LIST->remove_spell ($spell);
1173 delete $::COMPLETER->{command_list}{spells};
1173} 1174}
1174 1175
1175sub setup { 1176sub setup {
1176 my ($self, $setup) = @_; 1177 my ($self, $setup) = @_;
1177 1178
1200} 1201}
1201 1202
1202sub eof { 1203sub eof {
1203 my ($self) = @_; 1204 my ($self) = @_;
1204 1205
1205 $self->{map_widget}->clr_commands; 1206 $::COMPLETER->reset;
1206 1207
1207 ::stop_game (); 1208 ::stop_game ();
1208} 1209}
1209 1210
1210sub update_floorbox { 1211sub update_floorbox {
1356sub update_server_info { 1357sub update_server_info {
1357 my ($self) = @_; 1358 my ($self) = @_;
1358 1359
1359 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>");
1360 1361
1362 my $version = JSON::XS->new->encode ($self->{s_version});
1363
1361 $::SERVER_INFO->set_markup ( 1364 $::SERVER_INFO->set_markup (
1362 "server <tt>$self->{host}:$self->{port}</tt>\n" 1365 "server <tt>$self->{host}:$self->{port}</tt>\n"
1363 . "protocol version <tt>$self->{version}</tt>\n" 1366 . "protocol version <tt>$version</tt>\n"
1364 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1365 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1366 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1367 . "editing support $yesno[!!$self->{editor_support}]\n" 1367 . "editing support $yesno[!!$self->{editor_support}]\n"
1368 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1369 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1370 . "client support $yesno[$self->{cfplus_ext} > 0]" 1368 . "client support $yesno[$self->{cfplus_ext} > 0]"
1371 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1369 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1372 . "map size $self->{mapw}×$self->{maph}\n" 1370 . "map size $self->{mapw}×$self->{maph}\n"
1373 ); 1371 );
1374 1372
1397 1395
1398 $self->update_server_info; 1396 $self->update_server_info;
1399 1397
1400 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1398 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1401 $self->send_pickup ($::CFG->{pickup}); 1399 $self->send_pickup ($::CFG->{pickup});
1402
1403 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1404 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1405} 1400}
1406 1401
1407sub lookat { 1402sub lookat {
1408 my ($self, $x, $y) = @_; 1403 my ($self, $x, $y) = @_;
1409 1404
1411 $self->send_ext_req (lookat => $x, $y, sub { 1406 $self->send_ext_req (lookat => $x, $y, sub {
1412 my (%msg) = @_; 1407 my (%msg) = @_;
1413 1408
1414 if (exists $msg{npc_dialog}) { 1409 if (exists $msg{npc_dialog}) {
1415 # start npc chat dialog 1410 # start npc chat dialog
1416 $self->{npc_dialog} = new DC::NPCDialog:: 1411 $self->{w}{npc_dialog} = new DC::NPCDialog::
1417 token => $msg{npc_dialog}, 1412 token => $msg{npc_dialog},
1418 title => "$msg{npc_dialog}[0] (NPC)", 1413 title => "$msg{npc_dialog}[0] (NPC)",
1419 conn => $self, 1414 conn => $self,
1420 ; 1415 ;
1421 } 1416 }
1426} 1421}
1427 1422
1428sub destroy { 1423sub destroy {
1429 my ($self) = @_; 1424 my ($self) = @_;
1430 1425
1431 (delete $self->{npc_dialog})->destroy 1426 $_->destroy
1432 if $self->{npc_dialog}; 1427 for values %{ $self->{w} };
1433 1428
1434 $self->SUPER::destroy; 1429 $self->SUPER::destroy;
1435 1430
1436 %$self = (); 1431 %$self = ();
1437} 1432}
1591 1586
1592 #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
1593 1588
1594 if ($self->{conn}) { 1589 if ($self->{conn}) {
1595 $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};
1596 delete $self->{conn}{npc_dialog}; 1591 delete $self->{conn}{w}{npc_dialog};
1597 $self->{conn}->disconnect_ext ($self->{id}); 1592 $self->{conn}->disconnect_ext ($self->{id});
1598 } 1593 }
1599 1594
1600 $self->SUPER::destroy; 1595 $self->SUPER::destroy;
1601} 1596}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines