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.78 by elmex, Mon Aug 14 14:35:31 2006 UTC vs.
Revision 1.90 by root, Wed Dec 6 00:15:12 2006 UTC

7 7
8use CFPlus; 8use CFPlus;
9use CFPlus::UI; 9use CFPlus::UI;
10use CFPlus::Pod; 10use CFPlus::Pod;
11 11
12use Crossfire::Protocol::Base 0.95;
13
12use base 'Crossfire::Protocol::Base'; 14use base 'Crossfire::Protocol::Base';
13 15
14sub new { 16sub new {
15 my $class = shift; 17 my $class = shift;
16 18
17 my $self = $class->SUPER::new (@_); 19 my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 });
18 20
19 $self->{map_widget}->clr_commands; 21 $self->{map_widget}->clr_commands;
20 22
21 my @cmd_help = map { 23 my @cmd_help = map {
22 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 24 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
42 for @cmd_help; 44 for @cmd_help;
43 45
44 $self->{noface} = new_from_file CFPlus::Texture 46 $self->{noface} = new_from_file CFPlus::Texture
45 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; 47 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
46 48
49 {
50 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture
51 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
52 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
53 }
54
47 $self->{open_container} = 0; 55 $self->{open_container} = 0;
48 56
49 # "global" 57 # "global"
50 $self->{tilecache} = CFPlus::db_table "tilecache"; 58 $self->{tilecache} = CFPlus::db_table "tilecache"
59 or die "tilecache: unable to open database table";
51 $self->{facemap} = CFPlus::db_table "facemap"; 60 $self->{facemap} = CFPlus::db_table "facemap"
61 or die "facemap: unable to open database table";
52 62
53 # per server 63 # per server
54 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}"; 64 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}"
65 or die "mapcache_$self->{host}_$self->{port}: unable to open database table";
55 66
56 $self 67 $self
57} 68}
58 69
59sub logprint { 70sub logprint {
60 my ($self, @a) = @_; 71 my ($self, @a) = @_;
61 72
62 return;
63 $self->{log_fh} ||= do { 73 $self->{log_fh} ||= do {
64 my $path = "$Crossfire::VARDIR/log.$self->{host}"; 74 my $path = "$Crossfire::VARDIR/log.$self->{host}";
65 75
66 open my $fh, ">>:utf8", $path 76 open my $fh, ">>:utf8", $path
67 or die "Couldn't open logfile $path: $!"; 77 or die "Couldn't open logfile $path: $!";
278 if ($ev->{button} == 1) { 288 if ($ev->{button} == 1) {
279 $::CONN->user_send ("ready_skill $name"); 289 $::CONN->user_send ("ready_skill $name");
280 } elsif ($ev->{button} == 2) { 290 } elsif ($ev->{button} == 2) {
281 $::CONN->user_send ("use_skill $name"); 291 $::CONN->user_send ("use_skill $name");
282 } elsif ($ev->{button} == 3) { 292 } elsif ($ev->{button} == 3) {
293 my $shortname = CFPlus::shorten $name, 14;
283 (new CFPlus::UI::Menu 294 (new CFPlus::UI::Menu
284 items => [ 295 items => [
285 ["bind <i>ready_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], 296 ["bind <i>ready_skill $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }],
286 ["bind <i>use_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["use_skill $name"]) }], 297 ["bind <i>use_skill $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["use_skill $name"]) }],
287 ], 298 ],
288 )->popup ($ev); 299 )->popup ($ev);
289 } else { 300 } else {
290 return 0; 301 return 0;
291 } 302 }
311} 322}
312 323
313sub user_send { 324sub user_send {
314 my ($self, $command) = @_; 325 my ($self, $command) = @_;
315 326
316 if ($self->{record}) {
317 push @{$self->{record}}, $command; 327 push @{$self->{record}}, $command
318 } 328 if $self->{record};
319 329
320 $self->logprint ("send: ", $command); 330 $self->logprint ("send: ", $command);
321 $self->send_command ($command); 331 $self->send_command ($command);
322 ::status ($command); 332 ::status ($command);
323} 333}
340} 350}
341 351
342sub feed_map1a { 352sub feed_map1a {
343 my ($self, $data) = @_; 353 my ($self, $data) = @_;
344 354
345 $self->{map}->map1a_update ($data); 355 $self->{map}->map1a_update ($data, $self->{setup}{extmap});
346 $self->{map_widget}->update; 356 $self->{map_widget}->update;
347} 357}
348 358
349sub magicmap { 359sub magicmap {
350 my ($self, $w, $h, $x, $y, $data) = @_; 360 my ($self, $w, $h, $x, $y, $data) = @_;
615 [0.74, 0.65, 0.41], 625 [0.74, 0.65, 0.41],
616 ); 626 );
617 627
618 $self->logprint ("info: ", $text); 628 $self->logprint ("info: ", $text);
619 629
620 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
621
622 # try to create single paragraphs of multiple lines sent by the server 630 # try to create single paragraphs of multiple lines sent by the server
623 $text =~ s/(?<=\S)\n(?=\w)/ /g; 631 $text =~ s/(?<=\S)\n(?=\w)/ /g;
624 632
625 $text = CFPlus::asxml $text; 633 $text = CFPlus::asxml $text;
626 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 634 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
627 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 635 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
628 636
629 $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) 637 ::message ({ fg => $color[$color], markup => $_ })
630 for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; 638 for split /\n/, $text;
631 $self->{logview}->scroll_to_bottom;
632 639
633 $self->{statusbox}->add ($text, 640 $self->{statusbox}->add ($text,
634 group => $text, 641 group => $text,
635 fg => $color[$color], 642 fg => $color[$color],
636 timeout => $color >= 2 ? 180 : 10, 643 timeout => $color >= 2 ? 180 : 10,
650 # try to create single paragraphs out of the multiple lines sent by the server 657 # try to create single paragraphs out of the multiple lines sent by the server
651 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 658 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
652 $spell->{message} =~ s/\n+$//; 659 $spell->{message} =~ s/\n+$//;
653 $spell->{message} ||= "Server did not provide a description for this spell."; 660 $spell->{message} ||= "Server did not provide a description for this spell.";
654 661
655 $::SPELL_PAGE->add_spell ($spell); 662 $::SPELL_LIST->add_spell ($spell);
656 663
657 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); 664 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message});
658 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); 665 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message});
659} 666}
660 667
661sub spell_delete { 668sub spell_delete {
662 my ($self, $spell) = @_; 669 my ($self, $spell) = @_;
663 670
664 $::SPELL_PAGE->remove_spell ($spell); 671 $::SPELL_LIST->remove_spell ($spell);
672}
673
674sub setup {
675 my ($self, $setup) = @_;
676
677 $::MAP->resize ($self->{mapw}, $self->{maph});
665} 678}
666 679
667sub addme_success { 680sub addme_success {
668 my ($self) = @_; 681 my ($self) = @_;
669 682
875 $::SERVER_INFO->set_markup ( 888 $::SERVER_INFO->set_markup (
876 "server <tt>$self->{host}:$self->{port}</tt>\n" 889 "server <tt>$self->{host}:$self->{port}</tt>\n"
877 . "protocol version <tt>$self->{version}</tt>\n" 890 . "protocol version <tt>$self->{version}</tt>\n"
878 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 891 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
879 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 892 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
893 . "editing support $yesno[!!$self->{editor_support}]\n"
894 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
880 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 895 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
881 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 896 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
882 . "map size $self->{mapw}×$self->{maph}\n" 897 . "map size $self->{mapw}×$self->{maph}\n"
883 ); 898 );
899
900 ::setup_build_button ($self->{editor_support}->{builder_ui});
884} 901}
885 902
886sub logged_in { 903sub logged_in {
887 my ($self) = @_; 904 my ($self) = @_;
888 905
889 $self->send_ext_req (cfplus_support => version => 1, sub { 906 $self->send_ext_req (cfplus_support => version => 1, sub {
890 $self->{cfplus_ext} = $_[0]{version}; 907 $self->{cfplus_ext} = $_[0]{version};
891 $self->update_server_info; 908 $self->update_server_info;
892 909
910 if ($self->{cfplus_ext} >= 2) {
911 $self->send_ext_req ("editor_support", sub {
912 $self->{editor_support} = $_[0];
913 $self->update_server_info;
914
915 0
916 });
917 }
918
893 0 919 0
894 }); 920 });
895 921
896 $self->update_server_info; 922 $self->update_server_info;
897 923
898 $self->send_command ("output-sync $::CFG->{output_sync}"); 924 $self->send_command ("output-sync $::CFG->{output_sync}");
899 $self->send_command ("output-count $::CFG->{output_count}"); 925 $self->send_command ("output-count $::CFG->{output_count}");
900 $self->send_command ("pickup $::CFG->{pickup}"); 926 $self->send_command ("pickup $::CFG->{pickup}");
927}
928
929sub buildat {
930 my ($self, $builditem, $x, $y) = @_;
931
932 if ($self->{cfplus_ext}) {
933 $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem));
934 }
901} 935}
902 936
903sub lookat { 937sub lookat {
904 my ($self, $x, $y) = @_; 938 my ($self, $x, $y) = @_;
905 939
923} 957}
924 958
925sub destroy { 959sub destroy {
926 my ($self) = @_; 960 my ($self) = @_;
927 961
928 $self->{npc_dialog}->destroy 962 (delete $self->{npc_dialog})->destroy
929 if $self->{npc_dialog}; 963 if $self->{npc_dialog};
930 964
931 $self->SUPER::destroy; 965 $self->SUPER::destroy;
932} 966}
933 967
1082 1116
1083 $self->SUPER::destroy; 1117 $self->SUPER::destroy;
1084} 1118}
1085 1119
10861 11201
1121

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines