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.83 by root, Sun Oct 1 14:48:51 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}; 87 $SIG{__DIE__} = sub {
80 local $ENV{CFPLUS_UPLOAD} = $::CONN->{upload}; 88 warn "FATAL: @_\n";
81 local $ENV{CROSSFIRE_MAPDIR} = $::CONN->{cvs_root}; 89 CFPlus::_exit 99;
90 };
82 91
92 open STDERR, ">&STDOUT";
93 binmode STDOUT, ":utf8";
94 binmode STDERR, ":utf8";
95 close $fh;
96
97 $| = 1;
98 print "preparing editor startup...\n";
83# CFPlus::set_proxy; 99 CFPlus::set_proxy;
84 100
85 # TODO: move into editor 101 my $server = $editsup->{gameserver} || "default";
86 require LWP::Simple; 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
110 require LWP::UserAgent;
111
112 my $ua = LWP::UserAgent->new (
113 agent => "cfplus $CFPlus::VERSION",
114 keep_alive => 1,
115 env_proxy => 1,
116 timeout => 30,
117 );
118
119 for my $file (qw(archetypes crossfire.0)) {
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
131 # try to get the most recent head revision, what a hack,
132 # this should have been returned while downloading *sigh*
133 my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
134
135 if ($log =~ /\?rev=(\d+\.\d+)"/) {
136 my $rev = $1;
137
138 print "downloading revision $rev...\n";
139
140 my $map = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
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#
168
169 # now upload it
170# require HTTP::Request::Common;
171#
172# my $res = $ua->post (
173# $ENV{CFPLUS_UPLOAD},
174# Content_Type => 'multipart/form-data',
175# Content => [
176# path => $mapname,
177# mapdir => $ENV{CROSSFIRE_MAPDIR},
178# map => $map,
179# revision => $rev,
180# cf_login => $ENV{CFPLUS_LOGIN},
181# cf_password => $ENV{CFPLUS_PASSWORD},
182# comment => "",
183# ]
184# );
185#
186# if ($res->is_error) {
187# # fatal condition
188# warn $res->status_line;
189# } else {
190# # script replies are marked as {{..}}
191# my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g;
192# warn map "$_\n", @msgs;
193# }
194 } else {
195 die "viewvc parse error, unable to detect revision\n";
196 }
197 }
198
199 CFPlus::_exit;
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 });
87} 216}
88 217
89sub invoke_button_down { 218sub invoke_button_down {
90 my ($self, $ev, $x, $y) = @_; 219 my ($self, $ev, $x, $y) = @_;
91 220
118 $::CFG->{map_shift_y} = $bh + $y - $oy; 247 $::CFG->{map_shift_y} = $bh + $y - $oy;
119 248
120 $self->update; 249 $self->update;
121 }; 250 };
122 } elsif ($ev->{button} == 3) { 251 } elsif ($ev->{button} == 3) {
123 (new CFPlus::UI::Menu 252 my @items = (
124 items => [
125 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], 253 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
126 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], 254 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
127 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], 255 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
128 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], 256 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
129 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], 257 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
133 $::PICKUP_ENABLE->{state} 261 $::PICKUP_ENABLE->{state}
134 ? "Disable automatic pickup" 262 ? "Disable automatic pickup"
135 : "Enable automatic pickup", 263 : "Enable automatic pickup",
136 sub { $::PICKUP_ENABLE->toggle } 264 sub { $::PICKUP_ENABLE->toggle }
137 ], 265 ],
138 $::CONN && length $::CONN->{cvs_root} 266 );
267
268 if ($::CONN && $::CONN->{editor_support}) {
269 push @items, [
139 ? ["Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>", \&editor_invoke] 270 "Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>",
140 : (), 271 \&editor_invoke,
141 $::CONN && length $::CONN->{test_server} 272 ];
142 ? ["Login on Test Server", \&test_server_login] 273
143 : (), 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, [
281 "Login on $type server <span size='xx-small'>(" . (CFPlus::asxml $server) . ")</span>",
282 sub { server_login $server },
283 ];
284 }
285 }
286
287 push @items,
144 ["Quit", 288 ["Quit",
145 sub { 289 sub {
146 if ($::CONN) { 290 if ($::CONN) {
147 &::open_quit_dialog; 291 &::open_quit_dialog;
148 } else { 292 } else {
149 exit; 293 exit;
150 }
151 } 294 }
152 ], 295 }
153 ], 296 ],
297 ;
298
299 (new CFPlus::UI::Menu
300 items => \@items,
154 )->popup ($ev); 301 )->popup ($ev);
155 } 302 }
156 303
157 1 304 1
158} 305}
775 922
776 $self->SUPER::_draw; 923 $self->SUPER::_draw;
777} 924}
778 925
7791 9261
927

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines