1 | package DC::Protocol; |
1 | package DC::Protocol; |
2 | |
2 | |
3 | use utf8; |
3 | use common::sense; |
4 | use strict; |
|
|
5 | |
4 | |
6 | use Guard (); |
5 | use Guard (); |
7 | |
6 | |
8 | use Deliantra::Protocol::Constants; |
7 | use Deliantra::Protocol::Constants; |
9 | |
8 | |
… | |
… | |
18 | |
17 | |
19 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
18 | our $TEX_DIALOGUE = new_from_resource DC::Texture |
20 | "dialogue.png", minify => 1, mipmap => 1; |
19 | "dialogue.png", minify => 1, mipmap => 1; |
21 | |
20 | |
22 | our $TEX_NOFACE = new_from_resource DC::Texture |
21 | our $TEX_NOFACE = new_from_resource DC::Texture |
23 | "noface.png", minify => 1, mipmap => 1; |
22 | "noface.png", minify => 1, mipmap => 1, wrap => 1; |
24 | |
|
|
25 | our $TEX_HIDDEN = new_from_resource DC::Texture |
|
|
26 | "hidden.png", minify => 1, mipmap => 1; |
|
|
27 | |
23 | |
28 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
24 | sub MIN_TEXTURE_UNUSED() { 1 }#d# |
29 | |
25 | |
30 | sub new { |
26 | sub new { |
31 | my ($class, %arg) = @_; |
27 | my ($class, %arg) = @_; |
… | |
… | |
98 | { |
94 | { |
99 | $self->{noface} = my $tex = $TEX_NOFACE; |
95 | $self->{noface} = my $tex = $TEX_NOFACE; |
100 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
96 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
101 | } |
97 | } |
102 | |
98 | |
103 | { |
|
|
104 | $self->{hidden} = my $tex = $TEX_HIDDEN; |
|
|
105 | $self->{map}->set_texture (3, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
106 | } |
|
|
107 | |
|
|
108 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
99 | # $self->{expire_count} = DC::DB::FIRST_TILE_ID; # minimum non-fixed tile id |
109 | # $self->{expire_w} = EV::timer 1, 1, sub { |
100 | # $self->{expire_w} = AE::timer 1, 1, sub { |
110 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
101 | # my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; |
111 | # |
102 | # |
112 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
103 | # for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { |
113 | # warn DC::SvREFCNT $self->{texture}[$_]; |
104 | # warn DC::SvREFCNT $self->{texture}[$_]; |
114 | # $self->{texture}[$_]->unload; |
105 | # $self->{texture}[$_]->unload; |
… | |
… | |
410 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
401 | ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) |
411 | : () |
402 | : () |
412 | } |
403 | } |
413 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
404 | sort { $a <=> $b } keys %{$self->{spell_paths}}; |
414 | |
405 | |
415 | join "", @diff |
406 | "\u$name: " . (join ", ", @diff) |
416 | } |
407 | } |
417 | |
408 | |
418 | # all stats that are chacked against changes |
409 | # all stats that are chacked against changes |
419 | my @statchange = ( |
410 | my @statchange = ( |
420 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
411 | [&CS_STAT_STR => \&_stat_numdiff, "Str"], |
… | |
… | |
475 | } |
466 | } |
476 | |
467 | |
477 | if ( |
468 | if ( |
478 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
469 | my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange |
479 | ) { |
470 | ) { |
480 | my $msg = "<b>stat change</b>: " . (join " ", @diffs); |
471 | my $msg = "<b>stat change</b>: " . (join " ", map "($_)", @diffs); |
481 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
472 | $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20); |
482 | } |
473 | } |
483 | |
474 | |
484 | $self->update_stats_window ($stats, $prev); |
475 | $self->update_stats_window ($stats, $prev); |
485 | |
476 | |
… | |
… | |
547 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
538 | $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); |
548 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
539 | $::STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{+CS_STAT_WEAP_SP}); |
549 | |
540 | |
550 | $self->update_weight; |
541 | $self->update_weight; |
551 | |
542 | |
552 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) |
543 | $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}}) |
553 | for keys %RES_TBL; |
544 | for keys %RES_TBL; |
554 | |
545 | |
555 | my $sktbl = $::STATWIDS->{skill_tbl}; |
546 | my $sktbl = $::STATWIDS->{skill_tbl}; |
556 | my @skills = keys %{ $self->{skill_info} }; |
547 | my @skills = keys %{ $self->{skill_info} }; |
557 | |
548 | |
… | |
… | |
998 | |
989 | |
999 | my $tex = $self->{texture}[$tile] ||= |
990 | my $tex = $self->{texture}[$tile] ||= |
1000 | new DC::Texture |
991 | new DC::Texture |
1001 | tile => $tile, |
992 | tile => $tile, |
1002 | image => $data, delete_image => 1, |
993 | image => $data, delete_image => 1, |
1003 | minify => 1, mipmap => 1; |
994 | minify => 1; |
1004 | |
995 | |
1005 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
996 | if (my $cbs = delete $self->{tile_cb}{$tile}) { |
1006 | $_->($tex) for @$cbs; |
997 | $_->($tex) for @$cbs; |
1007 | } |
998 | } |
1008 | } |
999 | } |
… | |
… | |
1051 | my ($self, $flags, $prompt) = @_; |
1042 | my ($self, $flags, $prompt) = @_; |
1052 | |
1043 | |
1053 | $prompt = $LAST_QUERY unless length $prompt; |
1044 | $prompt = $LAST_QUERY unless length $prompt; |
1054 | $LAST_QUERY = $prompt; |
1045 | $LAST_QUERY = $prompt; |
1055 | |
1046 | |
1056 | $self->{query}-> ($self, $flags, $prompt); |
1047 | $self->{query}->($self, $flags, $prompt); |
1057 | } |
1048 | } |
1058 | |
1049 | |
1059 | sub sanitise_xml($) { |
1050 | sub sanitise_xml($) { |
1060 | local $_ = shift; |
1051 | local $_ = shift; |
1061 | |
1052 | |
… | |
… | |
1123 | $self->logprint ("msg: ", $text); |
1114 | $self->logprint ("msg: ", $text); |
1124 | return if $color < 0; # negative color == ignore if not understood |
1115 | return if $color < 0; # negative color == ignore if not understood |
1125 | |
1116 | |
1126 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1117 | my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; |
1127 | |
1118 | |
1128 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
1129 | # no longer neecssary with TRT servers |
|
|
1130 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
1131 | |
|
|
1132 | ::message ({ |
1119 | ::message ({ |
1133 | fg => $fg, |
1120 | fg => $fg, |
1134 | markup => $text, |
1121 | markup => $text, |
1135 | type => $type, |
1122 | type => $type, |
1136 | extra => [@extra], |
1123 | extra => [@extra], |
… | |
… | |
1356 | sub update_server_info { |
1343 | sub update_server_info { |
1357 | my ($self) = @_; |
1344 | my ($self) = @_; |
1358 | |
1345 | |
1359 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1346 | my @yesno = ("<span foreground='red'>no</span>", "<span foreground='green'>yes</span>"); |
1360 | |
1347 | |
|
|
1348 | my $version = JSON::XS->new->encode ($self->{s_version}); |
|
|
1349 | |
1361 | $::SERVER_INFO->set_markup ( |
1350 | $::SERVER_INFO->set_markup ( |
1362 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1351 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
1363 | . "protocol version <tt>$self->{version}</tt>\n" |
1352 | . "protocol version <tt>$version</tt>\n" |
1364 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
1353 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
1365 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1354 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
1366 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1355 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
1367 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1356 | . "editing support $yesno[!!$self->{editor_support}]\n" |
1368 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
1357 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
… | |
… | |
1397 | |
1386 | |
1398 | $self->update_server_info; |
1387 | $self->update_server_info; |
1399 | |
1388 | |
1400 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1389 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
1401 | $self->send_pickup ($::CFG->{pickup}); |
1390 | $self->send_pickup ($::CFG->{pickup}); |
1402 | |
|
|
1403 | $self->send_exti_msg (clientlog => sprintf "OpenGL Info: %s [%s]", |
|
|
1404 | DC::OpenGL::gl_vendor, DC::OpenGL::gl_version);#d# |
|
|
1405 | } |
1391 | } |
1406 | |
1392 | |
1407 | sub lookat { |
1393 | sub lookat { |
1408 | my ($self, $x, $y) = @_; |
1394 | my ($self, $x, $y) = @_; |
1409 | |
1395 | |
… | |
… | |
1411 | $self->send_ext_req (lookat => $x, $y, sub { |
1397 | $self->send_ext_req (lookat => $x, $y, sub { |
1412 | my (%msg) = @_; |
1398 | my (%msg) = @_; |
1413 | |
1399 | |
1414 | if (exists $msg{npc_dialog}) { |
1400 | if (exists $msg{npc_dialog}) { |
1415 | # start npc chat dialog |
1401 | # start npc chat dialog |
1416 | $self->{npc_dialog} = new DC::NPCDialog:: |
1402 | $self->{w}{npc_dialog} = new DC::NPCDialog:: |
1417 | token => $msg{npc_dialog}, |
1403 | token => $msg{npc_dialog}, |
1418 | title => "$msg{npc_dialog}[0] (NPC)", |
1404 | title => "$msg{npc_dialog}[0] (NPC)", |
1419 | conn => $self, |
1405 | conn => $self, |
1420 | ; |
1406 | ; |
1421 | } |
1407 | } |
… | |
… | |
1426 | } |
1412 | } |
1427 | |
1413 | |
1428 | sub destroy { |
1414 | sub destroy { |
1429 | my ($self) = @_; |
1415 | my ($self) = @_; |
1430 | |
1416 | |
1431 | (delete $self->{npc_dialog})->destroy |
1417 | $_->destroy |
1432 | if $self->{npc_dialog}; |
1418 | for values %{ $self->{w} }; |
1433 | |
1419 | |
1434 | $self->SUPER::destroy; |
1420 | $self->SUPER::destroy; |
1435 | |
1421 | |
1436 | %$self = (); |
1422 | %$self = (); |
1437 | } |
1423 | } |
… | |
… | |
1591 | |
1577 | |
1592 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1578 | #Carp::cluck "debug\n";#d# #todo# enable: destroy gets called twice because scalar keys {} is 1 |
1593 | |
1579 | |
1594 | if ($self->{conn}) { |
1580 | if ($self->{conn}) { |
1595 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1581 | $self->{conn}->send_ext_msg (npc_dialog_end => $self->{id}) if $self->{id}; |
1596 | delete $self->{conn}{npc_dialog}; |
1582 | delete $self->{conn}{w}{npc_dialog}; |
1597 | $self->{conn}->disconnect_ext ($self->{id}); |
1583 | $self->{conn}->disconnect_ext ($self->{id}); |
1598 | } |
1584 | } |
1599 | |
1585 | |
1600 | $self->SUPER::destroy; |
1586 | $self->SUPER::destroy; |
1601 | } |
1587 | } |