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.214 by root, Tue Dec 22 00:35:44 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, wrap => 1; 22 "noface.png", minify => 1, mipmap => 1, wrap => 1;
24 23
25sub MIN_TEXTURE_UNUSED() { 1 }#d# 24sub MIN_TEXTURE_UNUSED() { 1 }#d#
28 my ($class, %arg) = @_; 27 my ($class, %arg) = @_;
29 28
30 my $self = $class->SUPER::new (%arg, 29 my $self = $class->SUPER::new (%arg,
31 setup_req => { 30 setup_req => {
32 extmap => 1, 31 extmap => 1,
33 excmd => 1,
34 widget => 2, 32 widget => 2,
35 %{$arg{setup_req} || {}}, 33 %{$arg{setup_req} || {}},
36 }, 34 },
37 ); 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 });
38 71
39 $self->{map_widget}->clr_commands; 72 $self->{map_widget}->clr_commands;
40 73
41 my @cmd_help = map { 74 my @cmd_help = map {
42 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 75 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
96 $self->{noface} = my $tex = $TEX_NOFACE; 129 $self->{noface} = my $tex = $TEX_NOFACE;
97 $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}});
98 } 131 }
99 132
100# $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
101# $self->{expire_w} = EV::timer 1, 1, sub { 134# $self->{expire_w} = AE::timer 1, 1, sub {
102# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; 135# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
103# 136#
104# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { 137# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
105# warn DC::SvREFCNT $self->{texture}[$_]; 138# warn DC::SvREFCNT $self->{texture}[$_];
106# $self->{texture}[$_]->unload; 139# $self->{texture}[$_]->unload;
130 }); 163 });
131} 164}
132 165
133sub ext_capabilities { 166sub ext_capabilities {
134 my ($self, %cap) = @_; 167 my ($self, %cap) = @_;
135
136 $self->update_fx_want;
137
138 $self->send_exti_req (resource => "exp_table", sub {
139 my ($exp_table) = @_;
140
141 $self->register_face_handler ($exp_table, sub {
142 my ($face) = @_;
143
144 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
145 $_->() for values %{ $self->{on_exp_update} || {} };
146 });
147
148 ()
149 });
150 168
151 if (my $ts = $cap{tileset}) { 169 if (my $ts = $cap{tileset}) {
152 if (my ($default) = grep $_->[2] & 1, @$ts) { 170 if (my ($default) = grep $_->[2] & 1, @$ts) {
153 $self->{tileset} = $default; 171 $self->{tileset} = $default;
154 $self->{tilesize} = $default->[3]; 172 $self->{tilesize} = $default->[3];
455 473
456 if (my @diffs = 474 if (my @diffs =
457 ( 475 (
458 ($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" : ()),
459 map { 477 map {
460 $stats->{$_} && $prev->{$_} 478 $stats->{$_} && $prev->{$_}
461 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 479 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
462 } sort { $a <=> $b } keys %{$self->{skill_info}} 480 } sort { $a <=> $b } keys %{$self->{skill_info}}
463 ) 481 )
464 ) { 482 ) {
465 my $msg = join " ", @diffs; 483 my $msg = join " ", @diffs;
539 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 557 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
540 $::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});
541 559
542 $self->update_weight; 560 $self->update_weight;
543 561
544 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 562 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
545 for keys %RES_TBL; 563 for keys %RES_TBL;
546 564
547 my $sktbl = $::STATWIDS->{skill_tbl}; 565 my $sktbl = $::STATWIDS->{skill_tbl};
548 my @skills = keys %{ $self->{skill_info} }; 566 my @skills = keys %{ $self->{skill_info} };
549 567
670} 688}
671 689
672sub feed_map1a { 690sub feed_map1a {
673 my ($self, $data) = @_; 691 my ($self, $data) = @_;
674 692
675 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 693 my $missing = $self->{map}->map1a_update ($data);
676 my $delay; 694 my $delay;
677 695
678 for my $tile (@$missing) { 696 for my $tile (@$missing) {
679 next if $self->{delay}{$tile}; 697 next if $self->{delay}{$tile};
680 698
1043 my ($self, $flags, $prompt) = @_; 1061 my ($self, $flags, $prompt) = @_;
1044 1062
1045 $prompt = $LAST_QUERY unless length $prompt; 1063 $prompt = $LAST_QUERY unless length $prompt;
1046 $LAST_QUERY = $prompt; 1064 $LAST_QUERY = $prompt;
1047 1065
1048 $self->{query}-> ($self, $flags, $prompt); 1066 $self->{query}->($self, $flags, $prompt);
1049} 1067}
1050 1068
1051sub sanitise_xml($) { 1069sub sanitise_xml($) {
1052 local $_ = shift; 1070 local $_ = shift;
1053 1071
1085 tan => 12, 1103 tan => 12,
1086); 1104);
1087 1105
1088our @CF_COLOR = ( 1106our @CF_COLOR = (
1089 [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],
1090 [1.00, 1.00, 1.00], 1108 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1091 [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],
1092 [1.00, 0.00, 0.00], 1110 [1.00, 0.00, 0.00],
1093 [1.00, 0.54, 0.00], 1111 [1.00, 0.54, 0.00],
1094 [0.11, 0.56, 1.00], 1112 [0.11, 0.56, 1.00],
1095 [0.93, 0.46, 0.00], 1113 [0.93, 0.46, 0.00],
1096 [0.18, 0.54, 0.34], 1114 [0.18, 0.54, 0.34],
1114 } else { 1132 } else {
1115 $self->logprint ("msg: ", $text); 1133 $self->logprint ("msg: ", $text);
1116 return if $color < 0; # negative color == ignore if not understood 1134 return if $color < 0; # negative color == ignore if not understood
1117 1135
1118 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1136 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1119
1120 ## try to create single paragraphs of multiple lines sent by the server
1121 # no longer neecssary with TRT servers
1122 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1123 1137
1124 ::message ({ 1138 ::message ({
1125 fg => $fg, 1139 fg => $fg,
1126 markup => $text, 1140 markup => $text,
1127 type => $type, 1141 type => $type,
1348sub update_server_info { 1362sub update_server_info {
1349 my ($self) = @_; 1363 my ($self) = @_;
1350 1364
1351 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>");
1352 1366
1367 my $version = JSON::XS->new->encode ($self->{s_version});
1368
1353 $::SERVER_INFO->set_markup ( 1369 $::SERVER_INFO->set_markup (
1354 "server <tt>$self->{host}:$self->{port}</tt>\n" 1370 "server <tt>$self->{host}:$self->{port}</tt>\n"
1355 . "protocol version <tt>$self->{version}</tt>\n" 1371 . "protocol version <tt>$version</tt>\n"
1356 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1357 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1358 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1359 . "editing support $yesno[!!$self->{editor_support}]\n" 1372 . "editing support $yesno[!!$self->{editor_support}]\n"
1360 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1361 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1362 . "client support $yesno[$self->{cfplus_ext} > 0]" 1373 . "client support $yesno[$self->{cfplus_ext} > 0]"
1363 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1374 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1364 . "map size $self->{mapw}×$self->{maph}\n" 1375 . "map size $self->{mapw}×$self->{maph}\n"
1365 ); 1376 );
1366 1377
1389 1400
1390 $self->update_server_info; 1401 $self->update_server_info;
1391 1402
1392 $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;
1393 $self->send_pickup ($::CFG->{pickup}); 1404 $self->send_pickup ($::CFG->{pickup});
1394
1395 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1396 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1397} 1405}
1398 1406
1399sub lookat { 1407sub lookat {
1400 my ($self, $x, $y) = @_; 1408 my ($self, $x, $y) = @_;
1401 1409
1403 $self->send_ext_req (lookat => $x, $y, sub { 1411 $self->send_ext_req (lookat => $x, $y, sub {
1404 my (%msg) = @_; 1412 my (%msg) = @_;
1405 1413
1406 if (exists $msg{npc_dialog}) { 1414 if (exists $msg{npc_dialog}) {
1407 # start npc chat dialog 1415 # start npc chat dialog
1408 $self->{npc_dialog} = new DC::NPCDialog:: 1416 $self->{w}{npc_dialog} = new DC::NPCDialog::
1409 token => $msg{npc_dialog}, 1417 token => $msg{npc_dialog},
1410 title => "$msg{npc_dialog}[0] (NPC)", 1418 title => "$msg{npc_dialog}[0] (NPC)",
1411 conn => $self, 1419 conn => $self,
1412 ; 1420 ;
1413 } 1421 }
1418} 1426}
1419 1427
1420sub destroy { 1428sub destroy {
1421 my ($self) = @_; 1429 my ($self) = @_;
1422 1430
1423 (delete $self->{npc_dialog})->destroy 1431 $_->destroy
1424 if $self->{npc_dialog}; 1432 for values %{ $self->{w} };
1425 1433
1426 $self->SUPER::destroy; 1434 $self->SUPER::destroy;
1427 1435
1428 %$self = (); 1436 %$self = ();
1429} 1437}
1583 1591
1584 #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
1585 1593
1586 if ($self->{conn}) { 1594 if ($self->{conn}) {
1587 $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};
1588 delete $self->{conn}{npc_dialog}; 1596 delete $self->{conn}{w}{npc_dialog};
1589 $self->{conn}->disconnect_ext ($self->{id}); 1597 $self->{conn}->disconnect_ext ($self->{id});
1590 } 1598 }
1591 1599
1592 $self->SUPER::destroy; 1600 $self->SUPER::destroy;
1593} 1601}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines