ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.84 by root, Sun Oct 1 18:17:38 2006 UTC vs.
Revision 1.86 by root, Sun Oct 8 21:54:20 2006 UTC

59 59
60 $self->{completer}->hide 60 $self->{completer}->hide
61 if $self->{completer}; 61 if $self->{completer};
62} 62}
63 63
64sub test_server_login { 64sub server_login {
65 return unless 65 my ($server) = @_;
66 $::CONN && length $::CONN->{test_server};
67 66
68 my $server = $::CONN->{test_server};
69 ::stop_game (); 67 ::stop_game ();
70 local $::PROFILE->{host} = $server; 68 local $::PROFILE->{host} = $server;
71 ::start_game (); 69 ::start_game ();
72} 70}
73 71
72sub check_lwp($) {
73 my ($res) = @_;
74
75 $res->is_error
76 and die $res->status_line;
77
78 $res
79}
80
74sub editor_invoke { 81sub editor_invoke {
75 return unless $::CONN; 82 my $editsup = $::CONN && $::CONN->{editor_support}
83 or return;
76 84
77 # putting the password into the env is somewhat tasteless 85 my ($pid, $fh);
78 local $ENV{CFPLUS_LOGIN} = $::PROFILE->{user}; 86 unless ($pid = open $fh, "-|:utf8", "-") {
79 local $ENV{CFPLUS_PASSWORD} = $::PROFILE->{password};
80 local $ENV{CFPLUS_UPLOAD} = $::CONN->{upload};
81 local $ENV{CROSSFIRE_MAPDIR} = $::CONN->{cvs_root};
82
83 CFPlus::set_proxy;
84
85 my $map = "map:$::CONN->{map_info}[0]";
86
87 if (fork == 0) {
88 $SIG{__DIE__} = sub { 87 $SIG{__DIE__} = sub {
89 warn "@_"; 88 warn "FATAL: @_\n";
90 CFPlus::_exit 99; 89 CFPlus::_exit 99;
91 }; 90 };
92 91
93 # TODO: move into editor 92 open STDERR, ">&STDOUT";
93 binmode STDOUT, ":utf8";
94 binmode STDERR, ":utf8";
95 close $fh;
96
97 $| = 1;
98 print "preparing editor startup...\n";
99 CFPlus::set_proxy;
100
101 my $server = $editsup->{gameserver} || "default";
102 $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
103
104 local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir;
105 local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir;
106
107 print "map directory is $mapdir\n";
108 print "lib directory is $libdir\n";
109
94 require LWP::UserAgent; 110 require LWP::UserAgent;
95 111
96 my $ua = LWP::UserAgent->new ( 112 my $ua = LWP::UserAgent->new (
97 agent => "cfplus $CFPlus::VERSION", 113 agent => "cfplus $CFPlus::VERSION",
98 keep_alive => 1, 114 keep_alive => 1,
99 env_proxy => 1, 115 env_proxy => 1,
116 timeout => 30,
100 ); 117 );
101 118
102 if ($map =~ /^map:(.*)/) { 119 for my $file (qw(archetypes crossfire.0)) {
103 my $mapname = $1; 120 my $url = "$editsup->{lib_root}$file";
121 print "mirroring $url...\n";
122 check_lwp $ua->mirror ($url, "$libdir/$file");
123 printf "%s size %d octets\n", $file, -s "$libdir/$file";
124 }
125
126 if (1) { # upload a map
127 my $mapname = $::CONN->{map_info}[0];
128
129 print "getting map revision for $mapname...\n";
130
104 # try to get the most recent head revision, what a hack 131 # try to get the most recent head revision, what a hack,
132 # this should have been returned while downloading *sigh*
105 my $log = $ua->get ("$ENV{CROSSFIRE_MAPDIR}/$mapname?view=log&logsort=rev")->decoded_content; 133 my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
106 134
107 if ($log =~ /\?rev=(\d+\.\d+)"/) { 135 if ($log =~ /\?rev=(\d+\.\d+)"/) {
108 my $rev = $1; 136 my $rev = $1;
137
138 print "downloading revision $rev...\n";
139
109 my $map = $ua->get ("$ENV{CROSSFIRE_MAPDIR}/$mapname?rev=$rev")->decoded_content; 140 my $map = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
110 warn "revision is $rev " .(length $map)."\n";#d# 141
142 my $meta = {
143 %$editsup,
144 path => $mapname,
145 revision => $rev,
146 cf_login => $::PROFILE->{user},
147 };
148
149 my $mappath = "$mapdir/$mapname";
150
151 require File::Basename;
152 require File::Path;
153
154 File::Path::mkpath (File::Basename::dirname ($mappath));
155 open my $fh, ">:raw:perlio", "$mappath.meta"
156 or die "$mappath.meta: $!";
157 print $fh CFPlus::to_json $meta;
158 close $fh;
159 open my $fh, ">:raw:perlio:utf8", $mappath
160 or die "$mappath: $!";
161 print $fh $map;
162 close $fh;
163
164 print "saved as $mappath\n";
165
166 print "invoking editor...\n";
167 exec "/root/s2/gce $mappath";#d#
111 168
112 # now upload it 169 # now upload it
113 my $comment = "some comment";
114
115 require HTTP::Request::Common; 170# require HTTP::Request::Common;
116 171#
117 my $res = $ua->post ( 172# my $res = $ua->post (
118 $ENV{CFPLUS_UPLOAD}, 173# $ENV{CFPLUS_UPLOAD},
119 Content_Type => 'multipart/form-data', 174# Content_Type => 'multipart/form-data',
120 Content => [ 175# Content => [
121 path => $mapname, 176# path => $mapname,
122 mapdir => $ENV{CROSSFIRE_MAPDIR}, 177# mapdir => $ENV{CROSSFIRE_MAPDIR},
123 map => $map, 178# map => $map,
124 revision => $rev, 179# revision => $rev,
125 cf_login => $ENV{CFPLUS_LOGIN}, 180# cf_login => $ENV{CFPLUS_LOGIN},
126 cf_password => $ENV{CFPLUS_PASSWORD}, 181# cf_password => $ENV{CFPLUS_PASSWORD},
127 comment => "", 182# comment => "",
128 ] 183# ]
129 ); 184# );
130 185#
131 if ($res->is_error) { 186# if ($res->is_error) {
132 # fatal condition 187# # fatal condition
133 warn $res->status_line; 188# warn $res->status_line;
134 } else { 189# } else {
135 # script replies are marked as {{..}} 190# # script replies are marked as {{..}}
136 my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g; 191# my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g;
137 warn map "$_\n", @msgs; 192# warn map "$_\n", @msgs;
138 } 193# }
139 } else { 194 } else {
140 # error, could not detect revision 195 die "viewvc parse error, unable to detect revision\n";
141 } 196 }
142 } 197 }
143 198
144 CFPlus::_exit; 199 CFPlus::_exit;
145 } 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 });
146} 216}
147 217
148sub invoke_button_down { 218sub invoke_button_down {
149 my ($self, $ev, $x, $y) = @_; 219 my ($self, $ev, $x, $y) = @_;
150 220
177 $::CFG->{map_shift_y} = $bh + $y - $oy; 247 $::CFG->{map_shift_y} = $bh + $y - $oy;
178 248
179 $self->update; 249 $self->update;
180 }; 250 };
181 } elsif ($ev->{button} == 3) { 251 } elsif ($ev->{button} == 3) {
182 (new CFPlus::UI::Menu 252 my @items = (
183 items => [
184 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], 253 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
185 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], 254 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
186 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], 255 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
187 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], 256 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
188 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], 257 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
192 $::PICKUP_ENABLE->{state} 261 $::PICKUP_ENABLE->{state}
193 ? "Disable automatic pickup" 262 ? "Disable automatic pickup"
194 : "Enable automatic pickup", 263 : "Enable automatic pickup",
195 sub { $::PICKUP_ENABLE->toggle } 264 sub { $::PICKUP_ENABLE->toggle }
196 ], 265 ],
197 $::CONN && length $::CONN->{cvs_root} 266 );
267
268 if ($::CONN && $::CONN->{editor_support}) {
269 push @items, [
198 ? ["Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>", 270 "Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>",
199 \&editor_invoke] 271 \&editor_invoke,
200 : (), 272 ];
201 $::CONN && length $::CONN->{test_server} 273
274 for my $type (qw(test name)) {
275 $::CONN->{editor_support}{type} ne $type
276 or next;
277 my $server = $::CONN->{editor_support}{"${type}server"}
278 or next;
279
280 push @items, [
202 ? ["Login on Test Server <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{test_server}) . ")</span>", 281 "Login on $type server <span size='xx-small'>(" . (CFPlus::asxml $server) . ")</span>",
203 \&test_server_login] 282 sub { server_login $server },
204 : (), 283 ];
284 }
285 }
286
287 push @items,
205 ["Quit", 288 ["Quit",
206 sub { 289 sub {
207 if ($::CONN) { 290 if ($::CONN) {
208 &::open_quit_dialog; 291 &::open_quit_dialog;
209 } else { 292 } else {
210 exit; 293 exit;
211 }
212 } 294 }
213 ], 295 }
214 ], 296 ],
297 ;
298
299 (new CFPlus::UI::Menu
300 items => \@items,
215 )->popup ($ev); 301 )->popup ($ev);
216 } 302 }
217 303
218 1 304 1
219} 305}
836 922
837 $self->SUPER::_draw; 923 $self->SUPER::_draw;
838} 924}
839 925
8401 9261
927

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines