--- deliantra/server/lib/cf.pm 2008/04/13 01:34:09 1.419 +++ deliantra/server/lib/cf.pm 2008/05/01 06:33:19 1.428 @@ -429,6 +429,8 @@ }; sub get_slot($;$$) { + return if tick_inhibit || $Coro::current == $Coro::main; + my ($time, $pri, $name) = @_; $time = $TICK * .6 if $time > $TICK * .6; @@ -1141,18 +1143,18 @@ $decname, length $$rdata, scalar @$objs; if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { - chmod SAVE_MODE, $fh; + aio_chmod $fh, SAVE_MODE; aio_write $fh, 0, (length $$rdata), $$rdata, 0; aio_fsync $fh if $cf::USE_FSYNC; - close $fh; + aio_close $fh; if (@$objs) { if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { - chmod SAVE_MODE, $fh; + aio_chmod $fh, SAVE_MODE; my $data = Coro::Storable::nfreeze { version => 1, objs => $objs }; aio_write $fh, 0, (length $data), $data, 0; aio_fsync $fh if $cf::USE_FSYNC; - close $fh; + aio_close $fh; aio_rename "$filename.pst~", "$filename.pst"; } } else { @@ -1456,6 +1458,7 @@ my $pl = cf::player::load_pl $f or return; + local $cf::PLAYER_LOADING{$login} = $pl; $f->resolve_delayed_derefs; $cf::PLAYER{$login} = $pl @@ -1476,6 +1479,8 @@ aio_mkdir playerdir $pl, 0770; $pl->{last_save} = $cf::RUNTIME; + cf::get_slot 0.01; + $pl->save_pl ($path); cf::cede_to_tick; } @@ -1568,7 +1573,8 @@ my $path = path $login; # a .pst is a dead give-away for a valid player - unless (-e "$path.pst") { + # if no pst file found, open and chekc for blocked users + if (aio_stat "$path.pst") { my $fh = aio_open $path, Fcntl::O_RDONLY, 0 or next; aio_read $fh, 0, 512, my $buf, 0 or next; $buf !~ /^password -------------$/m or next; # official not-valid tag @@ -2115,7 +2121,7 @@ $self->{last_save} = $cf::RUNTIME; $self->last_access ($cf::RUNTIME); - $self->in_memory (cf::MAP_IN_MEMORY); + $self->in_memory (cf::MAP_ACTIVE); } $self->post_load; @@ -2183,7 +2189,7 @@ $path = normalise $path, $origin && $origin->{path}; if (my $map = $cf::MAP{$path}) { - return $map if !$load || $map->in_memory == cf::MAP_IN_MEMORY; + return $map if !$load || $map->in_memory == cf::MAP_ACTIVE; } $MAP_PREFETCH{$path} |= $load; @@ -2230,6 +2236,8 @@ $_->contr->save for $self->players; }; + cf::get_slot 0.02; + if ($uniq) { $self->_save_objects ($save, cf::IO_HEADER | cf::IO_OBJECTS); $self->_save_objects ($uniq, cf::IO_UNIQUES); @@ -2247,7 +2255,7 @@ my $lock = cf::lock_acquire "map_data:$self->{path}"; return if $self->players; - return if $self->in_memory != cf::MAP_IN_MEMORY; + return if $self->in_memory != cf::MAP_ACTIVE; return if $self->{deny_save}; $self->in_memory (cf::MAP_SWAPPED); @@ -2453,6 +2461,20 @@ =cut +our $SAY_CHANNEL = { + id => "say", + title => "Map", + reply => "say ", + tooltip => "Things said to and replied from npcs near you and other players on the same map only.", +}; + +our $CHAT_CHANNEL = { + id => "chat", + title => "Chat", + reply => "chat ", + tooltip => "Player chat and shouts, global to the server.", +}; + # rough implementation of a future "reply" method that works # with dialog boxes. #TODO: the first argument must go, split into a $npc->reply_to ( method @@ -2473,7 +2495,7 @@ } else { $msg = $npc->name . " says: $msg" if $npc; - $self->message ($msg, $flags); + $self->send_msg ($SAY_CHANNEL => $msg, $flags); } } } @@ -2695,7 +2717,7 @@ $rmp->{random_seed} ||= $exit->random_seed; - my $data = cf::encode_json $rmp; + my $data = JSON::XS->new->utf8->pretty->canonical->encode ($rmp); my $md5 = Digest::MD5::md5_hex $data; my $meta = "$RANDOMDIR/$md5.meta"; @@ -2828,6 +2850,12 @@ reply => undef, tooltip => "Information related to the maps", }, + "c/party" => { + id => "party", + title => "Party", + reply => "gsay ", + tooltip => "Messages and chat related to your party", + }, ); sub cf::client::send_msg { @@ -3074,7 +3102,7 @@ cf::object contr pay_amount pay_player map x y force_find force_add destroy - insert remove name archname title slaying race decrease_ob_nr + insert remove name archname title slaying race decrease split cf::object::player player @@ -3090,7 +3118,7 @@ for ( ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y insert remove inv name archname title slaying race - decrease_ob_nr destroy)], + decrease split destroy)], ["cf::object::player" => qw(player)], ["cf::player" => qw(peaceful)], ["cf::map" => qw(trigger)], @@ -3308,6 +3336,16 @@ } }; +sub load_resource_file($) { + my $guard = lock_acquire "load_resource_file"; + + my $status = load_resource_file_ $_[0]; + get_slot 0.1, 100; + cf::arch::commit_load; + + $status +} + sub reload_regions { # HACK to clear player env face cache, we need some signal framework # for this (global event?) @@ -3330,11 +3368,6 @@ sub reload_archetypes { load_resource_file "$DATADIR/archetypes" or die "unable to load archetypes\n"; - #d# NEED to laod twice to resolve forward references - # this really needs to be done in an extra post-pass - # (which needs to be synchronous, so solve it differently) - load_resource_file "$DATADIR/archetypes" - or die "unable to load archetypes\n"; } sub reload_treasures { @@ -3345,16 +3378,17 @@ sub reload_resources { warn "reloading resource files...\n"; - reload_regions; reload_facedata; - #reload_archetypes;#d# reload_archetypes; + reload_regions; reload_treasures; warn "finished reloading resource files\n"; } sub init { + my $guard = freeze_mainloop; + reload_resources; } @@ -3389,12 +3423,16 @@ })->prio (Coro::PRIO_MAX); }; - reload_config; - db_init; - load_extensions; + { + my $guard = freeze_mainloop; + reload_config; + db_init; + load_extensions; + + $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority + evthread_start IO::AIO::poll_fileno; + } - $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority - evthread_start IO::AIO::poll_fileno; EV::loop; } @@ -3686,8 +3724,7 @@ our @WAIT_FOR_TICK_BEGIN; sub wait_for_tick { - return if tick_inhibit; - return if $Coro::current == $Coro::main; + return if tick_inhibit || $Coro::current == $Coro::main; my $signal = new Coro::Signal; push @WAIT_FOR_TICK, $signal; @@ -3695,8 +3732,7 @@ } sub wait_for_tick_begin { - return if tick_inhibit; - return if $Coro::current == $Coro::main; + return if tick_inhibit || $Coro::current == $Coro::main; my $signal = new Coro::Signal; push @WAIT_FOR_TICK_BEGIN, $signal;