… | |
… | |
17 | use Coro::Semaphore; |
17 | use Coro::Semaphore; |
18 | use Coro::AIO; |
18 | use Coro::AIO; |
19 | |
19 | |
20 | use Digest::MD5; |
20 | use Digest::MD5; |
21 | use Fcntl; |
21 | use Fcntl; |
22 | use IO::AIO 2.31 (); |
22 | use IO::AIO 2.32 (); |
23 | use YAML::Syck (); |
23 | use YAML::Syck (); |
24 | use Time::HiRes; |
24 | use Time::HiRes; |
25 | |
25 | |
26 | use Event; $Event::Eval = 1; # no idea why this is required, but it is |
26 | use 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 | |
1087 | Returns the given player object, loading it if necessary (might block). |
1087 | Returns the given player object, loading it if necessary (might block). |
1088 | |
1088 | |
1089 | =cut |
1089 | =cut |
1090 | |
1090 | |
|
|
1091 | sub playerdir($) { |
|
|
1092 | cf::localdir |
|
|
1093 | . "/" |
|
|
1094 | . cf::playerdir |
|
|
1095 | . "/" |
|
|
1096 | . (ref $_[0] ? $_[0]->ob->name : $_[0]) |
|
|
1097 | } |
|
|
1098 | |
1091 | sub path($) { |
1099 | sub 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 | |
1097 | sub find_active($) { |
1105 | sub find_active($) { |
1098 | $cf::PLAYER{$_[0]} |
1106 | $cf::PLAYER{$_[0]} |
1099 | and $cf::PLAYER{$_[0]}->active |
1107 | and $cf::PLAYER{$_[0]}->active |
… | |
… | |
1111 | return $cf::PLAYER{$_[0]} || do { |
1119 | return $cf::PLAYER{$_[0]} || do { |
1112 | my $login = $_[0]; |
1120 | my $login = $_[0]; |
1113 | |
1121 | |
1114 | my $guard = cf::lock_acquire "user_find:$login"; |
1122 | my $guard = cf::lock_acquire "user_find:$login"; |
1115 | |
1123 | |
1116 | $cf::PLAYER{$login} ||= (load_pl path $login or return); |
1124 | $cf::PLAYER{$_[0]} || do { |
|
|
1125 | my $pl = load_pl path $login |
|
|
1126 | or return; |
|
|
1127 | $cf::PLAYER{$login} = $pl |
|
|
1128 | } |
1117 | }; |
1129 | } |
1118 | } |
1130 | } |
1119 | |
1131 | |
1120 | sub save($) { |
1132 | sub save($) { |
1121 | my ($pl) = @_; |
1133 | my ($pl) = @_; |
1122 | |
1134 | |
… | |
… | |
1124 | |
1136 | |
1125 | my $path = path $pl; |
1137 | my $path = path $pl; |
1126 | my $guard = cf::lock_acquire "user_save:$path"; |
1138 | my $guard = cf::lock_acquire "user_save:$path"; |
1127 | |
1139 | |
1128 | return if $pl->{deny_save}; |
1140 | return if $pl->{deny_save}; |
|
|
1141 | |
|
|
1142 | Coro::AIO::aio_mkdir playerdir $pl, 0770; |
1129 | $pl->{last_save} = $cf::RUNTIME; |
1143 | $pl->{last_save} = $cf::RUNTIME; |
1130 | |
1144 | |
1131 | Coro::cede; |
|
|
1132 | $pl->save_pl ($path); |
1145 | $pl->save_pl ($path); |
1133 | Coro::cede; |
1146 | Coro::cede; |
1134 | } |
1147 | } |
1135 | |
1148 | |
1136 | sub new($) { |
1149 | sub new($) { |
… | |
… | |
1142 | $self->{deny_save} = 1; |
1155 | $self->{deny_save} = 1; |
1143 | |
1156 | |
1144 | $cf::PLAYER{$login} = $self; |
1157 | $cf::PLAYER{$login} = $self; |
1145 | |
1158 | |
1146 | $self |
1159 | $self |
|
|
1160 | } |
|
|
1161 | |
|
|
1162 | sub quit_character { |
|
|
1163 | my ($pl) = @_; |
|
|
1164 | |
|
|
1165 | $pl->{deny_save} = 1; |
|
|
1166 | $pl->password ("*"); # this should lock out the player until we nuked the dir |
|
|
1167 | |
|
|
1168 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; |
|
|
1169 | $pl->deactivate; |
|
|
1170 | $pl->invoke (cf::EVENT_PLAYER_QUIT); |
|
|
1171 | $pl->ns->destroy if $pl->ns; |
|
|
1172 | |
|
|
1173 | my $path = playerdir $pl; |
|
|
1174 | my $temp = "$path~$cf::RUNTIME~deleting~"; |
|
|
1175 | Coro::AIO::aio_rename $path, $temp; |
|
|
1176 | delete $cf::PLAYER{$pl->ob->name}; |
|
|
1177 | $pl->destroy; |
|
|
1178 | IO::AIO::aio_rmtree $temp; |
1147 | } |
1179 | } |
1148 | |
1180 | |
1149 | =item $player->ext_reply ($msgid, $msgtype, %msg) |
1181 | =item $player->ext_reply ($msgid, $msgtype, %msg) |
1150 | |
1182 | |
1151 | Sends an ext reply to the player. |
1183 | Sends an ext reply to the player. |
… | |
… | |
1650 | $map = $map->customise_for ($self) if $map; |
1682 | $map = $map->customise_for ($self) if $map; |
1651 | |
1683 | |
1652 | # warn "entering ", $map->path, " at ($x, $y)\n" |
1684 | # warn "entering ", $map->path, " at ($x, $y)\n" |
1653 | # if $map; |
1685 | # if $map; |
1654 | |
1686 | |
|
|
1687 | $map or $map->cluck ("oy");#d# |
1655 | $map or $self->message ("The exit is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
1688 | $map or $self->message ("The exit to '" . ($path->visible_name) . "' is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
1656 | |
1689 | |
1657 | $self->leave_link ($map, $x, $y); |
1690 | $self->leave_link ($map, $x, $y); |
1658 | })->prio (1); |
1691 | })->prio (1); |
1659 | } |
1692 | } |
1660 | |
1693 | |
… | |
… | |
2068 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
2101 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
2069 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
2102 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
2070 | |
2103 | |
2071 | if (exists $CFG{mlockall}) { |
2104 | if (exists $CFG{mlockall}) { |
2072 | eval { |
2105 | eval { |
2073 | $CFG{mlockall} ? &mlockall : &munlockall |
2106 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
2074 | and die "WARNING: m(un)lockall failed: $!\n"; |
2107 | and die "WARNING: m(un)lockall failed: $!\n"; |
2075 | }; |
2108 | }; |
2076 | warn $@ if $@; |
2109 | warn $@ if $@; |
2077 | } |
2110 | } |
2078 | } |
2111 | } |