]> bicyclesonthemoon.info Git - ott/bsta/blob - reset.1.pl
hyperlinks to static previous/next page
[ott/bsta] / reset.1.pl
1 ###RUN_PERL: #!/usr/bin/perl
2
3 # reset is generated from reset.1.pl.
4 #
5 # Reset BSTA state
6 #
7 # Copyright (C) 2016, 2017, 2018, 2023, 2024  Balthasar SzczepaƄski
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU Affero General Public License as
11 # published by the Free Software Foundation, either version 3 of the
12 # License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU Affero General Public License for more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22 use strict;
23 use utf8;
24 use Encode::Locale ('decode_argv');
25 use Encode ('encode', 'decode');
26
27 ###PERL_LIB: use lib /botm/lib/bsta
28 use botm_common (
29         'read_data_file', 'write_data_file',
30         'opendir_encoded', 'readdir_decoded', 'unlink_encoded',
31         'join_path'
32 );
33 use bsta_lib (
34         'STATE', 'INTF_STATE', 'CHAT_STATE',
35         'write_index'
36 );
37
38 binmode STDIN,  ':encoding(UTF-8)';
39 binmode STDOUT, ':encoding(UTF-8)';
40 binmode STDERR, ':encoding(UTF-8)';
41 decode_argv();
42
43 ###PERL_PATH_SEPARATOR:     PATH_SEPARATOR     = /
44
45 ###PERL_DATA_CHAT_PATH:     DATA_CHAT_PATH     = /botm/data/bsta/chat
46 ###PERL_DATA_LIST_PATH:     DATA_LIST_PATH     = /botm/data/bsta/list
47 ###PERL_DATA_SETTINGS_PATH: DATA_SETTINGS_PATH = /botm/data/bsta/state
48 ###PERL_DATA_STATE_PATH:    DATA_STATE_PATH    = /botm/data/bsta/state
49 ###PERL_DATA_STORY_PATH:    DATA_STORY_PATH    = /botm/data/bsta/story
50 ###PERL_DATA_WORDS_PATH:    DATA_WORDS_PATH    = /botm/data/bsta/words/
51
52 ###PERL_RESET_PASSWORD:     RESET_PASSWORD     = ''
53
54 my %story;
55 my %state;
56 my %chat;
57 my %settings;
58 my %goto_list;
59
60 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
61 ###PERL_SET_PATH: $ENV{'PATH'} = /usr/local/bin:/usr/bin:/bin;
62
63 %settings = read_data_file(DATA_SETTINGS_PATH());
64 unless (
65         ($ARGV[0] ne '') && (
66                 ($ARGV[0] eq $settings{'password'}) ||
67                 ($ARGV[0] eq RESET_PASSWORD())
68         )
69 ) {
70         print STDERR "Wrong password; no reset.\n";
71         exit 1;
72 }
73
74 %state = (
75         'state' => STATE->{'inactive'},
76         'last'  => 0,
77         'ongtime' => '',
78         'nextong' => '',
79         'ip1' => '',
80         'ip2' => '',
81         'ip3' => ''
82 );
83 %story = (
84         'id'      => 0,
85         'letter'  => '',
86         'lastip'  => '0.0.0.0',
87         'content' => '',
88         'pass'    => 0,
89         'state'   => INTF_STATE->{'X'}
90 );
91 %chat = (
92         'id'      => 0,
93         'state'   => CHAT_STATE->{'disconnected'},
94         'content' => ''
95 );
96 %goto_list = (
97 );
98
99 write_data_file(DATA_STATE_PATH(), \%state);
100 write_data_file(DATA_STORY_PATH(), \%story);
101 write_data_file(DATA_CHAT_PATH() , \%chat);
102 write_data_file(DATA_LIST_PATH() , \%goto_list);
103
104 write_index(
105         \%state,
106         \%settings,
107         $story{'pass'},
108         $story{'state'},
109         0 # pause
110 );
111
112 if (opendir_encoded(my $dir, DATA_WORDS_PATH())) {
113         while (my $file_name = readdir_decoded($dir)) {
114                 if ($file_name !~ /^[0-9]+$/) {
115                         next;
116                 }
117                 my $full_path = join_path(PATH_SEPARATOR(), DATA_WORDS_PATH(), $file_name);
118                 unlink_encoded ($full_path);
119         }
120 }