1 | package DC::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use common::sense; |
4 | use strict; |
4 | |
|
|
5 | use Guard (); |
5 | |
6 | |
6 | use Deliantra::Protocol::Constants; |
7 | use Deliantra::Protocol::Constants; |
7 | |
8 | |
8 | use DC; |
9 | use DC; |
9 | use DC::DB; |
10 | use DC::DB; |
… | |
… | |
13 | use DC::Item; |
14 | use DC::Item; |
14 | |
15 | |
15 | use base 'Deliantra::Protocol::Base'; |
16 | use base 'Deliantra::Protocol::Base'; |
16 | |
17 | |
17 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
18 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
18 | "dialogue.png", minify => 1, mipmap => 1; |
19 | "dialogue.png", minify => 1, mipmap => 1; |
19 | |
20 | |
20 | our $TEX_NOFACE = new_from_resource DC::Texture |
21 | our $TEX_NOFACE = new_from_resource DC::Texture |
21 | "noface.png", minify => 1, mipmap => 1; |
22 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
|
|
23 | |
|
|
24 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
22 | |
25 | |
23 | sub new { |
26 | sub new { |
24 | my ($class, %arg) = @_; |
27 | my ($class, %arg) = @_; |
25 | |
28 | |
26 | my $self = $class->SUPER::new (%arg, |
29 | my $self = $class->SUPER::new (%arg, |
27 | setup_req => { |
30 | setup_req => { |
28 | extmap => 1, |
31 | extmap => 1, |
29 | excmd => 1, |
|
|
30 | widget => 2, |
32 | widget => 2, |
31 | %{$arg{setup_req} || {}}, |
33 | %{$arg{setup_req} || {}}, |
32 | }, |
34 | }, |
33 | ); |
35 | ); |
|
|
36 | |
|
|
37 | $self->update_fx_want; |
|
|
38 | |
|
|
39 | my $exp_guard = $self->addme_guard; |
|
|
40 | my $skl_guard = $self->addme_guard; |
|
|
41 | my $spl_guard = $self->addme_guard; |
|
|
42 | $self->send_exti_req (resource => qw(exp_table skill_info spell_paths), sub { |
|
|
43 | my ($exp, $skl, $spl) = @_; |
|
|
44 | |
|
|
45 | $self->register_face_handler ($exp, sub { |
|
|
46 | my ($face) = @_; |
|
|
47 | |
|
|
48 | undef $exp_guard; |
|
|
49 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
50 | $_->() for values %{ $self->{on_exp_update} }; |
|
|
51 | }); |
|
|
52 | |
|
|
53 | $self->register_face_handler ($skl, sub { |
|
|
54 | my ($face) = @_; |
|
|
55 | |
|
|
56 | undef $skl_guard; |
|
|
57 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
58 | $self->{skill_info} = { map { CS_STAT_SKILLINFO + $_ => $info->[$_][0] } 0 .. $#$info }; |
|
|
59 | }); |
|
|
60 | |
|
|
61 | $self->register_face_handler ($spl, sub { |
|
|
62 | my ($face) = @_; |
|
|
63 | |
|
|
64 | undef $spl_guard; |
|
|
65 | my $info = $self->{json_coder}->decode (delete $face->{data}); |
|
|
66 | $self->{spell_paths} = { map { (1 << $_) => $info->[$_][0] } 0 .. $#$info }; |
|
|
67 | }); |
|
|
68 | |
|
|
69 | () |
|
|
70 | }); |
34 | |
71 | |
35 | $self->{map_widget}->clr_commands; |
72 | $self->{map_widget}->clr_commands; |
36 | |
73 | |
37 | my @cmd_help = map { |
74 | my @cmd_help = map { |
38 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
75 | $_->[DC::Pod::N_KW][0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
… | |
… | |
91 | { |
128 | { |
92 | $self->{noface} = my $tex = $TEX_NOFACE; |
129 | $self->{noface} = my $tex = $TEX_NOFACE; |
93 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
130 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
94 | } |
131 | } |
95 | |
132 | |
|
|
133 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
|
|
134 | # $self->{expire_w} = AE::timer 1, 1, sub { |
|
|
135 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
|
|
136 | # |
|
|
137 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
|
|
138 | # warn DC::SvREFCNT $self->{texture}[$_]; |
|
|
139 | # $self->{texture}[$_]->unload; |
|
|
140 | # warn "expire texture $_\n";#d# |
|
|
141 | # } |
|
|
142 | # |
|
|
143 | # ($self->{expire_count} += $count) < @{ $self->{texture} } |
|
|
144 | # or $self->{expire_count} = DC::DB::FIRST_TILE_ID; |
|
|
145 | # warn "count is $count\n";#d# |
|
|
146 | # }; |
|
|
147 | |
96 | $self->{open_container} = 0; |
148 | $self->{open_container} = 0; |
97 | |
149 | |
98 | # per server |
150 | # per server |
99 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
151 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
100 | |
152 | |
… | |
… | |
111 | }); |
163 | }); |
112 | } |
164 | } |
113 | |
165 | |
114 | sub ext_capabilities { |
166 | sub ext_capabilities { |
115 | my ($self, %cap) = @_; |
167 | my ($self, %cap) = @_; |
116 | |
|
|
117 | $self->update_fx_want; |
|
|
118 | |
|
|
119 | $self->send_exti_req (resource => "exp_table", sub { |
|
|
120 | my ($exp_table) = @_; |
|
|
121 | |
|
|
122 | $self->register_face_handler ($exp_table, sub { |
|
|
123 | my ($face) = @_; |
|
|
124 | |
|
|
125 | $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data}); |
|
|
126 | $_->() for values %{ $self->{on_exp_update} || {} }; |
|
|
127 | }); |
|
|
128 | |
|
|
129 | () |
|
|
130 | }); |
|
|
131 | |
168 | |
132 | if (my $ts = $cap{tileset}) { |
169 | if (my $ts = $cap{tileset}) { |
133 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
170 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
134 | $self->{tileset} = $default; |
171 | $self->{tileset} = $default; |
135 | $self->{tilesize} = $default->[3]; |
172 | $self->{tilesize} = $default->[3]; |
… | |
… | |
260 | my %wkw = ( |
297 | my %wkw = ( |
261 | root => $DC::UI::ROOT, |
298 | root => $DC::UI::ROOT, |
262 | tooltip => $DC::UI::TOOLTIP, |
299 | tooltip => $DC::UI::TOOLTIP, |
263 | |
300 | |
264 | mapwidget => $::MAPWIDGET, |
301 | mapwidget => $::MAPWIDGET, |
|
|
302 | menubar => $::MENUBAR, |
|
|
303 | menupopup => $::MENUPOPUP, |
|
|
304 | pickup_enable => $::PICKUP_ENABLE, |
265 | buttonbar => $::BUTTONBAR, |
305 | buttonbar => $::BUTTONBAR, |
266 | metaserver => $::METASERVER, |
306 | metaserver => $::METASERVER, |
267 | buttonbar => $::BUTTONBAR, |
307 | buttonbar => $::BUTTONBAR, |
268 | login_button => $::LOGIN_BUTTON, |
308 | login_button => $::LOGIN_BUTTON, |
269 | quit_dialog => $::QUIT_DIALOG, |
309 | quit_dialog => $::QUIT_DIALOG, |
… | |
… | |
286 | |
326 | |
287 | floorbox => $::FLOORBOX, |
327 | floorbox => $::FLOORBOX, |
288 | help_window => $::HELP_WINDOW, |
328 | help_window => $::HELP_WINDOW, |
289 | message_window => $::MESSAGE_WINDOW, |
329 | message_window => $::MESSAGE_WINDOW, |
290 | message_dist => $::MESSAGE_DIST, |
330 | message_dist => $::MESSAGE_DIST, |
291 | statusbox => $::SDTATUSBOX, |
331 | statusbox => $::STATUSBOX, |
292 | |
332 | |
293 | inv => $::INV, |
333 | inv => $::INV, |
294 | invr => $::INVR, |
334 | invr => $::INVR, |
295 | invr_hb => $::INVR_HB, |
335 | invr_hb => $::INVR_HB, |
296 | ); |
336 | ); |
… | |
… | |
380 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
420 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
381 | : () |
421 | : () |
382 | } |
422 | } |
383 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
423 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
384 | |
424 | |
385 | join "", @diff |
425 | "\u$name: " . (join ", ", @diff) |
386 | } |
426 | } |
387 | |
427 | |
388 | # all stats that are chacked against changes |
428 | # all stats that are chacked against changes |
389 | my @statchange = ( |
429 | my @statchange = ( |
390 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
430 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
433 | |
473 | |
434 | if (my @diffs = |
474 | if (my @diffs = |
435 | ( |
475 | ( |
436 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
476 | ($stats->{+CS_STAT_EXP64} > $prev->{+CS_STAT_EXP64} ? ($stats->{+CS_STAT_EXP64} - $prev->{+CS_STAT_EXP64}) . " experience gained" : ()), |
437 | map { |
477 | map { |
438 | $stats->{$_} && $prev->{$_} |
478 | $stats->{$_} && $prev->{$_} |
439 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
479 | && $stats->{$_}[1] > $prev->{$_}[1] ? "($self->{skill_info}{$_}+" . ($stats->{$_}[1] - $prev->{$_}[1]) . ")" : () |
440 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
480 | } sort { $a <=> $b } keys %{$self->{skill_info}} |
441 | ) |
481 | ) |
442 | ) { |
482 | ) { |
443 | my $msg = join " ", @diffs; |
483 | my $msg = join " ", @diffs; |
… | |
… | |
445 | } |
485 | } |
446 | |
486 | |
447 | if ( |
487 | if ( |
448 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
488 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
449 | ) { |
489 | ) { |
450 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
490 | my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs); |
451 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
491 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
452 | } |
492 | } |
453 | |
493 | |
454 | $self->update_stats_window ($stats, $prev); |
494 | $self->update_stats_window ($stats, $prev); |
455 | |
495 | |
… | |
… | |
493 | |
533 | |
494 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
534 | $::GAUGES->{hp} ->set_value ($hp, $hp_m); |
495 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
535 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
496 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
536 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
497 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
537 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
498 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
538 | $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d# |
499 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
539 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
500 | $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
540 | $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); |
501 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
541 | $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); |
502 | my $title = $stats->{+CS_STAT_TITLE}; |
542 | my $title = $stats->{+CS_STAT_TITLE}; |
503 | $title =~ s/^Player: //; |
543 | $title =~ s/^Player: //; |
504 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
544 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
505 | |
545 | |
… | |
… | |
517 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
557 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
518 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
558 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
519 | |
559 | |
520 | $self->update_weight; |
560 | $self->update_weight; |
521 | |
561 | |
522 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
562 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
523 | for keys %RES_TBL; |
563 | for keys %RES_TBL; |
524 | |
564 | |
525 | my $sktbl = $::STATWIDS->{skill_tbl}; |
565 | my $sktbl = $::STATWIDS->{skill_tbl}; |
526 | my @skills = keys %{ $self->{skill_info} }; |
566 | my @skills = keys %{ $self->{skill_info} }; |
527 | |
567 | |
… | |
… | |
546 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
586 | 7, 0, (new DC::UI::Label text => "Skill", expand => 1, align => 0), |
547 | ]; |
587 | ]; |
548 | |
588 | |
549 | my @add = @$sw; |
589 | my @add = @$sw; |
550 | |
590 | |
551 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; |
591 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use skill\nRight click - further options</small>"; |
552 | |
592 | |
553 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
593 | my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
554 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
594 | my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); |
555 | |
595 | |
556 | my ($x, $y) = (0, 1); |
596 | my ($x, $y) = (0, 1); |
… | |
… | |
618 | my $sw = $self->{skillwid}{$idx}; |
658 | my $sw = $self->{skillwid}{$idx}; |
619 | $sw->[0]->set_text (::formsep ($val->[1])); |
659 | $sw->[0]->set_text (::formsep ($val->[1])); |
620 | $sw->[1]->set_text ($val->[0] * 1); |
660 | $sw->[1]->set_text ($val->[0] * 1); |
621 | $sw->[2]->set_value (@$val); |
661 | $sw->[2]->set_value (@$val); |
622 | |
662 | |
623 | $::GAUGES->{sklprg}->set_label ("$name %d%%"); |
663 | $::GAUGES->{skillexp}->set_label ("$name %d%%"); |
624 | $::GAUGES->{sklprg}->set_value (@$val); |
664 | $::GAUGES->{skillexp}->set_value (@$val); |
625 | } |
665 | } |
626 | } |
666 | } |
627 | |
667 | |
628 | sub user_send { |
668 | sub user_send { |
629 | my ($self, $command) = @_; |
669 | my ($self, $command) = @_; |
… | |
… | |
648 | } |
688 | } |
649 | |
689 | |
650 | sub feed_map1a { |
690 | sub feed_map1a { |
651 | my ($self, $data) = @_; |
691 | my ($self, $data) = @_; |
652 | |
692 | |
653 | my $missing = $self->{map}->map1a_update ($data, $self->{setup}{extmap}); |
693 | my $missing = $self->{map}->map1a_update ($data); |
654 | my $delay; |
694 | my $delay; |
655 | |
695 | |
656 | for my $tile (@$missing) { |
696 | for my $tile (@$missing) { |
657 | next if $self->{delay}{$tile}; |
697 | next if $self->{delay}{$tile}; |
658 | |
698 | |
659 | $delay = 1; |
699 | $delay = 1; |
660 | |
700 | |
661 | if (my $tex = $::CONN->{texture}[$tile]) { |
701 | if (my $tex = $self->{texture}[$tile]) { |
662 | $tex->upload; |
702 | $tex->upload; |
663 | } else { |
703 | } else { |
664 | $self->{delay}{$tile} = 1; |
704 | $self->{delay}{$tile} = 1; |
665 | |
705 | |
666 | # we assume the face is in-flight and will eventually come |
706 | # we assume the face is in-flight and will eventually arrive |
667 | push @{$self->{tile_cb}{$tile}}, sub { |
707 | push @{$self->{tile_cb}{$tile}}, sub { |
668 | delete $self->{delay}{$tile}; |
708 | delete $self->{delay}{$tile}; |
669 | $_[0]->upload; |
709 | $_[0]->upload; |
670 | }; |
710 | }; |
671 | } |
711 | } |
672 | } |
712 | } |
673 | |
713 | |
674 | if ($delay) { |
714 | if ($delay) { |
675 | # delay the map drawing a tiny bit in the hope of getting the missing fetched |
715 | # delay the map drawing a tiny bit in the hope of getting the missing tiles fetched |
676 | EV::once undef, 0, 0.03, sub { |
716 | EV::once undef, 0, 0.03, sub { |
677 | $self->{map_widget}->update |
717 | $self->{map_widget}->update |
678 | if $self->{map_widget}; |
718 | if $self->{map_widget}; |
679 | }; |
719 | }; |
680 | } else { |
720 | } else { |
… | |
… | |
968 | |
1008 | |
969 | my $tex = $self->{texture}[$tile] ||= |
1009 | my $tex = $self->{texture}[$tile] ||= |
970 | new DC::Texture |
1010 | new DC::Texture |
971 | tile => $tile, |
1011 | tile => $tile, |
972 | image => $data, delete_image => 1, |
1012 | image => $data, delete_image => 1, |
973 | minify => 1, mipmap => 1; |
1013 | minify => 1; |
974 | |
1014 | |
975 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1015 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
976 | $_->($tex) for @$cbs; |
1016 | $_->($tex) for @$cbs; |
977 | } |
1017 | } |
978 | } |
1018 | } |
… | |
… | |
983 | my ($self, $num, $cb) = @_; |
1023 | my ($self, $num, $cb) = @_; |
984 | |
1024 | |
985 | push @{$self->{face_cb}{$num}}, $cb; |
1025 | push @{$self->{face_cb}{$num}}, $cb; |
986 | |
1026 | |
987 | defined wantarray |
1027 | defined wantarray |
988 | ? DC::guard { |
1028 | ? Guard::guard { |
989 | @{$self->{face_cb}{$num}} |
1029 | @{$self->{face_cb}{$num}} |
990 | = grep $_ != $cb, |
1030 | = grep $_ != $cb, |
991 | @{$self->{face_cb}{$num}}; |
1031 | @{$self->{face_cb}{$num}}; |
992 | } |
1032 | } |
993 | : () |
1033 | : () |
… | |
… | |
1021 | my ($self, $flags, $prompt) = @_; |
1061 | my ($self, $flags, $prompt) = @_; |
1022 | |
1062 | |
1023 | $prompt = $LAST_QUERY unless length $prompt; |
1063 | $prompt = $LAST_QUERY unless length $prompt; |
1024 | $LAST_QUERY = $prompt; |
1064 | $LAST_QUERY = $prompt; |
1025 | |
1065 | |
1026 | $self->{query}-> ($self, $flags, $prompt); |
1066 | $self->{query}->($self, $flags, $prompt); |
1027 | } |
1067 | } |
1028 | |
1068 | |
1029 | sub sanitise_xml($) { |
1069 | sub sanitise_xml($) { |
1030 | local $_ = shift; |
1070 | local $_ = shift; |
1031 | |
1071 | |
… | |
… | |
1063 | tan => 12, |
1103 | tan => 12, |
1064 | ); |
1104 | ); |
1065 | |
1105 | |
1066 | our @CF_COLOR = ( |
1106 | our @CF_COLOR = ( |
1067 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1107 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1068 | [1.00, 1.00, 1.00], |
1108 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1069 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
1109 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55], |
1070 | [1.00, 0.00, 0.00], |
1110 | [1.00, 0.00, 0.00], |
1071 | [1.00, 0.54, 0.00], |
1111 | [1.00, 0.54, 0.00], |
1072 | [0.11, 0.56, 1.00], |
1112 | [0.11, 0.56, 1.00], |
1073 | [0.93, 0.46, 0.00], |
1113 | [0.93, 0.46, 0.00], |
1074 | [0.18, 0.54, 0.34], |
1114 | [0.18, 0.54, 0.34], |
… | |
… | |
1092 | } else { |
1132 | } else { |
1093 | $self->logprint ("msg: ", $text); |
1133 | $self->logprint ("msg: ", $text); |
1094 | return if $color < 0; # negative color == ignore if not understood |
1134 | return if $color < 0; # negative color == ignore if not understood |
1095 | |
1135 | |
1096 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1136 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1097 | |
|
|
1098 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1099 | # no longer neecssary with TRT servers |
|
|
1100 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1101 | |
1137 | |
1102 | ::message ({ |
1138 | ::message ({ |
1103 | fg => $fg, |
1139 | fg => $fg, |
1104 | markup => $text, |
1140 | markup => $text, |
1105 | type => $type, |
1141 | type => $type, |
… | |
… | |
1326 | sub update_server_info { |
1362 | sub update_server_info { |
1327 | my ($self) = @_; |
1363 | my ($self) = @_; |
1328 | |
1364 | |
1329 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1365 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1330 | |
1366 | |
|
|
1367 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1368 | |
1331 | $::SERVER_INFO->set_markup ( |
1369 | $::SERVER_INFO->set_markup ( |
1332 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1370 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1333 | . "protocol version <tt>$self->{version}</tt>\n" |
1371 | . "protocol version <tt>$version</tt>\n" |
1334 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
|
|
1335 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
1336 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
|
|
1337 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1372 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1338 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
1339 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
|
|
1340 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1373 | . "client support $yesno[$self->{cfplus_ext} > 0]" |
1341 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1374 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
1342 | . "map size $self->{mapw}×$self->{maph}\n" |
1375 | . "map size $self->{mapw}×$self->{maph}\n" |
1343 | ); |
1376 | ); |
1344 | |
1377 | |
… | |
… | |
1366 | }); |
1399 | }); |
1367 | |
1400 | |
1368 | $self->update_server_info; |
1401 | $self->update_server_info; |
1369 | |
1402 | |
1370 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1403 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1371 | $self->send_command ("pickup $::CFG->{pickup}"); |
1404 | $self->send_pickup ($::CFG->{pickup}); |
1372 | |
|
|
1373 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
|
|
1374 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
|
|
1375 | } |
1405 | } |
1376 | |
1406 | |
1377 | sub lookat { |
1407 | sub lookat { |
1378 | my ($self, $x, $y) = @_; |
1408 | my ($self, $x, $y) = @_; |
1379 | |
1409 | |
… | |
… | |
1381 | $self->send_ext_req (lookat => $x, $y, sub { |
1411 | $self->send_ext_req (lookat => $x, $y, sub { |
1382 | my (%msg) = @_; |
1412 | my (%msg) = @_; |
1383 | |
1413 | |
1384 | if (exists $msg{npc_dialog}) { |
1414 | if (exists $msg{npc_dialog}) { |
1385 | # start npc chat dialog |
1415 | # start npc chat dialog |
1386 | $self->{npc_dialog} = new DC::NPCDialog:: |
1416 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1387 | token => $msg{npc_dialog}, |
1417 | token => $msg{npc_dialog}, |
1388 | title => "$msg{npc_dialog}[0] (NPC)", |
1418 | title => "$msg{npc_dialog}[0] (NPC)", |
1389 | conn => $self, |
1419 | conn => $self, |
1390 | ; |
1420 | ; |
1391 | } |
1421 | } |
… | |
… | |
1396 | } |
1426 | } |
1397 | |
1427 | |
1398 | sub destroy { |
1428 | sub destroy { |
1399 | my ($self) = @_; |
1429 | my ($self) = @_; |
1400 | |
1430 | |
1401 | (delete $self->{npc_dialog})->destroy |
1431 | $_->destroy |
1402 | if $self->{npc_dialog}; |
1432 | for values %{ $self->{w} }; |
1403 | |
1433 | |
1404 | $self->SUPER::destroy; |
1434 | $self->SUPER::destroy; |
1405 | |
1435 | |
1406 | %$self = (); |
1436 | %$self = (); |
1407 | } |
1437 | } |
… | |
… | |
1543 | } |
1573 | } |
1544 | |
1574 | |
1545 | sub send { |
1575 | sub send { |
1546 | my ($self, $msg) = @_; |
1576 | my ($self, $msg) = @_; |
1547 | |
1577 | |
1548 | $self->{textview}->add_paragraph ({ markup => "\n" . DC::asxml $msg }); |
1578 | $self->{textview}->add_paragraph ({ |
|
|
1579 | markup => |
|
|
1580 | "\n<span foreground='#ffff00'><b>" |
|
|
1581 | . (DC::asxml $msg) |
|
|
1582 | . "</b></span>" |
|
|
1583 | }); |
1549 | $self->{textview}->scroll_to_bottom; |
1584 | $self->{textview}->scroll_to_bottom; |
1550 | |
1585 | |
1551 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1586 | $self->{conn}->send_ext_msg (npc_dialog_tell => $self->{id}, $msg); |
1552 | } |
1587 | } |
1553 | |
1588 | |
… | |
… | |
1556 | |
1591 | |
1557 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1592 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1558 | |
1593 | |
1559 | if ($self->{conn}) { |
1594 | if ($self->{conn}) { |
1560 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1595 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1561 | delete $self->{conn}{npc_dialog}; |
1596 | delete $self->{conn}{w}{npc_dialog}; |
1562 | $self->{conn}->disconnect_ext ($self->{id}); |
1597 | $self->{conn}->disconnect_ext ($self->{id}); |
1563 | } |
1598 | } |
1564 | |
1599 | |
1565 | $self->SUPER::destroy; |
1600 | $self->SUPER::destroy; |
1566 | } |
1601 | } |