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.76 by root, Mon Aug 14 01:21:02 2006 UTC vs.
Revision 1.95 by root, Wed Apr 4 02:43:30 2007 UTC

6use Crossfire::Protocol::Constants; 6use Crossfire::Protocol::Constants;
7 7
8use CFPlus; 8use CFPlus;
9use CFPlus::UI; 9use CFPlus::UI;
10use CFPlus::Pod; 10use CFPlus::Pod;
11use CFPlus::Macro;
12use CFPlus::Item;
13
14use Crossfire::Protocol::Base 0.95;
11 15
12use base 'Crossfire::Protocol::Base'; 16use base 'Crossfire::Protocol::Base';
13 17
14sub new { 18sub new {
15 my $class = shift; 19 my $class = shift;
16 20
17 my $self = $class->SUPER::new (@_); 21 my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 });
18 22
19 $self->{map_widget}->clr_commands; 23 $self->{map_widget}->clr_commands;
20 24
21 my @cmd_help = map { 25 my @cmd_help = map {
22 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 26 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
34 38
35 map ["$cmd$_", $text], 39 map ["$cmd$_", $text],
36 sort { (length $a) <=> (length $b) } 40 sort { (length $a) <=> (length $b) }
37 @args 41 @args
38 } sort { $a->{par} <=> $b->{par} } 42 } sort { $a->{par} <=> $b->{par} }
39 CFPlus::Pod::find command_help => "*"; 43 CFPlus::Pod::find command => "*";
44
45 $self->connect_ext (event_capabilities => sub {
46 my ($cap) = @_;
47
48 if (my $ts = $cap->{tileset}) {
49 if (my ($default) = grep $_->[2] & 1, @$ts) {
50 $self->{tileset} = $default;
51 $self->{tilesize} = $default->[3];
52 $self->setup_req (tileset => $default->[0]);
53
54 my $w = int $self->{mapw} * 32 / $self->{tilesize};
55 my $h = int $self->{maph} * 32 / $self->{tilesize};
56
57 $self->setup_req (mapsize => "${w}x${h}");
58 }
59 }
60 });
40 61
41 $self->{map_widget}->add_command (@$_) 62 $self->{map_widget}->add_command (@$_)
42 for @cmd_help; 63 for @cmd_help;
43 64
44 $self->{noface} = new_from_file CFPlus::Texture 65 $self->{noface} = new_from_file CFPlus::Texture
45 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; 66 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
46 67
68 {
69 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture
70 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
71 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
72 }
73
47 $self->{open_container} = 0; 74 $self->{open_container} = 0;
48 75
49 # "global" 76 # "global"
50 $self->{tilecache} = CFPlus::db_table "tilecache"; 77 $self->{tilecache} = CFPlus::db_table "tilecache"
78 or die "tilecache: unable to open database table";
51 $self->{facemap} = CFPlus::db_table "facemap"; 79 $self->{facemap} = CFPlus::db_table "facemap"
80 or die "facemap: unable to open database table";
52 81
53 # per server 82 # per server
54 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}"; 83 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}"
84 or die "mapcache_$self->{host}_$self->{port}: unable to open database table";
55 85
56 $self 86 $self
57} 87}
58 88
59sub logprint { 89sub logprint {
277 if ($ev->{button} == 1) { 307 if ($ev->{button} == 1) {
278 $::CONN->user_send ("ready_skill $name"); 308 $::CONN->user_send ("ready_skill $name");
279 } elsif ($ev->{button} == 2) { 309 } elsif ($ev->{button} == 2) {
280 $::CONN->user_send ("use_skill $name"); 310 $::CONN->user_send ("use_skill $name");
281 } elsif ($ev->{button} == 3) { 311 } elsif ($ev->{button} == 3) {
312 my $shortname = CFPlus::shorten $name, 14;
282 (new CFPlus::UI::Menu 313 (new CFPlus::UI::Menu
283 items => [ 314 items => [
284 ["bind <i>ready_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], 315 ["bind <i>ready_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["ready_skill $name"] }],
285 ["bind <i>use_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["use_skill $name"]) }], 316 ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }],
286 ], 317 ],
287 )->popup ($ev); 318 )->popup ($ev);
288 } else { 319 } else {
289 return 0; 320 return 0;
290 } 321 }
307 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 338 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
308 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 339 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
309 } 340 }
310} 341}
311 342
343sub macro_send {
344 my ($self, $macro) = @_;
345
346 for my $cmd (@{ $macro->{action} }) {
347 $self->send_command ($cmd);
348 }
349}
350
312sub user_send { 351sub user_send {
313 my ($self, $command) = @_; 352 my ($self, $command) = @_;
314 353
354 $self->{record}->($command)
315 if ($self->{record}) { 355 if $self->{record};
316 push @{$self->{record}}, $command;
317 }
318 356
319 $self->logprint ("send: ", $command); 357 $self->logprint ("send: ", $command);
320 $self->send_command ($command); 358 $self->send_command ($command);
321 ::status ($command); 359 ::status ($command);
322} 360}
323 361
324sub start_record { 362sub record {
325 my ($self) = @_; 363 my ($self, $cb) = @_;
326 364
327 $self->{record} = []; 365 $self->{record} = $cb;
328}
329
330sub stop_record {
331 my ($self) = @_;
332 return delete $self->{record};
333} 366}
334 367
335sub map_scroll { 368sub map_scroll {
336 my ($self, $dx, $dy) = @_; 369 my ($self, $dx, $dy) = @_;
337 370
339} 372}
340 373
341sub feed_map1a { 374sub feed_map1a {
342 my ($self, $data) = @_; 375 my ($self, $data) = @_;
343 376
344 $self->{map}->map1a_update ($data); 377 $self->{map}->map1a_update ($data, $self->{setup}{extmap});
345 $self->{map_widget}->update; 378 $self->{map_widget}->update;
346} 379}
347 380
348sub magicmap { 381sub magicmap {
349 my ($self, $w, $h, $x, $y, $data) = @_; 382 my ($self, $w, $h, $x, $y, $data) = @_;
612 [0.75, 0.61, 0.20], 645 [0.75, 0.61, 0.20],
613 [0.99, 0.77, 0.26], 646 [0.99, 0.77, 0.26],
614 [0.74, 0.65, 0.41], 647 [0.74, 0.65, 0.41],
615 ); 648 );
616 649
650 my $fg = $color[$color % @color];
651
617 $self->logprint ("info: ", $text); 652 $self->logprint ("info: ", $text);
618
619 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
620 653
621 # try to create single paragraphs of multiple lines sent by the server 654 # try to create single paragraphs of multiple lines sent by the server
622 $text =~ s/(?<=\S)\n(?=\w)/ /g; 655 $text =~ s/(?<=\S)\n(?=\w)/ /g;
623 656
624 $text = CFPlus::asxml $text; 657 $text = CFPlus::asxml $text;
625 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 658 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
626 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 659 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
627 660
628 $self->{logview}->add_paragraph ({ fg => $color[$color], markup => $_ }) 661 ::message ({ fg => $fg, markup => $_ })
629 for map "<span foreground='#ffffff'>$time</span> $_", split /\n/, $text; 662 for split /\n/, $text;
630 $self->{logview}->scroll_to_bottom;
631 663
632 $self->{statusbox}->add ($text, 664 $self->{statusbox}->add ($text,
633 group => $text, 665 group => $text,
634 fg => $color[$color], 666 fg => $fg,
635 timeout => $color >= 2 ? 180 : 10, 667 timeout => $color >= 2 ? 180 : 10,
636 tooltip_font => $::FONT_FIXED, 668 tooltip_font => $::FONT_FIXED,
637 ); 669 );
638} 670}
639 671
649 # try to create single paragraphs out of the multiple lines sent by the server 681 # try to create single paragraphs out of the multiple lines sent by the server
650 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 682 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
651 $spell->{message} =~ s/\n+$//; 683 $spell->{message} =~ s/\n+$//;
652 $spell->{message} ||= "Server did not provide a description for this spell."; 684 $spell->{message} ||= "Server did not provide a description for this spell.";
653 685
654 $::SPELL_PAGE->add_spell ($spell); 686 $::SPELL_LIST->add_spell ($spell);
655 687
656 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); 688 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message});
657 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); 689 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message});
658} 690}
659 691
660sub spell_delete { 692sub spell_delete {
661 my ($self, $spell) = @_; 693 my ($self, $spell) = @_;
662 694
663 $::SPELL_PAGE->remove_spell ($spell); 695 $::SPELL_LIST->remove_spell ($spell);
696}
697
698sub setup {
699 my ($self, $setup) = @_;
700
701 $self->{map_widget}->set_tilesize ($self->{tilesize});
702 $::MAP->resize ($self->{mapw}, $self->{maph});
664} 703}
665 704
666sub addme_success { 705sub addme_success {
667 my ($self) = @_; 706 my ($self) = @_;
668 707
874 $::SERVER_INFO->set_markup ( 913 $::SERVER_INFO->set_markup (
875 "server <tt>$self->{host}:$self->{port}</tt>\n" 914 "server <tt>$self->{host}:$self->{port}</tt>\n"
876 . "protocol version <tt>$self->{version}</tt>\n" 915 . "protocol version <tt>$self->{version}</tt>\n"
877 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 916 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
878 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 917 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
918 . "editing support $yesno[!!$self->{editor_support}]\n"
919 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
879 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 920 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
880 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 921 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
881 . "map size $self->{mapw}×$self->{maph}\n" 922 . "map size $self->{mapw}×$self->{maph}\n"
882 ); 923 );
924
925 ::setup_build_button ($self->{editor_support}->{builder_ui});
883} 926}
884 927
885sub logged_in { 928sub logged_in {
886 my ($self) = @_; 929 my ($self) = @_;
887 930
888 $self->send_ext_req (cfplus_support => version => 1, sub { 931 $self->send_ext_req (cfplus_support => version => 1, sub {
889 $self->{cfplus_ext} = $_[0]{version}; 932 $self->{cfplus_ext} = $_[0]{version};
890 $self->update_server_info; 933 $self->update_server_info;
891 934
935 if ($self->{cfplus_ext} >= 2) {
936 $self->send_ext_req ("editor_support", sub {
937 $self->{editor_support} = $_[0];
938 $self->update_server_info;
939
940 0
941 });
942 }
943
892 0 944 0
893 }); 945 });
894 946
895 $self->update_server_info; 947 $self->update_server_info;
896 948
897 $self->send_command ("output-sync $::CFG->{output_sync}"); 949 $self->send_command ("output-sync $::CFG->{output_sync}");
898 $self->send_command ("output-count $::CFG->{output_count}"); 950 $self->send_command ("output-count $::CFG->{output_count}");
951 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
899 $self->send_command ("pickup $::CFG->{pickup}"); 952 $self->send_command ("pickup $::CFG->{pickup}");
953}
954
955sub buildat {
956 my ($self, $builditem, $x, $y) = @_;
957
958 if ($self->{cfplus_ext}) {
959 $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem));
960 }
900} 961}
901 962
902sub lookat { 963sub lookat {
903 my ($self, $x, $y) = @_; 964 my ($self, $x, $y) = @_;
904 965
922} 983}
923 984
924sub destroy { 985sub destroy {
925 my ($self) = @_; 986 my ($self) = @_;
926 987
927 $self->{npc_dialog}->destroy 988 (delete $self->{npc_dialog})->destroy
928 if $self->{npc_dialog}; 989 if $self->{npc_dialog};
929 990
930 $self->SUPER::destroy; 991 $self->SUPER::destroy;
931} 992}
932 993
947 kw => { hi => 0, yes => 0, no => 0 }, 1008 kw => { hi => 0, yes => 0, no => 0 },
948 has_close_button => 1, 1009 has_close_button => 1,
949 @_, 1010 @_,
950 ); 1011 );
951 1012
952 Scalar::Util::weaken (my $this = $self); 1013 CFPlus::weaken (my $this = $self);
953 1014
954 $self->connect (delete => sub { $this->destroy; 1 }); 1015 $self->connect (delete => sub { $this->destroy; 1 });
955 1016
956 # better use a pane... 1017 # better use a pane...
957 $self->add (my $hbox = new CFPlus::UI::HBox); 1018 $self->add (my $hbox = new CFPlus::UI::HBox);
1001}; 1062};
1002 1063
1003sub update_options { 1064sub update_options {
1004 my ($self) = @_; 1065 my ($self) = @_;
1005 1066
1006 Scalar::Util::weaken $self; 1067 CFPlus::weaken $self;
1007 1068
1008 $self->{options}->clear; 1069 $self->{options}->clear;
1009 $self->{options}->add ($self->{bye_button}); 1070 $self->{options}->add ($self->{bye_button});
1010 1071
1011 for my $kw (sort keys %{ $self->{kw} }) { 1072 for my $kw (sort keys %{ $self->{kw} }) {
1020} 1081}
1021 1082
1022sub feed { 1083sub feed {
1023 my ($self, $msg) = @_; 1084 my ($self, $msg) = @_;
1024 1085
1025 Scalar::Util::weaken $self; 1086 CFPlus::weaken $self;
1026 1087
1027 if ($msg->{msgtype} eq "reply") { 1088 if ($msg->{msgtype} eq "reply") {
1028 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1089 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1029 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1090 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1030 1091
1081 1142
1082 $self->SUPER::destroy; 1143 $self->SUPER::destroy;
1083} 1144}
1084 1145
10851 11461
1147

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines