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.213 by root, Mon Dec 21 23:52:34 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, wrap => 1; 22 "noface.png", minify => 1, mipmap => 1, wrap => 1;
24
25our $TEX_HIDDEN = new_from_resource DC::Texture # MUST be POT
26 "hidden-0.png", minify => 1, mipmap => 1, wrap => 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 $self->{map_widget}{hidden_tex} = $tex;#d#
107 }
108
109# $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
110# $self->{expire_w} = EV::timer 1, 1, sub { 111# $self->{expire_w} = AE::timer 1, 1, sub {
111# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; 112# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
112# 113#
113# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { 114# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
114# warn DC::SvREFCNT $self->{texture}[$_]; 115# warn DC::SvREFCNT $self->{texture}[$_];
115# $self->{texture}[$_]->unload; 116# $self->{texture}[$_]->unload;
127 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 128 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
128 129
129 $self 130 $self
130} 131}
131 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
132sub update_fx_want { 136sub update_fx_want {
133 my ($self) = @_; 137 my ($self) = @_;
134 138
135 $self->send_exti_msg (fx_want => { 139 $self->send_exti_msg (fx_want => {
136 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC 140 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
140} 144}
141 145
142sub ext_capabilities { 146sub ext_capabilities {
143 my ($self, %cap) = @_; 147 my ($self, %cap) = @_;
144 148
145 $self->update_fx_want;
146
147 $self->send_exti_req (resource => "exp_table", sub {
148 my ($exp_table) = @_;
149
150 $self->register_face_handler ($exp_table, sub {
151 my ($face) = @_;
152
153 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
154 $_->() for values %{ $self->{on_exp_update} || {} };
155 });
156
157 ()
158 });
159
160 if (my $ts = $cap{tileset}) { 149 if (my $ts = $cap{tileset}) {
161 if (my ($default) = grep $_->[2] & 1, @$ts) { 150 if (my ($default) = grep $_->[2] & 1, @$ts) {
162 $self->{tileset} = $default; 151 $self->{tileset} = $default;
163 $self->{tilesize} = $default->[3]; 152 $self->{tilesize} = $default->[3];
164 $self->setup_req (tileset => $default->[0]); 153 $self->setup_req (tileset => $default->[0]);
172} 161}
173 162
174sub ext_ambient_music { 163sub ext_ambient_music {
175 my ($self, $songs) = @_; 164 my ($self, $songs) = @_;
176 &::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 }
177} 182}
178 183
179############################################################################# 184#############################################################################
180 185
181sub widget_associate { 186sub widget_associate {
464 469
465 if (my @diffs = 470 if (my @diffs =
466 ( 471 (
467 ($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" : ()),
468 map { 473 map {
469 $stats->{$_} && $prev->{$_} 474 $stats->{$_} && $prev->{$_}
470 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 475 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
471 } sort { $a <=> $b } keys %{$self->{skill_info}} 476 } sort { $a <=> $b } keys %{$self->{skill_info}}
472 ) 477 )
473 ) { 478 ) {
474 my $msg = join " ", @diffs; 479 my $msg = join " ", @diffs;
548 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 553 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
549 $::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});
550 555
551 $self->update_weight; 556 $self->update_weight;
552 557
553 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 558 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
554 for keys %RES_TBL; 559 for keys %RES_TBL;
555 560
556 my $sktbl = $::STATWIDS->{skill_tbl}; 561 my $sktbl = $::STATWIDS->{skill_tbl};
557 my @skills = keys %{ $self->{skill_info} }; 562 my @skills = keys %{ $self->{skill_info} };
558 563
679} 684}
680 685
681sub feed_map1a { 686sub feed_map1a {
682 my ($self, $data) = @_; 687 my ($self, $data) = @_;
683 688
684 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 689 my $missing = $self->{map}->map1a_update ($data);
685 my $delay; 690 my $delay;
686 691
687 for my $tile (@$missing) { 692 for my $tile (@$missing) {
688 next if $self->{delay}{$tile}; 693 next if $self->{delay}{$tile};
689 694
1052 my ($self, $flags, $prompt) = @_; 1057 my ($self, $flags, $prompt) = @_;
1053 1058
1054 $prompt = $LAST_QUERY unless length $prompt; 1059 $prompt = $LAST_QUERY unless length $prompt;
1055 $LAST_QUERY = $prompt; 1060 $LAST_QUERY = $prompt;
1056 1061
1057 $self->{query}-> ($self, $flags, $prompt); 1062 $self->{query}->($self, $flags, $prompt);
1058} 1063}
1059 1064
1060sub sanitise_xml($) { 1065sub sanitise_xml($) {
1061 local $_ = shift; 1066 local $_ = shift;
1062 1067
1094 tan => 12, 1099 tan => 12,
1095); 1100);
1096 1101
1097our @CF_COLOR = ( 1102our @CF_COLOR = (
1098 [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],
1099 [1.00, 1.00, 1.00], 1104 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1100 [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],
1101 [1.00, 0.00, 0.00], 1106 [1.00, 0.00, 0.00],
1102 [1.00, 0.54, 0.00], 1107 [1.00, 0.54, 0.00],
1103 [0.11, 0.56, 1.00], 1108 [0.11, 0.56, 1.00],
1104 [0.93, 0.46, 0.00], 1109 [0.93, 0.46, 0.00],
1105 [0.18, 0.54, 0.34], 1110 [0.18, 0.54, 0.34],
1124 $self->logprint ("msg: ", $text); 1129 $self->logprint ("msg: ", $text);
1125 return if $color < 0; # negative color == ignore if not understood 1130 return if $color < 0; # negative color == ignore if not understood
1126 1131
1127 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1132 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1128 1133
1129 ## try to create single paragraphs of multiple lines sent by the server
1130 # no longer neecssary with TRT servers
1131 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1132
1133 ::message ({ 1134 ::message ({
1134 fg => $fg, 1135 fg => $fg,
1135 markup => $text, 1136 markup => $text,
1136 type => $type, 1137 type => $type,
1137 extra => [@extra], 1138 extra => [@extra],
1160 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 1161 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
1161 $spell->{message} =~ s/\n+$//; 1162 $spell->{message} =~ s/\n+$//;
1162 $spell->{message} ||= "Server did not provide a description for this spell."; 1163 $spell->{message} ||= "Server did not provide a description for this spell.";
1163 1164
1164 $::SPELL_LIST->add_spell ($spell); 1165 $::SPELL_LIST->add_spell ($spell);
1165 1166 delete $::COMPLETER->{command_list}{spells};
1166 $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message});
1167 $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message});
1168} 1167}
1169 1168
1170sub spell_delete { 1169sub spell_delete {
1171 my ($self, $spell) = @_; 1170 my ($self, $spell) = @_;
1172 1171
1173 $::SPELL_LIST->remove_spell ($spell); 1172 $::SPELL_LIST->remove_spell ($spell);
1173 delete $::COMPLETER->{command_list}{spells};
1174} 1174}
1175 1175
1176sub setup { 1176sub setup {
1177 my ($self, $setup) = @_; 1177 my ($self, $setup) = @_;
1178 1178
1201} 1201}
1202 1202
1203sub eof { 1203sub eof {
1204 my ($self) = @_; 1204 my ($self) = @_;
1205 1205
1206 $self->{map_widget}->clr_commands; 1206 $::COMPLETER->reset;
1207 1207
1208 ::stop_game (); 1208 ::stop_game ();
1209} 1209}
1210 1210
1211sub update_floorbox { 1211sub update_floorbox {
1357sub update_server_info { 1357sub update_server_info {
1358 my ($self) = @_; 1358 my ($self) = @_;
1359 1359
1360 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>");
1361 1361
1362 my $version = JSON::XS->new->encode ($self->{s_version});
1363
1362 $::SERVER_INFO->set_markup ( 1364 $::SERVER_INFO->set_markup (
1363 "server <tt>$self->{host}:$self->{port}</tt>\n" 1365 "server <tt>$self->{host}:$self->{port}</tt>\n"
1364 . "protocol version <tt>$self->{version}</tt>\n" 1366 . "protocol version <tt>$version</tt>\n"
1365 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1366 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1367 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1368 . "editing support $yesno[!!$self->{editor_support}]\n" 1367 . "editing support $yesno[!!$self->{editor_support}]\n"
1369 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1370 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1371 . "client support $yesno[$self->{cfplus_ext} > 0]" 1368 . "client support $yesno[$self->{cfplus_ext} > 0]"
1372 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1369 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1373 . "map size $self->{mapw}×$self->{maph}\n" 1370 . "map size $self->{mapw}×$self->{maph}\n"
1374 ); 1371 );
1375 1372
1398 1395
1399 $self->update_server_info; 1396 $self->update_server_info;
1400 1397
1401 $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;
1402 $self->send_pickup ($::CFG->{pickup}); 1399 $self->send_pickup ($::CFG->{pickup});
1403
1404 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1405 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1406} 1400}
1407 1401
1408sub lookat { 1402sub lookat {
1409 my ($self, $x, $y) = @_; 1403 my ($self, $x, $y) = @_;
1410 1404
1412 $self->send_ext_req (lookat => $x, $y, sub { 1406 $self->send_ext_req (lookat => $x, $y, sub {
1413 my (%msg) = @_; 1407 my (%msg) = @_;
1414 1408
1415 if (exists $msg{npc_dialog}) { 1409 if (exists $msg{npc_dialog}) {
1416 # start npc chat dialog 1410 # start npc chat dialog
1417 $self->{npc_dialog} = new DC::NPCDialog:: 1411 $self->{w}{npc_dialog} = new DC::NPCDialog::
1418 token => $msg{npc_dialog}, 1412 token => $msg{npc_dialog},
1419 title => "$msg{npc_dialog}[0] (NPC)", 1413 title => "$msg{npc_dialog}[0] (NPC)",
1420 conn => $self, 1414 conn => $self,
1421 ; 1415 ;
1422 } 1416 }
1427} 1421}
1428 1422
1429sub destroy { 1423sub destroy {
1430 my ($self) = @_; 1424 my ($self) = @_;
1431 1425
1432 (delete $self->{npc_dialog})->destroy 1426 $_->destroy
1433 if $self->{npc_dialog}; 1427 for values %{ $self->{w} };
1434 1428
1435 $self->SUPER::destroy; 1429 $self->SUPER::destroy;
1436 1430
1437 %$self = (); 1431 %$self = ();
1438} 1432}
1592 1586
1593 #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
1594 1588
1595 if ($self->{conn}) { 1589 if ($self->{conn}) {
1596 $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};
1597 delete $self->{conn}{npc_dialog}; 1591 delete $self->{conn}{w}{npc_dialog};
1598 $self->{conn}->disconnect_ext ($self->{id}); 1592 $self->{conn}->disconnect_ext ($self->{id});
1599 } 1593 }
1600 1594
1601 $self->SUPER::destroy; 1595 $self->SUPER::destroy;
1602} 1596}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines