ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Protocol.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Protocol.pm (file contents):
Revision 1.7 by root, Sat May 27 20:46:54 2006 UTC vs.
Revision 1.30 by root, Sun Jun 11 18:41:30 2006 UTC

3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use Crossfire::Protocol::Constants; 6use Crossfire::Protocol::Constants;
7 7
8use CFClient;
8use CFClient::UI; 9use CFClient::UI;
9 10
10use base 'Crossfire::Protocol::Base'; 11use base 'Crossfire::Protocol::Base';
11 12
12sub new { 13sub new {
14 15
15 my $self = $class->SUPER::new (@_); 16 my $self = $class->SUPER::new (@_);
16 17
17 $self->{map_widget}->clr_commands; 18 $self->{map_widget}->clr_commands;
18 19
19 my $parser = new Pod::POM; 20 my $cmd_help = CFClient::load_pod CFClient::find_rcfile "pod/command_help.pod", command_help => 1, sub {
20 my $pod = $parser->parse_file (CFClient::find_rcfile "pod/command_help.pod"); 21 my ($pom) = @_;
21 22
23 my @cmd_help;
24
22 for my $head2 ($pod->head1->[-2]->head2) { 25 for my $head2 ($pom->head1->[-2]->head2) {
23 $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 26 $head2->title =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
24 or next; 27 or next;
25 28
26 my $cmd = $1; 29 my $cmd = $1;
27 my @args = split /\|/, $2; 30 my @args = split /\|/, $2;
28 @args = (".*") unless @args; 31 @args = (".*") unless @args;
29 32
30 $_ = $_ eq ".*" ? "" : " $_" 33 $_ = $_ eq ".*" ? "" : " $_"
31 for @args; 34 for @args;
32 35
33 my $text = CFClient::pod_to_pango $head2->content; 36 my $text = CFClient::pod_to_pango $head2->content;
34 37
35 $self->{map_widget}->add_command ("$cmd$_", $text) 38 push @cmd_help, ["$cmd$_", $text]
36 for sort { (length $a) <=> (length $b) } 39 for sort { (length $a) <=> (length $b) }
37 @args; 40 @args;
41 }
42
43 \@cmd_help
38 } 44 };
45
46 $self->{map_widget}->add_command (@$_)
47 for @$cmd_help;
39 48
40 $self->{noface} = new_from_file CFClient::Texture 49 $self->{noface} = new_from_file CFClient::Texture
41 CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1; 50 CFClient::find_rcfile "noface.png", minify => 1, mipmap => 1;
42 51
43 $self->{open_container} = 0; 52 $self->{open_container} = 0;
66} 75}
67 76
68sub user_send { 77sub user_send {
69 my ($self, $command) = @_; 78 my ($self, $command) = @_;
70 79
80 if ($self->{record}) {
81 push @{$self->{record}}, $command;
82 }
83
71 $self->send_command ($command); 84 $self->send_command ($command);
72 ::status $command; 85 ::status $command;
86}
87
88sub start_record {
89 my ($self) = @_;
90
91 $self->{record} = [];
92}
93
94sub stop_record {
95 my ($self) = @_;
96 return delete $self->{record};
73} 97}
74 98
75sub map_scroll { 99sub map_scroll {
76 my ($self, $dx, $dy) = @_; 100 my ($self, $dx, $dy) = @_;
77 101
253 unless ($id) { 277 unless ($id) {
254 # create new id for face 278 # create new id for face
255 # I love transactions 279 # I love transactions
256 for (1..100) { 280 for (1..100) {
257 my $txn = $CFClient::DB_ENV->txn_begin; 281 my $txn = $CFClient::DB_ENV->txn_begin;
258 my $status = $self->{facemap}->db_get (id => $id, BerkeleyDB::DB_RMW); 282 my $status = $self->{facemap}->db_get (id => $id);
259 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { 283 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
260 $id = ($id || 16) + 1; 284 $id = ($id || 16) + 1;
261 if ($self->{facemap}->put (id => $id) == 0 285 if ($self->{facemap}->put (id => $id) == 0
262 && $self->{facemap}->put ($hash => $id) == 0) { 286 && $self->{facemap}->put ($hash => $id) == 0) {
263 $txn->txn_commit; 287 $txn->txn_commit;
264 288
265 goto gotid; 289 goto gotid;
266 } 290 }
267 } 291 }
268 $txn->abort; 292 $txn->txn_abort;
269 } 293 }
270 294
271 CFClient::fatal "maximum number of transaction retries reached - database problems?"; 295 CFClient::fatal "maximum number of transaction retries reached - database problems?";
272 } 296 }
273 297
323 my ($self, $flags, $prompt) = @_; 347 my ($self, $flags, $prompt) = @_;
324 348
325 $prompt = $LAST_QUERY unless length $prompt; 349 $prompt = $LAST_QUERY unless length $prompt;
326 $LAST_QUERY = $prompt; 350 $LAST_QUERY = $prompt;
327 351
328 my $dialog = new CFClient::UI::FancyFrame 352 $self->{query}-> ($self, $flags, $prompt);
329 title => "Query",
330 child => my $vbox = new CFClient::UI::VBox;
331
332 $vbox->add (new CFClient::UI::Label
333 max_w => $::WIDTH * 0.4,
334 ellipsise => 0,
335 text => $prompt);
336
337 if ($flags & CS_QUERY_YESNO) {
338 $vbox->add (my $hbox = new CFClient::UI::HBox);
339 $hbox->add (new CFClient::UI::Button
340 text => "No",
341 on_activate => sub {
342 $self->send ("reply n");
343 $dialog->destroy;
344 $self->{map_widget}->focus_in;
345 }
346 );
347 $hbox->add (new CFClient::UI::Button
348 text => "Yes",
349 on_activate => sub {
350 $self->send ("reply y");
351 $dialog->destroy;
352 },
353 );
354
355 $dialog->focus_in;
356
357 } elsif ($flags & CS_QUERY_SINGLECHAR) {
358 $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)";
359 $vbox->add (my $entry = new CFClient::UI::Entry
360 on_changed => sub {
361 $self->send ("reply $_[1]");
362 $dialog->destroy;
363 },
364 );
365
366 $entry->focus_in;
367
368 } else {
369 $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)";
370
371 $vbox->add (my $entry = new CFClient::UI::Entry
372 $flags & CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (),
373 on_activate => sub {
374 $self->send ("reply $_[1]");
375 $dialog->destroy;
376 },
377 );
378
379 $entry->focus_in;
380 }
381
382 $dialog->show_centered;
383} 353}
384 354
385sub drawinfo { 355sub drawinfo {
386 my ($self, $color, $text) = @_; 356 my ($self, $color, $text) = @_;
387 357
401 [0.74, 0.65, 0.41], 371 [0.74, 0.65, 0.41],
402 ); 372 );
403 373
404 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0]; 374 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
405 375
376 # try to create single paragraphs of multiple lines sent by the server
377 $text =~ s/(?<=\S)\n(?=\w)/ /g;
378
406 $text = CFClient::UI::Label::escape $text; 379 $text = CFClient::UI::Label::escape $text;
407 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 380 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
408 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 381 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
409 382
410 $self->{logview}->add_paragraph ($color[$color], 383 $self->{logview}->add_paragraph ($color[$color],
411 join "\n", map "$time $_", split /\n/, $text); 384 join "\n", map "$time $_", split /\n/, $text);
412 385
413 $self->{statusbox}->add ($text, 386 $self->{statusbox}->add ($text,
414 group => $text, 387 group => $text,
415 fg => $color[$color], 388 fg => $color[$color],
416 timeout => 10, 389 timeout => $color >= 2 ? 60 : 10,
417 tooltip_font => $::FONT_FIXED, 390 tooltip_font => $::FONT_FIXED,
418 ); 391 );
419} 392}
420 393
421sub drawextinfo { 394sub drawextinfo {
425} 398}
426 399
427sub spell_add { 400sub spell_add {
428 my ($self, $spell) = @_; 401 my ($self, $spell) = @_;
429 402
430 # TODO 403 # try to create single paragraphs of multiple lines sent by the server
431 # create a widget dynamically, using spell face (CF::Protocol downloads them) 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
432 $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message}); 410 $self->{map_widget}->add_command ("invoke $spell->{name}", CFClient::UI::Label::escape $spell->{message});
433 $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message}); 411 $self->{map_widget}->add_command ("cast $spell->{name}", CFClient::UI::Label::escape $spell->{message});
434} 412}
435 413
436sub spell_delete { 414sub spell_delete {
437 my ($self, $spell) = @_; 415 my ($self, $spell) = @_;
416 $::SETUP_SPELLS->remove_spell ($spell);
438} 417}
439 418
440sub addme_success { 419sub addme_success {
441 my ($self) = @_; 420 my ($self) = @_;
442 421
443 $self->send ("command output-sync $::CFG->{output_sync}"); 422 my $skill_help = CFClient::load_pod CFClient::find_rcfile "pod/skill_help.pod", skill_help => 1, sub {
444 $self->send ("command output-count $::CFG->{output_count}"); 423 my ($pom) = @_;
445 424
446 my $parser = new Pod::POM;
447 my $pod = $parser->parse_file (CFClient::find_rcfile "pod/skill_help.pod");
448
449 my %skill_tooltip; 425 my %skill_help;
450 426
451 for my $head2 ($pod->head1->[-2]->head2) { 427 for my $head2 ($pom->head1->[3]->head2) {
452 $skill_tooltip{$head2->title} = CFClient::pod_to_pango $head2->content; 428 $skill_help{$head2->title} = CFClient::pod_to_pango $head2->content;
429 }
430
431 \%skill_help
453 } 432 };
454 433
455 for my $skill (values %{$self->{skill_info}}) { 434 for my $skill (values %{$self->{skill_info}}) {
456 $self->{map_widget}->add_command ("ready_skill $skill", 435 $self->{map_widget}->add_command ("ready_skill $skill",
457 (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n") 436 (CFClient::UI::Label::escape "Ready the skill '$skill'\n\n")
458 . $skill_tooltip{$skill}); 437 . $skill_help->{$skill});
459 $self->{map_widget}->add_command ("use_skill $skill", 438 $self->{map_widget}->add_command ("use_skill $skill",
460 (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n") 439 (CFClient::UI::Label::escape "Immediately use the skill '$skill'\n\n")
461 . $skill_tooltip{$skill}); 440 . $skill_help->{$skill});
462 } 441 }
463} 442}
464 443
465sub eof { 444sub eof {
466 my ($self) = @_; 445 my ($self) = @_;
491 my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, (); 470 my ($face) = splice @{ $self->{face_prefetch} }, + rand @{ $self->{face_prefetch} }, 1, ();
492 471
493 $self->send ("requestinfo image_sums $face $face"); 472 $self->send ("requestinfo image_sums $face $face");
494 473
495 $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo", 474 $self->{statusbox}->add (CFClient::UI::Label::escape "prefetching $todo",
496 group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); 475 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
497 } elsif (!exists $self->{num_faces}) { 476 } elsif (!exists $self->{num_faces}) {
498 $self->send ("requestinfo image_info"); 477 $self->send ("requestinfo image_info");
499 478
500 $self->{num_faces} = 0; 479 $self->{num_faces} = 0;
501 480
502 $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch", 481 $self->{statusbox}->add (CFClient::UI::Label::escape "starting to prefetch",
503 group => "prefetch", timeout => 2, fg => [1, 1, 0, 0.5]); 482 group => "prefetch", timeout => 3, fg => [1, 1, 0, 0.5]);
504 } 483 }
505} 484}
506 485
507sub update_floorbox { 486sub update_floorbox {
508 $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub { 487 $CFClient::UI::ROOT->on_refresh ($::FLOORBOX => sub {
510 489
511 $::FLOORBOX->clear; 490 $::FLOORBOX->clear;
512 491
513 my $row; 492 my $row;
514 for (@{ $::CONN->{container}{0} }) { 493 for (@{ $::CONN->{container}{0} }) {
515 if ($row < 7) { 494 if ($row < 6) {
516 local $_->{face_widget}; # hack to force recreation of widget 495 local $_->{face_widget}; # hack to force recreation of widget
517 local $_->{desc_widget}; # hack to force recreation of widget 496 local $_->{desc_widget}; # hack to force recreation of widget
518 CFClient::Item::update_widgets $_; 497 CFClient::Item::update_widgets $_;
519 498
520 $::FLOORBOX->add (0, $row, $_->{face_widget}); 499 $::FLOORBOX->add (0, $row, $_->{face_widget});
521 $::FLOORBOX->add (1, $row, $_->{desc_widget}); 500 $::FLOORBOX->add (1, $row, $_->{desc_widget});
522 501
523 $row++; 502 $row++;
524 } else { 503 } else {
525 $::FLOORBOX->add (1, $row, new CFClient::UI::Label text => "More..."); 504 $::FLOORBOX->add (1, $row, new CFClient::UI::Button
505 text => "More...",
506 on_activate => sub { $::INV_WINDOW->toggle_visibility },
507 );
526 last; 508 last;
527 } 509 }
528 } 510 }
529 }); 511 });
530 512
532} 514}
533 515
534sub set_opencont { 516sub set_opencont {
535 my ($conn, $tag, $name) = @_; 517 my ($conn, $tag, $name) = @_;
536 $conn->{open_container} = $tag; 518 $conn->{open_container} = $tag;
537 $::INVR_LBL->set_text ($name); 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
538 $::INVR->set_items ($conn->{container}{$tag}); 535 $::INVR->set_items ($conn->{container}{$tag});
539} 536}
540 537
541sub update_container { 538sub update_container {
542 my ($tag) = @_; 539 my ($tag) = @_;
571 if ($tag == 0) { 568 if ($tag == 0) {
572 update_floorbox; 569 update_floorbox;
573 update_container (0); 570 update_container (0);
574 } elsif ($tag == $self->{player}{tag}) { 571 } elsif ($tag == $self->{player}{tag}) {
575 $::INV->set_items ($self->{container}{$tag}) 572 $::INV->set_items ($self->{container}{$tag})
573 } else {
574 update_container ($tag);
576 } 575 }
577 576
578# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 577# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
579} 578}
580 579
588 update_floorbox; 587 update_floorbox;
589 update_container ($_->{tag}); 588 update_container ($_->{tag});
590 } elsif ($_->{container} == $self->{player}{tag}) { 589 } elsif ($_->{container} == $self->{player}{tag}) {
591 $::INV->set_items ($self->{container}{$self->{player}{tag}}) 590 $::INV->set_items ($self->{container}{$self->{player}{tag}})
592 } else { 591 } else {
593 update_container ($_->{tag}); 592 update_container ($_->{container});
594 } 593 }
595 } 594 }
596} 595}
597 596
598sub item_update { 597sub item_update {
622 } 621 }
623} 622}
624 623
625sub player_update { 624sub player_update {
626 my ($self, $player) = @_; 625 my ($self, $player) = @_;
626
627 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000); 627 $::STATWIDS->{weight}->set_text (sprintf "Weight: %.1fkg", $player->{weight} / 1000);
628} 628}
629 629
630sub 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 <tt>$self->{host}:$self->{port}</tt>\n"
645 . "protocol version <tt>$self->{version}</tt>\n"
646 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
647 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
648 . "cfplus support $yesno[$self->{cfplus_ext} > 0]\n"
649 . "map size $self->{mapw}×$self->{maph}\n"
650 );
651}
652
6301; 6531;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines