ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/gde/GCE/Util.pm
(Generate patch)

Comparing deliantra/gde/GCE/Util.pm (file contents):
Revision 1.15 by elmex, Sun Apr 2 17:57:37 2006 UTC vs.
Revision 1.22 by elmex, Tue Nov 28 16:26:22 2006 UTC

16use List::Util qw(min max); 16use List::Util qw(min max);
17 17
18use Crossfire; 18use Crossfire;
19use Crossfire::MapWidget; 19use Crossfire::MapWidget;
20use File::Spec::Functions; 20use File::Spec::Functions;
21use File::Basename;
22use File::Path;
23use HTTP::Request::Common;
21use Cwd 'abs_path'; 24use Cwd 'abs_path';
22 25
23our @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); 26our @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
25sub pseudohtml2txt { 31sub 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;
30 $html =~ s/<\/?\s*li>//gi; 37 $html =~ s/<\/?\s*li>//gi;
31 $html =~ s/<\/?\s*ul>//gi; 38 $html =~ s/<\/?\s*ul>//gi;
32 $html =~ s/&gt;/>/g; 39 $html =~ s/&gt;/>/g;
33 $html =~ s/&lt;/</g; 40 $html =~ s/&lt;/</g;
34 $html 41 $html
64} 71}
65 72
66sub map2abs { 73sub map2abs {
67 my ($dest, $mape) = @_; 74 my ($dest, $mape) = @_;
68 75
76 $mappath = abs_path $mappath;
69 my $dir; 77 my $dir;
70 if (File::Spec->file_name_is_absolute($dest)) { 78 if (File::Spec->file_name_is_absolute($dest)) {
71 $dir = catdir ($::CFG->{MAPDIR}, $dest); 79 $dir = catdir ($::MAPDIR, $dest);
72 } else { 80 } else {
73 my ($v, $p, $f) = File::Spec->splitpath ($mape->{path}); 81 my ($v, $p, $f) = File::Spec->splitpath ($mape->{path});
74 $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p)); 82 $dir = File::Spec->rel2abs ($dest, File::Spec->catpath ($v, $p));
75 } 83 }
76 return $dir; 84 return $dir;
151} 159}
152 160
153sub arch_is_floor { 161sub arch_is_floor {
154 my ($a) = @_; 162 my ($a) = @_;
155 my $ar = Crossfire::arch_attr $a; 163 my $ar = Crossfire::arch_attr $a;
164 return (
156 return (substr $ar->{name}, 0, 5) eq 'Floor'; 165 (substr $ar->{name}, 0, 5) eq 'Floor'
157#return $Crossfire::ARCH{$a->{_name}}->{is_floor}; 166 or (substr $ar->{name}, 0, 10) eq 'Shop Floor'
167 )
168}
169
170sub 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;
158} 191}
159 192
160sub arch_is_wall { 193sub arch_is_wall {
161 my ($a) = @_; 194 my ($a) = @_;
162 my $ar = Crossfire::arch_attr $a; 195 my $ar = Crossfire::arch_attr $a;
321 } 354 }
322 355
323 return \@outstack; 356 return \@outstack;
324} 357}
325 358
359sub upload {
360 my ($login, $password, $srcrep, $path, $rev, $mapdata) = @_;
361 require LWP::UserAgent;
362 my $ua = LWP::UserAgent->new (
363 agent => "gcrossedit",
364 keep_alive => 1,
365 env_proxy => 1,
366 timeout => 30,
367 );
368 require HTTP::Request::Common;
369
370 my $res = $ua->post (
371 $ENV{CFPLUS_UPLOAD},
372 Content_Type => 'multipart/form-data',
373 Content => [
374 path => $path,
375 mapdir => $srcrep,
376 map => $mapdata,
377 revision => $rev,
378 cf_login => $login, #ENV{CFPLUS_LOGIN},
379 cf_password => $password, #ENV{CFPLUS_PASSWORD},
380 comment => "",
381 ]
382 );
383
384 if ($res->is_error) {
385 # fatal condition
386 warn $res->status_line;
387 } else {
388 # script replies are marked as {{..}}
389 my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g;
390 warn map "$_\n", @msgs;
391 }
392}
393
326=head1 AUTHOR 394=head1 AUTHOR
327 395
328 Marc Lehmann <schmorp@schmorp.de> 396 Marc Lehmann <schmorp@schmorp.de>
329 http://home.schmorp.de/ 397 http://home.schmorp.de/
330 398

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines