###PERL_LIB: use lib /botm/lib/bsta
use botm_common (
+ 'HTTP_STATUS',
+ 'http_header_status', 'http_header_allow',
'read_data_file', 'write_data_file',
'merge_url',
'read_header_env',
my $last_IP;
my $story_id;
my $turn;
+my $status;
+my $allow;
my $message;
my $first_letter;
my $second_letter;
$method = $1;
}
else {
- exit fail_method($ENV{'REQUEST_METHOD'}, 'GET, POST, HEAD');
+ exit fail_method($ENV{'REQUEST_METHOD'}, ['GET','POST', 'HEAD']);
}
%http = read_header_env(\%ENV);
}
if (
- ($words eq $cmd_clear) ||
- ($words eq $cmd_clear_all) ||
- ($intf_state < 0)
+ ($intf_state < 0) || (
+ ($method eq 'POST') && (
+ ($words eq $cmd_clear) ||
+ ($words eq $cmd_clear_all)
+ )
+ )
) {
if (
($words eq $cmd_clear_all) ||
write_data_file($fh, \%story);
}
- if ($words ne '') {
+ if (($words ne '') && ($method eq 'POST')) {
if (!$turn) {
+ $status = HTTP_STATUS->{'forbidden'};
$message = "It's not your turn.";
}
# TODO: consider allowing non-ASCII letters in words.
($first_letter ne $last_letter) &&
($last_letter ne '')
) {
+ $status = HTTP_STATUS->{'bad_request'};
$message = 'The first word must start with '.uc($last_letter).'.';
}
elsif ($first_letter eq $second_letter) {
+ $status = HTTP_STATUS->{'bad_request'};
$message = 'The second word can\'t also start with '.uc($first_letter).'.';
}
else {
}
}
else {
+ $status = HTTP_STATUS->{'bad_request'};
$message = 'Please, two words, not more, not less (some punctuation is allowed).';
}
}
close($fh);
}
+if ($status ne '') {
+ print http_header_status($status);
+}
+if ($allow ne '') {
+ print http_header_allow($allow);
+}
print "Content-type: text/html; charset=UTF-8\n\n";
+
if($method eq 'HEAD') {
exit;
}