… | |
… | |
67 | ::stop_game (); |
67 | ::stop_game (); |
68 | local $::PROFILE->{host} = $server; |
68 | local $::PROFILE->{host} = $server; |
69 | ::start_game (); |
69 | ::start_game (); |
70 | } |
70 | } |
71 | |
71 | |
72 | sub check_lwp($) { |
|
|
73 | my ($res) = @_; |
|
|
74 | |
|
|
75 | $res->is_error |
|
|
76 | and die $res->status_line; |
|
|
77 | |
|
|
78 | $res |
|
|
79 | } |
|
|
80 | |
|
|
81 | sub editor_invoke { |
72 | sub editor_invoke { |
82 | my $editsup = $::CONN && $::CONN->{editor_support} |
73 | my $editsup = $::CONN && $::CONN->{editor_support} |
83 | or return; |
74 | or return; |
84 | |
75 | |
85 | CFPlus::background { |
76 | CFPlus::background { |
86 | print "preparing editor startup...\n"; |
77 | print "preparing editor startup...\n"; |
87 | CFPlus::set_proxy; |
|
|
88 | |
78 | |
89 | my $server = $editsup->{gameserver} || "default"; |
79 | my $server = $editsup->{gameserver} || "default"; |
90 | $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
80 | $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge; |
91 | |
81 | |
92 | local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir; |
82 | local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir; |
93 | local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir; |
83 | local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir; |
94 | |
84 | |
95 | print "map directory is $mapdir\n"; |
85 | print "map directory is $mapdir\n"; |
96 | print "lib directory is $libdir\n"; |
86 | print "lib directory is $libdir\n"; |
97 | |
87 | |
98 | require LWP::UserAgent; |
88 | my $ua = CFPlus::lwp_useragent; |
99 | |
|
|
100 | my $ua = LWP::UserAgent->new ( |
|
|
101 | agent => "cfplus $CFPlus::VERSION", |
|
|
102 | keep_alive => 1, |
|
|
103 | env_proxy => 1, |
|
|
104 | timeout => 30, |
|
|
105 | ); |
|
|
106 | |
89 | |
107 | for my $file (qw(archetypes crossfire.0)) { |
90 | for my $file (qw(archetypes crossfire.0)) { |
108 | my $url = "$editsup->{lib_root}$file"; |
91 | my $url = "$editsup->{lib_root}$file"; |
109 | print "mirroring $url...\n"; |
92 | print "mirroring $url...\n"; |
110 | check_lwp $ua->mirror ($url, "$libdir/$file"); |
93 | CFPlus::lwp_check $ua->mirror ($url, "$libdir/$file"); |
111 | printf "%s size %d octets\n", $file, -s "$libdir/$file"; |
94 | printf "%s size %d octets\n", $file, -s "$libdir/$file"; |
112 | } |
95 | } |
113 | |
96 | |
114 | if (1) { # upload a map |
97 | if (1) { # upload a map |
115 | my $mapname = $::CONN->{map_info}[0]; |
98 | my $mapname = $::CONN->{map_info}[0]; |
… | |
… | |
120 | |
103 | |
121 | print "getting map revision for $mapname...\n"; |
104 | print "getting map revision for $mapname...\n"; |
122 | |
105 | |
123 | # try to get the most recent head revision, what a hack, |
106 | # try to get the most recent head revision, what a hack, |
124 | # this should have been returned while downloading *sigh* |
107 | # this should have been returned while downloading *sigh* |
125 | my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; |
108 | my $log = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content; |
126 | |
109 | |
127 | if ($log =~ /\?rev=(\d+\.\d+)"/) { |
110 | if ($log =~ /\?rev=(\d+\.\d+)"/) { |
128 | my $rev = $1; |
111 | my $rev = $1; |
129 | |
112 | |
130 | print "downloading revision $rev...\n"; |
113 | print "downloading revision $rev...\n"; |
131 | |
114 | |
132 | my $map = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content; |
115 | my $map = (CFPlus::lwp_check $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content; |
133 | |
116 | |
134 | my $meta = { |
117 | my $meta = { |
135 | %$editsup, |
118 | %$editsup, |
136 | path => $mapname, |
119 | path => $mapname, |
137 | revision => $rev, |
120 | revision => $rev, |
… | |
… | |
446 | } |
429 | } |
447 | |
430 | |
448 | sub set_magicmap { |
431 | sub set_magicmap { |
449 | my ($self, $w, $h, $x, $y, $data) = @_; |
432 | my ($self, $w, $h, $x, $y, $data) = @_; |
450 | |
433 | |
451 | $x -= $::MAP->ox + int 0.5 * $::MAP->w; |
434 | $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; |
452 | $y -= $::MAP->oy + int 0.5 * $::MAP->h; |
435 | $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; |
453 | |
436 | |
454 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
437 | $self->{magicmap} = [$x, $y, $w, $h, $data]; |
455 | |
438 | |
456 | $self->update; |
439 | $self->update; |
457 | } |
440 | } |
… | |
… | |
530 | } |
513 | } |
531 | |
514 | |
532 | if ($self->{magicmap}) { |
515 | if ($self->{magicmap}) { |
533 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
516 | my ($x, $y, $w, $h, $data) = @{ $self->{magicmap} }; |
534 | |
517 | |
535 | $x += $::MAP->ox - $sx + int 0.5 * ($::MAP->w - $sw + 1); |
518 | $x += $::MAP->ox + $self->{dx}; |
536 | $y += $::MAP->oy - $sy + int 0.5 * ($::MAP->h - $sh + 1); |
519 | $y += $::MAP->oy + $self->{dy}; |
537 | |
520 | |
538 | glTranslate - $x - 1, - $y - 1; |
521 | glTranslate - $x - 1, - $y - 1; |
539 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
522 | glBindTexture GL_TEXTURE_2D, $magicmap_tex->{name}; |
540 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
523 | $::MAP->draw_magicmap ($x, $y, $w, $h, $data); |
541 | } |
524 | } |