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.157 by root, Tue Aug 21 02:39:17 2007 UTC vs.
Revision 1.174 by root, Sun Sep 2 08:44:28 2007 UTC

10use CFPlus::UI; 10use CFPlus::UI;
11use CFPlus::Pod; 11use CFPlus::Pod;
12use CFPlus::Macro; 12use CFPlus::Macro;
13use CFPlus::Item; 13use CFPlus::Item;
14 14
15use Crossfire::Protocol::Base 0.95;
16
17use base 'Crossfire::Protocol::Base'; 15use base 'Crossfire::Protocol::Base';
18 16
19sub new { 17sub new {
20 my ($class, %arg) = @_; 18 my ($class, %arg) = @_;
21 19
22 my $self = $class->SUPER::new (%arg, 20 my $self = $class->SUPER::new (%arg,
23 setup_req => { 21 setup_req => {
24 extmap => 1, 22 extmap => 1,
25 excmd => 1, 23 excmd => 1,
26 xwidget1 => 1,#d# 24 #xwidget2 => 1,#d#
27 %{$arg{setup_req} || {}}, 25 %{$arg{setup_req} || {}},
26 msg => 0,
28 }, 27 },
29 ); 28 );
30 29
31 $self->{map_widget}->clr_commands; 30 $self->{map_widget}->clr_commands;
32 31
48 sort { (length $a) <=> (length $b) } 47 sort { (length $a) <=> (length $b) }
49 @args 48 @args
50 } sort { $a->{par} <=> $b->{par} } 49 } sort { $a->{par} <=> $b->{par} }
51 CFPlus::Pod::find command => "*"; 50 CFPlus::Pod::find command => "*";
52 51
53 $self->connect_ext (ambient_music => sub {
54 my ($songs) = @_;
55 &::audio_music_set_ambient ($songs);
56 });
57
58 $self->connect_ext (capabilities => sub {
59 my (%cap) = @_;
60
61 #$self->send ("setup sound 0"); # we use a different protocol
62 $self->update_fx_want;
63
64 $self->send_exti_req (resource => "exp_table", sub {
65 my ($exp_table) = @_;
66
67 $self->register_face_handler ($exp_table, sub {
68 my ($face) = @_;
69
70 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
71 $_->() for values %{ $self->{on_exp_update} || {} };
72 });
73
74 ()
75 });
76
77 if (my $ts = $cap{tileset}) {
78 if (my ($default) = grep $_->[2] & 1, @$ts) {
79 $self->{tileset} = $default;
80 $self->{tilesize} = $default->[3];
81 $self->setup_req (tileset => $default->[0]);
82
83 my $w = int $self->{mapw} * 32 / $self->{tilesize};
84 my $h = int $self->{maph} * 32 / $self->{tilesize};
85
86 $self->setup_req (mapsize => "${w}x${h}");
87 }
88 }
89 });
90
91 $self->{json_coder} 52 $self->{json_coder}
92 ->convert_blessed 53 ->convert_blessed
93 ->filter_json_single_key_object (__w_ => sub { 54 ->filter_json_single_key_object ("\fw" => sub {
94 $self->{widget}{$_[0]} 55 $self->{widget}{$_[0]}
56 })
57 ->filter_json_single_key_object ("\fc" => sub {
58 my ($id) = @_;
59 sub {
60 $self->send_exti_msg (w_e => $id, @_);
61 }
95 }); 62 });
96
97 # widgetset new
98 $self->connect_ext (ws_n => sub {
99 my ($id) = @_;
100
101 $self->{widgetset}{$id} = {
102 w => {},
103 };
104 });
105
106 # widgetset destroy
107 $self->connect_ext (ws_d => sub {
108 my ($id) = @_;
109
110 my $ws = delete $self->{widgetset}{$id}
111 or return;
112
113 $_->destroy
114 for values %{$ws->{w}};
115 });
116
117 # widgetset create
118 $self->connect_ext (ws_c => sub {
119 my ($ws, $id, $class, $args) = @_;
120
121 for my $ev (grep /^on_/, keys %$args) {
122 my $rid = $args->{$ev};
123 $args->{$ev} = sub {
124 my $id = shift->{s_id};
125 $self->send_exti_msg (w_e => $id, $rid, @_);
126
127 1
128 };
129 }
130
131 $self->widget_associate (
132 $ws, $id => scalar eval {
133 local $SIG{__DIE__};
134 "CFPlus::UI::$class"->new (%$args)
135 }
136 ) or warn "server failed creating client-side widget " . (CFPlus::to_json $class) . ": $@\n";
137 });
138
139 # widgetset associate
140 $self->connect_ext (ws_a => sub {
141 my (%ass) = @_;
142
143 # everything that has a name, wether conceivably useful or not
144 my %wkw = (
145 root => $CFPlus::UI::ROOT,
146 tooltip => $CFPlus::UI::TOOLTIP,
147
148 mapwidget => $::MAPWIDGET,
149 buttonbar => $::BUTTONBAR,
150 metaserver => $::METASERVER,
151 buttonbar => $::BUTTONBAR,
152 login_button => $::LOGIN_BUTTON,
153 quit_dialog => $::QUIT_DIALOG,
154 host_entry => $::HOST_ENTRY,
155 metaserver => $::METASERVER,
156 server_info => $::SERVER_INFO,
157
158 setup_dialog => $::SETUP_DIALOG,
159 setup_notebook => $::SETUP_NOTEBOOK,
160 setup_server => $::SETUP_SERVER,
161 setup_keyboard => $::SETUP_KEYBOARD,
162
163 pl_notebook => $::PL_NOTEBOOK,
164 pl_window => $::PL_WINDOW,
165 inventory_page => $::INVENTORY_PAGE,
166 stats_page => $::STATS_PAGE,
167 skill_page => $::SKILL_PAGE,
168 spell_page => $::SPELL_PAGE,
169 spell_list => $::SPELL_LIST,
170
171 floorbox => $::FLOORBOX,
172 help_window => $::HELP_WINDOW,
173 message_window => $::MESSAGE_WINDOW,
174 statusbox => $::SDTATUSBOX,
175
176 inv => $::INV,
177 invr => $::INVR,
178 invr_hb => $::INVR_HB,
179 );
180
181 while (my ($id, $name) = each %ass) {
182 $self->widget_associate (undef, $id => $wkw{$name})
183 or warn "server failed to associate non-existent well-known widget $name\n";
184 }
185 });
186
187 # widget call
188 $self->connect_ext (w_c => sub {
189 my ($id, $rid, $method, @args) = @_;
190
191 my $w = $self->{widget}{$id}
192 or return;
193
194 if ($rid) {
195 $self->send_exti_msg (w_r => $rid, $w->$method (@args));
196 } else {
197 $w->$method (@args);
198 }
199 });
200
201 # widget set
202 $self->connect_ext (w_s => sub {
203 my ($id, $attr) = @_;
204
205 my $w = $self->{widget}{$id}
206 or return;
207
208 for (my $i = 0; $i < $#$attr; $i += 2) {
209 my ($member, $value) = @$attr[$i, $i+1];
210 if (defined $value) {
211 $w->{$member} = $value;
212 } else {
213 delete $w->{$member};
214 }
215 $w->{parent}->realloc if $member =~ /^c_/ && $w->{visible};
216 }
217 });
218
219 # widget get
220 $self->connect_ext (w_g => sub {
221 my ($id, $rid, $attr) = @_;
222
223 my $w = $self->{widget}{$id}
224 or return;
225
226 $self->send_exti_msg (w_r => $rid, [map $w->{$_}, @$attr]);
227 });
228
229 # message window
230 $self->connect_ext (channel_info => sub {
231 my ($info) = @_;
232 $self->{channels}->{$info->{id}} = $info;
233 $::MESSAGE_WINDOW->add_channel ($info);
234 });
235 63
236 # destroy widgets on logout 64 # destroy widgets on logout
237 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub { 65 $self->{on_stop_game_guard} = $self->{map_widget}{root}->connect (stop_game => sub {
238 for my $ws (values %{delete $self->{widgetset} || {}}) { 66 for my $ws (values %{delete $self->{widgetset} || {}}) {
239 $_->destroy 67 $_->destroy
262 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; 90 $self->{mapcache} = "mapcache_$self->{host}_$self->{port}";
263 91
264 $self 92 $self
265} 93}
266 94
267sub widget_associate {
268 my ($self, $ws, $id, $widget) = @_;
269
270 if ($widget) {
271 $widget->{s_id} = $id;
272 $self->{widget}{$id} = $widget;
273
274 if ($ws) {
275 $widget->{s_ws} = $ws;
276 $self->{widgetset}{$ws}{w}{$id} = $widget;
277 }
278
279 $widget->connect (on_destroy => sub {
280 my ($widget) = @_;
281
282 delete $self->{widget}{$widget->{s_id}};
283 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}}
284 if exists $widget->{s_ws};
285 });
286
287 1
288 } else {
289 $self->send_exti_msg (w_e => $id, undef);
290
291 0
292 }
293}
294
295sub update_fx_want { 95sub update_fx_want {
296 my ($self) = @_; 96 my ($self) = @_;
297 97
298 $self->send_exti_msg (fx_want => { 98 $self->send_exti_msg (fx_want => {
299 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC 99 3 => !!$::CFG->{bgm_enable}, # FT_MUSIC
300 5 => !!$::CFG->{audio_enable}, # FT_SOUND 100 5 => !!$::CFG->{audio_enable}, # FT_SOUND
301 6 => 1, # FT_RSRC 101 6 => 1, # FT_RSRC
302 }); 102 });
303} 103}
104
105sub ext_capabilities {
106 my ($self, %cap) = @_;
107
108 #$self->send ("setup sound 0"); # we use a different protocol
109 $self->update_fx_want;
110
111 $self->send_exti_req (resource => "exp_table", sub {
112 my ($exp_table) = @_;
113
114 $self->register_face_handler ($exp_table, sub {
115 my ($face) = @_;
116
117 $self->{exp_table} = $self->{json_coder}->decode (delete $face->{data});
118 $_->() for values %{ $self->{on_exp_update} || {} };
119 });
120
121 ()
122 });
123
124 if (my $ts = $cap{tileset}) {
125 if (my ($default) = grep $_->[2] & 1, @$ts) {
126 $self->{tileset} = $default;
127 $self->{tilesize} = $default->[3];
128 $self->setup_req (tileset => $default->[0]);
129
130 my $w = int $self->{mapw} * 32 / $self->{tilesize};
131 my $h = int $self->{maph} * 32 / $self->{tilesize};
132
133 $self->setup_req (mapsize => "${w}x${h}");
134 }
135 }
136}
137
138sub ext_ambient_music {
139 my ($self, $songs) = @_;
140 &::audio_music_set_ambient ($songs);
141}
142
143#############################################################################
144
145sub widget_associate {
146 my ($self, $ws, $id, $widget) = @_;
147
148 $widget ||= new CFPlus::UI::Bin;
149
150 $widget->{s_id} = $id;
151 $self->{widget}{$id} = $widget;
152
153 if ($ws) {
154 $widget->{s_ws} = $ws;
155 $self->{widgetset}{$ws}{w}{$id} = $widget;
156 }
157
158 $widget->connect (on_destroy => sub {
159 my ($widget) = @_;
160
161 delete $self->{widget}{$widget->{s_id}};
162 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}}
163 if exists $widget->{s_ws};
164 });
165}
166
167# widgetset new
168sub ext_ws_n {
169 my ($self, $id) = @_;
170
171 $self->{widgetset}{$id} = {
172 w => {},
173 };
174}
175
176# widgetset destroy
177sub ext_ws_d {
178 my ($self, $id) = @_;
179
180 my $ws = delete $self->{widgetset}{$id}
181 or return;
182
183 $_->destroy
184 for values %{$ws->{w}};
185}
186
187# widgetset create
188sub ext_ws_c {
189 my ($self, $ws, $id, $class, $args) = @_;
190
191 $self->widget_associate (
192 $ws, $id => scalar eval {
193 local $SIG{__DIE__};
194 "CFPlus::UI::$class"->new (%$args)
195 }
196 );
197}
198
199# widgetset associate
200sub ext_ws_a {
201 my ($self, %ass) = @_;
202
203 # everything that has a name, wether conceivably useful or not
204 my %wkw = (
205 root => $CFPlus::UI::ROOT,
206 tooltip => $CFPlus::UI::TOOLTIP,
207
208 mapwidget => $::MAPWIDGET,
209 buttonbar => $::BUTTONBAR,
210 metaserver => $::METASERVER,
211 buttonbar => $::BUTTONBAR,
212 login_button => $::LOGIN_BUTTON,
213 quit_dialog => $::QUIT_DIALOG,
214 host_entry => $::HOST_ENTRY,
215 metaserver => $::METASERVER,
216 server_info => $::SERVER_INFO,
217
218 setup_dialog => $::SETUP_DIALOG,
219 setup_notebook => $::SETUP_NOTEBOOK,
220 setup_server => $::SETUP_SERVER,
221 setup_keyboard => $::SETUP_KEYBOARD,
222
223 pl_notebook => $::PL_NOTEBOOK,
224 pl_window => $::PL_WINDOW,
225 inventory_page => $::INVENTORY_PAGE,
226 stats_page => $::STATS_PAGE,
227 skill_page => $::SKILL_PAGE,
228 spell_page => $::SPELL_PAGE,
229 spell_list => $::SPELL_LIST,
230
231 floorbox => $::FLOORBOX,
232 help_window => $::HELP_WINDOW,
233 message_window => $::MESSAGE_WINDOW,
234 statusbox => $::SDTATUSBOX,
235
236 inv => $::INV,
237 invr => $::INVR,
238 invr_hb => $::INVR_HB,
239 );
240
241 while (my ($id, $name) = each %ass) {
242 $self->widget_associate (undef, $id => $wkw{$name});
243 }
244}
245
246# widget call
247sub ext_w_c {
248 my ($self, $id, $rcb, $method, @args) = @_;
249
250 my $w = $self->{widget}{$id}
251 or return;
252
253 if ($rcb) {
254 $rcb->($w->$method (@args));
255 } else {
256 $w->$method (@args);
257 }
258}
259
260# widget set
261sub ext_w_s {
262 my ($self, $id, $attr) = @_;
263
264 my $w = $self->{widget}{$id}
265 or return;
266
267 for (my $i = 0; $i < $#$attr; $i += 2) {
268 my ($member, $value) = @$attr[$i, $i+1];
269 if (defined $value) {
270 $w->{$member} = $value;
271 } else {
272 delete $w->{$member};
273 }
274 $w->{parent}->realloc if $member =~ /^c_/ && $w->{visible};
275 }
276}
277
278# widget get
279sub ext_w_g {
280 my ($self, $id, $rid, @attr) = @_;
281
282 my $w = $self->{widget}{$id}
283 or return;
284
285 $self->send_exti_msg (w_e => $rid, map $w->{$_}, @attr);
286}
287
288# message window
289sub ext_channel_info {
290 my ($self, $info) = @_;
291 $self->{channels}->{$info->{id}} = $info;
292 $::MESSAGE_WINDOW->add_channel ($info);
293}
294
295#############################################################################
304 296
305sub logprint { 297sub logprint {
306 my ($self, @a) = @_; 298 my ($self, @a) = @_;
307 299
308 CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { }; 300 CFPlus::DB::logprint "$Crossfire::VARDIR/log.$self->{host}" => (join "", @a), sub { };
397 389
398 if ( 390 if (
399 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 391 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
400 ) { 392 ) {
401 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 393 my $msg = "<b>stat change</b>: " . (join " ", @diffs);
402 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 10); 394 $self->{statusbox}->add ($msg, group => "stat $msg", fg => [0.8, 1, 0.2, 1], timeout => 20);
403 } 395 }
404 396
405 $self->update_stats_window ($stats, $prev); 397 $self->update_stats_window ($stats, $prev);
406 398
407 $self->{prev_stats} = { %$stats }; 399 $self->{prev_stats} = { %$stats };
474 for keys %RES_TBL; 466 for keys %RES_TBL;
475 467
476 my $sktbl = $::STATWIDS->{skill_tbl}; 468 my $sktbl = $::STATWIDS->{skill_tbl};
477 my @skills = keys %{ $self->{skill_info} }; 469 my @skills = keys %{ $self->{skill_info} };
478 470
479 if (grep +(exists $stats->{$_}) != (exists $prev->{$_}), @skills) { 471 my @order = sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] }
472 map [$_, $self->{skill_info}{$_}],
473 grep exists $stats->{$_},
474 @skills;
475
476 if ($self->{stat_order} ne join ",", map $_->[0], @order) {
477 $self->{stat_order} = join ",", map $_->[0], @order;
478
480 $sktbl->clear; 479 $sktbl->clear;
481 480
482 my @add; 481 my $sw = $self->{skillwid}{""} ||= [
483
484 push @add,
485 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1), 482 0, 0, (new CFPlus::UI::Label text => "Experience", align => 1),
486 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), 483 1, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1),
487 2, 0, (new CFPlus::UI::Label text => "Progress", align => 0), 484 2, 0, (new CFPlus::UI::Label text => "Progress", align => 0),
488 3, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), 485 3, 0, (new CFPlus::UI::Label text => "Skill", expand => 1),
489 4, 0, (new CFPlus::UI::Label text => "Experience", align => 1), 486 4, 0, (new CFPlus::UI::Label text => "Experience", align => 1),
490 5, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1), 487 5, 0, (new CFPlus::UI::Label text => "Lvl.", align => 1),
491 6, 0, (new CFPlus::UI::Label text => "Progress", align => 0), 488 6, 0, (new CFPlus::UI::Label text => "Progress", align => 0),
492 7, 0, (new CFPlus::UI::Label text => "Skill", expand => 1), 489 7, 0, (new CFPlus::UI::Label text => "Skill", expand => 1),
493 ; 490 ];
491
492 my @add = @$sw;
494 493
495 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>"; 494 my $TOOLTIP_ALL = "\n\n<small>Left click - ready skill\nMiddle click - use spell\nRight click - further options</small>";
496 495
497 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 496 my @TOOLTIP_LVL = (tooltip => "<b>Level</b>. The level of the skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
498 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1); 497 my @TOOLTIP_EXP = (tooltip => "<b>Experience</b>. The experience points you have in this skill.$TOOLTIP_ALL", can_events => 1, can_hover => 1);
499 498
500 my ($x, $y) = (0, 1); 499 my ($x, $y) = (0, 1);
501 for ( 500 for (@order) {
502 sort { $stats->{$b->[0]}[1] <=> $stats->{$a->[0]}[1] or $a->[1] cmp $b->[1] }
503 map [$_, $self->{skill_info}{$_}],
504 grep exists $stats->{$_},
505 @skills
506 ) {
507 my ($idx, $name) = @$_; 501 my ($idx, $name) = @$_;
508 502
509 my $spell_cb = sub { 503 my $spell_cb = sub {
510 my ($widget, $ev) = @_; 504 my ($widget, $ev) = @_;
511 505
526 } 520 }
527 521
528 1 522 1
529 }; 523 };
530 524
525 my $sw = $self->{skillwid}{$idx} ||= [
526 # exp
527 (new CFPlus::UI::Label
528 align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP),
529
530 # level
531 (new CFPlus::UI::Label
532 text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL),
533
534 # progress
535 (new CFPlus::UI::ExperienceProgress),
536
537 # label
538 (new CFPlus::UI::Label text => $name, on_button_down => $spell_cb,
539 can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL),
540 ];
541
531 push @add, 542 push @add,
532 $x * 4 + 0, $y, ($self->{stat_widget_exp}{$idx} ||= new CFPlus::UI::Label 543 $x * 4 + 0, $y, $sw->[0],
533 align => 1, font => $::FONT_FIXED, fg => [1, 1, 0], on_button_down => $spell_cb, @TOOLTIP_EXP), 544 $x * 4 + 1, $y, $sw->[1],
534 $x * 4 + 1, $y, ($self->{stat_widget_lvl}{$idx} ||= new CFPlus::UI::Label 545 $x * 4 + 2, $y, $sw->[2],
535 text => "0", align => 1, font => $::FONT_FIXED, fg => [0, 1, 0], padding_x => 4, on_button_down => $spell_cb, @TOOLTIP_LVL), 546 $x * 4 + 3, $y, $sw->[3],
536 $x * 4 + 2, $y, ($self->{stat_widget_prg}{$idx} ||= new CFPlus::UI::ExperienceProgress),
537 $x * 4 + 3, $y, ($self->{stat_widget_lbl}{$idx} ||= new CFPlus::UI::Label text => $name, on_button_down => $spell_cb,
538 can_events => 1, can_hover => 1, tooltip => (CFPlus::Pod::section_label skill_description => $name) . $TOOLTIP_ALL),
539 ; 547 ;
540 548
541 $x++ and ($x, $y) = (0, $y + 1); 549 $x++ and ($x, $y) = (0, $y + 1);
542 } 550 }
543 551
544 $sktbl->add_at (@add); 552 $sktbl->add_at (@add);
545 } 553 }
546 554
547 for (grep exists $stats->{$_}, @skills) { 555 for (@order) {
548 $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); 556 my ($idx, $name) = @$_;
549 $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); 557 my $val = $stats->{$idx};
550 $self->{stat_widget_prg}{$_}->set_value (@{$stats->{$_}});
551 }
552}
553 558
554sub macro_send { 559 next if $prev->{$idx}[1] eq $val->[1];
555 my ($self, $macro) = @_;
556 560
557 for my $cmd (@{ $macro->{action} }) { 561 my $sw = $self->{skillwid}{$idx};
558 $self->send_command ($cmd); 562 $sw->[0]->set_text (::formsep ($val->[1]));
563 $sw->[1]->set_text ($val->[0] * 1);
564 $sw->[2]->set_value (@$val);
565
566 $::GAUGES->{sklprg}->set_label ("$name %d%%");
567 $::GAUGES->{sklprg}->set_value (@$val);
559 } 568 }
560} 569}
561 570
562sub user_send { 571sub user_send {
563 my ($self, $command) = @_; 572 my ($self, $command) = @_;
565 $self->{record}->($command) 574 $self->{record}->($command)
566 if $self->{record}; 575 if $self->{record};
567 576
568 $self->logprint ("send: ", $command); 577 $self->logprint ("send: ", $command);
569 $self->send_command ($command); 578 $self->send_command ($command);
570 ::status ($command);
571} 579}
572 580
573sub record { 581sub record {
574 my ($self, $cb) = @_; 582 my ($self, $cb) = @_;
575 583
608 616
609 if ($delay) { 617 if ($delay) {
610 # delay the map drawing a tiny bit in the hope of getting the missing fetched 618 # delay the map drawing a tiny bit in the hope of getting the missing fetched
611 Event->timer (after => 0.03, cb => sub { 619 Event->timer (after => 0.03, cb => sub {
612 $_[0]->w->cancel; 620 $_[0]->w->cancel;
613 $self->{map_widget}->update; 621 $self->{map_widget}->update
622 if $self->{map_widget};
614 }); 623 });
615 } else { 624 } else {
616 $self->{map_widget}->update; 625 $self->{map_widget}->update;
617 } 626 }
618} 627}
857 # split metadata case, FT_MUSIC, FT_SOUND 866 # split metadata case, FT_MUSIC, FT_SOUND
858 if ($changed) { # new data 867 if ($changed) { # new data
859 my ($meta, $data) = unpack "(w/a*)*", $face->{data}; 868 my ($meta, $data) = unpack "(w/a*)*", $face->{data};
860 $face->{data} = $meta; 869 $face->{data} = $meta;
861 870
871 # rely on strict ordering here and also on later fetch
862 CFPlus::DB::put res_data => $face->{name} => $data, sub { }; 872 CFPlus::DB::put res_data => $face->{name} => $data, sub { };
863 CFPlus::DB::put res_meta => $face->{name} => $meta, sub { }; 873 CFPlus::DB::put res_meta => $face->{name} => $meta, sub { };
864 } 874 }
865 875
866 $face->{data} = $self->{json_coder}->decode ($face->{data}); 876 $face->{data} = $self->{json_coder}->decode ($face->{data});
867
868 ::add_license ($face); 877 ::add_license ($face);
878 ::message ({ markup => CFPlus::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." })
879 if $changed;
869 880
870 if ($face->{type} == 3) { # FT_MUSIC 881 if ($face->{type} == 3) { # FT_MUSIC
871 ::message ({ markup => "downloaded song #$facenum" })
872 if $changed;
873
874 &::audio_music_push ($facenum); 882 &::audio_music_push ($facenum);
875 } elsif ($face->{type} == 5) { # FT_SOUND 883 } elsif ($face->{type} == 5) { # FT_SOUND
876 ::message ({ markup => "downloaded sound #$facenum" })
877 if $changed;
878
879 &::audio_sound_push ($facenum); 884 &::audio_sound_push ($facenum);
880 } 885 }
881 886
882 } else { 887 } else {
883 # flat resource case, FT_RSRC 888 # flat resource case, FT_RSRC
963 968
964sub sanitise_xml($) { 969sub sanitise_xml($) {
965 local $_ = shift; 970 local $_ = shift;
966 971
967 # we now weed out all tags we do not support 972 # we now weed out all tags we do not support
968 s%<(?!/?i>|/?u>|/?b>|fg |/fg>)%&lt;%g; 973 s{ <(?! /?i> | /?u> | /?b> | /?big | /?small | /?s | /?tt | fg\ | /fg>)
974 }{
975 "&lt;"
976 }gex;
977
969 # now all entities 978 # now all entities
970 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g; 979 s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&amp;/g;
971 980
972 # handle some elements 981 # handle some elements
973 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; 982 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
1026 1035
1027 ## try to create single paragraphs of multiple lines sent by the server 1036 ## try to create single paragraphs of multiple lines sent by the server
1028 # no longer neecssary with TRT servers 1037 # no longer neecssary with TRT servers
1029 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 1038 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1030 1039
1040 for (split /\n/, $text) {
1031 ::message ({ 1041 ::message ({
1032 fg => $fg, 1042 fg => $fg,
1033 markup => $_, 1043 markup => $_,
1034 type => $type, 1044 type => $type,
1035 extra => [@extra], 1045 extra => [@extra],
1036 color_flags => $color 1046 color_flags => $color, #d# ugly, kill
1037 }) for split /\n/, $text; 1047 });
1048
1049 $color &= ~NDI_CLEAR; # only clear once for multiline messages
1050 # actually, this is an ugly design. _we_ should control the channels,
1051 # not some random other widget, as the channels are clearly protocol-specific.
1052 # then we could also react to flags such as CLEAR without resorting to
1053 # hacks such as color_flags, above.
1054 }
1038 1055
1039 $self->{statusbox}->add ($text, 1056 $self->{statusbox}->add ($text,
1040 group => $text, 1057 group => $text,
1041 fg => $fg, 1058 fg => $fg,
1042 timeout => $color >= 2 ? 180 : 10, 1059 timeout => $color >= 2 ? 180 : 10,
1043 tooltip_font => $::FONT_FIXED, 1060 tooltip_font => $::FONT_FIXED,
1044 ); 1061 ) if $type eq "info";
1045 } 1062 }
1046} 1063}
1047 1064
1048sub spell_add { 1065sub spell_add {
1049 my ($self, $spell) = @_; 1066 my ($self, $spell) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines