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.418 by root, Fri Apr 11 21:09:53 2008 UTC vs.
Revision 1.434 by root, Thu May 29 03:27:37 2008 UTC

25use strict; 25use strict;
26 26
27use Symbol; 27use Symbol;
28use List::Util; 28use List::Util;
29use Socket; 29use Socket;
30use EV 3.2; 30use EV;
31use Opcode; 31use Opcode;
32use Safe; 32use Safe;
33use Safe::Hole; 33use Safe::Hole;
34use Storable (); 34use Storable ();
35 35
36use Coro 4.50 (); 36use Coro ();
37use Coro::State; 37use Coro::State;
38use Coro::Handle; 38use Coro::Handle;
39use Coro::EV; 39use Coro::AnyEvent;
40use Coro::Timer; 40use Coro::Timer;
41use Coro::Signal; 41use Coro::Signal;
42use Coro::Semaphore; 42use Coro::Semaphore;
43use Coro::AnyEvent;
43use Coro::AIO; 44use Coro::AIO;
44use Coro::BDB; 45use Coro::BDB;
45use Coro::Storable; 46use Coro::Storable;
46use Coro::Util (); 47use Coro::Util ();
47 48
49use BDB (); 50use BDB ();
50use Data::Dumper; 51use Data::Dumper;
51use Digest::MD5; 52use Digest::MD5;
52use Fcntl; 53use Fcntl;
53use YAML (); 54use YAML ();
54use IO::AIO 2.51 (); 55use IO::AIO ();
55use Time::HiRes; 56use Time::HiRes;
56use Compress::LZF; 57use Compress::LZF;
57use Digest::MD5 (); 58use Digest::MD5 ();
59
60AnyEvent::detect;
61
62IO::AIO::max_poll_reqs 1;#d#
58 63
59# configure various modules to our taste 64# configure various modules to our taste
60# 65#
61$Storable::canonical = 1; # reduce rsync transfers 66$Storable::canonical = 1; # reduce rsync transfers
62Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator 67Coro::State::cctx_stacksize 256000; # 1-2MB stack, for deep recursions in maze generator
90our $RANDOMDIR = "$LOCALDIR/random"; 95our $RANDOMDIR = "$LOCALDIR/random";
91our $BDBDIR = "$LOCALDIR/db"; 96our $BDBDIR = "$LOCALDIR/db";
92our %RESOURCE; 97our %RESOURCE;
93 98
94our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) 99our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
95our $AIO_POLL_WATCHER;
96our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 100our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
97our $NEXT_TICK; 101our $NEXT_TICK;
98our $USE_FSYNC = 1; # use fsync to write maps - default off 102our $USE_FSYNC = 1; # use fsync to write maps - default off
99 103
100our $BDB_POLL_WATCHER;
101our $BDB_DEADLOCK_WATCHER; 104our $BDB_DEADLOCK_WATCHER;
102our $BDB_CHECKPOINT_WATCHER; 105our $BDB_CHECKPOINT_WATCHER;
103our $BDB_TRICKLE_WATCHER; 106our $BDB_TRICKLE_WATCHER;
104our $DB_ENV; 107our $DB_ENV;
105 108
427 } 430 }
428 } 431 }
429}; 432};
430 433
431sub get_slot($;$$) { 434sub get_slot($;$$) {
435 return if tick_inhibit || $Coro::current == $Coro::main;
436
432 my ($time, $pri, $name) = @_; 437 my ($time, $pri, $name) = @_;
433 438
434 $time = $TICK * .6 if $time > $TICK * .6; 439 $time = $TICK * .6 if $time > $TICK * .6;
435 my $sig = new Coro::Signal; 440 my $sig = new Coro::Signal;
436 441
1139 utf8::decode (my $decname = $filename); 1144 utf8::decode (my $decname = $filename);
1140 warn sprintf "saving %s (%d,%d)\n", 1145 warn sprintf "saving %s (%d,%d)\n",
1141 $decname, length $$rdata, scalar @$objs; 1146 $decname, length $$rdata, scalar @$objs;
1142 1147
1143 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { 1148 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) {
1144 chmod SAVE_MODE, $fh; 1149 aio_chmod $fh, SAVE_MODE;
1145 aio_write $fh, 0, (length $$rdata), $$rdata, 0; 1150 aio_write $fh, 0, (length $$rdata), $$rdata, 0;
1146 aio_fsync $fh if $cf::USE_FSYNC; 1151 aio_fsync $fh if $cf::USE_FSYNC;
1147 close $fh; 1152 aio_close $fh;
1148 1153
1149 if (@$objs) { 1154 if (@$objs) {
1150 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { 1155 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) {
1151 chmod SAVE_MODE, $fh; 1156 aio_chmod $fh, SAVE_MODE;
1152 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs }; 1157 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs };
1153 aio_write $fh, 0, (length $data), $data, 0; 1158 aio_write $fh, 0, (length $data), $data, 0;
1154 aio_fsync $fh if $cf::USE_FSYNC; 1159 aio_fsync $fh if $cf::USE_FSYNC;
1155 close $fh; 1160 aio_close $fh;
1156 aio_rename "$filename.pst~", "$filename.pst"; 1161 aio_rename "$filename.pst~", "$filename.pst";
1157 } 1162 }
1158 } else { 1163 } else {
1159 aio_unlink "$filename.pst"; 1164 aio_unlink "$filename.pst";
1160 } 1165 }
1454 my $f = new_from_file cf::object::thawer path $login 1459 my $f = new_from_file cf::object::thawer path $login
1455 or return; 1460 or return;
1456 1461
1457 my $pl = cf::player::load_pl $f 1462 my $pl = cf::player::load_pl $f
1458 or return; 1463 or return;
1464
1459 local $cf::PLAYER_LOADING{$login} = $pl; 1465 local $cf::PLAYER_LOADING{$login} = $pl;
1460 $f->resolve_delayed_derefs; 1466 $f->resolve_delayed_derefs;
1461 $cf::PLAYER{$login} = $pl 1467 $cf::PLAYER{$login} = $pl
1462 } 1468 }
1463 } 1469 }
1473 1479
1474 return if $pl->{deny_save}; 1480 return if $pl->{deny_save};
1475 1481
1476 aio_mkdir playerdir $pl, 0770; 1482 aio_mkdir playerdir $pl, 0770;
1477 $pl->{last_save} = $cf::RUNTIME; 1483 $pl->{last_save} = $cf::RUNTIME;
1484
1485 cf::get_slot 0.01;
1478 1486
1479 $pl->save_pl ($path); 1487 $pl->save_pl ($path);
1480 cf::cede_to_tick; 1488 cf::cede_to_tick;
1481} 1489}
1482 1490
1518 $pl->{deny_save} = 1; 1526 $pl->{deny_save} = 1;
1519 $pl->password ("*"); # this should lock out the player until we nuked the dir 1527 $pl->password ("*"); # this should lock out the player until we nuked the dir
1520 1528
1521 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; 1529 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active;
1522 $pl->deactivate; 1530 $pl->deactivate;
1531 my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy;
1532 $pl->ob->check_score;
1523 $pl->invoke (cf::EVENT_PLAYER_QUIT); 1533 $pl->invoke (cf::EVENT_PLAYER_QUIT);
1524 $pl->ns->destroy if $pl->ns; 1534 $pl->ns->destroy if $pl->ns;
1525 1535
1526 my $path = playerdir $pl; 1536 my $path = playerdir $pl;
1527 my $temp = "$path~$cf::RUNTIME~deleting~"; 1537 my $temp = "$path~$cf::RUNTIME~deleting~";
1566 1576
1567 for my $login (@$dirs) { 1577 for my $login (@$dirs) {
1568 my $path = path $login; 1578 my $path = path $login;
1569 1579
1570 # a .pst is a dead give-away for a valid player 1580 # a .pst is a dead give-away for a valid player
1571 unless (-e "$path.pst") { 1581 # if no pst file found, open and chekc for blocked users
1582 if (aio_stat "$path.pst") {
1572 my $fh = aio_open $path, Fcntl::O_RDONLY, 0 or next; 1583 my $fh = aio_open $path, Fcntl::O_RDONLY, 0 or next;
1573 aio_read $fh, 0, 512, my $buf, 0 or next; 1584 aio_read $fh, 0, 512, my $buf, 0 or next;
1574 $buf !~ /^password -------------$/m or next; # official not-valid tag 1585 $buf !~ /^password -------------$/m or next; # official not-valid tag
1575 } 1586 }
1576 1587
1909 1920
1910# the temporary/swap location 1921# the temporary/swap location
1911sub save_path { 1922sub save_path {
1912 my ($self) = @_; 1923 my ($self) = @_;
1913 1924
1914 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g; 1925 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/go;
1915 "$TMPDIR/$path.map" 1926 "$TMPDIR/$path.map"
1916} 1927}
1917 1928
1918# the unique path, undef == no special unique path 1929# the unique path, undef == no special unique path
1919sub uniq_path { 1930sub uniq_path {
1920 my ($self) = @_; 1931 my ($self) = @_;
1921 1932
1922 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g; 1933 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/go;
1923 "$UNIQUEDIR/$path" 1934 "$UNIQUEDIR/$path"
1924} 1935}
1925 1936
1926# and all this just because we cannot iterate over 1937# and all this just because we cannot iterate over
1927# all maps in C++... 1938# all maps in C++...
2025 2036
2026 cf::lock_wait "map_data:$path";#d#remove 2037 cf::lock_wait "map_data:$path";#d#remove
2027 cf::lock_wait "map_find:$path"; 2038 cf::lock_wait "map_find:$path";
2028 2039
2029 $cf::MAP{$path} || do { 2040 $cf::MAP{$path} || do {
2030 my $guard1 = cf::lock_acquire "map_find:$path";
2031 my $guard2 = cf::lock_acquire "map_data:$path"; # just for the fun of it 2041 my $guard1 = cf::lock_acquire "map_data:$path"; # just for the fun of it
2042 my $guard2 = cf::lock_acquire "map_find:$path";
2032 2043
2033 my $map = new_from_path cf::map $path 2044 my $map = new_from_path cf::map $path
2034 or return; 2045 or return;
2035 2046
2036 $map->{last_save} = $cf::RUNTIME; 2047 $map->{last_save} = $cf::RUNTIME;
2039 or return; 2050 or return;
2040 2051
2041 if ($map->should_reset) {#d#TODO# disabled, crashy (locking issue?) 2052 if ($map->should_reset) {#d#TODO# disabled, crashy (locking issue?)
2042 # doing this can freeze the server in a sync job, obviously 2053 # doing this can freeze the server in a sync job, obviously
2043 #$cf::WAIT_FOR_TICK->wait; 2054 #$cf::WAIT_FOR_TICK->wait;
2055 undef $guard2;
2044 undef $guard1; 2056 undef $guard1;
2045 undef $guard2;
2046 $map->reset; 2057 $map->reset;
2047 return find $path; 2058 return find $path;
2048 } 2059 }
2049 2060
2050 $cf::MAP{$path} = $map 2061 $cf::MAP{$path} = $map
2113 } 2124 }
2114 2125
2115 $self->{last_save} = $cf::RUNTIME; 2126 $self->{last_save} = $cf::RUNTIME;
2116 $self->last_access ($cf::RUNTIME); 2127 $self->last_access ($cf::RUNTIME);
2117 2128
2118 $self->in_memory (cf::MAP_IN_MEMORY); 2129 $self->in_memory (cf::MAP_ACTIVE);
2119 } 2130 }
2120 2131
2121 $self->post_load; 2132 $self->post_load;
2122} 2133}
2123 2134
2181 my ($path, $origin, $load) = @_; 2192 my ($path, $origin, $load) = @_;
2182 2193
2183 $path = normalise $path, $origin && $origin->{path}; 2194 $path = normalise $path, $origin && $origin->{path};
2184 2195
2185 if (my $map = $cf::MAP{$path}) { 2196 if (my $map = $cf::MAP{$path}) {
2186 return $map if !$load || $map->in_memory == cf::MAP_IN_MEMORY; 2197 return $map if !$load || $map->in_memory == cf::MAP_ACTIVE;
2187 } 2198 }
2188 2199
2189 $MAP_PREFETCH{$path} |= $load; 2200 $MAP_PREFETCH{$path} |= $load;
2190 2201
2191 $MAP_PREFETCHER ||= cf::async { 2202 $MAP_PREFETCHER ||= cf::async {
2228 cf::async { 2239 cf::async {
2229 $Coro::current->{desc} = "map player save"; 2240 $Coro::current->{desc} = "map player save";
2230 $_->contr->save for $self->players; 2241 $_->contr->save for $self->players;
2231 }; 2242 };
2232 2243
2244 cf::get_slot 0.02;
2245
2233 if ($uniq) { 2246 if ($uniq) {
2234 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS); 2247 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS);
2235 $self->_save_objects ($uniq, cf::IO_UNIQUES); 2248 $self->_save_objects ($uniq, cf::IO_UNIQUES);
2236 } else { 2249 } else {
2237 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES); 2250 $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS | cf::IO_UNIQUES);
2245 $self->save; 2258 $self->save;
2246 2259
2247 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2260 my $lock = cf::lock_acquire "map_data:$self->{path}";
2248 2261
2249 return if $self->players; 2262 return if $self->players;
2250 return if $self->in_memory != cf::MAP_IN_MEMORY; 2263 return if $self->in_memory != cf::MAP_ACTIVE;
2251 return if $self->{deny_save}; 2264 return if $self->{deny_save};
2252 2265
2253 $self->in_memory (cf::MAP_SWAPPED); 2266 $self->in_memory (cf::MAP_SWAPPED);
2254 2267
2255 $self->deactivate; 2268 $self->deactivate;
2373 2386
2374sub unique_maps() { 2387sub unique_maps() {
2375 [ 2388 [
2376 map { 2389 map {
2377 utf8::decode $_; 2390 utf8::decode $_;
2378 /\.map$/ 2391 s/\.map$//; # TODO future compatibility hack
2392 /\.pst$/ || !/^$PATH_SEP/o # TODO unique maps apparebntly lack the .map suffix :/
2393 ? ()
2379 ? normalise $_ 2394 : normalise $_
2380 : ()
2381 } @{ aio_readdir $UNIQUEDIR or [] } 2395 } @{ aio_readdir $UNIQUEDIR or [] }
2382 ] 2396 ]
2383} 2397}
2384 2398
2385=back 2399=back
2392 2406
2393=over 4 2407=over 4
2394 2408
2395=item $ob->inv_recursive 2409=item $ob->inv_recursive
2396 2410
2397Returns the inventory of the object _and_ their inventories, recursively. 2411Returns the inventory of the object I<and> their inventories, recursively,
2412but I<not> the object itself.
2398 2413
2399=cut 2414=cut
2400 2415
2401sub inv_recursive_; 2416sub inv_recursive_;
2402sub inv_recursive_ { 2417sub inv_recursive_ {
2407 inv_recursive_ inv $_[0] 2422 inv_recursive_ inv $_[0]
2408} 2423}
2409 2424
2410=item $ref = $ob->ref 2425=item $ref = $ob->ref
2411 2426
2412creates and returns a persistent reference to an objetc that can be stored as a string. 2427Creates and returns a persistent reference to an object that can be stored as a string.
2413 2428
2414=item $ob = cf::object::deref ($refstring) 2429=item $ob = cf::object::deref ($refstring)
2415 2430
2416returns the objetc referenced by refstring. may return undef when it cnanot find the object, 2431returns the objetc referenced by refstring. may return undef when it cnanot find the object,
2417even if the object actually exists. May block. 2432even if the object actually exists. May block.
2449can be C<undef>. Does the right thing when the player is currently in a 2464can be C<undef>. Does the right thing when the player is currently in a
2450dialogue with the given NPC character. 2465dialogue with the given NPC character.
2451 2466
2452=cut 2467=cut
2453 2468
2469our $SAY_CHANNEL = {
2470 id => "say",
2471 title => "Map",
2472 reply => "say ",
2473 tooltip => "Things said to and replied from npcs near you and other players on the same map only.",
2474};
2475
2476our $CHAT_CHANNEL = {
2477 id => "chat",
2478 title => "Chat",
2479 reply => "chat ",
2480 tooltip => "Player chat and shouts, global to the server.",
2481};
2482
2454# rough implementation of a future "reply" method that works 2483# rough implementation of a future "reply" method that works
2455# with dialog boxes. 2484# with dialog boxes.
2456#TODO: the first argument must go, split into a $npc->reply_to ( method 2485#TODO: the first argument must go, split into a $npc->reply_to ( method
2457sub cf::object::player::reply($$$;$) { 2486sub cf::object::player::reply($$$;$) {
2458 my ($self, $npc, $msg, $flags) = @_; 2487 my ($self, $npc, $msg, $flags) = @_;
2469 my $dialog = $pl->{npc_dialog}; 2498 my $dialog = $pl->{npc_dialog};
2470 $dialog->{pl}->ext_msg ($dialog->{id}, update => msg => $dialog->{pl}->expand_cfpod ($msg)); 2499 $dialog->{pl}->ext_msg ($dialog->{id}, update => msg => $dialog->{pl}->expand_cfpod ($msg));
2471 2500
2472 } else { 2501 } else {
2473 $msg = $npc->name . " says: $msg" if $npc; 2502 $msg = $npc->name . " says: $msg" if $npc;
2474 $self->message ($msg, $flags); 2503 $self->send_msg ($SAY_CHANNEL => $msg, $flags);
2475 } 2504 }
2476 } 2505 }
2477} 2506}
2478 2507
2479=item $object->send_msg ($channel, $msg, $color, [extra...]) 2508=item $object->send_msg ($channel, $msg, $color, [extra...])
2674} 2703}
2675 2704
2676sub prepare_random_map { 2705sub prepare_random_map {
2677 my ($exit) = @_; 2706 my ($exit) = @_;
2678 2707
2679 my $guard = cf::lock_acquire "exit_prepare:$exit";
2680
2681 # all this does is basically replace the /! path by 2708 # all this does is basically replace the /! path by
2682 # a new random map path (?random/...) with a seed 2709 # a new random map path (?random/...) with a seed
2683 # that depends on the exit object 2710 # that depends on the exit object
2684 2711
2685 my $rmp = parse_random_map_params $exit->msg; 2712 my $rmp = parse_random_map_params $exit->msg;
2687 if ($exit->map) { 2714 if ($exit->map) {
2688 $rmp->{region} = $exit->region->name; 2715 $rmp->{region} = $exit->region->name;
2689 $rmp->{origin_map} = $exit->map->path; 2716 $rmp->{origin_map} = $exit->map->path;
2690 $rmp->{origin_x} = $exit->x; 2717 $rmp->{origin_x} = $exit->x;
2691 $rmp->{origin_y} = $exit->y; 2718 $rmp->{origin_y} = $exit->y;
2719
2720 $exit->map->touch;
2692 } 2721 }
2693 2722
2694 $rmp->{random_seed} ||= $exit->random_seed; 2723 $rmp->{random_seed} ||= $exit->random_seed;
2695 2724
2696 my $data = cf::encode_json $rmp; 2725 my $data = JSON::XS->new->utf8->pretty->canonical->encode ($rmp);
2697 my $md5 = Digest::MD5::md5_hex $data; 2726 my $md5 = Digest::MD5::md5_hex $data;
2698 my $meta = "$RANDOMDIR/$md5.meta"; 2727 my $meta = "$RANDOMDIR/$md5.meta";
2699 2728
2700 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) { 2729 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) {
2701 aio_write $fh, 0, (length $data), $data, 0; 2730 aio_write $fh, 0, (length $data), $data, 0;
2702 undef $fh; 2731 undef $fh;
2703 aio_rename "$meta~", $meta; 2732 aio_rename "$meta~", $meta;
2704 2733
2734 my $slaying = "?random/$md5";
2735
2736 if ($exit->valid) {
2705 $exit->slaying ("?random/$md5"); 2737 $exit->slaying ("?random/$md5");
2706 $exit->msg (undef); 2738 $exit->msg (undef);
2739 }
2707 } 2740 }
2708} 2741}
2709 2742
2710sub cf::object::player::enter_exit { 2743sub cf::object::player::enter_exit {
2711 my ($self, $exit) = @_; 2744 my ($self, $exit) = @_;
2712 2745
2713 return unless $self->type == cf::PLAYER; 2746 return unless $self->type == cf::PLAYER;
2714 2747
2715 if ($exit->slaying eq "/!") {
2716 #TODO: this should de-fi-ni-te-ly not be a sync-job
2717 # the problem is that $exit might not survive long enough
2718 # so it needs to be done right now, right here
2719 cf::sync_job { prepare_random_map $exit };
2720 }
2721
2722 my $slaying = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path;
2723 my $hp = $exit->stats->hp;
2724 my $sp = $exit->stats->sp;
2725
2726 $self->enter_link; 2748 $self->enter_link;
2727 2749
2728 # if exit is damned, update players death & WoR home-position
2729 $self->contr->savebed ($slaying, $hp, $sp)
2730 if $exit->flag (FLAG_DAMNED);
2731
2732 (async { 2750 (async {
2733 $Coro::current->{desc} = "enter_exit $slaying $hp $sp"; 2751 $Coro::current->{desc} = "enter_exit";
2734 2752
2735 $self->deactivate_recursive; # just to be sure
2736 unless (eval { 2753 unless (eval {
2754 $self->deactivate_recursive; # just to be sure
2755
2756 # random map handling
2757 {
2758 my $guard = cf::lock_acquire "exit_prepare:$exit";
2759
2760 prepare_random_map $exit
2761 if $exit->slaying eq "/!";
2762 }
2763
2764 my $map = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path;
2765 my $x = $exit->stats->hp;
2766 my $y = $exit->stats->sp;
2767
2737 $self->goto ($slaying, $hp, $sp); 2768 $self->goto ($map, $x, $y);
2738 2769
2770 # if exit is damned, update players death & WoR home-position
2771 $self->contr->savebed ($map, $x, $y)
2772 if $exit->flag (cf::FLAG_DAMNED);
2773
2739 1; 2774 1
2740 }) { 2775 }) {
2741 $self->message ("Something went wrong deep within the crossfire server. " 2776 $self->message ("Something went wrong deep within the crossfire server. "
2742 . "I'll try to bring you back to the map you were before. " 2777 . "I'll try to bring you back to the map you were before. "
2743 . "Please report this to the dungeon master!", 2778 . "Please report this to the dungeon master!",
2744 cf::NDI_UNIQUE | cf::NDI_RED); 2779 cf::NDI_UNIQUE | cf::NDI_RED);
2824 id => "infobox", 2859 id => "infobox",
2825 title => "Map Info", 2860 title => "Map Info",
2826 reply => undef, 2861 reply => undef,
2827 tooltip => "Information related to the maps", 2862 tooltip => "Information related to the maps",
2828 }, 2863 },
2864 "c/party" => {
2865 id => "party",
2866 title => "Party",
2867 reply => "gsay ",
2868 tooltip => "Messages and chat related to your party",
2869 },
2829); 2870);
2830 2871
2831sub cf::client::send_msg { 2872sub cf::client::send_msg {
2832 my ($self, $channel, $msg, $color, @extra) = @_; 2873 my ($self, $channel, $msg, $color, @extra) = @_;
2833 2874
3070 3111
3071The following functions and methods are available within a safe environment: 3112The following functions and methods are available within a safe environment:
3072 3113
3073 cf::object 3114 cf::object
3074 contr pay_amount pay_player map x y force_find force_add destroy 3115 contr pay_amount pay_player map x y force_find force_add destroy
3075 insert remove name archname title slaying race decrease_ob_nr 3116 insert remove name archname title slaying race decrease split
3076 3117
3077 cf::object::player 3118 cf::object::player
3078 player 3119 player
3079 3120
3080 cf::player 3121 cf::player
3085 3126
3086=cut 3127=cut
3087 3128
3088for ( 3129for (
3089 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y 3130 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y
3090 insert remove inv name archname title slaying race 3131 insert remove inv nrof name archname title slaying race
3091 decrease_ob_nr destroy)], 3132 decrease split destroy)],
3092 ["cf::object::player" => qw(player)], 3133 ["cf::object::player" => qw(player)],
3093 ["cf::player" => qw(peaceful)], 3134 ["cf::player" => qw(peaceful)],
3094 ["cf::map" => qw(trigger)], 3135 ["cf::map" => qw(trigger)],
3095) { 3136) {
3096 no strict 'refs'; 3137 no strict 'refs';
3304 while (my ($k, $v) = each %$want) { 3345 while (my ($k, $v) = each %$want) {
3305 $ns->fx_want ($k, $v); 3346 $ns->fx_want ($k, $v);
3306 } 3347 }
3307}; 3348};
3308 3349
3350sub load_resource_file($) {
3351 my $guard = lock_acquire "load_resource_file";
3352
3353 my $status = load_resource_file_ $_[0];
3354 get_slot 0.1, 100;
3355 cf::arch::commit_load;
3356
3357 $status
3358}
3359
3309sub reload_regions { 3360sub reload_regions {
3310 # HACK to clear player env face cache, we need some signal framework 3361 # HACK to clear player env face cache, we need some signal framework
3311 # for this (global event?) 3362 # for this (global event?)
3312 %ext::player_env::MUSIC_FACE_CACHE = (); 3363 %ext::player_env::MUSIC_FACE_CACHE = ();
3313 3364
3326} 3377}
3327 3378
3328sub reload_archetypes { 3379sub reload_archetypes {
3329 load_resource_file "$DATADIR/archetypes" 3380 load_resource_file "$DATADIR/archetypes"
3330 or die "unable to load archetypes\n"; 3381 or die "unable to load archetypes\n";
3331 #d# NEED to laod twice to resolve forward references
3332 # this really needs to be done in an extra post-pass
3333 # (which needs to be synchronous, so solve it differently)
3334 load_resource_file "$DATADIR/archetypes"
3335 or die "unable to load archetypes\n";
3336} 3382}
3337 3383
3338sub reload_treasures { 3384sub reload_treasures {
3339 load_resource_file "$DATADIR/treasures" 3385 load_resource_file "$DATADIR/treasures"
3340 or die "unable to load treasurelists\n"; 3386 or die "unable to load treasurelists\n";
3341} 3387}
3342 3388
3343sub reload_resources { 3389sub reload_resources {
3344 warn "reloading resource files...\n"; 3390 warn "reloading resource files...\n";
3345 3391
3392 reload_facedata;
3393 reload_archetypes;
3346 reload_regions; 3394 reload_regions;
3347 reload_facedata;
3348 #reload_archetypes;#d#
3349 reload_archetypes;
3350 reload_treasures; 3395 reload_treasures;
3351 3396
3352 warn "finished reloading resource files\n"; 3397 warn "finished reloading resource files\n";
3353} 3398}
3354 3399
3355sub init { 3400sub init {
3401 my $guard = freeze_mainloop;
3402
3356 reload_resources; 3403 reload_resources;
3357} 3404}
3358 3405
3359sub reload_config { 3406sub reload_config {
3360 open my $fh, "<:utf8", "$CONFDIR/config" 3407 open my $fh, "<:utf8", "$CONFDIR/config"
3385 $Coro::current->{desc} = "IDLE BUG HANDLER"; 3432 $Coro::current->{desc} = "IDLE BUG HANDLER";
3386 EV::loop EV::LOOP_ONESHOT; 3433 EV::loop EV::LOOP_ONESHOT;
3387 })->prio (Coro::PRIO_MAX); 3434 })->prio (Coro::PRIO_MAX);
3388 }; 3435 };
3389 3436
3437 {
3438 my $guard = freeze_mainloop;
3390 reload_config; 3439 reload_config;
3391 db_init; 3440 db_init;
3392 load_extensions; 3441 load_extensions;
3393 3442
3394 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3443 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3395 evthread_start IO::AIO::poll_fileno; 3444 }
3445
3396 EV::loop; 3446 EV::loop;
3397} 3447}
3398 3448
3399############################################################################# 3449#############################################################################
3400# initialisation and cleanup 3450# initialisation and cleanup
3682 3732
3683our @WAIT_FOR_TICK; 3733our @WAIT_FOR_TICK;
3684our @WAIT_FOR_TICK_BEGIN; 3734our @WAIT_FOR_TICK_BEGIN;
3685 3735
3686sub wait_for_tick { 3736sub wait_for_tick {
3687 return if tick_inhibit;
3688 return if $Coro::current == $Coro::main; 3737 return if tick_inhibit || $Coro::current == $Coro::main;
3689 3738
3690 my $signal = new Coro::Signal; 3739 my $signal = new Coro::Signal;
3691 push @WAIT_FOR_TICK, $signal; 3740 push @WAIT_FOR_TICK, $signal;
3692 $signal->wait; 3741 $signal->wait;
3693} 3742}
3694 3743
3695sub wait_for_tick_begin { 3744sub wait_for_tick_begin {
3696 return if tick_inhibit;
3697 return if $Coro::current == $Coro::main; 3745 return if tick_inhibit || $Coro::current == $Coro::main;
3698 3746
3699 my $signal = new Coro::Signal; 3747 my $signal = new Coro::Signal;
3700 push @WAIT_FOR_TICK_BEGIN, $signal; 3748 push @WAIT_FOR_TICK_BEGIN, $signal;
3701 $signal->wait; 3749 $signal->wait;
3702} 3750}
3741{ 3789{
3742 # configure BDB 3790 # configure BDB
3743 3791
3744 BDB::min_parallel 8; 3792 BDB::min_parallel 8;
3745 BDB::max_poll_reqs $TICK * 0.1; 3793 BDB::max_poll_reqs $TICK * 0.1;
3746 $Coro::BDB::WATCHER->priority (1); 3794 $AnyEvent::BDB::WATCHER->priority (1);
3747 3795
3748 unless ($DB_ENV) { 3796 unless ($DB_ENV) {
3749 $DB_ENV = BDB::db_env_create; 3797 $DB_ENV = BDB::db_env_create;
3750 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC 3798 $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT | BDB::TXN_NOSYNC
3751 | BDB::LOG_AUTOREMOVE, 1); 3799 | BDB::LOG_AUTOREMOVE, 1);
3782{ 3830{
3783 # configure IO::AIO 3831 # configure IO::AIO
3784 3832
3785 IO::AIO::min_parallel 8; 3833 IO::AIO::min_parallel 8;
3786 IO::AIO::max_poll_time $TICK * 0.1; 3834 IO::AIO::max_poll_time $TICK * 0.1;
3787 $Coro::AIO::WATCHER->priority (1); 3835 #undef $AnyEvent::AIO::WATCHER;
3788} 3836}
3789 3837
3790my $_log_backtrace; 3838my $_log_backtrace;
3791 3839
3792sub _log_backtrace { 3840sub _log_backtrace {
3830# load additional modules 3878# load additional modules
3831use cf::pod; 3879use cf::pod;
3832 3880
3833END { cf::emergency_save } 3881END { cf::emergency_save }
3834 3882
3883evthread_start IO::AIO::poll_fileno;
3884
38351 38851
3836 3886

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines