… | |
… | |
57 | |
57 | |
58 | %{$self->{completer}{command}} = (); |
58 | %{$self->{completer}{command}} = (); |
59 | |
59 | |
60 | $self->{completer}->hide |
60 | $self->{completer}->hide |
61 | if $self->{completer}; |
61 | if $self->{completer}; |
|
|
62 | } |
|
|
63 | |
|
|
64 | sub test_server_login { |
|
|
65 | return unless |
|
|
66 | $::CONN && length $::CONN->{test_server}; |
|
|
67 | |
|
|
68 | my $server = $::CONN->{test_server}; |
|
|
69 | ::stop_game (); |
|
|
70 | local $::PROFILE->{host} = $server; |
|
|
71 | ::start_game (); |
|
|
72 | } |
|
|
73 | |
|
|
74 | sub editor_invoke { |
|
|
75 | return unless $::CONN; |
|
|
76 | |
|
|
77 | # putting the password into the env is somewhat tasteless |
|
|
78 | local $ENV{CFPLUS_LOGIN} = $::PROFILE->{user}; |
|
|
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 { |
|
|
89 | warn "@_"; |
|
|
90 | CFPlus::_exit 99; |
|
|
91 | }; |
|
|
92 | |
|
|
93 | # TODO: move into editor |
|
|
94 | require LWP::UserAgent; |
|
|
95 | |
|
|
96 | my $ua = LWP::UserAgent->new ( |
|
|
97 | agent => "cfplus $CFPlus::VERSION", |
|
|
98 | keep_alive => 1, |
|
|
99 | env_proxy => 1, |
|
|
100 | ); |
|
|
101 | |
|
|
102 | if ($map =~ /^map:(.*)/) { |
|
|
103 | my $mapname = $1; |
|
|
104 | # try to get the most recent head revision, what a hack |
|
|
105 | my $log = $ua->get ("$ENV{CROSSFIRE_MAPDIR}/$mapname?view=log&logsort=rev")->decoded_content; |
|
|
106 | |
|
|
107 | if ($log =~ /\?rev=(\d+\.\d+)"/) { |
|
|
108 | my $rev = $1; |
|
|
109 | my $map = $ua->get ("$ENV{CROSSFIRE_MAPDIR}/$mapname?rev=$rev")->decoded_content; |
|
|
110 | warn "revision is $rev " .(length $map)."\n";#d# |
|
|
111 | |
|
|
112 | # now upload it |
|
|
113 | my $comment = "some comment"; |
|
|
114 | |
|
|
115 | require HTTP::Request::Common; |
|
|
116 | |
|
|
117 | my $res = $ua->post ( |
|
|
118 | $ENV{CFPLUS_UPLOAD}, |
|
|
119 | Content_Type => 'multipart/form-data', |
|
|
120 | Content => [ |
|
|
121 | path => $mapname, |
|
|
122 | mapdir => $ENV{CROSSFIRE_MAPDIR}, |
|
|
123 | map => $map, |
|
|
124 | revision => $rev, |
|
|
125 | cf_login => $ENV{CFPLUS_LOGIN}, |
|
|
126 | cf_password => $ENV{CFPLUS_PASSWORD}, |
|
|
127 | comment => "", |
|
|
128 | ] |
|
|
129 | ); |
|
|
130 | |
|
|
131 | if ($res->is_error) { |
|
|
132 | # fatal condition |
|
|
133 | warn $res->status_line; |
|
|
134 | } else { |
|
|
135 | # script replies are marked as {{..}} |
|
|
136 | my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g; |
|
|
137 | warn map "$_\n", @msgs; |
|
|
138 | } |
|
|
139 | } else { |
|
|
140 | # error, could not detect revision |
|
|
141 | } |
|
|
142 | } |
|
|
143 | |
|
|
144 | CFPlus::_exit; |
|
|
145 | } |
62 | } |
146 | } |
63 | |
147 | |
64 | sub invoke_button_down { |
148 | sub invoke_button_down { |
65 | my ($self, $ev, $x, $y) = @_; |
149 | my ($self, $ev, $x, $y) = @_; |
66 | |
150 | |
… | |
… | |
108 | $::PICKUP_ENABLE->{state} |
192 | $::PICKUP_ENABLE->{state} |
109 | ? "Disable automatic pickup" |
193 | ? "Disable automatic pickup" |
110 | : "Enable automatic pickup", |
194 | : "Enable automatic pickup", |
111 | sub { $::PICKUP_ENABLE->toggle } |
195 | sub { $::PICKUP_ENABLE->toggle } |
112 | ], |
196 | ], |
|
|
197 | $::CONN && length $::CONN->{cvs_root} |
|
|
198 | ? ["Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>", |
|
|
199 | \&editor_invoke] |
|
|
200 | : (), |
|
|
201 | $::CONN && length $::CONN->{test_server} |
|
|
202 | ? ["Login on Test Server <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{test_server}) . ")</span>", |
|
|
203 | \&test_server_login] |
|
|
204 | : (), |
113 | ["Quit", |
205 | ["Quit", |
114 | sub { |
206 | sub { |
115 | if ($::CONN) { |
207 | if ($::CONN) { |
116 | &::open_quit_dialog; |
208 | &::open_quit_dialog; |
117 | } else { |
209 | } else { |
… | |
… | |
205 | my ($mod, $sym, $cmds) = @_; |
297 | my ($mod, $sym, $cmds) = @_; |
206 | $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); |
298 | $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds); |
207 | }); |
299 | }); |
208 | $::BIND_EDITOR->start; |
300 | $::BIND_EDITOR->start; |
209 | $::BIND_EDITOR->show; |
301 | $::BIND_EDITOR->show; |
|
|
302 | #TODO: elmex, what was this supposed to do? it currently crashes the client. |
210 | } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) { |
303 | # } elsif ($sym == CFPlus::SDLK_INSERT && not ($mod & CFPlus::KMOD_CTRL)) { |
211 | $::BIND_EDITOR->stop; |
304 | # $::BIND_EDITOR->stop; |
212 | $::BIND_EDITOR->ask_for_bind_and_commit; |
305 | # $::BIND_EDITOR->ask_for_bind_and_commit; |
213 | $::BIND_EDITOR->hide; |
306 | # $::BIND_EDITOR->hide; |
214 | } elsif (!$::CONN) { |
307 | } elsif (!$::CONN) { |
215 | return 0; # bindings further down need a valid connection |
308 | return 0; # bindings further down need a valid connection |
216 | |
309 | |
217 | } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) { |
310 | } elsif ($sym == CFPlus::SDLK_KP5 && !$mod) { |
218 | $::CONN->user_send ("stay fire"); |
311 | $::CONN->user_send ("stay fire"); |
219 | } elsif ($uni == ord ",") { |
312 | } elsif ($uni == ord ",") { |
220 | $::CONN->user_send ("take"); |
313 | $::CONN->user_send ("take"); |
221 | } elsif ($uni == ord " ") { |
314 | } elsif ($uni == ord " ") { |
222 | $::CONN->user_send ("apply"); |
315 | $::CONN->user_send ("apply"); |
|
|
316 | } elsif ($uni == 13) { |
|
|
317 | $::CONN->user_send ("examine"); |
223 | } elsif ($uni == ord ".") { |
318 | } elsif ($uni == ord ".") { |
224 | $::CONN->user_send ($self->{completer}{last_command}) |
319 | $::CONN->user_send ($self->{completer}{last_command}) |
225 | if exists $self->{completer}{last_command}; |
320 | if exists $self->{completer}{last_command}; |
226 | } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { |
321 | } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) { |
227 | $::CONN->user_send ($_) for @$bind_cmd; |
322 | $::CONN->user_send ($_) for @$bind_cmd; |
228 | } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
323 | } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { |
229 | $::CONN->user_send ("rotateshoottype +"); |
324 | $::CONN->user_send ("rotateshoottype +"); |
230 | } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
325 | } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { |
231 | $::CONN->user_send ("rotateshoottype -"); |
326 | $::CONN->user_send ("rotateshoottype -"); |