… | |
… | |
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 | }); |
… | |
… | |
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 | }); |
188 | }); |
189 | |
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); |
|
|
195 | }); |
|
|
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} || {}}) { |
193 | $_->destroy |
200 | $_->destroy |
194 | for values %{delete $ws->{w} || {}}; |
201 | for values %{delete $ws->{w} || {}}; |
… | |
… | |
219 | } |
226 | } |
220 | |
227 | |
221 | sub logprint { |
228 | sub logprint { |
222 | my ($self, @a) = @_; |
229 | my ($self, @a) = @_; |
223 | |
230 | |
224 | $self->{log_fh} ||= do { |
231 | CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { }; |
225 | my $path = "$Crossfire::VARDIR/log.$self->{host}"; |
|
|
226 | |
|
|
227 | open my $fh, ">>:utf8", $path |
|
|
228 | or die "Couldn't open logfile $path: $!"; |
|
|
229 | |
|
|
230 | $fh->autoflush (1); |
|
|
231 | |
|
|
232 | $fh; |
|
|
233 | }; |
|
|
234 | |
|
|
235 | my ($sec, $min, $hour, $mday, $mon, $year) = localtime time; |
|
|
236 | |
|
|
237 | my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d", |
|
|
238 | $year + 1900, $mon + 1, $mday, $hour, $min, $sec; |
|
|
239 | |
|
|
240 | print {$self->{log_fh}} "$ts ", @a, "\n"; |
|
|
241 | } |
232 | } |
242 | |
233 | |
243 | sub _stat_numdiff { |
234 | sub _stat_numdiff { |
244 | my ($self, $name, $old, $new) = @_; |
235 | my ($self, $name, $old, $new) = @_; |
245 | |
236 | |
… | |
… | |
553 | do { |
544 | do { |
554 | $id = pop @{$self->{bg_fetch}} |
545 | $id = pop @{$self->{bg_fetch}} |
555 | or return; |
546 | or return; |
556 | } while $self->{texture}[$id]; |
547 | } while $self->{texture}[$id]; |
557 | |
548 | |
558 | CFPlus::DB::get tilecache => $id, sub { |
549 | CFPlus::DB::exists tilecache => $id, sub { |
559 | my ($data) = @_; |
550 | my ($exists) = @_; |
560 | |
551 | |
561 | return unless $self->{map}; # stop when destroyed |
552 | return unless $self->{map}; # stop when destroyed |
562 | |
553 | |
563 | $self->set_texture ($id => $data) |
554 | $self->have_tile ($id) |
564 | if defined $data; |
555 | if $exists; |
565 | |
556 | |
566 | $self->bg_fetch; |
557 | $self->bg_fetch; |
567 | }; |
558 | }; |
568 | } |
559 | } |
569 | |
560 | |
… | |
… | |
726 | |
717 | |
727 | CFPlus::DB::get tilecache => $id, $cb; |
718 | CFPlus::DB::get tilecache => $id, $cb; |
728 | |
719 | |
729 | } elsif ($face->{type} & 1) { # with metadata |
720 | } 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." }); |
721 | #::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; |
722 | CFPlus::DB::get res_meta => $face->{name}, $cb; |
732 | } |
723 | } |
733 | } |
724 | } |
734 | |
725 | |
735 | sub face_update { |
726 | sub face_update { |
736 | my ($self, $facenum, $face, $changed) = @_; |
727 | my ($self, $facenum, $face, $changed) = @_; |
737 | |
728 | |
738 | if ($face->{type} == 0) { # FT_FACE |
729 | if ($face->{type} == 0) { # FT_FACE |
739 | CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } |
730 | CFPlus::DB::put tilecache => $face->{id} => $face->{data}, sub { } |
740 | if $changed; |
731 | if $changed; |
741 | |
732 | |
742 | $self->set_texture ($face->{id} => delete $face->{data}); |
733 | $self->have_tile ($face->{id}); |
743 | |
734 | |
744 | } elsif ($face->{type} & 1) { # split metadata |
735 | } elsif ($face->{type} & 1) { # split metadata |
745 | my $cb = sub { }; |
736 | my $cb = sub { }; |
746 | |
737 | |
747 | if ($face->{type} == 3) { # FT_MUSIC |
738 | if ($face->{type} == 3) { # FT_MUSIC |
… | |
… | |
749 | $self->{music_meta}{$facenum} = $face; |
740 | $self->{music_meta}{$facenum} = $face; |
750 | |
741 | |
751 | ::message ({ markup => "downloaded song #$facenum" }) |
742 | ::message ({ markup => "downloaded song #$facenum" }) |
752 | if $changed; |
743 | if $changed; |
753 | |
744 | |
754 | &::audio_music_set ($self->{songs}); |
745 | &::audio_music_push ($facenum); |
|
|
746 | }; |
|
|
747 | } elsif ($face->{type} == 5) { # FT_SOUND |
|
|
748 | $cb = sub { |
|
|
749 | $self->{sound_meta}{$facenum} = $face; |
|
|
750 | |
|
|
751 | ::message ({ markup => "downloaded sound #$facenum" }) |
|
|
752 | if $changed; |
|
|
753 | |
|
|
754 | &::audio_sound_push ($facenum); |
755 | }; |
755 | }; |
756 | } |
756 | } |
757 | |
757 | |
758 | if ($changed) { # new data |
758 | if ($changed) { # new data |
759 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
759 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
760 | my $path = CFPlus::DB::path_of_res $face->{name}; |
|
|
761 | |
760 | |
762 | CFPlus::DB::write_file $path, $data, sub { |
761 | CFPlus::DB::put res_data => $face->{name} => $data, sub { }; |
763 | CFPlus::DB::put "res-metadata" => $face->{name} => $meta_json, sub { |
762 | CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { |
764 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
763 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
765 | $face->{path} = $path; |
764 | ::add_license ($face); |
766 | |
|
|
767 | $cb->(); |
765 | $cb->(); |
768 | }; |
|
|
769 | }; |
766 | }; |
|
|
767 | |
770 | } else { |
768 | } else { |
771 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
769 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
770 | ::add_license ($face); |
772 | $cb->(); |
771 | $cb->(); |
773 | } |
772 | } |
774 | } |
773 | } |
775 | } |
774 | } |
776 | |
775 | |
… | |
… | |
778 | my ($self, $facenum, $face) = @_; |
777 | my ($self, $facenum, $face) = @_; |
779 | |
778 | |
780 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
779 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
781 | } |
780 | } |
782 | |
781 | |
783 | sub set_texture { |
782 | sub have_tile { |
784 | my ($self, $id, $data) = @_; |
783 | my ($self, $tile) = @_; |
785 | |
784 | |
786 | return unless $self->{map}; |
785 | return unless $self->{map}; |
787 | |
786 | |
788 | $self->{texture}[$id] = my $tex = |
787 | $self->{texture}[$tile] ||= my $tex = |
789 | new_from_image CFPlus::Texture |
788 | new CFPlus::Texture |
790 | $data, minify => 1, mipmap => 1; |
789 | tile => $tile, minify => 1, mipmap => 1, delay => 1; |
791 | |
790 | |
792 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
793 | $self->{map_widget}->update; |
|
|
794 | |
|
|
795 | $_->() for @{(delete $self->{face_cb}{$id}) || []}; |
791 | $_->() for @{(delete $self->{face_cb}{$tile}) || []}; |
796 | } |
792 | } |
797 | |
793 | |
798 | sub connect_face_update { |
794 | sub connect_face_update { |
799 | my ($self, $id, $cb) = @_; |
795 | my ($self, $id, $cb) = @_; |
800 | |
796 | |
… | |
… | |
806 | @{$self->{face_cb}{$id}}; |
802 | @{$self->{face_cb}{$id}}; |
807 | } |
803 | } |
808 | } |
804 | } |
809 | |
805 | |
810 | sub sound_play { |
806 | sub sound_play { |
811 | my ($self, $x, $y, $soundnum, $type) = @_; |
807 | my ($self, $type, $face, $dx, $dy, $vol) = @_; |
812 | |
808 | |
813 | $self->{sound_play}->($x, $y, $soundnum, $type); |
809 | &::audio_sound_play ($face, $dx, $dy, $vol) |
|
|
810 | unless $type & 1; # odd types are silent for future expansion |
814 | } |
811 | } |
815 | |
812 | |
816 | my $LAST_QUERY; # server is stupid, stupid, stupid |
813 | my $LAST_QUERY; # server is stupid, stupid, stupid |
817 | |
814 | |
818 | sub query { |
815 | sub query { |
… | |
… | |
883 | $self->{$type} = $text; |
880 | $self->{$type} = $text; |
884 | } else { |
881 | } else { |
885 | $self->logprint ("msg: ", $text); |
882 | $self->logprint ("msg: ", $text); |
886 | return if $color < 0; # negative color == ignore if not understood |
883 | return if $color < 0; # negative color == ignore if not understood |
887 | |
884 | |
888 | my $fg = $CF_COLOR[$color % @CF_COLOR]; |
885 | my $fg = $CF_COLOR[$color & 0x1f] || [1, 0, 0]; |
889 | |
886 | |
890 | ## try to create single paragraphs of multiple lines sent by the server |
887 | ## try to create single paragraphs of multiple lines sent by the server |
891 | # no longer neecssary with TRT servers |
888 | # no longer neecssary with TRT servers |
892 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
889 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
893 | |
890 | |
894 | ::message ({ fg => $fg, markup => $_ }) |
891 | ::message ({ fg => $fg, markup => $_, type => $type, extra => [@extra] }) |
895 | for split /\n/, $text; |
892 | for split /\n/, $text; |
896 | |
893 | |
897 | $self->{statusbox}->add ($text, |
894 | $self->{statusbox}->add ($text, |
898 | group => $text, |
895 | group => $text, |
899 | fg => $fg, |
896 | fg => $fg, |
… | |
… | |
954 | my ($self) = @_; |
951 | my ($self) = @_; |
955 | |
952 | |
956 | $self->{map_widget}->clr_commands; |
953 | $self->{map_widget}->clr_commands; |
957 | |
954 | |
958 | ::stop_game (); |
955 | ::stop_game (); |
959 | } |
|
|
960 | |
|
|
961 | sub image_info { |
|
|
962 | my ($self, $numfaces) = @_; |
|
|
963 | |
|
|
964 | $self->{num_faces} = $numfaces; |
|
|
965 | $self->{face_prefetch} = [1 .. $numfaces]; |
|
|
966 | $self->face_prefetch; |
|
|
967 | } |
|
|
968 | |
|
|
969 | sub 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 | } |
956 | } |
994 | |
957 | |
995 | sub update_floorbox { |
958 | sub update_floorbox { |
996 | $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
959 | $CFPlus::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
997 | return unless $::CONN; |
960 | return unless $::CONN; |
… | |
… | |
1155 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
1118 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
1156 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1119 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1157 | . "map size $self->{mapw}×$self->{maph}\n" |
1120 | . "map size $self->{mapw}×$self->{maph}\n" |
1158 | ); |
1121 | ); |
1159 | |
1122 | |
1160 | ::setup_build_button ($self->{editor_support}->{builder_ui}); |
|
|
1161 | } |
1123 | } |
1162 | |
1124 | |
1163 | sub logged_in { |
1125 | sub logged_in { |
1164 | my ($self) = @_; |
1126 | my ($self) = @_; |
1165 | |
1127 | |
… | |
… | |
1185 | |
1147 | |
1186 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
1148 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
1187 | $self->send_command ("output-count $::CFG->{output_count}"); |
1149 | $self->send_command ("output-count $::CFG->{output_count}"); |
1188 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1150 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1189 | $self->send_command ("pickup $::CFG->{pickup}"); |
1151 | $self->send_command ("pickup $::CFG->{pickup}"); |
1190 | } |
|
|
1191 | |
|
|
1192 | sub 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 | } |
1152 | } |
1199 | |
1153 | |
1200 | sub lookat { |
1154 | sub lookat { |
1201 | my ($self, $x, $y) = @_; |
1155 | my ($self, $x, $y) = @_; |
1202 | |
1156 | |