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.224 by root, Wed Nov 7 00:25:46 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 );
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 });
41 71
42 $self->{map_widget}->clr_commands; 72 $self->{map_widget}->clr_commands;
43 73
44 my @cmd_help = map { 74 my @cmd_help = map {
45 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 75 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
98 { 128 {
99 $self->{noface} = my $tex = $TEX_NOFACE; 129 $self->{noface} = my $tex = $TEX_NOFACE;
100 $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}});
101 } 131 }
102 132
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 133# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
109# $self->{expire_w} = EV::timer 1, 1, sub { 134# $self->{expire_w} = AE::timer 1, 1, sub {
110# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; 135# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
111# 136#
112# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { 137# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
113# warn DC::SvREFCNT $self->{texture}[$_]; 138# warn DC::SvREFCNT $self->{texture}[$_];
114# $self->{texture}[$_]->unload; 139# $self->{texture}[$_]->unload;
138 }); 163 });
139} 164}
140 165
141sub ext_capabilities { 166sub ext_capabilities {
142 my ($self, %cap) = @_; 167 my ($self, %cap) = @_;
143
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 168
159 if (my $ts = $cap{tileset}) { 169 if (my $ts = $cap{tileset}) {
160 if (my ($default) = grep $_->[2] & 1, @$ts) { 170 if (my ($default) = grep $_->[2] & 1, @$ts) {
161 $self->{tileset} = $default; 171 $self->{tileset} = $default;
162 $self->{tilesize} = $default->[3]; 172 $self->{tilesize} = $default->[3];
463 473
464 if (my @diffs = 474 if (my @diffs =
465 ( 475 (
466 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), 476 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()),
467 map { 477 map {
468 $stats->{$_} && $prev->{$_} 478 $stats->{$_} && $prev->{$_}
469 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 479 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
470 } sort { $a <=> $b } keys %{$self->{skill_info}} 480 } sort { $a <=> $b } keys %{$self->{skill_info}}
471 ) 481 )
472 ) { 482 ) {
473 my $msg = join " ", @diffs; 483 my $msg = join " ", @diffs;
547 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 557 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
548 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); 558 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP});
549 559
550 $self->update_weight; 560 $self->update_weight;
551 561
552 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 562 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
553 for keys %RES_TBL; 563 for keys %RES_TBL;
554 564
555 my $sktbl = $::STATWIDS->{skill_tbl}; 565 my $sktbl = $::STATWIDS->{skill_tbl};
556 my @skills = keys %{ $self->{skill_info} }; 566 my @skills = keys %{ $self->{skill_info} };
557 567
678} 688}
679 689
680sub feed_map1a { 690sub feed_map1a {
681 my ($self, $data) = @_; 691 my ($self, $data) = @_;
682 692
683 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 693 my $missing = $self->{map}->map1a_update ($data);
684 my $delay; 694 my $delay;
685 695
686 for my $tile (@$missing) { 696 for my $tile (@$missing) {
687 next if $self->{delay}{$tile}; 697 next if $self->{delay}{$tile};
688 698
1051 my ($self, $flags, $prompt) = @_; 1061 my ($self, $flags, $prompt) = @_;
1052 1062
1053 $prompt = $LAST_QUERY unless length $prompt; 1063 $prompt = $LAST_QUERY unless length $prompt;
1054 $LAST_QUERY = $prompt; 1064 $LAST_QUERY = $prompt;
1055 1065
1056 $self->{query}-> ($self, $flags, $prompt); 1066 $self->{query}->($self, $flags, $prompt);
1057} 1067}
1058 1068
1059sub sanitise_xml($) { 1069sub sanitise_xml($) {
1060 local $_ = shift; 1070 local $_ = shift;
1061 1071
1093 tan => 12, 1103 tan => 12,
1094); 1104);
1095 1105
1096our @CF_COLOR = ( 1106our @CF_COLOR = (
1097 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 1107 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1098 [1.00, 1.00, 1.00], 1108 [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] 1109 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55],
1100 [1.00, 0.00, 0.00], 1110 [1.00, 0.00, 0.00],
1101 [1.00, 0.54, 0.00], 1111 [1.00, 0.54, 0.00],
1102 [0.11, 0.56, 1.00], 1112 [0.11, 0.56, 1.00],
1103 [0.93, 0.46, 0.00], 1113 [0.93, 0.46, 0.00],
1104 [0.18, 0.54, 0.34], 1114 [0.18, 0.54, 0.34],
1122 } else { 1132 } else {
1123 $self->logprint ("msg: ", $text); 1133 $self->logprint ("msg: ", $text);
1124 return if $color < 0; # negative color == ignore if not understood 1134 return if $color < 0; # negative color == ignore if not understood
1125 1135
1126 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1136 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1127
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 1137
1132 ::message ({ 1138 ::message ({
1133 fg => $fg, 1139 fg => $fg,
1134 markup => $text, 1140 markup => $text,
1135 type => $type, 1141 type => $type,
1356sub update_server_info { 1362sub update_server_info {
1357 my ($self) = @_; 1363 my ($self) = @_;
1358 1364
1359 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); 1365 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>");
1360 1366
1367 my $version = JSON::XS->new->encode ($self->{s_version});
1368
1361 $::SERVER_INFO->set_markup ( 1369 $::SERVER_INFO->set_markup (
1362 "server <tt>$self->{host}:$self->{port}</tt>\n" 1370 "server <tt>$self->{host}:$self->{port}</tt>\n"
1363 . "protocol version <tt>$self->{version}</tt>\n" 1371 . "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" 1372 . "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]" 1373 . "client support $yesno[$self->{cfplus_ext} > 0]"
1371 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1374 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1372 . "map size $self->{mapw}×$self->{maph}\n" 1375 . "map size $self->{mapw}×$self->{maph}\n"
1373 ); 1376 );
1374 1377
1397 1400
1398 $self->update_server_info; 1401 $self->update_server_info;
1399 1402
1400 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1403 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1401 $self->send_pickup ($::CFG->{pickup}); 1404 $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} 1405}
1406 1406
1407sub lookat { 1407sub lookat {
1408 my ($self, $x, $y) = @_; 1408 my ($self, $x, $y) = @_;
1409 1409
1411 $self->send_ext_req (lookat => $x, $y, sub { 1411 $self->send_ext_req (lookat => $x, $y, sub {
1412 my (%msg) = @_; 1412 my (%msg) = @_;
1413 1413
1414 if (exists $msg{npc_dialog}) { 1414 if (exists $msg{npc_dialog}) {
1415 # start npc chat dialog 1415 # start npc chat dialog
1416 $self->{npc_dialog} = new DC::NPCDialog:: 1416 $self->{w}{npc_dialog} = new DC::NPCDialog::
1417 token => $msg{npc_dialog}, 1417 token => $msg{npc_dialog},
1418 title => "$msg{npc_dialog}[0] (NPC)", 1418 title => "$msg{npc_dialog}[0] (NPC)",
1419 conn => $self, 1419 conn => $self,
1420 ; 1420 ;
1421 } 1421 }
1426} 1426}
1427 1427
1428sub destroy { 1428sub destroy {
1429 my ($self) = @_; 1429 my ($self) = @_;
1430 1430
1431 (delete $self->{npc_dialog})->destroy 1431 $_->destroy
1432 if $self->{npc_dialog}; 1432 for values %{ $self->{w} };
1433 1433
1434 $self->SUPER::destroy; 1434 $self->SUPER::destroy;
1435 1435
1436 %$self = (); 1436 %$self = ();
1437} 1437}
1591 1591
1592 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 1592 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
1593 1593
1594 if ($self->{conn}) { 1594 if ($self->{conn}) {
1595 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; 1595 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id};
1596 delete $self->{conn}{npc_dialog}; 1596 delete $self->{conn}{w}{npc_dialog};
1597 $self->{conn}->disconnect_ext ($self->{id}); 1597 $self->{conn}->disconnect_ext ($self->{id});
1598 } 1598 }
1599 1599
1600 $self->SUPER::destroy; 1600 $self->SUPER::destroy;
1601} 1601}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines