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.505 by root, Sun Jan 31 03:46:20 2010 UTC vs.
Revision 1.511 by root, Wed Apr 7 18:35:56 2010 UTC

1310} 1310}
1311 1311
1312use File::Glob (); 1312use File::Glob ();
1313 1313
1314cf::player->attach ( 1314cf::player->attach (
1315 on_command => sub { 1315 on_unknown_command => sub {
1316 my ($pl, $name, $params) = @_; 1316 my ($pl, $name, $params) = @_;
1317 1317
1318 my $cb = $COMMAND{$name} 1318 my $cb = $COMMAND{$name}
1319 or return; 1319 or return;
1320 1320
1533 $cf::PLAYER{$login} = $pl 1533 $cf::PLAYER{$login} = $pl
1534 } 1534 }
1535 } 1535 }
1536} 1536}
1537 1537
1538cf::player->attach (
1539 on_load => sub {
1540 my ($pl, $path) = @_;
1541
1542 # restore slots saved in save, below
1543 my $slots = delete $pl->{_slots};
1544
1545 $pl->ob->current_weapon ($slots->[0]);
1546 $pl->combat_ob ($slots->[1]);
1547 $pl->ranged_ob ($slots->[2]);
1548 },
1549);
1550
1538sub save($) { 1551sub save($) {
1539 my ($pl) = @_; 1552 my ($pl) = @_;
1540 1553
1541 return if $pl->{deny_save}; 1554 return if $pl->{deny_save};
1542 1555
1547 1560
1548 aio_mkdir playerdir $pl, 0770; 1561 aio_mkdir playerdir $pl, 0770;
1549 $pl->{last_save} = $cf::RUNTIME; 1562 $pl->{last_save} = $cf::RUNTIME;
1550 1563
1551 cf::get_slot 0.01; 1564 cf::get_slot 0.01;
1565
1566 # save slots, to be restored later
1567 local $pl->{_slots} = [$pl->ob->current_weapon, $pl->combat_ob, $pl->ranged_ob];
1552 1568
1553 $pl->save_pl ($path); 1569 $pl->save_pl ($path);
1554 cf::cede_to_tick; 1570 cf::cede_to_tick;
1555} 1571}
1556 1572
1769 my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM 1785 my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM
1770 1786
1771 # mit "rum" bekleckern, nicht 1787 # mit "rum" bekleckern, nicht
1772 $self->_create_random_map ( 1788 $self->_create_random_map (
1773 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle}, 1789 $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle},
1774 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, 1790 $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, $rmp->{miningstyle},
1775 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map}, 1791 $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map},
1776 $rmp->{exit_on_final_map}, 1792 $rmp->{exit_on_final_map},
1777 $rmp->{xsize}, $rmp->{ysize}, 1793 $rmp->{xsize}, $rmp->{ysize},
1778 $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3}, 1794 $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3},
1779 $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase}, 1795 $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase},
2093 } 2109 }
2094 2110
2095 $self->post_load; 2111 $self->post_load;
2096} 2112}
2097 2113
2114# customize the map for a given player, i.e.
2115# return the _real_ map. used by e.g. per-player
2116# maps to change the path to ~playername/mappath
2098sub customise_for { 2117sub customise_for {
2099 my ($self, $ob) = @_; 2118 my ($self, $ob) = @_;
2100 2119
2101 return find "~" . $ob->name . "/" . $self->{path} 2120 return find "~" . $ob->name . "/" . $self->{path}
2102 if $self->per_player; 2121 if $self->per_player;
3131 3150
3132 $coro 3151 $coro
3133} 3152}
3134 3153
3135cf::client->attach ( 3154cf::client->attach (
3136 on_destroy => sub { 3155 on_client_destroy => sub {
3137 my ($ns) = @_; 3156 my ($ns) = @_;
3138 3157
3139 $_->cancel for values %{ (delete $ns->{_coro}) || {} }; 3158 $_->cancel for values %{ (delete $ns->{_coro}) || {} };
3140 }, 3159 },
3141); 3160);
3538 reload_config; 3557 reload_config;
3539 db_init; 3558 db_init;
3540 3559
3541 cf::init_uuid; 3560 cf::init_uuid;
3542 cf::init_signals; 3561 cf::init_signals;
3543 cf::init_commands;
3544 cf::init_skills; 3562 cf::init_skills;
3545 3563
3546 cf::init_beforeplay; 3564 cf::init_beforeplay;
3547 3565
3548 atomic; 3566 atomic;
3573 }; 3591 };
3574 } 3592 }
3575} 3593}
3576 3594
3577sub write_runtime_sync { 3595sub write_runtime_sync {
3596 my $t0 = EV::time;
3597
3578 # first touch the runtime file to show we are still running: 3598 # first touch the runtime file to show we are still running:
3579 # the fsync below can take a very very long time. 3599 # the fsync below can take a very very long time.
3580 3600
3581 IO::AIO::aio_utime $RUNTIMEFILE, undef, undef; 3601 IO::AIO::aio_utime $RUNTIMEFILE, undef, undef;
3582 3602
3603 or return; 3623 or return;
3604 3624
3605 aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE 3625 aio_rename "$RUNTIMEFILE~", $RUNTIMEFILE
3606 and return; 3626 and return;
3607 3627
3608 warn "runtime file written.\n"; 3628 warn sprintf "runtime file written (%gs).\n", EV::time - $t0;
3609 3629
3610 1 3630 1
3611} 3631}
3612 3632
3613our $uuid_lock; 3633our $uuid_lock;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines