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.83 by root, Sun Oct 1 14:48:51 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
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";
83# CFPlus::set_proxy; 104 CFPlus::set_proxy;
84 105
85 # TODO: move into editor 106 my $server = $editsup->{gameserver} || "default";
86 require LWP::Simple; 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 });
87} 197}
88 198
89sub invoke_button_down { 199sub invoke_button_down {
90 my ($self, $ev, $x, $y) = @_; 200 my ($self, $ev, $x, $y) = @_;
91 201
118 $::CFG->{map_shift_y} = $bh + $y - $oy; 228 $::CFG->{map_shift_y} = $bh + $y - $oy;
119 229
120 $self->update; 230 $self->update;
121 }; 231 };
122 } elsif ($ev->{button} == 3) { 232 } elsif ($ev->{button} == 3) {
123 (new CFPlus::UI::Menu 233 my @items = (
124 items => [
125 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }], 234 ["Help Browser…\tF1", sub { $::HELP_WINDOW->toggle_visibility }],
126 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }], 235 ["Statistics\tF2", sub { ::toggle_player_page ($::STATS_PAGE) }],
127 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }], 236 ["Skills\tF3", sub { ::toggle_player_page ($::SKILL_PAGE) }],
128 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }], 237 ["Spells…\tF4", sub { ::toggle_player_page ($::SPELL_PAGE) }],
129 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }], 238 ["Inventory…\tF5", sub { ::toggle_player_page ($::INVENTORY_PAGE) }],
133 $::PICKUP_ENABLE->{state} 242 $::PICKUP_ENABLE->{state}
134 ? "Disable automatic pickup" 243 ? "Disable automatic pickup"
135 : "Enable automatic pickup", 244 : "Enable automatic pickup",
136 sub { $::PICKUP_ENABLE->toggle } 245 sub { $::PICKUP_ENABLE->toggle }
137 ], 246 ],
138 $::CONN && length $::CONN->{cvs_root} 247 );
248
249 if ($::CONN && $::CONN->{editor_support}) {
250 push @items, [
139 ? ["Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>", \&editor_invoke] 251 "Edit this map <span size='xx-small'>(" . (CFPlus::asxml $::CONN->{map_info}[0]) . ")</span>",
140 : (), 252 \&editor_invoke,
141 $::CONN && length $::CONN->{test_server} 253 ];
142 ? ["Login on Test Server", \&test_server_login] 254
143 : (), 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,
144 ["Quit", 269 ["Quit",
145 sub { 270 sub {
146 if ($::CONN) { 271 if ($::CONN) {
147 &::open_quit_dialog; 272 &::open_quit_dialog;
148 } else { 273 } else {
149 exit; 274 exit;
150 }
151 } 275 }
152 ], 276 }
153 ], 277 ],
278 ;
279
280 (new CFPlus::UI::Menu
281 items => \@items,
154 )->popup ($ev); 282 )->popup ($ev);
155 } 283 }
156 284
157 1 285 1
158} 286}
775 903
776 $self->SUPER::_draw; 904 $self->SUPER::_draw;
777} 905}
778 906
7791 9071
908

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines