… | |
… | |
4 | use strict; |
4 | use strict; |
5 | |
5 | |
6 | use Crossfire::Protocol::Constants; |
6 | use Crossfire::Protocol::Constants; |
7 | |
7 | |
8 | use CFPlus; |
8 | use CFPlus; |
|
|
9 | use CFPlus::DB; |
9 | use CFPlus::UI; |
10 | use CFPlus::UI; |
10 | use CFPlus::Pod; |
11 | use CFPlus::Pod; |
|
|
12 | use CFPlus::Macro; |
|
|
13 | use CFPlus::Item; |
|
|
14 | |
|
|
15 | use Crossfire::Protocol::Base 0.95; |
11 | |
16 | |
12 | use base 'Crossfire::Protocol::Base'; |
17 | use base 'Crossfire::Protocol::Base'; |
13 | |
18 | |
14 | sub new { |
19 | sub 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 | %{$arg{setup_req} || {}}, |
|
|
27 | }, |
|
|
28 | ); |
18 | |
29 | |
19 | $self->{map_widget}->clr_commands; |
30 | $self->{map_widget}->clr_commands; |
20 | |
31 | |
21 | my @cmd_help = map { |
32 | my @cmd_help = map { |
22 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
33 | $_->{kw}[0] =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x |
… | |
… | |
33 | for @args; |
44 | for @args; |
34 | |
45 | |
35 | map ["$cmd$_", $text], |
46 | map ["$cmd$_", $text], |
36 | sort { (length $a) <=> (length $b) } |
47 | sort { (length $a) <=> (length $b) } |
37 | @args |
48 | @args |
38 | } sort { $a->{par} <=> $b->{par} } |
49 | } sort { $a->{par} <=> $b->{par} } |
39 | CFPlus::Pod::find command => "*"; |
50 | CFPlus::Pod::find command => "*"; |
40 | |
51 | |
|
|
52 | $self->connect_ext (event_capabilities => sub { |
|
|
53 | my ($cap) = @_; |
|
|
54 | |
|
|
55 | if (my $ts = $cap->{tileset}) { |
|
|
56 | if (my ($default) = grep $_->[2] & 1, @$ts) { |
|
|
57 | $self->{tileset} = $default; |
|
|
58 | $self->{tilesize} = $default->[3]; |
|
|
59 | $self->setup_req (tileset => $default->[0]); |
|
|
60 | |
|
|
61 | my $w = int $self->{mapw} * 32 / $self->{tilesize}; |
|
|
62 | my $h = int $self->{maph} * 32 / $self->{tilesize}; |
|
|
63 | |
|
|
64 | $self->setup_req (mapsize => "${w}x${h}"); |
|
|
65 | } |
|
|
66 | } |
|
|
67 | }); |
|
|
68 | |
41 | $self->{map_widget}->add_command (@$_) |
69 | $self->{map_widget}->add_command (@$_) |
42 | for @cmd_help; |
70 | for @cmd_help; |
43 | |
|
|
44 | $self->{noface} = new_from_file CFPlus::Texture |
|
|
45 | CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
46 | |
71 | |
47 | { |
72 | { |
48 | $self->{dialogue} = my $tex = new_from_file CFPlus::Texture |
73 | $self->{dialogue} = my $tex = new_from_file CFPlus::Texture |
49 | CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1; |
74 | CFPlus::find_rcfile "dialogue.png", minify => 1, mipmap => 1; |
50 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
75 | $self->{map}->set_texture (1, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
51 | } |
76 | } |
52 | |
77 | |
|
|
78 | { |
|
|
79 | $self->{noface} = my $tex = new_from_file CFPlus::Texture |
|
|
80 | CFPlus::find_rcfile "noface.png", minify => 1, mipmap => 1; |
|
|
81 | $self->{map}->set_texture (2, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
82 | } |
|
|
83 | |
53 | $self->{open_container} = 0; |
84 | $self->{open_container} = 0; |
54 | |
85 | |
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 |
86 | # per server |
62 | $self->{mapcache} = CFPlus::db_table "mapcache_$self->{host}_$self->{port}" |
87 | $self->{mapcache} = "mapcache_$self->{host}_$self->{port}"; |
63 | or die "mapcache_$self->{host}_$self->{port}: unable to open database table"; |
|
|
64 | |
88 | |
65 | $self |
89 | $self |
66 | } |
90 | } |
67 | |
91 | |
68 | sub logprint { |
92 | sub logprint { |
… | |
… | |
225 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
249 | $::GAUGES->{mana} ->set_value ($sp, $sp_m); |
226 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
250 | $::GAUGES->{food} ->set_value ($fo, $fo_m); |
227 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
251 | $::GAUGES->{grace} ->set_value ($gr, $gr_m); |
228 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
252 | $::GAUGES->{exp} ->set_text ("Exp: " . (::formsep ($stats->{+CS_STAT_EXP64})) |
229 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
253 | . " (lvl " . ($stats->{+CS_STAT_LEVEL} * 1) . ")"); |
230 | my $rng = $stats->{+CS_STAT_RANGE}; |
254 | $::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}; |
255 | my $title = $stats->{+CS_STAT_TITLE}; |
234 | $title =~ s/^Player: //; |
256 | $title =~ s/^Player: //; |
235 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
257 | $::STATWIDS->{title} ->set_text ("Title: " . $title); |
236 | |
258 | |
237 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
259 | $::STATWIDS->{st_str} ->set_text (sprintf "%d" , $stats->{+CS_STAT_STR}); |
… | |
… | |
286 | if ($ev->{button} == 1) { |
308 | if ($ev->{button} == 1) { |
287 | $::CONN->user_send ("ready_skill $name"); |
309 | $::CONN->user_send ("ready_skill $name"); |
288 | } elsif ($ev->{button} == 2) { |
310 | } elsif ($ev->{button} == 2) { |
289 | $::CONN->user_send ("use_skill $name"); |
311 | $::CONN->user_send ("use_skill $name"); |
290 | } elsif ($ev->{button} == 3) { |
312 | } elsif ($ev->{button} == 3) { |
|
|
313 | my $shortname = CFPlus::shorten $name, 14; |
291 | (new CFPlus::UI::Menu |
314 | (new CFPlus::UI::Menu |
292 | items => [ |
315 | items => [ |
293 | ["bind <i>ready_skill $name</i> to a key" => sub { $::BIND_EDITOR->do_quick_binding (["ready_skill $name"]) }], |
316 | ["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"]) }], |
317 | ["bind <i>use_skill $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["use_skill $name"] }], |
295 | ], |
318 | ], |
296 | )->popup ($ev); |
319 | )->popup ($ev); |
297 | } else { |
320 | } else { |
298 | return 0; |
321 | return 0; |
299 | } |
322 | } |
… | |
… | |
316 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
339 | $self->{stat_widget_exp}{$_}->set_text (::formsep ($stats->{$_}[1])); |
317 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
340 | $self->{stat_widget_lvl}{$_}->set_text ($stats->{$_}[0] * 1); |
318 | } |
341 | } |
319 | } |
342 | } |
320 | |
343 | |
|
|
344 | sub macro_send { |
|
|
345 | my ($self, $macro) = @_; |
|
|
346 | |
|
|
347 | for my $cmd (@{ $macro->{action} }) { |
|
|
348 | $self->send_command ($cmd); |
|
|
349 | } |
|
|
350 | } |
|
|
351 | |
321 | sub user_send { |
352 | sub user_send { |
322 | my ($self, $command) = @_; |
353 | my ($self, $command) = @_; |
323 | |
354 | |
|
|
355 | $self->{record}->($command) |
324 | if ($self->{record}) { |
356 | if $self->{record}; |
325 | push @{$self->{record}}, $command; |
|
|
326 | } |
|
|
327 | |
357 | |
328 | $self->logprint ("send: ", $command); |
358 | $self->logprint ("send: ", $command); |
329 | $self->send_command ($command); |
359 | $self->send_command ($command); |
330 | ::status ($command); |
360 | ::status ($command); |
331 | } |
361 | } |
332 | |
362 | |
333 | sub start_record { |
363 | sub record { |
334 | my ($self) = @_; |
364 | my ($self, $cb) = @_; |
335 | |
365 | |
336 | $self->{record} = []; |
366 | $self->{record} = $cb; |
337 | } |
|
|
338 | |
|
|
339 | sub stop_record { |
|
|
340 | my ($self) = @_; |
|
|
341 | return delete $self->{record}; |
|
|
342 | } |
367 | } |
343 | |
368 | |
344 | sub map_scroll { |
369 | sub map_scroll { |
345 | my ($self, $dx, $dy) = @_; |
370 | my ($self, $dx, $dy) = @_; |
346 | |
371 | |
… | |
… | |
367 | or return; |
392 | or return; |
368 | |
393 | |
369 | my ($hash, $x, $y, $w, $h) = @$map_info; |
394 | my ($hash, $x, $y, $w, $h) = @$map_info; |
370 | |
395 | |
371 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
396 | my $data = $self->{map}->get_rect ($x, $y, $w, $h); |
372 | $self->{mapcache}->put ($hash => Compress::LZF::compress $data); |
397 | CFPlus::DB::put $self->{mapcache} => $hash => Compress::LZF::compress $data, sub { }; |
373 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
398 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
374 | } |
399 | } |
375 | |
400 | |
376 | sub map_clear { |
401 | sub map_clear { |
377 | my ($self) = @_; |
402 | my ($self) = @_; |
… | |
… | |
381 | |
406 | |
382 | $self->{map}->clear; |
407 | $self->{map}->clear; |
383 | delete $self->{map_widget}{magicmap}; |
408 | delete $self->{map_widget}{magicmap}; |
384 | } |
409 | } |
385 | |
410 | |
|
|
411 | sub bg_fetch { |
|
|
412 | my ($self) = @_; |
|
|
413 | |
|
|
414 | my $id; |
|
|
415 | |
|
|
416 | do { |
|
|
417 | $id = pop @{$self->{bg_fetch}} |
|
|
418 | or return; |
|
|
419 | } while $self->{texture}[$id]; |
|
|
420 | |
|
|
421 | CFPlus::DB::get tilecache => $id, sub { |
|
|
422 | my ($data) = @_; |
|
|
423 | |
|
|
424 | return unless $self->{map}; # stop when destroyed |
|
|
425 | |
|
|
426 | $self->set_texture ($id => $data) |
|
|
427 | if defined $data; |
|
|
428 | |
|
|
429 | $self->bg_fetch; |
|
|
430 | }; |
|
|
431 | } |
386 | |
432 | |
387 | sub load_map($$$) { |
433 | sub load_map($$$) { |
388 | my ($self, $hash, $x, $y) = @_; |
434 | my ($self, $hash, $x, $y) = @_; |
389 | |
435 | |
390 | if (defined (my $data = $self->{mapcache}->get ($hash))) { |
436 | my $gen = $self->{map_change_gen}; |
|
|
437 | |
|
|
438 | CFPlus::DB::get $self->{mapcache} => $hash, sub { |
|
|
439 | return unless $gen == $self->{map_change_gen}; |
|
|
440 | |
|
|
441 | my ($data) = @_; |
|
|
442 | |
|
|
443 | if (defined $data) { |
391 | $data = Compress::LZF::decompress $data; |
444 | $data = Compress::LZF::decompress $data; |
392 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
445 | #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 | |
446 | |
397 | $self->set_texture ($id => $data); |
447 | my $inprogress = @{ $self->{bg_fetch} || [] }; |
|
|
448 | unshift @{ $self->{bg_fetch} }, $self->{map}->set_rect ($x, $y, $data); |
|
|
449 | $self->bg_fetch unless $inprogress; |
398 | } |
450 | } |
399 | } |
451 | }; |
400 | } |
452 | } |
401 | |
453 | |
402 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
454 | # hardcode /world/world_xxx_xxx map names, the savings are enourmous, |
403 | # (server resource,s latency, bandwidth), so this hack is warranted. |
455 | # (server resource,s latency, bandwidth), so this hack is warranted. |
404 | # the right fix is to make real tiled maps with an overview file |
456 | # the right fix is to make real tiled maps with an overview file |
… | |
… | |
468 | |
520 | |
469 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
521 | $self->flood_fill ($block, $gx, $gy, "$path$tile", $hash, $flags) |
470 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
522 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
471 | |
523 | |
472 | } else { |
524 | } else { |
|
|
525 | my $gen = $self->{map_change_gen}; |
473 | $self->send_mapinfo ("spatial $path$tile", sub { |
526 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
527 | return unless $gen == $self->{map_change_gen}; |
|
|
528 | |
474 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
529 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
475 | |
530 | |
476 | return if $mode ne "spatial"; |
531 | return if $mode ne "spatial"; |
477 | |
532 | |
478 | $x += $self->{map}->ox; |
533 | $x += $self->{map}->ox; |
… | |
… | |
492 | |
547 | |
493 | sub map_change { |
548 | sub map_change { |
494 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
549 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
495 | |
550 | |
496 | $self->flush_map; |
551 | $self->flush_map; |
|
|
552 | |
|
|
553 | ++$self->{map_change_gen}; |
497 | |
554 | |
498 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
555 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
499 | |
556 | |
500 | my $mapmapw = $self->{mapmap}->{w}; |
557 | my $mapmapw = $self->{mapmap}->{w}; |
501 | my $mapmaph = $self->{mapmap}->{h}; |
558 | my $mapmaph = $self->{mapmap}->{h}; |
… | |
… | |
518 | $self->load_map ($hash, $x, $y); |
575 | $self->load_map ($hash, $x, $y); |
519 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
576 | $self->flood_fill (0, 0, 0, "", $hash, $flags); |
520 | } |
577 | } |
521 | |
578 | |
522 | sub face_find { |
579 | sub face_find { |
523 | my ($self, $facenum, $face) = @_; |
580 | my ($self, $facenum, $face, $cb) = @_; |
524 | |
581 | |
525 | my $hash = "$face->{chksum},$face->{name}"; |
582 | my $hash = "$face->{chksum},$face->{name}"; |
526 | |
583 | |
527 | my $id = $self->{facemap}->get ($hash); |
584 | my $id = CFPlus::DB::get_tile_id_sync $hash; |
528 | |
585 | |
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 | |
|
|
550 | gotid: |
|
|
551 | $face->{id} = $id; |
586 | $face->{id} = $id; |
552 | $self->{map}->set_face ($facenum => $id); |
|
|
553 | $self->{faceid}[$facenum] = $id;#d# |
587 | $self->{faceid}[$facenum] = $id; |
554 | |
588 | |
555 | my $face = $self->{tilecache}->get ($id); |
589 | $self->{map}->set_tileid ($facenum => $id); |
556 | |
590 | |
557 | if ($face) { |
591 | 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 | } |
592 | } |
566 | |
593 | |
567 | sub face_update { |
594 | sub face_update { |
568 | my ($self, $facenum, $face, $changed) = @_; |
595 | my ($self, $facenum, $face, $changed) = @_; |
569 | |
596 | |
570 | $self->{tilecache}->put ($face->{id} => $face->{image}) if $changed; |
597 | CFPlus::DB::put tilecache => $face->{id} => $face->{image}, sub { } |
|
|
598 | if $changed; |
571 | |
599 | |
572 | $self->set_texture ($face->{id} => delete $face->{image}); |
600 | $self->set_texture ($face->{id} => delete $face->{image}); |
|
|
601 | } |
|
|
602 | |
|
|
603 | sub smooth_update { |
|
|
604 | my ($self, $facenum, $face) = @_; |
|
|
605 | |
|
|
606 | $self->{map}->set_smooth ($facenum, $face->{smoothface}, $face->{smoothlevel}); |
573 | } |
607 | } |
574 | |
608 | |
575 | sub set_texture { |
609 | sub set_texture { |
576 | my ($self, $id, $data) = @_; |
610 | my ($self, $id, $data) = @_; |
577 | |
611 | |
578 | $self->{texture}[$id] ||= do { |
612 | $self->{texture}[$id] = my $tex = |
579 | my $tex = |
|
|
580 | new_from_image CFPlus::Texture |
613 | new_from_image CFPlus::Texture |
581 | $data, minify => 1, mipmap => 1; |
614 | $data, minify => 1, mipmap => 1; |
582 | |
615 | |
583 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
616 | $self->{map}->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
584 | $self->{map_widget}->update; |
617 | $self->{map_widget}->update; |
585 | |
|
|
586 | $tex |
|
|
587 | }; |
|
|
588 | } |
618 | } |
589 | |
619 | |
590 | sub sound_play { |
620 | sub sound_play { |
591 | my ($self, $x, $y, $soundnum, $type) = @_; |
621 | my ($self, $x, $y, $soundnum, $type) = @_; |
592 | |
622 | |
… | |
… | |
602 | $LAST_QUERY = $prompt; |
632 | $LAST_QUERY = $prompt; |
603 | |
633 | |
604 | $self->{query}-> ($self, $flags, $prompt); |
634 | $self->{query}-> ($self, $flags, $prompt); |
605 | } |
635 | } |
606 | |
636 | |
607 | sub drawinfo { |
637 | sub sanitise_xml($) { |
608 | my ($self, $color, $text) = @_; |
638 | local $_ = shift; |
609 | |
639 | |
610 | my @color = ( |
640 | # we now weed out all tags we do not support |
|
|
641 | s%<(?!/?i>|/?u>|/?b>|fg |/fg>)%<%g; |
|
|
642 | # now all entities |
|
|
643 | s/&(?!amp;|lt;|gt;|apos;|quot;|#[0-9]+;|#x[0-9a-fA-F]+;)/&/g; |
|
|
644 | |
|
|
645 | # handle some elements |
|
|
646 | s/<fg name='([^']*)'>(.*?)<\/fg>/<span foreground='$1'>$2<\/span>/gs; |
|
|
647 | s/<fg name="([^"]*)">(.*?)<\/fg>/<span foreground="$1">$2<\/span>/gs; |
|
|
648 | |
|
|
649 | $_ |
|
|
650 | } |
|
|
651 | |
|
|
652 | our %NAME_TO_COLOR = ( |
|
|
653 | black => 0, |
|
|
654 | white => 1, |
|
|
655 | darkblue => 2, |
|
|
656 | red => 3, |
|
|
657 | orange => 4, |
|
|
658 | lightblue => 5, |
|
|
659 | darkorange => 6, |
|
|
660 | green => 7, |
|
|
661 | darkgreen => 8, |
|
|
662 | grey => 9, |
|
|
663 | brown => 10, |
|
|
664 | yellow => 11, |
|
|
665 | tan => 12, |
|
|
666 | ); |
|
|
667 | |
|
|
668 | our @CF_COLOR = ( |
611 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
669 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
612 | [1.00, 1.00, 1.00], |
670 | [1.00, 1.00, 1.00], |
613 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
671 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
614 | [1.00, 0.00, 0.00], |
672 | [1.00, 0.00, 0.00], |
615 | [1.00, 0.54, 0.00], |
673 | [1.00, 0.54, 0.00], |
616 | [0.11, 0.56, 1.00], |
674 | [0.11, 0.56, 1.00], |
617 | [0.93, 0.46, 0.00], |
675 | [0.93, 0.46, 0.00], |
618 | [0.18, 0.54, 0.34], |
676 | [0.18, 0.54, 0.34], |
619 | [0.56, 0.73, 0.56], |
677 | [0.56, 0.73, 0.56], |
620 | [0.80, 0.80, 0.80], |
678 | [0.80, 0.80, 0.80], |
621 | [0.75, 0.61, 0.20], |
679 | [0.75, 0.61, 0.20], |
622 | [0.99, 0.77, 0.26], |
680 | [0.99, 0.77, 0.26], |
623 | [0.74, 0.65, 0.41], |
681 | [0.74, 0.65, 0.41], |
624 | ); |
682 | ); |
625 | |
683 | |
|
|
684 | sub msg { |
|
|
685 | my ($self, $color, $type, $text, @extra) = @_; |
|
|
686 | |
|
|
687 | $text = sanitise_xml $text; |
|
|
688 | |
|
|
689 | if (my $cb = $self->{cb_msg}{$type}) { |
|
|
690 | $_->($self, $color, $type, $text, @extra) for values %$cb; |
|
|
691 | } elsif ($type =~ /^(?:chargen-race-title|chargen-race-description)$/) { |
|
|
692 | $type =~ s/-/_/g; |
|
|
693 | $self->{$type} = $text; |
|
|
694 | } else { |
626 | $self->logprint ("info: ", $text); |
695 | $self->logprint ("msg: ", $text); |
|
|
696 | return if $color < 0; # negative color == ignore if not understood |
627 | |
697 | |
|
|
698 | my $fg = $CF_COLOR[$color % @CF_COLOR]; |
|
|
699 | |
628 | # try to create single paragraphs of multiple lines sent by the server |
700 | ## try to create single paragraphs of multiple lines sent by the server |
|
|
701 | # no longer neecssary with TRT servers |
629 | $text =~ s/(?<=\S)\n(?=\w)/ /g; |
702 | #$text =~ s/(?<=\S)\n(?=\w)/ /g; |
630 | |
703 | |
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 => $_ }) |
704 | ::message ({ fg => $fg, markup => $_ }) |
636 | for split /\n/, $text; |
705 | for split /\n/, $text; |
637 | |
706 | |
638 | $self->{statusbox}->add ($text, |
707 | $self->{statusbox}->add ($text, |
639 | group => $text, |
708 | group => $text, |
640 | fg => $color[$color], |
709 | fg => $fg, |
641 | timeout => $color >= 2 ? 180 : 10, |
710 | timeout => $color >= 2 ? 180 : 10, |
642 | tooltip_font => $::FONT_FIXED, |
711 | tooltip_font => $::FONT_FIXED, |
643 | ); |
712 | ); |
644 | } |
713 | } |
645 | |
|
|
646 | sub drawextinfo { |
|
|
647 | my ($self, $color, $type, $subtype, $message) = @_; |
|
|
648 | |
|
|
649 | $self->drawinfo ($color, $message); |
|
|
650 | } |
714 | } |
651 | |
715 | |
652 | sub spell_add { |
716 | sub spell_add { |
653 | my ($self, $spell) = @_; |
717 | my ($self, $spell) = @_; |
654 | |
718 | |
655 | # try to create single paragraphs out of the multiple lines sent by the server |
719 | # try to create single paragraphs out of the multiple lines sent by the server |
656 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
720 | $spell->{message} =~ s/(?<=\S)\n(?=\w)/ /g; |
657 | $spell->{message} =~ s/\n+$//; |
721 | $spell->{message} =~ s/\n+$//; |
658 | $spell->{message} ||= "Server did not provide a description for this spell."; |
722 | $spell->{message} ||= "Server did not provide a description for this spell."; |
659 | |
723 | |
660 | $::SPELL_PAGE->add_spell ($spell); |
724 | $::SPELL_LIST->add_spell ($spell); |
661 | |
725 | |
662 | $self->{map_widget}->add_command ("invoke $spell->{name}", CFPlus::asxml $spell->{message}); |
726 | $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}); |
727 | $self->{map_widget}->add_command ("cast $spell->{name}", CFPlus::asxml $spell->{message}); |
664 | } |
728 | } |
665 | |
729 | |
666 | sub spell_delete { |
730 | sub spell_delete { |
667 | my ($self, $spell) = @_; |
731 | my ($self, $spell) = @_; |
668 | |
732 | |
669 | $::SPELL_PAGE->remove_spell ($spell); |
733 | $::SPELL_LIST->remove_spell ($spell); |
|
|
734 | } |
|
|
735 | |
|
|
736 | sub setup { |
|
|
737 | my ($self, $setup) = @_; |
|
|
738 | |
|
|
739 | $self->{map_widget}->set_tilesize ($self->{tilesize}); |
|
|
740 | $::MAP->resize ($self->{mapw}, $self->{maph}); |
670 | } |
741 | } |
671 | |
742 | |
672 | sub addme_success { |
743 | sub addme_success { |
673 | my ($self) = @_; |
744 | my ($self) = @_; |
674 | |
745 | |
… | |
… | |
880 | $::SERVER_INFO->set_markup ( |
951 | $::SERVER_INFO->set_markup ( |
881 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
952 | "server <tt>$self->{host}:$self->{port}</tt>\n" |
882 | . "protocol version <tt>$self->{version}</tt>\n" |
953 | . "protocol version <tt>$self->{version}</tt>\n" |
883 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
954 | . "minimap support $yesno[$self->{setup}{mapinfocmd} > 0]\n" |
884 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
955 | . "extended command support $yesno[$self->{setup}{extcmd} > 0]\n" |
|
|
956 | . "examine command support $yesno[$self->{setup}{excmd} > 0]\n" |
885 | . "editing support $yesno[!!$self->{editor_support}]\n" |
957 | . "editing support $yesno[!!$self->{editor_support}]\n" |
886 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
958 | . "map attributes $yesno[$self->{setup}{extmap} > 0]\n" |
|
|
959 | . "big image protocol support $yesno[$self->{setup}{fxix} > 0]\n" |
887 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
960 | . "cfplus support $yesno[$self->{cfplus_ext} > 0]" |
888 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
961 | . ($self->{cfplus_ext} > 0 ? ", version $self->{cfplus_ext}" : "") ."\n" |
889 | . "map size $self->{mapw}×$self->{maph}\n" |
962 | . "map size $self->{mapw}×$self->{maph}\n" |
890 | ); |
963 | ); |
|
|
964 | |
|
|
965 | ::setup_build_button ($self->{editor_support}->{builder_ui}); |
891 | } |
966 | } |
892 | |
967 | |
893 | sub logged_in { |
968 | sub logged_in { |
894 | my ($self) = @_; |
969 | my ($self) = @_; |
895 | |
970 | |
… | |
… | |
911 | |
986 | |
912 | $self->update_server_info; |
987 | $self->update_server_info; |
913 | |
988 | |
914 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
989 | $self->send_command ("output-sync $::CFG->{output_sync}"); |
915 | $self->send_command ("output-count $::CFG->{output_count}"); |
990 | $self->send_command ("output-count $::CFG->{output_count}"); |
|
|
991 | $self->send_command ("output-rate $::CFG->{output_rate}") if $::CFG->{output_rate} > 0; |
916 | $self->send_command ("pickup $::CFG->{pickup}"); |
992 | $self->send_command ("pickup $::CFG->{pickup}"); |
|
|
993 | } |
|
|
994 | |
|
|
995 | sub buildat { |
|
|
996 | my ($self, $builditem, $x, $y) = @_; |
|
|
997 | |
|
|
998 | if ($self->{cfplus_ext}) { |
|
|
999 | $self->send_ext_msg (builder_build => dx => $x, dy => $y, (ref ($builditem) eq 'HASH') ? %$builditem : (item => $builditem)); |
|
|
1000 | } |
917 | } |
1001 | } |
918 | |
1002 | |
919 | sub lookat { |
1003 | sub lookat { |
920 | my ($self, $x, $y) = @_; |
1004 | my ($self, $x, $y) = @_; |
921 | |
1005 | |
… | |
… | |
964 | kw => { hi => 0, yes => 0, no => 0 }, |
1048 | kw => { hi => 0, yes => 0, no => 0 }, |
965 | has_close_button => 1, |
1049 | has_close_button => 1, |
966 | @_, |
1050 | @_, |
967 | ); |
1051 | ); |
968 | |
1052 | |
969 | Scalar::Util::weaken (my $this = $self); |
1053 | CFPlus::weaken (my $this = $self); |
970 | |
1054 | |
971 | $self->connect (delete => sub { $this->destroy; 1 }); |
1055 | $self->connect (delete => sub { $this->destroy; 1 }); |
972 | |
1056 | |
973 | # better use a pane... |
1057 | # better use a pane... |
974 | $self->add (my $hbox = new CFPlus::UI::HBox); |
1058 | $self->add (my $hbox = new CFPlus::UI::HBox); |
… | |
… | |
1018 | }; |
1102 | }; |
1019 | |
1103 | |
1020 | sub update_options { |
1104 | sub update_options { |
1021 | my ($self) = @_; |
1105 | my ($self) = @_; |
1022 | |
1106 | |
1023 | Scalar::Util::weaken $self; |
1107 | CFPlus::weaken $self; |
1024 | |
1108 | |
1025 | $self->{options}->clear; |
1109 | $self->{options}->clear; |
1026 | $self->{options}->add ($self->{bye_button}); |
1110 | $self->{options}->add ($self->{bye_button}); |
1027 | |
1111 | |
1028 | for my $kw (sort keys %{ $self->{kw} }) { |
1112 | for my $kw (sort keys %{ $self->{kw} }) { |
… | |
… | |
1037 | } |
1121 | } |
1038 | |
1122 | |
1039 | sub feed { |
1123 | sub feed { |
1040 | my ($self, $msg) = @_; |
1124 | my ($self, $msg) = @_; |
1041 | |
1125 | |
1042 | Scalar::Util::weaken $self; |
1126 | CFPlus::weaken $self; |
1043 | |
1127 | |
1044 | if ($msg->{msgtype} eq "reply") { |
1128 | if ($msg->{msgtype} eq "reply") { |
1045 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1129 | $self->{kw}{$_} = 1 for @{$msg->{add_topics} || []}; |
1046 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1130 | $self->{kw}{$_} = 0 for @{$msg->{del_topics} || []}; |
1047 | |
1131 | |
1048 | my $text = "\n" . CFPlus::asxml $msg->{msg}; |
1132 | 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} }; |
1133 | my $match = join "|", map "\\b\Q$_\E\\b", sort { (length $b) <=> (length $a) } keys %{ $self->{kw} }; |
1050 | my @link; |
1134 | my @link; |
1051 | $text =~ s{ |
1135 | $text =~ s{ |
1052 | ($match) |
1136 | ($match) |
1053 | }{ |
1137 | }{ |