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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines