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.115 by root, Thu Jul 12 19:10:52 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
16sub new { 19sub new {
17 my $class = shift; 20 my ($class, %arg) = @_;
18 21
19 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 ywidget => 1,
27 %{$arg{setup_req} || {}},
28 },
29 );
20 30
21 $self->{map_widget}->clr_commands; 31 $self->{map_widget}->clr_commands;
22 32
23 my @cmd_help = map { 33 my @cmd_help = map {
24 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x 34 $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x
35 for @args; 45 for @args;
36 46
37 map ["$cmd$_", $text], 47 map ["$cmd$_", $text],
38 sort { (length $a) <=> (length $b) } 48 sort { (length $a) <=> (length $b) }
39 @args 49 @args
40 } sort { $a->{par} <=> $b->{par} } 50 } sort { $a->{par} <=> $b->{par} }
41 CFPlus::Pod::find command => "*"; 51 CFPlus::Pod::find command => "*";
42 52
53 $self->connect_ext (event_music => sub {
54 my ($ev) = @_;
55
56 return unless $::CFG->{bgm_enable};
57
58 my $faces = $ev->{faces};
59 my @songs;
60
61 # request music from server if appropriate
62 if (my $faces = $ev->{faces}) {
63 for (@$faces) {
64 my ($face, $pri, $chksum) = @$_;
65 utf8::downgrade $chksum;
66
67 $chksum = unpack "H*", $chksum;
68 $self->{music_map}{$face} = $chksum;
69
70 # check if already cached
71 CFPlus::DB::get resmap => $chksum, sub {
72 my ($meta) = @_;
73
74 if (defined $meta) {
75 $self->{music_meta}{$chksum} = $self->{json_coder}->decode ($meta);
76 } else {
77 ::message ({ markup => "starting to download song #$face/$pri, check your output-rate setting if your connection gets laggy." });
78 $self->ask_face ($face, -100 - $pri, undef, sub {
79 my $len = length $_[1];
80 my ($meta, $data) = unpack "(w/a*)*", $_[1];
81
82 CFPlus::DB::write_file $chksum, $data, sub { };
83 CFPlus::DB::put resmap => $chksum => $meta, sub { };
84
85 $self->{music_meta}{$chksum} = $self->{json_coder}->decode ($meta);
86 ::message ({ markup => "downloaded song #$face, size $len octets" });
87
88 &::audio_music_set ($self->{songs});
89 });
90 }
91 }
92 }
93 }
94
95 if (my $play = $ev->{play}) {
96 &::audio_music_set ($self->{songs} = [map $self->{music_map}{$_}, @$play]);
97 use Data::Dumper;
98 warn Dumper $self->{songs};#d#
99 }
100 });
101
102 $self->connect_ext (event_capabilities => sub {
103 my ($cap) = @_;
104
105 if (my $ts = $cap->{tileset}) {
106 if (my ($default) = grep $_->[2] & 1, @$ts) {
107 $self->{tileset} = $default;
108 $self->{tilesize} = $default->[3];
109 $self->setup_req (tileset => $default->[0]);
110
111 my $w = int $self->{mapw} * 32 / $self->{tilesize};
112 my $h = int $self->{maph} * 32 / $self->{tilesize};
113
114 $self->setup_req (mapsize => "${w}x${h}");
115 }
116 }
117 });
118
119 $self->{json_coder}
120 ->convert_blessed
121 ->filter_json_single_key_object (__widget_ref__ => sub {
122 $self->{widget}{$_[0]}
123 });
124
125 $self->connect_ext (ws_n => sub {
126 my ($arg) = @_;
127
128 $self->{widgetset}{$arg{id}} = {
129 w => {},
130 };
131 });
132
133 $self->connect_ext (ws_d => sub {
134 my ($arg) = @_;
135
136 my $ws = delete $self->{widgetset}{$arg{id}}
137 or return;
138
139 $_->destroy
140 for values %{$ws->{w}};
141 });
142
143 $self->connect_ext (ws_c => sub {
144 my ($arg) = @_;
145
146 my $args = $arg->{args} || {};
147
148 for my $ev (grep /^on_/, keys %$args) {
149 $args->{$ev} = sub {
150 my $id = shift->{s_id};
151 $self->send_exti_msg (w_e => id => $id, name => $ev, args => \@_);
152
153 1
154 };
155 }
156
157 if (my $widget = eval {
158 local $SIG{__DIE__};
159 "CFPlus::UI::$arg->{class}"->new (
160 %$args,
161 s_ws => $arg->{ws},
162 s_id => $arg->{id},
163 )
164 }
165 ) {
166 $self->{widget}{$arg->{id}}
167 = $self->{widgetset}{$arg->{ws}}{w}{$arg->{id}}
168 = $widget;
169
170 $widget->connect (on_destroy => sub {
171 my ($widget) = @_;
172
173 delete $self->{widget}{$widget->{s_id}};
174 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}};
175 });
176 } else {
177 warn "server failed creating client-side widget " . (CFPlus::to_json $arg) . ": $@\n";
178 $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy");
179 }
180 });
181
182 $self->connect_ext (w_c => sub {
183 my ($arg) = @_;
184
185 my $w = $self->{widget}{$arg->{id}}
186 or return;
187 my $m = $arg->{name};
188
189 my $a = $arg->{args} || [];
190
191 if (exists $arg->{rid}) {
192 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@$a)]);
193 } else {
194 $w->$m (@$a);
195 }
196 });
197
198 $self->connect_ext (w_s => sub {
199 my ($arg) = @_;
200
201 my $w = $self->{widget}{$arg->{id}}
202 or return;
203
204 $w->{$arg->{name}} = $arg->{value};
205 });
206
207 $self->connect_ext (w_g => sub {
208 my ($arg) = @_;
209
210 my $w = $self->{widget}{$arg->{id}}
211 or return;
212
213 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->{$arg->{name}}]);
214 });
215
216 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
217 for my $ws (values %{delete $self->{widgetset} || {}}) {
218 $_->destroy
219 for values %{delete $ws->{w} || {}};
220 }
221 });
222
43 $self->{map_widget}->add_command (@$_) 223 $self->{map_widget}->add_command (@$_)
44 for @cmd_help; 224 for @cmd_help;
45
46 $self->{noface} = new_from_file CFPlus::Texture
47 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
48 225
49 { 226 {
50 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture 227 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture
51 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1; 228 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
52 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 229 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
53 } 230 }
54 231
232 {
233 $self->{noface} = my $tex = new_from_file CFPlus::Texture
234 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
235 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
236 }
237
55 $self->{open_container} = 0; 238 $self->{open_container} = 0;
56 239
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 240 # per server
64 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}" 241 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
65 or die "mapcache_$self->{host}_$self->{port}: unable to open database table";
66 242
67 $self 243 $self
68} 244}
69 245
70sub logprint { 246sub logprint {
227 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 403 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
228 $::GAUGES->{food} ->set_value ($fo, $fo_m); 404 $::GAUGES->{food} ->set_value ($fo, $fo_m);
229 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 405 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
230 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 406 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))
231 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 407 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
232 my $rng = $stats->{+CS_STAT_RANGE}; 408 $::GAUGES->{range} ->set_text ($stats->{+CS_STAT_RANGE});
233 $rng =~ s/^Range: //; # thank you so much dear server
234 $::GAUGES->{range} ->set_text ("Rng: " . $rng);
235 my $title = $stats->{+CS_STAT_TITLE}; 409 my $title = $stats->{+CS_STAT_TITLE};
236 $title =~ s/^Player: //; 410 $title =~ s/^Player: //;
237 $::STATWIDS->{title} ->set_text ("Title: " . $title); 411 $::STATWIDS->{title} ->set_text ("Title: " . $title);
238 412
239 $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); 413 $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR});
291 $::CONN->user_send ("use_skill $name"); 465 $::CONN->user_send ("use_skill $name");
292 } elsif ($ev->{button} == 3) { 466 } elsif ($ev->{button} == 3) {
293 my $shortname = CFPlus::shorten $name, 14; 467 my $shortname = CFPlus::shorten $name, 14;
294 (new CFPlus::UI::Menu 468 (new CFPlus::UI::Menu
295 items => [ 469 items => [
296 ["bind <i>ready_skill $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], 470 ["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"]) }], 471 ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }],
298 ], 472 ],
299 )->popup ($ev); 473 )->popup ($ev);
300 } else { 474 } else {
301 return 0; 475 return 0;
302 } 476 }
319 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 493 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
320 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 494 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
321 } 495 }
322} 496}
323 497
498sub macro_send {
499 my ($self, $macro) = @_;
500
501 for my $cmd (@{ $macro->{action} }) {
502 $self->send_command ($cmd);
503 }
504}
505
324sub user_send { 506sub user_send {
325 my ($self, $command) = @_; 507 my ($self, $command) = @_;
326 508
327 push @{$self->{record}}, $command 509 $self->{record}->($command)
328 if $self->{record}; 510 if $self->{record};
329 511
330 $self->logprint ("send: ", $command); 512 $self->logprint ("send: ", $command);
331 $self->send_command ($command); 513 $self->send_command ($command);
332 ::status ($command); 514 ::status ($command);
333} 515}
334 516
335sub start_record { 517sub record {
336 my ($self) = @_; 518 my ($self, $cb) = @_;
337 519
338 $self->{record} = []; 520 $self->{record} = $cb;
339}
340
341sub stop_record {
342 my ($self) = @_;
343 return delete $self->{record};
344} 521}
345 522
346sub map_scroll { 523sub map_scroll {
347 my ($self, $dx, $dy) = @_; 524 my ($self, $dx, $dy) = @_;
348 525
369 or return; 546 or return;
370 547
371 my ($hash, $x, $y, $w, $h) = @$map_info; 548 my ($hash, $x, $y, $w, $h) = @$map_info;
372 549
373 my $data = $self->{map}->get_rect ($x, $y, $w, $h); 550 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
374 $self->{mapcache}->put ($hash => Compress::LZF::compress $data); 551 CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { };
375 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 552 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
376} 553}
377 554
378sub map_clear { 555sub map_clear {
379 my ($self) = @_; 556 my ($self) = @_;
383 560
384 $self->{map}->clear; 561 $self->{map}->clear;
385 delete $self->{map_widget}{magicmap}; 562 delete $self->{map_widget}{magicmap};
386} 563}
387 564
565sub bg_fetch {
566 my ($self) = @_;
567
568 my $id;
569
570 do {
571 $id = pop @{$self->{bg_fetch}}
572 or return;
573 } while $self->{texture}[$id];
574
575 CFPlus::DB::get tilecache => $id, sub {
576 my ($data) = @_;
577
578 return unless $self->{map}; # stop when destroyed
579
580 $self->set_texture ($id => $data)
581 if defined $data;
582
583 $self->bg_fetch;
584 };
585}
388 586
389sub load_map($$$) { 587sub load_map($$$) {
390 my ($self, $hash, $x, $y) = @_; 588 my ($self, $hash, $x, $y) = @_;
391 589
392 if (defined (my $data = $self->{mapcache}->get ($hash))) { 590 my $gen = $self->{map_change_gen};
591
592 CFPlus::DB::get $self->{mapcache} => $hash, sub {
593 return unless $gen == $self->{map_change_gen};
594
595 my ($data) = @_;
596
597 if (defined $data) {
393 $data = Compress::LZF::decompress $data; 598 $data = Compress::LZF::decompress $data;
394 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 599 #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)) {
396 my $data = $self->{tilecache}->get ($id)
397 or next;
398 600
399 $self->set_texture ($id => $data); 601 my $inprogress = @{ $self->{bg_fetch} || [] };
602 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data);
603 $self->bg_fetch unless $inprogress;
400 } 604 }
401 } 605 };
402} 606}
403 607
404# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 608# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
405# (server resource,s latency, bandwidth), so this hack is warranted. 609# (server resource,s latency, bandwidth), so this hack is warranted.
406# the right fix is to make real tiled maps with an overview file 610# the right fix is to make real tiled maps with an overview file
470 674
471 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 675 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
472 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 676 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
473 677
474 } else { 678 } else {
679 my $gen = $self->{map_change_gen};
475 $self->send_mapinfo ("spatial $path$tile", sub { 680 $self->send_mapinfo ("spatial $path$tile", sub {
681 return unless $gen == $self->{map_change_gen};
682
476 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 683 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
477 684
478 return if $mode ne "spatial"; 685 return if $mode ne "spatial";
479 686
480 $x += $self->{map}->ox; 687 $x += $self->{map}->ox;
494 701
495sub map_change { 702sub map_change {
496 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 703 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
497 704
498 $self->flush_map; 705 $self->flush_map;
706
707 ++$self->{map_change_gen};
499 708
500 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 709 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
501 710
502 my $mapmapw = $self->{mapmap}->{w}; 711 my $mapmapw = $self->{mapmap}->{w};
503 my $mapmaph = $self->{mapmap}->{h}; 712 my $mapmaph = $self->{mapmap}->{h};
520 $self->load_map ($hash, $x, $y); 729 $self->load_map ($hash, $x, $y);
521 $self->flood_fill (0, 0, 0, "", $hash, $flags); 730 $self->flood_fill (0, 0, 0, "", $hash, $flags);
522} 731}
523 732
524sub face_find { 733sub face_find {
525 my ($self, $facenum, $face) = @_; 734 my ($self, $facenum, $face, $cb) = @_;
526 735
527 my $hash = "$face->{chksum},$face->{name}"; 736 my $hash = "$face->{chksum},$face->{name}";
528 737
529 my $id = $self->{facemap}->get ($hash); 738 my $id = CFPlus::DB::get_tile_id_sync $hash;
530 739
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; 740 $face->{id} = $id;
554 $self->{map}->set_face ($facenum => $id);
555 $self->{faceid}[$facenum] = $id;#d# 741 $self->{faceid}[$facenum] = $id;
556 742
557 my $face = $self->{tilecache}->get ($id); 743 $self->{map}->set_tileid ($facenum => $id);
558 744
559 if ($face) { 745 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} 746}
568 747
569sub face_update { 748sub face_update {
570 my ($self, $facenum, $face, $changed) = @_; 749 my ($self, $facenum, $face, $changed) = @_;
571 750
572 $self->{tilecache}->put ($face->{id} => $face->{image}) if $changed; 751 CFPlus::DB::put tilecache => $face->{id} => $face->{image}, sub { }
752 if $changed;
573 753
574 $self->set_texture ($face->{id} => delete $face->{image}); 754 $self->set_texture ($face->{id} => delete $face->{image});
755}
756
757sub smooth_update {
758 my ($self, $facenum, $face) = @_;
759
760 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
575} 761}
576 762
577sub set_texture { 763sub set_texture {
578 my ($self, $id, $data) = @_; 764 my ($self, $id, $data) = @_;
579 765
580 $self->{texture}[$id] ||= do { 766 $self->{texture}[$id] = my $tex =
581 my $tex =
582 new_from_image CFPlus::Texture 767 new_from_image CFPlus::Texture
583 $data, minify => 1, mipmap => 1; 768 $data, minify => 1, mipmap => 1;
584 769
585 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 770 $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
586 $self->{map_widget}->update; 771 $self->{map_widget}->update;
587
588 $tex
589 };
590} 772}
591 773
592sub sound_play { 774sub sound_play {
593 my ($self, $x, $y, $soundnum, $type) = @_; 775 my ($self, $x, $y, $soundnum, $type) = @_;
594 776
604 $LAST_QUERY = $prompt; 786 $LAST_QUERY = $prompt;
605 787
606 $self->{query}-> ($self, $flags, $prompt); 788 $self->{query}-> ($self, $flags, $prompt);
607} 789}
608 790
609sub drawinfo { 791sub sanitise_xml($) {
610 my ($self, $color, $text) = @_; 792 local $_ = shift;
611 793
612 my @color = ( 794 # we now weed out all tags we do not support
795 s%<(?!/?i>|/?u>|/?b>|fg |/fg>)%&lt;%g;
796 # now all entities
797 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
798
799 # handle some elements
800 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
801 s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs;
802
803 $_
804}
805
806our %NAME_TO_COLOR = (
807 black => 0,
808 white => 1,
809 darkblue => 2,
810 red => 3,
811 orange => 4,
812 lightblue => 5,
813 darkorange => 6,
814 green => 7,
815 darkgreen => 8,
816 grey => 9,
817 brown => 10,
818 yellow => 11,
819 tan => 12,
820);
821
822our @CF_COLOR = (
613 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 823 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
614 [1.00, 1.00, 1.00], 824 [1.00, 1.00, 1.00],
615 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] 825 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
616 [1.00, 0.00, 0.00], 826 [1.00, 0.00, 0.00],
617 [1.00, 0.54, 0.00], 827 [1.00, 0.54, 0.00],
618 [0.11, 0.56, 1.00], 828 [0.11, 0.56, 1.00],
619 [0.93, 0.46, 0.00], 829 [0.93, 0.46, 0.00],
620 [0.18, 0.54, 0.34], 830 [0.18, 0.54, 0.34],
621 [0.56, 0.73, 0.56], 831 [0.56, 0.73, 0.56],
622 [0.80, 0.80, 0.80], 832 [0.80, 0.80, 0.80],
623 [0.75, 0.61, 0.20], 833 [0.75, 0.61, 0.20],
624 [0.99, 0.77, 0.26], 834 [0.99, 0.77, 0.26],
625 [0.74, 0.65, 0.41], 835 [0.74, 0.65, 0.41],
626 ); 836);
627 837
838sub msg {
839 my ($self, $color, $type, $text, @extra) = @_;
840
841 $text = sanitise_xml $text;
842
843 if (my $cb = $self->{cb_msg}{$type}) {
844 $_->($self, $color, $type, $text, @extra) for values %$cb;
845 } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) {
846 $type =~ s/-/_/g;
847 $self->{$type} = $text;
848 } else {
628 $self->logprint ("info: ", $text); 849 $self->logprint ("msg: ", $text);
850 return if $color < 0; # negative color == ignore if not understood
629 851
852 my $fg = $CF_COLOR[$color % @CF_COLOR];
853
630 # try to create single paragraphs of multiple lines sent by the server 854 ## try to create single paragraphs of multiple lines sent by the server
855 # no longer neecssary with TRT servers
631 $text =~ s/(?<=\S)\n(?=\w)/ /g; 856 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
632 857
633 $text = CFPlus::asxml $text;
634 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
635 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
636
637 ::message ({ fg => $color[$color], markup => $_ }) 858 ::message ({ fg => $fg, markup => $_ })
638 for split /\n/, $text; 859 for split /\n/, $text;
639 860
640 $self->{statusbox}->add ($text, 861 $self->{statusbox}->add ($text,
641 group => $text, 862 group => $text,
642 fg => $color[$color], 863 fg => $fg,
643 timeout => $color >= 2 ? 180 : 10, 864 timeout => $color >= 2 ? 180 : 10,
644 tooltip_font => $::FONT_FIXED, 865 tooltip_font => $::FONT_FIXED,
645 ); 866 );
646} 867 }
647
648sub drawextinfo {
649 my ($self, $color, $type, $subtype, $message) = @_;
650
651 $self->drawinfo ($color, $message);
652} 868}
653 869
654sub spell_add { 870sub spell_add {
655 my ($self, $spell) = @_; 871 my ($self, $spell) = @_;
656 872
672} 888}
673 889
674sub setup { 890sub setup {
675 my ($self, $setup) = @_; 891 my ($self, $setup) = @_;
676 892
893 $self->{map_widget}->set_tilesize ($self->{tilesize});
677 $::MAP->resize ($self->{mapw}, $self->{maph}); 894 $::MAP->resize ($self->{mapw}, $self->{maph});
678} 895}
679 896
680sub addme_success { 897sub addme_success {
681 my ($self) = @_; 898 my ($self) = @_;
888 $::SERVER_INFO->set_markup ( 1105 $::SERVER_INFO->set_markup (
889 "server <tt>$self->{host}:$self->{port}</tt>\n" 1106 "server <tt>$self->{host}:$self->{port}</tt>\n"
890 . "protocol version <tt>$self->{version}</tt>\n" 1107 . "protocol version <tt>$self->{version}</tt>\n"
891 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" 1108 . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n"
892 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" 1109 . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n"
1110 . "examine command support $yesno[$self->{setup}{excmd} > 0]\n"
893 . "editing support $yesno[!!$self->{editor_support}]\n" 1111 . "editing support $yesno[!!$self->{editor_support}]\n"
894 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" 1112 . "map attributes $yesno[$self->{setup}{extmap} > 0]\n"
1113 . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n"
895 . "cfplus support $yesno[$self->{cfplus_ext} > 0]" 1114 . "cfplus support $yesno[$self->{cfplus_ext} > 0]"
896 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" 1115 . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n"
897 . "map size $self->{mapw}×$self->{maph}\n" 1116 . "map size $self->{mapw}×$self->{maph}\n"
898 ); 1117 );
899 1118
921 1140
922 $self->update_server_info; 1141 $self->update_server_info;
923 1142
924 $self->send_command ("output-sync $::CFG->{output_sync}"); 1143 $self->send_command ("output-sync $::CFG->{output_sync}");
925 $self->send_command ("output-count $::CFG->{output_count}"); 1144 $self->send_command ("output-count $::CFG->{output_count}");
1145 $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0;
926 $self->send_command ("pickup $::CFG->{pickup}"); 1146 $self->send_command ("pickup $::CFG->{pickup}");
927} 1147}
928 1148
929sub buildat { 1149sub buildat {
930 my ($self, $builditem, $x, $y) = @_; 1150 my ($self, $builditem, $x, $y) = @_;
961 1181
962 (delete $self->{npc_dialog})->destroy 1182 (delete $self->{npc_dialog})->destroy
963 if $self->{npc_dialog}; 1183 if $self->{npc_dialog};
964 1184
965 $self->SUPER::destroy; 1185 $self->SUPER::destroy;
1186
1187 %$self = ();
966} 1188}
967 1189
968package CFPlus::NPCDialog; 1190package CFPlus::NPCDialog;
969 1191
970our @ISA = 'CFPlus::UI::Toplevel'; 1192our @ISA = 'CFPlus::UI::Toplevel';
982 kw => { hi => 0, yes => 0, no => 0 }, 1204 kw => { hi => 0, yes => 0, no => 0 },
983 has_close_button => 1, 1205 has_close_button => 1,
984 @_, 1206 @_,
985 ); 1207 );
986 1208
987 Scalar::Util::weaken (my $this = $self); 1209 CFPlus::weaken (my $this = $self);
988 1210
989 $self->connect (delete => sub { $this->destroy; 1 }); 1211 $self->connect (delete => sub { $this->destroy; 1 });
990 1212
991 # better use a pane... 1213 # better use a pane...
992 $self->add (my $hbox = new CFPlus::UI::HBox); 1214 $self->add (my $hbox = new CFPlus::UI::HBox);
1036}; 1258};
1037 1259
1038sub update_options { 1260sub update_options {
1039 my ($self) = @_; 1261 my ($self) = @_;
1040 1262
1041 Scalar::Util::weaken $self; 1263 CFPlus::weaken $self;
1042 1264
1043 $self->{options}->clear; 1265 $self->{options}->clear;
1044 $self->{options}->add ($self->{bye_button}); 1266 $self->{options}->add ($self->{bye_button});
1045 1267
1046 for my $kw (sort keys %{ $self->{kw} }) { 1268 for my $kw (sort keys %{ $self->{kw} }) {
1055} 1277}
1056 1278
1057sub feed { 1279sub feed {
1058 my ($self, $msg) = @_; 1280 my ($self, $msg) = @_;
1059 1281
1060 Scalar::Util::weaken $self; 1282 CFPlus::weaken $self;
1061 1283
1062 if ($msg->{msgtype} eq "reply") { 1284 if ($msg->{msgtype} eq "reply") {
1063 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; 1285 $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []};
1064 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; 1286 $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []};
1065 1287
1066 my $text = "\n" . CFPlus::asxml $msg->{msg}; 1288 my $text = "\n" . CFPlus::Protocol::sanitise_xml $msg->{msg};
1067 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; 1289 my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} };
1068 my @link; 1290 my @link;
1069 $text =~ s{ 1291 $text =~ s{
1070 ($match) 1292 ($match)
1071 }{ 1293 }{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines