… | |
… | |
21 | |
21 | |
22 | my $self = $class->SUPER::new (%arg, |
22 | my $self = $class->SUPER::new (%arg, |
23 | setup_req => { |
23 | setup_req => { |
24 | extmap => 1, |
24 | extmap => 1, |
25 | excmd => 1, |
25 | excmd => 1, |
26 | ywidget => 1,#d# |
26 | xwidget => 1,#d# |
27 | %{$arg{setup_req} || {}}, |
27 | %{$arg{setup_req} || {}}, |
28 | }, |
28 | }, |
29 | ); |
29 | ); |
30 | |
30 | |
31 | $self->{map_widget}->clr_commands; |
31 | $self->{map_widget}->clr_commands; |
… | |
… | |
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) = @_; |
62 | |
60 | |
… | |
… | |
228 | } |
226 | } |
229 | |
227 | |
230 | sub logprint { |
228 | sub logprint { |
231 | my ($self, @a) = @_; |
229 | my ($self, @a) = @_; |
232 | |
230 | |
233 | $self->{log_fh} ||= do { |
231 | CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { }; |
234 | my $path = "$Crossfire::VARDIR/log.$self->{host}"; |
|
|
235 | |
|
|
236 | open my $fh, ">>:utf8", $path |
|
|
237 | or die "Couldn't open logfile $path: $!"; |
|
|
238 | |
|
|
239 | $fh->autoflush (1); |
|
|
240 | |
|
|
241 | $fh; |
|
|
242 | }; |
|
|
243 | |
|
|
244 | my ($sec, $min, $hour, $mday, $mon, $year) = localtime time; |
|
|
245 | |
|
|
246 | my $ts = sprintf "%04d-%02d-%02d %02d:%02d:%02d", |
|
|
247 | $year + 1900, $mon + 1, $mday, $hour, $min, $sec; |
|
|
248 | |
|
|
249 | print {$self->{log_fh}} "$ts ", @a, "\n"; |
|
|
250 | } |
232 | } |
251 | |
233 | |
252 | sub _stat_numdiff { |
234 | sub _stat_numdiff { |
253 | my ($self, $name, $old, $new) = @_; |
235 | my ($self, $name, $old, $new) = @_; |
254 | |
236 | |
… | |
… | |
758 | $self->{music_meta}{$facenum} = $face; |
740 | $self->{music_meta}{$facenum} = $face; |
759 | |
741 | |
760 | ::message ({ markup => "downloaded song #$facenum" }) |
742 | ::message ({ markup => "downloaded song #$facenum" }) |
761 | if $changed; |
743 | if $changed; |
762 | |
744 | |
763 | &::audio_music_set ($self->{songs}); |
745 | &::audio_music_push ($facenum); |
764 | }; |
746 | }; |
765 | } elsif ($face->{type} == 5) { # FT_SOUND |
747 | } elsif ($face->{type} == 5) { # FT_SOUND |
766 | $cb = sub { |
748 | $cb = sub { |
767 | $self->{sound_meta}{$facenum} = $face; |
749 | $self->{sound_meta}{$facenum} = $face; |
768 | |
750 | |
769 | use Data::Dumper; warn Dumper $face;#d# |
|
|
770 | ::message ({ markup => "downloaded sound #$facenum" }) |
751 | ::message ({ markup => "downloaded sound #$facenum" }) |
771 | if $changed; |
752 | if $changed; |
|
|
753 | |
|
|
754 | &::audio_sound_push ($facenum); |
772 | }; |
755 | }; |
773 | } |
756 | } |
774 | |
|
|
775 | |
757 | |
776 | if ($changed) { # new data |
758 | if ($changed) { # new data |
777 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
759 | my ($meta_json, $data) = unpack "(w/a*)*", delete $face->{data}; |
778 | |
760 | |
779 | CFPlus::DB::put res_data => $face->{name} => $data, sub { |
761 | CFPlus::DB::put res_data => $face->{name} => $data, sub { }; |
780 | CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { |
762 | CFPlus::DB::put res_meta => $face->{name} => $meta_json, sub { |
781 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
763 | $face->{meta} = $self->{json_coder}->decode ($meta_json); |
782 | |
764 | ::add_license ($face); |
783 | $cb->(); |
765 | $cb->(); |
784 | }; |
|
|
785 | }; |
766 | }; |
786 | |
767 | |
787 | } else { |
768 | } else { |
788 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
769 | $face->{meta} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
770 | ::add_license ($face); |
789 | $cb->(); |
771 | $cb->(); |
790 | } |
772 | } |
791 | } |
773 | } |
792 | } |
774 | } |
793 | |
775 | |
… | |
… | |
823 | @{$self->{face_cb}{$id}}; |
805 | @{$self->{face_cb}{$id}}; |
824 | } |
806 | } |
825 | } |
807 | } |
826 | |
808 | |
827 | sub sound_play { |
809 | sub sound_play { |
828 | my ($self, $x, $y, $soundnum, $type) = @_; |
810 | my ($self, $type, $face, $dx, $dy, $vol) = @_; |
829 | warn "sound play <@_>\n";#d# |
|
|
830 | |
811 | |
831 | #$self->{sound_play}->($x, $y, $soundnum, $type); |
812 | &::audio_sound_play ($face, $dx, $dy, $vol) |
|
|
813 | unless $type & 1; # odd types are silent for future expansion |
832 | } |
814 | } |
833 | |
815 | |
834 | my $LAST_QUERY; # server is stupid, stupid, stupid |
816 | my $LAST_QUERY; # server is stupid, stupid, stupid |
835 | |
817 | |
836 | sub query { |
818 | sub query { |