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.220 by root, Wed Jan 4 11:23:23 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;
16 17
17our $TEX_DIALOGUE = new_from_resource DC::Texture 18our $TEX_DIALOGUE = new_from_resource DC::Texture
18 "dialogue.png", minify => 1, mipmap => 1; 19 "dialogue.png", minify => 1, mipmap => 1;
19 20
20our $TEX_NOFACE = new_from_resource DC::Texture 21our $TEX_NOFACE = new_from_resource DC::Texture
21 "noface.png", minify => 1, mipmap => 1; 22 "noface.png", minify => 1, mipmap => 1, wrap => 1;
22 23
23sub MIN_TEXTURE_UNUSED() { 1 }#d# 24sub MIN_TEXTURE_UNUSED() { 1 }#d#
24 25
25sub new { 26sub new {
26 my ($class, %arg) = @_; 27 my ($class, %arg) = @_;
94 $self->{noface} = my $tex = $TEX_NOFACE; 95 $self->{noface} = my $tex = $TEX_NOFACE;
95 $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}});
96 } 97 }
97 98
98# $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
99# $self->{expire_w} = EV::timer 1, 1, sub { 100# $self->{expire_w} = AE::timer 1, 1, sub {
100# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1; 101# my $count = (int @{ $self->{texture} } / MIN_TEXTURE_UNUSED) || 1;
101# 102#
102# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) { 103# for ($self->{map}->expire_textures ($self->{expire_count}, $count)) {
103# warn DC::SvREFCNT $self->{texture}[$_]; 104# warn DC::SvREFCNT $self->{texture}[$_];
104# $self->{texture}[$_]->unload; 105# $self->{texture}[$_]->unload;
277 my %wkw = ( 278 my %wkw = (
278 root => $DC::UI::ROOT, 279 root => $DC::UI::ROOT,
279 tooltip => $DC::UI::TOOLTIP, 280 tooltip => $DC::UI::TOOLTIP,
280 281
281 mapwidget => $::MAPWIDGET, 282 mapwidget => $::MAPWIDGET,
283 menubar => $::MENUBAR,
284 menupopup => $::MENUPOPUP,
285 pickup_enable => $::PICKUP_ENABLE,
282 buttonbar => $::BUTTONBAR, 286 buttonbar => $::BUTTONBAR,
283 metaserver => $::METASERVER, 287 metaserver => $::METASERVER,
284 buttonbar => $::BUTTONBAR, 288 buttonbar => $::BUTTONBAR,
285 login_button => $::LOGIN_BUTTON, 289 login_button => $::LOGIN_BUTTON,
286 quit_dialog => $::QUIT_DIALOG, 290 quit_dialog => $::QUIT_DIALOG,
303 307
304 floorbox => $::FLOORBOX, 308 floorbox => $::FLOORBOX,
305 help_window => $::HELP_WINDOW, 309 help_window => $::HELP_WINDOW,
306 message_window => $::MESSAGE_WINDOW, 310 message_window => $::MESSAGE_WINDOW,
307 message_dist => $::MESSAGE_DIST, 311 message_dist => $::MESSAGE_DIST,
308 statusbox => $::SDTATUSBOX, 312 statusbox => $::STATUSBOX,
309 313
310 inv => $::INV, 314 inv => $::INV,
311 invr => $::INVR, 315 invr => $::INVR,
312 invr_hb => $::INVR_HB, 316 invr_hb => $::INVR_HB,
313 ); 317 );
397 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_}) 401 ? (($new & $_ ? "+" : "-") . $self->{spell_paths}{$_})
398 : () 402 : ()
399 } 403 }
400 sort { $a <=> $b } keys %{$self->{spell_paths}}; 404 sort { $a <=> $b } keys %{$self->{spell_paths}};
401 405
402 join "", @diff 406 "\u$name: " . (join ", ", @diff)
403} 407}
404 408
405# all stats that are chacked against changes 409# all stats that are chacked against changes
406my @statchange = ( 410my @statchange = (
407 [&CS_STAT_STR => \&_stat_numdiff, "Str"], 411 [&CS_STAT_STR => \&_stat_numdiff, "Str"],
462 } 466 }
463 467
464 if ( 468 if (
465 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 469 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
466 ) { 470 ) {
467 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 471 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); 472 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20);
469 } 473 }
470 474
471 $self->update_stats_window ($stats, $prev); 475 $self->update_stats_window ($stats, $prev);
472 476
510 514
511 $::GAUGES->{hp} ->set_value ($hp, $hp_m); 515 $::GAUGES->{hp} ->set_value ($hp, $hp_m);
512 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 516 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
513 $::GAUGES->{food} ->set_value ($fo, $fo_m); 517 $::GAUGES->{food} ->set_value ($fo, $fo_m);
514 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 518 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
515 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 519 $::GAUGES->{exp} ->set_label ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))#d#
516 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 520 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
517 $::GAUGES->{prg} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64}); 521 $::GAUGES->{exp} ->set_value ($stats->{+CS_STAT_LEVEL}, $stats->{+CS_STAT_EXP64});
518 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE}); 522 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
519 my $title = $stats->{+CS_STAT_TITLE}; 523 my $title = $stats->{+CS_STAT_TITLE};
520 $title =~ s/^Player: //; 524 $title =~ s/^Player: //;
521 $::STATWIDS->{title} ->set_text ("Title: " . $title); 525 $::STATWIDS->{title} ->set_text ("Title: " . $title);
522 526
534 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED}); 538 $::STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{+CS_STAT_SPEED});
535 $::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});
536 540
537 $self->update_weight; 541 $self->update_weight;
538 542
539 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$RES_TBL{$_}}) 543 $::STATWIDS->{"res_$_"}->set_text (sprintf "%d%%", $stats->{$RES_TBL{$_}})
540 for keys %RES_TBL; 544 for keys %RES_TBL;
541 545
542 my $sktbl = $::STATWIDS->{skill_tbl}; 546 my $sktbl = $::STATWIDS->{skill_tbl};
543 my @skills = keys %{ $self->{skill_info} }; 547 my @skills = keys %{ $self->{skill_info} };
544 548
635 my $sw = $self->{skillwid}{$idx}; 639 my $sw = $self->{skillwid}{$idx};
636 $sw->[0]->set_text (::formsep ($val->[1])); 640 $sw->[0]->set_text (::formsep ($val->[1]));
637 $sw->[1]->set_text ($val->[0] * 1); 641 $sw->[1]->set_text ($val->[0] * 1);
638 $sw->[2]->set_value (@$val); 642 $sw->[2]->set_value (@$val);
639 643
640 $::GAUGES->{sklprg}->set_label ("$name %d%%"); 644 $::GAUGES->{skillexp}->set_label ("$name %d%%");
641 $::GAUGES->{sklprg}->set_value (@$val); 645 $::GAUGES->{skillexp}->set_value (@$val);
642 } 646 }
643} 647}
644 648
645sub user_send { 649sub user_send {
646 my ($self, $command) = @_; 650 my ($self, $command) = @_;
985 989
986 my $tex = $self->{texture}[$tile] ||= 990 my $tex = $self->{texture}[$tile] ||=
987 new DC::Texture 991 new DC::Texture
988 tile => $tile, 992 tile => $tile,
989 image => $data, delete_image => 1, 993 image => $data, delete_image => 1,
990 minify => 1, mipmap => 1; 994 minify => 1;
991 995
992 if (my $cbs = delete $self->{tile_cb}{$tile}) { 996 if (my $cbs = delete $self->{tile_cb}{$tile}) {
993 $_->($tex) for @$cbs; 997 $_->($tex) for @$cbs;
994 } 998 }
995} 999}
1000 my ($self, $num, $cb) = @_; 1004 my ($self, $num, $cb) = @_;
1001 1005
1002 push @{$self->{face_cb}{$num}}, $cb; 1006 push @{$self->{face_cb}{$num}}, $cb;
1003 1007
1004 defined wantarray 1008 defined wantarray
1005 ? DC::guard { 1009 ? Guard::guard {
1006 @{$self->{face_cb}{$num}} 1010 @{$self->{face_cb}{$num}}
1007 = grep $_ != $cb, 1011 = grep $_ != $cb,
1008 @{$self->{face_cb}{$num}}; 1012 @{$self->{face_cb}{$num}};
1009 } 1013 }
1010 : () 1014 : ()
1038 my ($self, $flags, $prompt) = @_; 1042 my ($self, $flags, $prompt) = @_;
1039 1043
1040 $prompt = $LAST_QUERY unless length $prompt; 1044 $prompt = $LAST_QUERY unless length $prompt;
1041 $LAST_QUERY = $prompt; 1045 $LAST_QUERY = $prompt;
1042 1046
1043 $self->{query}-> ($self, $flags, $prompt); 1047 $self->{query}->($self, $flags, $prompt);
1044} 1048}
1045 1049
1046sub sanitise_xml($) { 1050sub sanitise_xml($) {
1047 local $_ = shift; 1051 local $_ = shift;
1048 1052
1110 $self->logprint ("msg: ", $text); 1114 $self->logprint ("msg: ", $text);
1111 return if $color < 0; # negative color == ignore if not understood 1115 return if $color < 0; # negative color == ignore if not understood
1112 1116
1113 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0]; 1117 my $fg = $CF_COLOR[$color & NDI_COLOR_MASK] || [1, 0, 0];
1114 1118
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 ({ 1119 ::message ({
1120 fg => $fg, 1120 fg => $fg,
1121 markup => $text, 1121 markup => $text,
1122 type => $type, 1122 type => $type,
1123 extra => [@extra], 1123 extra => [@extra],
1343sub update_server_info { 1343sub update_server_info {
1344 my ($self) = @_; 1344 my ($self) = @_;
1345 1345
1346 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>");
1347 1347
1348 my $version = JSON::XS->new->encode ($self->{s_version});
1349
1348 $::SERVER_INFO->set_markup ( 1350 $::SERVER_INFO->set_markup (
1349 "server <tt>$self->{host}:$self->{port}</tt>\n" 1351 "server <tt>$self->{host}:$self->{port}</tt>\n"
1350 . "protocol version <tt>$self->{version}</tt>\n" 1352 . "protocol version <tt>$version</tt>\n"
1351 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 1353 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
1352 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 1354 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1353 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" 1355 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
1354 . "editing support $yesno[!!$self->{editor_support}]\n" 1356 . "editing support $yesno[!!$self->{editor_support}]\n"
1355 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 1357 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1383 }); 1385 });
1384 1386
1385 $self->update_server_info; 1387 $self->update_server_info;
1386 1388
1387 $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;
1388 $self->send_command ("pickup $::CFG->{pickup}"); 1390 $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} 1391}
1393 1392
1394sub lookat { 1393sub lookat {
1395 my ($self, $x, $y) = @_; 1394 my ($self, $x, $y) = @_;
1396 1395
1398 $self->send_ext_req (lookat => $x, $y, sub { 1397 $self->send_ext_req (lookat => $x, $y, sub {
1399 my (%msg) = @_; 1398 my (%msg) = @_;
1400 1399
1401 if (exists $msg{npc_dialog}) { 1400 if (exists $msg{npc_dialog}) {
1402 # start npc chat dialog 1401 # start npc chat dialog
1403 $self->{npc_dialog} = new DC::NPCDialog:: 1402 $self->{w}{npc_dialog} = new DC::NPCDialog::
1404 token => $msg{npc_dialog}, 1403 token => $msg{npc_dialog},
1405 title => "$msg{npc_dialog}[0] (NPC)", 1404 title => "$msg{npc_dialog}[0] (NPC)",
1406 conn => $self, 1405 conn => $self,
1407 ; 1406 ;
1408 } 1407 }
1413} 1412}
1414 1413
1415sub destroy { 1414sub destroy {
1416 my ($self) = @_; 1415 my ($self) = @_;
1417 1416
1418 (delete $self->{npc_dialog})->destroy 1417 $_->destroy
1419 if $self->{npc_dialog}; 1418 for values %{ $self->{w} };
1420 1419
1421 $self->SUPER::destroy; 1420 $self->SUPER::destroy;
1422 1421
1423 %$self = (); 1422 %$self = ();
1424} 1423}
1578 1577
1579 #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
1580 1579
1581 if ($self->{conn}) { 1580 if ($self->{conn}) {
1582 $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};
1583 delete $self->{conn}{npc_dialog}; 1582 delete $self->{conn}{w}{npc_dialog};
1584 $self->{conn}->disconnect_ext ($self->{id}); 1583 $self->{conn}->disconnect_ext ($self->{id});
1585 } 1584 }
1586 1585
1587 $self->SUPER::destroy; 1586 $self->SUPER::destroy;
1588} 1587}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines