… | |
… | |
15 | use Storable; |
15 | use Storable; |
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; |
|
|
21 | use File::Basename; |
|
|
22 | use File::Path; |
|
|
23 | use HTTP::Request::Common; |
|
|
24 | use Cwd 'abs_path'; |
20 | |
25 | |
21 | 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); |
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); |
|
|
30 | |
|
|
31 | sub pseudohtml2txt { |
|
|
32 | my ($html) = @_; |
|
|
33 | |
|
|
34 | $html =~ s/<br\s*?\/?>/\n/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; |
|
|
41 | $html |
|
|
42 | } |
|
|
43 | |
|
|
44 | sub exit_paths { |
|
|
45 | my ($mappath, $map1path, $map2path) = @_; |
|
|
46 | $mappath = abs_path $mappath; |
|
|
47 | $map1path = abs_path $map1path; |
|
|
48 | $map2path = abs_path $map2path; |
|
|
49 | |
|
|
50 | if ( (substr $map1path, 0, length $mappath) eq $mappath |
|
|
51 | and (substr $map2path, 0, length $mappath) eq $mappath) { |
|
|
52 | substr $map1path, 0, length $mappath, ''; |
|
|
53 | substr $map2path, 0, length $mappath, ''; |
|
|
54 | |
|
|
55 | my ($v1, $d1, $f1) = File::Spec->splitpath ($map1path); |
|
|
56 | my ($v2, $d2, $f2) = File::Spec->splitpath ($map2path); |
|
|
57 | |
|
|
58 | my @di1 = File::Spec->splitdir ($d1); |
|
|
59 | my @di2 = File::Spec->splitdir ($d2); |
|
|
60 | |
|
|
61 | if ((defined $di1[1]) and (defined $di2[1]) and $di1[1] eq $di2[1]) { |
|
|
62 | my $m1 = File::Spec->abs2rel ($map1path, File::Spec->catdir (@di2)); |
|
|
63 | my $m2 = File::Spec->abs2rel ($map2path, File::Spec->catdir (@di1)); |
|
|
64 | return ($m1, $m2); |
|
|
65 | } else { |
|
|
66 | return ($map1path, $map2path); |
|
|
67 | } |
|
|
68 | } else { |
|
|
69 | return ('', ''); |
|
|
70 | } |
|
|
71 | } |
|
|
72 | |
|
|
73 | sub map2abs { |
|
|
74 | my ($dest, $mape) = @_; |
|
|
75 | |
|
|
76 | $mappath = abs_path $mappath; |
|
|
77 | my $dir; |
|
|
78 | if (File::Spec->file_name_is_absolute($dest)) { |
|
|
79 | $dir = catdir ($::MAPDIR, $dest); |
|
|
80 | } else { |
|
|
81 | my ($v, $p, $f) = File::Spec->splitpath ($mape->{path}); |
|
|
82 | $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p)); |
|
|
83 | } |
|
|
84 | return $dir; |
|
|
85 | } |
22 | |
86 | |
23 | sub def($$) { |
87 | sub def($$) { |
24 | return defined ($_[0]) ? $_[0] : $_[1]; |
88 | return defined ($_[0]) ? $_[0] : $_[1]; |
25 | } |
89 | } |
26 | |
90 | |
… | |
… | |
86 | |
150 | |
87 | return 'between'; |
151 | return 'between'; |
88 | } |
152 | } |
89 | } |
153 | } |
90 | |
154 | |
|
|
155 | sub arch_is_exit { |
|
|
156 | my ($a) = @_; |
|
|
157 | my $type = $Crossfire::ARCH{$a->{_name}}->{type}; |
|
|
158 | return $type eq '66' || $type eq '41'; |
|
|
159 | } |
|
|
160 | |
91 | sub arch_is_floor { |
161 | sub arch_is_floor { |
92 | my ($a) = @_; |
162 | my ($a) = @_; |
93 | return $Crossfire::ARCH{$a->{_name}}->{is_floor}; |
163 | my $ar = Crossfire::arch_attr $a; |
|
|
164 | return ( |
|
|
165 | (substr $ar->{name}, 0, 5) eq '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; |
94 | } |
191 | } |
95 | |
192 | |
96 | sub arch_is_wall { |
193 | sub arch_is_wall { |
97 | my ($a) = @_; |
194 | my ($a) = @_; |
|
|
195 | my $ar = Crossfire::arch_attr $a; |
|
|
196 | return $ar->{name} eq 'Wall'; |
98 | return $Crossfire::ARCH{$a->{_name}}->{no_pass}; |
197 | #return $Crossfire::ARCH{$a->{_name}}->{no_pass}; |
99 | } |
198 | } |
100 | |
199 | |
101 | sub arch_is_monster { |
200 | sub arch_is_monster { |
102 | my ($a) = @_; |
201 | my ($a) = @_; |
103 | my $arch = $Crossfire::ARCH{$a->{_name}}; |
202 | my $arch = $Crossfire::ARCH{$a->{_name}}; |
… | |
… | |
255 | } |
354 | } |
256 | |
355 | |
257 | return \@outstack; |
356 | return \@outstack; |
258 | } |
357 | } |
259 | |
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 | |
260 | =head1 AUTHOR |
387 | =head1 AUTHOR |
261 | |
388 | |
262 | Marc Lehmann <schmorp@schmorp.de> |
389 | Marc Lehmann <schmorp@schmorp.de> |
263 | http://home.schmorp.de/ |
390 | http://home.schmorp.de/ |
264 | |
391 | |