ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.345 by root, Tue Aug 28 19:30:11 2007 UTC vs.
Revision 1.353 by root, Sun Sep 2 08:43:46 2007 UTC

272Wait until the given lock is available and then acquires it and returns 272Wait until the given lock is available and then acquires it and returns
273a Coro::guard object. If the guard object gets destroyed (goes out of scope, 273a Coro::guard object. If the guard object gets destroyed (goes out of scope,
274for example when the coroutine gets canceled), the lock is automatically 274for example when the coroutine gets canceled), the lock is automatically
275returned. 275returned.
276 276
277Locks are *not* recursive, locking from the same coro twice results in a
278deadlocked coro.
279
277Lock names should begin with a unique identifier (for example, cf::map::find 280Lock names should begin with a unique identifier (for example, cf::map::find
278uses map_find and cf::map::load uses map_load). 281uses 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
575 if (1) { 578 if (1) {
576 $md5 = 579 $md5 =
577 join "\x00", 580 join "\x00",
578 $processversion, 581 $processversion,
579 map { 582 map {
580 Coro::cede; 583 cf::cede_to_tick;
581 ($src->[$_], Digest::MD5::md5_hex $data[$_]) 584 ($src->[$_], Digest::MD5::md5_hex $data[$_])
582 } 0.. $#$src; 585 } 0.. $#$src;
583 586
584 587
585 my $dbmd5 = db_get cache => "$id/md5"; 588 my $dbmd5 = db_get cache => "$id/md5";
1322 1325
1323 aio_mkdir playerdir $pl, 0770; 1326 aio_mkdir playerdir $pl, 0770;
1324 $pl->{last_save} = $cf::RUNTIME; 1327 $pl->{last_save} = $cf::RUNTIME;
1325 1328
1326 $pl->save_pl ($path); 1329 $pl->save_pl ($path);
1327 Coro::cede; 1330 cf::cede_to_tick;
1328} 1331}
1329 1332
1330sub new($) { 1333sub new($) {
1331 my ($login) = @_; 1334 my ($login) = @_;
1332 1335
1460sub expand_cfpod { 1463sub expand_cfpod {
1461 ((my $self), (local $_)) = @_; 1464 ((my $self), (local $_)) = @_;
1462 1465
1463 # escape & and < 1466 # escape & and <
1464 s/&/&amp;/g; 1467 s/&/&amp;/g;
1465 s/(?<![BIUGH])</&lt;/g; 1468 s/(?<![BIUGHT])</&lt;/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>
1859 $self->in_memory (cf::MAP_LOADING); 1863 $self->in_memory (cf::MAP_LOADING);
1860 1864
1861 $self->alloc; 1865 $self->alloc;
1862 1866
1863 $self->pre_load; 1867 $self->pre_load;
1864 Coro::cede; 1868 cf::cede_to_tick;
1865 1869
1866 $self->_load_objects ($self->{load_path}, 1) 1870 $self->_load_objects ($self->{load_path}, 1)
1867 or return; 1871 or return;
1868 1872
1869 $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1) 1873 $self->set_object_flag (cf::FLAG_OBJ_ORIGINAL, 1)
1875 $self->clear_unique_items; 1879 $self->clear_unique_items;
1876 $self->_load_objects ($uniq, 0); 1880 $self->_load_objects ($uniq, 0);
1877 } 1881 }
1878 } 1882 }
1879 1883
1880 Coro::cede; 1884 cf::cede_to_tick;
1881 # now do the right thing for maps 1885 # now do the right thing for maps
1882 $self->link_multipart_objects; 1886 $self->link_multipart_objects;
1883 $self->difficulty ($self->estimate_difficulty) 1887 $self->difficulty ($self->estimate_difficulty)
1884 unless $self->difficulty; 1888 unless $self->difficulty;
1885 Coro::cede; 1889 cf::cede_to_tick;
1886 1890
1887 unless ($self->{deny_activate}) { 1891 unless ($self->{deny_activate}) {
1888 $self->decay_objects; 1892 $self->decay_objects;
1889 $self->fix_auto_apply; 1893 $self->fix_auto_apply;
1890 $self->update_buttons; 1894 $self->update_buttons;
1891 Coro::cede; 1895 cf::cede_to_tick;
1892 $self->set_darkness_map; 1896 $self->set_darkness_map;
1893 Coro::cede; 1897 cf::cede_to_tick;
1894 $self->activate; 1898 $self->activate;
1895 } 1899 }
1896 1900
1897 $self->{last_save} = $cf::RUNTIME; 1901 $self->{last_save} = $cf::RUNTIME;
1898 $self->last_access ($cf::RUNTIME); 1902 $self->last_access ($cf::RUNTIME);
2083my $nuke_counter = "aaaa"; 2087my $nuke_counter = "aaaa";
2084 2088
2085sub nuke { 2089sub 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
2497the message, with C<log> being the default. If C<$color> is negative, suppress 2505the message, with C<log> being the default. If C<$color> is negative, suppress
2498the message unless the client supports the msg packet. 2506the message unless the client supports the msg packet.
2499 2507
2500=cut 2508=cut
2501 2509
2510our %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
2502sub cf::client::send_msg { 2525sub 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;
2513 $self->ext_msg (channel_info => $channel); 2539 $self->ext_msg (channel_info => $channel)
2540 if $self->can_msg;
2514 } 2541 }
2515 2542
2516 $channel = $channel->{id}; 2543 $channel = $channel->{id};
2517 } 2544 }
2518 2545
2833# the server's init and main functions 2860# the server's init and main functions
2834 2861
2835sub load_facedata($) { 2862sub load_facedata($) {
2836 my ($path) = @_; 2863 my ($path) = @_;
2837 2864
2865 # HACK to clear player env face cache, we need some signal framework
2866 # for this (global event?)
2867 %ext::player_env::MUSIC_FACE_CACHE = ();
2868
2838 my $enc = JSON::XS->new->utf8->canonical->relaxed; 2869 my $enc = JSON::XS->new->utf8->canonical->relaxed;
2839 2870
2840 warn "loading facedata from $path\n"; 2871 warn "loading facedata from $path\n";
2841 2872
2842 my $facedata; 2873 my $facedata;
2953 $ns->fx_want ($k, $v); 2984 $ns->fx_want ($k, $v);
2954 } 2985 }
2955}; 2986};
2956 2987
2957sub reload_regions { 2988sub reload_regions {
2989 # HACK to clear player env face cache, we need some signal framework
2990 # for this (global event?)
2991 %ext::player_env::MUSIC_FACE_CACHE = ();
2992
2958 load_resource_file "$MAPDIR/regions" 2993 load_resource_file "$MAPDIR/regions"
2959 or die "unable to load regions file\n"; 2994 or die "unable to load regions file\n";
2960 2995
2961 for (cf::region::list) { 2996 for (cf::region::list) {
2962 $_->{match} = qr/$_->{match}/ 2997 $_->{match} = qr/$_->{match}/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines