1 |
package CFClient::Protocol; |
2 |
|
3 |
use utf8; |
4 |
use strict; |
5 |
|
6 |
use Crossfire::Protocol::Constants; |
7 |
|
8 |
use CFClient; |
9 |
use CFClient::UI; |
10 |
|
11 |
use base 'Crossfire::Protocol::Base'; |
12 |
|
13 |
sub new { |
14 |
my $class = shift; |
15 |
|
16 |
my $self = $class->SUPER::new (@_); |
17 |
|
18 |
$self->{map_widget}->clr_commands; |
19 |
|
20 |
my $cmd_help = CFClient::load_pod CFClient::find_rcfile "pod/command_help.pod", command_help => 1, sub { |
21 |
my ($pom) = @_; |
22 |
|
23 |
my @cmd_help; |
24 |
|
25 |
for my $head2 ($pom->head1->[-2]->head2) { |
26 |
$head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
27 |
or next; |
28 |
|
29 |
my $cmd = $1; |
30 |
my @args = split /\|/, $2; |
31 |
@args = (".*") unless @args; |
32 |
|
33 |
$_ = $_ eq ".*" ? "" : " $_" |
34 |
for @args; |
35 |
|
36 |
my $text = CFClient::pod_to_pango $head2->content; |
37 |
|
38 |
push @cmd_help, ["$cmd$_", $text] |
39 |
for sort { (length $a) <=> (length $b) } |
40 |
@args; |
41 |
} |
42 |
|
43 |
\@cmd_help |
44 |
}; |
45 |
|
46 |
$self->{map_widget}->add_command (@$_) |
47 |
for @$cmd_help; |
48 |
|
49 |
$self->{noface} = new_from_file CFClient::Texture |
50 |
CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; |
51 |
|
52 |
$self->{open_container} = 0; |
53 |
|
54 |
# "global" |
55 |
$self->{tilecache} = CFClient::db_table "tilecache"; |
56 |
$self->{facemap} = CFClient::db_table "facemap"; |
57 |
|
58 |
# per server |
59 |
$self->{mapcache} = CFClient::db_table "mapcache_$self->{host}_$self->{port}"; |
60 |
|
61 |
$self |
62 |
} |
63 |
|
64 |
sub stats_update { |
65 |
my ($self, $stats) = @_; |
66 |
|
67 |
if (my $exp = $stats->{+CS_STAT_EXP64}) { |
68 |
my $diff = $exp - $self->{prev_exp}; |
69 |
$self->{statusbox}->add ("$diff experience gained", group => "experience $diff", fg => [0.5, 1, 0.5, 0.8], timeout => 5) |
70 |
if exists $self->{prev_exp} && $diff; |
71 |
$self->{prev_exp} = $exp; |
72 |
} |
73 |
|
74 |
::update_stats_window ($stats); |
75 |
} |
76 |
|
77 |
sub user_send { |
78 |
my ($self, $command) = @_; |
79 |
|
80 |
if ($self->{record}) { |
81 |
push @{$self->{record}}, $command; |
82 |
} |
83 |
|
84 |
$self->send_command ($command); |
85 |
::status $command; |
86 |
} |
87 |
|
88 |
sub start_record { |
89 |
my ($self) = @_; |
90 |
|
91 |
$self->{record} = []; |
92 |
} |
93 |
|
94 |
sub stop_record { |
95 |
my ($self) = @_; |
96 |
return delete $self->{record}; |
97 |
} |
98 |
|
99 |
sub map_scroll { |
100 |
my ($self, $dx, $dy) = @_; |
101 |
|
102 |
$self->{map}->scroll ($dx, $dy); |
103 |
} |
104 |
|
105 |
sub feed_map1a { |
106 |
my ($self, $data) = @_; |
107 |
|
108 |
$self->{map}->map1a_update ($data); |
109 |
$self->{map_widget}->update; |
110 |
} |
111 |
|
112 |
sub flush_map { |
113 |
my ($self) = @_; |
114 |
|
115 |
my $map_info = delete $self->{map_info} |
116 |
or return; |
117 |
|
118 |
my ($hash, $x, $y, $w, $h) = @$map_info; |
119 |
|
120 |
my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
121 |
$self->{mapcache}->put ($hash => Compress::LZF::compress $data); |
122 |
#warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
123 |
} |
124 |
|
125 |
sub map_clear { |
126 |
my ($self) = @_; |
127 |
|
128 |
$self->flush_map; |
129 |
delete $self->{neigh_map}; |
130 |
|
131 |
$self->{map}->clear; |
132 |
} |
133 |
|
134 |
|
135 |
sub load_map($$$) { |
136 |
my ($self, $hash, $x, $y) = @_; |
137 |
|
138 |
if (defined (my $data = $self->{mapcache}->get ($hash))) { |
139 |
$data = Compress::LZF::decompress $data; |
140 |
#warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
141 |
for my $id ($self->{map}->set_rect ($x, $y, $data)) { |
142 |
my $data = $self->{tilecache}->get ($id) |
143 |
or next; |
144 |
|
145 |
$self->set_texture ($id => $data); |
146 |
} |
147 |
} |
148 |
} |
149 |
|
150 |
# hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
151 |
# (server resource,s latency, bandwidth), so this hack is warranted. |
152 |
# the right fix is to make real tiled maps with an overview file |
153 |
sub send_mapinfo { |
154 |
my ($self, $data, $cb) = @_; |
155 |
|
156 |
if ($self->{map_info}[0] =~ m%^/world/world_(\d\d\d)_(\d\d\d)$%) { |
157 |
my ($wx, $wy) = ($1, $2); |
158 |
|
159 |
if ($data =~ /^spatial ([1-4]+)$/) { |
160 |
my @dx = (0, 0, 1, 0, -1); |
161 |
my @dy = (0, -1, 0, 1, 0); |
162 |
my ($dx, $dy); |
163 |
|
164 |
for (split //, $1) { |
165 |
$dx += $dx[$_]; |
166 |
$dy += $dy[$_]; |
167 |
} |
168 |
|
169 |
$cb->(spatial => 15, |
170 |
$self->{map_info}[1] - $self->{map}->ox + $dx * 50, |
171 |
$self->{map_info}[2] - $self->{map}->oy + $dy * 50, |
172 |
50, 50, |
173 |
sprintf "/world/world_%03d_%03d", $wx + $dx, $wy + $dy |
174 |
); |
175 |
|
176 |
return; |
177 |
} |
178 |
} |
179 |
|
180 |
$self->SUPER::send_mapinfo ($data, $cb); |
181 |
} |
182 |
|
183 |
# this method does a "flood fill" into every tile direction |
184 |
# it assumes that tiles are arranged in a rectangular grid, |
185 |
# i.e. a map is the same as the left of the right map etc. |
186 |
# failure to comply are harmless and result in display errors |
187 |
# at worst. |
188 |
sub flood_fill { |
189 |
my ($self, $block, $gx, $gy, $path, $hash, $flags) = @_; |
190 |
|
191 |
# the server does not allow map paths > 6 |
192 |
return if 7 <= length $path; |
193 |
|
194 |
my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
195 |
|
196 |
for ( |
197 |
[1, 3, 0, -1], |
198 |
[2, 4, 1, 0], |
199 |
[3, 1, 0, 1], |
200 |
[4, 2, -1, 0], |
201 |
) { |
202 |
my ($tile, $tile2, $dx, $dy) = @$_; |
203 |
|
204 |
next if $block & (1 << $tile); |
205 |
my $block = $block | (1 << $tile2); |
206 |
|
207 |
my $gx = $gx + $dx; |
208 |
my $gy = $gy + $dy; |
209 |
|
210 |
next unless $flags & (1 << ($tile - 1)); |
211 |
next if $self->{neigh_grid}{$gx, $gy}++; |
212 |
|
213 |
my $neigh = $self->{neigh_map}{$hash} ||= []; |
214 |
if (my $info = $neigh->[$tile]) { |
215 |
my ($flags, $x, $y, $w, $h, $hash) = @$info; |
216 |
|
217 |
$self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
218 |
if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
219 |
|
220 |
} else { |
221 |
$self->send_mapinfo ("spatial $path$tile", sub { |
222 |
my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
223 |
|
224 |
return if $mode ne "spatial"; |
225 |
|
226 |
$x += $self->{map}->ox; |
227 |
$y += $self->{map}->oy; |
228 |
|
229 |
$self->load_map ($hash, $x, $y) |
230 |
unless $self->{neigh_map}{$hash}[5]++;#d# |
231 |
|
232 |
$neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
233 |
|
234 |
$self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
235 |
if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
236 |
}); |
237 |
} |
238 |
} |
239 |
} |
240 |
|
241 |
sub map_change { |
242 |
my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
243 |
|
244 |
$self->flush_map; |
245 |
|
246 |
my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
247 |
|
248 |
my $mapmapw = $self->{mapmap}->{w}; |
249 |
my $mapmaph = $self->{mapmap}->{h}; |
250 |
|
251 |
$self->{neigh_rect} = [ |
252 |
$ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
253 |
$ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
254 |
]; |
255 |
|
256 |
delete $self->{neigh_grid}; |
257 |
|
258 |
$x += $ox; |
259 |
$y += $oy; |
260 |
|
261 |
$self->{map_info} = [$hash, $x, $y, $w, $h]; |
262 |
|
263 |
(my $map = $hash) =~ s/^.*?\/([^\/]+)$/\1/; |
264 |
$::STATWIDS->{map}->set_text ("Map: " . $map); |
265 |
|
266 |
$self->load_map ($hash, $x, $y); |
267 |
$self->flood_fill (0, 0, 0, "", $hash, $flags); |
268 |
} |
269 |
|
270 |
sub face_find { |
271 |
my ($self, $facenum, $face) = @_; |
272 |
|
273 |
my $hash = "$face->{chksum},$face->{name}"; |
274 |
|
275 |
my $id = $self->{facemap}->get ($hash); |
276 |
|
277 |
unless ($id) { |
278 |
# create new id for face |
279 |
# I love transactions |
280 |
for (1..100) { |
281 |
my $txn = $CFClient::DB_ENV->txn_begin; |
282 |
my $status = $self->{facemap}->db_get (id => $id); |
283 |
if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
284 |
$id = ($id || 16) + 1; |
285 |
if ($self->{facemap}->put (id => $id) == 0 |
286 |
&& $self->{facemap}->put ($hash => $id) == 0) { |
287 |
$txn->txn_commit; |
288 |
|
289 |
goto gotid; |
290 |
} |
291 |
} |
292 |
$txn->txn_abort; |
293 |
} |
294 |
|
295 |
CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
296 |
} |
297 |
|
298 |
gotid: |
299 |
$face->{id} = $id; |
300 |
$self->{map}->set_face ($facenum => $id); |
301 |
$self->{faceid}[$facenum] = $id;#d# |
302 |
|
303 |
my $face = $self->{tilecache}->get ($id); |
304 |
|
305 |
if ($face) { |
306 |
#$self->face_prefetch; |
307 |
$face |
308 |
} else { |
309 |
my $tex = $self->{noface}; |
310 |
$self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
311 |
undef |
312 |
}; |
313 |
} |
314 |
|
315 |
sub face_update { |
316 |
my ($self, $facenum, $face) = @_; |
317 |
|
318 |
$self->{tilecache}->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes |
319 |
|
320 |
$self->set_texture ($face->{id} => delete $face->{image}); |
321 |
} |
322 |
|
323 |
sub set_texture { |
324 |
my ($self, $id, $data) = @_; |
325 |
|
326 |
$self->{texture}[$id] ||= do { |
327 |
my $tex = |
328 |
new_from_image CFClient::Texture |
329 |
$data, minify => 1, mipmap => 1; |
330 |
|
331 |
$self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
332 |
$self->{map_widget}->update; |
333 |
|
334 |
$tex |
335 |
}; |
336 |
} |
337 |
|
338 |
sub sound_play { |
339 |
my ($self, $x, $y, $soundnum, $type) = @_; |
340 |
|
341 |
$self->{sound_play}->($x, $y, $soundnum, $type); |
342 |
} |
343 |
|
344 |
my $LAST_QUERY; # server is stupid, stupid, stupid |
345 |
|
346 |
sub query { |
347 |
my ($self, $flags, $prompt) = @_; |
348 |
|
349 |
$prompt = $LAST_QUERY unless length $prompt; |
350 |
$LAST_QUERY = $prompt; |
351 |
|
352 |
$self->{query}-> ($self, $flags, $prompt); |
353 |
} |
354 |
|
355 |
sub drawinfo { |
356 |
my ($self, $color, $text) = @_; |
357 |
|
358 |
my @color = ( |
359 |
[1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
360 |
[1.00, 1.00, 1.00], |
361 |
[0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
362 |
[1.00, 0.00, 0.00], |
363 |
[1.00, 0.54, 0.00], |
364 |
[0.11, 0.56, 1.00], |
365 |
[0.93, 0.46, 0.00], |
366 |
[0.18, 0.54, 0.34], |
367 |
[0.56, 0.73, 0.56], |
368 |
[0.80, 0.80, 0.80], |
369 |
[0.55, 0.41, 0.13], |
370 |
[0.99, 0.77, 0.26], |
371 |
[0.74, 0.65, 0.41], |
372 |
); |
373 |
|
374 |
my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; |
375 |
|
376 |
# try to create single paragraphs of multiple lines sent by the server |
377 |
$text =~ s/(?<=\S)\n(?=\w)/ /g; |
378 |
|
379 |
$text = CFClient::UI::Label::escape $text; |
380 |
$text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; |
381 |
$text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; |
382 |
|
383 |
$self->{logview}->add_paragraph ($color[$color], |
384 |
join "\n", map "$time $_", split /\n/, $text); |
385 |
|
386 |
$self->{statusbox}->add ($text, |
387 |
group => $text, |
388 |
fg => $color[$color], |
389 |
timeout => $color >= 2 ? 60 : 10, |
390 |
tooltip_font => $::FONT_FIXED, |
391 |
); |
392 |
} |
393 |
|
394 |
sub drawextinfo { |
395 |
my ($self, $color, $type, $subtype, $message) = @_; |
396 |
|
397 |
$self->drawinfo ($color, $message); |
398 |
} |
399 |
|
400 |
sub spell_add { |
401 |
my ($self, $spell) = @_; |
402 |
|
403 |
# try to create single paragraphs of multiple lines sent by the server |
404 |
$spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
405 |
$spell->{message} =~ s/\n+$//; |
406 |
$spell->{message} ||= "Server did not provide a description for this spell."; |
407 |
|
408 |
$::SETUP_SPELLS->add_spell ($spell); |
409 |
|
410 |
$self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
411 |
$self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); |
412 |
} |
413 |
|
414 |
sub spell_delete { |
415 |
my ($self, $spell) = @_; |
416 |
$::SETUP_SPELLS->remove_spell ($spell); |
417 |
} |
418 |
|
419 |
sub addme_success { |
420 |
my ($self) = @_; |
421 |
|
422 |
my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub { |
423 |
my ($pom) = @_; |
424 |
|
425 |
my %skill_help; |
426 |
|
427 |
for my $head2 ($pom->head1->[3]->head2) { |
428 |
$skill_help{$head2->title} = CFClient::pod_to_pango $head2->content; |
429 |
} |
430 |
|
431 |
\%skill_help |
432 |
}; |
433 |
|
434 |
for my $skill (values %{$self->{skill_info}}) { |
435 |
$self->{map_widget}->add_command ("ready_skill $skill", |
436 |
(CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") |
437 |
. $skill_help->{$skill}); |
438 |
$self->{map_widget}->add_command ("use_skill $skill", |
439 |
(CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") |
440 |
. $skill_help->{$skill}); |
441 |
} |
442 |
} |
443 |
|
444 |
sub eof { |
445 |
my ($self) = @_; |
446 |
|
447 |
$self->{map_widget}->clr_commands; |
448 |
|
449 |
::stop_game (); |
450 |
} |
451 |
|
452 |
sub image_info { |
453 |
my ($self, $numfaces) = @_; |
454 |
|
455 |
$self->{num_faces} = $numfaces; |
456 |
$self->{face_prefetch} = [1 .. $numfaces]; |
457 |
$self->face_prefetch; |
458 |
} |
459 |
|
460 |
sub face_prefetch { |
461 |
my ($self) = @_; |
462 |
|
463 |
return unless $::CFG->{face_prefetch}; |
464 |
|
465 |
if ($self->{num_faces}) { |
466 |
return if @{ $self->{send_queue} || [] }; |
467 |
my $todo = @{ $self->{face_prefetch} } |
468 |
or return; |
469 |
|
470 |
my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); |
471 |
|
472 |
$self->send ("requestinfo image_sums $face $face"); |
473 |
|
474 |
$self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", |
475 |
group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
476 |
} elsif (!exists $self->{num_faces}) { |
477 |
$self->send ("requestinfo image_info"); |
478 |
|
479 |
$self->{num_faces} = 0; |
480 |
|
481 |
$self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", |
482 |
group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]); |
483 |
} |
484 |
} |
485 |
|
486 |
sub update_floorbox { |
487 |
$CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { |
488 |
return unless $::CONN; |
489 |
|
490 |
$::FLOORBOX->clear; |
491 |
|
492 |
my $row; |
493 |
for (@{ $::CONN->{container}{0} }) { |
494 |
if ($row < 6) { |
495 |
local $_->{face_widget}; # hack to force recreation of widget |
496 |
local $_->{desc_widget}; # hack to force recreation of widget |
497 |
CFClient::Item::update_widgets $_; |
498 |
|
499 |
$::FLOORBOX->add (0, $row, $_->{face_widget}); |
500 |
$::FLOORBOX->add (1, $row, $_->{desc_widget}); |
501 |
|
502 |
$row++; |
503 |
} else { |
504 |
$::FLOORBOX->add (1, $row, new CFClient::UI::Button |
505 |
text => "More...", |
506 |
on_activate => sub { $::INV_WINDOW->toggle_visibility }, |
507 |
); |
508 |
last; |
509 |
} |
510 |
} |
511 |
}); |
512 |
|
513 |
$::WANT_REFRESH++; |
514 |
} |
515 |
|
516 |
sub set_opencont { |
517 |
my ($conn, $tag, $name) = @_; |
518 |
$conn->{open_container} = $tag; |
519 |
|
520 |
$::INV_RIGHT_HB->clear (); |
521 |
$::INV_RIGHT_HB->add (new CFClient::UI::Label align => 0, expand => 1, text => $name); |
522 |
|
523 |
if ($tag != 0) { # Floor isn't closable, is it? |
524 |
$::INV_RIGHT_HB->add (new CFClient::UI::Button |
525 |
text => "Close container", |
526 |
tooltip => "Close the currently open container (if one is open)", |
527 |
on_activate => sub { |
528 |
$::CONN->send ("apply $tag") # $::CONN->{open_container}") |
529 |
if $tag != 0; |
530 |
#if $CONN->{open_container} != 0; |
531 |
}, |
532 |
); |
533 |
} |
534 |
|
535 |
$::INVR->set_items ($conn->{container}{$tag}); |
536 |
} |
537 |
|
538 |
sub update_container { |
539 |
my ($tag) = @_; |
540 |
|
541 |
$::INVR->set_items ($::CONN->{container}{$::CONN->{open_container}}) |
542 |
if $tag == $::CONN->{open_container}; |
543 |
} |
544 |
|
545 |
sub container_add { |
546 |
my ($self, $tag, $items) = @_; |
547 |
|
548 |
#d# print "container_add: container $tag ($self->{player}{tag})\n"; |
549 |
|
550 |
if ($tag == 0) { |
551 |
update_floorbox; |
552 |
update_container (0); |
553 |
} elsif ($tag == $self->{player}{tag}) { |
554 |
$::INV->set_items ($self->{container}{$self->{player}{tag}}) |
555 |
} else { |
556 |
update_container ($tag); |
557 |
} |
558 |
|
559 |
# $self-<{player}{tag} => player inv |
560 |
#use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
561 |
} |
562 |
|
563 |
sub container_clear { |
564 |
my ($self, $tag) = @_; |
565 |
|
566 |
#d# print "container_clear: container $tag ($self->{player}{tag})\n"; |
567 |
|
568 |
if ($tag == 0) { |
569 |
update_floorbox; |
570 |
update_container (0); |
571 |
} elsif ($tag == $self->{player}{tag}) { |
572 |
$::INV->set_items ($self->{container}{$tag}) |
573 |
} else { |
574 |
update_container ($tag); |
575 |
} |
576 |
|
577 |
# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
578 |
} |
579 |
|
580 |
sub item_delete { |
581 |
my ($self, @items) = @_; |
582 |
|
583 |
for (@items) { |
584 |
#d# print "item_delete: $_->{tag} from $_->{container} ($self->{player}{tag})\n"; |
585 |
|
586 |
if ($_->{container} == 0) { |
587 |
update_floorbox; |
588 |
update_container ($_->{tag}); |
589 |
} elsif ($_->{container} == $self->{player}{tag}) { |
590 |
$::INV->set_items ($self->{container}{$self->{player}{tag}}) |
591 |
} else { |
592 |
update_container ($_->{container}); |
593 |
} |
594 |
} |
595 |
} |
596 |
|
597 |
sub item_update { |
598 |
my ($self, $item) = @_; |
599 |
|
600 |
#d# print "item_update: $item->{tag} in $item->{container} ($self->{player}{tag}) ($::CONN->{open_container})\n"; |
601 |
|
602 |
if ($item->{tag} == $self->{player}{tag}) { |
603 |
$::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $item->{weight} / 1000); |
604 |
return; |
605 |
} |
606 |
|
607 |
CFClient::Item::update_widgets $item; |
608 |
|
609 |
if ($item->{tag} == $::CONN->{open_container} && not ($item->{flags} & F_OPEN)) { |
610 |
set_opencont ($::CONN, 0, "Floor"); |
611 |
|
612 |
} elsif ($item->{flags} & F_OPEN) { |
613 |
set_opencont ($::CONN, $item->{tag}, CFClient::Item::desc_string $item); |
614 |
} else { |
615 |
if ($item->{container} == 0) { |
616 |
update_floorbox; |
617 |
update_container (0); |
618 |
} elsif ($item->{container} == $self->{player}{tag}) { |
619 |
$::INV->set_items ($self->{container}{$item->{container}}) |
620 |
} |
621 |
} |
622 |
} |
623 |
|
624 |
sub player_update { |
625 |
my ($self, $player) = @_; |
626 |
|
627 |
$::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); |
628 |
} |
629 |
|
630 |
sub logged_in { |
631 |
my ($self) = @_; |
632 |
|
633 |
$self->send_ext_req (cfplus => "version", "1", sub { |
634 |
$self->{cfplus_ext} = $_[0]; |
635 |
}); |
636 |
|
637 |
$self->send_command ("output-sync $::CFG->{output_sync}"); |
638 |
$self->send_command ("output-count $::CFG->{output_count}"); |
639 |
$self->send_command ("pickup $::CFG->{pickup}"); |
640 |
|
641 |
my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
642 |
|
643 |
$::SERVER_INFO->set_markup ( |
644 |
"server name:port <tt>$self->{host}:$self->{port}</tt>\n" |
645 |
. "protocol version <tt>$self->{version}</tt>\n" |
646 |
. "mapinfo support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
647 |
. "extcmd support $yesno[$self->{setup}{extcmd} > 0]\n" |
648 |
. "cfplus support $yesno[$self->{cfplus_ext} > 0]\n" |
649 |
); |
650 |
} |
651 |
|
652 |
1; |