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.218 by root, Thu Apr 8 19:11:21 2010 UTC vs.
Revision 1.225 by root, Sat Nov 10 18:29:32 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 );
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 $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub {
43 my ($exp, $skl, $spl) = @_;
44
45 $self->register_face_handler ($exp, sub {
46 my ($face) = @_;
47
48 undef $exp_guard;
49 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
50 $_->() for values %{ $self->{on_exp_update} };
51 });
52
53 $self->register_face_handler ($skl, sub {
54 my ($face) = @_;
55
56 undef $skl_guard;
57 my $info = $self->{json_coder}->decode (delete $face->{data});
58 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
59 });
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 });
37 71
38 $self->{map_widget}->clr_commands; 72 $self->{map_widget}->clr_commands;
39 73
40 my @cmd_help = map { 74 my @cmd_help = map {
41 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 75 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
95 $self->{noface} = my $tex = $TEX_NOFACE; 129 $self->{noface} = my $tex = $TEX_NOFACE;
96 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 130 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
97 } 131 }
98 132
99# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id 133# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
100# $self->{expire_w} = EV::timer 1, 1, sub { 134# $self->{expire_w} = AE::timer 1, 1, sub {
101# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; 135# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
102# 136#
103# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { 137# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
104# warn DC::SvREFCNT $self->{texture}[$_]; 138# warn DC::SvREFCNT $self->{texture}[$_];
105# $self->{texture}[$_]->unload; 139# $self->{texture}[$_]->unload;
117 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 151 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
118 152
119 $self 153 $self
120} 154}
121 155
156 #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d#
157#sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d#
158
122sub update_fx_want { 159sub update_fx_want {
123 my ($self) = @_; 160 my ($self) = @_;
124 161
125 $self->send_exti_msg (fx_want => { 162 $self->send_exti_msg (fx_want => {
126 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC 163 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
129 }); 166 });
130} 167}
131 168
132sub ext_capabilities { 169sub ext_capabilities {
133 my ($self, %cap) = @_; 170 my ($self, %cap) = @_;
134
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 171
150 if (my $ts = $cap{tileset}) { 172 if (my $ts = $cap{tileset}) {
151 if (my ($default) = grep $_->[2] & 1, @$ts) { 173 if (my ($default) = grep $_->[2] & 1, @$ts) {
152 $self->{tileset} = $default; 174 $self->{tileset} = $default;
153 $self->{tilesize} = $default->[3]; 175 $self->{tilesize} = $default->[3];
454 476
455 if (my @diffs = 477 if (my @diffs =
456 ( 478 (
457 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), 479 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()),
458 map { 480 map {
459 $stats->{$_} && $prev->{$_} 481 $stats->{$_} && $prev->{$_}
460 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 482 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
461 } sort { $a <=> $b } keys %{$self->{skill_info}} 483 } sort { $a <=> $b } keys %{$self->{skill_info}}
462 ) 484 )
463 ) { 485 ) {
464 my $msg = join " ", @diffs; 486 my $msg = join " ", @diffs;
669} 691}
670 692
671sub feed_map1a { 693sub feed_map1a {
672 my ($self, $data) = @_; 694 my ($self, $data) = @_;
673 695
674 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 696 my $missing = $self->{map}->map1a_update ($data);
675 my $delay; 697 my $delay;
676 698
677 for my $tile (@$missing) { 699 for my $tile (@$missing) {
678 next if $self->{delay}{$tile}; 700 next if $self->{delay}{$tile};
679 701
1042 my ($self, $flags, $prompt) = @_; 1064 my ($self, $flags, $prompt) = @_;
1043 1065
1044 $prompt = $LAST_QUERY unless length $prompt; 1066 $prompt = $LAST_QUERY unless length $prompt;
1045 $LAST_QUERY = $prompt; 1067 $LAST_QUERY = $prompt;
1046 1068
1047 $self->{query}-> ($self, $flags, $prompt); 1069 $self->{query}->($self, $flags, $prompt);
1048} 1070}
1049 1071
1050sub sanitise_xml($) { 1072sub sanitise_xml($) {
1051 local $_ = shift; 1073 local $_ = shift;
1052 1074
1084 tan => 12, 1106 tan => 12,
1085); 1107);
1086 1108
1087our @CF_COLOR = ( 1109our @CF_COLOR = (
1088 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 1110 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1089 [1.00, 1.00, 1.00], 1111 [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] 1112 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55],
1091 [1.00, 0.00, 0.00], 1113 [1.00, 0.00, 0.00],
1092 [1.00, 0.54, 0.00], 1114 [1.00, 0.54, 0.00],
1093 [0.11, 0.56, 1.00], 1115 [0.11, 0.56, 1.00],
1094 [0.93, 0.46, 0.00], 1116 [0.93, 0.46, 0.00],
1095 [0.18, 0.54, 0.34], 1117 [0.18, 0.54, 0.34],
1113 } else { 1135 } else {
1114 $self->logprint ("msg: ", $text); 1136 $self->logprint ("msg: ", $text);
1115 return if $color < 0; # negative color == ignore if not understood 1137 return if $color < 0; # negative color == ignore if not understood
1116 1138
1117 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1139 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1118
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 1140
1123 ::message ({ 1141 ::message ({
1124 fg => $fg, 1142 fg => $fg,
1125 markup => $text, 1143 markup => $text,
1126 type => $type, 1144 type => $type,
1352 my $version = JSON::XS->new->encode ($self->{s_version}); 1370 my $version = JSON::XS->new->encode ($self->{s_version});
1353 1371
1354 $::SERVER_INFO->set_markup ( 1372 $::SERVER_INFO->set_markup (
1355 "server <tt>$self->{host}:$self->{port}</tt>\n" 1373 "server <tt>$self->{host}:$self->{port}</tt>\n"
1356 . "protocol version <tt>$version</tt>\n" 1374 . "protocol version <tt>$version</tt>\n"
1357 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1358 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1359 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1360 . "editing support $yesno[!!$self->{editor_support}]\n" 1375 . "editing support $yesno[!!$self->{editor_support}]\n"
1361 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1362 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1363 . "client support $yesno[$self->{cfplus_ext} > 0]" 1376 . "client support $yesno[$self->{cfplus_ext} > 0]"
1364 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1377 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1365 . "map size $self->{mapw}×$self->{maph}\n" 1378 . "map size $self->{mapw}×$self->{maph}\n"
1366 ); 1379 );
1367 1380
1401 $self->send_ext_req (lookat => $x, $y, sub { 1414 $self->send_ext_req (lookat => $x, $y, sub {
1402 my (%msg) = @_; 1415 my (%msg) = @_;
1403 1416
1404 if (exists $msg{npc_dialog}) { 1417 if (exists $msg{npc_dialog}) {
1405 # start npc chat dialog 1418 # start npc chat dialog
1406 $self->{npc_dialog} = new DC::NPCDialog:: 1419 $self->{w}{npc_dialog} = new DC::NPCDialog::
1407 token => $msg{npc_dialog}, 1420 token => $msg{npc_dialog},
1408 title => "$msg{npc_dialog}[0] (NPC)", 1421 title => "$msg{npc_dialog}[0] (NPC)",
1409 conn => $self, 1422 conn => $self,
1410 ; 1423 ;
1411 } 1424 }
1416} 1429}
1417 1430
1418sub destroy { 1431sub destroy {
1419 my ($self) = @_; 1432 my ($self) = @_;
1420 1433
1421 (delete $self->{npc_dialog})->destroy 1434 $_->destroy
1422 if $self->{npc_dialog}; 1435 for values %{ $self->{w} };
1423 1436
1424 $self->SUPER::destroy; 1437 $self->SUPER::destroy;
1425 1438
1426 %$self = (); 1439 %$self = ();
1427} 1440}
1581 1594
1582 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 1595 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
1583 1596
1584 if ($self->{conn}) { 1597 if ($self->{conn}) {
1585 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; 1598 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id};
1586 delete $self->{conn}{npc_dialog}; 1599 delete $self->{conn}{w}{npc_dialog};
1587 $self->{conn}->disconnect_ext ($self->{id}); 1600 $self->{conn}->disconnect_ext ($self->{id});
1588 } 1601 }
1589 1602
1590 $self->SUPER::destroy; 1603 $self->SUPER::destroy;
1591} 1604}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines