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.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
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 );
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 $self->{map_widget}{hidden_tex} = $tex;#d#
107 }
108
109# $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
110# $self->{expire_w} = EV::timer 1, 1, sub { 134# $self->{expire_w} = AE::timer 1, 1, sub {
111# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; 135# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
112# 136#
113# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { 137# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
114# warn DC::SvREFCNT $self->{texture}[$_]; 138# warn DC::SvREFCNT $self->{texture}[$_];
115# $self->{texture}[$_]->unload; 139# $self->{texture}[$_]->unload;
139 }); 163 });
140} 164}
141 165
142sub ext_capabilities { 166sub ext_capabilities {
143 my ($self, %cap) = @_; 167 my ($self, %cap) = @_;
144
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 168
160 if (my $ts = $cap{tileset}) { 169 if (my $ts = $cap{tileset}) {
161 if (my ($default) = grep $_->[2] & 1, @$ts) { 170 if (my ($default) = grep $_->[2] & 1, @$ts) {
162 $self->{tileset} = $default; 171 $self->{tileset} = $default;
163 $self->{tilesize} = $default->[3]; 172 $self->{tilesize} = $default->[3];
464 473
465 if (my @diffs = 474 if (my @diffs =
466 ( 475 (
467 ($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" : ()),
468 map { 477 map {
469 $stats->{$_} && $prev->{$_} 478 $stats->{$_} && $prev->{$_}
470 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 479 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
471 } sort { $a <=> $b } keys %{$self->{skill_info}} 480 } sort { $a <=> $b } keys %{$self->{skill_info}}
472 ) 481 )
473 ) { 482 ) {
474 my $msg = join " ", @diffs; 483 my $msg = join " ", @diffs;
548 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 557 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
549 $::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});
550 559
551 $self->update_weight; 560 $self->update_weight;
552 561
553 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 562 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
554 for keys %RES_TBL; 563 for keys %RES_TBL;
555 564
556 my $sktbl = $::STATWIDS->{skill_tbl}; 565 my $sktbl = $::STATWIDS->{skill_tbl};
557 my @skills = keys %{ $self->{skill_info} }; 566 my @skills = keys %{ $self->{skill_info} };
558 567
679} 688}
680 689
681sub feed_map1a { 690sub feed_map1a {
682 my ($self, $data) = @_; 691 my ($self, $data) = @_;
683 692
684 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 693 my $missing = $self->{map}->map1a_update ($data);
685 my $delay; 694 my $delay;
686 695
687 for my $tile (@$missing) { 696 for my $tile (@$missing) {
688 next if $self->{delay}{$tile}; 697 next if $self->{delay}{$tile};
689 698
1052 my ($self, $flags, $prompt) = @_; 1061 my ($self, $flags, $prompt) = @_;
1053 1062
1054 $prompt = $LAST_QUERY unless length $prompt; 1063 $prompt = $LAST_QUERY unless length $prompt;
1055 $LAST_QUERY = $prompt; 1064 $LAST_QUERY = $prompt;
1056 1065
1057 $self->{query}-> ($self, $flags, $prompt); 1066 $self->{query}->($self, $flags, $prompt);
1058} 1067}
1059 1068
1060sub sanitise_xml($) { 1069sub sanitise_xml($) {
1061 local $_ = shift; 1070 local $_ = shift;
1062 1071
1094 tan => 12, 1103 tan => 12,
1095); 1104);
1096 1105
1097our @CF_COLOR = ( 1106our @CF_COLOR = (
1098 [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],
1099 [1.00, 1.00, 1.00], 1108 [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] 1109 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55],
1101 [1.00, 0.00, 0.00], 1110 [1.00, 0.00, 0.00],
1102 [1.00, 0.54, 0.00], 1111 [1.00, 0.54, 0.00],
1103 [0.11, 0.56, 1.00], 1112 [0.11, 0.56, 1.00],
1104 [0.93, 0.46, 0.00], 1113 [0.93, 0.46, 0.00],
1105 [0.18, 0.54, 0.34], 1114 [0.18, 0.54, 0.34],
1123 } else { 1132 } else {
1124 $self->logprint ("msg: ", $text); 1133 $self->logprint ("msg: ", $text);
1125 return if $color < 0; # negative color == ignore if not understood 1134 return if $color < 0; # negative color == ignore if not understood
1126 1135
1127 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1136 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1128
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 1137
1133 ::message ({ 1138 ::message ({
1134 fg => $fg, 1139 fg => $fg,
1135 markup => $text, 1140 markup => $text,
1136 type => $type, 1141 type => $type,
1357sub update_server_info { 1362sub update_server_info {
1358 my ($self) = @_; 1363 my ($self) = @_;
1359 1364
1360 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>");
1361 1366
1367 my $version = JSON::XS->new->encode ($self->{s_version});
1368
1362 $::SERVER_INFO->set_markup ( 1369 $::SERVER_INFO->set_markup (
1363 "server <tt>$self->{host}:$self->{port}</tt>\n" 1370 "server <tt>$self->{host}:$self->{port}</tt>\n"
1364 . "protocol version <tt>$self->{version}</tt>\n" 1371 . "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" 1372 . "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]" 1373 . "client support $yesno[$self->{cfplus_ext} > 0]"
1372 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1374 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1373 . "map size $self->{mapw}×$self->{maph}\n" 1375 . "map size $self->{mapw}×$self->{maph}\n"
1374 ); 1376 );
1375 1377
1398 1400
1399 $self->update_server_info; 1401 $self->update_server_info;
1400 1402
1401 $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;
1402 $self->send_pickup ($::CFG->{pickup}); 1404 $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} 1405}
1407 1406
1408sub lookat { 1407sub lookat {
1409 my ($self, $x, $y) = @_; 1408 my ($self, $x, $y) = @_;
1410 1409
1412 $self->send_ext_req (lookat => $x, $y, sub { 1411 $self->send_ext_req (lookat => $x, $y, sub {
1413 my (%msg) = @_; 1412 my (%msg) = @_;
1414 1413
1415 if (exists $msg{npc_dialog}) { 1414 if (exists $msg{npc_dialog}) {
1416 # start npc chat dialog 1415 # start npc chat dialog
1417 $self->{npc_dialog} = new DC::NPCDialog:: 1416 $self->{w}{npc_dialog} = new DC::NPCDialog::
1418 token => $msg{npc_dialog}, 1417 token => $msg{npc_dialog},
1419 title => "$msg{npc_dialog}[0] (NPC)", 1418 title => "$msg{npc_dialog}[0] (NPC)",
1420 conn => $self, 1419 conn => $self,
1421 ; 1420 ;
1422 } 1421 }
1427} 1426}
1428 1427
1429sub destroy { 1428sub destroy {
1430 my ($self) = @_; 1429 my ($self) = @_;
1431 1430
1432 (delete $self->{npc_dialog})->destroy 1431 $_->destroy
1433 if $self->{npc_dialog}; 1432 for values %{ $self->{w} };
1434 1433
1435 $self->SUPER::destroy; 1434 $self->SUPER::destroy;
1436 1435
1437 %$self = (); 1436 %$self = ();
1438} 1437}
1592 1591
1593 #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
1594 1593
1595 if ($self->{conn}) { 1594 if ($self->{conn}) {
1596 $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};
1597 delete $self->{conn}{npc_dialog}; 1596 delete $self->{conn}{w}{npc_dialog};
1598 $self->{conn}->disconnect_ext ($self->{id}); 1597 $self->{conn}->disconnect_ext ($self->{id});
1599 } 1598 }
1600 1599
1601 $self->SUPER::destroy; 1600 $self->SUPER::destroy;
1602} 1601}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines