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.82 by root, Fri Sep 29 00:56:06 2006 UTC vs.
Revision 1.85 by root, Sun Oct 8 21:22:30 2006 UTC

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
64sub server_login {
65 my ($server) = @_;
66
67 ::stop_game ();
68 local $::PROFILE->{host} = $server;
69 ::start_game ();
70}
71
72sub check_lwp($) {
73 my ($res) = @_;
74
75 $res->is_error
76 and die $res->status_line;
77
78 $res
79}
80
81sub editor_invoke {
82 my $editsup = $::CONN && $::CONN->{editor_support}
83 or return;
84
85 # putting the password into the env is somewhat tasteless
86# local $ENV{CFPLUS_LOGIN} = $::PROFILE->{user};
87# local $ENV{CFPLUS_PASSWORD} = $::PROFILE->{password};
88# local $ENV{CFPLUS_UPLOAD} = $::CONN->{upload};
89
90 my ($pid, $fh);
91 unless ($pid = open $fh, "-|:utf8", "-") {
92 $SIG{__DIE__} = sub {
93 warn "@_\n";
94 CFPlus::_exit 99;
95 };
96
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
115 require LWP::UserAgent;
116
117 my $ua = LWP::UserAgent->new (
118 agent => "cfplus $CFPlus::VERSION",
119 keep_alive => 1,
120 env_proxy => 1,
121 timeout => 30,
122 );
123
124 for my $file (qw(archetypes crossfire.0)) {
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
136 # try to get the most recent head revision, what a hack,
137 # this should have been returned while downloading *sigh*
138 my $log = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?view=log&logsort=rev"))->decoded_content;
139
140 if ($log =~ /\?rev=(\d+\.\d+)"/) {
141 my $rev = $1;
142
143 print "downloading revision $rev...\n";
144
145 my $map = (check_lwp $ua->get ("$editsup->{cvs_root}/$mapname?rev=$rev"))->decoded_content;
146
147 # now upload it
148# require HTTP::Request::Common;
149#
150# my $res = $ua->post (
151# $ENV{CFPLUS_UPLOAD},
152# Content_Type => 'multipart/form-data',
153# Content => [
154# path => $mapname,
155# mapdir => $ENV{CROSSFIRE_MAPDIR},
156# map => $map,
157# revision => $rev,
158# cf_login => $ENV{CFPLUS_LOGIN},
159# cf_password => $ENV{CFPLUS_PASSWORD},
160# comment => "",
161# ]
162# );
163#
164# if ($res->is_error) {
165# # fatal condition
166# warn $res->status_line;
167# } else {
168# # script replies are marked as {{..}}
169# my @msgs = $res->decoded_content =~ m/\{\{(.*?)\}\}/g;
170# warn map "$_\n", @msgs;
171# }
172 } else {
173 die "viewvc parse error, unable to detect revision\n";
174 }
175 }
176
177 print "invoking editor...\n";
178 exec "/root/s2/gce";#d#
179
180 CFPlus::_exit;
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 });
62} 197}
63 198
64sub invoke_button_down { 199sub invoke_button_down {
65 my ($self, $ev, $x, $y) = @_; 200 my ($self, $ev, $x, $y) = @_;
66 201
93 $::CFG->{map_shift_y} = $bh + $y - $oy; 228 $::CFG->{map_shift_y} = $bh + $y - $oy;
94 229
95 $self->update; 230 $self->update;
96 }; 231 };
97 } elsif ($ev->{button} == 3) { 232 } elsif ($ev->{button} == 3) {
98 (new CFPlus::UI::Menu 233 my @items = (
99 items => [
100 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], 234 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
101 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], 235 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
102 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], 236 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
103 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], 237 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
104 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], 238 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
108 $::PICKUP_ENABLE->{state} 242 $::PICKUP_ENABLE->{state}
109 ? "Disable automatic pickup" 243 ? "Disable automatic pickup"
110 : "Enable automatic pickup", 244 : "Enable automatic pickup",
111 sub { $::PICKUP_ENABLE->toggle } 245 sub { $::PICKUP_ENABLE->toggle }
112 ], 246 ],
247 );
248
249 if ($::CONN && $::CONN->{editor_support}) {
250 push @items, [
251 "Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>",
252 \&editor_invoke,
253 ];
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, [
262 "Login on $type server <span size='xx-small'>(" . (CFPlus::asxml $server) . ")</span>",
263 sub { server_login $server },
264 ];
265 }
266 }
267
268 push @items,
113 ["Quit", 269 ["Quit",
114 sub { 270 sub {
115 if ($::CONN) { 271 if ($::CONN) {
116 &::open_quit_dialog; 272 &::open_quit_dialog;
117 } else { 273 } else {
118 exit; 274 exit;
119 }
120 } 275 }
121 ], 276 }
122 ], 277 ],
278 ;
279
280 (new CFPlus::UI::Menu
281 items => \@items,
123 )->popup ($ev); 282 )->popup ($ev);
124 } 283 }
125 284
126 1 285 1
127} 286}
224 } elsif ($uni == 13) { 383 } elsif ($uni == 13) {
225 $::CONN->user_send ("examine"); 384 $::CONN->user_send ("examine");
226 } elsif ($uni == ord ".") { 385 } elsif ($uni == ord ".") {
227 $::CONN->user_send ($self->{completer}{last_command}) 386 $::CONN->user_send ($self->{completer}{last_command})
228 if exists $self->{completer}{last_command}; 387 if exists $self->{completer}{last_command};
229 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) { 388 } elsif (my $bind_cmd = $::PROFILE->{bindings}{$mod}{$sym}) {
230 $::CONN->user_send ($_) for @$bind_cmd; 389 $::CONN->user_send ($_) for @$bind_cmd;
231 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") { 390 } elsif (($sym == CFPlus::SDLK_KP_PLUS && !$mod) || $uni == ord "+") {
232 $::CONN->user_send ("rotateshoottype +"); 391 $::CONN->user_send ("rotateshoottype +");
233 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") { 392 } elsif (($sym == CFPlus::SDLK_KP_MINUS && !$mod) || $uni == ord "-") {
234 $::CONN->user_send ("rotateshoottype -"); 393 $::CONN->user_send ("rotateshoottype -");
744 903
745 $self->SUPER::_draw; 904 $self->SUPER::_draw;
746} 905}
747 906
7481 9071
908

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines