3 # This script is invoked when the YPP SC PCTB client uploads to
6 # This is part of ypp-sc-tools, a set of third-party tools for assisting
7 # players of Yohoho Puzzle Pirates.
9 # Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation, either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
25 # are used without permission. This program is not endorsed or
26 # sponsored by Three Rings.
30 # ocean canonical mixed case
31 # island canonical mixed case
32 # clientname "ypp-sc-tools"
33 # clientversion 2.1-g2e06a26 [from git-describe --tags HEAD]
34 # clientfixes "lastpage" [space separated list]
35 # data filename=deduped.tsv.gz output of ypp-commodities --tsv
37 use strict (qw(vars));
42 $CGI::POST_MAX= 3*1024*1024;
43 $CGI::DISABLE_UPLOADS= 1;
45 use CGI qw/:standard -private_tempfiles/;
47 setlocale(LC_CTYPE, "en_GB.UTF-8");
49 my $re_any= "^(.*)\$";
55 print header(-status=>'400 Bad commodity update',
57 -charset=>'us-ascii');
58 print "Error: $msg\n";
65 fail("missing form parameter $n") unless defined $v;
66 fail("invalid form parameter $n") unless $v =~ m/$re/;
70 my $clientname= must_param('clientname',$re_any);
71 my $clientinfo= $clients{$clientname};
72 fail('unknown client') unless defined $client;
74 my $clientfixes= must_param('clientfixes', "^([-0-9a-z ]*)\$");
75 my @clientfixes= sort grep { m/./ } split /\s+/, $clientfixes;
76 $clientfixes= "@clientfixes";
77 foreach my $bug (@$clientinfo) {
78 fail("client out of date - missing bugfix \`$bug'")
79 unless grep { $_ eq $bug } @clientfixes;
82 my $cversion= must_param('clientversion', "^(\\d[-+._0-9a-zA-Z]+)\$");
84 my $ocean= must_param('ocean', $re_any);
85 my $island= must_param('island', $re_any);
87 my $arches= $oceans{$ocean};
88 fail("unknown ocean") unless $arches;
91 foreach my $islands (values %$arches) {
92 my $sources= $islands->{$island};
95 $island_found= $sources;
97 fail("unknown island") unless $island_found;
99 die if $ocean =~ m/\=/;
100 die if $island =~ m/\=/;
102 $datafile= must_param('data',"^(deduped\\.tsv\\.gz)\$");
103 $indatafh= upload('data'); fail("data is not a file") unless defined $datafh;
107 my $content= MIME::Entity->build(Type => 'multipart/mixed',
111 my $clientspec= "$clientname $clientversion $clientfixes";
112 foreach $vn (qw(ocean island
114 clientname clientversion clientfixes)) {
117 !m/\P{IsPrint}/ or die bad_data('nonprinting char(s)');
119 @v==6 or bad_data('wrong number of fields');
120 my ($commod,$stall) = @v;
121 defined $commods{$commod} or bad_data("unknown commodity \`$commod'");
122 $stall =~ m/^\p{IsUpper}/ or bad_data("stall not capitalised");
123 !exists $done{$commod,$stall} or bad_data("repeated data");
124 $done{$commod,$stall}= 1;
125 foreach my $f (@v[2..5]) {
126 $f =~ m/^(0|[1-9][0-9]{0,5}|\>1000)$/ or bad_data("bad field");
127 ($v % 1) or ($v !~ m/\>/) or bad_data("> in price");
134 #foreach my $commod (sort keys %commods) {
137 #STDOUT->error and die $!;
138 #close STDOUT or die $!;