… | |
… | |
16 | use List::Util qw(min max); |
16 | use List::Util qw(min max); |
17 | |
17 | |
18 | use Crossfire; |
18 | use Crossfire; |
19 | use Crossfire::MapWidget; |
19 | use Crossfire::MapWidget; |
20 | use File::Spec::Functions; |
20 | use File::Spec::Functions; |
|
|
21 | use File::Basename; |
|
|
22 | use File::Path; |
|
|
23 | use HTTP::Request::Common; |
21 | use Cwd 'abs_path'; |
24 | use Cwd 'abs_path'; |
22 | |
25 | |
23 | our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer new_arch_pb fill_pb_from_arch arch_is_floor stack_find_floor stack_find_wall stack_find arch_is_wall arch_is_monster add_table_widget quick_msg def arch_is_exit map2abs exit_paths pseudohtml2txt); |
26 | our @EXPORT = qw(insert_arch_stack_layer replace_arch_stack_layer new_arch_pb |
|
|
27 | fill_pb_from_arch arch_is_floor stack_find_floor stack_find_wall |
|
|
28 | stack_find arch_is_wall arch_is_monster add_table_widget quick_msg |
|
|
29 | def arch_is_exit map2abs exit_paths pseudohtml2txt arch_is_connector); |
24 | |
30 | |
25 | sub pseudohtml2txt { |
31 | sub pseudohtml2txt { |
26 | my ($html) = @_; |
32 | my ($html) = @_; |
27 | |
33 | |
28 | $html =~ s/<br\s*?\/?>/\n/gsi; |
34 | $html =~ s/<br\s*?\/?>/\n/gsi; |
29 | $html =~ s/<b>(.*?)<\/b>/_\1_/gsi; |
35 | $html =~ s/<b>(.*?)<\/b>/_\1_/gsi; |
|
|
36 | $html =~ s/<li>/\n* /gi; |
|
|
37 | $html =~ s/<\/?\s*li>//gi; |
|
|
38 | $html =~ s/<\/?\s*ul>//gi; |
|
|
39 | $html =~ s/>/>/g; |
|
|
40 | $html =~ s/</</g; |
30 | $html |
41 | $html |
31 | } |
42 | } |
32 | |
43 | |
33 | sub exit_paths { |
44 | sub exit_paths { |
34 | my ($mappath, $map1path, $map2path) = @_; |
45 | my ($mappath, $map1path, $map2path) = @_; |
… | |
… | |
60 | } |
71 | } |
61 | |
72 | |
62 | sub map2abs { |
73 | sub map2abs { |
63 | my ($dest, $mape) = @_; |
74 | my ($dest, $mape) = @_; |
64 | |
75 | |
|
|
76 | $mappath = abs_path $mappath; |
65 | my $dir; |
77 | my $dir; |
66 | if (File::Spec->file_name_is_absolute($dest)) { |
78 | if (File::Spec->file_name_is_absolute($dest)) { |
67 | $dir = catdir ($::CFG->{MAPDIR}, $dest); |
79 | $dir = catdir ($::MAPDIR, $dest); |
68 | } else { |
80 | } else { |
69 | my ($v, $p, $f) = File::Spec->splitpath ($mape->{path}); |
81 | my ($v, $p, $f) = File::Spec->splitpath ($mape->{path}); |
70 | $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p)); |
82 | $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p)); |
71 | } |
83 | } |
72 | return $dir; |
84 | return $dir; |
… | |
… | |
147 | } |
159 | } |
148 | |
160 | |
149 | sub arch_is_floor { |
161 | sub arch_is_floor { |
150 | my ($a) = @_; |
162 | my ($a) = @_; |
151 | my $ar = Crossfire::arch_attr $a; |
163 | my $ar = Crossfire::arch_attr $a; |
|
|
164 | return ( |
152 | return (substr $ar->{name}, 0, 5) eq 'Floor'; |
165 | (substr $ar->{name}, 0, 5) eq 'Floor' |
153 | #return $Crossfire::ARCH{$a->{_name}}->{is_floor}; |
166 | or (substr $ar->{name}, 0, 10) eq 'Shop Floor' |
|
|
167 | ) |
|
|
168 | } |
|
|
169 | |
|
|
170 | sub arch_is_connector { |
|
|
171 | my ($a) = @_; |
|
|
172 | my $ar = Crossfire::arch_attr $a; |
|
|
173 | my $has_connect_field = 0; |
|
|
174 | |
|
|
175 | TOP: for (@{$ar->{section}}) { |
|
|
176 | my $name = shift @$_; |
|
|
177 | my @r = @$_; |
|
|
178 | if ($name eq 'general') { |
|
|
179 | for (@r) { |
|
|
180 | my ($k, $s) = ($_->[0], $_->[1]); |
|
|
181 | if ($k eq 'connected' && $s->{name} eq 'connection') { |
|
|
182 | $has_connect_field = 1; |
|
|
183 | last TOP; |
|
|
184 | } |
|
|
185 | } |
|
|
186 | last TOP; |
|
|
187 | } |
|
|
188 | } |
|
|
189 | |
|
|
190 | return $has_connect_field; |
154 | } |
191 | } |
155 | |
192 | |
156 | sub arch_is_wall { |
193 | sub arch_is_wall { |
157 | my ($a) = @_; |
194 | my ($a) = @_; |
158 | my $ar = Crossfire::arch_attr $a; |
195 | my $ar = Crossfire::arch_attr $a; |
… | |
… | |
317 | } |
354 | } |
318 | |
355 | |
319 | return \@outstack; |
356 | return \@outstack; |
320 | } |
357 | } |
321 | |
358 | |
|
|
359 | sub upload { |
|
|
360 | my ($login, $password, $path, $rev, $mapdata) = @_; |
|
|
361 | require HTTP::Request::Common; |
|
|
362 | |
|
|
363 | my $res = $ua->post ( |
|
|
364 | $ENV{CFPLUS_UPLOAD}, |
|
|
365 | Content_Type => 'multipart/form-data', |
|
|
366 | Content => [ |
|
|
367 | path => $path, |
|
|
368 | mapdir => $::MAPDIR, |
|
|
369 | map => $mapdata, |
|
|
370 | revision => $rev, |
|
|
371 | cf_login => $login, #ENV{CFPLUS_LOGIN}, |
|
|
372 | cf_password => $password, #ENV{CFPLUS_PASSWORD}, |
|
|
373 | comment => "", |
|
|
374 | ] |
|
|
375 | ); |
|
|
376 | |
|
|
377 | if ($res->is_error) { |
|
|
378 | # fatal condition |
|
|
379 | warn $res->status_line; |
|
|
380 | } else { |
|
|
381 | # script replies are marked as {{..}} |
|
|
382 | my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g; |
|
|
383 | warn map "$_\n", @msgs; |
|
|
384 | } |
|
|
385 | } |
|
|
386 | |
322 | =head1 AUTHOR |
387 | =head1 AUTHOR |
323 | |
388 | |
324 | Marc Lehmann <schmorp@schmorp.de> |
389 | Marc Lehmann <schmorp@schmorp.de> |
325 | http://home.schmorp.de/ |
390 | http://home.schmorp.de/ |
326 | |
391 | |