… | |
… | |
80 | |
80 | |
81 | sub editor_invoke { |
81 | sub editor_invoke { |
82 | my $editsup = $::CONN && $::CONN->{editor_support} |
82 | my $editsup = $::CONN && $::CONN->{editor_support} |
83 | or return; |
83 | or return; |
84 | |
84 | |
85 | my ($pid, $fh); |
85 | CFPlus::background { |
86 | unless ($pid = open $fh, "-|:utf8", "-") { |
|
|
87 | $SIG{__DIE__} = sub { |
|
|
88 | warn "FATAL: @_\n"; |
|
|
89 | CFPlus::_exit 99; |
|
|
90 | }; |
|
|
91 | |
|
|
92 | open STDERR, ">&STDOUT"; |
|
|
93 | binmode STDOUT, ":utf8"; |
|
|
94 | binmode STDERR, ":utf8"; |
|
|
95 | close $fh; |
|
|
96 | |
|
|
97 | $| = 1; |
|
|
98 | print "preparing editor startup...\n"; |
86 | print "preparing editor startup...\n"; |
99 | CFPlus::set_proxy; |
87 | CFPlus::set_proxy; |
100 | |
88 | |
101 | my $server = $editsup->{gameserver} || "default"; |
89 | my $server = $editsup->{gameserver} || "default"; |
102 | $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
90 | $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
… | |
… | |
124 | } |
112 | } |
125 | |
113 | |
126 | if (1) { # upload a map |
114 | if (1) { # upload a map |
127 | my $mapname = $::CONN->{map_info}[0]; |
115 | my $mapname = $::CONN->{map_info}[0]; |
128 | |
116 | |
|
|
117 | my $mappath = "$mapdir/$mapname"; |
|
|
118 | |
|
|
119 | -e $mappath and die "$mappath already exists\n"; |
|
|
120 | |
129 | print "getting map revision for $mapname...\n"; |
121 | print "getting map revision for $mapname...\n"; |
130 | |
122 | |
131 | # try to get the most recent head revision, what a hack, |
123 | # try to get the most recent head revision, what a hack, |
132 | # this should have been returned while downloading *sigh* |
124 | # this should have been returned while downloading *sigh* |
133 | my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; |
125 | my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; |
… | |
… | |
144 | path => $mapname, |
136 | path => $mapname, |
145 | revision => $rev, |
137 | revision => $rev, |
146 | cf_login => $::PROFILE->{user}, |
138 | cf_login => $::PROFILE->{user}, |
147 | }; |
139 | }; |
148 | |
140 | |
149 | my $mappath = "$mapdir/$mapname"; |
|
|
150 | |
|
|
151 | require File::Basename; |
141 | require File::Basename; |
152 | require File::Path; |
142 | require File::Path; |
153 | |
143 | |
154 | File::Path::mkpath (File::Basename::dirname ($mappath)); |
144 | File::Path::mkpath (File::Basename::dirname ($mappath)); |
155 | open my $fh, ">:raw:perlio", "$mappath.meta" |
145 | open my $fh, ">:raw:perlio", "$mappath.meta" |
156 | or die "$mappath.meta: $!"; |
146 | or die "$mappath.meta: $!\n"; |
157 | print $fh CFPlus::to_json $meta; |
147 | print $fh CFPlus::to_json $meta; |
158 | close $fh; |
148 | close $fh; |
159 | open my $fh, ">:raw:perlio:utf8", $mappath |
149 | open my $fh, ">:raw:perlio:utf8", $mappath |
160 | or die "$mappath: $!"; |
150 | or die "$mappath: $!\n"; |
161 | print $fh $map; |
151 | print $fh $map; |
162 | close $fh; |
152 | close $fh; |
163 | |
153 | |
164 | print "saved as $mappath\n"; |
154 | print "saved as $mappath\n"; |
165 | |
155 | |
… | |
… | |
193 | # } |
183 | # } |
194 | } else { |
184 | } else { |
195 | die "viewvc parse error, unable to detect revision\n"; |
185 | die "viewvc parse error, unable to detect revision\n"; |
196 | } |
186 | } |
197 | } |
187 | } |
198 | |
|
|
199 | CFPlus::_exit; |
|
|
200 | } |
|
|
201 | |
|
|
202 | my $buffer; |
|
|
203 | |
|
|
204 | Event->io (fd => $fh, poll => 'r', cb => sub { |
|
|
205 | unless (sysread $fh, $buffer, 4096, length $buffer) { |
|
|
206 | $_[0]->w->cancel; |
|
|
207 | $buffer .= "done\n"; |
|
|
208 | } |
|
|
209 | |
|
|
210 | while ($buffer =~ s/^(.*)\n//) { |
|
|
211 | ::message ({ |
|
|
212 | markup => "editor($pid): " . CFPlus::asxml $1, |
|
|
213 | }); |
|
|
214 | } |
|
|
215 | }); |
188 | } |
216 | } |
189 | } |
217 | |
190 | |
218 | sub invoke_button_down { |
191 | sub invoke_button_down { |
219 | my ($self, $ev, $x, $y) = @_; |
192 | my ($self, $ev, $x, $y) = @_; |
220 | |
193 | |