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.131 by root, Tue Jul 24 04:54:48 2007 UTC vs.
Revision 1.144 by root, Fri Aug 3 02:20:32 2007 UTC

48 sort { (length $a) <=> (length $b) } 48 sort { (length $a) <=> (length $b) }
49 @args 49 @args
50 } sort { $a->{par} <=> $b->{par} } 50 } sort { $a->{par} <=> $b->{par} }
51 CFPlus::Pod::find command => "*"; 51 CFPlus::Pod::find command => "*";
52 52
53 $self->connect_ext (music => sub { 53 $self->connect_ext (ambient_music => sub {
54 my ($ev) = @_; 54 my ($songs) = @_;
55 55 &::audio_music_set_ambient ($songs);
56 &::audio_music_set ($self->{songs} = $ev->{play})
57 if $ev->{play};
58 }); 56 });
59 57
60 $self->connect_ext (capabilities => sub { 58 $self->connect_ext (capabilities => sub {
61 my (%cap) = @_; 59 my (%cap) = @_;
60
61 #$self->send ("setup sound 0"); # we use a different protocol
62 62
63 $self->send_exti_msg (fx_want => { 63 $self->send_exti_msg (fx_want => {
64 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC 64 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
65 5 => !!$::CFG->{audio_enable}, # FT_SOUND 65 5 => !!$::CFG->{audio_enable}, # FT_SOUND
66 }); 66 });
183 183
184 my $w = $self->{widget}{$id} 184 my $w = $self->{widget}{$id}
185 or return; 185 or return;
186 186
187 $self->send_exti_msg (w_r => $rid, [map $w->{$_}, @$attr]); 187 $self->send_exti_msg (w_r => $rid, [map $w->{$_}, @$attr]);
188 });
189
190 # message window
191 $self->connect_ext (channel_info => sub {
192 my ($info) = @_;
193 $self->{channels}->{$info->{id}} = $info;
194 $::MESSAGE_WINDOW->add_channel ($info);
188 }); 195 });
189 196
190 # destroy widgets on logout 197 # destroy widgets on logout
191 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 198 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
192 for my $ws (values %{delete $self->{widgetset} || {}}) { 199 for my $ws (values %{delete $self->{widgetset} || {}}) {
726 733
727 CFPlus::DB::get tilecache => $id, $cb; 734 CFPlus::DB::get tilecache => $id, $cb;
728 735
729 } elsif ($face->{type} & 1) { # with metadata 736 } elsif ($face->{type} & 1) { # with metadata
730 #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." }); 737 #::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." });
731 CFPlus::DB::get "res-metadata" => $face->{name}, $cb; 738 CFPlus::DB::get res_meta => $face->{name}, $cb;
732 } 739 }
733} 740}
734 741
735sub face_update { 742sub face_update {
736 my ($self, $facenum, $face, $changed) = @_; 743 my ($self, $facenum, $face, $changed) = @_;
737 744
738 if ($face->{type} == 0) { # FT_FACE 745 if ($face->{type} == 0) { # FT_FACE
739 CFPlus::DB::put tilecache => $face->{id} => $face->{image}, sub { } 746 CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { }
740 if $changed; 747 if $changed;
741 748
742 $self->set_texture ($face->{id} => delete $face->{data}); 749 $self->set_texture ($face->{id} => delete $face->{data});
743 750
744 } elsif ($face->{type} & 1) { # split metadata 751 } elsif ($face->{type} & 1) { # split metadata
749 $self->{music_meta}{$facenum} = $face; 756 $self->{music_meta}{$facenum} = $face;
750 757
751 ::message ({ markup => "downloaded song #$facenum" }) 758 ::message ({ markup => "downloaded song #$facenum" })
752 if $changed; 759 if $changed;
753 760
754 &::audio_music_set ($self->{songs}); 761 &::audio_music_push ($facenum);
762 };
763 } elsif ($face->{type} == 5) { # FT_SOUND
764 $cb = sub {
765 $self->{sound_meta}{$facenum} = $face;
766
767 ::message ({ markup => "downloaded sound #$facenum" })
768 if $changed;
769
770 &::audio_sound_push ($facenum);
755 }; 771 };
756 } 772 }
757 773
758 if ($changed) { # new data 774 if ($changed) { # new data
759 my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; 775 my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data};
760 my $path = CFPlus::DB::path_of_res $face->{name};
761 776
762 CFPlus::DB::write_file $path, $data, sub { 777 CFPlus::DB::put res_data => $face->{name} => $data, sub { };
763 CFPlus::DB::put "res-metadata" => $face->{name} => $meta_json, sub { 778 CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub {
764 $face->{meta} = $self->{json_coder}->decode ($meta_json); 779 $face->{meta} = $self->{json_coder}->decode ($meta_json);
765 $face->{path} = $path; 780 ::add_license ($face);
766
767 $cb->(); 781 $cb->();
768 };
769 }; 782 };
783
770 } else { 784 } else {
771 $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); 785 $face->{meta} = $self->{json_coder}->decode (delete $face->{data});
786 ::add_license ($face);
772 $cb->(); 787 $cb->();
773 } 788 }
774 } 789 }
775} 790}
776 791
806 @{$self->{face_cb}{$id}}; 821 @{$self->{face_cb}{$id}};
807 } 822 }
808} 823}
809 824
810sub sound_play { 825sub sound_play {
811 my ($self, $x, $y, $soundnum, $type) = @_; 826 my ($self, $type, $face, $dx, $dy, $vol) = @_;
812 827
813 $self->{sound_play}->($x, $y, $soundnum, $type); 828 &::audio_sound_play ($face, $dx, $dy, $vol)
829 unless $type & 1; # odd types are silent for future expansion
814} 830}
815 831
816my $LAST_QUERY; # server is stupid, stupid, stupid 832my $LAST_QUERY; # server is stupid, stupid, stupid
817 833
818sub query { 834sub query {
883 $self->{$type} = $text; 899 $self->{$type} = $text;
884 } else { 900 } else {
885 $self->logprint ("msg: ", $text); 901 $self->logprint ("msg: ", $text);
886 return if $color < 0; # negative color == ignore if not understood 902 return if $color < 0; # negative color == ignore if not understood
887 903
888 my $fg = $CF_COLOR[$color % @CF_COLOR]; 904 my $fg = $CF_COLOR[$color & 0x1f] || [1, 0, 0];
889 905
890 ## try to create single paragraphs of multiple lines sent by the server 906 ## try to create single paragraphs of multiple lines sent by the server
891 # no longer neecssary with TRT servers 907 # no longer neecssary with TRT servers
892 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 908 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
893 909
894 ::message ({ fg => $fg, markup => $_ }) 910 ::message ({ fg => $fg, markup => $_, type => $type, extra => [@extra] })
895 for split /\n/, $text; 911 for split /\n/, $text;
896 912
897 $self->{statusbox}->add ($text, 913 $self->{statusbox}->add ($text,
898 group => $text, 914 group => $text,
899 fg => $fg, 915 fg => $fg,
954 my ($self) = @_; 970 my ($self) = @_;
955 971
956 $self->{map_widget}->clr_commands; 972 $self->{map_widget}->clr_commands;
957 973
958 ::stop_game (); 974 ::stop_game ();
959}
960
961sub image_info {
962 my ($self, $numfaces) = @_;
963
964 $self->{num_faces} = $numfaces;
965 $self->{face_prefetch} = [1 .. $numfaces];
966 $self->face_prefetch;
967}
968
969sub face_prefetch {
970 my ($self) = @_;
971
972 return unless $::CFG->{face_prefetch};
973
974 if ($self->{num_faces}) {
975 return if @{ $self->{send_queue} || [] };
976 my $todo = @{ $self->{face_prefetch} }
977 or return;
978
979 my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, ();
980
981 $self->send ("requestinfo image_sums $face $face");
982
983 $self->{statusbox}->add (CFPlus::asxml "prefetching $todo",
984 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
985 } elsif (!exists $self->{num_faces}) {
986 $self->send ("requestinfo image_info");
987
988 $self->{num_faces} = 0;
989
990 $self->{statusbox}->add (CFPlus::asxml "starting to prefetch",
991 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
992 }
993} 975}
994 976
995sub update_floorbox { 977sub update_floorbox {
996 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { 978 $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub {
997 return unless $::CONN; 979 return unless $::CONN;
1155 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 1137 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
1156 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1138 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1157 . "map size $self->{mapw}×$self->{maph}\n" 1139 . "map size $self->{mapw}×$self->{maph}\n"
1158 ); 1140 );
1159 1141
1160 ::setup_build_button ($self->{editor_support}->{builder_ui});
1161} 1142}
1162 1143
1163sub logged_in { 1144sub logged_in {
1164 my ($self) = @_; 1145 my ($self) = @_;
1165 1146
1185 1166
1186 $self->send_command ("output-sync $::CFG->{output_sync}"); 1167 $self->send_command ("output-sync $::CFG->{output_sync}");
1187 $self->send_command ("output-count $::CFG->{output_count}"); 1168 $self->send_command ("output-count $::CFG->{output_count}");
1188 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1169 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1189 $self->send_command ("pickup $::CFG->{pickup}"); 1170 $self->send_command ("pickup $::CFG->{pickup}");
1190}
1191
1192sub buildat {
1193 my ($self, $builditem, $x, $y) = @_;
1194
1195 if ($self->{cfplus_ext}) {
1196 $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem));
1197 }
1198} 1171}
1199 1172
1200sub lookat { 1173sub lookat {
1201 my ($self, $x, $y) = @_; 1174 my ($self, $x, $y) = @_;
1202 1175

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines