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.184 by root, Thu Dec 27 18:35:56 2007 UTC vs.
Revision 1.198 by root, Tue May 20 02:49:56 2008 UTC

27 ); 27 );
28 28
29 $self->{map_widget}->clr_commands; 29 $self->{map_widget}->clr_commands;
30 30
31 my @cmd_help = map { 31 my @cmd_help = map {
32 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 32 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
33 or die "unparseable command help: $_->{kw}[0]"; 33 or die "unparseable command help: $_->[DC::Pod::N_KW][0]";
34 34
35 my $cmd = $1; 35 my $cmd = $1;
36 my @args = split /\|/, $2; 36 my @args = split /\|/, $2;
37 @args = (".*") unless @args; 37 @args = (".*") unless @args;
38 38
43 for @args; 43 for @args;
44 44
45 map ["$cmd$_", $text], 45 map ["$cmd$_", $text],
46 sort { (length $a) <=> (length $b) } 46 sort { (length $a) <=> (length $b) }
47 @args 47 @args
48 } sort { $a->{par} <=> $b->{par} } 48 } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] }
49 DC::Pod::find command => "*"; 49 DC::Pod::find command => "*";
50 50
51 $self->{json_coder} 51 $self->{json_coder}
52 ->convert_blessed 52 ->convert_blessed
53 ->filter_json_single_key_object ("\fw" => sub { 53 ->filter_json_single_key_object ("\fw" => sub {
64 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 64 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
65 for my $ws (values %{delete $self->{widgetset} || {}}) { 65 for my $ws (values %{delete $self->{widgetset} || {}}) {
66 $_->destroy 66 $_->destroy
67 for values %{delete $ws->{w} || {}}; 67 for values %{delete $ws->{w} || {}};
68 } 68 }
69
70 delete $self->{items};
71 $::INV->clear;
72 $::INVR_HB->clear;
73 $::FLOORBOX->clear;
69 }); 74 });
70 75
71 $self->{map_widget}->add_command (@$_) 76 $self->{map_widget}->add_command (@$_)
72 for @cmd_help; 77 for @cmd_help;
73 78
194 ); 199 );
195} 200}
196 201
197# widgetset create template 202# widgetset create template
198sub ext_ws_ct { 203sub ext_ws_ct {
199 my ($self, $ws, $template, $cfg) = @_; 204 my ($self, $ws, $type, $template, $done_cb, $cfg) = @_;
200 205
201 $template = eval <<EOF; 206 $done_cb ||= sub { };
202[
203 Toplevel => {
204 s_id => "toplevel",
205 title => "Character Creation",
206 x => "center",
207 y => "center",
208 z => 5,
209 s_cl => [VBox => {s_cl => [
210 Label => {
211 text => "Character Creation",
212 fontsize => 1,
213 align => 0,
214 },
215 Label => {
216 markup => "View or Edit your character attributes below, then press <b>Finish</b> to create your character",
217 fontsize => 0.8,
218 align => 0,
219 },
220 Notebook => {
221 s_cl => [
222 Label => {
223 text => "hulla-hoop"
224 },
225 Entry => {
226 s_id => "entry",
227 },
228 ],
229 },
230 Button => {
231 s_id => "finish",
232 title => "Finish",
233 },
234 ]}],
235 },
236]
237EOF
238 die if $@;
239 207
240 my $parse_list; $parse_list = sub { 208 my $parse_list; $parse_list = sub {
241 my ($list) = @_; 209 my ($list) = @_;
242 my @w; 210 my @w;
243 211
260 } 228 }
261 229
262 @w 230 @w
263 }; 231 };
264 232
233 # either array reference, or face #
234 if ($type eq "inline") {
235 $done_cb->();
265 $parse_list->($template); 236 $parse_list->($template);
237 } elsif ($type eq "face") {
238 my $handler; $handler = $self->register_face_handler ($template, sub {
239 my ($face) = @_;
266 240
241 undef $handler;
242 $done_cb->();
243 $parse_list->($self->{json_coder}->decode ($face->{data}));
244 });
245 } else {
246 $done_cb->(0);
247 }
267} 248}
268 249
269# widgetset associate 250# widgetset associate
270sub ext_ws_a { 251sub ext_ws_a {
271 my ($self, %ass) = @_; 252 my ($self, %ass) = @_;
299 spell_list => $::SPELL_LIST, 280 spell_list => $::SPELL_LIST,
300 281
301 floorbox => $::FLOORBOX, 282 floorbox => $::FLOORBOX,
302 help_window => $::HELP_WINDOW, 283 help_window => $::HELP_WINDOW,
303 message_window => $::MESSAGE_WINDOW, 284 message_window => $::MESSAGE_WINDOW,
285 message_dist => $::MESSAGE_DIST,
304 statusbox => $::SDTATUSBOX, 286 statusbox => $::SDTATUSBOX,
305 287
306 inv => $::INV, 288 inv => $::INV,
307 invr => $::INVR, 289 invr => $::INVR,
308 invr_hb => $::INVR_HB, 290 invr_hb => $::INVR_HB,
357 339
358# message window 340# message window
359sub ext_channel_info { 341sub ext_channel_info {
360 my ($self, $info) = @_; 342 my ($self, $info) = @_;
361 $self->{channels}->{$info->{id}} = $info; 343 $self->{channels}->{$info->{id}} = $info;
362 $::MESSAGE_WINDOW->add_channel ($info); 344 $::MESSAGE_DIST->add_channel ($info);
363} 345}
364 346
365############################################################################# 347#############################################################################
366 348
367sub logprint { 349sub logprint {
549 $sktbl->clear; 531 $sktbl->clear;
550 532
551 my $sw = $self->{skillwid}{""} ||= [ 533 my $sw = $self->{skillwid}{""} ||= [
552 0, 0, (new DC::UI::Label text => "Experience", align => 1), 534 0, 0, (new DC::UI::Label text => "Experience", align => 1),
553 1, 0, (new DC::UI::Label text => "Lvl.", align => 1), 535 1, 0, (new DC::UI::Label text => "Lvl.", align => 1),
554 2, 0, (new DC::UI::Label text => "Progress", align => 0), 536 2, 0, (new DC::UI::Label text => "Progress"),
555 3, 0, (new DC::UI::Label text => "Skill", expand => 1), 537 3, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
556 4, 0, (new DC::UI::Label text => "Experience", align => 1), 538 4, 0, (new DC::UI::Label text => "Experience", align => 1),
557 5, 0, (new DC::UI::Label text => "Lvl.", align => 1), 539 5, 0, (new DC::UI::Label text => "Lvl.", align => 1),
558 6, 0, (new DC::UI::Label text => "Progress", align => 0), 540 6, 0, (new DC::UI::Label text => "Progress"),
559 7, 0, (new DC::UI::Label text => "Skill", expand => 1), 541 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
560 ]; 542 ];
561 543
562 my @add = @$sw; 544 my @add = @$sw;
563 545
564 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 546 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>";
603 585
604 # progress 586 # progress
605 (new DC::UI::ExperienceProgress), 587 (new DC::UI::ExperienceProgress),
606 588
607 # label 589 # label
608 (new DC::UI::Label text => $name, on_button_down => $spell_cb, 590 (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0,
609 can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), 591 can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL),
610 ]; 592 ];
611 593
612 push @add, 594 push @add,
613 $x * 4 + 0, $y, $sw->[0], 595 $x * 4 + 0, $y, $sw->[0],
702} 684}
703 685
704sub flush_map { 686sub flush_map {
705 my ($self) = @_; 687 my ($self) = @_;
706 688
707 my $map_info = delete $self->{map_info} 689 return unless $self->{map_info};
708 or return;
709 690
691 for my $map_info (values %{ $self->{map_cache} || {} }) {
710 my ($hash, $x, $y, $w, $h) = @$map_info; 692 my ($hash, $rdata, $x, $y, $w, $h) = @$map_info;
711 693
712 my $data = Compress::LZF::compress $self->{map}->get_rect ($x, $y, $w, $h); 694 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
713 $self->{map_cache_new}{$hash} = \$data; 695
696 if ($data ne $$rdata) {
697 $map_info->[1] = \$data;
698 my $cdata = Compress::LZF::compress $data;
714 DC::DB::put $self->{mapcache} => $hash => $data, sub { }; 699 DC::DB::put $self->{mapcache} => $hash => $cdata, sub { };
700 }
701 }
715} 702}
716 703
717sub map_clear { 704sub map_clear {
718 my ($self) = @_; 705 my ($self) = @_;
719 706
720 $self->flush_map; 707 $self->flush_map;
708 delete $self->{map_info};
721 delete $self->{neigh_map}; 709 delete $self->{neigh_map};
722 710
723 $self->{map}->clear; 711 $self->{map}->clear;
724 delete $self->{map_widget}{magicmap}; 712 delete $self->{map_widget}{magicmap};
725} 713}
746 734
747 $self->bg_fetch; 735 $self->bg_fetch;
748 }; 736 };
749} 737}
750 738
751sub load_map($$$) { 739sub load_map($$$$$$) {
752 my ($self, $hash, $x, $y) = @_; 740 my ($self, $hash, $x, $y, $w, $h) = @_;
753 741
754 my $gen = $self->{map_change_gen}; 742 my $map_info = $self->{map_cache}{$hash} = [$hash, \"", $x, $y, $w, $h];
755 743
756 my $cb = sub { 744 my $cb = sub {
757 return unless $gen == $self->{map_change_gen}; 745 $map_info->[1] = \$_[0];
758 746
759 my ($data) = @_;
760
761 if (defined $data) {
762 $self->{map_cache_new}{$hash} = \$data;
763
764 my $data = Compress::LZF::decompress $data;
765
766 my $inprogress = @{ $self->{bg_fetch} || [] }; 747 my $inprogress = @{ $self->{bg_fetch} || [] };
767 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); 748 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $_[0]);
768 $self->bg_fetch unless $inprogress; 749 $self->bg_fetch unless $inprogress;
769 }
770 }; 750 };
771 751
772 if (my $rdata = $self->{map_cache_old}{$hash}) { 752 if (my $map_info = $self->{map_cache_old}{$hash}) {
773 $cb->($$rdata); 753 $cb->(${ $map_info->[1] });
774 } else { 754 } else {
755 my $gen = $self->{map_change_gen};
756
775 DC::DB::get $self->{mapcache} => $hash, $cb; 757 DC::DB::get $self->{mapcache} => $hash, sub {
758 return unless $gen == $self->{map_change_gen};
759 return unless defined $_[0];
760 $cb->(Compress::LZF::decompress $_[0]);
761 };
776 } 762 }
777} 763}
778 764
779# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 765# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
780# (server resource,s latency, bandwidth), so this hack is warranted. 766# (server resources, latency, bandwidth), so this hack is warranted.
781# the right fix is to make real tiled maps with an overview file 767# the right fix is to make real tiled maps with an overview file
782sub send_mapinfo { 768sub send_mapinfo {
783 my ($self, $data, $cb) = @_; 769 my ($self, $data, $cb) = @_;
784 770
785 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { 771 if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) {
810} 796}
811 797
812# this method does a "flood fill" into every tile direction 798# this method does a "flood fill" into every tile direction
813# it assumes that tiles are arranged in a rectangular grid, 799# it assumes that tiles are arranged in a rectangular grid,
814# i.e. a map is the same as the left of the right map etc. 800# i.e. a map is the same as the left of the right map etc.
815# failure to comply are harmless and result in display errors 801# failure to comply is harmless and results in display errors
816# at worst. 802# at worst.
817sub flood_fill { 803sub flood_fill {
818 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; 804 my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_;
819 805
820 # the server does not allow map paths > 6 806 # the server does not allow map paths > 6
856 return if $mode ne "spatial"; 842 return if $mode ne "spatial";
857 843
858 $x += $self->{map}->ox; 844 $x += $self->{map}->ox;
859 $y += $self->{map}->oy; 845 $y += $self->{map}->oy;
860 846
861 $self->load_map ($hash, $x, $y) 847 $self->load_map ($hash, $x, $y, $w, $h)
862 unless $self->{neigh_map}{$hash}[5]++;#d# 848 unless $self->{neigh_map}{$hash}[5]++;#d#
863 849
864 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; 850 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
865 851
866 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 852 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
874 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 860 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
875 861
876 $self->flush_map; 862 $self->flush_map;
877 863
878 ++$self->{map_change_gen}; 864 ++$self->{map_change_gen};
879 $self->{map_cache_old} = delete $self->{map_cache_new}; 865 $self->{map_cache_old} = delete $self->{map_cache};
880 866
881 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 867 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
882 868
883 my $mapmapw = $self->{mapmap}->{w}; 869 my $mapmapw = $self->{mapmap}->{w};
884 my $mapmaph = $self->{mapmap}->{h}; 870 my $mapmaph = $self->{mapmap}->{h};
896 $self->{map_info} = [$hash, $x, $y, $w, $h]; 882 $self->{map_info} = [$hash, $x, $y, $w, $h];
897 883
898 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; 884 (my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/;
899 $::STATWIDS->{map}->set_text ("Map: " . $map); 885 $::STATWIDS->{map}->set_text ("Map: " . $map);
900 886
901 $self->load_map ($hash, $x, $y); 887 $self->load_map ($hash, $x, $y, $w, $h);
902 $self->flood_fill (0, 0, 0, "", $hash, $flags); 888 $self->flood_fill (0, 0, 0, "", $hash, $flags);
903} 889}
904 890
905sub face_find { 891sub face_find {
906 my ($self, $facenum, $face, $cb) = @_; 892 my ($self, $facenum, $face, $cb) = @_;
1048 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g; 1034 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
1049 1035
1050 # handle some elements 1036 # handle some elements
1051 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; 1037 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
1052 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; 1038 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
1039
1040 s/\s+$//;
1053 1041
1054 $_ 1042 $_
1055} 1043}
1056 1044
1057our %NAME_TO_COLOR = ( 1045our %NAME_TO_COLOR = (
1163 1151
1164 my %skill_help; 1152 my %skill_help;
1165 1153
1166 for my $node (DC::Pod::find skill_description => "*") { 1154 for my $node (DC::Pod::find skill_description => "*") {
1167 my (undef, @par) = DC::Pod::section_of $node; 1155 my (undef, @par) = DC::Pod::section_of $node;
1168 $skill_help{$node->{kw}[0]} = DC::Pod::as_label @par; 1156 $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par;
1169 }; 1157 };
1170 1158
1171 for my $skill (values %{$self->{skill_info}}) { 1159 for my $skill (values %{$self->{skill_info}}) {
1172 $self->{map_widget}->add_command ("ready_skill $skill", 1160 $self->{map_widget}->add_command ("ready_skill $skill",
1173 (DC::asxml "Ready the skill '$skill'\n\n") 1161 (DC::asxml "Ready the skill '$skill'\n\n")
1193 $::FLOORBOX->clear; 1181 $::FLOORBOX->clear;
1194 1182
1195 my @add; 1183 my @add;
1196 1184
1197 my $row; 1185 my $row;
1198 for (sort { $a->{count} <=> $b->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) { 1186 for (sort { $b->{count} <=> $a->{count} } values %{ $::CONN->{container}{$::CONN->{open_container} || 0} }) {
1187 next if $_->{tag} & 0x80000000;
1199 if ($row < 6) { 1188 if ($row < 6) {
1200 local $_->{face_widget}; # hack to force recreation of widget 1189 local $_->{face_widget}; # hack to force recreation of widget
1201 local $_->{desc_widget}; # hack to force recreation of widget 1190 local $_->{desc_widget}; # hack to force recreation of widget
1202 DC::Item::update_widgets $_; 1191 DC::Item::update_widgets $_;
1203 1192
1230sub set_opencont { 1219sub set_opencont {
1231 my ($conn, $tag, $name) = @_; 1220 my ($conn, $tag, $name) = @_;
1232 $conn->{open_container} = $tag; 1221 $conn->{open_container} = $tag;
1233 update_floorbox; 1222 update_floorbox;
1234 1223
1235 $::INVR_HB->clear (); 1224 $::INVR_HB->clear;
1236 $::INVR_HB->add (new DC::UI::Label align => 0, expand => 1, text => $name); 1225 $::INVR_HB->add (new DC::UI::Label expand => 1, text => $name);
1237 1226
1238 if ($tag != 0) { # Floor isn't closable, is it? 1227 if ($tag != 0) { # Floor isn't closable, is it?
1239 $::INVR_HB->add (new DC::UI::Button 1228 $::INVR_HB->add (new DC::UI::Button
1240 text => "Close container", 1229 text => "Close container",
1241 tooltip => "Close the currently open container (if one is open)", 1230 tooltip => "Close the currently open container (if one is open)",
1296} 1285}
1297 1286
1298sub item_update { 1287sub item_update {
1299 my ($self, $item) = @_; 1288 my ($self, $item) = @_;
1300 1289
1301 #d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; 1290 #print "item_update: $item->{tag} in $item->{container} pt($self->{player}{tag}) oc($::CONN->{open_container}) f($item->{flags})\n";
1302 1291
1303 DC::Item::update_widgets $item; 1292 DC::Item::update_widgets $item;
1304 1293
1305 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { 1294 if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) {
1306 set_opencont ($::CONN, 0, "Floor"); 1295 set_opencont ($::CONN, 0, "Floor");
1307 1296
1308 } elsif ($item->{flags} & F_OPEN) { 1297 } elsif ($item->{flags} & F_OPEN) {
1309 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item); 1298 set_opencont ($::CONN, $item->{tag}, DC::Item::desc_string $item);
1325 1314
1326 my $weight = .001 * $self->{player}{weight}; 1315 my $weight = .001 * $self->{player}{weight};
1327 my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM}; 1316 my $limit = .001 * $self->{stat}{+CS_STAT_WEIGHT_LIM};
1328 1317
1329 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight); 1318 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $weight);
1330 $::STATWIDS->{m_weight}->set_text (sprintf "%.1fkg", $limit); 1319 $::STATWIDS->{m_weight}->set_text (sprintf "Max Weight: %.1fkg", $limit);
1331 $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit); 1320 $::STATWIDS->{i_weight}->set_text (sprintf "%.1f/%.1fkg", $weight, $limit);
1332} 1321}
1333 1322
1334sub update_server_info { 1323sub update_server_info {
1335 my ($self) = @_; 1324 my ($self) = @_;
1343 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 1332 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1344 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" 1333 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1345 . "editing support $yesno[!!$self->{editor_support}]\n" 1334 . "editing support $yesno[!!$self->{editor_support}]\n"
1346 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 1335 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1347 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" 1336 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1348 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 1337 . "client support $yesno[$self->{cfplus_ext} > 0]"
1349 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1338 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1350 . "map size $self->{mapw}×$self->{maph}\n" 1339 . "map size $self->{mapw}×$self->{maph}\n"
1351 ); 1340 );
1352 1341
1353} 1342}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines