--- deliantra/Deliantra-Client/DC/MapWidget.pm 2006/10/01 18:17:38 1.84
+++ deliantra/Deliantra-Client/DC/MapWidget.pm 2006/10/08 21:57:54 1.87
@@ -61,88 +61,162 @@
if $self->{completer};
}
-sub test_server_login {
- return unless
- $::CONN && length $::CONN->{test_server};
+sub server_login {
+ my ($server) = @_;
- my $server = $::CONN->{test_server};
::stop_game ();
local $::PROFILE->{host} = $server;
::start_game ();
}
-sub editor_invoke {
- return unless $::CONN;
+sub check_lwp($) {
+ my ($res) = @_;
- # putting the password into the env is somewhat tasteless
- local $ENV{CFPLUS_LOGIN} = $::PROFILE->{user};
- local $ENV{CFPLUS_PASSWORD} = $::PROFILE->{password};
- local $ENV{CFPLUS_UPLOAD} = $::CONN->{upload};
- local $ENV{CROSSFIRE_MAPDIR} = $::CONN->{cvs_root};
+ $res->is_error
+ and die $res->status_line;
- CFPlus::set_proxy;
+ $res
+}
- my $map = "map:$::CONN->{map_info}[0]";
+sub editor_invoke {
+ my $editsup = $::CONN && $::CONN->{editor_support}
+ or return;
- if (fork == 0) {
+ my ($pid, $fh);
+ unless ($pid = open $fh, "-|:utf8", "-") {
$SIG{__DIE__} = sub {
- warn "@_";
+ my $msg = $_[0];
+ $msg =~ s/\n+/\n/;
+ warn "FATAL: $msg";
CFPlus::_exit 99;
};
- # TODO: move into editor
+ open STDERR, ">&STDOUT";
+ binmode STDOUT, ":utf8";
+ binmode STDERR, ":utf8";
+ close $fh;
+
+ $| = 1;
+ print "preparing editor startup...\n";
+ CFPlus::set_proxy;
+
+ my $server = $editsup->{gameserver} || "default";
+ $server =~ s/([^a-zA-Z0-9_\-])/sprintf "=%x=", ord $1/ge;
+
+ local $ENV{CROSSFIRE_MAPDIR} = my $mapdir = "$Crossfire::VARDIR/map.$server"; mkdir $mapdir;
+ local $ENV{CROSSFIRE_LIBDIR} = my $libdir = "$Crossfire::VARDIR/lib.$server"; mkdir $libdir;
+
+ print "map directory is $mapdir\n";
+ print "lib directory is $libdir\n";
+
require LWP::UserAgent;
my $ua = LWP::UserAgent->new (
agent => "cfplus $CFPlus::VERSION",
keep_alive => 1,
env_proxy => 1,
+ timeout => 30,
);
- if ($map =~ /^map:(.*)/) {
- my $mapname = $1;
- # try to get the most recent head revision, what a hack
- my $log = $ua->get ("$ENV{CROSSFIRE_MAPDIR}/$mapname?view=log&logsort=rev")->decoded_content;
+ for my $file (qw(archetypes crossfire.0)) {
+ my $url = "$editsup->{lib_root}$file";
+ print "mirroring $url...\n";
+ check_lwp $ua->mirror ($url, "$libdir/$file");
+ printf "%s size %d octets\n", $file, -s "$libdir/$file";
+ }
+
+ if (1) { # upload a map
+ my $mapname = $::CONN->{map_info}[0];
+
+ my $mappath = "$mapdir/$mapname";
+
+ -e $mappath and die "$mappath already exists\n";
+
+ print "getting map revision for $mapname...\n";
+
+ # try to get the most recent head revision, what a hack,
+ # this should have been returned while downloading *sigh*
+ my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
if ($log =~ /\?rev=(\d+\.\d+)"/) {
my $rev = $1;
- my $map = $ua->get ("$ENV{CROSSFIRE_MAPDIR}/$mapname?rev=$rev")->decoded_content;
- warn "revision is $rev " .(length $map)."\n";#d#
- # now upload it
- my $comment = "some comment";
+ print "downloading revision $rev...\n";
- require HTTP::Request::Common;
+ my $map = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
- my $res = $ua->post (
- $ENV{CFPLUS_UPLOAD},
- Content_Type => 'multipart/form-data',
- Content => [
- path => $mapname,
- mapdir => $ENV{CROSSFIRE_MAPDIR},
- map => $map,
- revision => $rev,
- cf_login => $ENV{CFPLUS_LOGIN},
- cf_password => $ENV{CFPLUS_PASSWORD},
- comment => "",
- ]
- );
+ my $meta = {
+ %$editsup,
+ path => $mapname,
+ revision => $rev,
+ cf_login => $::PROFILE->{user},
+ };
+
+ require File::Basename;
+ require File::Path;
+
+ File::Path::mkpath (File::Basename::dirname ($mappath));
+ open my $fh, ">:raw:perlio", "$mappath.meta"
+ or die "$mappath.meta: $!\n";
+ print $fh CFPlus::to_json $meta;
+ close $fh;
+ open my $fh, ">:raw:perlio:utf8", $mappath
+ or die "$mappath: $!\n";
+ print $fh $map;
+ close $fh;
- if ($res->is_error) {
- # fatal condition
- warn $res->status_line;
- } else {
- # script replies are marked as {{..}}
- my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g;
- warn map "$_\n", @msgs;
- }
+ print "saved as $mappath\n";
+
+ print "invoking editor...\n";
+ exec "/root/s2/gce $mappath";#d#
+
+ # now upload it
+# require HTTP::Request::Common;
+#
+# my $res = $ua->post (
+# $ENV{CFPLUS_UPLOAD},
+# Content_Type => 'multipart/form-data',
+# Content => [
+# path => $mapname,
+# mapdir => $ENV{CROSSFIRE_MAPDIR},
+# map => $map,
+# revision => $rev,
+# cf_login => $ENV{CFPLUS_LOGIN},
+# cf_password => $ENV{CFPLUS_PASSWORD},
+# comment => "",
+# ]
+# );
+#
+# if ($res->is_error) {
+# # fatal condition
+# warn $res->status_line;
+# } else {
+# # script replies are marked as {{..}}
+# my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g;
+# warn map "$_\n", @msgs;
+# }
} else {
- # error, could not detect revision
+ die "viewvc parse error, unable to detect revision\n";
}
}
CFPlus::_exit;
}
+
+ my $buffer;
+
+ Event->io (fd => $fh, poll => 'r', cb => sub {
+ unless (sysread $fh, $buffer, 4096, length $buffer) {
+ $_[0]->w->cancel;
+ $buffer .= "done\n";
+ }
+
+ while ($buffer =~ s/^(.*)\n//) {
+ ::message ({
+ markup => "editor($pid): " . CFPlus::asxml $1,
+ });
+ }
+ });
}
sub invoke_button_down {
@@ -179,8 +253,7 @@
$self->update;
};
} elsif ($ev->{button} == 3) {
- (new CFPlus::UI::Menu
- items => [
+ my @items = (
["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
@@ -194,24 +267,41 @@
: "Enable automatic pickup",
sub { $::PICKUP_ENABLE->toggle }
],
- $::CONN && length $::CONN->{cvs_root}
- ? ["Edit this map (" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")",
- \&editor_invoke]
- : (),
- $::CONN && length $::CONN->{test_server}
- ? ["Login on Test Server (" . (CFPlus::asxml $::CONN->{test_server}) . ")",
- \&test_server_login]
- : (),
- ["Quit",
- sub {
- if ($::CONN) {
- &::open_quit_dialog;
- } else {
- exit;
- }
+ );
+
+ if ($::CONN && $::CONN->{editor_support}) {
+ push @items, [
+ "Edit this map (" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")",
+ \&editor_invoke,
+ ];
+
+ for my $type (qw(test name)) {
+ $::CONN->{editor_support}{type} ne $type
+ or next;
+ my $server = $::CONN->{editor_support}{"${type}server"}
+ or next;
+
+ push @items, [
+ "Login on $type server (" . (CFPlus::asxml $server) . ")",
+ sub { server_login $server },
+ ];
+ }
+ }
+
+ push @items,
+ ["Quit",
+ sub {
+ if ($::CONN) {
+ &::open_quit_dialog;
+ } else {
+ exit;
}
- ],
+ }
],
+ ;
+
+ (new CFPlus::UI::Menu
+ items => \@items,
)->popup ($ev);
}
@@ -838,3 +928,4 @@
}
1
+