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.171 by root, Sun Jan 14 12:24:48 2007 UTC vs.
Revision 1.176 by root, Sun Jan 14 22:14:35 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;
1113 1113
1114use Fcntl; 1114use Fcntl;
1115use Coro::AIO; 1115use Coro::AIO;
1116 1116
1117use overload 1117use overload
1118 '""' => \&as_string; 1118 '""' => \&as_string,
1119 fallback => 1;
1119 1120
1120our $MAX_RESET = 3600; 1121our $MAX_RESET = 3600;
1121our $DEFAULT_RESET = 3000; 1122our $DEFAULT_RESET = 3000;
1122 1123
1123sub generate_random_map { 1124sub generate_random_map {
1151 1152
1152# also paths starting with '/' 1153# also paths starting with '/'
1153$EXT_MAP{"cf::map"} = qr{^(?=/)}; 1154$EXT_MAP{"cf::map"} = qr{^(?=/)};
1154 1155
1155sub thawer_merge { 1156sub thawer_merge {
1157 my ($self, $merge) = @_;
1158
1156 # we have to keep some variables in memory intact 1159 # we have to keep some variables in memory intact
1157 local $_[0]{path}; 1160 local $self->{path};
1161 local $self->{load_path};
1158 local $_[0]{deny_save}; 1162 local $self->{deny_save};
1159 local $_[0]{deny_reset}; 1163 local $self->{deny_reset};
1160 1164
1161 $_[0]->SUPER::thawer_merge ($_[1]); 1165 $self->SUPER::thawer_merge ($merge);
1162} 1166}
1163 1167
1164sub normalise { 1168sub normalise {
1165 my ($path, $base) = @_; 1169 my ($path, $base) = @_;
1166 1170
1531 my ($self) = @_; 1535 my ($self) = @_;
1532 1536
1533 $self->reset_at <= $cf::RUNTIME 1537 $self->reset_at <= $cf::RUNTIME
1534} 1538}
1535 1539
1536sub rename {
1537 my ($self, $new_path) = @_;
1538
1539 normalise $new_path;
1540
1541 $self->unlink_save;
1542
1543 delete $cf::MAP{$self->path};
1544 $self->{path} = $new_path; $self->path ($self->{path});
1545 $cf::MAP{$self->path} = $self;
1546
1547 $self->save;
1548}
1549
1550sub reset { 1540sub reset {
1551 my ($self) = @_; 1541 my ($self) = @_;
1552 1542
1553 my $lock = cf::lock_acquire "map_data:$self->{path}"; 1543 my $lock = cf::lock_acquire "map_data:$self->{path}";
1554 1544
1571my $nuke_counter = "aaaa"; 1561my $nuke_counter = "aaaa";
1572 1562
1573sub nuke { 1563sub nuke {
1574 my ($self) = @_; 1564 my ($self) = @_;
1575 1565
1566 delete $cf::MAP{$self->path};
1567
1568 $self->unlink_save;
1569
1570 bless $self, "cf::map";
1571 delete $self->{deny_reset};
1576 $self->{deny_save} = 1; 1572 $self->{deny_save} = 1;
1577 $self->reset_timeout (1); 1573 $self->reset_timeout (1);
1578 $self->rename ("{nuke}/" . ($nuke_counter++)); 1574 $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++));
1575
1576 $cf::MAP{$self->path} = $self;
1577
1579 $self->reset; # polite request, might not happen 1578 $self->reset; # polite request, might not happen
1580} 1579}
1581 1580
1582=item cf::map::unique_maps 1581=item cf::map::unique_maps
1583 1582
2229 2228
2230sub main { 2229sub main {
2231 # we must not ever block the main coroutine 2230 # we must not ever block the main coroutine
2232 local $Coro::idle = sub { 2231 local $Coro::idle = sub {
2233 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 2232 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
2233 (async {
2234 async { Event::one_event }; 2234 Event::one_event;
2235 })->prio (Coro::PRIO_MAX);
2235 }; 2236 };
2236 2237
2237 cfg_load; 2238 cfg_load;
2238 db_load; 2239 db_load;
2239 load_extensions; 2240 load_extensions;
2387 } 2388 }
2388 2389
2389 warn "reloaded"; 2390 warn "reloaded";
2390}; 2391};
2391 2392
2393our $RELOAD_WATCHER; # used only during reload
2394
2392register_command "reload" => sub { 2395register_command "reload" => sub {
2393 my ($who, $arg) = @_; 2396 my ($who, $arg) = @_;
2394 2397
2395 if ($who->flag (FLAG_WIZ)) { 2398 if ($who->flag (FLAG_WIZ)) {
2396 $who->message ("start of reload."); 2399 $who->message ("reloading server.");
2400
2401 # doing reload synchronously and two reloads happen back-to-back,
2402 # coro crashes during coro_state_free->destroy here.
2403
2404 $RELOAD_WATCHER ||= Event->timer (after => 0, data => WF_AUTOCANCEL, cb => sub {
2397 reload; 2405 reload;
2398 $who->message ("end of reload."); 2406 undef $RELOAD_WATCHER;
2407 });
2399 } 2408 }
2400}; 2409};
2401 2410
2402unshift @INC, $LIBDIR; 2411unshift @INC, $LIBDIR;
2403 2412

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines