#
# The wordgame interface
#
-# Copyright (C) 2016 - 2017, 2023 - 2024 Balthasar Szczepański
+# Copyright (C) 2016, 2017, 2023, 2024 Balthasar Szczepański
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
'merge_settings',
'ong'
);
-use File::Copy;
###PERL_PATH_SEPARATOR: PATH_SEPARATOR = /
$cmd_clear_all = $settings{'password'}.' clearall';
$story_lock=0;
-if (open ($story_file,"+<:encoding(UTF-8)",DATA_STORY_PATH())){
+if (open ($story_file, "+<:encoding(UTF-8)", encode('locale_fs', DATA_STORY_PATH()))){
$story_lock=1;
if (flock($story_file,2)) {
$story_lock=2;
$time, # ONG time; not relevant
0, # timer; not relevant
0, # update; not relevant
+ 0, # print
\%settings, # not relevant
'', # %default; not relevant
'', # %frame_data; not relevant
$time, # ONG time; not relevant
0, # timer; not relevant
0, # update; not relevant
+ 0, # print
\%settings,
'', # %default
'', # %frame_data
$time, # ONG time; might get overwritten later
0, # timer
0, # update
+ 0, # print
\%settings,
'', # %default
'', # %frame_data
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
-#use warnings;
+use utf8;
+# use Encode::Locale ('decode_argv');
+use Encode ('encode', 'decode');
+
###PERL_LIB: use lib /botm/lib/bsta
-use bsta_lib qw(entityencode readdatafile writedatafile urlencode);
-use File::Copy;
+use botm_common (
+ 'read_data_file', 'write_data_file'
+);
+use bsta_lib (
+ 'STATE',
+ 'ong'
+);
-###PERL_DATA_PATH: DATA_PATH = /botm/data/bsta
-###PERL_DATA_DEFAULT_PATH: DATA_DEFAULT_PATH = /botm/data/bsta/default
###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
###PERL_DATA_STATE_PATH: DATA_STATE_PATH = /botm/data/bsta/state
-###PERL_WWW_PATH: WWW_PATH = /botm/www/1190/bsta/
-###PERL_DATA_LIST_PATH: DATA_LIST_PATH = /botm/data/bsta/list
-my %framedata;
-my %nextframedata;
-my %default;
+my $time = time();
+srand ($time-$$);
+
my %settings;
my %state;
-my %gotolist;
+my %goto_list;
-my $statefile;
+my $fh;
my $ongstate;
my $frame;
-my $nextong;
-my $inpath;
-my $outpath;
+my $next_ong;
my $ongtime;
-my $static;
-my $dynamic;
+my $static_timer;
+my $timer;
my $last;
+my $r = 0;
-my $time = time();
-srand ($time-$$);
-$ongtime = int($time / 3600) * 3600;
+$ongtime = int($time / 3600) * 3600; # check time as if it was last full hour!
print $time.' - '.$ongtime."\n";
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
-
-if (open ($statefile,"+<",DATA_STATE_PATH)){
- if (flock($statefile,2)) {
- %state=readdatafile($statefile);
- $ongstate=int($state{'state'});
+unless (open ($fh, "+<:encoding(UTF-8)", encode('locale_fs', DATA_STATE_PATH()))) {
+ print "NO STATEFILE\n";
+}
+else {
+ unless (flock($fh, 2)) {
+ print "NO STATELOCK\n";
+ }
+ else {
+ %state = read_data_file($fh);
+ $ongstate = int($state{'state'});
print 'state: '.$ongstate."\n";
- if($ongstate > 0) {
- $nextong = int($state{'nextong'});
- print 'ongtime: '.$nextong."\n";
+ unless ($ongstate > STATE->{'inactive'}) {
+ print "INACTIVE\n";
+ }
+ else {
+ $next_ong = int($state{'nextong'});
+ print 'ongtime: '.$next_ong."\n";
- if($ongtime >= $nextong) {
- %settings=readdatafile(DATA_SETTINGS_PATH);
- $static=int($settings{'ongtime'});
- $dynamic=int($settings{'dynamicongtime'});
- $last=int($settings{'last'});
- $frame=int($state{'last'})+1;
+ unless ($ongtime >= $next_ong) {
+ print "WAIT\n";
+ }
+ else {
+ %settings = read_data_file(DATA_SETTINGS_PATH());
+ $static_timer = int($settings{'ongtime'});
+ $timer = int($settings{'dynamicongtime'});
+ $last = int($settings{'last'});
+ $frame = int($state {'last'})+1;
- if($dynamic > 0 && $frame < $last) {
- $dynamic = int($dynamic/($last-$frame));
+ if (($timer > 0) && ($frame < $last)) {
+ $timer = int($timer / ($last - $frame));
}
else {
- $dynamic=0;
+ $timer=0;
}
- if($static>$dynamic){
- $dynamic=$static;
+ if ($static_timer > $timer) {
+ $timer = $static_timer;
}
- $nextong=$ongtime+($dynamic*3600);
- $state{'nextong'}=$nextong;
- print 'next ongtime: '.$nextong.' (+'.$dynamic.")\n";
- $state{'ongtime'}=$dynamic;
+ $next_ong = $ongtime + ($timer*3600);
+ $state{'nextong'} = $next_ong;
+ print 'next ongtime: '.$next_ong.' (+'.$timer.")\n";
+ $state{'ongtime'}=$timer;
- if($ongstate == 2) {
+ if ($ongstate == STATE->{'ready'}) {
print 'next frame: '.$frame."\n";
- %framedata=readdatafile(DATA_PATH.$frame);
- %default=readdatafile(DATA_DEFAULT_PATH);
- %gotolist=readdatafile(DATA_LIST_PATH);
- $framedata{'ongtime'}=$time;
- $framedata{'timer'}=$dynamic;
- $gotolist{'title-'.$frame}=$framedata{'title'};
- $gotolist{'ongtime-'.$frame}=$framedata{'ongtime'};
- writedatafile(DATA_PATH.$frame,%framedata);
- writedatafile(DATA_LIST_PATH,%gotolist);
+ $r = ong (
+ $frame, # frame ID
+ $time, # ONG time
+ $timer, # timer to next ONG
+ 0, # update
+ 1, # print
+ \%settings,
+ '', # %default
+ '', # %frame_data
+ '' # %goto_list
+ );
- foreach my $ind (keys %default) {
- unless(defined($framedata{$ind})){
- $framedata{$ind}=$default{$ind};
- }
- unless(defined($nextframedata{$ind})){
- $nextframedata{$ind}=$default{$ind};
- }
- }
-
- $inpath = DATA_PATH.sprintf($settings{'frame'},$frame,$framedata{'ext'});
- $outpath = WWW_PATH.sprintf($settings{'frame'},$frame,$framedata{'ext'});
-
- print $inpath.' -> '.$outpath."\n";
-
- # ALSO-ATTACHMENTS!!! (here)
-
- if(copy ($inpath, $outpath)) {
- $state{'last'}=$frame;
- $state{'state'}=1;
- $state{'ip1'}='';
- $state{'ip2'}='';
- $state{'ip3'}='';
- $state{'ongtime'}=$dynamic;
+ if ($r) {
+ $state{'last'} = $frame;
+ $state{'state'} = 1;
+ $state{'ip1'} = '';
+ $state{'ip2'} = '';
+ $state{'ip3'} = '';
+ $state{'ongtime'}= $timer;
print "ONG\n";
}
else {
print "NO ONG\n";
}
}
- writedatafile($statefile,%state);
+ write_data_file($fh, '', '', \%state);
}
- else {
- print "WAIT\n";
- }
- }
- else {
- print "INACTIVE\n";
}
}
- else {
- print "NO STATELOCK\n";
- }
- close ($statefile);
-}
-else {
- print "NO STATEFILE\n";
+ close ($fh);
}
+
print "\n";
\ No newline at end of file