#
# 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
'print_html_body_start', 'print_html_body_end',
'write_index',
'get_remote_addr',
- 'merge_settings'
+ 'merge_settings',
+ 'ong'
);
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
my %new_story;
my %settings;
my %state;
-my %goto_list;
my $time = time();
srand ($time-$$);
}
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'};
#
# 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
###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
$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'});
#
# 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
'print_html_body_start', 'print_html_body_end',
'print_viewer_page',
'write_index',
+ 'ong',
'readdatafile', 'writedatafile', 'printdatafile', # TO REMOVE
'entityencode', # TO REMOVE
'read_data_file', 'write_data_file',
'join_path'
);
+use File::Copy;
###PERL_PATH_SEPARATOR: PATH_SEPARATOR = /
###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
'file' => 4,
};
-
use constant tags_bbcode => {
'ht' => '',
'/ht' => '',
};
-
# Function to return an error page
# arguments: 1 - header fields, 2 - page title, 3 - error message, 4 method
sub failpage {
);
}
+
# function to obtain address of remote agent
sub get_remote_addr {
if ($ENV{'HTTP_X_FORWARDED_FOR'} =~ /^.+$/) {
}
}
+
sub merge_settings {
my %final_settings;
return url_encode($t, '', $all);
}
+
# BB code stuff
# different & simpler implementation than in post library
# to consider:
return 1;
}
-
sub write_index {
(
my $state,
}
+# 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
# 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
_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 )
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 )
#
# 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
'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;
###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)';
# 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->{'>|'} ) &&
) {
# 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;
# 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'};
}