… | |
… | |
272 | Wait until the given lock is available and then acquires it and returns |
272 | Wait until the given lock is available and then acquires it and returns |
273 | a Coro::guard object. If the guard object gets destroyed (goes out of scope, |
273 | a Coro::guard object. If the guard object gets destroyed (goes out of scope, |
274 | for example when the coroutine gets canceled), the lock is automatically |
274 | for example when the coroutine gets canceled), the lock is automatically |
275 | returned. |
275 | returned. |
276 | |
276 | |
|
|
277 | Locks are *not* recursive, locking from the same coro twice results in a |
|
|
278 | deadlocked coro. |
|
|
279 | |
277 | Lock names should begin with a unique identifier (for example, cf::map::find |
280 | Lock names should begin with a unique identifier (for example, cf::map::find |
278 | uses map_find and cf::map::load uses map_load). |
281 | uses map_find and cf::map::load uses map_load). |
279 | |
282 | |
280 | =item $locked = cf::lock_active $string |
283 | =item $locked = cf::lock_active $string |
281 | |
284 | |
… | |
… | |
1460 | sub expand_cfpod { |
1463 | sub expand_cfpod { |
1461 | ((my $self), (local $_)) = @_; |
1464 | ((my $self), (local $_)) = @_; |
1462 | |
1465 | |
1463 | # escape & and < |
1466 | # escape & and < |
1464 | s/&/&/g; |
1467 | s/&/&/g; |
1465 | s/(?<![BIUGH])</</g; |
1468 | s/(?<![BIUGHT])</</g; |
1466 | |
1469 | |
1467 | # this is buggy, it needs to properly take care of nested <'s |
1470 | # this is buggy, it needs to properly take care of nested <'s |
1468 | |
1471 | |
1469 | 1 while |
1472 | 1 while |
1470 | # replace B<>, I<>, U<> etc. |
1473 | # replace B<>, I<>, U<> etc. |
1471 | s/B<([^\>]*)>/<b>$1<\/b>/ |
1474 | s/B<([^\>]*)>/<b>$1<\/b>/ |
1472 | || s/I<([^\>]*)>/<i>$1<\/i>/ |
1475 | || s/I<([^\>]*)>/<i>$1<\/i>/ |
1473 | || s/U<([^\>]*)>/<u>$1<\/u>/ |
1476 | || s/U<([^\>]*)>/<u>$1<\/u>/ |
|
|
1477 | || s/T<([^\>]*)>/<big><b>$1<\/b><\/big>/ |
1474 | # replace G<male|female> tags |
1478 | # replace G<male|female> tags |
1475 | || s{G<([^>|]*)\|([^>]*)>}{ |
1479 | || s{G<([^>|]*)\|([^>]*)>}{ |
1476 | $self->gender ? $2 : $1 |
1480 | $self->gender ? $2 : $1 |
1477 | }ge |
1481 | }ge |
1478 | # replace H<hint text> |
1482 | # replace H<hint text> |
… | |
… | |
2083 | my $nuke_counter = "aaaa"; |
2087 | my $nuke_counter = "aaaa"; |
2084 | |
2088 | |
2085 | sub nuke { |
2089 | sub nuke { |
2086 | my ($self) = @_; |
2090 | my ($self) = @_; |
2087 | |
2091 | |
|
|
2092 | { |
|
|
2093 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
|
|
2094 | |
2088 | delete $cf::MAP{$self->path}; |
2095 | delete $cf::MAP{$self->path}; |
2089 | |
2096 | |
2090 | $self->unlink_save; |
2097 | $self->unlink_save; |
2091 | |
2098 | |
2092 | bless $self, "cf::map"; |
2099 | bless $self, "cf::map"; |
2093 | delete $self->{deny_reset}; |
2100 | delete $self->{deny_reset}; |
2094 | $self->{deny_save} = 1; |
2101 | $self->{deny_save} = 1; |
2095 | $self->reset_timeout (1); |
2102 | $self->reset_timeout (1); |
2096 | $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++)); |
2103 | $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++)); |
2097 | |
2104 | |
2098 | $cf::MAP{$self->path} = $self; |
2105 | $cf::MAP{$self->path} = $self; |
|
|
2106 | } |
2099 | |
2107 | |
2100 | $self->reset; # polite request, might not happen |
2108 | $self->reset; # polite request, might not happen |
2101 | } |
2109 | } |
2102 | |
2110 | |
2103 | =item $maps = cf::map::tmp_maps |
2111 | =item $maps = cf::map::tmp_maps |
… | |
… | |
2497 | the message, with C<log> being the default. If C<$color> is negative, suppress |
2505 | the message, with C<log> being the default. If C<$color> is negative, suppress |
2498 | the message unless the client supports the msg packet. |
2506 | the message unless the client supports the msg packet. |
2499 | |
2507 | |
2500 | =cut |
2508 | =cut |
2501 | |
2509 | |
|
|
2510 | our %CHANNEL = ( |
|
|
2511 | "c/identify" => { |
|
|
2512 | id => "identify", |
|
|
2513 | title => "Identify", |
|
|
2514 | reply => undef, |
|
|
2515 | tooltip => "Items recently identified", |
|
|
2516 | }, |
|
|
2517 | "c/examine" => { |
|
|
2518 | id => "examine", |
|
|
2519 | title => "Examine", |
|
|
2520 | reply => undef, |
|
|
2521 | tooltip => "Signs and other items you examined", |
|
|
2522 | }, |
|
|
2523 | ); |
|
|
2524 | |
2502 | sub cf::client::send_msg { |
2525 | sub cf::client::send_msg { |
2503 | my ($self, $channel, $msg, $color, @extra) = @_; |
2526 | my ($self, $channel, $msg, $color, @extra) = @_; |
2504 | |
2527 | |
2505 | $msg = $self->pl->expand_cfpod ($msg); |
2528 | $msg = $self->pl->expand_cfpod ($msg); |
2506 | |
2529 | |
2507 | $color &= cf::NDI_CLIENT_MASK; # just in case... |
2530 | $color &= cf::NDI_CLIENT_MASK; # just in case... |
|
|
2531 | |
|
|
2532 | # check predefined channels, for the benefit of C |
|
|
2533 | $channel = $CHANNEL{$channel} if $CHANNEL{$channel}; |
2508 | |
2534 | |
2509 | if (ref $channel) { |
2535 | if (ref $channel) { |
2510 | # send meta info to client, if not yet sent |
2536 | # send meta info to client, if not yet sent |
2511 | unless (exists $self->{channel}{$channel->{id}}) { |
2537 | unless (exists $self->{channel}{$channel->{id}}) { |
2512 | $self->{channel}{$channel->{id}} = $channel; |
2538 | $self->{channel}{$channel->{id}} = $channel; |
… | |
… | |
2833 | # the server's init and main functions |
2859 | # the server's init and main functions |
2834 | |
2860 | |
2835 | sub load_facedata($) { |
2861 | sub load_facedata($) { |
2836 | my ($path) = @_; |
2862 | my ($path) = @_; |
2837 | |
2863 | |
|
|
2864 | # HACK to clear player env face cache, we need some signal framework |
|
|
2865 | # for this (global event?) |
|
|
2866 | %ext::player_env::MUSIC_FACE_CACHE = (); |
|
|
2867 | |
2838 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
2868 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
2839 | |
2869 | |
2840 | warn "loading facedata from $path\n"; |
2870 | warn "loading facedata from $path\n"; |
2841 | |
2871 | |
2842 | my $facedata; |
2872 | my $facedata; |
… | |
… | |
2953 | $ns->fx_want ($k, $v); |
2983 | $ns->fx_want ($k, $v); |
2954 | } |
2984 | } |
2955 | }; |
2985 | }; |
2956 | |
2986 | |
2957 | sub reload_regions { |
2987 | sub reload_regions { |
|
|
2988 | # HACK to clear player env face cache, we need some signal framework |
|
|
2989 | # for this (global event?) |
|
|
2990 | %ext::player_env::MUSIC_FACE_CACHE = (); |
|
|
2991 | |
2958 | load_resource_file "$MAPDIR/regions" |
2992 | load_resource_file "$MAPDIR/regions" |
2959 | or die "unable to load regions file\n"; |
2993 | or die "unable to load regions file\n"; |
2960 | |
2994 | |
2961 | for (cf::region::list) { |
2995 | for (cf::region::list) { |
2962 | $_->{match} = qr/$_->{match}/ |
2996 | $_->{match} = qr/$_->{match}/ |