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.98 by root, Fri Apr 6 19:17:25 2007 UTC vs.
Revision 1.107 by root, Sun Jun 24 03:46:46 2007 UTC

15use Crossfire::Protocol::Base 0.95; 15use Crossfire::Protocol::Base 0.95;
16 16
17use base 'Crossfire::Protocol::Base'; 17use base 'Crossfire::Protocol::Base';
18 18
19sub new { 19sub new {
20 my $class = shift; 20 my ($class, %arg) = @_;
21 21
22 my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 }); 22 my $self = $class->SUPER::new (%arg,
23 setup_req => {
24 extmap => 1,
25 excmd => 1,
26 %{$arg{setup_req} || {}},
27 },
28 );
23 29
24 $self->{map_widget}->clr_commands; 30 $self->{map_widget}->clr_commands;
25 31
26 my @cmd_help = map { 32 my @cmd_help = map {
27 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 33 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
243 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 249 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
244 $::GAUGES->{food} ->set_value ($fo, $fo_m); 250 $::GAUGES->{food} ->set_value ($fo, $fo_m);
245 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 251 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
246 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 252 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))
247 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 253 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
248 my $rng = $stats->{+CS_STAT_RANGE}; 254 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
249 $rng =~ s/^Range: //; # thank you so much dear server
250 $::GAUGES->{range} ->set_text ("Rng: " . $rng);
251 my $title = $stats->{+CS_STAT_TITLE}; 255 my $title = $stats->{+CS_STAT_TITLE};
252 $title =~ s/^Player: //; 256 $title =~ s/^Player: //;
253 $::STATWIDS->{title} ->set_text ("Title: " . $title); 257 $::STATWIDS->{title} ->set_text ("Title: " . $title);
254 258
255 $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); 259 $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR});
427} 431}
428 432
429sub load_map($$$) { 433sub load_map($$$) {
430 my ($self, $hash, $x, $y) = @_; 434 my ($self, $hash, $x, $y) = @_;
431 435
436 my $gen = $self->{map_change_gen};
437
432 CFPlus::DB::get $self->{mapcache} => $hash, sub { 438 CFPlus::DB::get $self->{mapcache} => $hash, sub {
439 return unless $gen == $self->{map_change_gen};
440
433 my ($data) = @_; 441 my ($data) = @_;
434 442
435 if (defined $data) { 443 if (defined $data) {
436 $data = Compress::LZF::decompress $data; 444 $data = Compress::LZF::decompress $data;
437 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 445 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
512 520
513 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 521 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
514 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 522 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
515 523
516 } else { 524 } else {
525 my $gen = $self->{map_change_gen};
517 $self->send_mapinfo ("spatial $path$tile", sub { 526 $self->send_mapinfo ("spatial $path$tile", sub {
527 return unless $gen == $self->{map_change_gen};
528
518 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 529 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
519 530
520 return if $mode ne "spatial"; 531 return if $mode ne "spatial";
521 532
522 $x += $self->{map}->ox; 533 $x += $self->{map}->ox;
536 547
537sub map_change { 548sub map_change {
538 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 549 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
539 550
540 $self->flush_map; 551 $self->flush_map;
552
553 ++$self->{map_change_gen};
541 554
542 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 555 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
543 556
544 my $mapmapw = $self->{mapmap}->{w}; 557 my $mapmapw = $self->{mapmap}->{w};
545 my $mapmaph = $self->{mapmap}->{h}; 558 my $mapmaph = $self->{mapmap}->{h};
585 if $changed; 598 if $changed;
586 599
587 $self->set_texture ($face->{id} => delete $face->{image}); 600 $self->set_texture ($face->{id} => delete $face->{image});
588} 601}
589 602
603sub smooth_update {
604 my ($self, $facenum, $face) = @_;
605
606 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
607}
608
590sub set_texture { 609sub set_texture {
591 my ($self, $id, $data) = @_; 610 my ($self, $id, $data) = @_;
592 611
593 $self->{texture}[$id] = my $tex = 612 $self->{texture}[$id] = my $tex =
594 new_from_image CFPlus::Texture 613 new_from_image CFPlus::Texture
613 $LAST_QUERY = $prompt; 632 $LAST_QUERY = $prompt;
614 633
615 $self->{query}-> ($self, $flags, $prompt); 634 $self->{query}-> ($self, $flags, $prompt);
616} 635}
617 636
618sub drawinfo { 637our %NAME_TO_COLOR = (
619 my ($self, $color, $text) = @_; 638 black => 0,
639 white => 1,
640 darkblue => 2,
641 red => 3,
642 orange => 4,
643 lightblue => 5,
644 darkorange => 6,
645 green => 7,
646 darkgreen => 8,
647 grey => 9,
648 brown => 10,
649 yellow => 11,
650 tan => 12,
651);
620 652
621 my @color = ( 653our @CF_COLOR = (
622 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 654 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
623 [1.00, 1.00, 1.00], 655 [1.00, 1.00, 1.00],
624 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] 656 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
625 [1.00, 0.00, 0.00], 657 [1.00, 0.00, 0.00],
626 [1.00, 0.54, 0.00], 658 [1.00, 0.54, 0.00],
627 [0.11, 0.56, 1.00], 659 [0.11, 0.56, 1.00],
628 [0.93, 0.46, 0.00], 660 [0.93, 0.46, 0.00],
629 [0.18, 0.54, 0.34], 661 [0.18, 0.54, 0.34],
630 [0.56, 0.73, 0.56], 662 [0.56, 0.73, 0.56],
631 [0.80, 0.80, 0.80], 663 [0.80, 0.80, 0.80],
632 [0.75, 0.61, 0.20], 664 [0.75, 0.61, 0.20],
633 [0.99, 0.77, 0.26], 665 [0.99, 0.77, 0.26],
634 [0.74, 0.65, 0.41], 666 [0.74, 0.65, 0.41],
635 ); 667);
636 668
637 my $fg = $color[$color % @color]; 669sub msg {
670 my ($self, $color, $type, $text, @extra) = @_;
638 671
672 # we now weed out all tags we do not support
673 $text =~ s%<(?!/?i>|/?u>|/?b>|fg |/fg>)%&lt;%g;
674 # now all entities
675 $text =~ s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
676
677 # handle some elements
678 $text =~ s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
679 $text =~ s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
680
681 if (my $cb = $self->{cb_msg}{$type}) {
682 $_->($self, $color, $type, $text, @extra) for values %$cb;
683 } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) {
684 $type =~ s/-/_/g;
685 $self->{$type} = $text;
686 } else {
639 $self->logprint ("info: ", $text); 687 $self->logprint ("msg: ", $text);
688 return if $color < 0; # negative color == ignore if not understood
640 689
690 my $fg = $CF_COLOR[$color % @CF_COLOR];
691
641 # try to create single paragraphs of multiple lines sent by the server 692 ## try to create single paragraphs of multiple lines sent by the server
693 # no longer neecssary with TRT servers
642 $text =~ s/(?<=\S)\n(?=\w)/ /g; 694 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
643 695
644 $text = CFPlus::asxml $text;
645 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
646 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
647
648 ::message ({ fg => $fg, markup => $_ }) 696 ::message ({ fg => $fg, markup => $_ })
649 for split /\n/, $text; 697 for split /\n/, $text;
650 698
651 $self->{statusbox}->add ($text, 699 $self->{statusbox}->add ($text,
652 group => $text, 700 group => $text,
653 fg => $fg, 701 fg => $fg,
654 timeout => $color >= 2 ? 180 : 10, 702 timeout => $color >= 2 ? 180 : 10,
655 tooltip_font => $::FONT_FIXED, 703 tooltip_font => $::FONT_FIXED,
656 ); 704 );
657} 705 }
658
659sub drawextinfo {
660 my ($self, $color, $type, $subtype, $message) = @_;
661
662 $self->drawinfo ($color, $message);
663} 706}
664 707
665sub spell_add { 708sub spell_add {
666 my ($self, $spell) = @_; 709 my ($self, $spell) = @_;
667 710
900 $::SERVER_INFO->set_markup ( 943 $::SERVER_INFO->set_markup (
901 "server <tt>$self->{host}:$self->{port}</tt>\n" 944 "server <tt>$self->{host}:$self->{port}</tt>\n"
902 . "protocol version <tt>$self->{version}</tt>\n" 945 . "protocol version <tt>$self->{version}</tt>\n"
903 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 946 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
904 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 947 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
948 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
905 . "editing support $yesno[!!$self->{editor_support}]\n" 949 . "editing support $yesno[!!$self->{editor_support}]\n"
906 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 950 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
951 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
907 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 952 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
908 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 953 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
909 . "map size $self->{mapw}×$self->{maph}\n" 954 . "map size $self->{mapw}×$self->{maph}\n"
910 ); 955 );
911 956

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines