]> bicyclesonthemoon.info Git - ott/bsta/commitdiff
generic ONG function, used in launch; ONG attachments too
authorb <rowerynaksiezycu@gmail.com>
Mon, 1 Jan 2024 23:43:25 +0000 (23:43 +0000)
committerb <rowerynaksiezycu@gmail.com>
Mon, 1 Jan 2024 23:43:25 +0000 (23:43 +0000)
2words.1.pl
attach.1.pl
bsta_lib.1.pm
settings.txt
viewer.1.pl

index 453f4d5700562f053ef39dd937def1bbf41222f0..cb5fd79be5008a10ce068a97b5a0c6f22c4d5c9b 100644 (file)
@@ -5,7 +5,7 @@
 #
 # The wordgame interface
 #
-# Copyright (C) 2016 - 2017, 2023  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
@@ -43,7 +43,8 @@ use bsta_lib (
        'print_html_body_start', 'print_html_body_end',
        'write_index',
        'get_remote_addr',
-       'merge_settings'
+       'merge_settings',
+       'ong'
 );
 use  File::Copy;
 
@@ -52,15 +53,10 @@ use  File::Copy;
 ###PERL_CGI_PATH:           CGI_PATH           = /bsta/
 ###PERL_CGI_2WORDS_PATH:    CGI_2WORDS_PATH    = /bsta/2words
 
-###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta/
-###PERL_DATA_DEFAULT_PATH:  DATA_DEFAULT_PATH  = /botm/data/bsta/default
-###PERL_DATA_LIST_PATH:     DATA_LIST_PATH     = /botm/data/bsta/list
 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
 ###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
 ###PERL_DATA_STORY_PATH:    DATA_STORY_PATH    = /botm/data/bsta/story
 
-###PERL_WWW_PATH:           WWW_PATH           = /botm/www/1190/bsta/
-
 ###PERL_WEBSITE_NAME:       WEBSITE_NAME       = Bicycles on the Moon
 
 ###PERL_STORY_LENGTH:       STORY_LENGTH       = 16
@@ -78,7 +74,6 @@ my %story;
 my %new_story;
 my %settings;
 my %state;
-my %goto_list;
 
 my $time = time();
 srand ($time-$$);
@@ -292,40 +287,46 @@ if (open ($story_file,"+<:encoding(UTF-8)",DATA_STORY_PATH())){
                                                }
                                                else {
                                                        # ready to activate?
-                                                       my $frame_data_path;
-                                                       my %frame_data;
-                                                       my %default;
-                                                       my $frame_file;
-                                                       my $in_path;
-                                                       my $out_path;
-                                                       my $ext;
-                                                       
-                                                       # prepare to ONG frame 0!
-                                                       
-                                                       $frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), 0);
-                                                       %frame_data = read_data_file($frame_data_path);
-                                                       %default    = read_data_file(DATA_DEFAULT_PATH());
-                                                       
-                                                       $ext = (defined($frame_data{'ext'})) ?
-                                                               $frame_data{'ext'} :
-                                                               $default{'ext'};
-                                                       
-                                                       $frame_file = sprintf($settings{'frame'}, 0, $ext);
-                                                       $in_path  = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame_file);;
-                                                       $out_path = join_path(PATH_SEPARATOR(), WWW_PATH(),  $frame_file);
-                                                       
-                                                       # set ONG time of frame 0
-                                                       # NOTE: might get overwritten later if ONG not launched
-                                                       $frame_data{'ongtime'} = $time;
-                                                       $frame_data{'timer'} = 0;
-                                                       write_data_file($frame_data_path, '', '', \%frame_data);
-                                                       
-                                                       # update the GOTO list with frame 0
-                                                       $goto_list{'title-0'  } = $frame_data{'title'};
-                                                       $goto_list{'ongtime-0'} = $frame_data{'ongtime'};
-                                                       write_data_file(DATA_LIST_PATH(), '', '', \%goto_list);
+                                                       my $r;
                                                        
-                                                       if(copy ($in_path, $out_path)) {
+                                                       # ONG tape interface
+                                                       $r = ong(
+                                                               'i',   # ID: tape interface
+                                                               $time, # ONG time;    not relevant
+                                                               0,     # timer;       not relevant
+                                                               0,     # update;      not relevant
+                                                               \%settings,         # not relevant
+                                                               '',    # %default;    not relevant
+                                                               '',    # %frame_data; not relevant
+                                                               ''     # $goto_list;  not relevant
+                                                       );
+                                                       if ($r) {
+                                                               # ONG CFRT
+                                                               $r = ong(
+                                                                       'c',   # ID: CFRT
+                                                                       $time, # ONG time;   not relevant
+                                                                       0,     # timer;      not relevant
+                                                                       0,     # update;     not relevant
+                                                                       \%settings,
+                                                                       '',    # %default
+                                                                       '',    # %frame_data
+                                                                       ''     # $goto_list; not relevant
+                                                               );
+                                                       }
+                                                       if ($r) {
+                                                               # ONG frame 0!
+                                                               $r = ong(
+                                                                       0,     # frame ID
+                                                                       $time, # ONG time; might get overwritten later
+                                                                       0,     # timer
+                                                                       0,     # update
+                                                                       \%settings,
+                                                                       '',    # %default
+                                                                       '',    # %frame_data
+                                                                       ''     # $goto_list
+                                                               );
+                                                       }
+                                                       if($r) {
                                                                # new state of hidden interface
                                                                $intf_pass = 1;
                                                                $intf_state = INTF_STATE->{'X'};
index 18caf8a2a4779ae01b02789507434e1d7c2db181..d61c2fd3d07853575f066b4b4f65576f791862bf 100644 (file)
@@ -5,7 +5,7 @@
 #
 # The attachment interface
 #
-# Copyright (C) 2016, 2023  Balthasar Szczepański
+# Copyright (C) 2016, 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
@@ -42,6 +42,7 @@ use bsta_lib (
 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
 
 ###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta
+###PERL_DATA_ATTACH_PATH:   DATA_ATTACH_PATH   = /botm/data/bsta/a
 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
 ###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
 
@@ -99,9 +100,9 @@ if ($method eq 'POST') {
 $ID       = get_id(      \%cgi);
 $password = get_password(\%cgi);
 
-%settings  = read_data_file(DATA_SETTINGS_PATH);
-%state     = read_data_file(DATA_STATE_PATH);
-%file_data = read_data_file(join_path(PATH_SEPARATOR(), DATA_PATH(), 'a'.$ID));
+%settings  = read_data_file(DATA_SETTINGS_PATH());
+%state     = read_data_file(DATA_STATE_PATH());
+%file_data = read_data_file(DATA_ATTACH_PATH().$ID);
 $frame = ($file_data{'frame'} ne '') ? int($file_data{'frame'}) : -1;
 
 $password_ok = ($password eq $settings{'password'});
index c16899c5871528f61b863f9e952208cc55982235..fe55c3b025a241ecaf5f6790568f3bb45633421d 100644 (file)
@@ -2,7 +2,7 @@
 # 
 # Library of functions
 #
-# Copyright (C) 2016, 2017, 2019, 2020, 2022, 2023  Balthasar Szczepański
+# Copyright (C) 2016, 2017, 2019, 2020, 2022, 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
@@ -47,6 +47,7 @@ our @EXPORT_OK   = (
        'print_html_body_start', 'print_html_body_end',
        'print_viewer_page',
        'write_index',
+       'ong',
        
        'readdatafile', 'writedatafile', 'printdatafile', # TO REMOVE
        'entityencode', # TO REMOVE
@@ -68,6 +69,7 @@ use botm_common (
        'read_data_file', 'write_data_file',
        'join_path'
 );
+use File::Copy;
 
 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
 
@@ -84,9 +86,13 @@ use botm_common (
 ###PERL_CGI_VIEWER_PATH:    CGI_VIEWER_PATH    = /bsta/v
 
 ###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta/
+###PERL_DATA_ATTACH_PATH:   DATA_ATTACH_PATH   = /botm/data/bsta/a
 ###PERL_DATA_COIN_PATH:     DATA_COIN_PATH     = /botm/data/bsta/coincidence
 ###PERL_DATA_DEFAULT_PATH:  DATA_DEFAULT_PATH  = /botm/data/bsta/default
+###PERL_DATA_LIST_PATH:     DATA_LIST_PATH     = /botm/data/bsta/list
+###PERL_DATA_NOACCESS_PATH: DATA_NOACCESS_PATH = /botm/data/bsta/noaccess
 
+###PERL_WWW_PATH:           WWW_PATH           = /botm/www/
 ###PERL_WWW_INDEX_PATH:     WWW_INDEX_PATH     = /botm/www/1190/bsta/index.htm
 
 ###PERL_SCHEME:             SCHEME             = http
@@ -134,7 +140,6 @@ use constant CHAT_ACTION => {
        'file'   => 4,
 };
 
-
 use constant tags_bbcode => {
        'ht'    => '',
        '/ht'   => '',
@@ -199,7 +204,6 @@ use constant tags_html => {
 };
 
 
-
 # Function to return an error page
 # arguments: 1 - header fields, 2 - page title, 3 - error message, 4 method
 sub failpage {
@@ -343,6 +347,7 @@ sub redirect
        );
 }
 
+
 # function to obtain address of remote agent
 sub get_remote_addr {
        if ($ENV{'HTTP_X_FORWARDED_FOR'} =~ /^.+$/) {
@@ -395,6 +400,7 @@ sub get_password {
        }
 }
 
+
 sub merge_settings {
                my %final_settings;
        
@@ -521,6 +527,7 @@ sub urlencode {
        return url_encode($t, '', $all);
 }
 
+
 # BB code stuff
 # different & simpler implementation than in post library
 # to consider:
@@ -1327,7 +1334,6 @@ sub print_viewer_page {
        return 1;
 }
 
-
 sub write_index {
        (
                my $state,
@@ -1569,4 +1575,145 @@ sub write_index {
 }
 
 
+# ONG the frame + attachment & stiff. NOT update state file.
+sub ong {
+       (
+               my $ID, my $ongtime, my $timer, my $update,
+               my $settings_ref, my $default_ref, my $data_ref, my $goto_ref
+       ) = @_;
+       my @files;
+       my $cfrt;
+       my $intf;
+       my $frame;
+       my $frame_data_path;
+       my $write_data;
+       my $in_path;
+       my $out_path;
+       my $r;
+       my %settings;
+       my %default;
+       my %frame_data;
+       my %frame_full_data;
+       my %goto_list;
+       
+       if ($ongtime eq '') {
+               $ongtime = time();
+       }
+       
+       if ($ID eq 'i') {
+               $intf = 1;
+       }
+       elsif ($ID eq 'c') {
+               $cfrt = 1;
+       }
+       else {
+               $frame = int($ID);
+       }
+       
+       if ($intf) {
+               @files = (
+                       'intf-00.gif',
+                       'intf-00_04.gif',
+                       'intf-00_08.gif',
+                       'intf-00_10.gif',
+                       'intf-01.gif',
+                       'intf-01_.gif',
+                       'intf-02.gif',
+                       'intf-02_.gif',
+                       'intf-04.gif',
+                       'intf-04_.gif',
+                       'intf-08.gif',
+                       'intf-08_.gif',
+                       'intf-10.gif',
+                       'intf-10_.gif',
+                       'intf-20.gif',
+                       'intf-20_.gif',
+                       'intf-kw.gif',
+                       'intf-ll.gif',
+                       'intf-pp.gif',
+                       'intf-tr.gif',
+               );
+       }
+       else {
+               %settings = (ref ($settings_ref)) ?
+                       %$settings_ref :
+                       read_data_file(DATA_SETTINGS_PATH());
+               %default = (ref ($default_ref)) ?
+                       %$default_ref :
+                       read_data_file(DATA_DEFAULT_PATH());
+               $frame_data_path = $cfrt ?
+                       DATA_NOACCESS_PATH() :
+                       join_path(PATH_SEPARATOR(), DATA_PATH(), $frame);
+               %frame_data = (ref ($data_ref)) ?
+                       %$data_ref :
+                       read_data_file($frame_data_path);
+               %frame_full_data = merge_settings(\%default, \%frame_data);
+               @files = (
+                       ($frame_full_data{'frame'} ne '') ?
+                               $frame_full_data{'frame'} :
+                               sprintf(
+                                       $settings{'frame'},
+                                       $frame, $frame_full_data{'ext'}
+                               )
+                       ,
+               );
+               unless ($cfrt) {
+                       %goto_list = (ref ($goto_ref)) ?
+                               %$goto_ref :
+                               read_data_file(DATA_LIST_PATH());
+                       for (my $i=0; ;$i+=1) {
+                               my %file_data = read_data_file(DATA_ATTACH_PATH().$i);
+                               if ($file_data{'frame'} eq '') {
+                                       last;
+                               }
+                               if (int($file_data{'frame'}) != $frame) {
+                                       next;
+                               }
+                               if ($file_data{'content'} ne '') {
+                                       next;
+                               }
+                               unshift @files, $file_data{'filename'};
+                       }
+                       if (
+                               (!$update) ||
+                               ($frame_full_data{'ongtime'} eq '')
+                       ) {
+                               $frame_data{'ongtime'} = $ongtime;
+                               $write_data = 1;
+                       }
+                       if (
+                               ($timer ne '') && (
+                                       (!$update) ||
+                                       ($frame_full_data{'timer'} eq '')
+                               )
+                       ) {
+                               $frame_data{'timer'} = int($timer);
+                               $write_data = 1;
+                       }
+                       if ($write_data) {
+                               $r = write_data_file($frame_data_path, '', '', \%frame_data);
+                       }
+                       unless ($r) {
+                               return $r;
+                       }
+                       $goto_list{'title-'  .$frame} = $frame_full_data{'title'};
+                       $goto_list{'ongtime-'.$frame} = $frame_full_data{'ongtime'};
+                       $r = write_data_file(DATA_LIST_PATH(), '', '', \%goto_list);
+                       unless ($r) {
+                               return $r;
+                       }
+               }
+       }
+       foreach my $file (@files) {
+               $in_path  = join_path(PATH_SEPARATOR(), DATA_PATH(), $file);
+               $out_path = join_path(PATH_SEPARATOR(), WWW_PATH() , $file);
+               $r = copy($in_path, $out_path);
+               unless ($r) {
+                       return $r
+               }
+       }
+       
+       return 1;
+}
+
 1
index 45bd4009b155127045269b93bd76fb466d0e1e35..68d5a25d5007d06b354f05b3143b408eff4cc709 100644 (file)
@@ -1,6 +1,6 @@
 # settings.txt
 # 
-# Copyright (C) 2023  Balthasar Szczepański
+# Copyright (C) 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
@@ -54,6 +54,7 @@ _cgi_timer_path     = @_PATH( $cgi_path, timer.js    )
 _cgi_viewer_path    = @_PATH( $cgi_path, v           )
 
 _data_path          = @_PATH( $data_path,            )
+_data_attach_path   = @_PATH( $data_path, a          )
 _data_chat_path     = @_PATH( $data_path, chat       )
 _data_coin_path     = @_PATH( $data_path, coincidence)
 _data_default_path  = @_PATH( $data_path, default    )
@@ -157,6 +158,7 @@ PERL_CGI_TIMER_PATH     = @_PERL_CONSTANT_STR( CGI_TIMER_PATH , $_cgi_timer_path
 PERL_CGI_VIEWER_PATH    = @_PERL_CONSTANT_STR( CGI_VIEWER_PATH, $_cgi_viewer_path)
 
 PERL_DATA_PATH          = @_PERL_CONSTANT_STR( DATA_PATH         , $_data_path         )
+PERL_DATA_ATTACH_PATH   = @_PERL_CONSTANT_STR( DATA_ATTACH_PATH  , $_data_attach_path  )
 PERL_DATA_CHAT_PATH     = @_PERL_CONSTANT_STR( DATA_CHAT_PATH    , $_data_chat_path    )
 PERL_DATA_COIN_PATH     = @_PERL_CONSTANT_STR( DATA_COIN_PATH    , $_data_coin_path    )
 PERL_DATA_DEFAULT_PATH  = @_PERL_CONSTANT_STR( DATA_DEFAULT_PATH , $_data_default_path )
index d535fe40bfe1cb7bf160771d54cc893ca475686d..27ef3fa1c9d1227a87e7e348112393a12f22e75e 100644 (file)
@@ -5,7 +5,7 @@
 #
 # The viewer interface
 #
-# Copyright (C) 2016-2017, 2019-2020, 2023  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
@@ -37,7 +37,8 @@ use bsta_lib (
        'fail_method', 'fail_content_type',
        'get_remote_addr', 'get_frame', 'get_password',
        'merge_settings',
-       'print_viewer_page', 'write_index'
+       'print_viewer_page', 'write_index',
+       'ong'
 );
 use File::Copy;
 
@@ -45,14 +46,11 @@ use File::Copy;
 
 ###PERL_DATA_PATH:          DATA_PATH          = /botm/data/bsta/
 ###PERL_DATA_DEFAULT_PATH:  DATA_DEFAULT_PATH  = /botm/data/bsta/default
-###PERL_DATA_LIST_PATH:     DATA_LIST_PATH     = /botm/data/bsta/list
 ###PERL_DATA_NOACCESS_PATH: DATA_NOACCESS_PATH = /botm/data/bsta/noaccess
 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/settings
 ###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
 ###PERL_DATA_STORY_PATH:    DATA_STORY_PATH    = /botm/data/bsta/story
 
-###PERL_WWW_PATH:           WWW_PATH           = /botm/www/1190/bsta/
-
 binmode STDIN,  ':encoding(UTF-8)';
 binmode STDOUT, ':encoding(UTF-8)';
 binmode STDERR, ':encoding(UTF-8)';
@@ -171,14 +169,10 @@ if (open ($state_file, "+<:encoding(UTF-8)", DATA_STATE_PATH())) {
                        # ready to activate?
                        # NOTE: at this point frame 0 is already ONGed.
                        my %story;
-                       my $frame_file;
-                       my $in_path;
-                       my $out_path;
-                       my $ext;
                        my $ong_time = int($settings{'firstongtime'});
+                       my $r;
                        
                        %story     = read_data_file(DATA_STORY_PATH());
-                       %goto_list = read_data_file(DATA_LIST_PATH);
                        
                        if (
                                (int($story{'state'}) == INTF_STATE->{'>|'} ) &&
@@ -186,11 +180,6 @@ if (open ($state_file, "+<:encoding(UTF-8)", DATA_STATE_PATH())) {
                        ) {
                                # conditions met; ACTIVATE!
                                
-                               # update ONG time of frame 1
-                               $frame_data{'ongtime'} = $time;
-                               $frame_data{'timer'} = $ong_time;
-                               write_data_file($frame_data_path, '', '', \%frame_data);
-                               
                                # set initial state
                                $state{'state'} = STATE->{'waiting'};
                                $state{'last'}  = 1; 
@@ -202,24 +191,23 @@ if (open ($state_file, "+<:encoding(UTF-8)", DATA_STATE_PATH())) {
                                
                                # prepare to ONG frame 1
                                
-                               # determine frame file & paths
-                               $ext = (defined($frame_data{'ext'})) ?
-                                       $frame_data{'ext'} :
-                                       $default{'ext'};
-                               $frame_file = sprintf($settings{'frame'}, $frame, $ext);
-                               $in_path  = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame_file);
-                               $out_path = join_path(PATH_SEPARATOR(), WWW_PATH(),  $frame_file);
-                               
-                               # update the GOTO list with frame 1
-                               $goto_list{'title-1'}   = $frame_data{'title'};
-                               $goto_list{'ongtime-1'} = $frame_data{'ongtime'};
-                               
-                               if (copy ($in_path, $out_path)) {
-                                       write_index(\%state, \%settings);
-                                       write_data_file($state_file,     '','', \%state);
-                                       write_data_file(DATA_LIST_PATH(),'','', \%goto_list);
+                               $r = ong(
+                                       1,         # frame ID
+                                       $time,     # ONG time,
+                                       $ong_time, # timer
+                                       0,         # update
+                                       \%settings,
+                                       \%default,
+                                       \%frame_data,
+                                       ''         # %goto_list
+                               );
+                               if ($r) {
+                                       $r = write_index(\%state, \%settings);
                                }
-                               else {
+                               if ($r) {
+                                       $r = write_data_file($state_file,     '','', \%state);
+                               }
+                               unless ($r) {
                                        # FAILED ONG! Story as if it was inactive!
                                        $state{'state'} = STATE->{'inactive'};
                                }