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.86 by root, Sun Oct 8 21:22:30 2006 UTC vs.
Revision 1.109 by root, Mon Jun 25 05:43:37 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;
14
15use Crossfire::Protocol::Base 0.95;
11 16
12use base 'Crossfire::Protocol::Base'; 17use base 'Crossfire::Protocol::Base';
13 18
14sub new { 19sub new {
15 my $class = shift; 20 my ($class, %arg) = @_;
16 21
17 my $self = $class->SUPER::new (@_, setup_req => { extmap => 1 }); 22 my $self = $class->SUPER::new (%arg,
23 setup_req => {
24 extmap => 1,
25 excmd => 1,
26 xwidget => 1,
27 %{$arg{setup_req} || {}},
28 },
29 );
18 30
19 $self->{map_widget}->clr_commands; 31 $self->{map_widget}->clr_commands;
20 32
21 my @cmd_help = map { 33 my @cmd_help = map {
22 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 34 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
33 for @args; 45 for @args;
34 46
35 map ["$cmd$_", $text], 47 map ["$cmd$_", $text],
36 sort { (length $a) <=> (length $b) } 48 sort { (length $a) <=> (length $b) }
37 @args 49 @args
38 } sort { $a->{par} <=> $b->{par} } 50 } sort { $a->{par} <=> $b->{par} }
39 CFPlus::Pod::find command => "*"; 51 CFPlus::Pod::find command => "*";
40 52
53 $self->connect_ext (event_capabilities => sub {
54 my ($cap) = @_;
55
56 if (my $ts = $cap->{tileset}) {
57 if (my ($default) = grep $_->[2] & 1, @$ts) {
58 $self->{tileset} = $default;
59 $self->{tilesize} = $default->[3];
60 $self->setup_req (tileset => $default->[0]);
61
62 my $w = int $self->{mapw} * 32 / $self->{tilesize};
63 my $h = int $self->{maph} * 32 / $self->{tilesize};
64
65 $self->setup_req (mapsize => "${w}x${h}");
66 }
67 }
68 });
69
70 $self->connect_ext (ws_n => sub {
71 my ($arg) = @_;
72
73 $self->{widgetset}{$arg{id}} = {
74 w => {},
75 };
76 });
77
78 $self->connect_ext (ws_d => sub {
79 my ($arg) = @_;
80
81 my $ws = delete $self->{widgetset}{$arg{id}}
82 or return;
83
84 $_->destroy
85 for values %{$ws->{w}};
86 });
87
88 $self->connect_ext (ws_c => sub {
89 my ($arg) = @_;
90
91 my $args = $arg->{args} || {};
92
93 for my $ev (grep /^on_/, keys %$args) {
94 $args->{$ev} = sub {
95 my $id = shift->{s_id};
96 $self->send_exti_msg (w_e => id => $id, name => $ev, args => \@_);
97
98 1
99 };
100 }
101
102 if (my $widget = eval {
103 "CFPlus::UI::$arg->{class}"->new (
104 %$args,
105 s_ws => $arg->{ws},
106 s_id => $arg->{id},
107 )
108 }
109 ) {
110 $self->{widget}{$arg->{id}}
111 = $self->{widgetset}{$arg->{ws}}{w}{$arg->{id}}
112 = $widget;
113
114 $widget->connect (on_destroy => sub {
115 my ($widget) = @_;
116
117 delete $self->{widget}{$widget->{s_id}};
118 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}};
119 });
120 } else {
121 warn "server failed creating client-side widget " . (CFPlus::to_json $arg) . ": $@\n";
122 $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy");
123 }
124 });
125
126 $self->connect_ext (w_c => sub {
127 my ($arg) = @_;
128
129 my $w = $self->{widget}{$arg->{id}}
130 or return;
131 my $m = $arg->{name};
132
133 my @a = map {
134 "HASH" eq ref && 1 == (scalar keys %$_) && exists $_->{__widget_ref__}
135 ? $self->{widget}{$_->{__widget_ref__}}
136 : $_
137 } @{ $arg->{args} || [] };
138
139 if (exists $arg->{rid}) {
140 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@a)]);
141 } else {
142 $w->$m (@a);
143 }
144 });
145
146 $self->connect_ext (w_s => sub {
147 my ($arg) = @_;
148
149 my $w = $self->{widget}{$arg->{id}}
150 or return;
151
152 $w->{$arg->{name}} = $arg->{value};
153 });
154
155 $self->connect_ext (w_g => sub {
156 my ($arg) = @_;
157
158 my $w = $self->{widget}{$arg->{id}}
159 or return;
160
161 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->{$arg->{name}}]);
162 });
163
164 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
165 for my $ws (values %{delete $self->{widgetset} || {}}) {
166 $_->destroy
167 for values %{delete $ws->{w} || {}};
168 }
169 });
170
41 $self->{map_widget}->add_command (@$_) 171 $self->{map_widget}->add_command (@$_)
42 for @cmd_help; 172 for @cmd_help;
43
44 $self->{noface} = new_from_file CFPlus::Texture
45 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
46 173
47 { 174 {
48 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture 175 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture
49 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1; 176 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
50 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 177 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
51 } 178 }
52 179
180 {
181 $self->{noface} = my $tex = new_from_file CFPlus::Texture
182 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
183 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
184 }
185
53 $self->{open_container} = 0; 186 $self->{open_container} = 0;
54 187
55 # "global"
56 $self->{tilecache} = CFPlus::db_table "tilecache"
57 or die "tilecache: unable to open database table";
58 $self->{facemap} = CFPlus::db_table "facemap"
59 or die "facemap: unable to open database table";
60
61 # per server 188 # per server
62 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}" 189 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
63 or die "mapcache_$self->{host}_$self->{port}: unable to open database table";
64 190
65 $self 191 $self
66} 192}
67 193
68sub logprint { 194sub logprint {
225 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 351 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
226 $::GAUGES->{food} ->set_value ($fo, $fo_m); 352 $::GAUGES->{food} ->set_value ($fo, $fo_m);
227 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 353 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
228 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 354 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))
229 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 355 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
230 my $rng = $stats->{+CS_STAT_RANGE}; 356 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
231 $rng =~ s/^Range: //; # thank you so much dear server
232 $::GAUGES->{range} ->set_text ("Rng: " . $rng);
233 my $title = $stats->{+CS_STAT_TITLE}; 357 my $title = $stats->{+CS_STAT_TITLE};
234 $title =~ s/^Player: //; 358 $title =~ s/^Player: //;
235 $::STATWIDS->{title} ->set_text ("Title: " . $title); 359 $::STATWIDS->{title} ->set_text ("Title: " . $title);
236 360
237 $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); 361 $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR});
286 if ($ev->{button} == 1) { 410 if ($ev->{button} == 1) {
287 $::CONN->user_send ("ready_skill $name"); 411 $::CONN->user_send ("ready_skill $name");
288 } elsif ($ev->{button} == 2) { 412 } elsif ($ev->{button} == 2) {
289 $::CONN->user_send ("use_skill $name"); 413 $::CONN->user_send ("use_skill $name");
290 } elsif ($ev->{button} == 3) { 414 } elsif ($ev->{button} == 3) {
415 my $shortname = CFPlus::shorten $name, 14;
291 (new CFPlus::UI::Menu 416 (new CFPlus::UI::Menu
292 items => [ 417 items => [
293 ["bind <i>ready_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], 418 ["bind <i>ready_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["ready_skill $name"] }],
294 ["bind <i>use_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["use_skill $name"]) }], 419 ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }],
295 ], 420 ],
296 )->popup ($ev); 421 )->popup ($ev);
297 } else { 422 } else {
298 return 0; 423 return 0;
299 } 424 }
316 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 441 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
317 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 442 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
318 } 443 }
319} 444}
320 445
446sub macro_send {
447 my ($self, $macro) = @_;
448
449 for my $cmd (@{ $macro->{action} }) {
450 $self->send_command ($cmd);
451 }
452}
453
321sub user_send { 454sub user_send {
322 my ($self, $command) = @_; 455 my ($self, $command) = @_;
323 456
457 $self->{record}->($command)
324 if ($self->{record}) { 458 if $self->{record};
325 push @{$self->{record}}, $command;
326 }
327 459
328 $self->logprint ("send: ", $command); 460 $self->logprint ("send: ", $command);
329 $self->send_command ($command); 461 $self->send_command ($command);
330 ::status ($command); 462 ::status ($command);
331} 463}
332 464
333sub start_record { 465sub record {
334 my ($self) = @_; 466 my ($self, $cb) = @_;
335 467
336 $self->{record} = []; 468 $self->{record} = $cb;
337}
338
339sub stop_record {
340 my ($self) = @_;
341 return delete $self->{record};
342} 469}
343 470
344sub map_scroll { 471sub map_scroll {
345 my ($self, $dx, $dy) = @_; 472 my ($self, $dx, $dy) = @_;
346 473
367 or return; 494 or return;
368 495
369 my ($hash, $x, $y, $w, $h) = @$map_info; 496 my ($hash, $x, $y, $w, $h) = @$map_info;
370 497
371 my $data = $self->{map}->get_rect ($x, $y, $w, $h); 498 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
372 $self->{mapcache}->put ($hash => Compress::LZF::compress $data); 499 CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { };
373 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 500 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
374} 501}
375 502
376sub map_clear { 503sub map_clear {
377 my ($self) = @_; 504 my ($self) = @_;
381 508
382 $self->{map}->clear; 509 $self->{map}->clear;
383 delete $self->{map_widget}{magicmap}; 510 delete $self->{map_widget}{magicmap};
384} 511}
385 512
513sub bg_fetch {
514 my ($self) = @_;
515
516 my $id;
517
518 do {
519 $id = pop @{$self->{bg_fetch}}
520 or return;
521 } while $self->{texture}[$id];
522
523 CFPlus::DB::get tilecache => $id, sub {
524 my ($data) = @_;
525
526 return unless $self->{map}; # stop when destroyed
527
528 $self->set_texture ($id => $data)
529 if defined $data;
530
531 $self->bg_fetch;
532 };
533}
386 534
387sub load_map($$$) { 535sub load_map($$$) {
388 my ($self, $hash, $x, $y) = @_; 536 my ($self, $hash, $x, $y) = @_;
389 537
390 if (defined (my $data = $self->{mapcache}->get ($hash))) { 538 my $gen = $self->{map_change_gen};
539
540 CFPlus::DB::get $self->{mapcache} => $hash, sub {
541 return unless $gen == $self->{map_change_gen};
542
543 my ($data) = @_;
544
545 if (defined $data) {
391 $data = Compress::LZF::decompress $data; 546 $data = Compress::LZF::decompress $data;
392 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 547 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
393 for my $id ($self->{map}->set_rect ($x, $y, $data)) {
394 my $data = $self->{tilecache}->get ($id)
395 or next;
396 548
397 $self->set_texture ($id => $data); 549 my $inprogress = @{ $self->{bg_fetch} || [] };
550 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data);
551 $self->bg_fetch unless $inprogress;
398 } 552 }
399 } 553 };
400} 554}
401 555
402# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 556# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
403# (server resource,s latency, bandwidth), so this hack is warranted. 557# (server resource,s latency, bandwidth), so this hack is warranted.
404# the right fix is to make real tiled maps with an overview file 558# the right fix is to make real tiled maps with an overview file
468 622
469 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 623 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
470 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 624 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
471 625
472 } else { 626 } else {
627 my $gen = $self->{map_change_gen};
473 $self->send_mapinfo ("spatial $path$tile", sub { 628 $self->send_mapinfo ("spatial $path$tile", sub {
629 return unless $gen == $self->{map_change_gen};
630
474 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 631 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
475 632
476 return if $mode ne "spatial"; 633 return if $mode ne "spatial";
477 634
478 $x += $self->{map}->ox; 635 $x += $self->{map}->ox;
492 649
493sub map_change { 650sub map_change {
494 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 651 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
495 652
496 $self->flush_map; 653 $self->flush_map;
654
655 ++$self->{map_change_gen};
497 656
498 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 657 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
499 658
500 my $mapmapw = $self->{mapmap}->{w}; 659 my $mapmapw = $self->{mapmap}->{w};
501 my $mapmaph = $self->{mapmap}->{h}; 660 my $mapmaph = $self->{mapmap}->{h};
518 $self->load_map ($hash, $x, $y); 677 $self->load_map ($hash, $x, $y);
519 $self->flood_fill (0, 0, 0, "", $hash, $flags); 678 $self->flood_fill (0, 0, 0, "", $hash, $flags);
520} 679}
521 680
522sub face_find { 681sub face_find {
523 my ($self, $facenum, $face) = @_; 682 my ($self, $facenum, $face, $cb) = @_;
524 683
525 my $hash = "$face->{chksum},$face->{name}"; 684 my $hash = "$face->{chksum},$face->{name}";
526 685
527 my $id = $self->{facemap}->get ($hash); 686 my $id = CFPlus::DB::get_tile_id_sync $hash;
528 687
529 unless ($id) {
530 # create new id for face
531 # I love transactions
532 for (1..100) {
533 my $txn = $CFPlus::DB_ENV->txn_begin;
534 my $status = $self->{facemap}->db_get (id => $id);
535 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
536 $id = ($id || 64) + 1;
537 if ($self->{facemap}->put (id => $id) == 0
538 && $self->{facemap}->put ($hash => $id) == 0) {
539 $txn->txn_commit;
540
541 goto gotid;
542 }
543 }
544 $txn->txn_abort;
545 }
546
547 CFPlus::fatal "maximum number of transaction retries reached - database problems?";
548 }
549
550gotid:
551 $face->{id} = $id; 688 $face->{id} = $id;
552 $self->{map}->set_face ($facenum => $id);
553 $self->{faceid}[$facenum] = $id;#d# 689 $self->{faceid}[$facenum] = $id;
554 690
555 my $face = $self->{tilecache}->get ($id); 691 $self->{map}->set_tileid ($facenum => $id);
556 692
557 if ($face) { 693 CFPlus::DB::get tilecache => $id, $cb;
558 #$self->face_prefetch;
559 $face
560 } else {
561 my $tex = $self->{noface};
562 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
563 undef
564 };
565} 694}
566 695
567sub face_update { 696sub face_update {
568 my ($self, $facenum, $face, $changed) = @_; 697 my ($self, $facenum, $face, $changed) = @_;
569 698
570 $self->{tilecache}->put ($face->{id} => $face->{image}) if $changed; 699 CFPlus::DB::put tilecache => $face->{id} => $face->{image}, sub { }
700 if $changed;
571 701
572 $self->set_texture ($face->{id} => delete $face->{image}); 702 $self->set_texture ($face->{id} => delete $face->{image});
703}
704
705sub smooth_update {
706 my ($self, $facenum, $face) = @_;
707
708 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
573} 709}
574 710
575sub set_texture { 711sub set_texture {
576 my ($self, $id, $data) = @_; 712 my ($self, $id, $data) = @_;
577 713
578 $self->{texture}[$id] ||= do { 714 $self->{texture}[$id] = my $tex =
579 my $tex =
580 new_from_image CFPlus::Texture 715 new_from_image CFPlus::Texture
581 $data, minify => 1, mipmap => 1; 716 $data, minify => 1, mipmap => 1;
582 717
583 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 718 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
584 $self->{map_widget}->update; 719 $self->{map_widget}->update;
585
586 $tex
587 };
588} 720}
589 721
590sub sound_play { 722sub sound_play {
591 my ($self, $x, $y, $soundnum, $type) = @_; 723 my ($self, $x, $y, $soundnum, $type) = @_;
592 724
602 $LAST_QUERY = $prompt; 734 $LAST_QUERY = $prompt;
603 735
604 $self->{query}-> ($self, $flags, $prompt); 736 $self->{query}-> ($self, $flags, $prompt);
605} 737}
606 738
607sub drawinfo { 739sub sanitise_xml($) {
608 my ($self, $color, $text) = @_; 740 local $_ = shift;
609 741
610 my @color = ( 742 # we now weed out all tags we do not support
743 s%<(?!/?i>|/?u>|/?b>|fg |/fg>)%&lt;%g;
744 # now all entities
745 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
746
747 # handle some elements
748 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
749 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
750
751 $_
752}
753
754our %NAME_TO_COLOR = (
755 black => 0,
756 white => 1,
757 darkblue => 2,
758 red => 3,
759 orange => 4,
760 lightblue => 5,
761 darkorange => 6,
762 green => 7,
763 darkgreen => 8,
764 grey => 9,
765 brown => 10,
766 yellow => 11,
767 tan => 12,
768);
769
770our @CF_COLOR = (
611 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 771 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
612 [1.00, 1.00, 1.00], 772 [1.00, 1.00, 1.00],
613 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] 773 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
614 [1.00, 0.00, 0.00], 774 [1.00, 0.00, 0.00],
615 [1.00, 0.54, 0.00], 775 [1.00, 0.54, 0.00],
616 [0.11, 0.56, 1.00], 776 [0.11, 0.56, 1.00],
617 [0.93, 0.46, 0.00], 777 [0.93, 0.46, 0.00],
618 [0.18, 0.54, 0.34], 778 [0.18, 0.54, 0.34],
619 [0.56, 0.73, 0.56], 779 [0.56, 0.73, 0.56],
620 [0.80, 0.80, 0.80], 780 [0.80, 0.80, 0.80],
621 [0.75, 0.61, 0.20], 781 [0.75, 0.61, 0.20],
622 [0.99, 0.77, 0.26], 782 [0.99, 0.77, 0.26],
623 [0.74, 0.65, 0.41], 783 [0.74, 0.65, 0.41],
624 ); 784);
625 785
786sub msg {
787 my ($self, $color, $type, $text, @extra) = @_;
788
789 $text = sanitise_xml $text;
790
791 if (my $cb = $self->{cb_msg}{$type}) {
792 $_->($self, $color, $type, $text, @extra) for values %$cb;
793 } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) {
794 $type =~ s/-/_/g;
795 $self->{$type} = $text;
796 } else {
626 $self->logprint ("info: ", $text); 797 $self->logprint ("msg: ", $text);
798 return if $color < 0; # negative color == ignore if not understood
627 799
800 my $fg = $CF_COLOR[$color % @CF_COLOR];
801
628 # try to create single paragraphs of multiple lines sent by the server 802 ## try to create single paragraphs of multiple lines sent by the server
803 # no longer neecssary with TRT servers
629 $text =~ s/(?<=\S)\n(?=\w)/ /g; 804 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
630 805
631 $text = CFPlus::asxml $text;
632 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
633 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
634
635 ::message ({ fg => $color[$color], markup => $_ }) 806 ::message ({ fg => $fg, markup => $_ })
636 for split /\n/, $text; 807 for split /\n/, $text;
637 808
638 $self->{statusbox}->add ($text, 809 $self->{statusbox}->add ($text,
639 group => $text, 810 group => $text,
640 fg => $color[$color], 811 fg => $fg,
641 timeout => $color >= 2 ? 180 : 10, 812 timeout => $color >= 2 ? 180 : 10,
642 tooltip_font => $::FONT_FIXED, 813 tooltip_font => $::FONT_FIXED,
643 ); 814 );
644} 815 }
645
646sub drawextinfo {
647 my ($self, $color, $type, $subtype, $message) = @_;
648
649 $self->drawinfo ($color, $message);
650} 816}
651 817
652sub spell_add { 818sub spell_add {
653 my ($self, $spell) = @_; 819 my ($self, $spell) = @_;
654 820
655 # try to create single paragraphs out of the multiple lines sent by the server 821 # try to create single paragraphs out of the multiple lines sent by the server
656 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; 822 $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g;
657 $spell->{message} =~ s/\n+$//; 823 $spell->{message} =~ s/\n+$//;
658 $spell->{message} ||= "Server did not provide a description for this spell."; 824 $spell->{message} ||= "Server did not provide a description for this spell.";
659 825
660 $::SPELL_PAGE->add_spell ($spell); 826 $::SPELL_LIST->add_spell ($spell);
661 827
662 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); 828 $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message});
663 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); 829 $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message});
664} 830}
665 831
666sub spell_delete { 832sub spell_delete {
667 my ($self, $spell) = @_; 833 my ($self, $spell) = @_;
668 834
669 $::SPELL_PAGE->remove_spell ($spell); 835 $::SPELL_LIST->remove_spell ($spell);
836}
837
838sub setup {
839 my ($self, $setup) = @_;
840
841 $self->{map_widget}->set_tilesize ($self->{tilesize});
842 $::MAP->resize ($self->{mapw}, $self->{maph});
670} 843}
671 844
672sub addme_success { 845sub addme_success {
673 my ($self) = @_; 846 my ($self) = @_;
674 847
880 $::SERVER_INFO->set_markup ( 1053 $::SERVER_INFO->set_markup (
881 "server <tt>$self->{host}:$self->{port}</tt>\n" 1054 "server <tt>$self->{host}:$self->{port}</tt>\n"
882 . "protocol version <tt>$self->{version}</tt>\n" 1055 . "protocol version <tt>$self->{version}</tt>\n"
883 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 1056 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
884 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 1057 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1058 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
885 . "editing support $yesno[!!$self->{editor_support}]\n" 1059 . "editing support $yesno[!!$self->{editor_support}]\n"
886 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 1060 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1061 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
887 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 1062 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
888 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1063 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
889 . "map size $self->{mapw}×$self->{maph}\n" 1064 . "map size $self->{mapw}×$self->{maph}\n"
890 ); 1065 );
1066
1067 ::setup_build_button ($self->{editor_support}->{builder_ui});
891} 1068}
892 1069
893sub logged_in { 1070sub logged_in {
894 my ($self) = @_; 1071 my ($self) = @_;
895 1072
911 1088
912 $self->update_server_info; 1089 $self->update_server_info;
913 1090
914 $self->send_command ("output-sync $::CFG->{output_sync}"); 1091 $self->send_command ("output-sync $::CFG->{output_sync}");
915 $self->send_command ("output-count $::CFG->{output_count}"); 1092 $self->send_command ("output-count $::CFG->{output_count}");
1093 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
916 $self->send_command ("pickup $::CFG->{pickup}"); 1094 $self->send_command ("pickup $::CFG->{pickup}");
1095}
1096
1097sub buildat {
1098 my ($self, $builditem, $x, $y) = @_;
1099
1100 if ($self->{cfplus_ext}) {
1101 $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem));
1102 }
917} 1103}
918 1104
919sub lookat { 1105sub lookat {
920 my ($self, $x, $y) = @_; 1106 my ($self, $x, $y) = @_;
921 1107
964 kw => { hi => 0, yes => 0, no => 0 }, 1150 kw => { hi => 0, yes => 0, no => 0 },
965 has_close_button => 1, 1151 has_close_button => 1,
966 @_, 1152 @_,
967 ); 1153 );
968 1154
969 Scalar::Util::weaken (my $this = $self); 1155 CFPlus::weaken (my $this = $self);
970 1156
971 $self->connect (delete => sub { $this->destroy; 1 }); 1157 $self->connect (delete => sub { $this->destroy; 1 });
972 1158
973 # better use a pane... 1159 # better use a pane...
974 $self->add (my $hbox = new CFPlus::UI::HBox); 1160 $self->add (my $hbox = new CFPlus::UI::HBox);
1018}; 1204};
1019 1205
1020sub update_options { 1206sub update_options {
1021 my ($self) = @_; 1207 my ($self) = @_;
1022 1208
1023 Scalar::Util::weaken $self; 1209 CFPlus::weaken $self;
1024 1210
1025 $self->{options}->clear; 1211 $self->{options}->clear;
1026 $self->{options}->add ($self->{bye_button}); 1212 $self->{options}->add ($self->{bye_button});
1027 1213
1028 for my $kw (sort keys %{ $self->{kw} }) { 1214 for my $kw (sort keys %{ $self->{kw} }) {
1037} 1223}
1038 1224
1039sub feed { 1225sub feed {
1040 my ($self, $msg) = @_; 1226 my ($self, $msg) = @_;
1041 1227
1042 Scalar::Util::weaken $self; 1228 CFPlus::weaken $self;
1043 1229
1044 if ($msg->{msgtype} eq "reply") { 1230 if ($msg->{msgtype} eq "reply") {
1045 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1231 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1046 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1232 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1047 1233
1048 my $text = "\n" . CFPlus::asxml $msg->{msg}; 1234 my $text = "\n" . CFPlus::Protocol::sanitise_xml $msg->{msg};
1049 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; 1235 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} };
1050 my @link; 1236 my @link;
1051 $text =~ s{ 1237 $text =~ s{
1052 ($match) 1238 ($match)
1053 }{ 1239 }{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines