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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines