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.178 by root, Thu Jan 18 00:06:55 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
1846 1845
1847 $rmp->{random_seed} ||= $exit->random_seed; 1846 $rmp->{random_seed} ||= $exit->random_seed;
1848 1847
1849 my $data = cf::to_json $rmp; 1848 my $data = cf::to_json $rmp;
1850 my $md5 = Digest::MD5::md5_hex $data; 1849 my $md5 = Digest::MD5::md5_hex $data;
1850 my $meta = "$cf::RANDOM_MAPS/$md5.meta";
1851 1851
1852 if (my $fh = aio_open "$cf::RANDOM_MAPS/$md5.meta", O_WRONLY | O_CREAT, 0666) { 1852 if (my $fh = aio_open "$meta~", O_WRONLY | O_CREAT, 0666) {
1853 aio_write $fh, 0, (length $data), $data, 0; 1853 aio_write $fh, 0, (length $data), $data, 0;
1854 undef $fh;
1855 aio_rename "$meta~", $meta;
1854 1856
1855 $exit->slaying ("?random/$md5"); 1857 $exit->slaying ("?random/$md5");
1856 $exit->msg (undef); 1858 $exit->msg (undef);
1857 } 1859 }
1858} 1860}
2228 2230
2229sub main { 2231sub main {
2230 # we must not ever block the main coroutine 2232 # we must not ever block the main coroutine
2231 local $Coro::idle = sub { 2233 local $Coro::idle = sub {
2232 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 2234 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
2235 (async {
2233 async { Event::one_event }; 2236 Event::one_event;
2237 })->prio (Coro::PRIO_MAX);
2234 }; 2238 };
2235 2239
2236 cfg_load; 2240 cfg_load;
2237 db_load; 2241 db_load;
2238 load_extensions; 2242 load_extensions;
2386 } 2390 }
2387 2391
2388 warn "reloaded"; 2392 warn "reloaded";
2389}; 2393};
2390 2394
2395our $RELOAD_WATCHER; # used only during reload
2396
2391register_command "reload" => sub { 2397register_command "reload" => sub {
2392 my ($who, $arg) = @_; 2398 my ($who, $arg) = @_;
2393 2399
2394 if ($who->flag (FLAG_WIZ)) { 2400 if ($who->flag (FLAG_WIZ)) {
2395 $who->message ("start of reload."); 2401 $who->message ("reloading server.");
2402
2403 # doing reload synchronously and two reloads happen back-to-back,
2404 # coro crashes during coro_state_free->destroy here.
2405
2406 $RELOAD_WATCHER ||= Event->timer (after => 0, data => WF_AUTOCANCEL, cb => sub {
2396 reload; 2407 reload;
2397 $who->message ("end of reload."); 2408 undef $RELOAD_WATCHER;
2409 });
2398 } 2410 }
2399}; 2411};
2400 2412
2401unshift @INC, $LIBDIR; 2413unshift @INC, $LIBDIR;
2402 2414

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines