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.163 by root, Wed Aug 22 21:17:32 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
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->{json_coder} 52 $self->{json_coder}
54 ->convert_blessed 53 ->convert_blessed
55 ->filter_json_single_key_object (__w_ => sub { 54 ->filter_json_single_key_object ("\fw" => sub {
56 $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 }
57 }); 62 });
58 63
59 # destroy widgets on logout 64 # destroy widgets on logout
60 $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 {
61 for my $ws (values %{delete $self->{widgetset} || {}}) { 66 for my $ws (values %{delete $self->{widgetset} || {}}) {
138############################################################################# 143#############################################################################
139 144
140sub widget_associate { 145sub widget_associate {
141 my ($self, $ws, $id, $widget) = @_; 146 my ($self, $ws, $id, $widget) = @_;
142 147
143 if ($widget) { 148 $widget ||= new CFPlus::UI::Bin;
149
144 $widget->{s_id} = $id; 150 $widget->{s_id} = $id;
145 $self->{widget}{$id} = $widget; 151 $self->{widget}{$id} = $widget;
146 152
147 if ($ws) { 153 if ($ws) {
148 $widget->{s_ws} = $ws; 154 $widget->{s_ws} = $ws;
149 $self->{widgetset}{$ws}{w}{$id} = $widget; 155 $self->{widgetset}{$ws}{w}{$id} = $widget;
150 } 156 }
151 157
152 $widget->connect (on_destroy => sub { 158 $widget->connect (on_destroy => sub {
153 my ($widget) = @_; 159 my ($widget) = @_;
154 160
155 delete $self->{widget}{$widget->{s_id}}; 161 delete $self->{widget}{$widget->{s_id}};
156 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}} 162 delete $self->{widgetset}{$widget->{s_ws}}{$widget->{s_id}}
157 if exists $widget->{s_ws}; 163 if exists $widget->{s_ws};
158 }); 164 });
159
160 1
161 } else {
162 $self->send_exti_msg (w_e => $id, undef);
163
164 0
165 }
166} 165}
167 166
168# widgetset new 167# widgetset new
169sub ext_ws_n { 168sub ext_ws_n {
170 my ($self, $id) = @_; 169 my ($self, $id) = @_;
186} 185}
187 186
188# widgetset create 187# widgetset create
189sub ext_ws_c { 188sub ext_ws_c {
190 my ($self, $ws, $id, $class, $args) = @_; 189 my ($self, $ws, $id, $class, $args) = @_;
191
192 for my $ev (grep /^on_/, keys %$args) {
193 my $rid = $args->{$ev};
194 $args->{$ev} = sub {
195 my $id = shift->{s_id};
196 $self->send_exti_msg (w_e => $id, $rid, @_);
197
198 1
199 };
200 }
201 190
202 $self->widget_associate ( 191 $self->widget_associate (
203 $ws, $id => scalar eval { 192 $ws, $id => scalar eval {
204 local $SIG{__DIE__}; 193 local $SIG{__DIE__};
205 "CFPlus::UI::$class"->new (%$args) 194 "CFPlus::UI::$class"->new (%$args)
206 } 195 }
207 ) or warn "server failed creating client-side widget " . (CFPlus::to_json $class) . ": $@\n"; 196 );
208} 197}
209 198
210# widgetset associate 199# widgetset associate
211sub ext_ws_a { 200sub ext_ws_a {
212 my ($self, %ass) = @_; 201 my ($self, %ass) = @_;
248 invr => $::INVR, 237 invr => $::INVR,
249 invr_hb => $::INVR_HB, 238 invr_hb => $::INVR_HB,
250 ); 239 );
251 240
252 while (my ($id, $name) = each %ass) { 241 while (my ($id, $name) = each %ass) {
253 $self->widget_associate (undef, $id => $wkw{$name}) 242 $self->widget_associate (undef, $id => $wkw{$name});
254 or warn "server failed to associate non-existent well-known widget $name\n";
255 } 243 }
256} 244}
257 245
258# widget call 246# widget call
259sub ext_w_c { 247sub ext_w_c {
260 my ($self, $id, $rid, $method, @args) = @_; 248 my ($self, $id, $rcb, $method, @args) = @_;
261 249
262 my $w = $self->{widget}{$id} 250 my $w = $self->{widget}{$id}
263 or return; 251 or return;
264 252
265 if ($rid) { 253 if ($rcb) {
266 $self->send_exti_msg (w_r => $rid, $w->$method (@args)); 254 $rcb->($w->$method (@args));
267 } else { 255 } else {
268 $w->$method (@args); 256 $w->$method (@args);
269 } 257 }
270} 258}
271 259
287 } 275 }
288} 276}
289 277
290# widget get 278# widget get
291sub ext_w_g { 279sub ext_w_g {
292 my ($self, $id, $rid, $attr) = @_; 280 my ($self, $id, $rid, @attr) = @_;
293 281
294 my $w = $self->{widget}{$id} 282 my $w = $self->{widget}{$id}
295 or return; 283 or return;
296 284
297 $self->send_exti_msg (w_r => $rid, [map $w->{$_}, @$attr]); 285 $self->send_exti_msg (w_e => $rid, map $w->{$_}, @attr);
298} 286}
299 287
300# message window 288# message window
301sub ext_channel_info { 289sub ext_channel_info {
302 my ($self, $info) = @_; 290 my ($self, $info) = @_;
401 389
402 if ( 390 if (
403 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange 391 my @diffs = map $_->[1]->($self, $_->[2], $prev->{$_->[0]}, $stats->{$_->[0]}), @statchange
404 ) { 392 ) {
405 my $msg = "<b>stat change</b>: " . (join " ", @diffs); 393 my $msg = "<b>stat change</b>: " . (join " ", @diffs);
406 $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);
407 } 395 }
408 396
409 $self->update_stats_window ($stats, $prev); 397 $self->update_stats_window ($stats, $prev);
410 398
411 $self->{prev_stats} = { %$stats }; 399 $self->{prev_stats} = { %$stats };
566 554
567 for (@order) { 555 for (@order) {
568 my ($idx, $name) = @$_; 556 my ($idx, $name) = @$_;
569 my $val = $stats->{$idx}; 557 my $val = $stats->{$idx};
570 558
571 next if $prev->{$idx}[1] == $val->[1]; 559 next if $prev->{$idx}[1] eq $val->[1];
572 560
573 my $sw = $self->{skillwid}{$idx}; 561 my $sw = $self->{skillwid}{$idx};
574 $sw->[0]->set_text (::formsep ($val->[1])); 562 $sw->[0]->set_text (::formsep ($val->[1]));
575 $sw->[1]->set_text ($val->[0] * 1); 563 $sw->[1]->set_text ($val->[0] * 1);
576 $sw->[2]->set_value (@$val); 564 $sw->[2]->set_value (@$val);
577 565
578 #$::GAUGES->{sklprg}->set_label ($name); 566 $::GAUGES->{sklprg}->set_label ("$name %d%%");
579 $::GAUGES->{sklprg}->set_value (@$val); 567 $::GAUGES->{sklprg}->set_value (@$val);
580 }
581}
582
583sub macro_send {
584 my ($self, $macro) = @_;
585
586 for my $cmd (@{ $macro->{action} }) {
587 $self->send_command ($cmd);
588 } 568 }
589} 569}
590 570
591sub user_send { 571sub user_send {
592 my ($self, $command) = @_; 572 my ($self, $command) = @_;
594 $self->{record}->($command) 574 $self->{record}->($command)
595 if $self->{record}; 575 if $self->{record};
596 576
597 $self->logprint ("send: ", $command); 577 $self->logprint ("send: ", $command);
598 $self->send_command ($command); 578 $self->send_command ($command);
599 ::status ($command);
600} 579}
601 580
602sub record { 581sub record {
603 my ($self, $cb) = @_; 582 my ($self, $cb) = @_;
604 583
887 # split metadata case, FT_MUSIC, FT_SOUND 866 # split metadata case, FT_MUSIC, FT_SOUND
888 if ($changed) { # new data 867 if ($changed) { # new data
889 my ($meta, $data) = unpack "(w/a*)*", $face->{data}; 868 my ($meta, $data) = unpack "(w/a*)*", $face->{data};
890 $face->{data} = $meta; 869 $face->{data} = $meta;
891 870
871 # rely on strict ordering here and also on later fetch
892 CFPlus::DB::put res_data => $face->{name} => $data, sub { }; 872 CFPlus::DB::put res_data => $face->{name} => $data, sub { };
893 CFPlus::DB::put res_meta => $face->{name} => $meta, sub { }; 873 CFPlus::DB::put res_meta => $face->{name} => $meta, sub { };
894 } 874 }
895 875
896 $face->{data} = $self->{json_coder}->decode ($face->{data}); 876 $face->{data} = $self->{json_coder}->decode ($face->{data});
897
898 ::add_license ($face); 877 ::add_license ($face);
878 ::message ({ markup => CFPlus::asxml "downloaded resource '$face->{data}{name}', type $face->{type}." })
879 if $changed;
899 880
900 if ($face->{type} == 3) { # FT_MUSIC 881 if ($face->{type} == 3) { # FT_MUSIC
901 ::message ({ markup => "downloaded song #$facenum" })
902 if $changed;
903
904 &::audio_music_push ($facenum); 882 &::audio_music_push ($facenum);
905 } elsif ($face->{type} == 5) { # FT_SOUND 883 } elsif ($face->{type} == 5) { # FT_SOUND
906 ::message ({ markup => "downloaded sound #$facenum" })
907 if $changed;
908
909 &::audio_sound_push ($facenum); 884 &::audio_sound_push ($facenum);
910 } 885 }
911 886
912 } else { 887 } else {
913 # flat resource case, FT_RSRC 888 # flat resource case, FT_RSRC
993 968
994sub sanitise_xml($) { 969sub sanitise_xml($) {
995 local $_ = shift; 970 local $_ = shift;
996 971
997 # we now weed out all tags we do not support 972 # we now weed out all tags we do not support
998 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
999 # now all entities 978 # now all entities
1000 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;
1001 980
1002 # handle some elements 981 # handle some elements
1003 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; 982 s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs;
1056 1035
1057 ## 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
1058 # no longer neecssary with TRT servers 1037 # no longer neecssary with TRT servers
1059 #$text =~ s/(?<=\S)\n(?=\w)/ /g; 1038 #$text =~ s/(?<=\S)\n(?=\w)/ /g;
1060 1039
1040 for (split /\n/, $text) {
1061 ::message ({ 1041 ::message ({
1062 fg => $fg, 1042 fg => $fg,
1063 markup => $_, 1043 markup => $_,
1064 type => $type, 1044 type => $type,
1065 extra => [@extra], 1045 extra => [@extra],
1066 color_flags => $color 1046 color_flags => $color, #d# ugly, kill
1067 }) 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 }
1068 1055
1069 $self->{statusbox}->add ($text, 1056 $self->{statusbox}->add ($text,
1070 group => $text, 1057 group => $text,
1071 fg => $fg, 1058 fg => $fg,
1072 timeout => $color >= 2 ? 180 : 10, 1059 timeout => $color >= 2 ? 180 : 10,
1073 tooltip_font => $::FONT_FIXED, 1060 tooltip_font => $::FONT_FIXED,
1074 ); 1061 ) if $type eq "info";
1075 } 1062 }
1076} 1063}
1077 1064
1078sub spell_add { 1065sub spell_add {
1079 my ($self, $spell) = @_; 1066 my ($self, $spell) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines