--- deliantra/Deliantra-Client/DC/MapWidget.pm 2006/08/13 15:14:17 1.81 +++ deliantra/Deliantra-Client/DC/MapWidget.pm 2006/10/01 18:17:38 1.84 @@ -61,6 +61,90 @@ if $self->{completer}; } +sub test_server_login { + return unless + $::CONN && length $::CONN->{test_server}; + + my $server = $::CONN->{test_server}; + ::stop_game (); + local $::PROFILE->{host} = $server; + ::start_game (); +} + +sub editor_invoke { + return unless $::CONN; + + # 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}; + + CFPlus::set_proxy; + + my $map = "map:$::CONN->{map_info}[0]"; + + if (fork == 0) { + $SIG{__DIE__} = sub { + warn "@_"; + CFPlus::_exit 99; + }; + + # TODO: move into editor + require LWP::UserAgent; + + my $ua = LWP::UserAgent->new ( + agent => "cfplus $CFPlus::VERSION", + keep_alive => 1, + env_proxy => 1, + ); + + 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; + + 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"; + + 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 + } + } + + CFPlus::_exit; + } +} + sub invoke_button_down { my ($self, $ev, $x, $y) = @_; @@ -110,6 +194,14 @@ : "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) { @@ -207,10 +299,11 @@ }); $::BIND_EDITOR->start; $::BIND_EDITOR->show; - } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) { - $::BIND_EDITOR->stop; - $::BIND_EDITOR->ask_for_bind_and_commit; - $::BIND_EDITOR->hide; +#TODO: elmex, what was this supposed to do? it currently crashes the client. +# } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) { +# $::BIND_EDITOR->stop; +# $::BIND_EDITOR->ask_for_bind_and_commit; +# $::BIND_EDITOR->hide; } elsif (!$::CONN) { return 0; # bindings further down need a valid connection @@ -220,10 +313,12 @@ $::CONN->user_send ("take"); } elsif ($uni == ord " ") { $::CONN->user_send ("apply"); + } elsif ($uni == 13) { + $::CONN->user_send ("examine"); } elsif ($uni == ord ".") { $::CONN->user_send ($self->{completer}{last_command}) if exists $self->{completer}{last_command}; - } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { + } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) { $::CONN->user_send ($_) for @$bind_cmd; } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { $::CONN->user_send ("rotateshoottype +");