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.90 by root, Wed Dec 6 00:15:12 2006 UTC vs.
Revision 1.96 by root, Fri Apr 6 07:45:35 2007 UTC

4use strict; 4use strict;
5 5
6use Crossfire::Protocol::Constants; 6use Crossfire::Protocol::Constants;
7 7
8use CFPlus; 8use CFPlus;
9use CFPlus::DB;
9use CFPlus::UI; 10use CFPlus::UI;
10use CFPlus::Pod; 11use CFPlus::Pod;
12use CFPlus::Macro;
13use CFPlus::Item;
11 14
12use Crossfire::Protocol::Base 0.95; 15use Crossfire::Protocol::Base 0.95;
13 16
14use base 'Crossfire::Protocol::Base'; 17use base 'Crossfire::Protocol::Base';
15 18
35 for @args; 38 for @args;
36 39
37 map ["$cmd$_", $text], 40 map ["$cmd$_", $text],
38 sort { (length $a) <=> (length $b) } 41 sort { (length $a) <=> (length $b) }
39 @args 42 @args
40 } sort { $a->{par} <=> $b->{par} } 43 } sort { $a->{par} <=> $b->{par} }
41 CFPlus::Pod::find command => "*"; 44 CFPlus::Pod::find command => "*";
42 45
46 $self->connect_ext (event_capabilities => sub {
47 my ($cap) = @_;
48
49 if (my $ts = $cap->{tileset}) {
50 if (my ($default) = grep $_->[2] & 1, @$ts) {
51 $self->{tileset} = $default;
52 $self->{tilesize} = $default->[3];
53 $self->setup_req (tileset => $default->[0]);
54
55 my $w = int $self->{mapw} * 32 / $self->{tilesize};
56 my $h = int $self->{maph} * 32 / $self->{tilesize};
57
58 $self->setup_req (mapsize => "${w}x${h}");
59 }
60 }
61 });
62
43 $self->{map_widget}->add_command (@$_) 63 $self->{map_widget}->add_command (@$_)
44 for @cmd_help; 64 for @cmd_help;
45
46 $self->{noface} = new_from_file CFPlus::Texture
47 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
48 65
49 { 66 {
50 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture 67 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture
51 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1; 68 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
52 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 69 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
53 } 70 }
54 71
72 {
73 $self->{noface} = my $tex = new_from_file CFPlus::Texture
74 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
75 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
76 }
77
55 $self->{open_container} = 0; 78 $self->{open_container} = 0;
56 79
57 # "global"
58 $self->{tilecache} = CFPlus::db_table "tilecache"
59 or die "tilecache: unable to open database table";
60 $self->{facemap} = CFPlus::db_table "facemap"
61 or die "facemap: unable to open database table";
62
63 # per server 80 # per server
64 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}" 81 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
65 or die "mapcache_$self->{host}_$self->{port}: unable to open database table";
66 82
67 $self 83 $self
68} 84}
69 85
70sub logprint { 86sub logprint {
291 $::CONN->user_send ("use_skill $name"); 307 $::CONN->user_send ("use_skill $name");
292 } elsif ($ev->{button} == 3) { 308 } elsif ($ev->{button} == 3) {
293 my $shortname = CFPlus::shorten $name, 14; 309 my $shortname = CFPlus::shorten $name, 14;
294 (new CFPlus::UI::Menu 310 (new CFPlus::UI::Menu
295 items => [ 311 items => [
296 ["bind <i>ready_skill $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], 312 ["bind <i>ready_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["ready_skill $name"] }],
297 ["bind <i>use_skill $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["use_skill $name"]) }], 313 ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }],
298 ], 314 ],
299 )->popup ($ev); 315 )->popup ($ev);
300 } else { 316 } else {
301 return 0; 317 return 0;
302 } 318 }
319 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 335 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
320 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 336 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
321 } 337 }
322} 338}
323 339
340sub macro_send {
341 my ($self, $macro) = @_;
342
343 for my $cmd (@{ $macro->{action} }) {
344 $self->send_command ($cmd);
345 }
346}
347
324sub user_send { 348sub user_send {
325 my ($self, $command) = @_; 349 my ($self, $command) = @_;
326 350
327 push @{$self->{record}}, $command 351 $self->{record}->($command)
328 if $self->{record}; 352 if $self->{record};
329 353
330 $self->logprint ("send: ", $command); 354 $self->logprint ("send: ", $command);
331 $self->send_command ($command); 355 $self->send_command ($command);
332 ::status ($command); 356 ::status ($command);
333} 357}
334 358
335sub start_record { 359sub record {
336 my ($self) = @_; 360 my ($self, $cb) = @_;
337 361
338 $self->{record} = []; 362 $self->{record} = $cb;
339}
340
341sub stop_record {
342 my ($self) = @_;
343 return delete $self->{record};
344} 363}
345 364
346sub map_scroll { 365sub map_scroll {
347 my ($self, $dx, $dy) = @_; 366 my ($self, $dx, $dy) = @_;
348 367
369 or return; 388 or return;
370 389
371 my ($hash, $x, $y, $w, $h) = @$map_info; 390 my ($hash, $x, $y, $w, $h) = @$map_info;
372 391
373 my $data = $self->{map}->get_rect ($x, $y, $w, $h); 392 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
374 $self->{mapcache}->put ($hash => Compress::LZF::compress $data); 393 CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { };
375 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 394 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
376} 395}
377 396
378sub map_clear { 397sub map_clear {
379 my ($self) = @_; 398 my ($self) = @_;
387 406
388 407
389sub load_map($$$) { 408sub load_map($$$) {
390 my ($self, $hash, $x, $y) = @_; 409 my ($self, $hash, $x, $y) = @_;
391 410
392 if (defined (my $data = $self->{mapcache}->get ($hash))) { 411 CFPlus::DB::get $self->{mapcache} => $hash, sub {
412 my ($data) = @_;
413
414 if (defined $data) {
393 $data = Compress::LZF::decompress $data; 415 $data = Compress::LZF::decompress $data;
394 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 416 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
395 for my $id ($self->{map}->set_rect ($x, $y, $data)) { 417 for my $id ($self->{map}->set_rect ($x, $y, $data)) {
396 my $data = $self->{tilecache}->get ($id) 418 CFPlus::DB::get tilecache => $id, sub {
397 or next; 419 my ($data) = @_;
398 420
399 $self->set_texture ($id => $data); 421 $self->set_texture ($id => $data)
422 if defined $data;
423 };
424 }
400 } 425 }
401 } 426 };
402} 427}
403 428
404# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 429# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
405# (server resource,s latency, bandwidth), so this hack is warranted. 430# (server resource,s latency, bandwidth), so this hack is warranted.
406# the right fix is to make real tiled maps with an overview file 431# the right fix is to make real tiled maps with an overview file
520 $self->load_map ($hash, $x, $y); 545 $self->load_map ($hash, $x, $y);
521 $self->flood_fill (0, 0, 0, "", $hash, $flags); 546 $self->flood_fill (0, 0, 0, "", $hash, $flags);
522} 547}
523 548
524sub face_find { 549sub face_find {
525 my ($self, $facenum, $face) = @_; 550 my ($self, $facenum, $face, $cb) = @_;
526 551
527 my $hash = "$face->{chksum},$face->{name}"; 552 my $hash = "$face->{chksum},$face->{name}";
528 553
529 my $id = $self->{facemap}->get ($hash); 554 my $id = CFPlus::DB::get_tile_id_sync $hash;
530 555
531 unless ($id) {
532 # create new id for face
533 # I love transactions
534 for (1..100) {
535 my $txn = $CFPlus::DB_ENV->txn_begin;
536 my $status = $self->{facemap}->db_get (id => $id);
537 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
538 $id = ($id || 64) + 1;
539 if ($self->{facemap}->put (id => $id) == 0
540 && $self->{facemap}->put ($hash => $id) == 0) {
541 $txn->txn_commit;
542
543 goto gotid;
544 }
545 }
546 $txn->txn_abort;
547 }
548
549 CFPlus::fatal "maximum number of transaction retries reached - database problems?";
550 }
551
552gotid:
553 $face->{id} = $id; 556 $face->{id} = $id;
554 $self->{map}->set_face ($facenum => $id);
555 $self->{faceid}[$facenum] = $id;#d# 557 $self->{faceid}[$facenum] = $id;
556 558
557 my $face = $self->{tilecache}->get ($id); 559 $self->{map}->set_tileid ($facenum => $id);
558 560
559 if ($face) { 561 CFPlus::DB::get tilecache => $id, $cb;
560 #$self->face_prefetch;
561 $face
562 } else {
563 my $tex = $self->{noface};
564 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
565 undef
566 };
567} 562}
568 563
569sub face_update { 564sub face_update {
570 my ($self, $facenum, $face, $changed) = @_; 565 my ($self, $facenum, $face, $changed) = @_;
571 566
572 $self->{tilecache}->put ($face->{id} => $face->{image}) if $changed; 567 CFPlus::DB::put tilecache => $face->{id} => $face->{image}, sub { }
568 if $changed;
573 569
574 $self->set_texture ($face->{id} => delete $face->{image}); 570 $self->set_texture ($face->{id} => delete $face->{image});
575} 571}
576 572
577sub set_texture { 573sub set_texture {
623 [0.75, 0.61, 0.20], 619 [0.75, 0.61, 0.20],
624 [0.99, 0.77, 0.26], 620 [0.99, 0.77, 0.26],
625 [0.74, 0.65, 0.41], 621 [0.74, 0.65, 0.41],
626 ); 622 );
627 623
624 my $fg = $color[$color % @color];
625
628 $self->logprint ("info: ", $text); 626 $self->logprint ("info: ", $text);
629 627
630 # try to create single paragraphs of multiple lines sent by the server 628 # try to create single paragraphs of multiple lines sent by the server
631 $text =~ s/(?<=\S)\n(?=\w)/ /g; 629 $text =~ s/(?<=\S)\n(?=\w)/ /g;
632 630
633 $text = CFPlus::asxml $text; 631 $text = CFPlus::asxml $text;
634 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g; 632 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
635 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g; 633 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
636 634
637 ::message ({ fg => $color[$color], markup => $_ }) 635 ::message ({ fg => $fg, markup => $_ })
638 for split /\n/, $text; 636 for split /\n/, $text;
639 637
640 $self->{statusbox}->add ($text, 638 $self->{statusbox}->add ($text,
641 group => $text, 639 group => $text,
642 fg => $color[$color], 640 fg => $fg,
643 timeout => $color >= 2 ? 180 : 10, 641 timeout => $color >= 2 ? 180 : 10,
644 tooltip_font => $::FONT_FIXED, 642 tooltip_font => $::FONT_FIXED,
645 ); 643 );
646} 644}
647 645
672} 670}
673 671
674sub setup { 672sub setup {
675 my ($self, $setup) = @_; 673 my ($self, $setup) = @_;
676 674
675 $self->{map_widget}->set_tilesize ($self->{tilesize});
677 $::MAP->resize ($self->{mapw}, $self->{maph}); 676 $::MAP->resize ($self->{mapw}, $self->{maph});
678} 677}
679 678
680sub addme_success { 679sub addme_success {
681 my ($self) = @_; 680 my ($self) = @_;
921 920
922 $self->update_server_info; 921 $self->update_server_info;
923 922
924 $self->send_command ("output-sync $::CFG->{output_sync}"); 923 $self->send_command ("output-sync $::CFG->{output_sync}");
925 $self->send_command ("output-count $::CFG->{output_count}"); 924 $self->send_command ("output-count $::CFG->{output_count}");
925 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
926 $self->send_command ("pickup $::CFG->{pickup}"); 926 $self->send_command ("pickup $::CFG->{pickup}");
927} 927}
928 928
929sub buildat { 929sub buildat {
930 my ($self, $builditem, $x, $y) = @_; 930 my ($self, $builditem, $x, $y) = @_;
982 kw => { hi => 0, yes => 0, no => 0 }, 982 kw => { hi => 0, yes => 0, no => 0 },
983 has_close_button => 1, 983 has_close_button => 1,
984 @_, 984 @_,
985 ); 985 );
986 986
987 Scalar::Util::weaken (my $this = $self); 987 CFPlus::weaken (my $this = $self);
988 988
989 $self->connect (delete => sub { $this->destroy; 1 }); 989 $self->connect (delete => sub { $this->destroy; 1 });
990 990
991 # better use a pane... 991 # better use a pane...
992 $self->add (my $hbox = new CFPlus::UI::HBox); 992 $self->add (my $hbox = new CFPlus::UI::HBox);
1036}; 1036};
1037 1037
1038sub update_options { 1038sub update_options {
1039 my ($self) = @_; 1039 my ($self) = @_;
1040 1040
1041 Scalar::Util::weaken $self; 1041 CFPlus::weaken $self;
1042 1042
1043 $self->{options}->clear; 1043 $self->{options}->clear;
1044 $self->{options}->add ($self->{bye_button}); 1044 $self->{options}->add ($self->{bye_button});
1045 1045
1046 for my $kw (sort keys %{ $self->{kw} }) { 1046 for my $kw (sort keys %{ $self->{kw} }) {
1055} 1055}
1056 1056
1057sub feed { 1057sub feed {
1058 my ($self, $msg) = @_; 1058 my ($self, $msg) = @_;
1059 1059
1060 Scalar::Util::weaken $self; 1060 CFPlus::weaken $self;
1061 1061
1062 if ($msg->{msgtype} eq "reply") { 1062 if ($msg->{msgtype} eq "reply") {
1063 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1063 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1064 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1064 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1065 1065

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines