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.174 by root, Sun Jan 14 19:55:37 2007 UTC vs.
Revision 1.179 by root, Thu Jan 18 20:39:00 2007 UTC

8use Storable; 8use Storable;
9use Opcode; 9use Opcode;
10use Safe; 10use Safe;
11use Safe::Hole; 11use Safe::Hole;
12 12
13use Coro 3.3 (); 13use Coro 3.4 ();
14use Coro::Event; 14use Coro::Event;
15use Coro::Timer; 15use Coro::Timer;
16use Coro::Signal; 16use Coro::Signal;
17use Coro::Semaphore; 17use Coro::Semaphore;
18use Coro::AIO; 18use Coro::AIO;
1121our $MAX_RESET = 3600; 1121our $MAX_RESET = 3600;
1122our $DEFAULT_RESET = 3000; 1122our $DEFAULT_RESET = 3000;
1123 1123
1124sub generate_random_map { 1124sub generate_random_map {
1125 my ($self, $rmp) = @_; 1125 my ($self, $rmp) = @_;
1126
1127 # mit "rum" bekleckern, nicht 1126 # mit "rum" bekleckern, nicht
1128 $self->_create_random_map ( 1127 $self->_create_random_map (
1129 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle}, 1128 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle},
1130 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, 1129 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle},
1131 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map}, 1130 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map},
1813 1812
1814sub parse_random_map_params { 1813sub parse_random_map_params {
1815 my ($spec) = @_; 1814 my ($spec) = @_;
1816 1815
1817 my $rmp = { # defaults 1816 my $rmp = { # defaults
1818 xsize => 10, 1817 xsize => -1,
1819 ysize => 10, 1818 ysize => -1,
1820 }; 1819 };
1821 1820
1822 for (split /\n/, $spec) { 1821 for (split /\n/, $spec) {
1823 my ($k, $v) = split /\s+/, $_, 2; 1822 my ($k, $v) = split /\s+/, $_, 2;
1824 1823
1828 $rmp 1827 $rmp
1829} 1828}
1830 1829
1831sub prepare_random_map { 1830sub prepare_random_map {
1832 my ($exit) = @_; 1831 my ($exit) = @_;
1832
1833 my $guard = cf::lock_acquire "exit_prepare:$exit";
1833 1834
1834 # all this does is basically replace the /! path by 1835 # all this does is basically replace the /! path by
1835 # a new random map path (?random/...) with a seed 1836 # a new random map path (?random/...) with a seed
1836 # that depends on the exit object 1837 # that depends on the exit object
1837 1838
1846 1847
1847 $rmp->{random_seed} ||= $exit->random_seed; 1848 $rmp->{random_seed} ||= $exit->random_seed;
1848 1849
1849 my $data = cf::to_json $rmp; 1850 my $data = cf::to_json $rmp;
1850 my $md5 = Digest::MD5::md5_hex $data; 1851 my $md5 = Digest::MD5::md5_hex $data;
1852 my $meta = "$cf::RANDOM_MAPS/$md5.meta";
1851 1853
1852 if (my $fh = aio_open "$cf::RANDOM_MAPS/$md5.meta", O_WRONLY | O_CREAT, 0666) { 1854 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) {
1853 aio_write $fh, 0, (length $data), $data, 0; 1855 aio_write $fh, 0, (length $data), $data, 0;
1856 undef $fh;
1857 aio_rename "$meta~", $meta;
1854 1858
1855 $exit->slaying ("?random/$md5"); 1859 $exit->slaying ("?random/$md5");
1856 $exit->msg (undef); 1860 $exit->msg (undef);
1857 } 1861 }
1858} 1862}
2228 2232
2229sub main { 2233sub main {
2230 # we must not ever block the main coroutine 2234 # we must not ever block the main coroutine
2231 local $Coro::idle = sub { 2235 local $Coro::idle = sub {
2232 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 2236 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
2237 (async {
2233 async { Event::one_event }; 2238 Event::one_event;
2239 })->prio (Coro::PRIO_MAX);
2234 }; 2240 };
2235 2241
2236 cfg_load; 2242 cfg_load;
2237 db_load; 2243 db_load;
2238 load_extensions; 2244 load_extensions;
2386 } 2392 }
2387 2393
2388 warn "reloaded"; 2394 warn "reloaded";
2389}; 2395};
2390 2396
2397our $RELOAD_WATCHER; # used only during reload
2398
2391register_command "reload" => sub { 2399register_command "reload" => sub {
2392 my ($who, $arg) = @_; 2400 my ($who, $arg) = @_;
2393 2401
2394 if ($who->flag (FLAG_WIZ)) { 2402 if ($who->flag (FLAG_WIZ)) {
2395 $who->message ("start of reload."); 2403 $who->message ("reloading server.");
2404
2405 # doing reload synchronously and two reloads happen back-to-back,
2406 # coro crashes during coro_state_free->destroy here.
2407
2408 $RELOAD_WATCHER ||= Event->timer (after => 0, data => WF_AUTOCANCEL, cb => sub {
2396 reload; 2409 reload;
2397 $who->message ("end of reload."); 2410 undef $RELOAD_WATCHER;
2411 });
2398 } 2412 }
2399}; 2413};
2400 2414
2401unshift @INC, $LIBDIR; 2415unshift @INC, $LIBDIR;
2402 2416

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines