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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines