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.201 by root, Wed Sep 3 06:35:55 2008 UTC vs.
Revision 1.228 by root, Wed Nov 21 13:23:10 2012 UTC

1package DC::Protocol; 1package DC::Protocol;
2 2
3use utf8; 3use common::sense;
4use strict; 4
5use Guard ();
5 6
6use Deliantra::Protocol::Constants; 7use Deliantra::Protocol::Constants;
7 8
8use DC; 9use DC;
9use DC::DB; 10use DC::DB;
10use DC::UI; 11use DC::UI;
11use DC::Pod;
12use DC::Macro; 12use DC::Macro;
13use DC::Item; 13use DC::Item;
14 14
15use base 'Deliantra::Protocol::Base'; 15use base 'Deliantra::Protocol::Base';
16 16
17our $TEX_DIALOGUE = new_from_resource DC::Texture 17our $TEX_DIALOGUE = new_from_resource DC::Texture
18 "dialogue.png", minify => 1, mipmap => 1; 18 "dialogue.png", minify => 1, mipmap => 1;
19 19
20our $TEX_NOFACE = new_from_resource DC::Texture 20our $TEX_NOFACE = new_from_resource DC::Texture
21 "noface.png", minify => 1, mipmap => 1; 21 "noface.png", minify => 1, mipmap => 1, wrap => 1;
22
23sub MIN_TEXTURE_UNUSED() { 1 }#d#
22 24
23sub new { 25sub new {
24 my ($class, %arg) = @_; 26 my ($class, %arg) = @_;
25 27
26 my $self = $class->SUPER::new (%arg, 28 my $self = $class->SUPER::new (%arg,
27 setup_req => { 29 setup_req => {
28 extmap => 1, 30 extmap => 1,
29 excmd => 1,
30 widget => 2, 31 widget => 2,
31 %{$arg{setup_req} || {}}, 32 %{$arg{setup_req} || {}},
32 }, 33 },
33 ); 34 );
34 35
35 $self->{map_widget}->clr_commands; 36 $self->update_fx_want;
36 37
37 my @cmd_help = map { 38 my $exp_guard = $self->addme_guard;
38 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 39 my $skl_guard = $self->addme_guard;
39 or die "unparseable command help: $_->[DC::Pod::N_KW][0]"; 40 my $spl_guard = $self->addme_guard;
41 $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub {
42 my ($exp, $skl, $spl) = @_;
40 43
41 my $cmd = $1; 44 $self->register_face_handler ($exp, sub {
42 my @args = split /\|/, $2; 45 my ($face) = @_;
43 @args = (".*") unless @args;
44 46
45 my (undef, @par) = DC::Pod::section_of $_; 47 undef $exp_guard;
46 my $text = DC::Pod::as_label @par; 48 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
49 $_->() for values %{ $self->{on_exp_update} };
50 });
47 51
48 $_ = $_ eq ".*" ? "" : " $_" 52 $self->register_face_handler ($skl, sub {
49 for @args; 53 my ($face) = @_;
50 54
51 map ["$cmd$_", $text], 55 undef $skl_guard;
52 sort { (length $a) <=> (length $b) } 56 my $info = $self->{json_coder}->decode (delete $face->{data});
53 @args 57 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
54 } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } 58 });
55 DC::Pod::find command => "*"; 59
60 $self->register_face_handler ($spl, sub {
61 my ($face) = @_;
62
63 undef $spl_guard;
64 my $info = $self->{json_coder}->decode (delete $face->{data});
65 $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info };
66 });
67
68 ()
69 });
70
71 $::COMPLETER->reset;
56 72
57 $self->{json_coder} 73 $self->{json_coder}
58 ->convert_blessed 74 ->convert_blessed
59 ->filter_json_single_key_object ("\fw" => sub { 75 ->filter_json_single_key_object ("\fw" => sub {
60 $self->{widget}{$_[0]} 76 $self->{widget}{$_[0]}
73 for values %{delete $ws->{w} || {}}; 89 for values %{delete $ws->{w} || {}};
74 } 90 }
75 91
76 delete $self->{items}; 92 delete $self->{items};
77 $::INV->clear; 93 $::INV->clear;
94 $::INVR->clear;
78 $::INVR_HB->clear; 95 $::INVR_HB->clear;
79 $::FLOORBOX->clear; 96 $::FLOORBOX->clear;
80 }); 97 });
81 98
82 $self->{map_widget}->add_command (@$_)
83 for @cmd_help;
84
85 { 99 {
86 $self->{dialogue} = my $tex = $TEX_DIALOGUE; 100 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
87 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 101 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
88 } 102 }
89 103
90 { 104 {
91 $self->{noface} = my $tex = $TEX_NOFACE; 105 $self->{noface} = my $tex = $TEX_NOFACE;
92 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 106 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
93 } 107 }
94 108
109# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
110# $self->{expire_w} = AE::timer 1, 1, sub {
111# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
112#
113# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
114# warn DC::SvREFCNT $self->{texture}[$_];
115# $self->{texture}[$_]->unload;
116# warn "expire texture $_\n";#d#
117# }
118#
119# ($self->{expire_count} += $count) < @{ $self->{texture} }
120# or $self->{expire_count} = DC::DB::FIRST_TILE_ID;
121# warn "count is $count\n";#d#
122# };
123
95 $self->{open_container} = 0; 124 $self->{open_container} = 0;
96 125
97 # per server 126 # per server
98 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 127 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
99 128
100 $self 129 $self
101} 130}
131
132 #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d#
133#sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d#
102 134
103sub update_fx_want { 135sub update_fx_want {
104 my ($self) = @_; 136 my ($self) = @_;
105 137
106 $self->send_exti_msg (fx_want => { 138 $self->send_exti_msg (fx_want => {
111} 143}
112 144
113sub ext_capabilities { 145sub ext_capabilities {
114 my ($self, %cap) = @_; 146 my ($self, %cap) = @_;
115 147
116 $self->update_fx_want;
117
118 $self->send_exti_req (resource => "exp_table", sub {
119 my ($exp_table) = @_;
120
121 $self->register_face_handler ($exp_table, sub {
122 my ($face) = @_;
123
124 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
125 $_->() for values %{ $self->{on_exp_update} || {} };
126 });
127
128 ()
129 });
130
131 if (my $ts = $cap{tileset}) { 148 if (my $ts = $cap{tileset}) {
132 if (my ($default) = grep $_->[2] & 1, @$ts) { 149 if (my ($default) = grep $_->[2] & 1, @$ts) {
133 $self->{tileset} = $default; 150 $self->{tileset} = $default;
134 $self->{tilesize} = $default->[3]; 151 $self->{tilesize} = $default->[3];
135 $self->setup_req (tileset => $default->[0]); 152 $self->setup_req (tileset => $default->[0]);
143} 160}
144 161
145sub ext_ambient_music { 162sub ext_ambient_music {
146 my ($self, $songs) = @_; 163 my ($self, $songs) = @_;
147 &::audio_music_set_ambient ($songs); 164 &::audio_music_set_ambient ($songs);
165}
166
167sub ext_command_list {
168 my ($self, @faces) = @_;
169
170 my $handler = $self->{command_facehandler} = {};
171 my $commands = $::COMPLETER->{command_list} = {};
172
173 for my $idx (@faces) {
174 $handler->{$idx} = $self->register_face_handler ($idx, sub {
175 my ($face) = @_;
176
177 $commands->{$idx} =
178 $face->{cache} ||= $self->{json_coder}->decode ($face->{data});
179 });
180 }
148} 181}
149 182
150############################################################################# 183#############################################################################
151 184
152sub widget_associate { 185sub widget_associate {
259 my %wkw = ( 292 my %wkw = (
260 root => $DC::UI::ROOT, 293 root => $DC::UI::ROOT,
261 tooltip => $DC::UI::TOOLTIP, 294 tooltip => $DC::UI::TOOLTIP,
262 295
263 mapwidget => $::MAPWIDGET, 296 mapwidget => $::MAPWIDGET,
297 menubar => $::MENUBAR,
298 menupopup => $::MENUPOPUP,
299 pickup_enable => $::PICKUP_ENABLE,
264 buttonbar => $::BUTTONBAR, 300 buttonbar => $::BUTTONBAR,
265 metaserver => $::METASERVER, 301 metaserver => $::METASERVER,
266 buttonbar => $::BUTTONBAR, 302 buttonbar => $::BUTTONBAR,
267 login_button => $::LOGIN_BUTTON, 303 login_button => $::LOGIN_BUTTON,
268 quit_dialog => $::QUIT_DIALOG, 304 quit_dialog => $::QUIT_DIALOG,
285 321
286 floorbox => $::FLOORBOX, 322 floorbox => $::FLOORBOX,
287 help_window => $::HELP_WINDOW, 323 help_window => $::HELP_WINDOW,
288 message_window => $::MESSAGE_WINDOW, 324 message_window => $::MESSAGE_WINDOW,
289 message_dist => $::MESSAGE_DIST, 325 message_dist => $::MESSAGE_DIST,
290 statusbox => $::SDTATUSBOX, 326 statusbox => $::STATUSBOX,
291 327
292 inv => $::INV, 328 inv => $::INV,
293 invr => $::INVR, 329 invr => $::INVR,
294 invr_hb => $::INVR_HB, 330 invr_hb => $::INVR_HB,
295 ); 331 );
379 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 415 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
380 : () 416 : ()
381 } 417 }
382 sort { $a <=> $b } keys %{$self->{spell_paths}}; 418 sort { $a <=> $b } keys %{$self->{spell_paths}};
383 419
384 join "", @diff 420 "\u$name: " . (join ", ", @diff)
385} 421}
386 422
387# all stats that are chacked against changes 423# all stats that are chacked against changes
388my @statchange = ( 424my @statchange = (
389 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 425 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
432 468
433 if (my @diffs = 469 if (my @diffs =
434 ( 470 (
435 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), 471 ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()),
436 map { 472 map {
437 $stats->{$_} && $prev->{$_} 473 $stats->{$_} && $prev->{$_}
438 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 474 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
439 } sort { $a <=> $b } keys %{$self->{skill_info}} 475 } sort { $a <=> $b } keys %{$self->{skill_info}}
440 ) 476 )
441 ) { 477 ) {
442 my $msg = join " ", @diffs; 478 my $msg = join " ", @diffs;
444 } 480 }
445 481
446 if ( 482 if (
447 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 483 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
448 ) { 484 ) {
449 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 485 my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs);
450 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); 486 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20);
451 } 487 }
452 488
453 $self->update_stats_window ($stats, $prev); 489 $self->update_stats_window ($stats, $prev);
454 490
492 528
493 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 529 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
494 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 530 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
495 $::GAUGES->{food} ->set_value ($fo, $fo_m); 531 $::GAUGES->{food} ->set_value ($fo, $fo_m);
496 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 532 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
497 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 533 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
498 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 534 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
499 $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); 535 $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64});
500 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 536 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
501 my $title = $stats->{+CS_STAT_TITLE}; 537 my $title = $stats->{+CS_STAT_TITLE};
502 $title =~ s/^Player: //; 538 $title =~ s/^Player: //;
503 $::STATWIDS->{title} ->set_text ("Title: " . $title); 539 $::STATWIDS->{title} ->set_text ("Title: " . $title);
504 540
516 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 552 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
517 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); 553 $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP});
518 554
519 $self->update_weight; 555 $self->update_weight;
520 556
521 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 557 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
522 for keys %RES_TBL; 558 for keys %RES_TBL;
523 559
524 my $sktbl = $::STATWIDS->{skill_tbl}; 560 my $sktbl = $::STATWIDS->{skill_tbl};
525 my @skills = keys %{ $self->{skill_info} }; 561 my @skills = keys %{ $self->{skill_info} };
526 562
545 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), 581 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0),
546 ]; 582 ];
547 583
548 my @add = @$sw; 584 my @add = @$sw;
549 585
550 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 586 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>";
551 587
552 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 588 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
553 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 589 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
554 590
555 my ($x, $y) = (0, 1); 591 my ($x, $y) = (0, 1);
590 # progress 626 # progress
591 (new DC::UI::ExperienceProgress), 627 (new DC::UI::ExperienceProgress),
592 628
593 # label 629 # label
594 (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0, 630 (new DC::UI::Label text => $name, on_button_down => $spell_cb, align => 0,
595 can_events => 1, can_hover => 1, tooltip => (DC::Pod::section_label skill_description => $name) . $TOOLTIP_ALL), 631 can_events => 1, can_hover => 1, tooltip => "#(skill/$name)$TOOLTIP_ALL"),
596 ]; 632 ];
597 633
598 push @add, 634 push @add,
599 $x * 4 + 0, $y, $sw->[0], 635 $x * 4 + 0, $y, $sw->[0],
600 $x * 4 + 1, $y, $sw->[1], 636 $x * 4 + 1, $y, $sw->[1],
617 my $sw = $self->{skillwid}{$idx}; 653 my $sw = $self->{skillwid}{$idx};
618 $sw->[0]->set_text (::formsep ($val->[1])); 654 $sw->[0]->set_text (::formsep ($val->[1]));
619 $sw->[1]->set_text ($val->[0] * 1); 655 $sw->[1]->set_text ($val->[0] * 1);
620 $sw->[2]->set_value (@$val); 656 $sw->[2]->set_value (@$val);
621 657
622 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 658 $::GAUGES->{skillexp}->set_label ("$name %d%%");
623 $::GAUGES->{sklprg}->set_value (@$val); 659 $::GAUGES->{skillexp}->set_value (@$val);
624 } 660 }
625} 661}
626 662
627sub user_send { 663sub user_send {
628 my ($self, $command) = @_; 664 my ($self, $command) = @_;
647} 683}
648 684
649sub feed_map1a { 685sub feed_map1a {
650 my ($self, $data) = @_; 686 my ($self, $data) = @_;
651 687
652 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 688 my $missing = $self->{map}->map1a_update ($data);
653 my $delay; 689 my $delay;
654 690
655 for my $tile (@$missing) { 691 for my $tile (@$missing) {
656 next if $self->{delay}{$tile}; 692 next if $self->{delay}{$tile};
657 693
658 $delay = 1; 694 $delay = 1;
659 695
660 if (my $tex = $::CONN->{texture}[$tile]) { 696 if (my $tex = $self->{texture}[$tile]) {
661 $tex->upload; 697 $tex->upload;
662 } else { 698 } else {
663 $self->{delay}{$tile} = 1; 699 $self->{delay}{$tile} = 1;
664 700
665 # we assume the face is in-flight and will eventually come 701 # we assume the face is in-flight and will eventually arrive
666 push @{$self->{tile_cb}{$tile}}, sub { 702 push @{$self->{tile_cb}{$tile}}, sub {
667 delete $self->{delay}{$tile}; 703 delete $self->{delay}{$tile};
668 $_[0]->upload; 704 $_[0]->upload;
669 }; 705 };
670 } 706 }
671 } 707 }
672 708
673 if ($delay) { 709 if ($delay) {
674 # delay the map drawing a tiny bit in the hope of getting the missing fetched 710 # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched
675 EV::once undef, 0, 0.03, sub { 711 EV::once undef, 0, 0.03, sub {
676 $self->{map_widget}->update 712 $self->{map_widget}->update
677 if $self->{map_widget}; 713 if $self->{map_widget};
678 }; 714 };
679 } else { 715 } else {
967 1003
968 my $tex = $self->{texture}[$tile] ||= 1004 my $tex = $self->{texture}[$tile] ||=
969 new DC::Texture 1005 new DC::Texture
970 tile => $tile, 1006 tile => $tile,
971 image => $data, delete_image => 1, 1007 image => $data, delete_image => 1,
972 minify => 1, mipmap => 1; 1008 minify => 1;
973 1009
974 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1010 if (my $cbs = delete $self->{tile_cb}{$tile}) {
975 $_->($tex) for @$cbs; 1011 $_->($tex) for @$cbs;
976 } 1012 }
977} 1013}
982 my ($self, $num, $cb) = @_; 1018 my ($self, $num, $cb) = @_;
983 1019
984 push @{$self->{face_cb}{$num}}, $cb; 1020 push @{$self->{face_cb}{$num}}, $cb;
985 1021
986 defined wantarray 1022 defined wantarray
987 ? DC::guard { 1023 ? Guard::guard {
988 @{$self->{face_cb}{$num}} 1024 @{$self->{face_cb}{$num}}
989 = grep $_ != $cb, 1025 = grep $_ != $cb,
990 @{$self->{face_cb}{$num}}; 1026 @{$self->{face_cb}{$num}};
991 } 1027 }
992 : () 1028 : ()
1020 my ($self, $flags, $prompt) = @_; 1056 my ($self, $flags, $prompt) = @_;
1021 1057
1022 $prompt = $LAST_QUERY unless length $prompt; 1058 $prompt = $LAST_QUERY unless length $prompt;
1023 $LAST_QUERY = $prompt; 1059 $LAST_QUERY = $prompt;
1024 1060
1025 $self->{query}-> ($self, $flags, $prompt); 1061 $self->{query}->($self, $flags, $prompt);
1026}
1027
1028sub sanitise_xml($) {
1029 local $_ = shift;
1030
1031 # we now weed out all tags we do not support
1032 s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>)
1033 }{
1034 "&lt;"
1035 }gex;
1036
1037 # now all entities
1038 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
1039
1040 # handle some elements
1041 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
1042 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
1043
1044 s/\s+$//;
1045
1046 $_
1047} 1062}
1048 1063
1049our %NAME_TO_COLOR = ( 1064our %NAME_TO_COLOR = (
1050 black => 0, 1065 black => 0,
1051 white => 1, 1066 white => 1,
1062 tan => 12, 1077 tan => 12,
1063); 1078);
1064 1079
1065our @CF_COLOR = ( 1080our @CF_COLOR = (
1066 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 1081 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1067 [1.00, 1.00, 1.00], 1082 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1068 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] 1083 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55],
1069 [1.00, 0.00, 0.00], 1084 [1.00, 0.00, 0.00],
1070 [1.00, 0.54, 0.00], 1085 [1.00, 0.54, 0.00],
1071 [0.11, 0.56, 1.00], 1086 [0.11, 0.56, 1.00],
1072 [0.93, 0.46, 0.00], 1087 [0.93, 0.46, 0.00],
1073 [0.18, 0.54, 0.34], 1088 [0.18, 0.54, 0.34],
1079); 1094);
1080 1095
1081sub msg { 1096sub msg {
1082 my ($self, $color, $type, $text, @extra) = @_; 1097 my ($self, $color, $type, $text, @extra) = @_;
1083 1098
1084 $text = sanitise_xml $text; 1099 $text = DC::sanitise_cfxml $text;
1085 1100
1086 if (my $cb = $self->{cb_msg}{$type}) { 1101 if (my $cb = $self->{cb_msg}{$type}) {
1087 $_->($self, $color, $type, $text, @extra) for values %$cb; 1102 $_->($self, $color, $type, $text, @extra) for values %$cb;
1088 } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { 1103 } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) {
1089 $type =~ s/-/_/g; 1104 $type =~ s/-/_/g;
1092 $self->logprint ("msg: ", $text); 1107 $self->logprint ("msg: ", $text);
1093 return if $color < 0; # negative color == ignore if not understood 1108 return if $color < 0; # negative color == ignore if not understood
1094 1109
1095 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1110 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1096 1111
1097 ## try to create single paragraphs of multiple lines sent by the server
1098 # no longer neecssary with TRT servers
1099 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1100
1101 for (split /\n/, $text) {
1102 ::message ({ 1112 ::message ({
1103 fg => $fg, 1113 fg => $fg,
1104 markup => $_, 1114 markup => $text,
1105 type => $type, 1115 type => $type,
1106 extra => [@extra], 1116 extra => [@extra],
1107 color_flags => $color, #d# ugly, kill 1117 color_flags => $color, #d# ugly, kill
1108 }); 1118 });
1109 1119
1110 $color &= ~NDI_CLEAR; # only clear once for multiline messages 1120# $color &= ~NDI_CLEAR; # only clear once for multiline messages
1111 # actually, this is an ugly design. _we_ should control the channels, 1121# # actually, this is an ugly design. _we_ should control the channels,
1112 # not some random other widget, as the channels are clearly protocol-specific. 1122# # not some random other widget, as the channels are clearly protocol-specific.
1113 # then we could also react to flags such as CLEAR without resorting to 1123# # then we could also react to flags such as CLEAR without resorting to
1114 # hacks such as color_flags, above. 1124# # hacks such as color_flags, above.
1115 }
1116 1125
1117 $self->{statusbox}->add ($text, 1126 $self->{statusbox}->add ($text,
1118 group => $text, 1127 group => $text,
1119 fg => $fg, 1128 fg => $fg,
1120 timeout => $color >= 2 ? 180 : 10, 1129 timeout => $color >= 2 ? 180 : 10,
1124} 1133}
1125 1134
1126sub spell_add { 1135sub spell_add {
1127 my ($self, $spell) = @_; 1136 my ($self, $spell) = @_;
1128 1137
1129 # try to create single paragraphs out of the multiple lines sent by the server
1130 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
1131 $spell->{message} =~ s/\n+$//;
1132 $spell->{message} ||= "Server did not provide a description for this spell.";
1133
1134 $::SPELL_LIST->add_spell ($spell); 1138 $::SPELL_LIST->add_spell ($spell);
1135 1139 delete $::COMPLETER->{command_list}{spells};
1136 $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message});
1137 $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message});
1138} 1140}
1139 1141
1140sub spell_delete { 1142sub spell_delete {
1141 my ($self, $spell) = @_; 1143 my ($self, $spell) = @_;
1142 1144
1143 $::SPELL_LIST->remove_spell ($spell); 1145 $::SPELL_LIST->remove_spell ($spell);
1146 delete $::COMPLETER->{command_list}{spells};
1144} 1147}
1145 1148
1146sub setup { 1149sub setup {
1147 my ($self, $setup) = @_; 1150 my ($self, $setup) = @_;
1148 1151
1149 $self->{map_widget}->set_tilesize ($self->{tilesize}); 1152 $self->{map_widget}->set_tilesize ($self->{tilesize});
1150 $::MAP->resize ($self->{mapw}, $self->{maph}); 1153 $::MAP->resize ($self->{mapw}, $self->{maph});
1151} 1154}
1152 1155
1153sub addme_success {
1154 my ($self) = @_;
1155
1156 my %skill_help;
1157
1158 for my $node (DC::Pod::find skill_description => "*") {
1159 my (undef, @par) = DC::Pod::section_of $node;
1160 $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par;
1161 };
1162
1163 for my $skill (values %{$self->{skill_info}}) {
1164 $self->{map_widget}->add_command ("ready_skill $skill",
1165 (DC::asxml "Ready the skill '$skill'\n\n")
1166 . $skill_help{$skill});
1167 $self->{map_widget}->add_command ("use_skill $skill",
1168 (DC::asxml "Immediately use the skill '$skill'\n\n")
1169 . $skill_help{$skill});
1170 }
1171}
1172
1173sub eof { 1156sub eof {
1174 my ($self) = @_; 1157 my ($self) = @_;
1175 1158
1176 $self->{map_widget}->clr_commands; 1159 $::COMPLETER->reset;
1177 1160
1178 ::stop_game (); 1161 ::stop_game ();
1179} 1162}
1180 1163
1181sub update_floorbox { 1164sub update_floorbox {
1327sub update_server_info { 1310sub update_server_info {
1328 my ($self) = @_; 1311 my ($self) = @_;
1329 1312
1330 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); 1313 my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>");
1331 1314
1315 my $version = JSON::XS->new->encode ($self->{s_version});
1316
1332 $::SERVER_INFO->set_markup ( 1317 $::SERVER_INFO->set_markup (
1333 "server <tt>$self->{host}:$self->{port}</tt>\n" 1318 "server <tt>$self->{host}:$self->{port}</tt>\n"
1334 . "protocol version <tt>$self->{version}</tt>\n" 1319 . "protocol version <tt>$version</tt>\n"
1335 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1336 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1337 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1338 . "editing support $yesno[!!$self->{editor_support}]\n" 1320 . "editing support $yesno[!!$self->{editor_support}]\n"
1339 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1340 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1341 . "client support $yesno[$self->{cfplus_ext} > 0]" 1321 . "client support $yesno[$self->{cfplus_ext} > 0]"
1342 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1322 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1343 . "map size $self->{mapw}×$self->{maph}\n" 1323 . "map size $self->{mapw}×$self->{maph}\n"
1344 ); 1324 );
1345 1325
1367 }); 1347 });
1368 1348
1369 $self->update_server_info; 1349 $self->update_server_info;
1370 1350
1371 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; 1351 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
1372 $self->send_command ("pickup $::CFG->{pickup}"); 1352 $self->send_pickup ($::CFG->{pickup});
1373
1374 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1375 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1376} 1353}
1377 1354
1378sub lookat { 1355sub lookat {
1379 my ($self, $x, $y) = @_; 1356 my ($self, $x, $y) = @_;
1380 1357
1382 $self->send_ext_req (lookat => $x, $y, sub { 1359 $self->send_ext_req (lookat => $x, $y, sub {
1383 my (%msg) = @_; 1360 my (%msg) = @_;
1384 1361
1385 if (exists $msg{npc_dialog}) { 1362 if (exists $msg{npc_dialog}) {
1386 # start npc chat dialog 1363 # start npc chat dialog
1387 $self->{npc_dialog} = new DC::NPCDialog:: 1364 $self->{w}{npc_dialog} = new DC::NPCDialog::
1388 token => $msg{npc_dialog}, 1365 token => $msg{npc_dialog},
1389 title => "$msg{npc_dialog}[0] (NPC)", 1366 title => "$msg{npc_dialog}[0] (NPC)",
1390 conn => $self, 1367 conn => $self,
1391 ; 1368 ;
1392 } 1369 }
1397} 1374}
1398 1375
1399sub destroy { 1376sub destroy {
1400 my ($self) = @_; 1377 my ($self) = @_;
1401 1378
1402 (delete $self->{npc_dialog})->destroy 1379 $_->destroy
1403 if $self->{npc_dialog}; 1380 for values %{ $self->{w} };
1404 1381
1405 $self->SUPER::destroy; 1382 $self->SUPER::destroy;
1406 1383
1407 %$self = (); 1384 %$self = ();
1408} 1385}
1508 1485
1509 $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; 1486 $self->{kw}{$_} = 1 for @{$info{add_topics} || []};
1510 $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; 1487 $self->{kw}{$_} = 0 for @{$info{del_topics} || []};
1511 1488
1512 if (exists $info{msg}) { 1489 if (exists $info{msg}) {
1513 my $text = "\n" . DC::Protocol::sanitise_xml $info{msg}; 1490 my $text = "\n" . DC::sanitise_cfxml $info{msg};
1514 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; 1491 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} };
1515 my @link; 1492 my @link;
1516 $text =~ s{ 1493 $text =~ s{
1517 ($match) 1494 ($match)
1518 }{ 1495 }{
1544} 1521}
1545 1522
1546sub send { 1523sub send {
1547 my ($self, $msg) = @_; 1524 my ($self, $msg) = @_;
1548 1525
1549 $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); 1526 $self->{textview}->add_paragraph ({
1527 markup =>
1528 "\n<span foreground='#ffff00'><b>"
1529 . (DC::asxml $msg)
1530 . "</b></span>"
1531 });
1550 $self->{textview}->scroll_to_bottom; 1532 $self->{textview}->scroll_to_bottom;
1551 1533
1552 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); 1534 $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg);
1553} 1535}
1554 1536
1557 1539
1558 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 1540 #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1
1559 1541
1560 if ($self->{conn}) { 1542 if ($self->{conn}) {
1561 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; 1543 $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id};
1562 delete $self->{conn}{npc_dialog}; 1544 delete $self->{conn}{w}{npc_dialog};
1563 $self->{conn}->disconnect_ext ($self->{id}); 1545 $self->{conn}->disconnect_ext ($self->{id});
1564 } 1546 }
1565 1547
1566 $self->SUPER::destroy; 1548 $self->SUPER::destroy;
1567} 1549}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines