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.206 by elmex, Sun Dec 7 16:20:44 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 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 22
23sub MIN_TEXTURE_UNUSED() { 1 }#d# 23sub MIN_TEXTURE_UNUSED() { 1 }#d#
24 24
25sub new { 25sub new {
26 my ($class, %arg) = @_; 26 my ($class, %arg) = @_;
27 27
28 my $self = $class->SUPER::new (%arg, 28 my $self = $class->SUPER::new (%arg,
29 setup_req => { 29 setup_req => {
30 extmap => 1, 30 extmap => 1,
31 excmd => 1,
32 widget => 2, 31 widget => 2,
33 %{$arg{setup_req} || {}}, 32 %{$arg{setup_req} || {}},
34 }, 33 },
35 ); 34 );
36 35
37 $self->{map_widget}->clr_commands; 36 $self->update_fx_want;
38 37
39 my @cmd_help = map { 38 my $exp_guard = $self->addme_guard;
40 $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 39 my $skl_guard = $self->addme_guard;
41 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) = @_;
42 43
43 my $cmd = $1; 44 $self->register_face_handler ($exp, sub {
44 my @args = split /\|/, $2; 45 my ($face) = @_;
45 @args = (".*") unless @args;
46 46
47 my (undef, @par) = DC::Pod::section_of $_; 47 undef $exp_guard;
48 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 });
49 51
50 $_ = $_ eq ".*" ? "" : " $_" 52 $self->register_face_handler ($skl, sub {
51 for @args; 53 my ($face) = @_;
52 54
53 map ["$cmd$_", $text], 55 undef $skl_guard;
54 sort { (length $a) <=> (length $b) } 56 my $info = $self->{json_coder}->decode (delete $face->{data});
55 @args 57 $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info };
56 } sort { $a->[DC::Pod::N_PAR] <=> $b->[DC::Pod::N_PAR] } 58 });
57 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;
58 72
59 $self->{json_coder} 73 $self->{json_coder}
60 ->convert_blessed 74 ->convert_blessed
61 ->filter_json_single_key_object ("\fw" => sub { 75 ->filter_json_single_key_object ("\fw" => sub {
62 $self->{widget}{$_[0]} 76 $self->{widget}{$_[0]}
80 $::INVR->clear; 94 $::INVR->clear;
81 $::INVR_HB->clear; 95 $::INVR_HB->clear;
82 $::FLOORBOX->clear; 96 $::FLOORBOX->clear;
83 }); 97 });
84 98
85 $self->{map_widget}->add_command (@$_)
86 for @cmd_help;
87
88 { 99 {
89 $self->{dialogue} = my $tex = $TEX_DIALOGUE; 100 $self->{dialogue} = my $tex = $TEX_DIALOGUE;
90 $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}});
91 } 102 }
92 103
94 $self->{noface} = my $tex = $TEX_NOFACE; 105 $self->{noface} = my $tex = $TEX_NOFACE;
95 $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}});
96 } 107 }
97 108
98# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id 109# $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id
99# $self->{expire_w} = EV::timer 1, 1, sub { 110# $self->{expire_w} = AE::timer 1, 1, sub {
100# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; 111# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
101# 112#
102# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { 113# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
103# warn DC::SvREFCNT $self->{texture}[$_]; 114# warn DC::SvREFCNT $self->{texture}[$_];
104# $self->{texture}[$_]->unload; 115# $self->{texture}[$_]->unload;
116 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 127 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
117 128
118 $self 129 $self
119} 130}
120 131
132 #$self->send_exti_req (nickmon => 1, sub { use Data::Dump; ddx \@_ });#d#
133#sub ext_nicklist { shift; use Data::Dump; ddx \@_; } #d#
134
121sub update_fx_want { 135sub update_fx_want {
122 my ($self) = @_; 136 my ($self) = @_;
123 137
124 $self->send_exti_msg (fx_want => { 138 $self->send_exti_msg (fx_want => {
125 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC 139 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
129} 143}
130 144
131sub ext_capabilities { 145sub ext_capabilities {
132 my ($self, %cap) = @_; 146 my ($self, %cap) = @_;
133 147
134 $self->update_fx_want;
135
136 $self->send_exti_req (resource => "exp_table", sub {
137 my ($exp_table) = @_;
138
139 $self->register_face_handler ($exp_table, sub {
140 my ($face) = @_;
141
142 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
143 $_->() for values %{ $self->{on_exp_update} || {} };
144 });
145
146 ()
147 });
148
149 if (my $ts = $cap{tileset}) { 148 if (my $ts = $cap{tileset}) {
150 if (my ($default) = grep $_->[2] & 1, @$ts) { 149 if (my ($default) = grep $_->[2] & 1, @$ts) {
151 $self->{tileset} = $default; 150 $self->{tileset} = $default;
152 $self->{tilesize} = $default->[3]; 151 $self->{tilesize} = $default->[3];
153 $self->setup_req (tileset => $default->[0]); 152 $self->setup_req (tileset => $default->[0]);
161} 160}
162 161
163sub ext_ambient_music { 162sub ext_ambient_music {
164 my ($self, $songs) = @_; 163 my ($self, $songs) = @_;
165 &::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 }
166} 183}
167 184
168############################################################################# 185#############################################################################
169 186
170sub widget_associate { 187sub widget_associate {
277 my %wkw = ( 294 my %wkw = (
278 root => $DC::UI::ROOT, 295 root => $DC::UI::ROOT,
279 tooltip => $DC::UI::TOOLTIP, 296 tooltip => $DC::UI::TOOLTIP,
280 297
281 mapwidget => $::MAPWIDGET, 298 mapwidget => $::MAPWIDGET,
299 menubar => $::MENUBAR,
300 menupopup => $::MENUPOPUP,
301 pickup_enable => $::PICKUP_ENABLE,
282 buttonbar => $::BUTTONBAR, 302 buttonbar => $::BUTTONBAR,
283 metaserver => $::METASERVER, 303 metaserver => $::METASERVER,
284 buttonbar => $::BUTTONBAR, 304 buttonbar => $::BUTTONBAR,
285 login_button => $::LOGIN_BUTTON, 305 login_button => $::LOGIN_BUTTON,
286 quit_dialog => $::QUIT_DIALOG, 306 quit_dialog => $::QUIT_DIALOG,
303 323
304 floorbox => $::FLOORBOX, 324 floorbox => $::FLOORBOX,
305 help_window => $::HELP_WINDOW, 325 help_window => $::HELP_WINDOW,
306 message_window => $::MESSAGE_WINDOW, 326 message_window => $::MESSAGE_WINDOW,
307 message_dist => $::MESSAGE_DIST, 327 message_dist => $::MESSAGE_DIST,
308 statusbox => $::SDTATUSBOX, 328 statusbox => $::STATUSBOX,
309 329
310 inv => $::INV, 330 inv => $::INV,
311 invr => $::INVR, 331 invr => $::INVR,
312 invr_hb => $::INVR_HB, 332 invr_hb => $::INVR_HB,
313 ); 333 );
397 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 417 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
398 : () 418 : ()
399 } 419 }
400 sort { $a <=> $b } keys %{$self->{spell_paths}}; 420 sort { $a <=> $b } keys %{$self->{spell_paths}};
401 421
402 join "", @diff 422 "\u$name: " . (join ", ", @diff)
403} 423}
404 424
405# all stats that are chacked against changes 425# all stats that are chacked against changes
406my @statchange = ( 426my @statchange = (
407 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 427 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
450 470
451 if (my @diffs = 471 if (my @diffs =
452 ( 472 (
453 ($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" : ()),
454 map { 474 map {
455 $stats->{$_} && $prev->{$_} 475 $stats->{$_} && $prev->{$_}
456 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () 476 && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : ()
457 } sort { $a <=> $b } keys %{$self->{skill_info}} 477 } sort { $a <=> $b } keys %{$self->{skill_info}}
458 ) 478 )
459 ) { 479 ) {
460 my $msg = join " ", @diffs; 480 my $msg = join " ", @diffs;
462 } 482 }
463 483
464 if ( 484 if (
465 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 485 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
466 ) { 486 ) {
467 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 487 my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs);
468 $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);
469 } 489 }
470 490
471 $self->update_stats_window ($stats, $prev); 491 $self->update_stats_window ($stats, $prev);
472 492
510 530
511 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 531 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
512 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 532 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
513 $::GAUGES->{food} ->set_value ($fo, $fo_m); 533 $::GAUGES->{food} ->set_value ($fo, $fo_m);
514 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 534 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
515 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 535 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
516 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 536 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
517 $::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});
518 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 538 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
519 my $title = $stats->{+CS_STAT_TITLE}; 539 my $title = $stats->{+CS_STAT_TITLE};
520 $title =~ s/^Player: //; 540 $title =~ s/^Player: //;
521 $::STATWIDS->{title} ->set_text ("Title: " . $title); 541 $::STATWIDS->{title} ->set_text ("Title: " . $title);
522 542
534 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 554 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
535 $::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});
536 556
537 $self->update_weight; 557 $self->update_weight;
538 558
539 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 559 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
540 for keys %RES_TBL; 560 for keys %RES_TBL;
541 561
542 my $sktbl = $::STATWIDS->{skill_tbl}; 562 my $sktbl = $::STATWIDS->{skill_tbl};
543 my @skills = keys %{ $self->{skill_info} }; 563 my @skills = keys %{ $self->{skill_info} };
544 564
608 # progress 628 # progress
609 (new DC::UI::ExperienceProgress), 629 (new DC::UI::ExperienceProgress),
610 630
611 # label 631 # label
612 (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,
613 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"),
614 ]; 634 ];
615 635
616 push @add, 636 push @add,
617 $x * 4 + 0, $y, $sw->[0], 637 $x * 4 + 0, $y, $sw->[0],
618 $x * 4 + 1, $y, $sw->[1], 638 $x * 4 + 1, $y, $sw->[1],
635 my $sw = $self->{skillwid}{$idx}; 655 my $sw = $self->{skillwid}{$idx};
636 $sw->[0]->set_text (::formsep ($val->[1])); 656 $sw->[0]->set_text (::formsep ($val->[1]));
637 $sw->[1]->set_text ($val->[0] * 1); 657 $sw->[1]->set_text ($val->[0] * 1);
638 $sw->[2]->set_value (@$val); 658 $sw->[2]->set_value (@$val);
639 659
640 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 660 $::GAUGES->{skillexp}->set_label ("$name %d%%");
641 $::GAUGES->{sklprg}->set_value (@$val); 661 $::GAUGES->{skillexp}->set_value (@$val);
642 } 662 }
643} 663}
644 664
645sub user_send { 665sub user_send {
646 my ($self, $command) = @_; 666 my ($self, $command) = @_;
665} 685}
666 686
667sub feed_map1a { 687sub feed_map1a {
668 my ($self, $data) = @_; 688 my ($self, $data) = @_;
669 689
670 my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); 690 my $missing = $self->{map}->map1a_update ($data);
671 my $delay; 691 my $delay;
672 692
673 for my $tile (@$missing) { 693 for my $tile (@$missing) {
674 next if $self->{delay}{$tile}; 694 next if $self->{delay}{$tile};
675 695
985 1005
986 my $tex = $self->{texture}[$tile] ||= 1006 my $tex = $self->{texture}[$tile] ||=
987 new DC::Texture 1007 new DC::Texture
988 tile => $tile, 1008 tile => $tile,
989 image => $data, delete_image => 1, 1009 image => $data, delete_image => 1,
990 minify => 1, mipmap => 1; 1010 minify => 1;
991 1011
992 if (my $cbs = delete $self->{tile_cb}{$tile}) { 1012 if (my $cbs = delete $self->{tile_cb}{$tile}) {
993 $_->($tex) for @$cbs; 1013 $_->($tex) for @$cbs;
994 } 1014 }
995} 1015}
1000 my ($self, $num, $cb) = @_; 1020 my ($self, $num, $cb) = @_;
1001 1021
1002 push @{$self->{face_cb}{$num}}, $cb; 1022 push @{$self->{face_cb}{$num}}, $cb;
1003 1023
1004 defined wantarray 1024 defined wantarray
1005 ? DC::guard { 1025 ? Guard::guard {
1006 @{$self->{face_cb}{$num}} 1026 @{$self->{face_cb}{$num}}
1007 = grep $_ != $cb, 1027 = grep $_ != $cb,
1008 @{$self->{face_cb}{$num}}; 1028 @{$self->{face_cb}{$num}};
1009 } 1029 }
1010 : () 1030 : ()
1038 my ($self, $flags, $prompt) = @_; 1058 my ($self, $flags, $prompt) = @_;
1039 1059
1040 $prompt = $LAST_QUERY unless length $prompt; 1060 $prompt = $LAST_QUERY unless length $prompt;
1041 $LAST_QUERY = $prompt; 1061 $LAST_QUERY = $prompt;
1042 1062
1043 $self->{query}-> ($self, $flags, $prompt); 1063 $self->{query}->($self, $flags, $prompt);
1044}
1045
1046sub sanitise_xml($) {
1047 local $_ = shift;
1048
1049 # we now weed out all tags we do not support
1050 s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>)
1051 }{
1052 "&lt;"
1053 }gex;
1054
1055 # now all entities
1056 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
1057
1058 # handle some elements
1059 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
1060 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
1061
1062 s/\s+$//;
1063
1064 $_
1065} 1064}
1066 1065
1067our %NAME_TO_COLOR = ( 1066our %NAME_TO_COLOR = (
1068 black => 0, 1067 black => 0,
1069 white => 1, 1068 white => 1,
1080 tan => 12, 1079 tan => 12,
1081); 1080);
1082 1081
1083our @CF_COLOR = ( 1082our @CF_COLOR = (
1084 [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],
1085 [1.00, 1.00, 1.00], 1084 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1086 [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],
1087 [1.00, 0.00, 0.00], 1086 [1.00, 0.00, 0.00],
1088 [1.00, 0.54, 0.00], 1087 [1.00, 0.54, 0.00],
1089 [0.11, 0.56, 1.00], 1088 [0.11, 0.56, 1.00],
1090 [0.93, 0.46, 0.00], 1089 [0.93, 0.46, 0.00],
1091 [0.18, 0.54, 0.34], 1090 [0.18, 0.54, 0.34],
1097); 1096);
1098 1097
1099sub msg { 1098sub msg {
1100 my ($self, $color, $type, $text, @extra) = @_; 1099 my ($self, $color, $type, $text, @extra) = @_;
1101 1100
1102 $text = sanitise_xml $text; 1101 $text = DC::sanitise_cfxml $text;
1103 1102
1104 if (my $cb = $self->{cb_msg}{$type}) { 1103 if (my $cb = $self->{cb_msg}{$type}) {
1105 $_->($self, $color, $type, $text, @extra) for values %$cb; 1104 $_->($self, $color, $type, $text, @extra) for values %$cb;
1106 } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { 1105 } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) {
1107 $type =~ s/-/_/g; 1106 $type =~ s/-/_/g;
1110 $self->logprint ("msg: ", $text); 1109 $self->logprint ("msg: ", $text);
1111 return if $color < 0; # negative color == ignore if not understood 1110 return if $color < 0; # negative color == ignore if not understood
1112 1111
1113 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1112 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1114 1113
1115 ## try to create single paragraphs of multiple lines sent by the server
1116 # no longer neecssary with TRT servers
1117 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1118
1119 ::message ({ 1114 ::message ({
1120 fg => $fg, 1115 fg => $fg,
1121 markup => $text, 1116 markup => $text,
1122 type => $type, 1117 type => $type,
1123 extra => [@extra], 1118 extra => [@extra],
1140} 1135}
1141 1136
1142sub spell_add { 1137sub spell_add {
1143 my ($self, $spell) = @_; 1138 my ($self, $spell) = @_;
1144 1139
1145 # try to create single paragraphs out of the multiple lines sent by the server
1146 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
1147 $spell->{message} =~ s/\n+$//;
1148 $spell->{message} ||= "Server did not provide a description for this spell.";
1149
1150 $::SPELL_LIST->add_spell ($spell); 1140 $::SPELL_LIST->add_spell ($spell);
1151 1141 delete $::COMPLETER->{command_list}{spells};
1152 $self->{map_widget}->add_command ("invoke $spell->{name}", DC::asxml $spell->{message});
1153 $self->{map_widget}->add_command ("cast $spell->{name}", DC::asxml $spell->{message});
1154} 1142}
1155 1143
1156sub spell_delete { 1144sub spell_delete {
1157 my ($self, $spell) = @_; 1145 my ($self, $spell) = @_;
1158 1146
1159 $::SPELL_LIST->remove_spell ($spell); 1147 $::SPELL_LIST->remove_spell ($spell);
1148 delete $::COMPLETER->{command_list}{spells};
1160} 1149}
1161 1150
1162sub setup { 1151sub setup {
1163 my ($self, $setup) = @_; 1152 my ($self, $setup) = @_;
1164 1153
1165 $self->{map_widget}->set_tilesize ($self->{tilesize}); 1154 $self->{map_widget}->set_tilesize ($self->{tilesize});
1166 $::MAP->resize ($self->{mapw}, $self->{maph}); 1155 $::MAP->resize ($self->{mapw}, $self->{maph});
1167} 1156}
1168 1157
1169sub addme_success {
1170 my ($self) = @_;
1171
1172 my %skill_help;
1173
1174 for my $node (DC::Pod::find skill_description => "*") {
1175 my (undef, @par) = DC::Pod::section_of $node;
1176 $skill_help{$node->[DC::Pod::N_KW][0]} = DC::Pod::as_label @par;
1177 };
1178
1179 for my $skill (values %{$self->{skill_info}}) {
1180 $self->{map_widget}->add_command ("ready_skill $skill",
1181 (DC::asxml "Ready the skill '$skill'\n\n")
1182 . $skill_help{$skill});
1183 $self->{map_widget}->add_command ("use_skill $skill",
1184 (DC::asxml "Immediately use the skill '$skill'\n\n")
1185 . $skill_help{$skill});
1186 }
1187}
1188
1189sub eof { 1158sub eof {
1190 my ($self) = @_; 1159 my ($self) = @_;
1191 1160
1192 $self->{map_widget}->clr_commands; 1161 $::COMPLETER->reset;
1193 1162
1194 ::stop_game (); 1163 ::stop_game ();
1195} 1164}
1196 1165
1197sub update_floorbox { 1166sub update_floorbox {
1343sub update_server_info { 1312sub update_server_info {
1344 my ($self) = @_; 1313 my ($self) = @_;
1345 1314
1346 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>");
1347 1316
1317 my $version = JSON::XS->new->encode ($self->{s_version});
1318
1348 $::SERVER_INFO->set_markup ( 1319 $::SERVER_INFO->set_markup (
1349 "server <tt>$self->{host}:$self->{port}</tt>\n" 1320 "server <tt>$self->{host}:$self->{port}</tt>\n"
1350 . "protocol version <tt>$self->{version}</tt>\n" 1321 . "protocol version <tt>$version</tt>\n"
1351 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1352 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1353 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1354 . "editing support $yesno[!!$self->{editor_support}]\n" 1322 . "editing support $yesno[!!$self->{editor_support}]\n"
1355 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1356 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
1357 . "client support $yesno[$self->{cfplus_ext} > 0]" 1323 . "client support $yesno[$self->{cfplus_ext} > 0]"
1358 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1324 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
1359 . "map size $self->{mapw}×$self->{maph}\n" 1325 . "map size $self->{mapw}×$self->{maph}\n"
1360 ); 1326 );
1361 1327
1383 }); 1349 });
1384 1350
1385 $self->update_server_info; 1351 $self->update_server_info;
1386 1352
1387 $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;
1388 $self->send_command ("pickup $::CFG->{pickup}"); 1354 $self->send_pickup ($::CFG->{pickup});
1389
1390 $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]",
1391 DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d#
1392} 1355}
1393 1356
1394sub lookat { 1357sub lookat {
1395 my ($self, $x, $y) = @_; 1358 my ($self, $x, $y) = @_;
1396 1359
1398 $self->send_ext_req (lookat => $x, $y, sub { 1361 $self->send_ext_req (lookat => $x, $y, sub {
1399 my (%msg) = @_; 1362 my (%msg) = @_;
1400 1363
1401 if (exists $msg{npc_dialog}) { 1364 if (exists $msg{npc_dialog}) {
1402 # start npc chat dialog 1365 # start npc chat dialog
1403 $self->{npc_dialog} = new DC::NPCDialog:: 1366 $self->{w}{npc_dialog} = new DC::NPCDialog::
1404 token => $msg{npc_dialog}, 1367 token => $msg{npc_dialog},
1405 title => "$msg{npc_dialog}[0] (NPC)", 1368 title => "$msg{npc_dialog}[0] (NPC)",
1406 conn => $self, 1369 conn => $self,
1407 ; 1370 ;
1408 } 1371 }
1413} 1376}
1414 1377
1415sub destroy { 1378sub destroy {
1416 my ($self) = @_; 1379 my ($self) = @_;
1417 1380
1418 (delete $self->{npc_dialog})->destroy 1381 $_->destroy
1419 if $self->{npc_dialog}; 1382 for values %{ $self->{w} };
1420 1383
1421 $self->SUPER::destroy; 1384 $self->SUPER::destroy;
1422 1385
1423 %$self = (); 1386 %$self = ();
1424} 1387}
1524 1487
1525 $self->{kw}{$_} = 1 for @{$info{add_topics} || []}; 1488 $self->{kw}{$_} = 1 for @{$info{add_topics} || []};
1526 $self->{kw}{$_} = 0 for @{$info{del_topics} || []}; 1489 $self->{kw}{$_} = 0 for @{$info{del_topics} || []};
1527 1490
1528 if (exists $info{msg}) { 1491 if (exists $info{msg}) {
1529 my $text = "\n" . DC::Protocol::sanitise_xml $info{msg}; 1492 my $text = "\n" . DC::sanitise_cfxml $info{msg};
1530 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} };
1531 my @link; 1494 my @link;
1532 $text =~ s{ 1495 $text =~ s{
1533 ($match) 1496 ($match)
1534 }{ 1497 }{
1578 1541
1579 #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
1580 1543
1581 if ($self->{conn}) { 1544 if ($self->{conn}) {
1582 $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};
1583 delete $self->{conn}{npc_dialog}; 1546 delete $self->{conn}{w}{npc_dialog};
1584 $self->{conn}->disconnect_ext ($self->{id}); 1547 $self->{conn}->disconnect_ext ($self->{id});
1585 } 1548 }
1586 1549
1587 $self->SUPER::destroy; 1550 $self->SUPER::destroy;
1588} 1551}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines