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.143 by root, Sun Jan 7 02:39:14 2007 UTC vs.
Revision 1.150 by root, Mon Jan 8 19:25:53 2007 UTC

17use Coro::Semaphore; 17use Coro::Semaphore;
18use Coro::AIO; 18use Coro::AIO;
19 19
20use Digest::MD5; 20use Digest::MD5;
21use Fcntl; 21use Fcntl;
22use IO::AIO 2.31 (); 22use IO::AIO 2.32 ();
23use YAML::Syck (); 23use YAML::Syck ();
24use Time::HiRes; 24use Time::HiRes;
25 25
26use Event; $Event::Eval = 1; # no idea why this is required, but it is 26use Event; $Event::Eval = 1; # no idea why this is required, but it is
27 27
118 utf8::encode $msg; 118 utf8::encode $msg;
119 119
120 $msg .= "\n" 120 $msg .= "\n"
121 unless $msg =~ /\n$/; 121 unless $msg =~ /\n$/;
122 122
123 LOG llevError, "cfperl: $msg"; 123 LOG llevError, $msg;
124 }; 124 };
125} 125}
126 126
127@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable'; 127@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable';
128@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable'; 128@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable';
1086 1086
1087Returns the given player object, loading it if necessary (might block). 1087Returns the given player object, loading it if necessary (might block).
1088 1088
1089=cut 1089=cut
1090 1090
1091sub playerdir($) {
1092 cf::localdir
1093 . "/"
1094 . cf::playerdir
1095 . "/"
1096 . (ref $_[0] ? $_[0]->ob->name : $_[0])
1097}
1098
1091sub path($) { 1099sub path($) {
1092 sprintf "%s/%s/%s/%s.pl", 1100 my $login = ref $_[0] ? $_[0]->ob->name : $_[0];
1093 cf::localdir, cf::playerdir, 1101
1094 (ref $_[0] ? $_[0]->ob->name : $_[0]) x 2 1102 (playerdir $login) . "/$login.pl"
1095} 1103}
1096 1104
1097sub find_active($) { 1105sub find_active($) {
1098 $cf::PLAYER{$_[0]} 1106 $cf::PLAYER{$_[0]}
1099 and $cf::PLAYER{$_[0]}->active 1107 and $cf::PLAYER{$_[0]}->active
1124 1132
1125 my $path = path $pl; 1133 my $path = path $pl;
1126 my $guard = cf::lock_acquire "user_save:$path"; 1134 my $guard = cf::lock_acquire "user_save:$path";
1127 1135
1128 return if $pl->{deny_save}; 1136 return if $pl->{deny_save};
1137
1138 Coro::AIO::aio_mkdir playerdir $pl, 0770;
1129 $pl->{last_save} = $cf::RUNTIME; 1139 $pl->{last_save} = $cf::RUNTIME;
1130 1140
1131 Coro::cede;
1132 $pl->save_pl ($path); 1141 $pl->save_pl ($path);
1133 Coro::cede; 1142 Coro::cede;
1134} 1143}
1135 1144
1136sub new($) { 1145sub new($) {
1142 $self->{deny_save} = 1; 1151 $self->{deny_save} = 1;
1143 1152
1144 $cf::PLAYER{$login} = $self; 1153 $cf::PLAYER{$login} = $self;
1145 1154
1146 $self 1155 $self
1156}
1157
1158sub quit_character {
1159 my ($pl) = @_;
1160
1161 $pl->{deny_save} = 1;
1162 $pl->password ("*"); # this should lock out the player until we nuked the dir
1163
1164 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active;
1165 $pl->deactivate;
1166 $pl->invoke (cf::EVENT_PLAYER_QUIT);
1167 $pl->ns->destroy if $pl->ns;
1168
1169 my $path = playerdir $pl;
1170 my $temp = "$path~$cf::RUNTIME~deleting~";
1171 Coro::AIO::aio_rename $path, $temp;
1172 delete $cf::PLAYER{$pl->ob->name};
1173 $pl->destroy;
1174 IO::AIO::aio_rmtree $temp;
1147} 1175}
1148 1176
1149=item $player->ext_reply ($msgid, $msgtype, %msg) 1177=item $player->ext_reply ($msgid, $msgtype, %msg)
1150 1178
1151Sends an ext reply to the player. 1179Sends an ext reply to the player.
1474} 1502}
1475 1503
1476sub emergency_save { 1504sub emergency_save {
1477 my $freeze_guard = cf::freeze_mainloop; 1505 my $freeze_guard = cf::freeze_mainloop;
1478 1506
1479 warn "enter emergency map save\n"; 1507 warn "enter emergency perl save\n";
1480 1508
1481 cf::sync_job { 1509 cf::sync_job {
1510 warn "begin emergency player save\n";
1511 $_->save for values %cf::PLAYER;
1512 warn "end emergency player save\n";
1513
1482 warn "begin emergency map save\n"; 1514 warn "begin emergency map save\n";
1483 $_->save for values %cf::MAP; 1515 $_->save for values %cf::MAP;
1516 warn "end emergency map save\n";
1484 }; 1517 };
1485 1518
1486 warn "end emergency map save\n"; 1519 warn "leave emergency perl save\n";
1487} 1520}
1488 1521
1489package cf; 1522package cf;
1490 1523
1491=back 1524=back
1645 $map = $map->customise_for ($self) if $map; 1678 $map = $map->customise_for ($self) if $map;
1646 1679
1647# warn "entering ", $map->path, " at ($x, $y)\n" 1680# warn "entering ", $map->path, " at ($x, $y)\n"
1648# if $map; 1681# if $map;
1649 1682
1683 $map or $map->cluck ("oy");#d#
1650 $map or $self->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED); 1684 $map or $self->message ("The exit to '" . ($path->visible_name) . "' is closed", cf::NDI_UNIQUE | cf::NDI_RED);
1651 1685
1652 $self->leave_link ($map, $x, $y); 1686 $self->leave_link ($map, $x, $y);
1653 })->prio (1); 1687 })->prio (1);
1654} 1688}
1655 1689
2063 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; 2097 $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset};
2064 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; 2098 $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset};
2065 2099
2066 if (exists $CFG{mlockall}) { 2100 if (exists $CFG{mlockall}) {
2067 eval { 2101 eval {
2068 $CFG{mlockall} ? &mlockall : &munlockall 2102 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()"
2069 and die "WARNING: m(un)lockall failed: $!\n"; 2103 and die "WARNING: m(un)lockall failed: $!\n";
2070 }; 2104 };
2071 warn $@ if $@; 2105 warn $@ if $@;
2072 } 2106 }
2073} 2107}
2167 cf::load_extensions; 2201 cf::load_extensions;
2168 2202
2169 # reattach attachments to objects 2203 # reattach attachments to objects
2170 warn "reattach"; 2204 warn "reattach";
2171 _global_reattach; 2205 _global_reattach;
2206 reattach $_ for values %MAP;
2172 }; 2207 };
2173 2208
2174 if ($@) { 2209 if ($@) {
2175 warn $@; 2210 warn $@;
2176 warn "error while reloading, exiting."; 2211 warn "error while reloading, exiting.";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines