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.118 by root, Fri Jul 13 15:44:48 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 "res-metadata" => $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 "res-metadata" => $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 }
98 });
99
100 $self->connect_ext (event_capabilities => sub {
101 my ($cap) = @_;
102
103 if (my $ts = $cap->{tileset}) {
104 if (my ($default) = grep $_->[2] & 1, @$ts) {
105 $self->{tileset} = $default;
106 $self->{tilesize} = $default->[3];
107 $self->setup_req (tileset => $default->[0]);
108
109 my $w = int $self->{mapw} * 32 / $self->{tilesize};
110 my $h = int $self->{maph} * 32 / $self->{tilesize};
111
112 $self->setup_req (mapsize => "${w}x${h}");
113 }
114 }
115 });
116
117 $self->{json_coder}
118 ->convert_blessed
119 ->filter_json_single_key_object (__widget_ref__ => sub {
120 $self->{widget}{$_[0]}
121 });
122
123 $self->connect_ext (ws_n => sub {
124 my ($arg) = @_;
125
126 $self->{widgetset}{$arg{id}} = {
127 w => {},
128 };
129 });
130
131 $self->connect_ext (ws_d => sub {
132 my ($arg) = @_;
133
134 my $ws = delete $self->{widgetset}{$arg{id}}
135 or return;
136
137 $_->destroy
138 for values %{$ws->{w}};
139 });
140
141 $self->connect_ext (ws_c => sub {
142 my ($arg) = @_;
143
144 my $args = $arg->{args} || {};
145
146 for my $ev (grep /^on_/, keys %$args) {
147 $args->{$ev} = sub {
148 my $id = shift->{s_id};
149 $self->send_exti_msg (w_e => id => $id, name => $ev, args => \@_);
150
151 1
152 };
153 }
154
155 if (my $widget = eval {
156 local $SIG{__DIE__};
157 "CFPlus::UI::$arg->{class}"->new (
158 %$args,
159 s_ws => $arg->{ws},
160 s_id => $arg->{id},
161 )
162 }
163 ) {
164 $self->{widget}{$arg->{id}}
165 = $self->{widgetset}{$arg->{ws}}{w}{$arg->{id}}
166 = $widget;
167
168 $widget->connect (on_destroy => sub {
169 my ($widget) = @_;
170
171 delete $self->{widget}{$widget->{s_id}};
172 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}};
173 });
174 } else {
175 warn "server failed creating client-side widget " . (CFPlus::to_json $arg) . ": $@\n";
176 $self->send_exti_msg (w_e => id => $arg->{id}, name => "destroy");
177 }
178 });
179
180 $self->connect_ext (w_c => sub {
181 my ($arg) = @_;
182
183 my $w = $self->{widget}{$arg->{id}}
184 or return;
185 my $m = $arg->{name};
186
187 my $a = $arg->{args} || [];
188
189 if (exists $arg->{rid}) {
190 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->$m (@$a)]);
191 } else {
192 $w->$m (@$a);
193 }
194 });
195
196 $self->connect_ext (w_s => sub {
197 my ($arg) = @_;
198
199 my $w = $self->{widget}{$arg->{id}}
200 or return;
201
202 $w->{$arg->{name}} = $arg->{value};
203 });
204
205 $self->connect_ext (w_g => sub {
206 my ($arg) = @_;
207
208 my $w = $self->{widget}{$arg->{id}}
209 or return;
210
211 $self->send_exti_msg (w_r => rid => $arg->{rid}, res => [$w->{$arg->{name}}]);
212 });
213
214 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
215 for my $ws (values %{delete $self->{widgetset} || {}}) {
216 $_->destroy
217 for values %{delete $ws->{w} || {}};
218 }
219 });
220
43 $self->{map_widget}->add_command (@$_) 221 $self->{map_widget}->add_command (@$_)
44 for @cmd_help; 222 for @cmd_help;
45
46 $self->{noface} = new_from_file CFPlus::Texture
47 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
48 223
49 { 224 {
50 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture 225 $self->{dialogue} = my $tex = new_from_file CFPlus::Texture
51 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1; 226 CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1;
52 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 227 $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}});
53 } 228 }
54 229
230 {
231 $self->{noface} = my $tex = new_from_file CFPlus::Texture
232 CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1;
233 $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}});
234 }
235
55 $self->{open_container} = 0; 236 $self->{open_container} = 0;
56 237
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 238 # per server
64 $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}" 239 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
65 or die "mapcache_$self->{host}_$self->{port}: unable to open database table";
66 240
67 $self 241 $self
68} 242}
69 243
70sub logprint { 244sub logprint {
227 $::GAUGES->{mana} ->set_value ($sp, $sp_m); 401 $::GAUGES->{mana} ->set_value ($sp, $sp_m);
228 $::GAUGES->{food} ->set_value ($fo, $fo_m); 402 $::GAUGES->{food} ->set_value ($fo, $fo_m);
229 $::GAUGES->{grace} ->set_value ($gr, $gr_m); 403 $::GAUGES->{grace} ->set_value ($gr, $gr_m);
230 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) 404 $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64}))
231 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); 405 . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")");
232 my $rng = $stats->{+CS_STAT_RANGE}; 406 $::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}; 407 my $title = $stats->{+CS_STAT_TITLE};
236 $title =~ s/^Player: //; 408 $title =~ s/^Player: //;
237 $::STATWIDS->{title} ->set_text ("Title: " . $title); 409 $::STATWIDS->{title} ->set_text ("Title: " . $title);
238 410
239 $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); 411 $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR});
291 $::CONN->user_send ("use_skill $name"); 463 $::CONN->user_send ("use_skill $name");
292 } elsif ($ev->{button} == 3) { 464 } elsif ($ev->{button} == 3) {
293 my $shortname = CFPlus::shorten $name, 14; 465 my $shortname = CFPlus::shorten $name, 14;
294 (new CFPlus::UI::Menu 466 (new CFPlus::UI::Menu
295 items => [ 467 items => [
296 ["bind <i>ready_skill $shortname</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], 468 ["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"]) }], 469 ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }],
298 ], 470 ],
299 )->popup ($ev); 471 )->popup ($ev);
300 } else { 472 } else {
301 return 0; 473 return 0;
302 } 474 }
319 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 491 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1]));
320 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 492 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1);
321 } 493 }
322} 494}
323 495
496sub macro_send {
497 my ($self, $macro) = @_;
498
499 for my $cmd (@{ $macro->{action} }) {
500 $self->send_command ($cmd);
501 }
502}
503
324sub user_send { 504sub user_send {
325 my ($self, $command) = @_; 505 my ($self, $command) = @_;
326 506
327 push @{$self->{record}}, $command 507 $self->{record}->($command)
328 if $self->{record}; 508 if $self->{record};
329 509
330 $self->logprint ("send: ", $command); 510 $self->logprint ("send: ", $command);
331 $self->send_command ($command); 511 $self->send_command ($command);
332 ::status ($command); 512 ::status ($command);
333} 513}
334 514
335sub start_record { 515sub record {
336 my ($self) = @_; 516 my ($self, $cb) = @_;
337 517
338 $self->{record} = []; 518 $self->{record} = $cb;
339}
340
341sub stop_record {
342 my ($self) = @_;
343 return delete $self->{record};
344} 519}
345 520
346sub map_scroll { 521sub map_scroll {
347 my ($self, $dx, $dy) = @_; 522 my ($self, $dx, $dy) = @_;
348 523
369 or return; 544 or return;
370 545
371 my ($hash, $x, $y, $w, $h) = @$map_info; 546 my ($hash, $x, $y, $w, $h) = @$map_info;
372 547
373 my $data = $self->{map}->get_rect ($x, $y, $w, $h); 548 my $data = $self->{map}->get_rect ($x, $y, $w, $h);
374 $self->{mapcache}->put ($hash => Compress::LZF::compress $data); 549 CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { };
375 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 550 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
376} 551}
377 552
378sub map_clear { 553sub map_clear {
379 my ($self) = @_; 554 my ($self) = @_;
383 558
384 $self->{map}->clear; 559 $self->{map}->clear;
385 delete $self->{map_widget}{magicmap}; 560 delete $self->{map_widget}{magicmap};
386} 561}
387 562
563sub bg_fetch {
564 my ($self) = @_;
565
566 my $id;
567
568 do {
569 $id = pop @{$self->{bg_fetch}}
570 or return;
571 } while $self->{texture}[$id];
572
573 CFPlus::DB::get tilecache => $id, sub {
574 my ($data) = @_;
575
576 return unless $self->{map}; # stop when destroyed
577
578 $self->set_texture ($id => $data)
579 if defined $data;
580
581 $self->bg_fetch;
582 };
583}
388 584
389sub load_map($$$) { 585sub load_map($$$) {
390 my ($self, $hash, $x, $y) = @_; 586 my ($self, $hash, $x, $y) = @_;
391 587
392 if (defined (my $data = $self->{mapcache}->get ($hash))) { 588 my $gen = $self->{map_change_gen};
589
590 CFPlus::DB::get $self->{mapcache} => $hash, sub {
591 return unless $gen == $self->{map_change_gen};
592
593 my ($data) = @_;
594
595 if (defined $data) {
393 $data = Compress::LZF::decompress $data; 596 $data = Compress::LZF::decompress $data;
394 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 597 #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 598
399 $self->set_texture ($id => $data); 599 my $inprogress = @{ $self->{bg_fetch} || [] };
600 unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data);
601 $self->bg_fetch unless $inprogress;
400 } 602 }
401 } 603 };
402} 604}
403 605
404# hardcode /world/world_xxx_xxx map names, the savings are enourmous, 606# hardcode /world/world_xxx_xxx map names, the savings are enourmous,
405# (server resource,s latency, bandwidth), so this hack is warranted. 607# (server resource,s latency, bandwidth), so this hack is warranted.
406# the right fix is to make real tiled maps with an overview file 608# the right fix is to make real tiled maps with an overview file
470 672
471 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) 673 $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags)
472 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 674 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
473 675
474 } else { 676 } else {
677 my $gen = $self->{map_change_gen};
475 $self->send_mapinfo ("spatial $path$tile", sub { 678 $self->send_mapinfo ("spatial $path$tile", sub {
679 return unless $gen == $self->{map_change_gen};
680
476 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 681 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
477 682
478 return if $mode ne "spatial"; 683 return if $mode ne "spatial";
479 684
480 $x += $self->{map}->ox; 685 $x += $self->{map}->ox;
494 699
495sub map_change { 700sub map_change {
496 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 701 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
497 702
498 $self->flush_map; 703 $self->flush_map;
704
705 ++$self->{map_change_gen};
499 706
500 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 707 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
501 708
502 my $mapmapw = $self->{mapmap}->{w}; 709 my $mapmapw = $self->{mapmap}->{w};
503 my $mapmaph = $self->{mapmap}->{h}; 710 my $mapmaph = $self->{mapmap}->{h};
520 $self->load_map ($hash, $x, $y); 727 $self->load_map ($hash, $x, $y);
521 $self->flood_fill (0, 0, 0, "", $hash, $flags); 728 $self->flood_fill (0, 0, 0, "", $hash, $flags);
522} 729}
523 730
524sub face_find { 731sub face_find {
525 my ($self, $facenum, $face) = @_; 732 my ($self, $facenum, $face, $cb) = @_;
526 733
527 my $hash = "$face->{chksum},$face->{name}"; 734 my $hash = "$face->{chksum},$face->{name}";
528 735
529 my $id = $self->{facemap}->get ($hash); 736 my $id = CFPlus::DB::get_tile_id_sync $hash;
530 737
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; 738 $face->{id} = $id;
554 $self->{map}->set_face ($facenum => $id);
555 $self->{faceid}[$facenum] = $id;#d# 739 $self->{faceid}[$facenum] = $id;
556 740
557 my $face = $self->{tilecache}->get ($id); 741 $self->{map}->set_tileid ($facenum => $id);
558 742
559 if ($face) { 743 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} 744}
568 745
569sub face_update { 746sub face_update {
570 my ($self, $facenum, $face, $changed) = @_; 747 my ($self, $facenum, $face, $changed) = @_;
571 748
572 $self->{tilecache}->put ($face->{id} => $face->{image}) if $changed; 749 CFPlus::DB::put tilecache => $face->{id} => $face->{image}, sub { }
750 if $changed;
573 751
574 $self->set_texture ($face->{id} => delete $face->{image}); 752 $self->set_texture ($face->{id} => delete $face->{image});
753}
754
755sub smooth_update {
756 my ($self, $facenum, $face) = @_;
757
758 $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel});
575} 759}
576 760
577sub set_texture { 761sub set_texture {
578 my ($self, $id, $data) = @_; 762 my ($self, $id, $data) = @_;
579 763
764 return unless $self->{map};
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