]> bicyclesonthemoon.info Git - botm/oldlogs/commitdiff
ONG will use generic function
authorb <rowerynaksiezycu@gmail.com>
Tue, 2 Jan 2024 11:35:16 +0000 (11:35 +0000)
committerb <rowerynaksiezycu@gmail.com>
Tue, 2 Jan 2024 11:35:16 +0000 (11:35 +0000)
2words.1.pl
attach.1.pl
bsta_lib.1.pm
ong.1.pl
viewer.1.pl

index cb5fd79be5008a10ce068a97b5a0c6f22c4d5c9b..e679c62adad649deb78295ff68629b04720cd731 100644 (file)
@@ -5,7 +5,7 @@
 #
 # 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
@@ -46,7 +46,6 @@ use bsta_lib (
        'merge_settings',
        'ong'
 );
-use  File::Copy;
 
 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
 
@@ -140,7 +139,7 @@ $cmd_clear     = $settings{'password'}.' clear';
 $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;
@@ -295,6 +294,7 @@ if (open ($story_file,"+<:encoding(UTF-8)",DATA_STORY_PATH())){
                                                                $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
@@ -307,6 +307,7 @@ if (open ($story_file,"+<:encoding(UTF-8)",DATA_STORY_PATH())){
                                                                        $time, # ONG time;   not relevant
                                                                        0,     # timer;      not relevant
                                                                        0,     # update;     not relevant
+                                                                       0,     # print
                                                                        \%settings,
                                                                        '',    # %default
                                                                        '',    # %frame_data
@@ -320,6 +321,7 @@ if (open ($story_file,"+<:encoding(UTF-8)",DATA_STORY_PATH())){
                                                                        $time, # ONG time; might get overwritten later
                                                                        0,     # timer
                                                                        0,     # update
+                                                                       0,     # print
                                                                        \%settings,
                                                                        '',    # %default
                                                                        '',    # %frame_data
index 26ed4137ae368111dad5e9a87699b7728e6ff369..d680f7676cf4debcdd7c847278823c9adea33835 100644 (file)
@@ -161,7 +161,7 @@ else {
                        exit fail_attachment($method, $ID);
                }
        }
-       unless(binmode($fh)) {
+       unless (binmode($fh)) {
                close($fh);
                exit fail_500("Can't switch file to binary mode.");
        }
index fe55c3b025a241ecaf5f6790568f3bb45633421d..6d90ed8c1910761600954124b88d9c10387e310e 100644 (file)
@@ -1578,7 +1578,7 @@ sub write_index {
 # ONG the frame + attachment & stiff. NOT update state file.
 sub ong {
        (
-               my $ID, my $ongtime, my $timer, my $update,
+               my $ID, my $ongtime, my $timer, my $update, my $print,
                my $settings_ref, my $default_ref, my $data_ref, my $goto_ref
        ) = @_;
        my @files;
@@ -1707,7 +1707,13 @@ sub ong {
        foreach my $file (@files) {
                $in_path  = join_path(PATH_SEPARATOR(), DATA_PATH(), $file);
                $out_path = join_path(PATH_SEPARATOR(), WWW_PATH() , $file);
+               if ($print) {
+                       print $in_path.' -> '.$out_path;
+               }
                $r = copy($in_path, $out_path);
+               if ($print) {
+                       print (($r) ? " OK\n" : " FAIL\n");
+               }
                unless ($r) {
                        return $r
                }
index 1eeb352697786e5e531f09c0c45d4730639538bf..ef9063233a05a2d17276663ba7c8233bfd8f76c6 100644 (file)
--- a/ong.1.pl
+++ b/ong.1.pl
 # 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
index 27ef3fa1c9d1227a87e7e348112393a12f22e75e..263e502744c0c0c9e8c65182379f120f55d54b2c 100644 (file)
@@ -5,7 +5,7 @@
 #
 # The viewer interface
 #
-# Copyright (C) 2016-2017, 2019-2020, 2023 - 2024  Balthasar Szczepański
+# Copyright (C) 2016, 2017, 2019, 2020, 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
@@ -40,7 +40,6 @@ use bsta_lib (
        'print_viewer_page', 'write_index',
        'ong'
 );
-use File::Copy;
 
 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
 
@@ -196,6 +195,7 @@ if (open ($state_file, "+<:encoding(UTF-8)", DATA_STATE_PATH())) {
                                        $time,     # ONG time,
                                        $ong_time, # timer
                                        0,         # update
+                                       0,         # print
                                        \%settings,
                                        \%default,
                                        \%frame_data,